Sort applications to avoid backup data change
Bug: 328698829 Fix: 328698829 Test: Manual test (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:ea8ed47d070be8b74297f1ca330dfdf9b196ec29) Merged-In: I0e5bf1145d972db136bbd85571f015b4ab6fb171 Change-Id: I0e5bf1145d972db136bbd85571f015b4ab6fb171
This commit is contained in:
committed by
Cherrypicker Worker
parent
85e130ad7a
commit
b03de69d79
@@ -52,6 +52,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/** An implementation to backup and restore battery configurations. */
|
||||
@@ -321,8 +322,8 @@ public final class BatterySettingsStorage extends ObservableBackupRestoreStorage
|
||||
@NonNull BackupContext backupContext, @NonNull OutputStream outputStream)
|
||||
throws IOException {
|
||||
final long timestamp = System.currentTimeMillis();
|
||||
final ArraySet<ApplicationInfo> applications = getInstalledApplications();
|
||||
if (applications == null || applications.isEmpty()) {
|
||||
final ApplicationInfo[] applications = getInstalledApplications();
|
||||
if (applications.length == 0) {
|
||||
Log.w(TAG, "no data found in the getInstalledApplications()");
|
||||
return EntityBackupResult.DELETE;
|
||||
}
|
||||
@@ -360,15 +361,24 @@ public final class BatterySettingsStorage extends ObservableBackupRestoreStorage
|
||||
TAG,
|
||||
String.format(
|
||||
"backup getInstalledApplications():%d count=%d in %d/ms",
|
||||
applications.size(),
|
||||
applications.length,
|
||||
backupCount,
|
||||
(System.currentTimeMillis() - timestamp)));
|
||||
return EntityBackupResult.UPDATE;
|
||||
}
|
||||
|
||||
private @Nullable ArraySet<ApplicationInfo> getInstalledApplications() {
|
||||
return BatteryOptimizeUtils.getInstalledApplications(
|
||||
private ApplicationInfo[] getInstalledApplications() {
|
||||
ArraySet<ApplicationInfo> installedApplications =
|
||||
BatteryOptimizeUtils.getInstalledApplications(
|
||||
mApplication, AppGlobals.getPackageManager());
|
||||
ApplicationInfo[] applicationInfos = new ApplicationInfo[0];
|
||||
if (installedApplications == null || installedApplications.isEmpty()) {
|
||||
return applicationInfos;
|
||||
}
|
||||
applicationInfos = installedApplications.toArray(applicationInfos);
|
||||
// sort the list to ensure backup data is stable
|
||||
Arrays.sort(applicationInfos, Comparator.comparing(info -> info.packageName));
|
||||
return applicationInfos;
|
||||
}
|
||||
|
||||
static @NonNull SharedPreferences getSharedPreferences(Context context) {
|
||||
|
Reference in New Issue
Block a user