Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae7c1bed authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ibb97d7b8,I4780d48a into main

* changes:
  [PM] Add app snippet on some unarchive error dialogs
  [PM] Add app snippet on the uninstallation error dialogs
parents 8a2338cc 2e4f8759
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -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) {
@@ -196,7 +211,8 @@ class UnarchiveRepository(private val context: Context) {
            installerPackageName,
            installerAppTitle,
            requiredBytes,
            pendingIntent
            pendingIntent,
            appSnippet
        )
    }

+9 −2
Original line number Diff line number Diff line
@@ -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? }
}
+30 −25
Original line number Diff line number Diff line
@@ -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

@@ -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)
@@ -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)
@@ -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)
+10 −2
Original line number Diff line number Diff line
@@ -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 -> {
+12 −0
Original line number Diff line number Diff line
@@ -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 -> {
@@ -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