diff options
author | 2023-10-03 16:23:22 +0000 | |
---|---|---|
committer | 2023-10-03 16:23:22 +0000 | |
commit | d8e470a581a61552c0af76bb82fe3cc8d36e1852 (patch) | |
tree | dc83d7aea49f9f5eb180f24e75ae9f1d8d86905c /rs | |
parent | b45e69de0c1a71aabc75518566bda6c62b431fb0 (diff) | |
parent | f62b3d73aeb01f7a0a5cc0285401f8339da02429 (diff) |
Merge "Throw an exception when using RenderScript ScriptC with an API level above 34" into main am: 6958a77825 am: f62b3d73ae
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2743418
Change-Id: Ibf1152614b9068c62ff8822890df521ca87a03f1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'rs')
-rw-r--r-- | rs/java/android/renderscript/ScriptC.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/rs/java/android/renderscript/ScriptC.java b/rs/java/android/renderscript/ScriptC.java index 1866a9983495..eb7e9aed1944 100644 --- a/rs/java/android/renderscript/ScriptC.java +++ b/rs/java/android/renderscript/ScriptC.java @@ -16,9 +16,12 @@ package android.renderscript; +import android.app.compat.CompatChanges; +import android.compat.annotation.ChangeId; +import android.compat.annotation.EnabledAfter; import android.content.res.Resources; +import android.util.Slog; -import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -35,6 +38,15 @@ public class ScriptC extends Script { private static final String TAG = "ScriptC"; /** + * In targetSdkVersion 35 and above, Renderscript's ScriptC stops being supported + * and an exception is thrown when the class is instantiated. + * In targetSdkVersion 34 and below, Renderscript's ScriptC still works. + */ + @ChangeId + @EnabledAfter(targetSdkVersion = 35) + private static final long RENDERSCRIPT_SCRIPTC_DEPRECATION_CHANGE_ID = 297019750L; + + /** * Only intended for use by the generated derived classes. * * @param id @@ -89,7 +101,20 @@ public class ScriptC extends Script { setID(id); } - private static synchronized long internalCreate(RenderScript rs, Resources resources, int resourceID) { + private static void throwExceptionIfSDKTooHigh() { + String message = + "ScriptC scripts are not supported when targeting an API Level >= 35. Please refer " + + "to https://developer.android.com/guide/topics/renderscript/migration-guide " + + "for proposed alternatives."; + Slog.w(TAG, message); + if (CompatChanges.isChangeEnabled(RENDERSCRIPT_SCRIPTC_DEPRECATION_CHANGE_ID)) { + throw new UnsupportedOperationException(message); + } + } + + private static synchronized long internalCreate( + RenderScript rs, Resources resources, int resourceID) { + throwExceptionIfSDKTooHigh(); byte[] pgm; int pgmLength; InputStream is = resources.openRawResource(resourceID); @@ -125,6 +150,7 @@ public class ScriptC extends Script { } private static synchronized long internalStringCreate(RenderScript rs, String resName, byte[] bitcode) { + throwExceptionIfSDKTooHigh(); // Log.v(TAG, "Create script for resource = " + resName); return rs.nScriptCCreate(resName, RenderScript.getCachePath(), bitcode, bitcode.length); } |