DO NOT MERGE Set CarSysUI unprovisioned state depending on SUW progress. am: d185a842c1

Change-Id: If3c51ad180a84ab656b3d823c7e83d62f09e398c
This commit is contained in:
Automerger Merge Worker
2019-12-12 23:44:42 +00:00
2 changed files with 164 additions and 15 deletions

View File

@@ -0,0 +1,129 @@
/*
* 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.car;
import android.app.ActivityManager;
import android.car.settings.CarSettings;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.provider.Settings;
import com.android.systemui.Dependency;
import java.util.ArrayList;
/**
* A controller that monitors the status of SUW progress for each user.
*/
public class SUWProgressController {
private static final Uri USER_SETUP_IN_PROGRESS_URI = Settings.Secure.getUriFor(
CarSettings.Secure.KEY_SETUP_WIZARD_IN_PROGRESS);
private final ArrayList<SUWProgressListener> mListeners = new ArrayList<>();
private final ContentObserver mCarSettingsObserver = new ContentObserver(
Dependency.get(Dependency.MAIN_HANDLER)) {
@Override
public void onChange(boolean selfChange, Uri uri, int userId) {
if (USER_SETUP_IN_PROGRESS_URI.equals(uri)) {
notifyUserSetupInProgressChanged();
}
}
};
private final ContentResolver mContentResolver;
public SUWProgressController(Context context) {
mContentResolver = context.getContentResolver();
}
/**
* Returns {@code true} then SUW is in progress for the given user.
*/
public boolean isUserSetupInProgress(int user) {
return Settings.Secure.getIntForUser(mContentResolver,
CarSettings.Secure.KEY_SETUP_WIZARD_IN_PROGRESS, /* def= */ 0, user) != 0;
}
/**
* Returns {@code true} then SUW is in progress for the current user.
*/
public boolean isCurrentUserSetupInProgress() {
return isUserSetupInProgress(ActivityManager.getCurrentUser());
}
/**
* Adds a {@link SUWProgressListener} callback.
*/
public void addCallback(SUWProgressListener listener) {
mListeners.add(listener);
if (mListeners.size() == 1) {
startListening(ActivityManager.getCurrentUser());
}
listener.onUserSetupInProgressChanged();
}
/**
* Removes a {@link SUWProgressListener} callback.
*/
public void removeCallback(SUWProgressListener listener) {
mListeners.remove(listener);
if (mListeners.size() == 0) {
stopListening();
}
}
private void startListening(int user) {
mContentResolver.registerContentObserver(
USER_SETUP_IN_PROGRESS_URI, /* notifyForDescendants= */ true, mCarSettingsObserver,
user);
}
private void stopListening() {
mContentResolver.unregisterContentObserver(mCarSettingsObserver);
}
/**
* Allows SUWProgressController to switch its listeners to observe SUW progress for new user.
*/
public void onUserSwitched() {
if (mListeners.size() == 0) {
return;
}
mContentResolver.unregisterContentObserver(mCarSettingsObserver);
mContentResolver.registerContentObserver(
USER_SETUP_IN_PROGRESS_URI, /* notifyForDescendants= */ true, mCarSettingsObserver,
ActivityManager.getCurrentUser());
}
private void notifyUserSetupInProgressChanged() {
for (int i = mListeners.size() - 1; i >= 0; --i) {
mListeners.get(i).onUserSetupInProgressChanged();
}
}
/**
* A listener that listens for changes in SUW progress for a user.
*/
public interface SUWProgressListener {
/**
* A callback for when a change occurs in SUW progress for a user.
*/
default void onUserSetupInProgressChanged() {
}
}
}

View File

@@ -72,6 +72,7 @@ import com.android.systemui.ForegroundServiceController;
import com.android.systemui.Prefs; import com.android.systemui.Prefs;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.SystemUIFactory; import com.android.systemui.SystemUIFactory;
import com.android.systemui.car.SUWProgressController;
import com.android.systemui.classifier.FalsingLog; import com.android.systemui.classifier.FalsingLog;
import com.android.systemui.colorextraction.SysuiColorExtractor; import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.fragments.FragmentHostManager; import com.android.systemui.fragments.FragmentHostManager;
@@ -155,7 +156,9 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
private CarFacetButtonController mCarFacetButtonController; private CarFacetButtonController mCarFacetButtonController;
private ActivityManagerWrapper mActivityManagerWrapper; private ActivityManagerWrapper mActivityManagerWrapper;
private DeviceProvisionedController mDeviceProvisionedController; private DeviceProvisionedController mDeviceProvisionedController;
private SUWProgressController mSUWProgressController;
private boolean mDeviceIsSetUpForUser = true; private boolean mDeviceIsSetUpForUser = true;
private boolean mIsUserSetupInProgress = false;
private HvacController mHvacController; private HvacController mHvacController;
private DrivingStateHelper mDrivingStateHelper; private DrivingStateHelper mDrivingStateHelper;
private PowerManagerHelper mPowerManagerHelper; private PowerManagerHelper mPowerManagerHelper;
@@ -273,7 +276,9 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
// get the provisioned state before calling the parent class since it's that flow that // get the provisioned state before calling the parent class since it's that flow that
// builds the nav bar // builds the nav bar
mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class); mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class);
mSUWProgressController = new SUWProgressController(mContext);
mDeviceIsSetUpForUser = mDeviceProvisionedController.isCurrentUserSetup(); mDeviceIsSetUpForUser = mDeviceProvisionedController.isCurrentUserSetup();
mIsUserSetupInProgress = mSUWProgressController.isCurrentUserSetupInProgress();
// Keyboard related setup, before nav bars are created. // Keyboard related setup, before nav bars are created.
mHideNavBarForKeyboard = mContext.getResources().getBoolean( mHideNavBarForKeyboard = mContext.getResources().getBoolean(
@@ -326,6 +331,13 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
mHvacController.connectToCarService(); mHvacController.connectToCarService();
mSUWProgressController.addCallback(
new SUWProgressController.SUWProgressListener() {
@Override
public void onUserSetupInProgressChanged() {
mHandler.post(() -> restartNavBarsIfNecessary());
}
});
mDeviceProvisionedController.addCallback( mDeviceProvisionedController.addCallback(
new DeviceProvisionedController.DeviceProvisionedListener() { new DeviceProvisionedController.DeviceProvisionedListener() {
@Override @Override
@@ -335,6 +347,7 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
@Override @Override
public void onUserSwitched() { public void onUserSwitched() {
mSUWProgressController.onUserSwitched();
mHandler.post(() -> restartNavBarsIfNecessary()); mHandler.post(() -> restartNavBarsIfNecessary());
} }
}); });
@@ -367,14 +380,6 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
}); });
} }
private void restartNavBarsIfNecessary() {
boolean currentUserSetup = mDeviceProvisionedController.isCurrentUserSetup();
if (mDeviceIsSetUpForUser != currentUserSetup) {
mDeviceIsSetUpForUser = currentUserSetup;
restartNavBars();
}
}
@Override @Override
protected void getDependencies() { protected void getDependencies() {
// Keyguard // Keyguard
@@ -424,6 +429,17 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
mContext.unregisterReceiver(mBootCompletedReceiver); mContext.unregisterReceiver(mBootCompletedReceiver);
} }
private void restartNavBarsIfNecessary() {
boolean currentUserSetup = mDeviceProvisionedController.isCurrentUserSetup();
boolean currentUserSetupInProgress = mSUWProgressController.isCurrentUserSetupInProgress();
if (mIsUserSetupInProgress != currentUserSetupInProgress
|| mDeviceIsSetUpForUser != currentUserSetup) {
mDeviceIsSetUpForUser = currentUserSetup;
mIsUserSetupInProgress = currentUserSetupInProgress;
restartNavBars();
}
}
/** /**
* Remove all content from navbars and rebuild them. Used to allow for different nav bars * Remove all content from navbars and rebuild them. Used to allow for different nav bars
* before and after the device is provisioned. . Also for change of density and font size. * before and after the device is provisioned. . Also for change of density and font size.
@@ -592,7 +608,7 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
new HandleBarCloseNotificationGestureListener()); new HandleBarCloseNotificationGestureListener());
mTopNavBarNotificationTouchListener = (v, event) -> { mTopNavBarNotificationTouchListener = (v, event) -> {
if (!mDeviceIsSetUpForUser) { if (!mDeviceIsSetUpForUser || mIsUserSetupInProgress) {
return true; return true;
} }
boolean consumed = openGestureDetector.onTouchEvent(event); boolean consumed = openGestureDetector.onTouchEvent(event);
@@ -932,22 +948,24 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
} }
private void buildNavBarContent() { private void buildNavBarContent() {
boolean shouldBuildNavBarContent = mDeviceIsSetUpForUser && !mIsUserSetupInProgress;
// Always build top bar. // Always build top bar.
buildTopBar((mDeviceIsSetUpForUser) ? R.layout.car_top_navigation_bar : buildTopBar(shouldBuildNavBarContent ? R.layout.car_top_navigation_bar :
R.layout.car_top_navigation_bar_unprovisioned); R.layout.car_top_navigation_bar_unprovisioned);
if (mShowBottom) { if (mShowBottom) {
buildBottomBar((mDeviceIsSetUpForUser) ? R.layout.car_navigation_bar : buildBottomBar(shouldBuildNavBarContent ? R.layout.car_navigation_bar :
R.layout.car_navigation_bar_unprovisioned); R.layout.car_navigation_bar_unprovisioned);
} }
if (mShowLeft) { if (mShowLeft) {
buildLeft((mDeviceIsSetUpForUser) ? R.layout.car_left_navigation_bar : buildLeft(shouldBuildNavBarContent ? R.layout.car_left_navigation_bar :
R.layout.car_left_navigation_bar_unprovisioned); R.layout.car_left_navigation_bar_unprovisioned);
} }
if (mShowRight) { if (mShowRight) {
buildRight((mDeviceIsSetUpForUser) ? R.layout.car_right_navigation_bar : buildRight(shouldBuildNavBarContent ? R.layout.car_right_navigation_bar :
R.layout.car_right_navigation_bar_unprovisioned); R.layout.car_right_navigation_bar_unprovisioned);
} }
} }
@@ -1570,8 +1588,10 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
@Override @Override
protected void setHeadsUpVisible() { protected void setHeadsUpVisible() {
// if the Notifications panel is showing don't show the Heads up // if the Notifications panel is showing or SUW for user is in progress then don't show
if (!mEnableHeadsUpNotificationWhenNotificationShadeOpen && mPanelExpanded) { // heads up notifications
if ((!mEnableHeadsUpNotificationWhenNotificationShadeOpen && mPanelExpanded)
|| !mDeviceIsSetUpForUser || mIsUserSetupInProgress) {
return; return;
} }