From 42f9a2fbbd754bcfe4d91db739f6f7aeea2069a7 Mon Sep 17 00:00:00 2001 From: Ady Abraham Date: Tue, 26 Feb 2019 14:13:39 -0800 Subject: [PATCH] SurfaceControl: add getAllowedDisplayConfigs expose ISurfaceComposer::getAllowedDisplayConfigs to SurfaceControl. Test: manual test to call getAllowedDisplayConfigs() from SurfaceControl observe config change. Bug: 122905403 Change-Id: I0587ac5ed2eb29788c2ce941d9c54ebfd215ddf9 --- core/java/android/view/SurfaceControl.java | 11 ++++++++++ core/jni/android_view_SurfaceControl.cpp | 25 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index ea7f31dd85070..3768acaaaad5f 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -160,6 +160,7 @@ public final class SurfaceControl implements Parcelable { private static native boolean nativeSetActiveConfig(IBinder displayToken, int id); private static native boolean nativeSetAllowedDisplayConfigs(IBinder displayToken, int[] allowedConfigs); + private static native int[] nativeGetAllowedDisplayConfigs(IBinder displayToken); private static native int[] nativeGetDisplayColorModes(IBinder displayToken); private static native SurfaceControl.DisplayPrimaries nativeGetDisplayNativePrimaries( IBinder displayToken); @@ -1535,6 +1536,16 @@ public final class SurfaceControl implements Parcelable { return nativeSetAllowedDisplayConfigs(displayToken, allowedConfigs); } + /** + * @hide + */ + public static int[] getAllowedDisplayConfigs(IBinder displayToken) { + if (displayToken == null) { + throw new IllegalArgumentException("displayToken must not be null"); + } + return nativeGetAllowedDisplayConfigs(displayToken); + } + /** * @hide */ diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index 4c25fd465301e..af2bf2d40146a 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -717,6 +717,29 @@ static jboolean nativeSetAllowedDisplayConfigs(JNIEnv* env, jclass clazz, return result == NO_ERROR ? JNI_TRUE : JNI_FALSE; } +static jintArray nativeGetAllowedDisplayConfigs(JNIEnv* env, jclass clazz, jobject tokenObj) { + sp token(ibinderForJavaObject(env, tokenObj)); + if (token == nullptr) return JNI_FALSE; + + std::vector allowedConfigs; + size_t result = SurfaceComposerClient::getAllowedDisplayConfigs(token, &allowedConfigs); + if (result != NO_ERROR) { + return nullptr; + } + + jintArray allowedConfigsArray = env->NewIntArray(allowedConfigs.size()); + if (allowedConfigsArray == nullptr) { + jniThrowException(env, "java/lang/OutOfMemoryError", NULL); + return nullptr; + } + jint* allowedConfigsArrayValues = env->GetIntArrayElements(allowedConfigsArray, 0); + for (size_t i = 0; i < allowedConfigs.size(); i++) { + allowedConfigsArrayValues[i] = static_cast(allowedConfigs[i]); + } + env->ReleaseIntArrayElements(allowedConfigsArray, allowedConfigsArrayValues, 0); + return allowedConfigsArray; +} + static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) { sp token(ibinderForJavaObject(env, tokenObj)); if (token == NULL) return -1; @@ -1215,6 +1238,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = { (void*)nativeSetActiveConfig }, {"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z", (void*)nativeSetAllowedDisplayConfigs }, + {"nativeGetAllowedDisplayConfigs", "(Landroid/os/IBinder;)[I", + (void*)nativeGetAllowedDisplayConfigs }, {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I", (void*)nativeGetDisplayColorModes}, {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",