diff options
author | 2022-12-08 08:12:25 +0000 | |
---|---|---|
committer | 2022-12-08 08:12:25 +0000 | |
commit | 003d052167cc924c5df79ad6b8127ea5e4c655ee (patch) | |
tree | e5adead2d33ca41e1c46969f8dcb01c5e0b2d207 | |
parent | eaf3a33999c348ba46628d795a7de1c6732b74b1 (diff) | |
parent | ef9444d6c651bf5a44797c6982faf80156ca1f55 (diff) |
Merge "Make executeIssueActionInternal method" into tm-mainline-prod
-rw-r--r-- | service/java/com/android/safetycenter/SafetyCenterService.java | 146 |
1 files changed, 76 insertions, 70 deletions
diff --git a/service/java/com/android/safetycenter/SafetyCenterService.java b/service/java/com/android/safetycenter/SafetyCenterService.java index 106d8ef8c..2e2d56066 100644 --- a/service/java/com/android/safetycenter/SafetyCenterService.java +++ b/service/java/com/android/safetycenter/SafetyCenterService.java @@ -553,56 +553,10 @@ public final class SafetyCenterService extends SystemService { "executeSafetyCenterIssueAction", userProfileGroup, safetyCenterIssueKey.getUserId()); - synchronized (mApiLock) { - SafetySourceIssue.Action safetySourceIssueAction = - mSafetyCenterRepository.getSafetySourceIssueAction( - safetyCenterIssueActionId); - if (safetySourceIssueAction == null) { - Log.w( - TAG, - "Attempt to execute an issue action that is not provided by the source," - + " that was dismissed, or is already in flight"); - // Don't send the error to the UI here, since it could happen when clicking the - // button multiple times in a row. - return; - } - - Integer taskId = - safetyCenterIssueId.hasTaskId() ? safetyCenterIssueId.getTaskId() : null; - PendingIntent issueActionPendingIntent = - mPendingIntentFactory.maybeOverridePendingIntent( - safetyCenterIssueKey.getSafetySourceId(), - safetySourceIssueAction.getPendingIntent(), - false); - if (!dispatchPendingIntent(issueActionPendingIntent, taskId)) { - Log.w( - TAG, - "Error dispatching action: " - + toUserFriendlyString(safetyCenterIssueActionId)); - CharSequence errorMessage; - if (safetySourceIssueAction.willResolve()) { - errorMessage = - mSafetyCenterResourcesContext.getStringByName( - "resolving_action_error"); - } else { - errorMessage = - mSafetyCenterResourcesContext.getStringByName("redirecting_error"); - } - mSafetyCenterListeners.deliverUpdateForUserProfileGroup( - userProfileGroup, false, new SafetyCenterErrorDetails(errorMessage)); - return; - } - if (safetySourceIssueAction.willResolve()) { - mSafetyCenterRepository.markSafetyCenterIssueActionInFlight( - safetyCenterIssueActionId); - ResolvingActionTimeout resolvingActionTimeout = - new ResolvingActionTimeout(safetyCenterIssueActionId, userProfileGroup); - mSafetyCenterTimeouts.add( - resolvingActionTimeout, SafetyCenterFlags.getResolvingActionTimeout()); - mSafetyCenterListeners.deliverUpdateForUserProfileGroup( - userProfileGroup, true, null); - } - } + Integer taskId = + safetyCenterIssueId.hasTaskId() ? safetyCenterIssueId.getTaskId() : null; + executeIssueActionInternal( + safetyCenterIssueKey, safetyCenterIssueActionId, userProfileGroup, taskId); } @Override @@ -725,26 +679,6 @@ public final class SafetyCenterService extends SystemService { } } - private boolean dispatchPendingIntent( - @NonNull PendingIntent pendingIntent, @Nullable Integer taskId) { - try { - if (taskId != null - && pendingIntent.isActivity() - && getContext().checkCallingOrSelfPermission(START_TASKS_FROM_RECENTS) - == PERMISSION_GRANTED) { - ActivityOptions options = ActivityOptions.makeBasic(); - options.setLaunchTaskId(taskId); - pendingIntent.send(null, 0, null, null, null, null, options.toBundle()); - } else { - pendingIntent.send(); - } - return true; - } catch (PendingIntent.CanceledException ex) { - Log.w(TAG, "Couldn't dispatch PendingIntent", ex); - return false; - } - } - @Override public int handleShellCommand( @NonNull ParcelFileDescriptor in, @@ -1052,6 +986,78 @@ public final class SafetyCenterService extends SystemService { } } + private void executeIssueActionInternal( + @NonNull SafetyCenterIssueKey safetyCenterIssueKey, + @NonNull SafetyCenterIssueActionId safetyCenterIssueActionId, + @NonNull UserProfileGroup userProfileGroup, + @Nullable Integer taskId) { + synchronized (mApiLock) { + SafetySourceIssue.Action safetySourceIssueAction = + mSafetyCenterRepository.getSafetySourceIssueAction(safetyCenterIssueActionId); + if (safetySourceIssueAction == null) { + Log.w( + TAG, + "Attempt to execute an issue action that is not provided by the source," + + " that was dismissed, or is already in flight"); + // Don't send the error to the UI here, since it could happen when clicking the + // button multiple times in a row. + return; + } + PendingIntent issueActionPendingIntent = + mPendingIntentFactory.maybeOverridePendingIntent( + safetyCenterIssueKey.getSafetySourceId(), + safetySourceIssueAction.getPendingIntent(), + false); + if (!dispatchPendingIntent(issueActionPendingIntent, taskId)) { + Log.w( + TAG, + "Error dispatching action: " + + toUserFriendlyString(safetyCenterIssueActionId)); + CharSequence errorMessage; + if (safetySourceIssueAction.willResolve()) { + errorMessage = + mSafetyCenterResourcesContext.getStringByName("resolving_action_error"); + } else { + errorMessage = + mSafetyCenterResourcesContext.getStringByName("redirecting_error"); + } + mSafetyCenterListeners.deliverUpdateForUserProfileGroup( + userProfileGroup, false, new SafetyCenterErrorDetails(errorMessage)); + return; + } + if (safetySourceIssueAction.willResolve()) { + mSafetyCenterRepository.markSafetyCenterIssueActionInFlight( + safetyCenterIssueActionId); + ResolvingActionTimeout resolvingActionTimeout = + new ResolvingActionTimeout(safetyCenterIssueActionId, userProfileGroup); + mSafetyCenterTimeouts.add( + resolvingActionTimeout, SafetyCenterFlags.getResolvingActionTimeout()); + mSafetyCenterListeners.deliverUpdateForUserProfileGroup( + userProfileGroup, true, null); + } + } + } + + private boolean dispatchPendingIntent( + @NonNull PendingIntent pendingIntent, @Nullable Integer taskId) { + try { + if (taskId != null + && pendingIntent.isActivity() + && getContext().checkCallingOrSelfPermission(START_TASKS_FROM_RECENTS) + == PERMISSION_GRANTED) { + ActivityOptions options = ActivityOptions.makeBasic(); + options.setLaunchTaskId(taskId); + pendingIntent.send(null, 0, null, null, null, null, options.toBundle()); + } else { + pendingIntent.send(); + } + return true; + } catch (PendingIntent.CanceledException ex) { + Log.w(TAG, "Couldn't dispatch PendingIntent", ex); + return false; + } + } + /** Schedule writing the cache to file. */ @GuardedBy("mApiLock") private void scheduleWriteSafetyCenterIssueCacheFileIfNeededLocked() { |