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

Commit c3e4619a authored by Doris Ling's avatar Doris Ling
Browse files

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
parent 0929651a
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -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();
    }

+8 −0
Original line number Diff line number Diff line
@@ -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
    }
}