Merge "Fix NPE crash in UsageAccessDetails"
diff --git a/src/com/android/settings/applications/AppInfoBase.java b/src/com/android/settings/applications/AppInfoBase.java
index a93bfbd..3e83856 100644
--- a/src/com/android/settings/applications/AppInfoBase.java
+++ b/src/com/android/settings/applications/AppInfoBase.java
@@ -214,7 +214,9 @@
@Override
public void onPackageListChanged() {
- refreshUi();
+ if (!refreshUi()) {
+ setIntentAndFinish(true, true);
+ }
}
public static void startAppInfoFragment(Class<?> fragment, int titleRes,
diff --git a/src/com/android/settings/applications/UsageAccessDetails.java b/src/com/android/settings/applications/UsageAccessDetails.java
index e40ae37..253ddfd 100644
--- a/src/com/android/settings/applications/UsageAccessDetails.java
+++ b/src/com/android/settings/applications/UsageAccessDetails.java
@@ -137,6 +137,9 @@
@Override
protected boolean refreshUi() {
+ if (mPackageInfo == null) {
+ return false;
+ }
mUsageState = mUsageBridge.getUsageInfo(mPackageName,
mPackageInfo.applicationInfo.uid);
diff --git a/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java b/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java
index 532a923..fba02c3 100644
--- a/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java
@@ -17,6 +17,7 @@
package com.android.settings.applications;
import android.content.Context;
+import android.os.RemoteException;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsRobolectricTestRunner;
@@ -65,4 +66,11 @@
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_USAGE_VIEW_DENY), eq("app"));
}
+
+ @Test
+ public void refreshUi_nullPackageInfo_shouldNotCrash() throws RemoteException {
+ mFragment.mPackageInfo = null;
+ mFragment.refreshUi();
+ // should not crash
+ }
}