Stop passing issue cache operations through SafetyCenterDataTracker
This is a follow-up to ag/20074168 where I proxied/delegated these
methods to minimize the diff and risk in that CL.
Bug: 249950069
Test: atest SafetyCenterManagerTest
Change-Id: I1b2a7f634c5bd15cc2bdaf65e909990bb6d0dc91
diff --git a/service/java/com/android/safetycenter/SafetyCenterDataTracker.java b/service/java/com/android/safetycenter/SafetyCenterDataTracker.java
index 5d72441..73ab109 100644
--- a/service/java/com/android/safetycenter/SafetyCenterDataTracker.java
+++ b/service/java/com/android/safetycenter/SafetyCenterDataTracker.java
@@ -66,7 +66,6 @@
import com.android.safetycenter.internaldata.SafetyCenterIssueActionId;
import com.android.safetycenter.internaldata.SafetyCenterIssueId;
import com.android.safetycenter.internaldata.SafetyCenterIssueKey;
-import com.android.safetycenter.persistence.PersistedSafetyCenterIssue;
import com.android.safetycenter.resources.SafetyCenterResourcesContext;
import java.io.PrintWriter;
@@ -131,40 +130,6 @@
}
/**
- * Returns whether the Safety Center issue cache has been modified since the last time a
- * snapshot was taken.
- */
- // TODO(b/249950069): Consider removing issue cache APIs from SafetyCenterDataTracker
- boolean isSafetyCenterIssueCacheDirty() {
- return mSafetyCenterIssueCache.isDirty();
- }
-
- /**
- * Takes a snapshot of the Safety Center issue cache that should be written to persistent
- * storage.
- *
- * <p>This method will reset the value reported by {@link #isSafetyCenterIssueCacheDirty} to
- * {@code false}.
- */
- // TODO(b/249950069): Consider removing issue cache APIs from SafetyCenterDataTracker
- @NonNull
- List<PersistedSafetyCenterIssue> snapshotSafetyCenterIssueCache() {
- return mSafetyCenterIssueCache.snapshot();
- }
-
- /**
- * Replaces the Safety Center issue cache with the given list of issues.
- *
- * <p>This method may modify the Safety Center issue cache and change the value reported by
- * {@link #isSafetyCenterIssueCacheDirty} to {@code true}.
- */
- // TODO(b/249950069): Consider removing issue cache APIs from SafetyCenterDataTracker
- void loadSafetyCenterIssueCache(
- @NonNull List<PersistedSafetyCenterIssue> persistedSafetyCenterIssues) {
- mSafetyCenterIssueCache.load(persistedSafetyCenterIssues);
- }
-
- /**
* Sets the latest {@link SafetySourceData} for the given {@code safetySourceId}, {@link
* SafetyEvent}, {@code packageName} and {@code userId}, and returns whether there was a change
* to the underlying {@link SafetyCenterData}.
@@ -176,8 +141,7 @@
* <p>Setting a {@code null} {@link SafetySourceData} evicts the current {@link
* SafetySourceData} entry and clears the Safety Center issue cache for the source.
*
- * <p>This method may modify the Safety Center issue cache and change the value reported by
- * {@link #isSafetyCenterIssueCacheDirty} to {@code true}.
+ * <p>This method may modify the {@link SafetyCenterIssueCache}.
*/
boolean setSafetySourceData(
@Nullable SafetySourceData safetySourceData,
@@ -349,10 +313,8 @@
/**
* Dismisses the given {@link SafetyCenterIssueKey}.
*
- * <p>This method may modify the Safety Center issue cache and change the value reported by
- * {@link #isSafetyCenterIssueCacheDirty} to {@code true}.
+ * <p>This method may modify the {@link SafetyCenterIssueCache}.
*/
- // TODO(b/249950069): Consider removing issue cache APIs from SafetyCenterDataTracker
void dismissSafetyCenterIssue(@NonNull SafetyCenterIssueKey safetyCenterIssueKey) {
mSafetyCenterIssueCache.dismissIssue(safetyCenterIssueKey);
}
@@ -446,31 +408,17 @@
emptyList());
}
- /**
- * Clears all the {@link SafetySourceData} and errors, metadata associated with {@link
- * SafetyCenterIssueKey}s, in flight {@link SafetyCenterIssueActionId} and any refresh in
- * progress so far, for all users.
- *
- * <p>This method will modify the Safety Center issue cache and change the value reported by
- * {@link #isSafetyCenterIssueCacheDirty} to {@code true}.
- */
+ /** Clears all {@link SafetySourceData}, errors, issues and in flight actions for all users. */
void clear() {
mSafetySourceDataForKey.clear();
mSafetySourceErrors.clear();
-
- // TODO(b/249950069): Consider removing issue cache APIs from SafetyCenterDataTracker
mSafetyCenterIssueCache.clear();
-
mSafetyCenterIssueActionsInFlight.clear();
}
/**
- * Clears all the {@link SafetySourceData}, metadata associated with {@link
- * SafetyCenterIssueKey}s, in flight {@link SafetyCenterIssueActionId} and any refresh in
- * progress so far, for the given user.
- *
- * <p>This method may modify the Safety Center issue cache and change the value reported by
- * {@link #isSafetyCenterIssueCacheDirty} to {@code true}.
+ * Clears all {@link SafetySourceData}, errors, issues and in flight actions, for the given
+ * user.
*/
void clearForUser(@UserIdInt int userId) {
// Loop in reverse index order to be able to remove entries while iterating.
@@ -487,10 +435,8 @@
mSafetySourceErrors.removeAt(i);
}
}
-
- // TODO(b/249950069): Consider removing issue cache APIs from SafetyCenterDataTracker
+ // Issue cache implements this itself.
mSafetyCenterIssueCache.clearForUser(userId);
-
// Loop in reverse index order to be able to remove entries while iterating.
for (int i = mSafetyCenterIssueActionsInFlight.size() - 1; i >= 0; i--) {
SafetyCenterIssueActionId issueActionId = mSafetyCenterIssueActionsInFlight.keyAt(i);
@@ -519,9 +465,6 @@
}
fout.println();
- // TODO(b/249950069): Consider removing issue cache APIs from SafetyCenterDataTracker
- mSafetyCenterIssueCache.dump(fout);
-
int actionInFlightCount = mSafetyCenterIssueActionsInFlight.size();
fout.println("ACTIONS IN FLIGHT (" + actionInFlightCount + ")");
for (int i = 0; i < actionInFlightCount; i++) {
diff --git a/service/java/com/android/safetycenter/SafetyCenterService.java b/service/java/com/android/safetycenter/SafetyCenterService.java
index d5486d4..22f3985 100644
--- a/service/java/com/android/safetycenter/SafetyCenterService.java
+++ b/service/java/com/android/safetycenter/SafetyCenterService.java
@@ -147,6 +147,7 @@
private final SafetyCenterDataTracker mSafetyCenterDataTracker;
@GuardedBy("mApiLock")
+ @NonNull
private final SafetyCenterListeners mSafetyCenterListeners;
@GuardedBy("mApiLock")
@@ -154,6 +155,10 @@
@GuardedBy("mApiLock")
@NonNull
+ private final SafetyCenterIssueCache mSafetyCenterIssueCache;
+
+ @GuardedBy("mApiLock")
+ @NonNull
private final SafetyCenterBroadcastDispatcher mSafetyCenterBroadcastDispatcher;
@NonNull private final AppOpsManager mAppOpsManager;
@@ -168,6 +173,7 @@
mSafetyCenterConfigReader = new SafetyCenterConfigReader(mSafetyCenterResourcesContext);
WestworldLogger westworldLogger = new WestworldLogger(context, mSafetyCenterConfigReader);
mSafetyCenterRefreshTracker = new SafetyCenterRefreshTracker(westworldLogger);
+ mSafetyCenterIssueCache = new SafetyCenterIssueCache(mSafetyCenterConfigReader);
mSafetyCenterDataTracker =
new SafetyCenterDataTracker(
context,
@@ -176,7 +182,7 @@
mSafetyCenterRefreshTracker,
westworldLogger,
new PendingIntentFactory(context),
- new SafetyCenterIssueCache(mSafetyCenterConfigReader));
+ mSafetyCenterIssueCache);
mSafetyCenterListeners = new SafetyCenterListeners(mSafetyCenterDataTracker);
mSafetyCenterBroadcastDispatcher =
new SafetyCenterBroadcastDispatcher(
@@ -722,6 +728,7 @@
SafetyCenterFlags.dump(fout);
mSafetyCenterConfigReader.dump(fout);
mSafetyCenterDataTracker.dump(fout);
+ mSafetyCenterIssueCache.dump(fout);
mSafetyCenterRefreshTracker.dump(fout);
mSafetyCenterTimeouts.dump(fout);
mSafetyCenterListeners.dump(fout);
@@ -1040,7 +1047,7 @@
/** Schedule writing the cache to file. */
@GuardedBy("mApiLock")
private void scheduleWriteSafetyCenterIssueCacheFileIfNeededLocked() {
- if (!mSafetyCenterDataTracker.isSafetyCenterIssueCacheDirty()) {
+ if (!mSafetyCenterIssueCache.isDirty()) {
return;
}
if (!mSafetyCenterIssueCacheWriteScheduled) {
@@ -1056,7 +1063,7 @@
synchronized (mApiLock) {
mSafetyCenterIssueCacheWriteScheduled = false;
- persistedSafetyCenterIssues = mSafetyCenterDataTracker.snapshotSafetyCenterIssueCache();
+ persistedSafetyCenterIssues = mSafetyCenterIssueCache.snapshot();
// Since all write operations are scheduled in the same background thread, we can safely
// release the lock after creating a snapshot and know that all snapshots will be
// written in the correct order even if we are not holding the lock.
@@ -1078,7 +1085,7 @@
Log.e(TAG, "Cannot read Safety Center persisted issues", e);
}
- mSafetyCenterDataTracker.loadSafetyCenterIssueCache(persistedSafetyCenterIssues);
+ mSafetyCenterIssueCache.load(persistedSafetyCenterIssues);
scheduleWriteSafetyCenterIssueCacheFileIfNeededLocked();
}