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

Commit e17dd704 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski Committed by Android (Google) Code Review
Browse files

Merge "Hidden API to get virtual device policy for a specific display." into main

parents ed33457d 17e9150a
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -103,6 +103,11 @@ interface IVirtualDeviceManager {
     */
    int getDevicePolicy(int deviceId, int policyType);

    /**
     * Returns the device policy for the given display ID and policy type.
     */
    int getDevicePolicyForDisplayId(int displayId, int policyType);

    /**
     * Returns device-specific session id for playback, or AUDIO_SESSION_ID_GENERATE
     * if there's none.
+25 −0
Original line number Diff line number Diff line
@@ -377,6 +377,31 @@ public final class VirtualDeviceManager {
        }
    }

    /**
     * Returns the device policy for the display with the given ID and the given policy type.
     *
     * <p>In case the display does not exist or is not owned by a virtual device,
     * {@link VirtualDeviceParams#DEVICE_POLICY_DEFAULT} is returned.
     *
     * @hide
     */
    public @VirtualDeviceParams.DevicePolicy int getDevicePolicyForDisplayId(
            int displayId, @VirtualDeviceParams.PolicyType int policyType) {
        if (displayId == Context.DEVICE_ID_DEFAULT) {
            // Avoid unnecessary binder call, for default display, policy will be always default.
            return VirtualDeviceParams.DEVICE_POLICY_DEFAULT;
        }
        if (mService == null) {
            Log.w(TAG, "Failed to retrieve device policy; no virtual device manager service.");
            return VirtualDeviceParams.DEVICE_POLICY_DEFAULT;
        }
        try {
            return mService.getDevicePolicyForDisplayId(displayId, policyType);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns the ID of the device which owns the display with the given ID.
     *
+6 −0
Original line number Diff line number Diff line
@@ -239,6 +239,12 @@ public class GenericWindowPolicyController extends DisplayWindowPolicyController
        }
    }

    boolean isActivityLaunchAllowedByDefault() {
        synchronized (mGenericWindowPolicyControllerLock) {
            return mActivityLaunchAllowedByDefault;
        }
    }

    void setActivityLaunchDefaultAllowed(boolean activityLaunchDefaultAllowed) {
        synchronized (mGenericWindowPolicyControllerLock) {
            if (mActivityLaunchAllowedByDefault != activityLaunchDefaultAllowed) {
+19 −0
Original line number Diff line number Diff line
@@ -605,6 +605,25 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
        }
    }

    public @VirtualDeviceParams.DevicePolicy int getDevicePolicyForDisplayId(
            int displayId, @VirtualDeviceParams.PolicyType int policyType) {
        synchronized (mVirtualDeviceLock) {
            switch (policyType) {
                case POLICY_TYPE_RECENTS:
                    return mVirtualDisplays.get(displayId).getWindowPolicyController()
                            .canShowTasksInHostDeviceRecents()
                            ? DEVICE_POLICY_DEFAULT : DEVICE_POLICY_CUSTOM;
                case POLICY_TYPE_ACTIVITY:
                    return mVirtualDisplays.get(displayId).getWindowPolicyController()
                            .isActivityLaunchAllowedByDefault()
                            ? DEVICE_POLICY_DEFAULT : DEVICE_POLICY_CUSTOM;
                default:
                    // fallback to device-level policy
                    return mDevicePolicies.get(policyType, DEVICE_POLICY_DEFAULT);
            }
        }
    }

    /** Returns device-specific audio session id for playback. */
    public int getAudioPlaybackSessionId() {
        return mParams.getAudioPlaybackSessionId();
+17 −0
Original line number Diff line number Diff line
@@ -567,6 +567,23 @@ public class VirtualDeviceManagerService extends SystemService {
            return virtualDevice.getDevicePolicy(policyType);
        }

        @Override // Binder call
        @VirtualDeviceParams.DevicePolicy
        public int getDevicePolicyForDisplayId(int displayId,
            @VirtualDeviceParams.PolicyType int policyType) {
            final int deviceId = getDeviceIdForDisplayId(displayId);
            if (deviceId == Context.DEVICE_ID_DEFAULT) {
                return DEVICE_POLICY_DEFAULT;
            }
            VirtualDeviceImpl virtualDevice = getVirtualDeviceForId(deviceId);
            // Do not return DEVICE_POLICY_INVALID here, because the display may exist but not
            // owned by any virtual device, just like the default display.
            if (virtualDevice == null) {
                return DEVICE_POLICY_DEFAULT;
            }
            return virtualDevice.getDevicePolicyForDisplayId(displayId, policyType);
        }

        @Override // Binder call
        public int getDeviceIdForDisplayId(int displayId) {
            if (displayId == Display.INVALID_DISPLAY || displayId == Display.DEFAULT_DISPLAY) {
Loading