1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.systemui.statusbar.phone 16 17 import android.app.PendingIntent 18 import android.content.Intent 19 import android.os.Bundle 20 import android.os.UserHandle 21 import android.view.View 22 import com.android.systemui.animation.ActivityTransitionAnimator 23 import com.android.systemui.dagger.SysUISingleton 24 import com.android.systemui.dagger.qualifiers.Main 25 import com.android.systemui.plugins.ActivityStarter 26 import com.android.systemui.plugins.ActivityStarter.OnDismissAction 27 import com.android.systemui.statusbar.SysuiStatusBarStateController 28 import com.android.systemui.util.concurrency.DelayableExecutor 29 import dagger.Lazy 30 import javax.inject.Inject 31 32 /** Handles start activity logic in SystemUI. */ 33 @SysUISingleton 34 class ActivityStarterImpl 35 @Inject 36 constructor( 37 private val statusBarStateController: SysuiStatusBarStateController, 38 @Main private val mainExecutor: DelayableExecutor, 39 legacyActivityStarter: Lazy<LegacyActivityStarterInternalImpl> 40 ) : ActivityStarter { 41 42 private val activityStarterInternal: ActivityStarterInternal = legacyActivityStarter.get() 43 startPendingIntentDismissingKeyguardnull44 override fun startPendingIntentDismissingKeyguard(intent: PendingIntent) { 45 activityStarterInternal.startPendingIntentDismissingKeyguard( 46 intent = intent, 47 dismissShade = true 48 ) 49 } 50 startPendingIntentDismissingKeyguardnull51 override fun startPendingIntentDismissingKeyguard( 52 intent: PendingIntent, 53 intentSentUiThreadCallback: Runnable?, 54 ) { 55 activityStarterInternal.startPendingIntentDismissingKeyguard( 56 intent = intent, 57 intentSentUiThreadCallback = intentSentUiThreadCallback, 58 dismissShade = true, 59 ) 60 } 61 startPendingIntentDismissingKeyguardnull62 override fun startPendingIntentDismissingKeyguard( 63 intent: PendingIntent, 64 intentSentUiThreadCallback: Runnable?, 65 associatedView: View?, 66 ) { 67 activityStarterInternal.startPendingIntentDismissingKeyguard( 68 intent = intent, 69 intentSentUiThreadCallback = intentSentUiThreadCallback, 70 associatedView = associatedView, 71 dismissShade = true, 72 ) 73 } 74 startPendingIntentDismissingKeyguardnull75 override fun startPendingIntentDismissingKeyguard( 76 intent: PendingIntent, 77 intentSentUiThreadCallback: Runnable?, 78 animationController: ActivityTransitionAnimator.Controller?, 79 ) { 80 activityStarterInternal.startPendingIntentDismissingKeyguard( 81 intent = intent, 82 intentSentUiThreadCallback = intentSentUiThreadCallback, 83 animationController = animationController, 84 dismissShade = true, 85 ) 86 } 87 startPendingIntentWithoutDismissingnull88 override fun startPendingIntentWithoutDismissing( 89 intent: PendingIntent, 90 dismissShade: Boolean, 91 intentSentUiThreadCallback: Runnable?, 92 animationController: ActivityTransitionAnimator.Controller?, 93 fillInIntent: Intent?, 94 extraOptions: Bundle? 95 ) { 96 activityStarterInternal.startPendingIntentDismissingKeyguard( 97 intent = intent, 98 intentSentUiThreadCallback = intentSentUiThreadCallback, 99 animationController = animationController, 100 showOverLockscreen = true, 101 skipLockscreenChecks = true, 102 dismissShade = dismissShade, 103 fillInIntent = fillInIntent, 104 extraOptions = extraOptions, 105 ) 106 } 107 startPendingIntentMaybeDismissingKeyguardnull108 override fun startPendingIntentMaybeDismissingKeyguard( 109 intent: PendingIntent, 110 intentSentUiThreadCallback: Runnable?, 111 animationController: ActivityTransitionAnimator.Controller? 112 ) { 113 activityStarterInternal.startPendingIntentDismissingKeyguard( 114 intent = intent, 115 intentSentUiThreadCallback = intentSentUiThreadCallback, 116 animationController = animationController, 117 showOverLockscreen = true, 118 dismissShade = true, 119 ) 120 } 121 startPendingIntentMaybeDismissingKeyguardnull122 override fun startPendingIntentMaybeDismissingKeyguard( 123 intent: PendingIntent, 124 dismissShade: Boolean, 125 intentSentUiThreadCallback: Runnable?, 126 animationController: ActivityTransitionAnimator.Controller?, 127 fillInIntent: Intent?, 128 extraOptions: Bundle?, 129 ) { 130 activityStarterInternal.startPendingIntentDismissingKeyguard( 131 intent = intent, 132 intentSentUiThreadCallback = intentSentUiThreadCallback, 133 animationController = animationController, 134 showOverLockscreen = true, 135 dismissShade = dismissShade, 136 fillInIntent = fillInIntent, 137 extraOptions = extraOptions, 138 ) 139 } 140 141 /** 142 * TODO(b/279084380): Change callers to just call startActivityDismissingKeyguard and deprecate 143 * this. 144 */ startActivitynull145 override fun startActivity(intent: Intent, dismissShade: Boolean) { 146 activityStarterInternal.startActivityDismissingKeyguard( 147 intent = intent, 148 dismissShade = dismissShade, 149 ) 150 } 151 152 /** 153 * TODO(b/279084380): Change callers to just call startActivityDismissingKeyguard and deprecate 154 * this. 155 */ startActivitynull156 override fun startActivity(intent: Intent, onlyProvisioned: Boolean, dismissShade: Boolean) { 157 activityStarterInternal.startActivityDismissingKeyguard( 158 intent = intent, 159 onlyProvisioned = onlyProvisioned, 160 dismissShade = dismissShade, 161 ) 162 } 163 164 /** 165 * TODO(b/279084380): Change callers to just call startActivityDismissingKeyguard and deprecate 166 * this. 167 */ startActivitynull168 override fun startActivity( 169 intent: Intent, 170 dismissShade: Boolean, 171 callback: ActivityStarter.Callback?, 172 ) { 173 activityStarterInternal.startActivityDismissingKeyguard( 174 intent = intent, 175 dismissShade = dismissShade, 176 callback = callback, 177 ) 178 } 179 180 /** 181 * TODO(b/279084380): Change callers to just call startActivityDismissingKeyguard and deprecate 182 * this. 183 */ startActivitynull184 override fun startActivity( 185 intent: Intent, 186 onlyProvisioned: Boolean, 187 dismissShade: Boolean, 188 flags: Int, 189 ) { 190 activityStarterInternal.startActivityDismissingKeyguard( 191 intent = intent, 192 onlyProvisioned = onlyProvisioned, 193 dismissShade = dismissShade, 194 flags = flags, 195 ) 196 } 197 startActivitynull198 override fun startActivity( 199 intent: Intent, 200 dismissShade: Boolean, 201 animationController: ActivityTransitionAnimator.Controller?, 202 showOverLockscreenWhenLocked: Boolean, 203 ) { 204 activityStarterInternal.startActivity( 205 intent = intent, 206 dismissShade = dismissShade, 207 animationController = animationController, 208 showOverLockscreenWhenLocked = showOverLockscreenWhenLocked, 209 ) 210 } 211 startActivitynull212 override fun startActivity( 213 intent: Intent, 214 dismissShade: Boolean, 215 animationController: ActivityTransitionAnimator.Controller?, 216 showOverLockscreenWhenLocked: Boolean, 217 userHandle: UserHandle?, 218 ) { 219 activityStarterInternal.startActivity( 220 intent = intent, 221 dismissShade = dismissShade, 222 animationController = animationController, 223 showOverLockscreenWhenLocked = showOverLockscreenWhenLocked, 224 userHandle = userHandle, 225 ) 226 } 227 postStartActivityDismissingKeyguardnull228 override fun postStartActivityDismissingKeyguard(intent: PendingIntent) { 229 postOnUiThread { 230 activityStarterInternal.startPendingIntentDismissingKeyguard( 231 intent = intent, 232 dismissShade = true, 233 ) 234 } 235 } 236 postStartActivityDismissingKeyguardnull237 override fun postStartActivityDismissingKeyguard( 238 intent: PendingIntent, 239 animationController: ActivityTransitionAnimator.Controller? 240 ) { 241 postOnUiThread { 242 activityStarterInternal.startPendingIntentDismissingKeyguard( 243 intent = intent, 244 animationController = animationController, 245 dismissShade = true, 246 ) 247 } 248 } 249 postStartActivityDismissingKeyguardnull250 override fun postStartActivityDismissingKeyguard(intent: Intent, delay: Int) { 251 postOnUiThread(delay) { 252 activityStarterInternal.startActivityDismissingKeyguard( 253 intent = intent, 254 onlyProvisioned = true, 255 dismissShade = true, 256 ) 257 } 258 } 259 postStartActivityDismissingKeyguardnull260 override fun postStartActivityDismissingKeyguard( 261 intent: Intent, 262 delay: Int, 263 animationController: ActivityTransitionAnimator.Controller?, 264 ) { 265 postOnUiThread(delay) { 266 activityStarterInternal.startActivityDismissingKeyguard( 267 intent = intent, 268 onlyProvisioned = true, 269 dismissShade = true, 270 animationController = animationController, 271 ) 272 } 273 } 274 postStartActivityDismissingKeyguardnull275 override fun postStartActivityDismissingKeyguard( 276 intent: Intent, 277 delay: Int, 278 animationController: ActivityTransitionAnimator.Controller?, 279 customMessage: String?, 280 ) { 281 postOnUiThread(delay) { 282 activityStarterInternal.startActivityDismissingKeyguard( 283 intent = intent, 284 onlyProvisioned = true, 285 dismissShade = true, 286 animationController = animationController, 287 customMessage = customMessage, 288 ) 289 } 290 } 291 dismissKeyguardThenExecutenull292 override fun dismissKeyguardThenExecute( 293 action: OnDismissAction, 294 cancel: Runnable?, 295 afterKeyguardGone: Boolean, 296 ) { 297 activityStarterInternal.dismissKeyguardThenExecute( 298 action = action, 299 cancel = cancel, 300 afterKeyguardGone = afterKeyguardGone, 301 ) 302 } 303 dismissKeyguardThenExecutenull304 override fun dismissKeyguardThenExecute( 305 action: OnDismissAction, 306 cancel: Runnable?, 307 afterKeyguardGone: Boolean, 308 customMessage: String?, 309 ) { 310 activityStarterInternal.dismissKeyguardThenExecute( 311 action = action, 312 cancel = cancel, 313 afterKeyguardGone = afterKeyguardGone, 314 customMessage = customMessage, 315 ) 316 } 317 startActivityDismissingKeyguardnull318 override fun startActivityDismissingKeyguard( 319 intent: Intent, 320 onlyProvisioned: Boolean, 321 dismissShade: Boolean, 322 ) { 323 activityStarterInternal.startActivityDismissingKeyguard( 324 intent = intent, 325 onlyProvisioned = onlyProvisioned, 326 dismissShade = dismissShade, 327 ) 328 } 329 startActivityDismissingKeyguardnull330 override fun startActivityDismissingKeyguard( 331 intent: Intent, 332 onlyProvisioned: Boolean, 333 dismissShade: Boolean, 334 disallowEnterPictureInPictureWhileLaunching: Boolean, 335 callback: ActivityStarter.Callback?, 336 flags: Int, 337 animationController: ActivityTransitionAnimator.Controller?, 338 userHandle: UserHandle?, 339 ) { 340 activityStarterInternal.startActivityDismissingKeyguard( 341 intent = intent, 342 onlyProvisioned = onlyProvisioned, 343 dismissShade = dismissShade, 344 disallowEnterPictureInPictureWhileLaunching = 345 disallowEnterPictureInPictureWhileLaunching, 346 callback = callback, 347 flags = flags, 348 animationController = animationController, 349 userHandle = userHandle, 350 ) 351 } 352 executeRunnableDismissingKeyguardnull353 override fun executeRunnableDismissingKeyguard( 354 runnable: Runnable?, 355 cancelAction: Runnable?, 356 dismissShade: Boolean, 357 afterKeyguardGone: Boolean, 358 deferred: Boolean, 359 ) { 360 activityStarterInternal.executeRunnableDismissingKeyguard( 361 runnable = runnable, 362 cancelAction = cancelAction, 363 dismissShade = dismissShade, 364 afterKeyguardGone = afterKeyguardGone, 365 deferred = deferred, 366 ) 367 } 368 postQSRunnableDismissingKeyguardnull369 override fun postQSRunnableDismissingKeyguard(runnable: Runnable?) { 370 postOnUiThread { 371 statusBarStateController.setLeaveOpenOnKeyguardHide(true) 372 activityStarterInternal.executeRunnableDismissingKeyguard( 373 runnable = { runnable?.let { postOnUiThread(runnable = it) } }, 374 ) 375 } 376 } 377 shouldAnimateLaunchnull378 override fun shouldAnimateLaunch(isActivityIntent: Boolean): Boolean { 379 return activityStarterInternal.shouldAnimateLaunch(isActivityIntent) 380 } 381 postOnUiThreadnull382 private fun postOnUiThread(delay: Int = 0, runnable: Runnable) { 383 mainExecutor.executeDelayed(runnable, delay.toLong()) 384 } 385 } 386