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

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

Merge changes I335fb48f,Id5d98c7f,I9f66a5d1,Iee72576d,Id8ca634b into main

* changes:
  Introduce base class to hold uninstall stage related data
  Introduce UninstallRepository and UninstallViewModel
  Foundation of Uninstall flow in PiaV2
  Cache the staged session id to skip a staging again
  Replace if..else-if with a switch
parents aabaabaf 82104d8a
Loading
Loading
Loading
Loading
+9 −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"
@@ -140,6 +140,14 @@
            </intent-filter>
        </activity>

        <activity android:name=".v2.ui.UninstallLaunch"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:theme="@style/Theme.AlertDialogActivity.NoActionBar"
            android:excludeFromRecents="true"
            android:noHistory="true"
            android:exported="false">
        </activity>

        <receiver android:name=".UninstallEventReceiver"
            android:permission="android.permission.INSTALL_PACKAGES"
            android:exported="false">
+18 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import com.android.packageinstaller.television.ErrorFragment;
import com.android.packageinstaller.television.UninstallAlertFragment;
import com.android.packageinstaller.television.UninstallAppProgress;

import com.android.packageinstaller.v2.ui.UninstallLaunch;
import java.util.List;

/*
@@ -80,6 +81,9 @@ public class UninstallerActivity extends Activity {
    private String mPackageName;
    private DialogInfo mDialogInfo;

    // TODO (sumedhsen): Replace with an Android Feature Flag once implemented
    private static final boolean USE_PIA_V2 = false;

    @Override
    public void onCreate(Bundle icicle) {
        getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
@@ -88,6 +92,20 @@ public class UninstallerActivity extends Activity {
        // be stale, if e.g. the app was uninstalled while the activity was destroyed.
        super.onCreate(null);

        if (USE_PIA_V2 && !isTv()) {
            boolean returnResult = getIntent().getBooleanExtra(Intent.EXTRA_RETURN_RESULT, false);
            Intent piaV2 = new Intent(getIntent());
            piaV2.putExtra(UninstallLaunch.EXTRA_CALLING_PKG_UID, getLaunchedFromUid());
            piaV2.putExtra(UninstallLaunch.EXTRA_CALLING_ACTIVITY_NAME, getCallingActivity());
            if (returnResult) {
                piaV2.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
            }
            piaV2.setClass(this, UninstallLaunch.class);
            startActivity(piaV2);
            finish();
            return;
        }

        int callingUid = getLaunchedFromUid();
        if (callingUid == Process.INVALID_UID) {
            // Cannot reach Package/ActivityManager. Aborting uninstall.
+16 −4
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,7 +172,10 @@ public class InstallRepository {
            return new InstallAborted.Builder(ABORT_REASON_INTERNAL_ERROR).build();
        }

        if (!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();
        }

@@ -254,10 +261,11 @@ 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. Setting the mStagingResult as null will signal InstallViewModel to
            // proceed with user confirmation stage.
            // for us to stage.
            mStagingResult.setValue(new InstallReady());
            return;
        }
@@ -324,6 +332,10 @@ public class InstallRepository {
        }
    }

    public int getStagedSessionId() {
        return mStagedSessionId;
    }

    private void cleanupStagingSession() {
        if (mStagedSessionId > 0) {
            try {
+0 −3
Original line number Diff line number Diff line
@@ -205,9 +205,6 @@ public class PackageUtil {
     */
    public static boolean isCallerSessionOwner(PackageInstaller pi, int originatingUid,
        int sessionId) {
        if (sessionId == SessionInfo.INVALID_ID) {
            return false;
        }
        if (originatingUid == Process.ROOT_UID) {
            return true;
        }
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.packageinstaller.v2.model;

import android.content.Context;

public class UninstallRepository {

    private static final String TAG = UninstallRepository.class.getSimpleName();
    private final Context mContext;

    public UninstallRepository(Context context) {
        mContext = context;
    }
}
Loading