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

Commit ed587c17 authored by TYM Tsai's avatar TYM Tsai
Browse files

Avoid NullPointerException

Bug: 381944372
Flag: EXEMPT bugfix
Test: atest PackageManagerServiceServerTests
Change-Id: Ib41daab00118972c673d2ac9bcb567af1bbd3402
parent 8218dda7
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -68,6 +68,10 @@ class UserDataPreparer {
    void prepareUserData(UserInfo userInfo, int flags) {
        try (PackageManagerTracedLock installLock = mInstallLock.acquireLock()) {
            final StorageManager storage = mContext.getSystemService(StorageManager.class);
            if (storage == null) {
                Log.e(TAG, "prepareUserData failed due to unable get StorageManager");
                return;
            }
            /*
             * Internal storage must be prepared before adoptable storage, since the user's volume
             * keys are stored in their internal storage.
@@ -159,6 +163,7 @@ class UserDataPreparer {
    void destroyUserData(int userId, int flags) {
        try (PackageManagerTracedLock installLock = mInstallLock.acquireLock()) {
            final StorageManager storage = mContext.getSystemService(StorageManager.class);
            if (storage != null) {
                /*
                 * Volume destruction order isn't really important, but to avoid any weird issues we
                 * process internal storage last, the opposite of prepareUserData.
@@ -169,6 +174,7 @@ class UserDataPreparer {
                        destroyUserDataLI(volumeUuid, userId, flags);
                    }
                }
            }
            destroyUserDataLI(null /* internal storage */, userId, flags);
        }
    }
@@ -194,9 +200,10 @@ class UserDataPreparer {
                }
            }

            if (storage != null) {
                // All the user's data directories should be empty now, so finish the job.
                storage.destroyUserStorage(volumeUuid, userId, flags);

            }
        } catch (Exception e) {
            logCriticalInfo(Log.WARN,
                    "Failed to destroy user " + userId + " on volume " + volumeUuid + ": " + e);