Merge "Remove the usage of device_config flag: DisplayManagerService.KEY_ALLOW_ALWAYS_UNLOCKED_VIRTUAL_DISPLAYS." into tm-dev

This commit is contained in:
TreeHugger Robot
2022-05-03 19:29:34 +00:00
committed by Android (Google) Code Review
3 changed files with 0 additions and 103 deletions

View File

@@ -1436,13 +1436,5 @@ public final class DisplayManager {
* @hide
*/
String KEY_HIGH_REFRESH_RATE_BLACKLIST = "high_refresh_rate_blacklist";
/**
* Whether to allow the creation of always unlocked virtual displays by apps having the
* required permissions.
* @hide
*/
String KEY_ALLOW_ALWAYS_UNLOCKED_VIRTUAL_DISPLAYS =
"allow_always_unlocked_virtual_displays";
}
}

View File

@@ -103,8 +103,6 @@ import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.DeviceConfig;
import android.provider.DeviceConfigInterface;
import android.provider.Settings;
import android.sysprop.DisplayProperties;
import android.text.TextUtils;
@@ -406,7 +404,6 @@ public final class DisplayManagerService extends SystemService {
private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>();
private final Injector mInjector;
private final DeviceConfigInterface mDeviceConfig;
// The minimum brightness curve, which guarantess that any brightness curve that dips below it
// is rejected by the system.
@@ -483,7 +480,6 @@ public final class DisplayManagerService extends SystemService {
DisplayManagerService(Context context, Injector injector) {
super(context);
mInjector = injector;
mDeviceConfig = mInjector.getDeviceConfig();
mContext = context;
mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper());
mUiHandler = UiThread.getHandler();
@@ -1332,21 +1328,6 @@ public final class DisplayManagerService extends SystemService {
"Requires ADD_ALWAYS_UNLOCKED_DISPLAY permission to "
+ "create an always unlocked virtual display.");
}
boolean allowedByDeviceConfig = false;
final long token = Binder.clearCallingIdentity();
try {
allowedByDeviceConfig = mDeviceConfig.getBoolean(
DeviceConfig.NAMESPACE_DISPLAY_MANAGER,
DisplayManager.DeviceConfig.KEY_ALLOW_ALWAYS_UNLOCKED_VIRTUAL_DISPLAYS,
false);
} finally {
Binder.restoreCallingIdentity(token);
}
if (!allowedByDeviceConfig) {
Slog.w(TAG, "Ignoring flag VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED "
+ "because it is not allowed by DeviceConfig");
flags &= ~VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED;
}
}
if ((flags & VIRTUAL_DISPLAY_FLAG_TRUSTED) == 0) {
@@ -2562,11 +2543,6 @@ public final class DisplayManagerService extends SystemService {
return DisplayProperties
.debug_allow_non_native_refresh_rate_override().orElse(true);
}
@NonNull
public DeviceConfigInterface getDeviceConfig() {
return DeviceConfigInterface.REAL;
}
}
@VisibleForTesting

View File

@@ -16,7 +16,6 @@
package com.android.server.display;
import static android.Manifest.permission.ADD_ALWAYS_UNLOCKED_DISPLAY;
import static android.Manifest.permission.ADD_TRUSTED_DISPLAY;
import static com.android.server.display.VirtualDisplayAdapter.UNIQUE_ID_PREFIX;
@@ -58,8 +57,6 @@ import android.os.IBinder;
import android.os.MessageQueue;
import android.os.Process;
import android.platform.test.annotations.Presubmit;
import android.provider.DeviceConfig;
import android.provider.DeviceConfigInterface;
import android.view.Display;
import android.view.DisplayCutout;
import android.view.DisplayEventReceiver;
@@ -67,7 +64,6 @@ import android.view.DisplayInfo;
import android.view.Surface;
import android.view.SurfaceControl;
import androidx.annotation.NonNull;
import androidx.test.InstrumentationRegistry;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.filters.FlakyTest;
@@ -81,7 +77,6 @@ import com.android.server.companion.virtual.VirtualDeviceManagerInternal;
import com.android.server.display.DisplayManagerService.SyncRoot;
import com.android.server.lights.LightsManager;
import com.android.server.sensors.SensorManagerInternal;
import com.android.server.testutils.FakeDeviceConfigInterface;
import com.android.server.wm.WindowManagerInternal;
import com.google.common.collect.ImmutableMap;
@@ -123,7 +118,6 @@ public class DisplayManagerServiceTest {
public TestRule compatChangeRule = new PlatformCompatChangeRule();
private Context mContext;
private FakeDeviceConfigInterface mDeviceConfig;
private final DisplayManagerService.Injector mShortMockedInjector =
new DisplayManagerService.Injector() {
@@ -146,12 +140,6 @@ public class DisplayManagerServiceTest {
return new VirtualDisplayAdapter(syncRoot, context, handler, displayAdapterListener,
(String name, boolean secure) -> mMockDisplayToken);
}
@NonNull
@Override
public DeviceConfigInterface getDeviceConfig() {
return mDeviceConfig;
}
}
private final DisplayManagerService.Injector mBasicInjector = new BasicInjector();
@@ -199,7 +187,6 @@ public class DisplayManagerServiceTest {
VirtualDeviceManagerInternal.class, mMockVirtualDeviceManagerInternal);
mContext = spy(new ContextWrapper(ApplicationProvider.getApplicationContext()));
mDeviceConfig = new FakeDeviceConfigInterface();
// Disable binder caches in this process.
PropertyInvalidatedCache.disableForTestMode();
@@ -660,25 +647,6 @@ public class DisplayManagerServiceTest {
assertEquals(displayManager.getVirtualDisplaySurfaceInternal(mMockAppToken), surface);
}
/**
* Tests that specifying the VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED flag is processed correctly
* when it is allowed by DeviceConfig.
*/
@Test
public void testCreateVirtualDisplay_alwaysUnlockedAllowed() {
testCreateVirtualDisplay_alwaysUnlocked(/*deviceConfigAllows*/ true, /*flagExpected*/ true);
}
/**
* Tests that specifying the VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED flag when DeviceConfig does
* not allow it results in the flag being stripped from the final flags.
*/
@Test
public void testCreateVirtualDisplay_alwaysUnlockedDisallowed() {
testCreateVirtualDisplay_alwaysUnlocked(
/*deviceConfigAllows*/ false, /*flagExpected*/ false);
}
/**
* Tests that specifying VIRTUAL_DISPLAY_FLAG_OWN_DISPLAY_GROUP is allowed when the permission
* ADD_TRUSTED_DISPLAY is granted.
@@ -1198,45 +1166,6 @@ public class DisplayManagerServiceTest {
assertEquals(expectedRefreshRate, displayInfo.getRefreshRate(), 0.01f);
}
private void testCreateVirtualDisplay_alwaysUnlocked(boolean deviceConfigAllows,
boolean flagExpected) {
mDeviceConfig.setProperty(DeviceConfig.NAMESPACE_DISPLAY_MANAGER,
DisplayManager.DeviceConfig.KEY_ALLOW_ALWAYS_UNLOCKED_VIRTUAL_DISPLAYS,
deviceConfigAllows ? "true" : "false", /*makeDefault*/ false);
DisplayManagerService displayManager =
new DisplayManagerService(mContext, mBasicInjector);
registerDefaultDisplays(displayManager);
String uniqueId = "uniqueId --- ALWAYS_UNLOCKED";
int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_DISPLAY_GROUP
| DisplayManager.VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED;
DisplayManagerService.BinderService bs = displayManager.new BinderService();
when(mMockAppToken.asBinder()).thenReturn(mMockAppToken);
when(mContext.checkCallingPermission(ADD_ALWAYS_UNLOCKED_DISPLAY)).thenReturn(
PackageManager.PERMISSION_GRANTED);
when(mContext.checkCallingPermission(ADD_TRUSTED_DISPLAY)).thenReturn(
PackageManager.PERMISSION_GRANTED);
final VirtualDisplayConfig.Builder builder = new VirtualDisplayConfig.Builder(
VIRTUAL_DISPLAY_NAME, 600, 800, 320);
builder.setFlags(flags);
builder.setUniqueId(uniqueId);
int displayId = bs.createVirtualDisplay(builder.build(), mMockAppToken /* callback */,
null /* projection */, null /* virtualDeviceToken */, PACKAGE_NAME);
displayManager.performTraversalInternal(mock(SurfaceControl.Transaction.class));
displayManager.getDisplayHandler().runWithScissors(() -> {}, 0 /* now */);
DisplayDeviceInfo ddi = displayManager.getDisplayDeviceInfoInternal(displayId);
assertNotNull(ddi);
if (flagExpected) {
assertNotEquals(ddi.flags & DisplayDeviceInfo.FLAG_ALWAYS_UNLOCKED, 0);
} else {
assertEquals(ddi.flags & DisplayDeviceInfo.FLAG_ALWAYS_UNLOCKED, 0);
}
}
private int getDisplayIdForDisplayDevice(
DisplayManagerService displayManager,
DisplayManagerService.BinderService displayManagerBinderService,