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

Commit 2e4f8759 authored by Ivan Chiang's avatar Ivan Chiang
Browse files

[PM] Add app snippet on some unarchive error dialogs

Flag: android.content.pm.use_pia_v2
Test: manual
Bug: 274120822
Change-Id: Ibb97d7b8a1948b7a9523295412751a6919d3a6e6
parent ec09e15b
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? }
}
+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 -> {
+1 −0
Original line number Diff line number Diff line
@@ -1282,6 +1282,7 @@ public class PackageArchiver {
            // Error already logged.
            return null;
        }
        dialogIntent.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, appPackageName);
        dialogIntent.putExtra(EXTRA_INSTALLER_TITLE, installerTitle);
        return dialogIntent;
    }