diff options
| author | 2022-02-17 18:32:07 +0000 | |
|---|---|---|
| committer | 2022-02-17 18:32:07 +0000 | |
| commit | 3d0c48b78a85567143834afb40b74a595fd8a95e (patch) | |
| tree | bc124fd1591613ea7db2636586627f2c8dc1b54d | |
| parent | 3a3a407c172fbe15e252f663ac557a00c6bd0787 (diff) | |
| parent | 07a5930852864683d383fe4b3c5410bd8c64d40b (diff) | |
Merge "Handle static safety sources in collapsible group."
| -rw-r--r-- | service/java/com/android/safetycenter/SafetyCenterDataTracker.java | 82 |
1 files changed, 48 insertions, 34 deletions
diff --git a/service/java/com/android/safetycenter/SafetyCenterDataTracker.java b/service/java/com/android/safetycenter/SafetyCenterDataTracker.java index 91dfa74dc..beffd9d08 100644 --- a/service/java/com/android/safetycenter/SafetyCenterDataTracker.java +++ b/service/java/com/android/safetycenter/SafetyCenterDataTracker.java @@ -349,45 +349,59 @@ final class SafetyCenterDataTracker { @Nullable private SafetyCenterEntry toSafetyCenterEntry(@NonNull SafetySource safetySource, @UserIdInt int userId) { - if (safetySource.getType() == SafetySource.SAFETY_SOURCE_TYPE_ISSUE_ONLY) { - Log.w(TAG, "Issue only safety source found in collapsible group"); - return null; - } - - Key key = Key.of(safetySource.getId(), safetySource.getPackageName(), userId); - SafetySourceStatus safetySourceStatus = getSafetySourceStatus( - mSafetySourceDataForKey.get(key)); - SafetyCenterEntry.Builder safetyCenterEntryBuilder = new SafetyCenterEntry.Builder( - safetySource.getId()); - // TODO(b/218817233): Add missing fields like: iconAction, statelessIconType. - if (safetySourceStatus != null) { - safetyCenterEntryBuilder - .setSeverityLevel(sourceToSafetyCenterEntrySeverityLevel( - safetySourceStatus.getStatusLevel())) - .setTitle(safetySourceStatus.getTitle()) - .setSummary(safetySourceStatus.getSummary()) - .setEnabled(safetySourceStatus.isEnabled()) - .setPendingIntent(safetySourceStatus.getPendingIntent()); - } else { - PendingIntent pendingIntent = toPendingIntent(safetySource.getIntentAction(), - safetySource.getPackageName()); - if (pendingIntent == null) { - // TODO(b/218817241): We may make the PendingIntent nullable, in which case - // we won't want to skip here. + switch (safetySource.getType()) { + case SafetySource.SAFETY_SOURCE_TYPE_ISSUE_ONLY: { + Log.w(TAG, "Issue only safety source found in collapsible group"); return null; } + case SafetySource.SAFETY_SOURCE_TYPE_DYNAMIC: { + Key key = Key.of(safetySource.getId(), safetySource.getPackageName(), userId); + SafetySourceStatus safetySourceStatus = getSafetySourceStatus( + mSafetySourceDataForKey.get(key)); + // TODO(b/218817233): Add missing fields like: iconAction, statelessIconType. + if (safetySourceStatus != null) { + return new SafetyCenterEntry.Builder(safetySource.getId()) + .setSeverityLevel(sourceToSafetyCenterEntrySeverityLevel( + safetySourceStatus.getStatusLevel())) + .setTitle(safetySourceStatus.getTitle()) + .setSummary(safetySourceStatus.getSummary()) + .setEnabled(safetySourceStatus.isEnabled()) + .setPendingIntent(safetySourceStatus.getPendingIntent()).build(); + } + return toDefaultSafetyCenterEntry(safetySource, safetySource.getPackageName(), + SafetyCenterEntry.ENTRY_SEVERITY_LEVEL_NONE); + } + case SafetySource.SAFETY_SOURCE_TYPE_STATIC: { + return toDefaultSafetyCenterEntry(safetySource, null, + SafetyCenterEntry.ENTRY_SEVERITY_LEVEL_UNKNOWN); + } + } + Log.w(TAG, String.format("Unknown safety source type found in collapsible group: %s", + safetySource.getType())); + return null; + } - // TODO(b/218817233): Add missing fields like: enabled. - safetyCenterEntryBuilder - .setSeverityLevel(SafetyCenterEntry.ENTRY_SEVERITY_LEVEL_NONE) - .setTitle(mSafetyCenterConfigReader.readStringResource( - safetySource.getTitleResId())) - .setSummary(mSafetyCenterConfigReader.readStringResource( - safetySource.getSummaryResId())) - .setPendingIntent(pendingIntent); + @Nullable + private SafetyCenterEntry toDefaultSafetyCenterEntry( + @NonNull SafetySource safetySource, + @Nullable String packageName, + @SafetyCenterEntry.EntrySeverityLevel int entrySeverityLevel) { + PendingIntent pendingIntent = toPendingIntent(safetySource.getIntentAction(), packageName); + + if (pendingIntent == null) { + // TODO(b/218817241): We may make the PendingIntent nullable, in which case + // we won't want to skip here. + return null; } - return safetyCenterEntryBuilder.build(); + // TODO(b/218817233): Add missing fields like: enabled. + return new SafetyCenterEntry.Builder(safetySource.getId()) + .setSeverityLevel(entrySeverityLevel) + .setTitle(mSafetyCenterConfigReader.readStringResource( + safetySource.getTitleResId())) + .setSummary(mSafetyCenterConfigReader.readStringResource( + safetySource.getSummaryResId())) + .setPendingIntent(pendingIntent).build(); } private void addSafetyCenterStaticEntryGroup( |