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

Commit 259403ef authored by Kweku Adams's avatar Kweku Adams
Browse files

Add null check for retrieved package.

PackageManagerInternal.getPackage() states that the returned value can
be null. Check that the returned object isn't null before calling any of
its methods to avoid NullPointerExceptions.

Bug: 154899364
Test: atest FrameworksServicesTests:AppStandbyControllerTests
Change-Id: Ifcb200a4a0ed6582cc1a368c2949f0aaf32d7dd2
parent cd220824
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ConcurrentUtils;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.LocalServices;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.usage.AppIdleHistory.AppUsageHistory;

import java.io.File;
@@ -1862,10 +1863,15 @@ public class AppStandbyController implements AppStandbyInternal {

        public List<UserHandle> getValidCrossProfileTargets(String pkg, int userId) {
            final int uid = mPackageManagerInternal.getPackageUidInternal(pkg, 0, userId);
            final AndroidPackage aPkg = mPackageManagerInternal.getPackage(uid);
            if (uid < 0
                    || !mPackageManagerInternal.getPackage(uid).isCrossProfile()
                    || aPkg == null
                    || !aPkg.isCrossProfile()
                    || !mCrossProfileAppsInternal
                            .verifyUidHasInteractAcrossProfilePermission(pkg, uid)) {
                if (uid >= 0 && aPkg == null) {
                    Slog.wtf(TAG, "Null package retrieved for UID " + uid);
                }
                return Collections.emptyList();
            }
            return mCrossProfileAppsInternal.getTargetUserProfiles(pkg, userId);