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

Commit 022be6f3 authored by Robert Horvath's avatar Robert Horvath Committed by Android (Google) Code Review
Browse files

Merge "Move InattentiveSleepWarningController callbacks to PowerUI"

parents ae14fc9f 121e0256
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -281,7 +281,6 @@
        <item>com.android.systemui.statusbar.phone.StatusBar</item>
        <item>com.android.systemui.usb.StorageNotification</item>
        <item>com.android.systemui.power.PowerUI</item>
        <item>com.android.systemui.power.InattentiveSleepWarningController</item>
        <item>com.android.systemui.media.RingtonePlayer</item>
        <item>com.android.systemui.keyboard.KeyboardUI</item>
        <item>com.android.systemui.pip.PipUI</item>
+0 −8
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.systemui.biometrics.AuthController;
import com.android.systemui.globalactions.GlobalActionsComponent;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.pip.PipUI;
import com.android.systemui.power.InattentiveSleepWarningController;
import com.android.systemui.power.PowerUI;
import com.android.systemui.recents.Recents;
import com.android.systemui.recents.RecentsModule;
@@ -103,13 +102,6 @@ public abstract class SystemUIBinder {
    @ClassKey(PowerUI.class)
    public abstract SystemUI bindPowerUI(PowerUI sysui);

    /** Inject into InattentiveSleepWarningController. */
    @Binds
    @IntoMap
    @ClassKey(InattentiveSleepWarningController.class)
    public abstract SystemUI bindInattentiveSleepWarningController(
            InattentiveSleepWarningController sysui);

    /** Inject into Recents. */
    @Binds
    @IntoMap
+0 −62
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.power;

import android.content.Context;

import com.android.systemui.SystemUI;
import com.android.systemui.statusbar.CommandQueue;

import javax.inject.Inject;
import javax.inject.Singleton;

/**
 * Receives messages sent from {@link com.android.server.power.InattentiveSleepWarningController}
 * and shows the appropriate inattentive sleep UI (e.g. {@link InattentiveSleepWarningView}).
 */
@Singleton
public class InattentiveSleepWarningController extends SystemUI implements CommandQueue.Callbacks {
    private final CommandQueue mCommandQueue;
    private InattentiveSleepWarningView mOverlayView;

    @Inject
    public InattentiveSleepWarningController(Context context, CommandQueue commandQueue) {
        super(context);
        mCommandQueue = commandQueue;
    }

    @Override
    public void start() {
        mCommandQueue.addCallback(this);
    }

    @Override
    public void showInattentiveSleepWarning() {
        if (mOverlayView == null) {
            mOverlayView = new InattentiveSleepWarningView(mContext);
        }

        mOverlayView.show();
    }

    @Override
    public void dismissInattentiveSleepWarning(boolean animated) {
        if (mOverlayView != null) {
            mOverlayView.dismiss(animated);
        }
    }
}
+23 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.SystemUI;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.phone.StatusBar;

import java.io.FileDescriptor;
@@ -60,7 +61,7 @@ import javax.inject.Singleton;
import dagger.Lazy;

@Singleton
public class PowerUI extends SystemUI {
public class PowerUI extends SystemUI implements CommandQueue.Callbacks {

    static final String TAG = "PowerUI";
    static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -80,6 +81,7 @@ public class PowerUI extends SystemUI {

    private PowerManager mPowerManager;
    private WarningsUI mWarnings;
    private InattentiveSleepWarningView mOverlayView;
    private final Configuration mLastConfiguration = new Configuration();
    private int mPlugType = 0;
    private int mInvalidCharger = 0;
@@ -105,13 +107,15 @@ public class PowerUI extends SystemUI {
    private IThermalEventListener mSkinThermalEventListener;
    private IThermalEventListener mUsbThermalEventListener;
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final CommandQueue mCommandQueue;
    private final Lazy<StatusBar> mStatusBarLazy;

    @Inject
    public PowerUI(Context context, BroadcastDispatcher broadcastDispatcher,
            Lazy<StatusBar> statusBarLazy) {
            CommandQueue commandQueue, Lazy<StatusBar> statusBarLazy) {
        super(context);
        mBroadcastDispatcher = broadcastDispatcher;
        mCommandQueue = commandQueue;
        mStatusBarLazy = statusBarLazy;
    }

@@ -162,6 +166,7 @@ public class PowerUI extends SystemUI {
                    }
                });
        initThermalEventListeners();
        mCommandQueue.addCallback(this);
    }

    @Override
@@ -581,6 +586,22 @@ public class PowerUI extends SystemUI {
        }
    }

    @Override
    public void showInattentiveSleepWarning() {
        if (mOverlayView == null) {
            mOverlayView = new InattentiveSleepWarningView(mContext);
        }

        mOverlayView.show();
    }

    @Override
    public void dismissInattentiveSleepWarning(boolean animated) {
        if (mOverlayView != null) {
            mOverlayView.dismiss(animated);
        }
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.print("mLowBatteryAlertCloseLevel=");
        pw.println(mLowBatteryAlertCloseLevel);
+3 −1
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.power.PowerUI.WarningsUI;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.phone.StatusBar;

import org.junit.Before;
@@ -87,6 +88,7 @@ public class PowerUITest extends SysuiTestCase {
    private IThermalEventListener mUsbThermalEventListener;
    private IThermalEventListener mSkinThermalEventListener;
    @Mock private BroadcastDispatcher mBroadcastDispatcher;
    @Mock private CommandQueue mCommandQueue;
    @Mock private Lazy<StatusBar> mStatusBarLazy;
    @Mock private StatusBar mStatusBar;

@@ -686,7 +688,7 @@ public class PowerUITest extends SysuiTestCase {
    }

    private void createPowerUi() {
        mPowerUI = new PowerUI(mContext, mBroadcastDispatcher, mStatusBarLazy);
        mPowerUI = new PowerUI(mContext, mBroadcastDispatcher, mCommandQueue, mStatusBarLazy);
        mPowerUI.mThermalService = mThermalServiceMock;
    }