Loading packages/PackageInstaller/src/com/android/packageinstaller/v2/model/UnarchiveRepository.kt +17 −1 Original line number Diff line number Diff line Loading @@ -146,6 +146,21 @@ class UnarchiveRepository(private val context: Context) { Intent.EXTRA_INTENT, PendingIntent::class.java ) val appPackageName = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME) var appSnippet: PackageUtil.AppSnippet? = null if (appPackageName != null) { try { val applicationInfo = packageManager.getApplicationInfo( appPackageName, PackageManager.ApplicationInfoFlags.of(PackageManager.MATCH_ARCHIVED_PACKAGES) ) appSnippet = getAppSnippet(context, applicationInfo) } catch (e: NameNotFoundException) { Log.e(LOG_TAG, "Invalid packageName $appPackageName: ", e) } } when (unarchivalStatus) { PackageInstaller.UNARCHIVAL_ERROR_USER_ACTION_NEEDED -> { if (pendingIntent == null) { Loading Loading @@ -196,7 +211,8 @@ class UnarchiveRepository(private val context: Context) { installerPackageName, installerAppTitle, requiredBytes, pendingIntent pendingIntent, appSnippet ) } Loading packages/PackageInstaller/src/com/android/packageinstaller/v2/model/UnarchiveStages.kt +9 −2 Original line number Diff line number Diff line Loading @@ -60,5 +60,12 @@ data class UnarchiveError( val installerPackageName: String?, val installerAppTitle: String?, val requiredBytes: Long, val pendingIntent: PendingIntent? ) : UnarchiveStage(STAGE_ERROR) val pendingIntent: PendingIntent?, val appSnippet: PackageUtil.AppSnippet? = null ) : UnarchiveStage(STAGE_ERROR) { val appIcon: Drawable? get() = appSnippet?.icon val appLabel: String? get() = appSnippet?.let { appSnippet.label as String? } } packages/PackageInstaller/src/com/android/packageinstaller/v2/model/UninstallRepository.kt +30 −25 Original line number Diff line number Diff line Loading @@ -54,7 +54,6 @@ import com.android.packageinstaller.v2.model.PackageUtil.getMaxTargetSdkVersionF import com.android.packageinstaller.v2.model.PackageUtil.getPackageNameForUid import com.android.packageinstaller.v2.model.PackageUtil.isPermissionGranted import com.android.packageinstaller.v2.model.PackageUtil.isProfileOfOrSame import com.android.packageinstaller.v2.model.UninstallAborted.Companion.ABORT_REASON_UNINSTALL_DONE import android.content.pm.Flags as PmFlags import android.multiuser.Flags as MultiuserFlags Loading Loading @@ -134,10 +133,34 @@ class UninstallRepository(private val context: Context) { return UninstallAborted(UninstallAborted.ABORT_REASON_APP_UNAVAILABLE) } callback = intent.getParcelableExtra( PackageInstaller.EXTRA_CALLBACK, PackageManager.UninstallCompleteCallback::class.java ) try { targetAppInfo = packageManager.getApplicationInfo( targetPackageName!!, ApplicationInfoFlags.of( PackageManager.MATCH_ANY_USER.toLong() or PackageManager.MATCH_ARCHIVED_PACKAGES ) ) } catch (e: PackageManager.NameNotFoundException) { Log.e(LOG_TAG, "Unable to get packageName") } if (targetAppInfo == null) { Log.e(LOG_TAG, "Invalid packageName: $targetPackageName") return UninstallAborted(UninstallAborted.ABORT_REASON_APP_UNAVAILABLE) } uninstallFromAllUsers = intent.getBooleanExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false) if (uninstallFromAllUsers && !userManager!!.isAdminUser) { Log.e(LOG_TAG, "Only admin user can request uninstall for all users") return UninstallAborted(UninstallAborted.ABORT_REASON_USER_NOT_ALLOWED) return UninstallAborted( UninstallAborted.ABORT_REASON_USER_NOT_ALLOWED, getAppSnippet(context, targetAppInfo!!) ) } uninstalledUser = intent.getParcelableExtra(Intent.EXTRA_USER, UserHandle::class.java) Loading @@ -153,30 +176,12 @@ class UninstallRepository(private val context: Context) { "User " + Process.myUserHandle() + " can't request uninstall " + "for user " + uninstalledUser ) return UninstallAborted(UninstallAborted.ABORT_REASON_USER_NOT_ALLOWED) } } } callback = intent.getParcelableExtra( PackageInstaller.EXTRA_CALLBACK, PackageManager.UninstallCompleteCallback::class.java ) try { targetAppInfo = packageManager.getApplicationInfo( targetPackageName!!, ApplicationInfoFlags.of( PackageManager.MATCH_ANY_USER.toLong() or PackageManager.MATCH_ARCHIVED_PACKAGES return UninstallAborted( UninstallAborted.ABORT_REASON_USER_NOT_ALLOWED, getAppSnippet(context, targetAppInfo!!) ) ) } catch (e: PackageManager.NameNotFoundException) { Log.e(LOG_TAG, "Unable to get packageName") } if (targetAppInfo == null) { Log.e(LOG_TAG, "Invalid packageName: $targetPackageName") return UninstallAborted(UninstallAborted.ABORT_REASON_APP_UNAVAILABLE) } } // The class name may have been specified (e.g. when deleting an app from all apps) Loading Loading @@ -533,7 +538,7 @@ class UninstallRepository(private val context: Context) { callback!!.onUninstallComplete(targetPackageName!!, legacyStatus, message) // Since the caller already received the results, just finish the app at this point uninstallResult.value = UninstallAborted(ABORT_REASON_UNINSTALL_DONE) uninstallResult.value = UninstallAborted(UninstallAborted.ABORT_REASON_UNINSTALL_DONE) return } val returnResult = intent.getBooleanExtra(Intent.EXTRA_RETURN_RESULT, false) Loading packages/PackageInstaller/src/com/android/packageinstaller/v2/model/UninstallStages.kt +10 −2 Original line number Diff line number Diff line Loading @@ -84,12 +84,20 @@ data class UninstallFailed( } } data class UninstallAborted(val abortReason: Int) : UninstallStage(STAGE_ABORTED) { data class UninstallAborted( val abortReason: Int, val appSnippet: PackageUtil.AppSnippet? = null ) : UninstallStage(STAGE_ABORTED) { var dialogTitleResource = 0 var dialogTextResource = 0 val activityResultCode = Activity.RESULT_FIRST_USER val appIcon: Drawable? get() = appSnippet?.icon val appLabel: String? get() = appSnippet?.let { appSnippet.label as String? } init { when (abortReason) { ABORT_REASON_APP_UNAVAILABLE -> { Loading packages/PackageInstaller/src/com/android/packageinstaller/v2/ui/fragments/UnarchiveFragment.java +12 −0 Original line number Diff line number Diff line Loading @@ -160,6 +160,12 @@ public class UnarchiveFragment extends DialogFragment { customMessage = getString(R.string.message_restore_error_user_action_needed, installerAppTitle); if (unarchiveStage.getAppIcon() != null) { mAppSnippet.setVisibility(View.VISIBLE); mAppIcon.setImageDrawable(unarchiveStage.getAppIcon()); mAppLabelTextView.setText(unarchiveStage.getAppLabel()); } } case PackageInstaller.UNARCHIVAL_ERROR_INSUFFICIENT_STORAGE -> { Loading @@ -171,6 +177,12 @@ public class UnarchiveFragment extends DialogFragment { getString(R.string.message_restore_error_less_storage), Formatter.formatShortFileSize(requireContext(), requiredBytes)); customMessage = Html.fromHtml(message, Html.FROM_HTML_MODE_LEGACY); if (unarchiveStage.getAppIcon() != null) { mAppSnippet.setVisibility(View.VISIBLE); mAppIcon.setImageDrawable(unarchiveStage.getAppIcon()); mAppLabelTextView.setText(unarchiveStage.getAppLabel()); } } case PackageInstaller.UNARCHIVAL_ERROR_NO_CONNECTIVITY -> { Loading Loading
packages/PackageInstaller/src/com/android/packageinstaller/v2/model/UnarchiveRepository.kt +17 −1 Original line number Diff line number Diff line Loading @@ -146,6 +146,21 @@ class UnarchiveRepository(private val context: Context) { Intent.EXTRA_INTENT, PendingIntent::class.java ) val appPackageName = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME) var appSnippet: PackageUtil.AppSnippet? = null if (appPackageName != null) { try { val applicationInfo = packageManager.getApplicationInfo( appPackageName, PackageManager.ApplicationInfoFlags.of(PackageManager.MATCH_ARCHIVED_PACKAGES) ) appSnippet = getAppSnippet(context, applicationInfo) } catch (e: NameNotFoundException) { Log.e(LOG_TAG, "Invalid packageName $appPackageName: ", e) } } when (unarchivalStatus) { PackageInstaller.UNARCHIVAL_ERROR_USER_ACTION_NEEDED -> { if (pendingIntent == null) { Loading Loading @@ -196,7 +211,8 @@ class UnarchiveRepository(private val context: Context) { installerPackageName, installerAppTitle, requiredBytes, pendingIntent pendingIntent, appSnippet ) } Loading
packages/PackageInstaller/src/com/android/packageinstaller/v2/model/UnarchiveStages.kt +9 −2 Original line number Diff line number Diff line Loading @@ -60,5 +60,12 @@ data class UnarchiveError( val installerPackageName: String?, val installerAppTitle: String?, val requiredBytes: Long, val pendingIntent: PendingIntent? ) : UnarchiveStage(STAGE_ERROR) val pendingIntent: PendingIntent?, val appSnippet: PackageUtil.AppSnippet? = null ) : UnarchiveStage(STAGE_ERROR) { val appIcon: Drawable? get() = appSnippet?.icon val appLabel: String? get() = appSnippet?.let { appSnippet.label as String? } }
packages/PackageInstaller/src/com/android/packageinstaller/v2/model/UninstallRepository.kt +30 −25 Original line number Diff line number Diff line Loading @@ -54,7 +54,6 @@ import com.android.packageinstaller.v2.model.PackageUtil.getMaxTargetSdkVersionF import com.android.packageinstaller.v2.model.PackageUtil.getPackageNameForUid import com.android.packageinstaller.v2.model.PackageUtil.isPermissionGranted import com.android.packageinstaller.v2.model.PackageUtil.isProfileOfOrSame import com.android.packageinstaller.v2.model.UninstallAborted.Companion.ABORT_REASON_UNINSTALL_DONE import android.content.pm.Flags as PmFlags import android.multiuser.Flags as MultiuserFlags Loading Loading @@ -134,10 +133,34 @@ class UninstallRepository(private val context: Context) { return UninstallAborted(UninstallAborted.ABORT_REASON_APP_UNAVAILABLE) } callback = intent.getParcelableExtra( PackageInstaller.EXTRA_CALLBACK, PackageManager.UninstallCompleteCallback::class.java ) try { targetAppInfo = packageManager.getApplicationInfo( targetPackageName!!, ApplicationInfoFlags.of( PackageManager.MATCH_ANY_USER.toLong() or PackageManager.MATCH_ARCHIVED_PACKAGES ) ) } catch (e: PackageManager.NameNotFoundException) { Log.e(LOG_TAG, "Unable to get packageName") } if (targetAppInfo == null) { Log.e(LOG_TAG, "Invalid packageName: $targetPackageName") return UninstallAborted(UninstallAborted.ABORT_REASON_APP_UNAVAILABLE) } uninstallFromAllUsers = intent.getBooleanExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false) if (uninstallFromAllUsers && !userManager!!.isAdminUser) { Log.e(LOG_TAG, "Only admin user can request uninstall for all users") return UninstallAborted(UninstallAborted.ABORT_REASON_USER_NOT_ALLOWED) return UninstallAborted( UninstallAborted.ABORT_REASON_USER_NOT_ALLOWED, getAppSnippet(context, targetAppInfo!!) ) } uninstalledUser = intent.getParcelableExtra(Intent.EXTRA_USER, UserHandle::class.java) Loading @@ -153,30 +176,12 @@ class UninstallRepository(private val context: Context) { "User " + Process.myUserHandle() + " can't request uninstall " + "for user " + uninstalledUser ) return UninstallAborted(UninstallAborted.ABORT_REASON_USER_NOT_ALLOWED) } } } callback = intent.getParcelableExtra( PackageInstaller.EXTRA_CALLBACK, PackageManager.UninstallCompleteCallback::class.java ) try { targetAppInfo = packageManager.getApplicationInfo( targetPackageName!!, ApplicationInfoFlags.of( PackageManager.MATCH_ANY_USER.toLong() or PackageManager.MATCH_ARCHIVED_PACKAGES return UninstallAborted( UninstallAborted.ABORT_REASON_USER_NOT_ALLOWED, getAppSnippet(context, targetAppInfo!!) ) ) } catch (e: PackageManager.NameNotFoundException) { Log.e(LOG_TAG, "Unable to get packageName") } if (targetAppInfo == null) { Log.e(LOG_TAG, "Invalid packageName: $targetPackageName") return UninstallAborted(UninstallAborted.ABORT_REASON_APP_UNAVAILABLE) } } // The class name may have been specified (e.g. when deleting an app from all apps) Loading Loading @@ -533,7 +538,7 @@ class UninstallRepository(private val context: Context) { callback!!.onUninstallComplete(targetPackageName!!, legacyStatus, message) // Since the caller already received the results, just finish the app at this point uninstallResult.value = UninstallAborted(ABORT_REASON_UNINSTALL_DONE) uninstallResult.value = UninstallAborted(UninstallAborted.ABORT_REASON_UNINSTALL_DONE) return } val returnResult = intent.getBooleanExtra(Intent.EXTRA_RETURN_RESULT, false) Loading
packages/PackageInstaller/src/com/android/packageinstaller/v2/model/UninstallStages.kt +10 −2 Original line number Diff line number Diff line Loading @@ -84,12 +84,20 @@ data class UninstallFailed( } } data class UninstallAborted(val abortReason: Int) : UninstallStage(STAGE_ABORTED) { data class UninstallAborted( val abortReason: Int, val appSnippet: PackageUtil.AppSnippet? = null ) : UninstallStage(STAGE_ABORTED) { var dialogTitleResource = 0 var dialogTextResource = 0 val activityResultCode = Activity.RESULT_FIRST_USER val appIcon: Drawable? get() = appSnippet?.icon val appLabel: String? get() = appSnippet?.let { appSnippet.label as String? } init { when (abortReason) { ABORT_REASON_APP_UNAVAILABLE -> { Loading
packages/PackageInstaller/src/com/android/packageinstaller/v2/ui/fragments/UnarchiveFragment.java +12 −0 Original line number Diff line number Diff line Loading @@ -160,6 +160,12 @@ public class UnarchiveFragment extends DialogFragment { customMessage = getString(R.string.message_restore_error_user_action_needed, installerAppTitle); if (unarchiveStage.getAppIcon() != null) { mAppSnippet.setVisibility(View.VISIBLE); mAppIcon.setImageDrawable(unarchiveStage.getAppIcon()); mAppLabelTextView.setText(unarchiveStage.getAppLabel()); } } case PackageInstaller.UNARCHIVAL_ERROR_INSUFFICIENT_STORAGE -> { Loading @@ -171,6 +177,12 @@ public class UnarchiveFragment extends DialogFragment { getString(R.string.message_restore_error_less_storage), Formatter.formatShortFileSize(requireContext(), requiredBytes)); customMessage = Html.fromHtml(message, Html.FROM_HTML_MODE_LEGACY); if (unarchiveStage.getAppIcon() != null) { mAppSnippet.setVisibility(View.VISIBLE); mAppIcon.setImageDrawable(unarchiveStage.getAppIcon()); mAppLabelTextView.setText(unarchiveStage.getAppLabel()); } } case PackageInstaller.UNARCHIVAL_ERROR_NO_CONNECTIVITY -> { Loading