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

Commit 8ad94cb6 authored by Aaron Liu's avatar Aaron Liu
Browse files

Register contentObserver on bg thread.

Perfetto trace shows thats that this registration is blocking the main
thread for 64 ms. We can eliminate this blocking call by putting it on a
bg thread.

Fixes: 310584954
Test: atest KeyguardClockSwitchControllerTest
Flag: NONE

Change-Id: I8c134e23dc430729a965bb2ba517c525a438a5f7
parent 7820d50e
Loading
Loading
Loading
Loading
+25 −15
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ import androidx.annotation.VisibleForTesting;


import com.android.systemui.Dumpable;
import com.android.systemui.Dumpable;
import com.android.systemui.common.ui.ConfigurationState;
import com.android.systemui.common.ui.ConfigurationState;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FeatureFlagsClassic;
import com.android.systemui.flags.FeatureFlagsClassic;
@@ -78,6 +79,7 @@ import com.android.systemui.util.settings.SecureSettings;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.Locale;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Consumer;


import javax.inject.Inject;
import javax.inject.Inject;
@@ -136,6 +138,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
    private KeyguardInteractor mKeyguardInteractor;
    private KeyguardInteractor mKeyguardInteractor;
    private KeyguardClockInteractor mKeyguardClockInteractor;
    private KeyguardClockInteractor mKeyguardClockInteractor;
    private final DelayableExecutor mUiExecutor;
    private final DelayableExecutor mUiExecutor;
    private final Executor mBgExecutor;
    private boolean mCanShowDoubleLineClock = true;
    private boolean mCanShowDoubleLineClock = true;
    private DisposableHandle mAodIconsBindHandle;
    private DisposableHandle mAodIconsBindHandle;
    @Nullable private NotificationIconContainer mAodIconContainer;
    @Nullable private NotificationIconContainer mAodIconContainer;
@@ -186,6 +189,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
            KeyguardUnlockAnimationController keyguardUnlockAnimationController,
            KeyguardUnlockAnimationController keyguardUnlockAnimationController,
            SecureSettings secureSettings,
            SecureSettings secureSettings,
            @Main DelayableExecutor uiExecutor,
            @Main DelayableExecutor uiExecutor,
            @Background Executor bgExecutor,
            DumpManager dumpManager,
            DumpManager dumpManager,
            ClockEventController clockEventController,
            ClockEventController clockEventController,
            @KeyguardClockLog LogBuffer logBuffer,
            @KeyguardClockLog LogBuffer logBuffer,
@@ -209,6 +213,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
        mIconViewBindingFailureTracker = iconViewBindingFailureTracker;
        mIconViewBindingFailureTracker = iconViewBindingFailureTracker;
        mSecureSettings = secureSettings;
        mSecureSettings = secureSettings;
        mUiExecutor = uiExecutor;
        mUiExecutor = uiExecutor;
        mBgExecutor = bgExecutor;
        mKeyguardUnlockAnimationController = keyguardUnlockAnimationController;
        mKeyguardUnlockAnimationController = keyguardUnlockAnimationController;
        mDumpManager = dumpManager;
        mDumpManager = dumpManager;
        mClockEventController = clockEventController;
        mClockEventController = clockEventController;
@@ -328,6 +333,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
        updateAodIcons();
        updateAodIcons();
        mStatusArea = mView.findViewById(R.id.keyguard_status_area);
        mStatusArea = mView.findViewById(R.id.keyguard_status_area);


        mBgExecutor.execute(() -> {
            mSecureSettings.registerContentObserverForUser(
            mSecureSettings.registerContentObserverForUser(
                    Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK,
                    Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK,
                    false, /* notifyForDescendants */
                    false, /* notifyForDescendants */
@@ -341,6 +347,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
                    mShowWeatherObserver,
                    mShowWeatherObserver,
                    UserHandle.USER_ALL
                    UserHandle.USER_ALL
            );
            );
        });

        updateDoubleLineClock();
        updateDoubleLineClock();


        mKeyguardUnlockAnimationController.addKeyguardUnlockAnimationListener(
        mKeyguardUnlockAnimationController.addKeyguardUnlockAnimationListener(
@@ -382,8 +390,10 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
        mClockEventController.unregisterListeners();
        mClockEventController.unregisterListeners();
        setClock(null);
        setClock(null);


        mBgExecutor.execute(() -> {
            mSecureSettings.unregisterContentObserver(mDoubleLineClockObserver);
            mSecureSettings.unregisterContentObserver(mDoubleLineClockObserver);
            mSecureSettings.unregisterContentObserver(mShowWeatherObserver);
            mSecureSettings.unregisterContentObserver(mShowWeatherObserver);
        });


        mKeyguardUnlockAnimationController.removeKeyguardUnlockAnimationListener(
        mKeyguardUnlockAnimationController.removeKeyguardUnlockAnimationListener(
                mKeyguardUnlockAnimationListener);
                mKeyguardUnlockAnimationListener);
+1 −0
Original line number Original line Diff line number Diff line
@@ -195,6 +195,7 @@ public class KeyguardClockSwitchControllerBaseTest extends SysuiTestCase {
                mKeyguardUnlockAnimationController,
                mKeyguardUnlockAnimationController,
                mSecureSettings,
                mSecureSettings,
                mExecutor,
                mExecutor,
                mExecutor,
                mDumpManager,
                mDumpManager,
                mClockEventController,
                mClockEventController,
                mLogBuffer,
                mLogBuffer,
+2 −0
Original line number Original line Diff line number Diff line
@@ -157,6 +157,7 @@ public class KeyguardClockSwitchControllerTest extends KeyguardClockSwitchContro
        ArgumentCaptor<ContentObserver> observerCaptor =
        ArgumentCaptor<ContentObserver> observerCaptor =
                ArgumentCaptor.forClass(ContentObserver.class);
                ArgumentCaptor.forClass(ContentObserver.class);
        mController.init();
        mController.init();
        mExecutor.runAllReady();
        verify(mSecureSettings).registerContentObserverForUser(
        verify(mSecureSettings).registerContentObserverForUser(
                eq(Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK),
                eq(Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK),
                    anyBoolean(), observerCaptor.capture(), eq(UserHandle.USER_ALL));
                    anyBoolean(), observerCaptor.capture(), eq(UserHandle.USER_ALL));
@@ -212,6 +213,7 @@ public class KeyguardClockSwitchControllerTest extends KeyguardClockSwitchContro
        ArgumentCaptor<ContentObserver> observerCaptor =
        ArgumentCaptor<ContentObserver> observerCaptor =
                ArgumentCaptor.forClass(ContentObserver.class);
                ArgumentCaptor.forClass(ContentObserver.class);
        mController.init();
        mController.init();
        mExecutor.runAllReady();
        verify(mSecureSettings).registerContentObserverForUser(
        verify(mSecureSettings).registerContentObserverForUser(
                eq(Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED), anyBoolean(),
                eq(Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED), anyBoolean(),
                    observerCaptor.capture(), eq(UserHandle.USER_ALL));
                    observerCaptor.capture(), eq(UserHandle.USER_ALL));