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

Commit cb62207e authored by Jakob Schneider's avatar Jakob Schneider
Browse files

Prohibit archival of system apps.

Bug: 299299569
Test: PackageInstallerArchiveTest
Change-Id: I0b94f13e5d81323a7e01479fdda2dadf67574720
parent a712057a
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import android.app.BroadcastOptions;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentSender;
import android.content.IntentSender;
import android.content.pm.ApplicationInfo;
import android.content.pm.ArchivedActivityParcel;
import android.content.pm.ArchivedActivityParcel;
import android.content.pm.ArchivedPackageParcel;
import android.content.pm.ArchivedPackageParcel;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherActivityInfo;
@@ -184,6 +185,7 @@ public class PackageArchiver {
            throws PackageManager.NameNotFoundException {
            throws PackageManager.NameNotFoundException {
        PackageStateInternal ps = getPackageState(packageName, mPm.snapshotComputer(),
        PackageStateInternal ps = getPackageState(packageName, mPm.snapshotComputer(),
                Binder.getCallingUid(), userId);
                Binder.getCallingUid(), userId);
        verifyNotSystemApp(ps.getFlags());
        String responsibleInstallerPackage = getResponsibleInstallerPackage(ps);
        String responsibleInstallerPackage = getResponsibleInstallerPackage(ps);
        verifyInstaller(responsibleInstallerPackage, userId);
        verifyInstaller(responsibleInstallerPackage, userId);
        verifyOptOutStatus(packageName,
        verifyOptOutStatus(packageName,
@@ -318,6 +320,13 @@ public class PackageArchiver {
        return intentReceivers != null && !intentReceivers.getList().isEmpty();
        return intentReceivers != null && !intentReceivers.getList().isEmpty();
    }
    }


    private void verifyNotSystemApp(int flags) throws PackageManager.NameNotFoundException {
        if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0 || (
                (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)) {
            throw new PackageManager.NameNotFoundException("System apps cannot be archived.");
        }
    }

    /**
    /**
     * Returns true if the app is archivable.
     * Returns true if the app is archivable.
     */
     */
@@ -339,6 +348,11 @@ public class PackageArchiver {
            throw new ParcelableException(e);
            throw new ParcelableException(e);
        }
        }


        if ((ps.getFlags() & ApplicationInfo.FLAG_SYSTEM) != 0 || (
                (ps.getFlags() & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)) {
            return false;
        }

        if (isAppOptedOutOfArchiving(packageName, ps.getAppId())) {
        if (isAppOptedOutOfArchiving(packageName, ps.getAppId())) {
            return false;
            return false;
        }
        }