Skip to content

Commit

Permalink
Merge "Throw when ScriptC is used on unsupported ABIs" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jyaif authored and Gerrit Code Review committed Feb 26, 2024
2 parents 095f7f7 + 4f585f7 commit 82b0838
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions rs/java/android/renderscript/ScriptC.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,19 @@ protected ScriptC(RenderScript rs, String resName, byte[] bitcode32, byte[] bitc
setID(id);
}

private static void throwExceptionIfSDKTooHigh() {
private static void throwExceptionIfScriptCUnsupported() {
// Checks that this device actually does have an ABI that supports ScriptC.
//
// For an explanation as to why `System.loadLibrary` is used, see discussion at
// https://android-review.googlesource.com/c/platform/frameworks/base/+/2957974/comment/2f908b80_a05292ee
try {
System.loadLibrary("RS");
} catch (UnsatisfiedLinkError e) {
String s = "This device does not have an ABI that supports ScriptC.";
throw new UnsupportedOperationException(s);
}

// Throw an exception if the target API is 35 or above
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 "
Expand All @@ -113,7 +125,7 @@ private static void throwExceptionIfSDKTooHigh() {
}

private static synchronized long internalCreate(RenderScript rs, Resources resources, int resourceID) {
throwExceptionIfSDKTooHigh();
throwExceptionIfScriptCUnsupported();
byte[] pgm;
int pgmLength;
InputStream is = resources.openRawResource(resourceID);
Expand Down Expand Up @@ -150,7 +162,7 @@ private static synchronized long internalCreate(RenderScript rs, Resources resou

private static synchronized long internalStringCreate(RenderScript rs, String resName, byte[] bitcode) {
// Log.v(TAG, "Create script for resource = " + resName);
throwExceptionIfSDKTooHigh();
throwExceptionIfScriptCUnsupported();
return rs.nScriptCCreate(resName, RenderScript.getCachePath(), bitcode, bitcode.length);
}
}

0 comments on commit 82b0838

Please sign in to comment.