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

Commit 12eed538 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Set CarSysUI unprovisioned state depending on SUW progress."

parents 64bae6b7 ee51369b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.systemui.Dependency.LEAK_REPORT_EMAIL_NAME;

import android.content.Context;

import com.android.systemui.car.CarDeviceProvisionedControllerImpl;
import com.android.systemui.car.CarNotificationEntryManager;
import com.android.systemui.car.CarNotificationInterruptionStateProvider;
import com.android.systemui.dagger.SystemUIRootComponent;
@@ -46,6 +47,7 @@ import com.android.systemui.statusbar.phone.KeyguardEnvironmentImpl;
import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.volume.CarVolumeDialogComponent;
import com.android.systemui.volume.VolumeDialogComponent;
@@ -143,4 +145,8 @@ abstract class CarSystemUIModule {
    @Binds
    abstract StatusBarKeyguardViewManager bindStatusBarKeyguardViewManager(
            CarStatusBarKeyguardViewManager keyguardViewManager);

    @Binds
    abstract DeviceProvisionedController bindDeviceProvisionedController(
            CarDeviceProvisionedControllerImpl deviceProvisionedController);
}
+37 −0
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.car;

import com.android.systemui.statusbar.policy.DeviceProvisionedController;

/**
 * This interface defines controller that monitors the status of SUW progress for each user in
 * addition to the functionality defined by {@link DeviceProvisionedController}.
 */
public interface CarDeviceProvisionedController extends DeviceProvisionedController {
    /**
     * Returns {@code true} then SUW is in progress for the given user.
     */
    boolean isUserSetupInProgress(int user);

    /**
     * Returns {@code true} then SUW is in progress for the current user.
     */
    default boolean isCurrentUserSetupInProgress() {
        return isUserSetupInProgress(getCurrentUser());
    }
}
+116 −0
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.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.os.Handler;
import android.provider.Settings;

import com.android.systemui.Dependency;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.MainHandler;
import com.android.systemui.statusbar.policy.DeviceProvisionedControllerImpl;

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

/**
 * A controller that monitors the status of SUW progress for each user in addition to the
 * functionality provided by {@link DeviceProvisionedControllerImpl}.
 */
@Singleton
public class CarDeviceProvisionedControllerImpl extends DeviceProvisionedControllerImpl implements
        CarDeviceProvisionedController {
    private static final Uri USER_SETUP_IN_PROGRESS_URI = Settings.Secure.getUriFor(
            CarSettings.Secure.KEY_SETUP_WIZARD_IN_PROGRESS);
    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;

    @Inject
    public CarDeviceProvisionedControllerImpl(Context context, @MainHandler Handler mainHandler,
            BroadcastDispatcher broadcastDispatcher) {
        super(context, mainHandler, broadcastDispatcher);
        mContentResolver = context.getContentResolver();
    }

    @Override
    public boolean isUserSetupInProgress(int user) {
        return Settings.Secure.getIntForUser(mContentResolver,
                CarSettings.Secure.KEY_SETUP_WIZARD_IN_PROGRESS, /* def= */ 0, user) != 0;
    }

    @Override
    public boolean isCurrentUserSetupInProgress() {
        return isUserSetupInProgress(ActivityManager.getCurrentUser());
    }

    @Override
    public void addCallback(DeviceProvisionedListener listener) {
        super.addCallback(listener);
        if (listener instanceof CarDeviceProvisionedListener) {
            ((CarDeviceProvisionedListener) listener).onUserSetupInProgressChanged();
        }
    }

    @Override
    protected void startListening(int user) {
        mContentResolver.registerContentObserver(
                USER_SETUP_IN_PROGRESS_URI, /* notifyForDescendants= */ true, mCarSettingsObserver,
                user);
        // The SUW Flag observer is registered before super.startListening() so that the observer is
        // in place before DeviceProvisionedController starts to track user switches which avoids
        // an edge case where our observer gets registered twice.
        super.startListening(user);
    }

    @Override
    protected void stopListening() {
        super.stopListening();
        mContentResolver.unregisterContentObserver(mCarSettingsObserver);
    }

    @Override
    public void onUserSwitched(int newUserId) {
        super.onUserSwitched(newUserId);
        mContentResolver.unregisterContentObserver(mCarSettingsObserver);
        mContentResolver.registerContentObserver(
                USER_SETUP_IN_PROGRESS_URI, /* notifyForDescendants= */ true, mCarSettingsObserver,
                newUserId);
    }

    private void notifyUserSetupInProgressChanged() {
        for (int i = mListeners.size() - 1; i >= 0; --i) {
            DeviceProvisionedListener listener = mListeners.get(i);
            if (listener instanceof CarDeviceProvisionedListener) {
                ((CarDeviceProvisionedListener) listener).onUserSetupInProgressChanged();
            }
        }
    }
}
+36 −0
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.car;

import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener;

/**
 * A listener that listens for changes in SUW progress for a user in addition to the
 * functionality defined by {@link DeviceProvisionedListener}.
 */
public interface CarDeviceProvisionedListener extends DeviceProvisionedListener {
    @Override
    default void onUserSwitched() {
        onUserSetupChanged();
        onUserSetupInProgressChanged();
    }
    /**
     * A callback for when a change occurs in SUW progress for a user.
     */
    default void onUserSetupInProgressChanged() {
    }
}
+30 −12
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.RegisterStatusBarResult;
import com.android.systemui.R;
import com.android.systemui.SystemUI;
import com.android.systemui.car.CarDeviceProvisionedController;
import com.android.systemui.car.CarDeviceProvisionedListener;
import com.android.systemui.dagger.qualifiers.MainHandler;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.statusbar.CommandQueue;
@@ -53,7 +55,7 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks

    private final CarNavigationBarController mCarNavigationBarController;
    private final WindowManager mWindowManager;
    private final DeviceProvisionedController mDeviceProvisionedController;
    private final CarDeviceProvisionedController mCarDeviceProvisionedController;
    private final CommandQueue mCommandQueue;
    private final Lazy<FacetButtonTaskStackListener> mFacetButtonTaskStackListenerLazy;
    private final Handler mMainHandler;
@@ -82,6 +84,7 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
    // To be attached to the navigation bars such that they can close the notification panel if
    // it's open.
    private boolean mDeviceIsSetUpForUser = true;
    private boolean mIsUserSetupInProgress = false;

    @Inject
    public CarNavigationBar(Context context,
@@ -98,7 +101,8 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
        super(context);
        mCarNavigationBarController = carNavigationBarController;
        mWindowManager = windowManager;
        mDeviceProvisionedController = deviceProvisionedController;
        mCarDeviceProvisionedController = (CarDeviceProvisionedController)
                deviceProvisionedController;
        mCommandQueue = commandQueue;
        mFacetButtonTaskStackListenerLazy = facetButtonTaskStackListenerLazy;
        mMainHandler = mainHandler;
@@ -129,9 +133,15 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
            ex.rethrowFromSystemServer();
        }

        mDeviceIsSetUpForUser = mDeviceProvisionedController.isCurrentUserSetup();
        mDeviceProvisionedController.addCallback(
                new DeviceProvisionedController.DeviceProvisionedListener() {
        mDeviceIsSetUpForUser = mCarDeviceProvisionedController.isCurrentUserSetup();
        mIsUserSetupInProgress = mCarDeviceProvisionedController.isCurrentUserSetupInProgress();
        mCarDeviceProvisionedController.addCallback(
                new CarDeviceProvisionedListener() {
                    @Override
                    public void onUserSetupInProgressChanged() {
                        mMainHandler.post(() -> restartNavBarsIfNecessary());
                    }

                    @Override
                    public void onUserSetupChanged() {
                        mMainHandler.post(() -> restartNavBarsIfNecessary());
@@ -152,9 +162,13 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
    }

    private void restartNavBarsIfNecessary() {
        boolean currentUserSetup = mDeviceProvisionedController.isCurrentUserSetup();
        if (mDeviceIsSetUpForUser != currentUserSetup) {
        boolean currentUserSetup = mCarDeviceProvisionedController.isCurrentUserSetup();
        boolean currentUserSetupInProgress = mCarDeviceProvisionedController
                .isCurrentUserSetupInProgress();
        if (mIsUserSetupInProgress != currentUserSetupInProgress
                || mDeviceIsSetUpForUser != currentUserSetup) {
            mDeviceIsSetUpForUser = currentUserSetup;
            mIsUserSetupInProgress = currentUserSetupInProgress;
            restartNavBars();
        }
    }
@@ -193,8 +207,12 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
        // If the UI was rebuilt (day/night change) while the keyguard was up we need to
        // correctly respect that state.
        if (mKeyguardStateControllerLazy.get().isShowing()) {
            mCarNavigationBarController.showAllKeyguardButtons(mDeviceIsSetUpForUser);
            mCarNavigationBarController.showAllKeyguardButtons(isDeviceSetupForUser());
        }
    }

    private boolean isDeviceSetupForUser() {
        return mDeviceIsSetUpForUser && !mIsUserSetupInProgress;
    }

    private void createNavigationBar(RegisterStatusBarResult result) {
@@ -225,22 +243,22 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
    }

    private void buildNavBarContent() {
        mTopNavigationBarView = mCarNavigationBarController.getTopBar(mDeviceIsSetUpForUser);
        mTopNavigationBarView = mCarNavigationBarController.getTopBar(isDeviceSetupForUser());
        if (mTopNavigationBarView != null) {
            mTopNavigationBarWindow.addView(mTopNavigationBarView);
        }

        mBottomNavigationBarView = mCarNavigationBarController.getBottomBar(mDeviceIsSetUpForUser);
        mBottomNavigationBarView = mCarNavigationBarController.getBottomBar(isDeviceSetupForUser());
        if (mBottomNavigationBarView != null) {
            mBottomNavigationBarWindow.addView(mBottomNavigationBarView);
        }

        mLeftNavigationBarView = mCarNavigationBarController.getLeftBar(mDeviceIsSetUpForUser);
        mLeftNavigationBarView = mCarNavigationBarController.getLeftBar(isDeviceSetupForUser());
        if (mLeftNavigationBarView != null) {
            mLeftNavigationBarWindow.addView(mLeftNavigationBarView);
        }

        mRightNavigationBarView = mCarNavigationBarController.getRightBar(mDeviceIsSetUpForUser);
        mRightNavigationBarView = mCarNavigationBarController.getRightBar(isDeviceSetupForUser());
        if (mRightNavigationBarView != null) {
            mRightNavigationBarWindow.addView(mRightNavigationBarView);
        }
Loading