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

Commit 3aac4e65 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Usage:fix arrayIndexOutOfBoundsException to aviod systemServer crash."...

Merge "Usage:fix arrayIndexOutOfBoundsException to aviod systemServer crash." into main am: 5e5902ff

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3119591



Change-Id: Ife50f5a0414c903a0da5c2502f5d8938d0ead332
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 1b8e1992 5e5902ff
Loading
Loading
Loading
Loading
+32 −25
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.util.SparseArray;
import android.util.TimeUtils;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.IndentingPrintWriter;

@@ -136,6 +137,7 @@ public class UsageStatsDatabase {
    // The obfuscated packages to tokens mappings file
    private final File mPackageMappingsFile;
    // Holds all of the data related to the obfuscated packages and their token mappings.
    @GuardedBy("mLock")
    final PackagesTokenData mPackagesTokenData = new PackagesTokenData();

    /**
@@ -771,6 +773,7 @@ public class UsageStatsDatabase {
     * all of the stats at once has an amortized cost for future calls.
     */
    void filterStats(IntervalStats stats) {
        synchronized (mLock) {
            if (mPackagesTokenData.removedPackagesMap.isEmpty()) {
                return;
            }
@@ -781,7 +784,8 @@ public class UsageStatsDatabase {
            for (int i = 0; i < removedPackagesSize; i++) {
                final String removedPackage = removedPackagesMap.keyAt(i);
                final UsageStats usageStats = stats.packageStats.get(removedPackage);
            if (usageStats != null && usageStats.mEndTimeStamp < removedPackagesMap.valueAt(i)) {
                if (usageStats != null &&
                        usageStats.mEndTimeStamp < removedPackagesMap.valueAt(i)) {
                    stats.packageStats.remove(removedPackage);
                }
            }
@@ -795,6 +799,7 @@ public class UsageStatsDatabase {
                }
            }
        }
    }

    /**
     * Figures out what to extract from the given IntervalStats object.
@@ -1226,6 +1231,7 @@ public class UsageStatsDatabase {
    }

    void obfuscateCurrentStats(IntervalStats[] currentStats) {
        synchronized (mLock) {
            if (mCurrentVersion < 5) {
                return;
            }
@@ -1234,6 +1240,7 @@ public class UsageStatsDatabase {
                stats.obfuscateData(mPackagesTokenData);
            }
        }
    }

    /**
     * Update the stats in the database. They may not be written to disk immediately.