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

Commit 51a1afe4 authored by Christian Göllner's avatar Christian Göllner Committed by Android (Google) Code Review
Browse files

Merge "Preserve shade state on fold/unfold."

parents 06425229 ab7ad3e8
Loading
Loading
Loading
Loading
+57 −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 com.android.systemui.statusbar.phone

import android.content.Context
import android.hardware.devicestate.DeviceStateManager.DeviceStateCallback
import com.android.internal.R

/**
 * Listens for fold state changes and reports the new folded state together with other properties
 * associated with that state.
 */
internal class FoldStateListener(
    context: Context,
    private val listener: OnFoldStateChangeListener
) : DeviceStateCallback {

    internal interface OnFoldStateChangeListener {
        /**
         * Reports that the device either became folded or unfolded.
         *
         * @param folded whether the device is folded.
         * @param willGoToSleep whether the device will go to sleep and keep the screen off.
         */
        fun onFoldStateChanged(folded: Boolean, willGoToSleep: Boolean)
    }

    private val foldedDeviceStates: IntArray =
        context.resources.getIntArray(R.array.config_foldedDeviceStates)
    private val goToSleepDeviceStates: IntArray =
        context.resources.getIntArray(R.array.config_deviceStatesOnWhichToSleep)

    private var wasFolded: Boolean? = null

    override fun onStateChanged(state: Int) {
        val isFolded = foldedDeviceStates.contains(state)
        if (wasFolded == isFolded) {
            return
        }
        wasFolded = isFolded
        val willGoToSleep = goToSleepDeviceStates.contains(state)
        listener.onFoldStateChanged(isFolded, willGoToSleep)
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -55,6 +55,9 @@ public interface ShadeController {
     */
    boolean closeShadeIfOpen();

    /** Returns whether the shade is currently open or opening. */
    boolean isShadeOpen();

    /**
     * Add a runnable for NotificationPanelView to post when the panel is expanded.
     *
+7 −0
Original line number Diff line number Diff line
@@ -147,6 +147,13 @@ public class ShadeControllerImpl implements ShadeController {
        return false;
    }

    @Override
    public boolean isShadeOpen() {
        NotificationPanelViewController controller =
                getNotificationPanelViewController();
        return controller.isExpanding() || controller.isFullyExpanded();
    }

    @Override
    public void postOnShadeExpanded(Runnable executable) {
        getNotificationPanelViewController().addOnGlobalLayoutListener(
+27 −1
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.graphics.Point;
import android.graphics.PointF;
import android.hardware.devicestate.DeviceStateManager;
import android.metrics.LogMaker;
import android.net.Uri;
import android.os.Bundle;
@@ -779,7 +780,8 @@ public class StatusBar extends CoreStartable implements
            Optional<StartingSurface> startingSurfaceOptional,
            ActivityLaunchAnimator activityLaunchAnimator,
            NotifPipelineFlags notifPipelineFlags,
            InteractionJankMonitor jankMonitor) {
            InteractionJankMonitor jankMonitor,
            DeviceStateManager deviceStateManager) {
        super(context);
        mNotificationsController = notificationsController;
        mFragmentService = fragmentService;
@@ -902,6 +904,9 @@ public class StatusBar extends CoreStartable implements
                data -> mCommandQueueCallbacks.animateExpandSettingsPanel(data.mSubpanel));
        mMessageRouter.subscribeTo(MSG_LAUNCH_TRANSITION_TIMEOUT,
                id -> onLaunchTransitionTimeout());

        deviceStateManager.registerCallback(mMainExecutor,
                new FoldStateListener(mContext, this::onFoldedStateChanged));
    }

    @Override
@@ -1100,6 +1105,27 @@ public class StatusBar extends CoreStartable implements
                                requestTopUi, componentTag))));
    }

    private void onFoldedStateChanged(boolean isFolded, boolean willGoToSleep) {
        // Folded state changes are followed by a screen off event.
        // By default turning off the screen also closes the shade.
        // We want to make sure that the shade status is kept after
        // folding/unfolding.
        boolean isShadeOpen = mShadeController.isShadeOpen();
        boolean leaveOpen = isShadeOpen && !willGoToSleep;
        if (DEBUG) {
            Log.d(TAG, String.format(
                    "#onFoldedStateChanged(): "
                            + "isFolded=%s, "
                            + "willGoToSleep=%s, "
                            + "isShadeOpen=%s, "
                            + "leaveOpen=%s",
                    isFolded, willGoToSleep, isShadeOpen, leaveOpen));
        }
        if (leaveOpen) {
            mStatusBarStateController.setLeaveOpenOnKeyguardHide(true);
        }
    }

    // ================================================================================
    // Constructing the view
    // ================================================================================
+5 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.systemui.Dependency.TIME_TICK_HANDLER_NAME;

import android.app.WallpaperManager;
import android.content.Context;
import android.hardware.devicestate.DeviceStateManager;
import android.os.Handler;
import android.os.PowerManager;
import android.util.DisplayMetrics;
@@ -231,7 +232,8 @@ public interface StatusBarPhoneModule {
            Optional<StartingSurface> startingSurfaceOptional,
            ActivityLaunchAnimator activityLaunchAnimator,
            NotifPipelineFlags notifPipelineFlags,
            InteractionJankMonitor jankMonitor) {
            InteractionJankMonitor jankMonitor,
            DeviceStateManager deviceStateManager) {
        return new StatusBar(
                context,
                notificationsController,
@@ -327,7 +329,8 @@ public interface StatusBarPhoneModule {
                startingSurfaceOptional,
                activityLaunchAnimator,
                notifPipelineFlags,
                jankMonitor
                jankMonitor,
                deviceStateManager
        );
    }
}
Loading