Delete getInternalDisplayToken

No longer any uses of getInternalDisplayToken.

Also moved getPhysicalDisplayIds and getPhysicalDisplayToken into system
server to make it harder to use accidentally.

Test: LocalDisplayAdapterTest
Test: SizeCompatTests#testRestartProcessIfVisible
Fixes: 242714168
Change-Id: Id5eb42d5304e6a5d4c39e593bad354ccc04ce294
This commit is contained in:
Chavi Weingarten
2022-09-30 20:52:14 +00:00
parent e1388556f7
commit e2f3337287
11 changed files with 114 additions and 80 deletions

View File

@@ -2886,7 +2886,6 @@ package android.view {
public final class SurfaceControl implements android.os.Parcelable {
ctor public SurfaceControl(@NonNull android.view.SurfaceControl, @NonNull String);
method @NonNull public static android.os.IBinder getInternalDisplayToken();
method public boolean isSameSurface(@NonNull android.view.SurfaceControl);
}

View File

@@ -33,7 +33,7 @@ public abstract class DisplayAddress implements Parcelable {
*
* @param physicalDisplayId A physical display ID.
* @return The {@link Physical} address.
* @see SurfaceControl#getPhysicalDisplayIds
* @see com.android.server.display.DisplayControl#getPhysicalDisplayIds
*/
@NonNull
public static Physical fromPhysicalDisplayId(long physicalDisplayId) {
@@ -83,7 +83,7 @@ public abstract class DisplayAddress implements Parcelable {
* Stable display ID combining port and model.
*
* @return An ID in the range [0, 2^64) interpreted as signed.
* @see SurfaceControl#getPhysicalDisplayIds
* @see com.android.server.display.DisplayControl#getPhysicalDisplayIds
*/
public long getPhysicalDisplayId() {
return mPhysicalDisplayId;

View File

@@ -173,8 +173,6 @@ public final class SurfaceControl implements Parcelable {
private static native boolean nativeClearAnimationFrameStats();
private static native boolean nativeGetAnimationFrameStats(WindowAnimationFrameStats outStats);
private static native long[] nativeGetPhysicalDisplayIds();
private static native IBinder nativeGetPhysicalDisplayToken(long physicalDisplayId);
private static native void nativeSetDisplaySurface(long transactionObj,
IBinder displayToken, long nativeSurfaceObject);
private static native void nativeSetDisplayLayerStack(long transactionObj,
@@ -2034,35 +2032,6 @@ public final class SurfaceControl implements Parcelable {
IVirtualDisplayCallback.Stub.asInterface(displayToken));
}
/**
* @hide
*/
public static long[] getPhysicalDisplayIds() {
return nativeGetPhysicalDisplayIds();
}
/**
* @hide
*/
public static IBinder getPhysicalDisplayToken(long physicalDisplayId) {
return nativeGetPhysicalDisplayToken(physicalDisplayId);
}
/**
* TODO(b/116025192): Remove this stopgap once framework is display-agnostic.
*
* @hide
*/
@TestApi
@NonNull
public static IBinder getInternalDisplayToken() {
final long[] physicalDisplayIds = getPhysicalDisplayIds();
if (physicalDisplayIds.length == 0) {
return null;
}
return getPhysicalDisplayToken(physicalDisplayIds[0]);
}
/**
* Returns whether protected content is supported in GPU composition.
* @hide

View File

@@ -886,34 +886,6 @@ static void nativeSetDestinationFrame(JNIEnv* env, jclass clazz, jlong transacti
transaction->setDestinationFrame(ctrl, crop);
}
static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
jlongArray array = env->NewLongArray(displayIds.size());
if (array == nullptr) {
jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
return nullptr;
}
if (displayIds.empty()) {
return array;
}
jlong* values = env->GetLongArrayElements(array, 0);
for (size_t i = 0; i < displayIds.size(); ++i) {
values[i] = static_cast<jlong>(displayIds[i].value);
}
env->ReleaseLongArrayElements(array, values, 0);
return array;
}
static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
const auto id = DisplayId::fromValue<PhysicalDisplayId>(physicalDisplayId);
if (!id) return nullptr;
sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(*id);
return javaObjectForIBinder(env, token);
}
static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
jobject tokenObj) {
sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
@@ -1992,10 +1964,6 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
(void*)nativeSetFrameRate },
{"nativeSetDefaultFrameRateCompatibility", "(JJI)V",
(void*)nativeSetDefaultFrameRateCompatibility},
{"nativeGetPhysicalDisplayIds", "()[J",
(void*)nativeGetPhysicalDisplayIds },
{"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
(void*)nativeGetPhysicalDisplayToken },
{"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
(void*)nativeSetDisplaySurface },
{"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",

View File

@@ -30,6 +30,8 @@ public class DisplayControl {
private static native IBinder nativeCreateDisplay(String name, boolean secure);
private static native void nativeDestroyDisplay(IBinder displayToken);
private static native void nativeOverrideHdrTypes(IBinder displayToken, int[] modes);
private static native long[] nativeGetPhysicalDisplayIds();
private static native IBinder nativeGetPhysicalDisplayToken(long physicalDisplayId);
/**
* Create a display in SurfaceFlinger.
@@ -63,4 +65,18 @@ public class DisplayControl {
public static void overrideHdrTypes(@NonNull IBinder displayToken, @NonNull int[] modes) {
nativeOverrideHdrTypes(displayToken, modes);
}
/**
* Gets all the physical display ids.
*/
public static long[] getPhysicalDisplayIds() {
return nativeGetPhysicalDisplayIds();
}
/**
* Gets the display's token from the physical display id
*/
public static IBinder getPhysicalDisplayToken(long physicalDisplayId) {
return nativeGetPhysicalDisplayToken(physicalDisplayId);
}
}

View File

@@ -1456,8 +1456,8 @@ public final class DisplayManagerService extends SystemService {
// Register default display adapters.
synchronized (mSyncRoot) {
// main display adapter
registerDisplayAdapterLocked(new LocalDisplayAdapter(
mSyncRoot, mContext, mHandler, mDisplayDeviceRepo));
registerDisplayAdapterLocked(mInjector.getLocalDisplayAdapter(mSyncRoot, mContext,
mHandler, mDisplayDeviceRepo));
// Standalone VR devices rely on a virtual display as their primary display for
// 2D UI. We register virtual display adapter along side the main display adapter
@@ -2515,6 +2515,11 @@ public final class DisplayManagerService extends SystemService {
return new VirtualDisplayAdapter(syncRoot, context, handler, displayAdapterListener);
}
LocalDisplayAdapter getLocalDisplayAdapter(SyncRoot syncRoot, Context context,
Handler handler, DisplayAdapter.Listener displayAdapterListener) {
return new LocalDisplayAdapter(syncRoot, context, handler, displayAdapterListener);
}
long getDefaultDisplayDelayTimeout() {
return WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT;
}

View File

@@ -1390,17 +1390,17 @@ final class LocalDisplayAdapter extends DisplayAdapter {
}
@VisibleForTesting
static class SurfaceControlProxy {
public static class SurfaceControlProxy {
public SurfaceControl.DynamicDisplayInfo getDynamicDisplayInfo(IBinder token) {
return SurfaceControl.getDynamicDisplayInfo(token);
}
public long[] getPhysicalDisplayIds() {
return SurfaceControl.getPhysicalDisplayIds();
return DisplayControl.getPhysicalDisplayIds();
}
public IBinder getPhysicalDisplayToken(long physicalDisplayId) {
return SurfaceControl.getPhysicalDisplayToken(physicalDisplayId);
return DisplayControl.getPhysicalDisplayToken(physicalDisplayId);
}
public SurfaceControl.StaticDisplayInfo getStaticDisplayInfo(IBinder displayToken) {

View File

@@ -56,6 +56,7 @@ import android.window.ScreenCapture;
import com.android.internal.R;
import com.android.internal.protolog.common.ProtoLog;
import com.android.server.display.DisplayControl;
import com.android.server.wm.SurfaceAnimator.AnimationType;
import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
import com.android.server.wm.utils.RotationAnimationUtils;
@@ -177,7 +178,7 @@ class ScreenRotationAnimation {
}
final DisplayAddress.Physical physicalAddress =
(DisplayAddress.Physical) address;
final IBinder displayToken = SurfaceControl.getPhysicalDisplayToken(
final IBinder displayToken = DisplayControl.getPhysicalDisplayToken(
physicalAddress.getPhysicalDisplayId());
if (displayToken == null) {
Slog.e(TAG, "Display token is null.");

View File

@@ -55,6 +55,28 @@ static void nativeOverrideHdrTypes(JNIEnv* env, jclass clazz, jobject tokenObjec
}
}
static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
ScopedLongArrayRW values(env, env->NewLongArray(displayIds.size()));
if (values.get() == nullptr) {
jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
return nullptr;
}
for (size_t i = 0; i < displayIds.size(); ++i) {
values[i] = static_cast<jlong>(displayIds[i].value);
}
return values.getJavaArray();
}
static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
const auto id = DisplayId::fromValue<PhysicalDisplayId>(physicalDisplayId);
if (!id) return nullptr;
sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(*id);
return javaObjectForIBinder(env, token);
}
// ----------------------------------------------------------------------------
static const JNINativeMethod sDisplayMethods[] = {
@@ -65,6 +87,10 @@ static const JNINativeMethod sDisplayMethods[] = {
(void*)nativeDestroyDisplay },
{"nativeOverrideHdrTypes", "(Landroid/os/IBinder;[I)V",
(void*)nativeOverrideHdrTypes },
{"nativeGetPhysicalDisplayIds", "()[J",
(void*)nativeGetPhysicalDisplayIds },
{"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
(void*)nativeGetPhysicalDisplayToken },
// clang-format on
};

View File

@@ -27,6 +27,7 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -128,20 +129,44 @@ public class DisplayManagerServiceTest {
return mMockVirtualDisplayAdapter;
}
@Override
LocalDisplayAdapter getLocalDisplayAdapter(SyncRoot syncRoot, Context context,
Handler handler, DisplayAdapter.Listener displayAdapterListener) {
return new LocalDisplayAdapter(syncRoot, context, handler,
displayAdapterListener, new LocalDisplayAdapter.Injector() {
@Override
public LocalDisplayAdapter.SurfaceControlProxy getSurfaceControlProxy() {
return mSurfaceControlProxy;
}
});
}
@Override
long getDefaultDisplayDelayTimeout() {
return SHORT_DEFAULT_DISPLAY_TIMEOUT_MILLIS;
}
};
class BasicInjector extends DisplayManagerService.Injector {
@Override
VirtualDisplayAdapter getVirtualDisplayAdapter(SyncRoot syncRoot, Context context,
Handler handler, DisplayAdapter.Listener displayAdapterListener) {
return new VirtualDisplayAdapter(syncRoot, context, handler, displayAdapterListener,
(String name, boolean secure) -> mMockDisplayToken);
}
}
class BasicInjector extends DisplayManagerService.Injector {
@Override
VirtualDisplayAdapter getVirtualDisplayAdapter(SyncRoot syncRoot, Context context,
Handler handler, DisplayAdapter.Listener displayAdapterListener) {
return new VirtualDisplayAdapter(syncRoot, context, handler, displayAdapterListener,
(String name, boolean secure) -> mMockDisplayToken);
}
@Override
LocalDisplayAdapter getLocalDisplayAdapter(SyncRoot syncRoot, Context context,
Handler handler, DisplayAdapter.Listener displayAdapterListener) {
return new LocalDisplayAdapter(syncRoot, context, handler,
displayAdapterListener, new LocalDisplayAdapter.Injector() {
@Override
public LocalDisplayAdapter.SurfaceControlProxy getSurfaceControlProxy() {
return mSurfaceControlProxy;
}
});
}
}
private final DisplayManagerService.Injector mBasicInjector = new BasicInjector();
@@ -168,6 +193,7 @@ public class DisplayManagerServiceTest {
@Mock WindowManagerInternal mMockWindowManagerInternal;
@Mock LightsManager mMockLightsManager;
@Mock VirtualDisplayAdapter mMockVirtualDisplayAdapter;
@Mock LocalDisplayAdapter.SurfaceControlProxy mSurfaceControlProxy;
@Mock IBinder mMockDisplayToken;
@Mock SensorManagerInternal mMockSensorManagerInternal;
@@ -191,6 +217,28 @@ public class DisplayManagerServiceTest {
// Disable binder caches in this process.
PropertyInvalidatedCache.disableForTestMode();
setUpDisplay();
}
private void setUpDisplay() {
long[] ids = new long[] {100};
when(mSurfaceControlProxy.getPhysicalDisplayIds()).thenReturn(ids);
when(mSurfaceControlProxy.getPhysicalDisplayToken(anyLong()))
.thenReturn(mMockDisplayToken);
SurfaceControl.StaticDisplayInfo staticDisplayInfo = new SurfaceControl.StaticDisplayInfo();
staticDisplayInfo.isInternal = true;
when(mSurfaceControlProxy.getStaticDisplayInfo(mMockDisplayToken))
.thenReturn(staticDisplayInfo);
SurfaceControl.DynamicDisplayInfo dynamicDisplayMode =
new SurfaceControl.DynamicDisplayInfo();
SurfaceControl.DisplayMode displayMode = new SurfaceControl.DisplayMode();
displayMode.width = 100;
displayMode.height = 200;
dynamicDisplayMode.supportedDisplayModes = new SurfaceControl.DisplayMode[] {displayMode};
when(mSurfaceControlProxy.getDynamicDisplayInfo(mMockDisplayToken))
.thenReturn(dynamicDisplayMode);
when(mSurfaceControlProxy.getDesiredDisplayModeSpecs(mMockDisplayToken))
.thenReturn(new SurfaceControl.DesiredDisplayModeSpecs());
}
@Test

View File

@@ -79,6 +79,7 @@ import com.android.server.LockGuard;
import com.android.server.UiThread;
import com.android.server.Watchdog;
import com.android.server.am.ActivityManagerService;
import com.android.server.display.DisplayControl;
import com.android.server.display.color.ColorDisplayService;
import com.android.server.firewall.IntentFirewall;
import com.android.server.input.InputManagerService;
@@ -177,6 +178,7 @@ public class SystemServicesTestRule implements TestRule {
.mockStatic(LocalServices.class, spyStubOnly)
.mockStatic(DeviceConfig.class, spyStubOnly)
.mockStatic(SurfaceControl.class, mockStubOnly)
.mockStatic(DisplayControl.class, mockStubOnly)
.mockStatic(LockGuard.class, mockStubOnly)
.mockStatic(Watchdog.class, mockStubOnly)
.strictness(Strictness.LENIENT)