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

Commit 7767eac3 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Keep track of whether an app is installed for each user.

This add a new per-user state for an app, indicating whether
it is installed for that user.

All system apps are always installed for all users (we still
use disable to "uninstall" them).

Now when you call into the package manager to install an app,
it will only install the app for that user unless you supply
a flag saying to install for all users.  Only being installed
for the user is just the normal install state, but all other
users have marked in their state for that app that it is not
installed.

When you call the package manager APIs for information about
apps, uninstalled apps are treated as really being not visible
(somewhat more-so than disabled apps), unless you use the
GET_UNINSTALLED_PACKAGES flag.

If another user calls to install an app that is already installed,
just not for them, then the normal install process takes place
but in addition that user's installed state is toggled on.

The package manager will not send PACKAGE_ADDED, PACKAGE_REMOVED,
PACKAGE_REPLACED etc broadcasts to users who don't have a package
installed or not being involved in a change in the install state.
There are a few things that are not quite right with this -- for
example if you go through a full install (with a new apk) of an
app for one user who doesn't have it already installed, you will
still get the PACKAGED_REPLACED messages even though this is
technically the first install for your user.  I'm not sure how
much of an issue this is.

When you call the existing API to uninstall an app, this toggles
the installed state of the app for that user to be off.  Only if
that is the last user user that has the app uinstalled will it
actually be removed from the device.  Again there is a new flag
you can pass in to force the app to be uninstalled for all users.

Also fixed issues with cleaning external storage of apps, which
was not dealing with multiple users.  We now keep track of cleaning
each user for each package.

Change-Id: I00e66452b149defc08c5e0183fa673f532465ed5
parent 15525862
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -6293,6 +6293,7 @@ package android.content.pm {
    field public static final int FLAG_EXTERNAL_STORAGE = 262144; // 0x40000
    field public static final int FLAG_FACTORY_TEST = 16; // 0x10
    field public static final int FLAG_HAS_CODE = 4; // 0x4
    field public static final int FLAG_INSTALLED = 8388608; // 0x800000
    field public static final int FLAG_KILL_AFTER_RESTORE = 65536; // 0x10000
    field public static final int FLAG_LARGE_HEAP = 1048576; // 0x100000
    field public static final int FLAG_PERSISTENT = 8; // 0x8
@@ -6629,6 +6630,17 @@ package android.content.pm {
    field public java.lang.String packageName;
  }
  public class PackageUserState {
    ctor public PackageUserState();
    ctor public PackageUserState(android.content.pm.PackageUserState);
    field public java.util.HashSet disabledComponents;
    field public int enabled;
    field public java.util.HashSet enabledComponents;
    field public boolean installed;
    field public boolean notLaunched;
    field public boolean stopped;
  }
  public class PathPermission extends android.os.PatternMatcher {
    ctor public PathPermission(java.lang.String, int, java.lang.String, java.lang.String);
    ctor public PathPermission(android.os.Parcel);
@@ -26928,6 +26940,7 @@ package android.webkit {
    method public synchronized int getDefaultFixedFontSize();
    method public synchronized int getDefaultFontSize();
    method public synchronized java.lang.String getDefaultTextEncodingName();
    method public static java.lang.String getDefaultUserAgent(android.content.Context);
    method public android.webkit.WebSettings.ZoomDensity getDefaultZoom();
    method public boolean getDisplayZoomControls();
    method public synchronized boolean getDomStorageEnabled();
@@ -26958,7 +26971,6 @@ package android.webkit {
    method public synchronized boolean getUseWideViewPort();
    method public deprecated synchronized int getUserAgent();
    method public synchronized java.lang.String getUserAgentString();
    method public static java.lang.String getDefaultUserAgent(android.content.Context);
    method public void setAllowContentAccess(boolean);
    method public void setAllowFileAccess(boolean);
    method public abstract void setAllowFileAccessFromFileURLs(boolean);
+1 −1
Original line number Diff line number Diff line
@@ -393,7 +393,7 @@ public class Am {
    private void runStartService() throws Exception {
        Intent intent = makeIntent();
        System.out.println("Starting service: " + intent);
        ComponentName cn = mAm.startService(null, intent, intent.getType());
        ComponentName cn = mAm.startService(null, intent, intent.getType(), 0);
        if (cn == null) {
            System.err.println("Error: Not found; no service started.");
        }
+5 −2
Original line number Diff line number Diff line
@@ -776,7 +776,7 @@ public final class Pm {
    }

    private void runInstall() {
        int installFlags = 0;
        int installFlags = PackageManager.INSTALL_ALL_USERS;
        String installerPackageName = null;

        String opt;
@@ -811,6 +811,8 @@ public final class Pm {
            } else if (opt.equals("-f")) {
                // Override if -s option is specified.
                installFlags |= PackageManager.INSTALL_INTERNAL;
            } else if (opt.equals("-d")) {
                installFlags |= PackageManager.INSTALL_ALLOW_DOWNGRADE;
            } else if (opt.equals("--algo")) {
                algo = nextOptionData();
                if (algo == null) {
@@ -1105,7 +1107,7 @@ public final class Pm {

        String opt = nextOption();
        if (opt != null && opt.equals("-k")) {
            unInstallFlags = PackageManager.DONT_DELETE_DATA;
            unInstallFlags = PackageManager.DELETE_KEEP_DATA;
        }

        String pkg = nextArg();
@@ -1525,6 +1527,7 @@ public final class Pm {
        System.err.println("    -i: specify the installer package name.");
        System.err.println("    -s: install package on sdcard.");
        System.err.println("    -f: install package on internal flash.");
        System.err.println("    -d: allow version code downgrade.");
        System.err.println("");
        System.err.println("pm uninstall: removes a package from the system. Options:");
        System.err.println("    -k: keep the data and cache directories around after package removal.");
+8 −4
Original line number Diff line number Diff line
@@ -697,7 +697,8 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            IApplicationThread app = ApplicationThreadNative.asInterface(b);
            Intent service = Intent.CREATOR.createFromParcel(data);
            String resolvedType = data.readString();
            ComponentName cn = startService(app, service, resolvedType);
            int userId = data.readInt();
            ComponentName cn = startService(app, service, resolvedType, userId);
            reply.writeNoException();
            ComponentName.writeToParcel(cn, reply);
            return true;
@@ -709,7 +710,8 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            IApplicationThread app = ApplicationThreadNative.asInterface(b);
            Intent service = Intent.CREATOR.createFromParcel(data);
            String resolvedType = data.readString();
            int res = stopService(app, service, resolvedType);
            int userId = data.readInt();
            int res = stopService(app, service, resolvedType, userId);
            reply.writeNoException();
            reply.writeInt(res);
            return true;
@@ -2523,7 +2525,7 @@ class ActivityManagerProxy implements IActivityManager
    }
    
    public ComponentName startService(IApplicationThread caller, Intent service,
            String resolvedType) throws RemoteException
            String resolvedType, int userId) throws RemoteException
    {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
@@ -2531,6 +2533,7 @@ class ActivityManagerProxy implements IActivityManager
        data.writeStrongBinder(caller != null ? caller.asBinder() : null);
        service.writeToParcel(data, 0);
        data.writeString(resolvedType);
        data.writeInt(userId);
        mRemote.transact(START_SERVICE_TRANSACTION, data, reply, 0);
        reply.readException();
        ComponentName res = ComponentName.readFromParcel(reply);
@@ -2539,7 +2542,7 @@ class ActivityManagerProxy implements IActivityManager
        return res;
    }
    public int stopService(IApplicationThread caller, Intent service,
            String resolvedType) throws RemoteException
            String resolvedType, int userId) throws RemoteException
    {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
@@ -2547,6 +2550,7 @@ class ActivityManagerProxy implements IActivityManager
        data.writeStrongBinder(caller != null ? caller.asBinder() : null);
        service.writeToParcel(data, 0);
        data.writeString(resolvedType);
        data.writeInt(userId);
        mRemote.transact(STOP_SERVICE_TRANSACTION, data, reply, 0);
        reply.readException();
        int res = reply.readInt();
+16 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.content.pm.ManifestDigest;
import android.content.pm.UserInfo;
import android.content.pm.VerificationParams;
import android.content.pm.VerifierDeviceIdentity;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
@@ -996,6 +997,21 @@ final class ApplicationPackageManager extends PackageManager {
        }
    }

    @Override
    public int installExistingPackage(String packageName)
            throws NameNotFoundException {
        try {
            int res = mPM.installExistingPackage(packageName);
            if (res == INSTALL_FAILED_INVALID_URI) {
                throw new NameNotFoundException("Package " + packageName + " doesn't exist");
            }
            return res;
        } catch (RemoteException e) {
            // Should never happen!
            throw new NameNotFoundException("Package " + packageName + " doesn't exist");
        }
    }

    @Override
    public void verifyPendingInstall(int id, int response) {
        try {
Loading