diff options
| author | Anna Trostanetski <atrost@google.com> | 2019-10-10 16:26:11 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-10-10 16:26:11 +0000 |
| commit | ccaea274c061611906bc6ee26d542550124fd6ff (patch) | |
| tree | 7f8d462790cca38168e62bfe963d1e39cb2018a1 /core/java | |
| parent | ab911951aed8ce17a6c623e8acc4101b12553de1 (diff) | |
| parent | 893f84d353b5f263a477f0c936ad9ca9587bd78d (diff) | |
Merge "Reset app reporting on app launch."
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/com/android/internal/compat/ChangeReporter.java | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/core/java/com/android/internal/compat/ChangeReporter.java b/core/java/com/android/internal/compat/ChangeReporter.java index 8283eb749376..72b0ad7a02bc 100644 --- a/core/java/com/android/internal/compat/ChangeReporter.java +++ b/core/java/com/android/internal/compat/ChangeReporter.java @@ -22,7 +22,9 @@ import android.util.StatsLog; import com.android.internal.annotations.GuardedBy; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Objects; import java.util.Set; @@ -36,12 +38,10 @@ public final class ChangeReporter { private int mSource; private final class ChangeReport { - int mUid; long mChangeId; int mState; - ChangeReport(int uid, long changeId, int state) { - mUid = uid; + ChangeReport(long changeId, int state) { mChangeId = changeId; mState = state; } @@ -51,40 +51,62 @@ public final class ChangeReporter { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ChangeReport that = (ChangeReport) o; - return mUid == that.mUid - && mChangeId == that.mChangeId + return mChangeId == that.mChangeId && mState == that.mState; } @Override public int hashCode() { - return Objects.hash(mUid, mChangeId, mState); + return Objects.hash(mChangeId, mState); } } + // Maps uid to a set of ChangeReports (that were reported for that uid). @GuardedBy("mReportedChanges") - private Set<ChangeReport> mReportedChanges = new HashSet<>(); + private final Map<Integer, Set<ChangeReport>> mReportedChanges; public ChangeReporter(int source) { mSource = source; + mReportedChanges = new HashMap<>(); } /** - * Report the change to stats log. + * Report the change to stats log and to the debug log if the change was not previously + * logged already. * * @param uid affected by the change * @param changeId the reported change id * @param state of the reported change - enabled/disabled/only logged */ public void reportChange(int uid, long changeId, int state) { - ChangeReport report = new ChangeReport(uid, changeId, state); + ChangeReport report = new ChangeReport(changeId, state); synchronized (mReportedChanges) { - if (!mReportedChanges.contains(report)) { + Set<ChangeReport> reportedChangesForUid = mReportedChanges.get(uid); + if (reportedChangesForUid == null) { + mReportedChanges.put(uid, new HashSet<ChangeReport>()); + reportedChangesForUid = mReportedChanges.get(uid); + } + if (!reportedChangesForUid.contains(report)) { debugLog(uid, changeId, state); StatsLog.write(StatsLog.APP_COMPATIBILITY_CHANGE_REPORTED, uid, changeId, state, mSource); - mReportedChanges.add(report); + reportedChangesForUid.add(report); } + + } + } + + /** + * Clears the saved information about a given uid. Requests to report uid again will be reported + * regardless to the past reports. + * + * <p> Only intended to be called from PlatformCompat. + * + * @param uid to reset + */ + public void resetReportedChanges(int uid) { + synchronized (mReportedChanges) { + mReportedChanges.remove(uid); } } |
