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

Commit aca03a17 authored by Naomi Musgrave's avatar Naomi Musgrave
Browse files

[2/n] Display stack provides DisplayInfos

For all possible states a device can assume, the DisplayManagerService
provides the DisplayInfo associated with that layout of the logical
display. WindowManager applies each possible rotation to these
DisplayInfo. This, in turn, is used to calculate the possible max
WindowMetrics on the device.

Done:
* Display stack builds collection of DisplayInfo, for all
 possible display states (folded, unfolded on jumbo)
* Display stack pushing set of DisplayInfos to WindowManager
* WindowManager calculates max bounds for all possible
  (display layouts x rotations)

Not started:
* WindowManager calculates insets for each rotation

Bug: 181127261
Test: atest DeviceStateManagerGlobalTest
Test: atest DeviceStateManagerServiceTest
Test: atest LogicalDisplayMapperTest
Change-Id: I3a407262e755cb57c506b7255eb5c067523381d3
parent a77d117f
Loading
Loading
Loading
Loading
+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();
}
+9 −0
Original line number Diff line number Diff line
@@ -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.
@@ -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.
     *
+2 −2
Original line number Diff line number Diff line
@@ -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.
+12 −7
Original line number Diff line number Diff line
@@ -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;
@@ -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
@@ -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()];
@@ -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();
            }
        }
    }
}
+53 −4
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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;

@@ -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);
        }
@@ -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