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

Commit 71ced8ff authored by Songchun Fan's avatar Songchun Fan
Browse files

[pm] fix NPE in PreferredComponent

The list of ResolveInfo is from a previous snapshot, so it's possible
that by the time the code reaches PreferredComponent.isSameSet, some of
the apps in the list has already been uninstalled. This CL adds an NPE
fix. A longer term fix should pass the same snapshot into
PreferredComponent to ensure consistency.

BUG: 320033788
Test: presubmit

Change-Id: I488943043a85be23558c06e020f4a91544fe3dc5
parent f687e4ee
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -28,7 +28,8 @@ import com.android.internal.util.XmlUtils;
import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;
import com.android.server.LocalServices;
import com.android.server.pm.pkg.PackageUserState;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.pkg.PackageUserStateInternal;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -218,11 +219,15 @@ public class PreferredComponent {
                continue;
            }

            // Avoid showing the disambiguation dialog if the package which is installed with
            // reason INSTALL_REASON_DEVICE_SETUP.
            final PackageUserState pkgUserState =
                    pmi.getPackageStateInternal(ai.packageName).getUserStates().get(userId);
            if (pkgUserState != null && pkgUserState.getInstallReason()
            // Avoid showing the disambiguation dialog if the package is not installed or
            // installed with reason INSTALL_REASON_DEVICE_SETUP.
            final PackageStateInternal ps = pmi.getPackageStateInternal(ai.packageName);
            if (ps == null) {
                continue;
            }
            final PackageUserStateInternal pkgUserState = ps.getUserStates().get(userId);
            if (pkgUserState == null
                    || pkgUserState.getInstallReason()
                    == PackageManager.INSTALL_REASON_DEVICE_SETUP) {
                continue;
            }