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

Commit a2186c9f authored by Anthony Hugh's avatar Anthony Hugh Committed by Android (Google) Code Review
Browse files

Merge "Delete SwitchToGuestTimer"

parents 58b75389 39f0e4cd
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -20,11 +20,6 @@
    <!-- Full screen user switcher column number TODO: move to support library-->
    <integer name="user_fullscreen_switcher_num_col">3</integer>

    <!-- Number of milliseconds user can spend driving with the keyguard up. After that, we switch to Guest. -->
    <!-- If the number is negative, the feature is disabled.
         If it's zero, we switch to guest immediately as we start driving. -->
    <integer name="driving_on_keyguard_timeout_ms">-1</integer>

    <!--Percentage of the screen height, from the bottom, that a notification panel being
    partially closed at will result in it remaining open if released-->
    <integer name="notification_settle_open_percentage">20</integer>
+0 −28
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.animation.ValueAnimator;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.car.Car;
import android.car.drivingstate.CarDrivingStateEvent;
import android.car.drivingstate.CarUxRestrictionsManager;
import android.car.hardware.power.CarPowerManager.CarPowerStateListener;
import android.content.Context;
@@ -179,10 +178,8 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
    private final CarServiceProvider mCarServiceProvider;

    private DeviceProvisionedController mDeviceProvisionedController;
    private DrivingStateHelper mDrivingStateHelper;
    private PowerManagerHelper mPowerManagerHelper;
    private FlingAnimationUtils mFlingAnimationUtils;
    private SwitchToGuestTimer mSwitchToGuestTimer;
    private NotificationDataManager mNotificationDataManager;
    private NotificationClickHandlerFactory mNotificationClickHandlerFactory;
    private ScreenLifecycle mScreenLifecycle;
@@ -440,15 +437,6 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
        createBatteryController();
        mCarBatteryController.startListening();

        // Used by onDrivingStateChanged and it can be called inside
        // DrivingStateHelper.connectToCarService()
        mSwitchToGuestTimer = new SwitchToGuestTimer(mContext);

        // Register a listener for driving state changes.
        mDrivingStateHelper = mDrivingStateHelperLazy.get();
        mDrivingStateHelper.setCarDrivingStateEventListener(this::onDrivingStateChanged);
        mDrivingStateHelper.connectToCarService();

        mPowerManagerHelper = mPowerManagerHelperLazy.get();
        mPowerManagerHelper.setCarPowerStateListener(mCarPowerStateListener);
        mPowerManagerHelper.connectToCarService();
@@ -914,20 +902,6 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
        }
    }

    private void onDrivingStateChanged(CarDrivingStateEvent notUsed) {
        // Check if we need to start the timer every time driving state changes.
        startSwitchToGuestTimerIfDrivingOnKeyguard();
    }

    private void startSwitchToGuestTimerIfDrivingOnKeyguard() {
        if (mDrivingStateHelper.isCurrentlyDriving() && mState != StatusBarState.SHADE) {
            // We're driving while keyguard is up.
            mSwitchToGuestTimer.start();
        } else {
            mSwitchToGuestTimer.cancel();
        }
    }

    @Override
    protected void createUserSwitcher() {
        UserSwitcherController userSwitcherController =
@@ -953,8 +927,6 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
    public void onStateChanged(int newState) {
        super.onStateChanged(newState);

        startSwitchToGuestTimerIfDrivingOnKeyguard();

        if (newState != StatusBarState.FULLSCREEN_USER_SWITCHER) {
            hideUserSwitcher();
        } else {
+0 −116
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.car;

import android.car.userlib.CarUserManagerHelper;
import android.content.Context;
import android.os.CountDownTimer;
import android.util.Log;

import androidx.annotation.GuardedBy;

import com.android.systemui.R;

/**
 * Wrapper for a countdown timer that switches to Guest if the user has been driving with
 * the keyguard up for configurable number of seconds.
 */
public class SwitchToGuestTimer {
    private static final String TAG = "SwitchToGuestTimer";

    // After how many ms CountdownTimer.onTick gets triggered.
    private static final int COUNTDOWN_INTERVAL_MS = 1000;

    private final CarUserManagerHelper mCarUserManagerHelper;
    private final Object mTimerLock;
    private final String mGuestName;
    private final int mTimeoutMs;
    private final boolean mEnabled;

    @GuardedBy("mTimerLock")
    private CountDownTimer mSwitchToGuestTimer;

    public SwitchToGuestTimer(Context context) {
        mCarUserManagerHelper = new CarUserManagerHelper(context);
        mGuestName = context.getResources().getString(R.string.car_guest);
        mTimeoutMs = context.getResources().getInteger(R.integer.driving_on_keyguard_timeout_ms);

        // Lock prevents multiple timers being started.
        mTimerLock = new Object();

        // If milliseconds to switch is a negative number, the feature is disabled.
        mEnabled = mTimeoutMs >= 0;
    }

    /**
     * Starts the timer if it's not already running.
     */
    public void start() {
        if (!mEnabled) {
            logD("Switching to guest after driving on keyguard is disabled.");
            return;
        }

        synchronized (mTimerLock) {
            if (mSwitchToGuestTimer != null) {
                logD("Timer is already running.");
                return;
            }

            mSwitchToGuestTimer = new CountDownTimer(mTimeoutMs, COUNTDOWN_INTERVAL_MS) {
                @Override
                public void onTick(long msUntilFinished) {
                    logD("Ms until switching to guest: " + Long.toString(msUntilFinished));
                }

                @Override
                public void onFinish() {
                    mCarUserManagerHelper.startGuestSession(mGuestName);
                    cancel();
                }
            };

            logI("Starting timer");
            mSwitchToGuestTimer.start();
        }
    }

    /**
     * Cancels the running timer.
     */
    public void cancel() {
        synchronized (mTimerLock) {
            if (mSwitchToGuestTimer != null) {
                logI("Cancelling timer");
                mSwitchToGuestTimer.cancel();
                mSwitchToGuestTimer = null;
            }
        }
    }

    private void logD(String message) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, message);
        }
    }

    private void logI(String message) {
        if (Log.isLoggable(TAG, Log.INFO)) {
            Log.i(TAG, message);
        }
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -232,9 +232,6 @@
    <!-- to read and change hvac values in a car -->
    <uses-permission android:name="android.car.permission.CONTROL_CAR_CLIMATE" />

    <!-- to be able to detect the driving state in a car-->
    <uses-permission android:name="android.car.permission.CAR_DRIVING_STATE" />

    <!-- Permission necessary to change car audio volume through CarAudioManager -->
    <uses-permission android:name="android.car.permission.CAR_CONTROL_AUDIO_VOLUME" />