diff options
author | 2022-12-07 15:17:38 +0000 | |
---|---|---|
committer | 2022-12-07 15:17:38 +0000 | |
commit | 99badceabd585e1b0a8cd519ada884fd8a1e245f (patch) | |
tree | 720e4d545e0c7a5c13ea1db7f6ca848566b7e4c5 | |
parent | 238a76a77d5a3fb3d114299b0af612f24cca6674 (diff) | |
parent | ef9444d6c651bf5a44797c6982faf80156ca1f55 (diff) |
[automerge] Make executeIssueActionInternal method 2p: ef9444d6c6
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Permission/+/20665586
Bug: 260084296
Change-Id: I597b9bb77c0e1ee7ee8a83155fa79513cff48e51
-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 42ec63621..8d6449f92 100644 --- a/service/java/com/android/safetycenter/SafetyCenterService.java +++ b/service/java/com/android/safetycenter/SafetyCenterService.java @@ -572,56 +572,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 @@ -744,26 +698,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, @@ -1078,6 +1012,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() { |