Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0fce6f21 authored by Zixuan Qu's avatar Zixuan Qu
Browse files

Remove the usage of device_config flag:...

Remove the usage of device_config flag: DisplayManagerService.KEY_ALLOW_ALWAYS_UNLOCKED_VIRTUAL_DISPLAYS.

Test:  atest  DisplayManagerServiceTest
Bug: 227384335
Change-Id: I125761acfd6f91a362484abacd6bc92cdfbd9a52
parent c170d9ad
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -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";
    }
}
+0 −24
Original line number Diff line number Diff line
@@ -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
+0 −71
Original line number Diff line number Diff line
@@ -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;
@@ -56,8 +55,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;
@@ -65,7 +62,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;
@@ -78,7 +74,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;
@@ -119,7 +114,6 @@ public class DisplayManagerServiceTest {
    public TestRule compatChangeRule = new PlatformCompatChangeRule();

    private Context mContext;
    private FakeDeviceConfigInterface mDeviceConfig;

    private final DisplayManagerService.Injector mShortMockedInjector =
            new DisplayManagerService.Injector() {
@@ -142,12 +136,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();
@@ -195,7 +183,6 @@ public class DisplayManagerServiceTest {
                VirtualDeviceManagerInternal.class, mMockVirtualDeviceManagerInternal);

        mContext = spy(new ContextWrapper(ApplicationProvider.getApplicationContext()));
        mDeviceConfig = new FakeDeviceConfigInterface();

        // Disable binder caches in this process.
        PropertyInvalidatedCache.disableForTestMode();
@@ -648,25 +635,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.
@@ -1186,45 +1154,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,