diff options
author | Jean-François Geyelin <jif@google.com> | 2023-11-14 14:36:56 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-11-14 14:36:56 +0000 |
commit | ef254e8f39c283bfacb5b25a20a487acb7cd4229 (patch) | |
tree | 05085dda5c76f413784ea47bf1b79f3b9fb2d89b | |
parent | 47fcd9e1ff50a4afe7c2af6e2860be44d481bebd (diff) | |
parent | b03b50ad36225e0d471451f40ad2bd11851eec7b (diff) | |
download | rs-ef254e8f39c283bfacb5b25a20a487acb7cd4229.tar.gz |
Merge "Throw an exception when using RenderScript ScriptC with an API level above 34" into main
-rw-r--r-- | support/java/src/androidx/renderscript/ScriptC.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/support/java/src/androidx/renderscript/ScriptC.java b/support/java/src/androidx/renderscript/ScriptC.java index 4fd626e6..e1d06a30 100644 --- a/support/java/src/androidx/renderscript/ScriptC.java +++ b/support/java/src/androidx/renderscript/ScriptC.java @@ -90,7 +90,24 @@ public class ScriptC extends Script { setID(id); } + private static void throwExceptionIfSDKTooHigh(RenderScript rs) { + String message = + "ScriptC scripts are not supported when targeting an API Level > 34. Please refer " + + "to https://developer.android.com/guide/topics/renderscript/migration-guide " + + "for proposed alternatives."; + Log.w(TAG, message); + // Inlining of the Build.VERSION_CODES.UPSIDE_DOWN_CAKE constant because it is not available + // when building with older SDKs. + // https://developer.android.com/reference/android/os/Build.VERSION_CODES#UPSIDE_DOWN_CAKE + final int maxSupportedTargetSDKVersion = 34; + int targetSdkVersion = rs.getApplicationContext().getApplicationInfo().targetSdkVersion; + if (targetSdkVersion > maxSupportedTargetSDKVersion) { + throw new UnsupportedOperationException(message); + } + } + private static synchronized long internalCreate(RenderScript rs, Resources resources, int resourceID) { + throwExceptionIfSDKTooHigh(rs); byte[] pgm; int pgmLength; InputStream is = resources.openRawResource(resourceID); @@ -129,6 +146,7 @@ public class ScriptC extends Script { private static synchronized long internalStringCreate(RenderScript rs, String resName, byte[] bitcode) { // Log.v(TAG, "Create script for resource = " + resName); + throwExceptionIfSDKTooHigh(rs); String cachePath = rs.getApplicationContext().getCacheDir().toString(); return rs.nScriptCCreate(resName, cachePath, bitcode, bitcode.length); } |