Keep the legacy ssaid for apps on SD card

Symptom:
After O OS upgrade, LINE application on SD card got crash loop. The
encrypted data depended on the ssaid and it was changed by OS upgrade.

Root cause:
At the 1st boot-time of OS upgrade, StorageProvider migrates the legacy
ssaids.

At that moment, SD card is not mounted yet. The target of migration
depends on the list of PMS#getInstalledPackages() and the list doesn't
contain the apps on unmounted SD card.
As a result, the ssaids for the apps on SD card are not migrated.

Solution:
The target of ssaid migration respects the all known packages of PMS.
To achieve it, getInstalledPackages() with MATCH_UNINSTALLED_PACKAGES
is improved. Now, it can provide the information of package which has
an inaccessible package file.
Even though SD card is not mounted, the package list contains the apps
on SD card.

Bug: 72343790
Change-Id: If5d31e44cf7ec44da6010434515a157b00a5a09a
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index d1459bb..06dff53 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -2328,7 +2328,9 @@
                     // Get all uids for the user's packages.
                     final List<PackageInfo> packages;
                     try {
-                        packages = mPackageManager.getInstalledPackages(0, user.id).getList();
+                        packages = mPackageManager.getInstalledPackages(
+                            PackageManager.MATCH_UNINSTALLED_PACKAGES,
+                            user.id).getList();
                     } catch (RemoteException e) {
                         throw new IllegalStateException("Package manager not available");
                     }
@@ -3401,7 +3403,9 @@
                         // Fill each uid with the legacy ssaid to be backwards compatible.
                         final List<PackageInfo> packages;
                         try {
-                            packages = mPackageManager.getInstalledPackages(0, userId).getList();
+                            packages = mPackageManager.getInstalledPackages(
+                                PackageManager.MATCH_UNINSTALLED_PACKAGES,
+                                userId).getList();
                         } catch (RemoteException e) {
                             throw new IllegalStateException("Package manager not available");
                         }
@@ -3416,6 +3420,9 @@
                                 // Android Id doesn't exist for this package so create it.
                                 ssaidSettings.insertSettingLocked(uid, legacySsaid, null, true,
                                         info.packageName);
+                                if (DEBUG) {
+                                    Slog.d(LOG_TAG, "Keep the legacy ssaid for uid=" + uid);
+                                }
                             }
                         }
                     }