Loading libs/WindowManager/Jetpack/src/androidx/window/extensions/area/WindowAreaComponentImpl.java +66 −33 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ package androidx.window.extensions.area; import static android.hardware.devicestate.DeviceState.PROPERTY_FEATURE_DUAL_DISPLAY_INTERNAL_DEFAULT; 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.DeviceStateManager.INVALID_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateManager.INVALID_DEVICE_STATE_IDENTIFIER; import android.app.Activity; Loading @@ -23,6 +27,7 @@ import android.content.Context; import android.hardware.devicestate.DeviceState; import android.hardware.devicestate.DeviceStateManager; import android.hardware.devicestate.DeviceStateRequest; import android.hardware.devicestate.feature.flags.Flags; import android.hardware.display.DisplayManager; import android.util.ArraySet; import android.util.DisplayMetrics; Loading Loading @@ -72,18 +77,18 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, @GuardedBy("mLock") private final ArraySet<Consumer<ExtensionWindowAreaStatus>> mRearDisplayPresentationStatusListeners = new ArraySet<>(); private final int mRearDisplayState; private int mRearDisplayState = INVALID_DEVICE_STATE_IDENTIFIER; private final int mConcurrentDisplayState; @NonNull private final int[] mFoldedDeviceStates; private int[] mFoldedDeviceStates = new int[0]; private long mRearDisplayAddress = INVALID_DISPLAY_ADDRESS; @WindowAreaSessionState private int mRearDisplaySessionStatus = WindowAreaComponent.SESSION_STATE_INACTIVE; @GuardedBy("mLock") private int mCurrentDeviceState = INVALID_DEVICE_STATE_IDENTIFIER; private DeviceState mCurrentDeviceState = INVALID_DEVICE_STATE; @GuardedBy("mLock") private int[] mCurrentSupportedDeviceStates; private List<DeviceState> mCurrentSupportedDeviceStates; @GuardedBy("mLock") private DeviceStateRequest mRearDisplayStateRequest; Loading @@ -103,16 +108,25 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, mDisplayManager = context.getSystemService(DisplayManager.class); mExecutor = context.getMainExecutor(); // TODO(b/329436166): Update the usage of device state manager API's mCurrentSupportedDeviceStates = getSupportedStateIdentifiers( mDeviceStateManager.getSupportedDeviceStates()); mCurrentSupportedDeviceStates = mDeviceStateManager.getSupportedDeviceStates(); if (Flags.deviceStatePropertyMigration()) { for (int i = 0; i < mCurrentSupportedDeviceStates.size(); i++) { DeviceState state = mCurrentSupportedDeviceStates.get(i); if (state.hasProperty(PROPERTY_FEATURE_REAR_DISPLAY)) { mRearDisplayState = state.getIdentifier(); break; } } } else { mFoldedDeviceStates = context.getResources().getIntArray( R.array.config_foldedDeviceStates); // TODO(b/236022708) Move rear display state to device state config file mRearDisplayState = context.getResources().getInteger( R.integer.config_deviceStateRearDisplay); } // TODO(b/374351956) Use DeviceState API when the dual display state is always returned mConcurrentDisplayState = context.getResources().getInteger( R.integer.config_deviceStateConcurrentRearDisplay); Loading Loading @@ -147,7 +161,7 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, mRearDisplayStatusListeners.add(consumer); // If current device state is still invalid, the initial value has not been provided. if (mCurrentDeviceState == INVALID_DEVICE_STATE_IDENTIFIER) { if (mCurrentDeviceState.getIdentifier() == INVALID_DEVICE_STATE_IDENTIFIER) { return; } consumer.accept(getCurrentRearDisplayModeStatus()); Loading Loading @@ -312,7 +326,7 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, mRearDisplayPresentationStatusListeners.add(consumer); // If current device state is still invalid, the initial value has not been provided if (mCurrentDeviceState == INVALID_DEVICE_STATE_IDENTIFIER) { if (mCurrentDeviceState.getIdentifier() == INVALID_DEVICE_STATE_IDENTIFIER) { return; } @WindowAreaStatus int currentStatus = getCurrentRearDisplayPresentationModeStatus(); Loading Loading @@ -452,8 +466,7 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, @Override public void onSupportedStatesChanged(@NonNull List<DeviceState> supportedStates) { synchronized (mLock) { // TODO(b/329436166): Update the usage of device state manager API's mCurrentSupportedDeviceStates = getSupportedStateIdentifiers(supportedStates); mCurrentSupportedDeviceStates = supportedStates; updateRearDisplayStatusListeners(getCurrentRearDisplayModeStatus()); updateRearDisplayPresentationStatusListeners( getCurrentRearDisplayPresentationModeStatus()); Loading @@ -463,8 +476,7 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, @Override public void onDeviceStateChanged(@NonNull DeviceState state) { synchronized (mLock) { // TODO(b/329436166): Update the usage of device state manager API's mCurrentDeviceState = state.getIdentifier(); mCurrentDeviceState = state; updateRearDisplayStatusListeners(getCurrentRearDisplayModeStatus()); updateRearDisplayPresentationStatusListeners( getCurrentRearDisplayPresentationModeStatus()); Loading @@ -477,7 +489,8 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, return WindowAreaComponent.STATUS_UNSUPPORTED; } if (!ArrayUtils.contains(mCurrentSupportedDeviceStates, mRearDisplayState)) { if (!deviceStateListContainsIdentifier(mCurrentSupportedDeviceStates, mRearDisplayState)) { return WindowAreaComponent.STATUS_UNAVAILABLE; } Loading @@ -488,15 +501,6 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, return WindowAreaComponent.STATUS_AVAILABLE; } // TODO(b/329436166): Remove and update the usage of device state manager API's private int[] getSupportedStateIdentifiers(@NonNull List<DeviceState> states) { int[] identifiers = new int[states.size()]; for (int i = 0; i < states.size(); i++) { identifiers[i] = states.get(i).getIdentifier(); } return identifiers; } /** * Helper method to determine if a rear display session is currently active by checking * if the current device state is that which corresponds to {@code mRearDisplayState}. Loading @@ -505,7 +509,31 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, */ @GuardedBy("mLock") private boolean isRearDisplayActive() { return mCurrentDeviceState == mRearDisplayState; if (Flags.deviceStatePropertyApi()) { return mCurrentDeviceState.hasProperty(PROPERTY_FEATURE_REAR_DISPLAY); } else { return mCurrentDeviceState.getIdentifier() == mRearDisplayState; } } @GuardedBy("mLock") private boolean isRearDisplayPresentationModeActive() { if (Flags.deviceStatePropertyApi()) { return mCurrentDeviceState.hasProperty(PROPERTY_FEATURE_DUAL_DISPLAY_INTERNAL_DEFAULT); } else { return mCurrentDeviceState.getIdentifier() == mConcurrentDisplayState; } } @GuardedBy("mLock") private boolean deviceStateListContainsIdentifier(List<DeviceState> deviceStates, int identifier) { for (int i = 0; i < deviceStates.size(); i++) { if (deviceStates.get(i).getIdentifier() == identifier) { return true; } } return false; } @GuardedBy("mLock") Loading @@ -526,12 +554,12 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, return WindowAreaComponent.STATUS_UNSUPPORTED; } if (mCurrentDeviceState == mConcurrentDisplayState) { if (isRearDisplayPresentationModeActive()) { return WindowAreaComponent.STATUS_ACTIVE; } if (!ArrayUtils.contains(mCurrentSupportedDeviceStates, mConcurrentDisplayState) || isDeviceFolded()) { if (!deviceStateListContainsIdentifier(mCurrentSupportedDeviceStates, mConcurrentDisplayState) || isDeviceFolded()) { return WindowAreaComponent.STATUS_UNAVAILABLE; } return WindowAreaComponent.STATUS_AVAILABLE; Loading @@ -539,7 +567,12 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, @GuardedBy("mLock") private boolean isDeviceFolded() { return ArrayUtils.contains(mFoldedDeviceStates, mCurrentDeviceState); if (Flags.deviceStatePropertyApi()) { return mCurrentDeviceState.hasProperty( PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY); } else { return ArrayUtils.contains(mFoldedDeviceStates, mCurrentDeviceState.getIdentifier()); } } @GuardedBy("mLock") Loading Loading
libs/WindowManager/Jetpack/src/androidx/window/extensions/area/WindowAreaComponentImpl.java +66 −33 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ package androidx.window.extensions.area; import static android.hardware.devicestate.DeviceState.PROPERTY_FEATURE_DUAL_DISPLAY_INTERNAL_DEFAULT; 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.DeviceStateManager.INVALID_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateManager.INVALID_DEVICE_STATE_IDENTIFIER; import android.app.Activity; Loading @@ -23,6 +27,7 @@ import android.content.Context; import android.hardware.devicestate.DeviceState; import android.hardware.devicestate.DeviceStateManager; import android.hardware.devicestate.DeviceStateRequest; import android.hardware.devicestate.feature.flags.Flags; import android.hardware.display.DisplayManager; import android.util.ArraySet; import android.util.DisplayMetrics; Loading Loading @@ -72,18 +77,18 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, @GuardedBy("mLock") private final ArraySet<Consumer<ExtensionWindowAreaStatus>> mRearDisplayPresentationStatusListeners = new ArraySet<>(); private final int mRearDisplayState; private int mRearDisplayState = INVALID_DEVICE_STATE_IDENTIFIER; private final int mConcurrentDisplayState; @NonNull private final int[] mFoldedDeviceStates; private int[] mFoldedDeviceStates = new int[0]; private long mRearDisplayAddress = INVALID_DISPLAY_ADDRESS; @WindowAreaSessionState private int mRearDisplaySessionStatus = WindowAreaComponent.SESSION_STATE_INACTIVE; @GuardedBy("mLock") private int mCurrentDeviceState = INVALID_DEVICE_STATE_IDENTIFIER; private DeviceState mCurrentDeviceState = INVALID_DEVICE_STATE; @GuardedBy("mLock") private int[] mCurrentSupportedDeviceStates; private List<DeviceState> mCurrentSupportedDeviceStates; @GuardedBy("mLock") private DeviceStateRequest mRearDisplayStateRequest; Loading @@ -103,16 +108,25 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, mDisplayManager = context.getSystemService(DisplayManager.class); mExecutor = context.getMainExecutor(); // TODO(b/329436166): Update the usage of device state manager API's mCurrentSupportedDeviceStates = getSupportedStateIdentifiers( mDeviceStateManager.getSupportedDeviceStates()); mCurrentSupportedDeviceStates = mDeviceStateManager.getSupportedDeviceStates(); if (Flags.deviceStatePropertyMigration()) { for (int i = 0; i < mCurrentSupportedDeviceStates.size(); i++) { DeviceState state = mCurrentSupportedDeviceStates.get(i); if (state.hasProperty(PROPERTY_FEATURE_REAR_DISPLAY)) { mRearDisplayState = state.getIdentifier(); break; } } } else { mFoldedDeviceStates = context.getResources().getIntArray( R.array.config_foldedDeviceStates); // TODO(b/236022708) Move rear display state to device state config file mRearDisplayState = context.getResources().getInteger( R.integer.config_deviceStateRearDisplay); } // TODO(b/374351956) Use DeviceState API when the dual display state is always returned mConcurrentDisplayState = context.getResources().getInteger( R.integer.config_deviceStateConcurrentRearDisplay); Loading Loading @@ -147,7 +161,7 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, mRearDisplayStatusListeners.add(consumer); // If current device state is still invalid, the initial value has not been provided. if (mCurrentDeviceState == INVALID_DEVICE_STATE_IDENTIFIER) { if (mCurrentDeviceState.getIdentifier() == INVALID_DEVICE_STATE_IDENTIFIER) { return; } consumer.accept(getCurrentRearDisplayModeStatus()); Loading Loading @@ -312,7 +326,7 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, mRearDisplayPresentationStatusListeners.add(consumer); // If current device state is still invalid, the initial value has not been provided if (mCurrentDeviceState == INVALID_DEVICE_STATE_IDENTIFIER) { if (mCurrentDeviceState.getIdentifier() == INVALID_DEVICE_STATE_IDENTIFIER) { return; } @WindowAreaStatus int currentStatus = getCurrentRearDisplayPresentationModeStatus(); Loading Loading @@ -452,8 +466,7 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, @Override public void onSupportedStatesChanged(@NonNull List<DeviceState> supportedStates) { synchronized (mLock) { // TODO(b/329436166): Update the usage of device state manager API's mCurrentSupportedDeviceStates = getSupportedStateIdentifiers(supportedStates); mCurrentSupportedDeviceStates = supportedStates; updateRearDisplayStatusListeners(getCurrentRearDisplayModeStatus()); updateRearDisplayPresentationStatusListeners( getCurrentRearDisplayPresentationModeStatus()); Loading @@ -463,8 +476,7 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, @Override public void onDeviceStateChanged(@NonNull DeviceState state) { synchronized (mLock) { // TODO(b/329436166): Update the usage of device state manager API's mCurrentDeviceState = state.getIdentifier(); mCurrentDeviceState = state; updateRearDisplayStatusListeners(getCurrentRearDisplayModeStatus()); updateRearDisplayPresentationStatusListeners( getCurrentRearDisplayPresentationModeStatus()); Loading @@ -477,7 +489,8 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, return WindowAreaComponent.STATUS_UNSUPPORTED; } if (!ArrayUtils.contains(mCurrentSupportedDeviceStates, mRearDisplayState)) { if (!deviceStateListContainsIdentifier(mCurrentSupportedDeviceStates, mRearDisplayState)) { return WindowAreaComponent.STATUS_UNAVAILABLE; } Loading @@ -488,15 +501,6 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, return WindowAreaComponent.STATUS_AVAILABLE; } // TODO(b/329436166): Remove and update the usage of device state manager API's private int[] getSupportedStateIdentifiers(@NonNull List<DeviceState> states) { int[] identifiers = new int[states.size()]; for (int i = 0; i < states.size(); i++) { identifiers[i] = states.get(i).getIdentifier(); } return identifiers; } /** * Helper method to determine if a rear display session is currently active by checking * if the current device state is that which corresponds to {@code mRearDisplayState}. Loading @@ -505,7 +509,31 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, */ @GuardedBy("mLock") private boolean isRearDisplayActive() { return mCurrentDeviceState == mRearDisplayState; if (Flags.deviceStatePropertyApi()) { return mCurrentDeviceState.hasProperty(PROPERTY_FEATURE_REAR_DISPLAY); } else { return mCurrentDeviceState.getIdentifier() == mRearDisplayState; } } @GuardedBy("mLock") private boolean isRearDisplayPresentationModeActive() { if (Flags.deviceStatePropertyApi()) { return mCurrentDeviceState.hasProperty(PROPERTY_FEATURE_DUAL_DISPLAY_INTERNAL_DEFAULT); } else { return mCurrentDeviceState.getIdentifier() == mConcurrentDisplayState; } } @GuardedBy("mLock") private boolean deviceStateListContainsIdentifier(List<DeviceState> deviceStates, int identifier) { for (int i = 0; i < deviceStates.size(); i++) { if (deviceStates.get(i).getIdentifier() == identifier) { return true; } } return false; } @GuardedBy("mLock") Loading @@ -526,12 +554,12 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, return WindowAreaComponent.STATUS_UNSUPPORTED; } if (mCurrentDeviceState == mConcurrentDisplayState) { if (isRearDisplayPresentationModeActive()) { return WindowAreaComponent.STATUS_ACTIVE; } if (!ArrayUtils.contains(mCurrentSupportedDeviceStates, mConcurrentDisplayState) || isDeviceFolded()) { if (!deviceStateListContainsIdentifier(mCurrentSupportedDeviceStates, mConcurrentDisplayState) || isDeviceFolded()) { return WindowAreaComponent.STATUS_UNAVAILABLE; } return WindowAreaComponent.STATUS_AVAILABLE; Loading @@ -539,7 +567,12 @@ public class WindowAreaComponentImpl implements WindowAreaComponent, @GuardedBy("mLock") private boolean isDeviceFolded() { return ArrayUtils.contains(mFoldedDeviceStates, mCurrentDeviceState); if (Flags.deviceStatePropertyApi()) { return mCurrentDeviceState.hasProperty( PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY); } else { return ArrayUtils.contains(mFoldedDeviceStates, mCurrentDeviceState.getIdentifier()); } } @GuardedBy("mLock") Loading