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

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

Merge changes from topic "pia-utils" into main

* changes:
  Change the imports in Pia V2 to use refactored utils
  Change the imports in Pia V1 to use refactored utils
  Delete redundant utils classes from Pia v2
  Move PackageInstaller app utility clases to separate directory
parents e195fea6 26d9e37d
Loading
Loading
Loading
Loading
+3 −29
Original line number Original line Diff line number Diff line
@@ -36,21 +36,13 @@
            android:forceQueryable="true"
            android:forceQueryable="true"
            android:directBootAware="true">
            android:directBootAware="true">


        <receiver android:name=".TemporaryFileManager"
        <receiver android:name=".common.TemporaryFileManager"
            android:exported="false">
            android:exported="false">
            <intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
            </intent-filter>
        </receiver>
        </receiver>


        <receiver android:name="v2.model.TemporaryFileManager"
            android:exported="false"
            android:enabled="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <activity android:name=".v2.ui.InstallLaunch"
        <activity android:name=".v2.ui.InstallLaunch"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:theme="@style/Theme.AlertDialogActivity"
            android:theme="@style/Theme.AlertDialogActivity"
@@ -101,7 +93,7 @@
                android:theme="@style/Theme.AlertDialogActivity.NoAnimation"
                android:theme="@style/Theme.AlertDialogActivity.NoAnimation"
                android:exported="false" />
                android:exported="false" />


        <receiver android:name=".InstallEventReceiver"
        <receiver android:name=".common.InstallEventReceiver"
                android:permission="android.permission.INSTALL_PACKAGES"
                android:permission="android.permission.INSTALL_PACKAGES"
                android:exported="false">
                android:exported="false">
            <intent-filter android:priority="1">
            <intent-filter android:priority="1">
@@ -109,15 +101,6 @@
            </intent-filter>
            </intent-filter>
        </receiver>
        </receiver>


        <receiver android:name=".v2.model.InstallEventReceiver"
            android:permission="android.permission.INSTALL_PACKAGES"
            android:exported="false"
            android:enabled="false">
            <intent-filter android:priority="1">
                <action android:name="com.android.packageinstaller.ACTION_INSTALL_COMMIT" />
            </intent-filter>
        </receiver>

        <activity android:name=".InstallSuccess"
        <activity android:name=".InstallSuccess"
                android:theme="@style/Theme.AlertDialogActivity.NoAnimation"
                android:theme="@style/Theme.AlertDialogActivity.NoAnimation"
                android:exported="false" />
                android:exported="false" />
@@ -148,7 +131,7 @@
            android:exported="false">
            android:exported="false">
        </activity>
        </activity>


        <receiver android:name=".UninstallEventReceiver"
        <receiver android:name=".common.UninstallEventReceiver"
            android:permission="android.permission.INSTALL_PACKAGES"
            android:permission="android.permission.INSTALL_PACKAGES"
            android:exported="false">
            android:exported="false">
            <intent-filter android:priority="1">
            <intent-filter android:priority="1">
@@ -156,15 +139,6 @@
            </intent-filter>
            </intent-filter>
        </receiver>
        </receiver>


        <receiver android:name=".v2.model.UninstallEventReceiver"
            android:permission="android.permission.INSTALL_PACKAGES"
            android:exported="false"
            android:enabled="false">
            <intent-filter android:priority="1">
                <action android:name="com.android.packageinstaller.ACTION_UNINSTALL_COMMIT" />
            </intent-filter>
        </receiver>

        <receiver android:name=".PackageInstalledReceiver"
        <receiver android:name=".PackageInstalledReceiver"
                android:exported="false">
                android:exported="false">
            <intent-filter android:priority="1">
            <intent-filter android:priority="1">
+2 −2
Original line number Original line Diff line number Diff line
@@ -33,9 +33,9 @@ import android.os.Bundle;
import android.util.Log;
import android.util.Log;
import android.view.View;
import android.view.View;
import android.widget.Button;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.annotation.Nullable;

import com.android.packageinstaller.common.EventResultPersister;
import com.android.packageinstaller.common.InstallEventReceiver;
import java.io.File;
import java.io.File;
import java.io.IOException;
import java.io.IOException;


+2 −10
Original line number Original line Diff line number Diff line
@@ -23,7 +23,6 @@ import android.Manifest;
import android.app.Activity;
import android.app.Activity;
import android.app.DialogFragment;
import android.app.DialogFragment;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;
@@ -39,7 +38,6 @@ import android.os.UserManager;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.EventLog;
import android.util.EventLog;
import android.util.Log;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
import com.android.packageinstaller.v2.ui.InstallLaunch;
import com.android.packageinstaller.v2.ui.InstallLaunch;
@@ -63,17 +61,10 @@ public class InstallStart extends Activity {
    protected void onCreate(@Nullable Bundle savedInstanceState) {
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);


        mPackageManager = getPackageManager();

        if (usePiaV2()) {
        if (usePiaV2()) {
            Log.i(TAG, "Using Pia V2");
            Log.i(TAG, "Using Pia V2");


            mPackageManager.setComponentEnabledSetting(new ComponentName(this,
                    com.android.packageinstaller.InstallEventReceiver.class),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
            mPackageManager.setComponentEnabledSetting(new ComponentName(this,
                    com.android.packageinstaller.v2.model.InstallEventReceiver.class),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);

            Intent piaV2 = new Intent(getIntent());
            Intent piaV2 = new Intent(getIntent());
            piaV2.putExtra(InstallLaunch.EXTRA_CALLING_PKG_NAME, getCallingPackage());
            piaV2.putExtra(InstallLaunch.EXTRA_CALLING_PKG_NAME, getCallingPackage());
            piaV2.putExtra(InstallLaunch.EXTRA_CALLING_PKG_UID, getLaunchedFromUid());
            piaV2.putExtra(InstallLaunch.EXTRA_CALLING_PKG_UID, getLaunchedFromUid());
@@ -83,6 +74,7 @@ public class InstallStart extends Activity {
            finish();
            finish();
            return;
            return;
        }
        }
        mPackageManager = getPackageManager();
        mUserManager = getSystemService(UserManager.class);
        mUserManager = getSystemService(UserManager.class);


        Intent intent = getIntent();
        Intent intent = getIntent();
+0 −86
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2016 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
 *
 *      http://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;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import androidx.annotation.NonNull;

/**
 * Receives uninstall events and persists them using a {@link EventResultPersister}.
 */
public class UninstallEventReceiver extends BroadcastReceiver {
    private static final Object sLock = new Object();
    private static EventResultPersister sReceiver;

    /**
     * Get the event receiver persisting the results
     *
     * @return The event receiver.
     */
    @NonNull private static EventResultPersister getReceiver(@NonNull Context context) {
        synchronized (sLock) {
            if (sReceiver == null) {
                sReceiver = new EventResultPersister(
                        TemporaryFileManager.getUninstallStateFile(context));
            }
        }

        return sReceiver;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        getReceiver(context).onEventReceived(context, intent);
    }

    /**
     * Add an observer. If there is already an event for this id, call back inside of this call.
     *
     * @param context  A context of the current app
     * @param id       The id the observer is for or {@code GENERATE_NEW_ID} to generate a new one.
     * @param observer The observer to call back.
     *
     * @return The id for this event
     */
    public static int addObserver(@NonNull Context context, int id,
            @NonNull EventResultPersister.EventResultObserver observer)
            throws EventResultPersister.OutOfIdsException {
        return getReceiver(context).addObserver(id, observer);
    }

    /**
     * Remove a observer.
     *
     * @param context  A context of the current app
     * @param id The id the observer was added for
     */
    static void removeObserver(@NonNull Context context, int id) {
        getReceiver(context).removeObserver(id);
    }

    /**
     * @param context A context of the current app
     *
     * @return A new uninstall id
     */
    static int getNewId(@NonNull Context context) throws EventResultPersister.OutOfIdsException {
        return getReceiver(context).getNewId();
    }
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -34,8 +34,9 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.util.Log;
import android.util.Log;
import android.widget.Toast;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
import com.android.packageinstaller.common.EventResultPersister;
import com.android.packageinstaller.common.UninstallEventReceiver;


/**
/**
 * Start an uninstallation, show a dialog while uninstalling and return result to the caller.
 * Start an uninstallation, show a dialog while uninstalling and return result to the caller.
Loading