Fix crash in ExternalSourceDetailPreferenceController.
- Add null check for the package info when trying to retrieve the install app state. During package update, the package info might becomes null. The App info activity will finish in that case, but this method might be called before the activity actually finishes. Change-Id: I18ff448666dfb403bb6693fccd3e54276db36f37 Fixes: 78257414 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.applications.appinfo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.os.UserManager;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
@@ -57,9 +58,13 @@ public class ExternalSourceDetailPreferenceController extends AppInfoPreferenceC
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isPotentialAppSource() {
|
||||
final PackageInfo packageInfo = mParent.getPackageInfo();
|
||||
if (packageInfo == null) {
|
||||
return false;
|
||||
}
|
||||
AppStateInstallAppsBridge.InstallAppsState appState =
|
||||
new AppStateInstallAppsBridge(mContext, null, null).createInstallAppsStateFor(
|
||||
mPackageName, mParent.getPackageInfo().applicationInfo.uid);
|
||||
mPackageName, packageInfo.applicationInfo.uid);
|
||||
return appState.isPotentialAppSource();
|
||||
}
|
||||
|
||||
|
@@ -101,4 +101,12 @@ public class ExternalSourceDetailPreferenceControllerTest {
|
||||
|
||||
verify(mPreference).setSummary(summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPotentialAppSource_nullPackageInfo_shouldNotCrash() {
|
||||
when(mUserManager.isManagedProfile()).thenReturn(false);
|
||||
|
||||
mController.isPotentialAppSource();
|
||||
// no crash
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user