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

Commit 10656582 authored by Kenneth Ford's avatar Kenneth Ford Committed by Android (Google) Code Review
Browse files

Merge "Use Updated DeviceStateManager API's in DSMService" into main

parents 69a415e8 04d37762
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -9,3 +9,12 @@ flag {
    bug: "293636629"
    is_fixed_read_only: true
}

flag {
    name: "device_state_property_migration"
    is_exported: true
    namespace: "windowing_sdk"
    description: "Client migration to updated DeviceStateManager API's"
    bug: "336640888"
    is_fixed_read_only: true
}
 No newline at end of file
+52 −15
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ package com.android.server.devicestate;
import static android.Manifest.permission.CONTROL_DEVICE_STATE;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.hardware.devicestate.DeviceState.PROPERTY_FEATURE_REAR_DISPLAY;
import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY;
import static android.hardware.devicestate.DeviceState.PROPERTY_POLICY_AVAILABLE_FOR_APP_REQUEST;
import static android.hardware.devicestate.DeviceState.PROPERTY_POLICY_CANCEL_OVERRIDE_REQUESTS;
import static android.hardware.devicestate.DeviceState.PROPERTY_POLICY_CANCEL_WHEN_REQUESTER_NOT_ON_TOP;
import static android.hardware.devicestate.DeviceStateManager.INVALID_DEVICE_STATE_IDENTIFIER;
@@ -47,6 +50,8 @@ import android.hardware.devicestate.DeviceStateManager;
import android.hardware.devicestate.DeviceStateManagerInternal;
import android.hardware.devicestate.IDeviceStateManager;
import android.hardware.devicestate.IDeviceStateManagerCallback;
import android.hardware.devicestate.feature.flags.FeatureFlags;
import android.hardware.devicestate.feature.flags.FeatureFlagsImpl;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
@@ -175,7 +180,7 @@ public final class DeviceStateManagerService extends SystemService {

    private Set<Integer> mDeviceStatesAvailableForAppRequests = new HashSet<>();

    private Set<Integer> mFoldedDeviceStates;
    private Set<Integer> mFoldedDeviceStates = new HashSet<>();

    @Nullable
    private DeviceState mRearDisplayState;
@@ -185,6 +190,9 @@ public final class DeviceStateManagerService extends SystemService {
    @Nullable
    private OverrideRequest mRearDisplayPendingOverrideRequest;

    @NonNull
    private final FeatureFlags mFlags;

    @VisibleForTesting
    interface SystemPropertySetter {
        void setDebugTracingDeviceStateProperty(String value);
@@ -245,6 +253,7 @@ public final class DeviceStateManagerService extends SystemService {
            @NonNull SystemPropertySetter systemPropertySetter) {
        super(context);
        mSystemPropertySetter = systemPropertySetter;
        mFlags = new FeatureFlagsImpl();
        // We use the DisplayThread because this service indirectly drives
        // display (on/off) and window (position) events through its callbacks.
        DisplayThread displayThread = DisplayThread.get();
@@ -270,9 +279,12 @@ public final class DeviceStateManagerService extends SystemService {
        publishBinderService(Context.DEVICE_STATE_SERVICE, mBinderService);
        publishLocalService(DeviceStateManagerInternal.class, new LocalService());

        if (!mFlags.deviceStatePropertyMigration()) {
            synchronized (mLock) {
                readStatesAvailableForRequestFromApps();
                mFoldedDeviceStates = readFoldedStates();
                setRearDisplayStateLocked();
            }
        }

        mActivityTaskManagerInternal.registerScreenObserver(mOverrideRequestScreenObserver);
@@ -461,8 +473,6 @@ public final class DeviceStateManagerService extends SystemService {
            mOverrideRequestController.handleNewSupportedStates(newStateIdentifiers, reason);
            updatePendingStateLocked();

            setRearDisplayStateLocked();

            notifyDeviceStateInfoChangedAsync();

            mHandler.post(this::notifyPolicyIfNeeded);
@@ -838,6 +848,15 @@ public final class DeviceStateManagerService extends SystemService {
            OverrideRequest request = new OverrideRequest(token, callingPid, callingUid,
                    deviceState.get(), flags, OVERRIDE_REQUEST_TYPE_EMULATED_STATE);

            if (mFlags.deviceStatePropertyMigration()) {
                // If we don't have the CONTROL_DEVICE_STATE permission, we want to show the overlay
                if (!hasControlDeviceStatePermission && deviceState.get().hasProperty(
                        PROPERTY_FEATURE_REAR_DISPLAY)) {
                    showRearDisplayEducationalOverlayLocked(request);
                } else {
                    mOverrideRequestController.addRequest(request);
                }
            } else {
                // If we don't have the CONTROL_DEVICE_STATE permission, we want to show the overlay
                if (!hasControlDeviceStatePermission && mRearDisplayState != null
                        && state == mRearDisplayState.getIdentifier()) {
@@ -847,6 +866,7 @@ public final class DeviceStateManagerService extends SystemService {
                }
            }
        }
    }

    /**
     * If we get a request to enter rear display  mode, we need to display an educational
@@ -1034,9 +1054,15 @@ public final class DeviceStateManagerService extends SystemService {

    private boolean isStateAvailableForAppRequests(int state) {
        synchronized (mLock) {
            if (mFlags.deviceStatePropertyMigration()) {
                Optional<DeviceState> deviceState =  getStateLocked(state);
                return deviceState.isPresent() && deviceState.get().hasProperty(
                        PROPERTY_POLICY_AVAILABLE_FOR_APP_REQUEST);
            } else {
                return mDeviceStatesAvailableForAppRequests.contains(state);
            }
        }
    }

    /**
     * Adds device state values that are available to be requested by the top level app.
@@ -1096,10 +1122,21 @@ public final class DeviceStateManagerService extends SystemService {
     */
    @GuardedBy("mLock")
    private boolean isDeviceOpeningLocked(int newBaseState) {
        if (mFlags.deviceStatePropertyMigration()) {
            final DeviceState currentBaseState = mBaseState.orElse(INVALID_DEVICE_STATE);
            final DeviceState newDeviceBaseState = getStateLocked(newBaseState).orElse(
                    INVALID_DEVICE_STATE);

            return currentBaseState.hasProperty(
                    PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY)
                    && !newDeviceBaseState.hasProperty(
                    PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY);
        } else {
            return mBaseState.filter(
                    deviceState -> mFoldedDeviceStates.contains(deviceState.getIdentifier())
                            && !mFoldedDeviceStates.contains(newBaseState)).isPresent();
        }
    }

    private final class DeviceStateProviderListener implements DeviceStateProvider.Listener {
        @IntRange(from = MINIMUM_DEVICE_STATE_IDENTIFIER, to = MAXIMUM_DEVICE_STATE_IDENTIFIER)