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

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

Cache the staged session id to skip a staging again

On restarting install after the user grants install permission to
unknown app, we need to skip staging the original file once again. As
such, pass the stagedsessionId while restarting the activity so that
staging can be skipped.

Bug: 182205982
Test: builds successfully
Test: No CTS Tests. Flag to use new app is turned off by default

Change-Id: Iee72576d535613e39e132ffd9e1a1a452838fb82
parent 250c9b25
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@
        <activity android:name=".v2.ui.InstallLaunch"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:theme="@style/Theme.AlertDialogActivity"
            android:exported="true"/>
            android:exported="false"/>

        <activity android:name=".InstallStart"
                android:theme="@style/Theme.AlertDialogActivity"
+15 −3
Original line number Diff line number Diff line
@@ -76,6 +76,8 @@ import java.io.IOException;

public class InstallRepository {

    public static final String EXTRA_STAGED_SESSION_ID =
        "com.android.packageinstaller.extra.STAGED_SESSION_ID";
    private static final String SCHEME_PACKAGE = "package";
    private static final String BROADCAST_ACTION =
        "com.android.packageinstaller.ACTION_INSTALL_COMMIT";
@@ -142,6 +144,8 @@ public class InstallRepository {
            ? intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, SessionInfo.INVALID_ID)
            : SessionInfo.INVALID_ID;

        mStagedSessionId = mIntent.getIntExtra(EXTRA_STAGED_SESSION_ID, SessionInfo.INVALID_ID);

        mCallingPackage = callerInfo.getPackageName();

        if (mCallingPackage == null && mSessionId != SessionInfo.INVALID_ID) {
@@ -168,8 +172,10 @@ public class InstallRepository {
            return new InstallAborted.Builder(ABORT_REASON_INTERNAL_ERROR).build();
        }

        if (mSessionId != SessionInfo.INVALID_ID &&
            !isCallerSessionOwner(mPackageInstaller, originatingUid, mSessionId)) {
        if ((mSessionId != SessionInfo.INVALID_ID
            && !isCallerSessionOwner(mPackageInstaller, originatingUid, mSessionId))
            || (mStagedSessionId != SessionInfo.INVALID_ID
            && !isCallerSessionOwner(mPackageInstaller, Process.myUid(), mStagedSessionId))) {
            return new InstallAborted.Builder(ABORT_REASON_INTERNAL_ERROR).build();
        }

@@ -255,7 +261,9 @@ public class InstallRepository {

    public void stageForInstall() {
        Uri uri = mIntent.getData();
        if (mIsSessionInstall || (uri != null && SCHEME_PACKAGE.equals(uri.getScheme()))) {
        if (mStagedSessionId != SessionInfo.INVALID_ID
            || mIsSessionInstall
            || (uri != null && SCHEME_PACKAGE.equals(uri.getScheme()))) {
            // For a session based install or installing with a package:// URI, there is no file
            // for us to stage.
            mStagingResult.setValue(new InstallReady());
@@ -324,6 +332,10 @@ public class InstallRepository {
        }
    }

    public int getStagedSessionId() {
        return mStagedSessionId;
    }

    private void cleanupStagingSession() {
        if (mStagedSessionId > 0) {
            try {
+10 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.packageinstaller.v2.ui;
import static android.content.Intent.CATEGORY_LAUNCHER;
import static android.content.Intent.FLAG_ACTIVITY_NO_HISTORY;
import static android.os.Process.INVALID_UID;
import static com.android.packageinstaller.v2.model.InstallRepository.EXTRA_STAGED_SESSION_ID;

import android.app.Activity;
import android.app.AppOpsManager;
@@ -336,10 +337,16 @@ public class InstallLaunch extends FragmentActivity implements InstallActionList
            }
            new Handler(Looper.getMainLooper()).postDelayed(() -> {
                if (!isDestroyed()) {
                    // Bring Pia to the foreground. FLAG_ACTIVITY_REORDER_TO_FRONT will reuse the
                    // paused instance, so we don't unnecessarily create a new instance of Pia.
                    // Relaunch Pia to continue installation.
                    startActivity(getIntent()
                        .addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
                        .putExtra(EXTRA_STAGED_SESSION_ID, mInstallViewModel.getStagedSessionId()));

                    // If the userId of the root of activity stack is different from current userId,
                    // starting Pia again lead to duplicate instances of the app in the stack.
                    // As such, finish the old instance. Old Pia is finished even if the userId of
                    // the root is the same, since there is no way to determine the difference in
                    // userIds.
                    finish();
                }
            }, 500);
        }
+4 −0
Original line number Diff line number Diff line
@@ -98,4 +98,8 @@ public class InstallViewModel extends AndroidViewModel {
            }
        });
    }

    public int getStagedSessionId() {
        return mRepository.getStagedSessionId();
    }
}