Change Shallow Copy to Deep Copy in UsageStats
There are three reference type members in UsageStats's constructor, when using "new UsageStats(stats)" to copy, it will be a Shallow Copy, which may cause concurrent modify problem. For example, in UserUsageStatsService.java, the sUsageStatsCombiner is using "new UsageStats(stats.packageStats.valueAt(i)" to copy, and the value is passing to the computeCacheQuotaHints in CacheQuotaStrategy.java. If we change the UsageStats.mForegroundServices at the same time, IndexOutOfBounds Exception will happen. Therefore, it is necessary to modify the way of copying of the UsageStats. Signed-off-by: zhuyunyi <zhuyunyi@xiaomi.com> Change-Id: I58a54d17aad6ef5213e52658ee3387f3069339af
This commit is contained in:
@@ -171,9 +171,9 @@ public final class UsageStats implements Parcelable {
|
||||
mLaunchCount = stats.mLaunchCount;
|
||||
mAppLaunchCount = stats.mAppLaunchCount;
|
||||
mLastEvent = stats.mLastEvent;
|
||||
mActivities = stats.mActivities;
|
||||
mForegroundServices = stats.mForegroundServices;
|
||||
mChooserCounts = stats.mChooserCounts;
|
||||
mActivities = stats.mActivities.clone();
|
||||
mForegroundServices = new ArrayMap<>(stats.mForegroundServices);
|
||||
mChooserCounts = new ArrayMap<>(stats.mChooserCounts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user