Loading core/java/android/hardware/devicestate/DeviceStateManager.java +33 −0 Original line number Diff line number Diff line Loading @@ -24,7 +24,10 @@ import android.annotation.SystemService; import android.annotation.TestApi; import android.content.Context; import com.android.internal.util.ArrayUtils; import java.util.concurrent.Executor; import java.util.function.Consumer; /** * Manages the state of the system for devices with user-configurable hardware like a foldable Loading Loading @@ -170,4 +173,34 @@ public final class DeviceStateManager { */ void onStateChanged(int state); } /** * Listens to changes in device state and reports the state as folded if the device state * matches the value in the {@link com.android.internal.R.integer.config_foldedDeviceState} * resource. * @hide */ public static class FoldStateListener implements DeviceStateCallback { private final int[] mFoldedDeviceStates; private final Consumer<Boolean> mDelegate; @Nullable private Boolean lastResult; public FoldStateListener(Context context, Consumer<Boolean> listener) { mFoldedDeviceStates = context.getResources().getIntArray( com.android.internal.R.array.config_foldedDeviceStates); mDelegate = listener; } @Override public final void onStateChanged(int state) { final boolean folded = ArrayUtils.contains(mFoldedDeviceStates, state); if (lastResult == null || !lastResult.equals(folded)) { lastResult = folded; mDelegate.accept(folded); } } } } services/core/java/com/android/server/policy/DisplayFoldController.java +2 −27 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.content.Context; import android.graphics.Rect; import android.hardware.ICameraService; import android.hardware.devicestate.DeviceStateManager; import android.hardware.devicestate.DeviceStateManager.FoldStateListener; import android.hardware.display.DisplayManagerInternal; import android.os.Handler; import android.os.HandlerExecutor; Loading Loading @@ -75,7 +76,7 @@ class DisplayFoldController { DeviceStateManager deviceStateManager = context.getSystemService(DeviceStateManager.class); deviceStateManager.registerCallback(new HandlerExecutor(handler), new DeviceStateListener(context)); new FoldStateListener(context, folded -> setDeviceFolded(folded))); } void finishedGoingToSleep() { Loading Loading @@ -202,30 +203,4 @@ class DisplayFoldController { return new DisplayFoldController(context, windowManagerService, displayService, cameraServiceProxy, displayId, foldedArea, DisplayThread.getHandler()); } /** * Listens to changes in device state and reports the state as folded if the device state * matches the value in the {@link com.android.internal.R.integer.config_foldedDeviceState} * resource. */ private class DeviceStateListener implements DeviceStateManager.DeviceStateCallback { private final int[] mFoldedDeviceStates; DeviceStateListener(Context context) { mFoldedDeviceStates = context.getResources().getIntArray( com.android.internal.R.array.config_foldedDeviceStates); } @Override public void onStateChanged(int deviceState) { boolean folded = false; for (int i = 0; i < mFoldedDeviceStates.length; i++) { if (deviceState == mFoldedDeviceStates[i]) { folded = true; break; } } setDeviceFolded(folded); } } } Loading
core/java/android/hardware/devicestate/DeviceStateManager.java +33 −0 Original line number Diff line number Diff line Loading @@ -24,7 +24,10 @@ import android.annotation.SystemService; import android.annotation.TestApi; import android.content.Context; import com.android.internal.util.ArrayUtils; import java.util.concurrent.Executor; import java.util.function.Consumer; /** * Manages the state of the system for devices with user-configurable hardware like a foldable Loading Loading @@ -170,4 +173,34 @@ public final class DeviceStateManager { */ void onStateChanged(int state); } /** * Listens to changes in device state and reports the state as folded if the device state * matches the value in the {@link com.android.internal.R.integer.config_foldedDeviceState} * resource. * @hide */ public static class FoldStateListener implements DeviceStateCallback { private final int[] mFoldedDeviceStates; private final Consumer<Boolean> mDelegate; @Nullable private Boolean lastResult; public FoldStateListener(Context context, Consumer<Boolean> listener) { mFoldedDeviceStates = context.getResources().getIntArray( com.android.internal.R.array.config_foldedDeviceStates); mDelegate = listener; } @Override public final void onStateChanged(int state) { final boolean folded = ArrayUtils.contains(mFoldedDeviceStates, state); if (lastResult == null || !lastResult.equals(folded)) { lastResult = folded; mDelegate.accept(folded); } } } }
services/core/java/com/android/server/policy/DisplayFoldController.java +2 −27 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.content.Context; import android.graphics.Rect; import android.hardware.ICameraService; import android.hardware.devicestate.DeviceStateManager; import android.hardware.devicestate.DeviceStateManager.FoldStateListener; import android.hardware.display.DisplayManagerInternal; import android.os.Handler; import android.os.HandlerExecutor; Loading Loading @@ -75,7 +76,7 @@ class DisplayFoldController { DeviceStateManager deviceStateManager = context.getSystemService(DeviceStateManager.class); deviceStateManager.registerCallback(new HandlerExecutor(handler), new DeviceStateListener(context)); new FoldStateListener(context, folded -> setDeviceFolded(folded))); } void finishedGoingToSleep() { Loading Loading @@ -202,30 +203,4 @@ class DisplayFoldController { return new DisplayFoldController(context, windowManagerService, displayService, cameraServiceProxy, displayId, foldedArea, DisplayThread.getHandler()); } /** * Listens to changes in device state and reports the state as folded if the device state * matches the value in the {@link com.android.internal.R.integer.config_foldedDeviceState} * resource. */ private class DeviceStateListener implements DeviceStateManager.DeviceStateCallback { private final int[] mFoldedDeviceStates; DeviceStateListener(Context context) { mFoldedDeviceStates = context.getResources().getIntArray( com.android.internal.R.array.config_foldedDeviceStates); } @Override public void onStateChanged(int deviceState) { boolean folded = false; for (int i = 0; i < mFoldedDeviceStates.length; i++) { if (deviceState == mFoldedDeviceStates[i]) { folded = true; break; } } setDeviceFolded(folded); } } }