Fix SysUI NPE crash during the boot/init progress

When Device boot and SystemUI servies starting, settings provider
may callback onChange() when OneHandedController register observer.
If the callback timing earlier han mEventCallback registered by
WMShll#initOneHanded, then the NPE will happen.

The simple fix is to add NPE check in
OneHandedController#notifyExpandNotifcation()
we can just ignore the callback during init time since the singal
is to expand notification and come from shorcut after user enable
and tap shortcut.(No need to act for the signal during boot progress.)

Test: manual reboot device and observe
Test: atest WMShellUnitTests
Bug: 191600033
Change-Id: I73849afa9904031759da304298221dbb222aeaaa
This commit is contained in:
Bill Lin
2021-06-22 11:22:37 +08:00
parent bdd8ff3fdd
commit c4bdf37af2
2 changed files with 16 additions and 1 deletions

View File

@@ -481,7 +481,9 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
@VisibleForTesting
void notifyExpandNotification() {
mMainExecutor.execute(() -> mEventCallback.notifyExpandNotification());
if (mEventCallback != null) {
mMainExecutor.execute(() -> mEventCallback.notifyExpandNotification());
}
}
@VisibleForTesting

View File

@@ -435,4 +435,17 @@ public class OneHandedControllerTest extends OneHandedTestCase {
verify(mSpiedOneHandedController).notifyShortcutState(anyInt());
}
@Test
public void testNotifyExpandNotification_withNullCheckProtection() {
when(mSpiedOneHandedController.isOneHandedEnabled()).thenReturn(false);
when(mSpiedTransitionState.getState()).thenReturn(STATE_NONE);
when(mSpiedTransitionState.isTransitioning()).thenReturn(false);
when(mSpiedOneHandedController.isSwipeToNotificationEnabled()).thenReturn(true);
mSpiedOneHandedController.setOneHandedEnabled(true);
mSpiedOneHandedController.notifyExpandNotification();
// Verify no NPE crash and mMockShellMainExecutor never be execute.
verify(mMockShellMainExecutor, never()).execute(any());
}
}