fix: crash when starting home with fade-out remote transition on Android 14+ (#7528)
Co-authored-by: caizhixing <caizhixing@users.noreply.github.com>
This commit is contained in:
1 parent
6c592e7924
commit
f4b71266fa
1 file changed
+15
@@ -25,6 +25,7 @@ import android.content.Intent
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.pm.LauncherActivityInfo
|
||||
import android.content.pm.LauncherApps
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.ShortcutInfo
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Rect
|
||||
@@ -59,6 +60,9 @@ import javax.inject.Inject
|
||||
|
||||
import app.lawnchair.LawnchairApp
|
||||
|
||||
private const val CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS =
|
||||
"android.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS"
|
||||
|
||||
/** A wrapper for the hidden API calls */
|
||||
@LauncherAppSingleton
|
||||
open class SystemApiWrapper @Inject constructor(@ApplicationContext context: Context?) :
|
||||
@@ -75,6 +79,17 @@ open class SystemApiWrapper @Inject constructor(@ApplicationContext context: Con
|
||||
}
|
||||
|
||||
override fun createFadeOutAnimOptions(): ActivityOptions {
|
||||
// Since Android 14, starting an activity with a RemoteTransition in its options
|
||||
// requires the CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS permission, which cannot be
|
||||
// granted to third-party apps; the system throws SecurityException at startActivity
|
||||
// otherwise. Fall back to the default fade-out animation when it isn't held.
|
||||
if (
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE &&
|
||||
mContext.checkSelfPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS) !=
|
||||
PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
return super.createFadeOutAnimOptions()
|
||||
}
|
||||
return try {
|
||||
ActivityOptions.makeBasic().apply {
|
||||
remoteTransition = RemoteTransition(FadeOutRemoteTransition(), "FadeOut")
|
||||
|
||||
Reference in new issue
Block a user