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

Commit 77a200b8 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Catch when telecom isn't ready yet

The service can be non-null even when it's not ready.

Test: NotificationManagerServiceTest
Fixes: 232895613
Change-Id: I06210142b614aecfc5c70eb764e39a6c7d249014
parent 96f4a2af
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -6936,9 +6936,14 @@ public class NotificationManagerService extends SystemService {
        try {
            if (mPackageManagerClient.hasSystemFeature(FEATURE_TELECOM)
                    && mTelecomManager != null) {
                try {
                    return mTelecomManager.isInManagedCall()
                            || mTelecomManager.isInSelfManagedCall(
                            pkg, UserHandle.getUserHandleForUid(uid));
                } catch (IllegalStateException ise) {
                    // Telecom is not ready (this is likely early boot), so there are no calls.
                    return false;
                }
            }
            return false;
        } finally {
+19 −0
Original line number Diff line number Diff line
@@ -9332,6 +9332,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(),
                           r.getSbn().getId(), r.getSbn().getTag(), r, false))
                .isFalse();

        // telecom manager is not ready - blocked
        mService.setTelecomManager(mTelecomManager);
        when(mTelecomManager.isInCall()).thenThrow(new IllegalStateException("not ready"));
        assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(),
                r.getSbn().getId(), r.getSbn().getTag(), r, false))
                .isFalse();
    }

    @Test
@@ -9431,6 +9438,18 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

        verify(mUsageStats).registerBlocked(any());
        verify(mUsageStats, never()).registerPostedByApp(any());

        // telecom is not ready - notifications should be blocked but no crashes
        mService.setTelecomManager(mTelecomManager);
        when(mTelecomManager.isInCall()).thenThrow(new IllegalStateException("not ready"));
        reset(mUsageStats);

        mService.addEnqueuedNotification(r);
        runnable.run();
        waitForIdle();

        verify(mUsageStats).registerBlocked(any());
        verify(mUsageStats, never()).registerPostedByApp(any());
    }

    @Test