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

Commit fdb3930b authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Rewrite DeviceProvisionedController

The old version made IPC calls in the main thread. Instead, fix the
following:

1. Calls to settings provider are made in background thread, except
maybe on object creation to set initial state or if requesting the state
of a user that hasn't been started (unlikely).
2. Cache state of device_provisioned and each user (that has been
started) user_setup_complete
3. Do all operations in background (with proper locks) and notify in
main thread.
4. Use UserTracker to avoid calls to `ActivityManager`.
5. The tracker is always registered so no changes are missed, and we
don't need to retrieve cache every time we would register. The number of
calls from the system are pretty low any way.
6. Listeners are not called on addCallback. None of the listeners
expected this and at least one assumed that a call meant an actual
change in state.

Test: atest DeviceProvisionedControllerTest
Test: manual, things are not hopelessly broken
Fixes: 203138620
Change-Id: I9caccd7593732a07d688d5ca2f8de8cedb8b02ef
parent 4d242afb
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -187,9 +187,13 @@ public abstract class SystemUIDefaultModule {
        return new Recents(context, recentsImplementation, commandQueue);
    }

    @Binds
    abstract DeviceProvisionedController bindDeviceProvisionedController(
            DeviceProvisionedControllerImpl deviceProvisionedController);
    @SysUISingleton
    @Provides
    static DeviceProvisionedController bindDeviceProvisionedController(
            DeviceProvisionedControllerImpl deviceProvisionedController) {
        deviceProvisionedController.init();
        return deviceProvisionedController;
    }

    @Binds
    abstract KeyguardViewController bindKeyguardViewController(
+1 −2
Original line number Diff line number Diff line
@@ -332,8 +332,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
        deviceProvisionedController.addCallback(new DeviceProvisionedListener() {
            @Override
            public void onUserSetupChanged() {
                setUserSetupComplete(deviceProvisionedController.isUserSetup(
                        deviceProvisionedController.getCurrentUser()));
                setUserSetupComplete(deviceProvisionedController.isCurrentUserSetup());
            }
        });

+1 −2
Original line number Diff line number Diff line
@@ -604,8 +604,7 @@ public class PhoneStatusBarPolicy

    @Override
    public void onUserSetupChanged() {
        boolean userSetup = mProvisionedController.isUserSetup(
                mProvisionedController.getCurrentUser());
        boolean userSetup = mProvisionedController.isCurrentUserSetup();
        if (mCurrentUserSetup == userSetup) return;
        mCurrentUserSetup = userSetup;
        updateAlarm();
+3 −4
Original line number Diff line number Diff line
@@ -4299,10 +4299,9 @@ public class StatusBar extends SystemUI implements
    private final DeviceProvisionedListener mUserSetupObserver = new DeviceProvisionedListener() {
        @Override
        public void onUserSetupChanged() {
            final boolean userSetup = mDeviceProvisionedController.isUserSetup(
                    mDeviceProvisionedController.getCurrentUser());
            Log.d(TAG, "mUserSetupObserver - DeviceProvisionedListener called for user "
                    + mDeviceProvisionedController.getCurrentUser());
            final boolean userSetup = mDeviceProvisionedController.isCurrentUserSetup();
            Log.d(TAG, "mUserSetupObserver - DeviceProvisionedListener called for "
                    + "current user");
            if (MULTIUSER_DEBUG) {
                Log.d(TAG, String.format("User setup changed: userSetup=%s mUserSetup=%s",
                        userSetup, mUserSetup));
+41 −4
Original line number Diff line number Diff line
@@ -14,23 +14,60 @@

package com.android.systemui.statusbar.policy;

import android.provider.Settings;

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

/**
 * Controller to cache in process the state of the device provisioning.
 * <p>
 * This controller keeps track of the values of device provisioning and user setup complete
 */
public interface DeviceProvisionedController extends CallbackController<DeviceProvisionedListener> {

    /**
     * @return whether the device is provisioned
     * @see Settings.Global#DEVICE_PROVISIONED
     */
    boolean isDeviceProvisioned();
    boolean isUserSetup(int currentUser);

    /**
     * @deprecated use {@link com.android.systemui.settings.UserTracker}
     */
    @Deprecated
    int getCurrentUser();

    default boolean isCurrentUserSetup() {
        return isUserSetup(getCurrentUser());
    }
    /**
     * @param user the user to query
     * @return whether that user has completed the user setup
     * @see Settings.Secure#USER_SETUP_COMPLETE
     */
    boolean isUserSetup(int user);

    /**
     * @see DeviceProvisionedController#isUserSetup
     */
    boolean isCurrentUserSetup();

    /**
     * Interface to provide calls when the values tracked change
     */
    interface DeviceProvisionedListener {
        /**
         * Call when the device changes from not provisioned to provisioned
         */
        default void onDeviceProvisionedChanged() { }

        /**
         * Call on user switched
         */
        default void onUserSwitched() {
            onUserSetupChanged();
        }

        /**
         * Call when some user changes from not provisioned to provisioned
         */
        default void onUserSetupChanged() { }
    }
}
Loading