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

Commit e865626d authored by Sumedh Sen's avatar Sumedh Sen
Browse files

Replace AlertController with AlertDialog

To better support OEMs UI customization, use the standard AlertDialog
instead of the internal variant of AlertController

Bug: 297132020
Test: Install any APK

Change-Id: I2e60ec74dc603edba03d0cf5f466d2bf00b1f1af
parent 7ce1881a
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -81,6 +81,7 @@
            android:exported="false" />
            android:exported="false" />


        <activity android:name=".PackageInstallerActivity"
        <activity android:name=".PackageInstallerActivity"
                  android:theme="@style/Theme.AlertDialogActivity.NoAnimation"
                  android:exported="false" />
                  android:exported="false" />


        <activity android:name=".InstallInstalling"
        <activity android:name=".InstallInstalling"
+2 −2
Original line number Original line Diff line number Diff line
@@ -32,8 +32,8 @@
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowNoTitle">true</item>
    </style>
    </style>


    <style name="Theme.AlertDialogActivity.NoDim">
    <style name="Theme.AlertDialogActivity.NoDim"
        <item name="android:windowNoTitle">true</item>
        parent="@style/Theme.AlertDialogActivity.NoActionBar">
        <item name="android:backgroundDimAmount">0</item>
        <item name="android:backgroundDimAmount">0</item>
    </style>
    </style>


+20 −12
Original line number Original line Diff line number Diff line
@@ -36,12 +36,14 @@ import androidx.annotation.Nullable;
/**
/**
 * Installation failed: Return status code to the caller or display failure UI to user
 * Installation failed: Return status code to the caller or display failure UI to user
 */
 */
public class InstallFailed extends AlertActivity {
public class InstallFailed extends Activity {
    private static final String LOG_TAG = InstallFailed.class.getSimpleName();
    private static final String LOG_TAG = InstallFailed.class.getSimpleName();


    /** Label of the app that failed to install */
    /** Label of the app that failed to install */
    private CharSequence mLabel;
    private CharSequence mLabel;


    private AlertDialog mDialog;

    /**
    /**
     * Unhide the appropriate label for the statusCode.
     * Unhide the appropriate label for the statusCode.
     *
     *
@@ -53,19 +55,19 @@ public class InstallFailed extends AlertActivity {
        View viewToEnable;
        View viewToEnable;
        switch (statusCode) {
        switch (statusCode) {
            case PackageInstaller.STATUS_FAILURE_BLOCKED:
            case PackageInstaller.STATUS_FAILURE_BLOCKED:
                viewToEnable = requireViewById(R.id.install_failed_blocked);
                viewToEnable = mDialog.requireViewById(R.id.install_failed_blocked);
                break;
                break;
            case PackageInstaller.STATUS_FAILURE_CONFLICT:
            case PackageInstaller.STATUS_FAILURE_CONFLICT:
                viewToEnable = requireViewById(R.id.install_failed_conflict);
                viewToEnable = mDialog.requireViewById(R.id.install_failed_conflict);
                break;
                break;
            case PackageInstaller.STATUS_FAILURE_INCOMPATIBLE:
            case PackageInstaller.STATUS_FAILURE_INCOMPATIBLE:
                viewToEnable = requireViewById(R.id.install_failed_incompatible);
                viewToEnable = mDialog.requireViewById(R.id.install_failed_incompatible);
                break;
                break;
            case PackageInstaller.STATUS_FAILURE_INVALID:
            case PackageInstaller.STATUS_FAILURE_INVALID:
                viewToEnable = requireViewById(R.id.install_failed_invalid_apk);
                viewToEnable = mDialog.requireViewById(R.id.install_failed_invalid_apk);
                break;
                break;
            default:
            default:
                viewToEnable = requireViewById(R.id.install_failed);
                viewToEnable = mDialog.requireViewById(R.id.install_failed);
                break;
                break;
        }
        }


@@ -105,12 +107,18 @@ public class InstallFailed extends AlertActivity {
            // Store label for dialog
            // Store label for dialog
            mLabel = as.label;
            mLabel = as.label;


            mAlert.setIcon(as.icon);
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            mAlert.setTitle(as.label);

            mAlert.setView(R.layout.install_content_view);
            builder.setIcon(as.icon);
            mAlert.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.done),
            builder.setTitle(as.label);
                    (ignored, ignored2) -> finish(), null);
            builder.setView(R.layout.install_content_view);
            setupAlert();
            builder.setPositiveButton(getString(R.string.done),
                    (ignored, ignored2) -> finish());
            builder.setOnCancelListener(dialog -> {
                finish();
            });
            mDialog = builder.create();
            mDialog.show();


            // Show out of space dialog if needed
            // Show out of space dialog if needed
            if (statusCode == PackageInstaller.STATUS_FAILURE_STORAGE) {
            if (statusCode == PackageInstaller.STATUS_FAILURE_STORAGE) {
+17 −9
Original line number Original line Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.packageinstaller;
import static com.android.packageinstaller.PackageInstallerActivity.EXTRA_APP_SNIPPET;
import static com.android.packageinstaller.PackageInstallerActivity.EXTRA_APP_SNIPPET;
import static com.android.packageinstaller.PackageInstallerActivity.EXTRA_STAGED_SESSION_ID;
import static com.android.packageinstaller.PackageInstallerActivity.EXTRA_STAGED_SESSION_ID;


import android.app.Activity;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Intent;
@@ -43,7 +45,7 @@ import java.io.IOException;
 * <p>This has two phases: First send the data to the package manager, then wait until the package
 * <p>This has two phases: First send the data to the package manager, then wait until the package
 * manager processed the result.</p>
 * manager processed the result.</p>
 */
 */
public class InstallInstalling extends AlertActivity {
public class InstallInstalling extends Activity {
    private static final String LOG_TAG = InstallInstalling.class.getSimpleName();
    private static final String LOG_TAG = InstallInstalling.class.getSimpleName();


    private static final String SESSION_ID = "com.android.packageinstaller.SESSION_ID";
    private static final String SESSION_ID = "com.android.packageinstaller.SESSION_ID";
@@ -67,6 +69,8 @@ public class InstallInstalling extends AlertActivity {
    /** The button that can cancel this dialog */
    /** The button that can cancel this dialog */
    private Button mCancelButton;
    private Button mCancelButton;


    private AlertDialog mDialog;

    @Override
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
@@ -90,10 +94,12 @@ public class InstallInstalling extends AlertActivity {
            PackageUtil.AppSnippet as = getIntent()
            PackageUtil.AppSnippet as = getIntent()
                    .getParcelableExtra(EXTRA_APP_SNIPPET, PackageUtil.AppSnippet.class);
                    .getParcelableExtra(EXTRA_APP_SNIPPET, PackageUtil.AppSnippet.class);


            mAlert.setIcon(as.icon);
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            mAlert.setTitle(as.label);

            mAlert.setView(R.layout.install_content_view);
            builder.setIcon(as.icon);
            mAlert.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel),
            builder.setTitle(as.label);
            builder.setView(R.layout.install_content_view);
            builder.setNegativeButton(getString(R.string.cancel),
                    (ignored, ignored2) -> {
                    (ignored, ignored2) -> {
                        if (mInstallingTask != null) {
                        if (mInstallingTask != null) {
                            mInstallingTask.cancel(true);
                            mInstallingTask.cancel(true);
@@ -106,9 +112,11 @@ public class InstallInstalling extends AlertActivity {


                        setResult(RESULT_CANCELED);
                        setResult(RESULT_CANCELED);
                        finish();
                        finish();
                    }, null);
                    });
            setupAlert();
            builder.setCancelable(false);
            requireViewById(R.id.installing).setVisibility(View.VISIBLE);
            mDialog = builder.create();
            mDialog.show();
            mDialog.requireViewById(R.id.installing).setVisibility(View.VISIBLE);


            if (savedInstanceState != null) {
            if (savedInstanceState != null) {
                mSessionId = savedInstanceState.getInt(SESSION_ID);
                mSessionId = savedInstanceState.getInt(SESSION_ID);
@@ -145,7 +153,7 @@ public class InstallInstalling extends AlertActivity {
                }
                }
            }
            }


            mCancelButton = mAlert.getButton(DialogInterface.BUTTON_NEGATIVE);
            mCancelButton = mDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
        }
        }
    }
    }


+28 −10
Original line number Original line Diff line number Diff line
@@ -52,7 +52,7 @@ import java.io.OutputStream;
 * If a package gets installed from a content URI this step stages the installation session
 * If a package gets installed from a content URI this step stages the installation session
 * reading bytes from the URI.
 * reading bytes from the URI.
 */
 */
public class InstallStaging extends AlertActivity {
public class InstallStaging extends Activity {
    private static final String LOG_TAG = InstallStaging.class.getSimpleName();
    private static final String LOG_TAG = InstallStaging.class.getSimpleName();


    private static final String STAGED_SESSION_ID = "STAGED_SESSION_ID";
    private static final String STAGED_SESSION_ID = "STAGED_SESSION_ID";
@@ -65,6 +65,8 @@ public class InstallStaging extends AlertActivity {
    /** The session the package is in */
    /** The session the package is in */
    private int mStagedSessionId;
    private int mStagedSessionId;


    private AlertDialog mDialog;

    @Override
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
@@ -72,10 +74,13 @@ public class InstallStaging extends AlertActivity {
        mInstaller = getPackageManager().getPackageInstaller();
        mInstaller = getPackageManager().getPackageInstaller();


        setFinishOnTouchOutside(true);
        setFinishOnTouchOutside(true);
        mAlert.setIcon(R.drawable.ic_file_download);

        mAlert.setTitle(getString(R.string.app_name_unknown));
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        mAlert.setView(R.layout.install_content_view);

        mAlert.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel),
        builder.setIcon(R.drawable.ic_file_download);
        builder.setTitle(getString(R.string.app_name_unknown));
        builder.setView(R.layout.install_content_view);
        builder.setNegativeButton(getString(R.string.cancel),
                (ignored, ignored2) -> {
                (ignored, ignored2) -> {
                    if (mStagingTask != null) {
                    if (mStagingTask != null) {
                        mStagingTask.cancel(true);
                        mStagingTask.cancel(true);
@@ -85,9 +90,21 @@ public class InstallStaging extends AlertActivity {


                    setResult(RESULT_CANCELED);
                    setResult(RESULT_CANCELED);
                    finish();
                    finish();
                }, null);
                });
        setupAlert();
        builder.setOnCancelListener(dialog -> {
        requireViewById(R.id.staging).setVisibility(View.VISIBLE);
            if (mStagingTask != null) {
                mStagingTask.cancel(true);
            }

            cleanupStagingSession();

            setResult(RESULT_CANCELED);
            finish();
        });
        mDialog = builder.create();
        mDialog.show();
        mDialog.requireViewById(com.android.packageinstaller.R.id.staging)
            .setVisibility(View.VISIBLE);


        if (savedInstanceState != null) {
        if (savedInstanceState != null) {
            mStagedSessionId = savedInstanceState.getInt(STAGED_SESSION_ID, 0);
            mStagedSessionId = savedInstanceState.getInt(STAGED_SESSION_ID, 0);
@@ -275,8 +292,9 @@ public class InstallStaging extends AlertActivity {
        @Override
        @Override
        protected void onPreExecute() {
        protected void onPreExecute() {
            final long sizeBytes = getContentSizeBytes();
            final long sizeBytes = getContentSizeBytes();

            if (sizeBytes > 0 && mDialog != null) {
            mProgressBar = sizeBytes > 0 ? requireViewById(R.id.progress_indeterminate) : null;
                mProgressBar = mDialog.requireViewById(R.id.progress_indeterminate);
            }
            if (mProgressBar != null) {
            if (mProgressBar != null) {
                mProgressBar.setProgress(0);
                mProgressBar.setProgress(0);
                mProgressBar.setMax(100);
                mProgressBar.setMax(100);
Loading