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

Commit 6eb41dbe authored by Jernej Virag's avatar Jernej Virag
Browse files

Move global settings observer registration to bg thread

We shouldn't be running these Binder calls on main thread, especially in
constructors. Use async version which runs on a bg thread.

The calls aren't race-condition sensitive so Async version is ok.

Bug: 327558308
Flag: EXEMPT bugfix
Test: presubmit
Change-Id: Id9d94fbc140f8a8d24e3331589d588da56c59430
parent 3ddbaf9d
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -56,6 +56,8 @@ import android.provider.Settings.Global.HEADS_UP_ON
import com.android.internal.logging.UiEventLogger.UiEventEnum
import com.android.internal.logging.testing.UiEventLoggerFake
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogcatEchoTracker
import com.android.systemui.log.core.LogLevel
@@ -78,10 +80,10 @@ import com.android.systemui.statusbar.notification.interruption.NotificationInte
import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderImpl.NotificationInterruptEvent.HUN_SUPPRESSED_OLD_WHEN
import com.android.systemui.statusbar.policy.FakeDeviceProvisionedController
import com.android.systemui.util.FakeEventLog
import com.android.systemui.util.settings.FakeGlobalSettings
import com.android.systemui.util.settings.FakeSettings
import com.android.systemui.util.settings.SystemSettings
import com.android.systemui.util.time.FakeSystemClock
import com.android.systemui.util.settings.fakeGlobalSettings
import com.android.systemui.util.settings.fakeSettings
import com.android.systemui.util.time.fakeSystemClock
import com.android.systemui.utils.leaks.FakeBatteryController
import com.android.systemui.utils.leaks.FakeKeyguardStateController
import com.android.systemui.utils.leaks.LeakCheckedTest
@@ -114,13 +116,14 @@ abstract class VisualInterruptionDecisionProviderTestBase : SysuiTestCase() {

    private val leakCheck = LeakCheckedTest.SysuiLeakCheck()

    protected val kosmos = Kosmos()
    protected val ambientDisplayConfiguration = FakeAmbientDisplayConfiguration(context)
    protected val batteryController = FakeBatteryController(leakCheck)
    protected val deviceProvisionedController = FakeDeviceProvisionedController()
    protected val eventLog = FakeEventLog()
    protected val flags: NotifPipelineFlags = mock()
    protected val globalSettings =
        FakeGlobalSettings().also { it.putInt(HEADS_UP_NOTIFICATIONS_ENABLED, HEADS_UP_ON) }
        kosmos.fakeGlobalSettings.also { it.putInt(HEADS_UP_NOTIFICATIONS_ENABLED, HEADS_UP_ON) }
    protected val headsUpManager: HeadsUpManager = mock()
    protected val keyguardNotificationVisibilityProvider: KeyguardNotificationVisibilityProvider =
        mock()
@@ -130,7 +133,7 @@ abstract class VisualInterruptionDecisionProviderTestBase : SysuiTestCase() {
    protected val oldLogger = NotificationInterruptLogger(fakeLogBuffer)
    protected val powerManager: PowerManager = mock()
    protected val statusBarStateController = FakeStatusBarStateController()
    protected val systemClock = FakeSystemClock()
    protected val systemClock = kosmos.fakeSystemClock
    protected val uiEventLogger = UiEventLoggerFake()
    protected val userTracker = FakeUserTracker()
    protected val avalancheProvider: AvalancheProvider = mock()
@@ -166,10 +169,12 @@ abstract class VisualInterruptionDecisionProviderTestBase : SysuiTestCase() {

        deviceProvisionedController.currentUser = userId
        userTracker.set(listOf(user), /* currentUserIndex= */ 0)
        systemSettings = FakeSettings()
        systemSettings = kosmos.fakeSettings
        whenever(bubbles.canShowBubbleNotification()).thenReturn(true)
        whenever(settingsInteractor.isCooldownEnabled).thenReturn(MutableStateFlow(true))
        provider.start()
        // Needed to handle async settings registrations
        kosmos.runCurrent()
    }

    @Test
+2 −2
Original line number Diff line number Diff line
@@ -247,7 +247,7 @@ public class HeadsUpManagerImpl
                }
            }
        };
        globalSettings.registerContentObserverSync(
        globalSettings.registerContentObserverAsync(
                globalSettings.getUriFor(SETTING_HEADS_UP_SNOOZE_LENGTH_MS),
                /* notifyForDescendants= */ false,
                settingsObserver);
+1 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ class PeekDisabledSuppressor(
                }
            }

        globalSettings.registerContentObserverSync(
        globalSettings.registerContentObserverAsync(
            globalSettings.getUriFor(HEADS_UP_NOTIFICATIONS_ENABLED),
            /* notifyForDescendants = */ true,
            observer,
+3 −4
Original line number Diff line number Diff line
@@ -171,13 +171,12 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
        };

        if (ENABLE_HEADS_UP) {
            mGlobalSettings.registerContentObserverSync(
            mGlobalSettings.registerContentObserverAsync(
                    mGlobalSettings.getUriFor(HEADS_UP_NOTIFICATIONS_ENABLED),
                    true,
                    headsUpObserver);
            mGlobalSettings.registerContentObserverSync(
                    mGlobalSettings.getUriFor(SETTING_HEADS_UP_TICKER), true,
                    headsUpObserver);
            mGlobalSettings.registerContentObserverAsync(
                    mGlobalSettings.getUriFor(SETTING_HEADS_UP_TICKER), true, headsUpObserver);
        }
        headsUpObserver.onChange(true); // set up
    }
+9 −5
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import android.app.ActivityManager;
import android.app.Flags;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.PendingIntent;
@@ -58,28 +57,31 @@ import android.graphics.drawable.Icon;
import android.hardware.display.AmbientDisplayConfiguration;
import android.os.Handler;
import android.os.PowerManager;
import android.platform.test.annotations.DisableFlags;

import android.platform.test.annotations.EnableFlags;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.internal.logging.testing.UiEventLoggerFake;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.kosmos.GeneralKosmosKt;
import com.android.systemui.kosmos.Kosmos;
import com.android.systemui.kosmos.KosmosKt;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.res.R;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.notification.NotifPipelineFlags;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
import com.android.systemui.statusbar.notification.headsup.HeadsUpManager;
import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider.FullScreenIntentDecision;
import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderImpl.NotificationInterruptEvent;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.notification.headsup.HeadsUpManager;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.FakeEventLog;
import com.android.systemui.util.settings.FakeGlobalSettings;
import com.android.systemui.util.settings.FakeGlobalSettingsKosmosKt;
import com.android.systemui.util.time.FakeSystemClock;
import com.android.wm.shell.bubbles.Bubbles;

@@ -102,6 +104,7 @@ import java.util.Set;
@SmallTest
public class NotificationInterruptStateProviderImplTest extends SysuiTestCase {

    Kosmos mKosmos = KosmosKt.Kosmos();
    @Mock
    PowerManager mPowerManager;
    @Mock
@@ -145,7 +148,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase {

        mUiEventLoggerFake = new UiEventLoggerFake();
        mSystemClock = new FakeSystemClock();
        mGlobalSettings = new FakeGlobalSettings();
        mGlobalSettings = FakeGlobalSettingsKosmosKt.getFakeGlobalSettings(mKosmos);
        mGlobalSettings.putInt(HEADS_UP_NOTIFICATIONS_ENABLED, HEADS_UP_ON);
        mEventLog = new FakeEventLog();

@@ -169,6 +172,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase {
                        mEventLog,
                        Optional.of(mBubbles));
        mNotifInterruptionStateProvider.mUseHeadsUp = true;
        GeneralKosmosKt.runCurrent(mKosmos);
    }

    /**