Loading core/java/android/hardware/devicestate/DeviceStateManagerInternal.java 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.hardware.devicestate; /** * Device state manager local system service interface. * * @hide Only for use within the system server. */ public abstract class DeviceStateManagerInternal { /** Returns the list of currently supported device state identifiers. */ public abstract int[] getSupportedStateIdentifiers(); } core/java/android/hardware/display/DisplayManagerInternal.java +9 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.List; import java.util.Objects; import java.util.Set; /** * Display manager local system service interface. Loading Loading @@ -128,6 +129,14 @@ public abstract class DisplayManagerInternal { */ public abstract DisplayInfo getDisplayInfo(int displayId); /** * Returns a set of DisplayInfo, for the states that may be assumed by either the given display, * or any other display within that display's group. * * @param displayId The logical display id to fetch DisplayInfo for. */ public abstract Set<DisplayInfo> getPossibleDisplayInfo(int displayId); /** * Returns the position of the display's projection. * Loading core/java/android/view/WindowManagerImpl.java +2 −2 Original line number Diff line number Diff line Loading @@ -374,8 +374,8 @@ public final class WindowManagerImpl implements WindowManager { currentDisplayInfo = possibleDisplayInfos.get(i); // Calculate max bounds for this rotation and state. Rect maxBounds = new Rect(0, 0, currentDisplayInfo.getNaturalWidth(), currentDisplayInfo.getNaturalHeight()); Rect maxBounds = new Rect(0, 0, currentDisplayInfo.logicalWidth, currentDisplayInfo.logicalHeight); // Calculate insets for the rotated max bounds. // TODO(181127261) calculate insets for each display rotation and state. Loading services/core/java/com/android/server/devicestate/DeviceStateManagerService.java +12 −7 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.annotation.Nullable; import android.content.Context; import android.hardware.devicestate.DeviceStateInfo; import android.hardware.devicestate.DeviceStateManager; import android.hardware.devicestate.DeviceStateManagerInternal; import android.hardware.devicestate.IDeviceStateManager; import android.hardware.devicestate.IDeviceStateManagerCallback; import android.os.Binder; Loading Loading @@ -161,6 +162,7 @@ public final class DeviceStateManagerService extends SystemService { @Override public void onStart() { publishBinderService(Context.DEVICE_STATE_SERVICE, mBinderService); publishLocalService(DeviceStateManagerInternal.class, new LocalService()); } @VisibleForTesting Loading Loading @@ -239,13 +241,6 @@ public final class DeviceStateManagerService extends SystemService { } } /** Returns the list of currently supported device state identifiers. */ private int[] getSupportedStateIdentifiers() { synchronized (mLock) { return getSupportedStateIdentifiersLocked(); } } /** Returns the list of currently supported device state identifiers. */ private int[] getSupportedStateIdentifiersLocked() { int[] supportedStates = new int[mDeviceStates.size()]; Loading Loading @@ -848,4 +843,14 @@ public final class DeviceStateManagerService extends SystemService { } } } /** Implementation of {@link DeviceStateManagerInternal} published as a local service. */ private final class LocalService extends DeviceStateManagerInternal { @Override public int[] getSupportedStateIdentifiers() { synchronized (mLock) { return getSupportedStateIdentifiersLocked(); } } } } services/core/java/com/android/server/display/DisplayManagerService.java +53 −4 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import android.graphics.Point; import android.hardware.Sensor; import android.hardware.SensorManager; import android.hardware.devicestate.DeviceStateManager; import android.hardware.devicestate.DeviceStateManagerInternal; import android.hardware.display.AmbientBrightnessDayStats; import android.hardware.display.BrightnessChangeEvent; import android.hardware.display.BrightnessConfiguration; Loading Loading @@ -131,6 +132,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Consumer; Loading Loading @@ -210,6 +212,7 @@ public final class DisplayManagerService extends SystemService { private WindowManagerInternal mWindowManagerInternal; private InputManagerInternal mInputManagerInternal; private IMediaProjectionManager mProjectionService; private DeviceStateManagerInternal mDeviceStateManager; private int[] mUserDisabledHdrTypes = {}; private boolean mAreUserDisabledHdrTypesAllowed = true; Loading Loading @@ -557,10 +560,9 @@ public final class DisplayManagerService extends SystemService { mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); DeviceStateManager deviceStateManager = mContext.getSystemService(DeviceStateManager.class); deviceStateManager.registerCallback(new HandlerExecutor(mHandler), new DeviceStateListener()); mDeviceStateManager = LocalServices.getService(DeviceStateManagerInternal.class); mContext.getSystemService(DeviceStateManager.class).registerCallback( new HandlerExecutor(mHandler), new DeviceStateListener()); scheduleTraversalLocked(false); } Loading Loading @@ -3273,6 +3275,53 @@ public final class DisplayManagerService extends SystemService { return getDisplayInfoInternal(displayId, Process.myUid()); } @Override public Set<DisplayInfo> getPossibleDisplayInfo(int displayId) { synchronized (mSyncRoot) { // Retrieve the group associated with this display id. final int displayGroupId = mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(displayId); if (displayGroupId == Display.INVALID_DISPLAY_GROUP) { Slog.w(TAG, "Can't get possible display info since display group for " + displayId + " does not exist"); return new ArraySet<>(); } // Assume any display in this group can be swapped out for the given display id. Set<DisplayInfo> possibleInfo = new ArraySet<>(); final DisplayGroup group = mLogicalDisplayMapper.getDisplayGroupLocked( displayGroupId); for (int i = 0; i < group.getSizeLocked(); i++) { final int id = group.getIdLocked(i); final LogicalDisplay logical = mLogicalDisplayMapper.getDisplayLocked(id); if (logical == null) { Slog.w(TAG, "Can't get possible display info since logical display for " + "display id " + id + " does not exist, as part of group " + displayGroupId); } else { possibleInfo.add(logical.getDisplayInfoLocked()); } } // For the supported device states, retrieve the DisplayInfos for the logical // display layout. if (mDeviceStateManager == null) { Slog.w(TAG, "Can't get supported states since DeviceStateManager not ready"); } else { final int[] supportedStates = mDeviceStateManager.getSupportedStateIdentifiers(); for (int state : supportedStates) { possibleInfo.addAll( mLogicalDisplayMapper.getDisplayInfoForStateLocked(state, displayId, displayGroupId)); } } return possibleInfo; } } @Override public Point getDisplayPosition(int displayId) { synchronized (mSyncRoot) { Loading Loading
core/java/android/hardware/devicestate/DeviceStateManagerInternal.java 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.hardware.devicestate; /** * Device state manager local system service interface. * * @hide Only for use within the system server. */ public abstract class DeviceStateManagerInternal { /** Returns the list of currently supported device state identifiers. */ public abstract int[] getSupportedStateIdentifiers(); }
core/java/android/hardware/display/DisplayManagerInternal.java +9 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.List; import java.util.Objects; import java.util.Set; /** * Display manager local system service interface. Loading Loading @@ -128,6 +129,14 @@ public abstract class DisplayManagerInternal { */ public abstract DisplayInfo getDisplayInfo(int displayId); /** * Returns a set of DisplayInfo, for the states that may be assumed by either the given display, * or any other display within that display's group. * * @param displayId The logical display id to fetch DisplayInfo for. */ public abstract Set<DisplayInfo> getPossibleDisplayInfo(int displayId); /** * Returns the position of the display's projection. * Loading
core/java/android/view/WindowManagerImpl.java +2 −2 Original line number Diff line number Diff line Loading @@ -374,8 +374,8 @@ public final class WindowManagerImpl implements WindowManager { currentDisplayInfo = possibleDisplayInfos.get(i); // Calculate max bounds for this rotation and state. Rect maxBounds = new Rect(0, 0, currentDisplayInfo.getNaturalWidth(), currentDisplayInfo.getNaturalHeight()); Rect maxBounds = new Rect(0, 0, currentDisplayInfo.logicalWidth, currentDisplayInfo.logicalHeight); // Calculate insets for the rotated max bounds. // TODO(181127261) calculate insets for each display rotation and state. Loading
services/core/java/com/android/server/devicestate/DeviceStateManagerService.java +12 −7 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.annotation.Nullable; import android.content.Context; import android.hardware.devicestate.DeviceStateInfo; import android.hardware.devicestate.DeviceStateManager; import android.hardware.devicestate.DeviceStateManagerInternal; import android.hardware.devicestate.IDeviceStateManager; import android.hardware.devicestate.IDeviceStateManagerCallback; import android.os.Binder; Loading Loading @@ -161,6 +162,7 @@ public final class DeviceStateManagerService extends SystemService { @Override public void onStart() { publishBinderService(Context.DEVICE_STATE_SERVICE, mBinderService); publishLocalService(DeviceStateManagerInternal.class, new LocalService()); } @VisibleForTesting Loading Loading @@ -239,13 +241,6 @@ public final class DeviceStateManagerService extends SystemService { } } /** Returns the list of currently supported device state identifiers. */ private int[] getSupportedStateIdentifiers() { synchronized (mLock) { return getSupportedStateIdentifiersLocked(); } } /** Returns the list of currently supported device state identifiers. */ private int[] getSupportedStateIdentifiersLocked() { int[] supportedStates = new int[mDeviceStates.size()]; Loading Loading @@ -848,4 +843,14 @@ public final class DeviceStateManagerService extends SystemService { } } } /** Implementation of {@link DeviceStateManagerInternal} published as a local service. */ private final class LocalService extends DeviceStateManagerInternal { @Override public int[] getSupportedStateIdentifiers() { synchronized (mLock) { return getSupportedStateIdentifiersLocked(); } } } }
services/core/java/com/android/server/display/DisplayManagerService.java +53 −4 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import android.graphics.Point; import android.hardware.Sensor; import android.hardware.SensorManager; import android.hardware.devicestate.DeviceStateManager; import android.hardware.devicestate.DeviceStateManagerInternal; import android.hardware.display.AmbientBrightnessDayStats; import android.hardware.display.BrightnessChangeEvent; import android.hardware.display.BrightnessConfiguration; Loading Loading @@ -131,6 +132,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Consumer; Loading Loading @@ -210,6 +212,7 @@ public final class DisplayManagerService extends SystemService { private WindowManagerInternal mWindowManagerInternal; private InputManagerInternal mInputManagerInternal; private IMediaProjectionManager mProjectionService; private DeviceStateManagerInternal mDeviceStateManager; private int[] mUserDisabledHdrTypes = {}; private boolean mAreUserDisabledHdrTypesAllowed = true; Loading Loading @@ -557,10 +560,9 @@ public final class DisplayManagerService extends SystemService { mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); DeviceStateManager deviceStateManager = mContext.getSystemService(DeviceStateManager.class); deviceStateManager.registerCallback(new HandlerExecutor(mHandler), new DeviceStateListener()); mDeviceStateManager = LocalServices.getService(DeviceStateManagerInternal.class); mContext.getSystemService(DeviceStateManager.class).registerCallback( new HandlerExecutor(mHandler), new DeviceStateListener()); scheduleTraversalLocked(false); } Loading Loading @@ -3273,6 +3275,53 @@ public final class DisplayManagerService extends SystemService { return getDisplayInfoInternal(displayId, Process.myUid()); } @Override public Set<DisplayInfo> getPossibleDisplayInfo(int displayId) { synchronized (mSyncRoot) { // Retrieve the group associated with this display id. final int displayGroupId = mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(displayId); if (displayGroupId == Display.INVALID_DISPLAY_GROUP) { Slog.w(TAG, "Can't get possible display info since display group for " + displayId + " does not exist"); return new ArraySet<>(); } // Assume any display in this group can be swapped out for the given display id. Set<DisplayInfo> possibleInfo = new ArraySet<>(); final DisplayGroup group = mLogicalDisplayMapper.getDisplayGroupLocked( displayGroupId); for (int i = 0; i < group.getSizeLocked(); i++) { final int id = group.getIdLocked(i); final LogicalDisplay logical = mLogicalDisplayMapper.getDisplayLocked(id); if (logical == null) { Slog.w(TAG, "Can't get possible display info since logical display for " + "display id " + id + " does not exist, as part of group " + displayGroupId); } else { possibleInfo.add(logical.getDisplayInfoLocked()); } } // For the supported device states, retrieve the DisplayInfos for the logical // display layout. if (mDeviceStateManager == null) { Slog.w(TAG, "Can't get supported states since DeviceStateManager not ready"); } else { final int[] supportedStates = mDeviceStateManager.getSupportedStateIdentifiers(); for (int state : supportedStates) { possibleInfo.addAll( mLogicalDisplayMapper.getDisplayInfoForStateLocked(state, displayId, displayGroupId)); } } return possibleInfo; } } @Override public Point getDisplayPosition(int displayId) { synchronized (mSyncRoot) { Loading