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

Commit f054d1d2 authored by Sumedh Sen's avatar Sumedh Sen Committed by Android (Google) Code Review
Browse files

Merge changes from topic "single-update-owner-dialog" into main

* changes:
  [pia v2] Show a user confirmation dialog only when update-ownership isn't changed
  Show a user confirmation dialog only when update-ownership isn't changed
  [piav2] Cleanup CL to prepare for single user-confirmation dialog change
  Cleanup CL to prepare for single user-confirmation dialog change
parents e1d3975e 20c4f7fb
Loading
Loading
Loading
Loading
+31 −28
Original line number Diff line number Diff line
@@ -23,23 +23,23 @@ import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * Installation failed: Return status code to the caller or display failure UI to user
 */
public class InstallFailed extends Activity {

    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 AlertDialog mDialog;
@@ -80,11 +80,13 @@ public class InstallFailed extends Activity {

        setFinishOnTouchOutside(true);

        int statusCode = getIntent().getIntExtra(PackageInstaller.EXTRA_STATUS,
        Intent intent = getIntent();
        int statusCode = intent.getIntExtra(PackageInstaller.EXTRA_STATUS,
            PackageInstaller.STATUS_FAILURE);
        boolean returnResult = intent.getBooleanExtra(Intent.EXTRA_RETURN_RESULT, false);

        if (getIntent().getBooleanExtra(Intent.EXTRA_RETURN_RESULT, false)) {
            int legacyStatus = getIntent().getIntExtra(PackageInstaller.EXTRA_LEGACY_STATUS,
        if (returnResult) {
            int legacyStatus = intent.getIntExtra(PackageInstaller.EXTRA_LEGACY_STATUS,
                PackageManager.INSTALL_FAILED_INTERNAL_ERROR);

            // Return result if requested
@@ -92,17 +94,15 @@ public class InstallFailed extends Activity {
            result.putExtra(Intent.EXTRA_INSTALL_RESULT, legacyStatus);
            setResult(Activity.RESULT_FIRST_USER, result);
            finish();
        } else {
            Intent intent = getIntent();
            ApplicationInfo appInfo = intent
                    .getParcelableExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO);
            Uri packageURI = intent.getData();
        } else if (statusCode != PackageInstaller.STATUS_FAILURE_ABORTED) {
            // statusCode will be STATUS_FAILURE_ABORTED if the update-owner confirmation dialog was
            // dismissed by the user. We don't want to show a InstallFailed dialog in this case.
            // If the user denies install permission for normal installs, this dialog will never be
            // triggered as the status code is returned from PackageInstallerActivity.java

            // Set header icon and title
            PackageUtil.AppSnippet as;
            PackageManager pm = getPackageManager();
            as = intent.getParcelableExtra(PackageInstallerActivity.EXTRA_APP_SNIPPET,
                    PackageUtil.AppSnippet.class);
            PackageUtil.AppSnippet as = intent.getParcelableExtra(
                PackageInstallerActivity.EXTRA_APP_SNIPPET, PackageUtil.AppSnippet.class);

            // Store label for dialog
            mLabel = as.label;
@@ -127,6 +127,8 @@ public class InstallFailed extends Activity {

            // Get status messages
            setExplanationFromErrorCode(statusCode);
        } else {
            finish();
        }
    }

@@ -135,6 +137,7 @@ public class InstallFailed extends Activity {
     * "manage applications" settings page.
     */
    public static class OutOfSpaceDialog extends DialogFragment {

        private InstallFailed mActivity;

        @Override
+20 −3
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.widget.Button;
@@ -91,8 +93,11 @@ public class InstallInstalling extends Activity {
            // ContentResolver.SCHEME_FILE
            // STAGED_SESSION_ID extra contains an ID of a previously staged install session.
            final File sourceFile = new File(mPackageURI.getPath());
            PackageUtil.AppSnippet as = getIntent()
                    .getParcelableExtra(EXTRA_APP_SNIPPET, PackageUtil.AppSnippet.class);

            // Dialogs displayed while changing update-owner have a blank icon. To fix this,
            // fetch the appSnippet from the source file again
            PackageUtil.AppSnippet as = PackageUtil.getAppSnippet(this, appInfo, sourceFile);
            getIntent().putExtra(EXTRA_APP_SNIPPET, as);

            AlertDialog.Builder builder = new AlertDialog.Builder(this);

@@ -244,6 +249,14 @@ public class InstallInstalling extends Activity {
        super.onDestroy();
    }

    @Override
    public void finish() {
        if (mDialog != null) {
            mDialog.dismiss();
        }
        super.finish();
    }

    /**
     * Launch the appropriate finish activity (success or failed) for the installation result.
     *
@@ -299,7 +312,11 @@ public class InstallInstalling extends Activity {
                        PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);

                try {
                    // Delay committing the session by 100ms to fix a UI glitch while displaying the
                    // Update-Owner change dialog on top of the Installing dialog
                    new Handler(Looper.getMainLooper()).postDelayed(() -> {
                        session.commit(pendingIntent.getIntentSender());
                    }, 100);
                } catch (Exception e) {
                    Log.e(LOG_TAG, "Cannot install package: ", e);
                    launchFailure(PackageInstaller.STATUS_FAILURE,
+3 −1
Original line number Diff line number Diff line
@@ -165,7 +165,9 @@ public class InstallStaging extends Activity {
        if (mStagingTask != null) {
            mStagingTask.cancel(true);
        }

        if (mDialog != null) {
            mDialog.dismiss();
        }
        super.onDestroy();
    }

+1 −0
Original line number Diff line number Diff line
@@ -193,6 +193,7 @@ public class InstallStart extends Activity {

        if (isSessionInstall) {
            nextActivity.setClass(this, PackageInstallerActivity.class);
            nextActivity.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        } else {
            Uri packageUri = intent.getData();

+21 −3
Original line number Diff line number Diff line
@@ -176,11 +176,14 @@ public class PackageInstallerActivity extends Activity {
    }

    private CharSequence getExistingUpdateOwnerLabel() {
        return getApplicationLabel(getExistingUpdateOwner());
    }

    private String getExistingUpdateOwner() {
        try {
            final String packageName = mPkgInfo.packageName;
            final InstallSourceInfo sourceInfo = mPm.getInstallSourceInfo(packageName);
            final String existingUpdateOwner = sourceInfo.getUpdateOwnerPackageName();
            return getApplicationLabel(existingUpdateOwner);
            return sourceInfo.getUpdateOwnerPackageName();
        } catch (NameNotFoundException e) {
            return null;
        }
@@ -299,6 +302,18 @@ public class PackageInstallerActivity extends Activity {
    }

    private void initiateInstall() {
        final String existingUpdateOwner = getExistingUpdateOwner();
        if (mSessionId == SessionInfo.INVALID_ID &&
            !TextUtils.isEmpty(existingUpdateOwner) &&
            !TextUtils.equals(existingUpdateOwner, mOriginatingPackage)) {
            // Since update ownership is being changed, the system will request another
            // user confirmation shortly. Thus, we don't need to ask the user to confirm
            // installation here.
            startInstall();
            return;
        }

        // Proceed with user confirmation as we are not changing the update-owner in this install.
        String pkgName = mPkgInfo.packageName;
        // Check if there is already a package on the device with this name
        // but it has been renamed to something else.
@@ -465,10 +480,13 @@ public class PackageInstallerActivity extends Activity {

    @Override
    protected void onDestroy() {
        super.onDestroy();
        while (!mActiveUnknownSourcesListeners.isEmpty()) {
            unregister(mActiveUnknownSourcesListeners.get(0));
        }
        if (mDialog != null) {
            mDialog.dismiss();
        }
        super.onDestroy();
    }

    private void bindUi() {
Loading