Fix NPE with registering content listener
1) Fix the condition to check either subscribed or null. 2) Don't register listeners unless the feature flag is enabled Test: make RunSettingsRoboTest Bug: 267357231 Change-Id: I0134812cbac60c394d96c5a5621a7c16d781b05d
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.settings.biometrics.activeunlock;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.shadows.ShadowLooper.idleMainLooper;
|
||||
@@ -43,6 +44,8 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public class ActiveUnlockContentListenerTest {
|
||||
@@ -136,6 +139,26 @@ public class ActiveUnlockContentListenerTest {
|
||||
assertThat(mUpdateCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noProvider_subscribeDoesntRegisterObserver() {
|
||||
when(mPackageManager.getInstalledPackages(any()))
|
||||
.thenReturn(new ArrayList<>());
|
||||
OnContentChangedListener listener = new OnContentChangedListener() {
|
||||
@Override
|
||||
public void onContentChanged(String newValue) {}
|
||||
};
|
||||
|
||||
ActiveUnlockContentListener contentListener =
|
||||
new ActiveUnlockContentListener(
|
||||
mContext,
|
||||
listener,
|
||||
"logTag",
|
||||
FakeContentProvider.METHOD_SUMMARY,
|
||||
FakeContentProvider.KEY_SUMMARY);
|
||||
|
||||
assertThat(contentListener.subscribe()).isFalse();
|
||||
}
|
||||
|
||||
private void updateContent(String content) {
|
||||
FakeContentProvider.setTileSummary(content);
|
||||
mContext.getContentResolver().notifyChange(
|
||||
|
||||
Reference in New Issue
Block a user