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

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

Foundation for Unarchival in Pia V2

Bug: 398032488
Test: atest CtsPackageUninstallTestCases:ArchiveTest
Flag: android.content.pm.use_pia_v2
Change-Id: If37d6502b7a474c2e90588ca568c0740d831fb65
parent 2ef14fd9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -175,6 +175,11 @@
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity android:name=".v2.ui.UnarchiveLaunch"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:theme="@style/Theme.AlertDialogActivity"
            android:exported="false"/>
    </application>

</manifest>
+6 −17
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
package com.android.packageinstaller;

import static android.content.pm.Flags.usePiaV2;

import static com.android.packageinstaller.PackageUtil.getMaxTargetSdkVersionForUid;
import static com.android.packageinstaller.PackageUtil.getReasonForDebug;

import android.Manifest;
import android.app.Activity;
@@ -41,8 +43,11 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.util.EventLog;
import android.util.Log;

import androidx.annotation.Nullable;

import com.android.packageinstaller.v2.ui.InstallLaunch;

import java.util.Arrays;

/**
@@ -69,7 +74,7 @@ public class InstallStart extends Activity {
        boolean usePiaV2aConfig = usePiaV2();

        if (usePiaV2aConfig || testOverrideForPiaV2) {
            logReasonForDebug(usePiaV2aConfig, testOverrideForPiaV2);
            Log.d(TAG, getReasonForDebug(usePiaV2aConfig, testOverrideForPiaV2));

            Intent piaV2 = new Intent(getIntent());
            piaV2.putExtra(InstallLaunch.EXTRA_CALLING_PKG_NAME, getLaunchedFromPackage());
@@ -398,20 +403,4 @@ public class InstallStart extends Activity {
        }
        return null;
    }

    private void logReasonForDebug(boolean usePiaV2aConfig, boolean testOverrideForPiaV2) {
        StringBuilder sb = new StringBuilder("Using Pia V2 due to: ");
        boolean aconfigUsed = false;
        if (usePiaV2aConfig) {
            sb.append("aconfig flag USE_PIA_V2");
            aconfigUsed = true;
        }
        if (testOverrideForPiaV2) {
            if (aconfigUsed) {
                sb.append(" and ");
            }
            sb.append("testOverrideForPiaV2.");
        }
        Log.i(TAG, sb.toString());
    }
}
+19 −0
Original line number Diff line number Diff line
@@ -385,4 +385,23 @@ public class PackageUtil {
        }
        return null;
    }

    /**
     * Returns a string containing the reason for using Pia V2. Used for debugging purposes
     */
    public static String getReasonForDebug(boolean usePiaV2aConfig, boolean testOverrideForPiaV2) {
        StringBuilder sb = new StringBuilder("Using Pia V2 due to: ");
        boolean aconfigUsed = false;
        if (usePiaV2aConfig) {
            sb.append("aconfig flag USE_PIA_V2");
            aconfigUsed = true;
        }
        if (testOverrideForPiaV2) {
            if (aconfigUsed) {
                sb.append(" and ");
            }
            sb.append("testOverrideForPiaV2.");
        }
        return sb.toString();
    }
}
+24 −0
Original line number Diff line number Diff line
@@ -17,25 +17,32 @@
package com.android.packageinstaller;

import static android.Manifest.permission;
import static android.content.pm.Flags.usePiaV2;
import static android.content.pm.PackageManager.GET_PERMISSIONS;
import static android.content.pm.PackageManager.MATCH_ARCHIVED_PACKAGES;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;

import static com.android.packageinstaller.PackageUtil.getReasonForDebug;

import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.InstallSourceInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Process;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;

import com.android.packageinstaller.v2.ui.UnarchiveLaunch;

import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
@@ -58,6 +65,23 @@ public class UnarchiveActivity extends Activity {

        super.onCreate(null);

        boolean testOverrideForPiaV2 = Settings.System.getInt(getContentResolver(),
                "use_pia_v2", 0) == 1;
        boolean usePiaV2aConfig = usePiaV2();

        if (usePiaV2aConfig || testOverrideForPiaV2) {
            Log.d(TAG, getReasonForDebug(usePiaV2aConfig, testOverrideForPiaV2));

            Intent piaV2 = new Intent(getIntent());
            piaV2.putExtra(UnarchiveLaunch.EXTRA_CALLING_PKG_NAME, getLaunchedFromPackage());
            piaV2.putExtra(UnarchiveLaunch.EXTRA_CALLING_PKG_UID, getLaunchedFromUid());
            piaV2.setClass(this, UnarchiveLaunch.class);
            piaV2.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
            startActivity(piaV2);
            finish();
            return;
        }

        int callingUid = getLaunchedFromUid();
        if (callingUid == Process.INVALID_UID) {
            // Cannot reach Package/ActivityManager. Aborting uninstall.
+21 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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

class UnarchiveRepository(private val context: Context)
Loading