Java Code Examples for android.content.pm.PackageManager#INSTALL_INSTANT_APP

The following examples show how to use android.content.pm.PackageManager#INSTALL_INSTANT_APP . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageInstallerSession.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public PackageInstallerSession(PackageInstallerService.InternalCallback callback,
        Context context, PackageManagerService pm, Looper looper, int sessionId, int userId,
        String installerPackageName, int installerUid, SessionParams params, long createdMillis,
        File stageDir, String stageCid, boolean prepared, boolean sealed) {
    mCallback = callback;
    mContext = context;
    mPm = pm;
    mHandler = new Handler(looper, mHandlerCallback);

    this.sessionId = sessionId;
    this.userId = userId;
    mOriginalInstallerUid = installerUid;
    mInstallerPackageName = installerPackageName;
    mInstallerUid = installerUid;
    this.params = params;
    this.createdMillis = createdMillis;
    this.stageDir = stageDir;
    this.stageCid = stageCid;

    if ((stageDir == null) == (stageCid == null)) {
        throw new IllegalArgumentException(
                "Exactly one of stageDir or stageCid stage must be set");
    }

    mPrepared = prepared;

    if (sealed) {
        synchronized (mLock) {
            try {
                sealAndValidateLocked();
            } catch (PackageManagerException | IOException e) {
                destroyInternal();
                throw new IllegalArgumentException(e);
            }
        }
    }

    final long identity = Binder.clearCallingIdentity();
    try {
        final int uid = mPm.getPackageUid(PackageManagerService.DEFAULT_CONTAINER_PACKAGE,
                PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM);
        defaultContainerGid = UserHandle.getSharedAppGid(uid);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
    // attempt to bind to the DefContainer as early as possible
    if ((params.installFlags & PackageManager.INSTALL_INSTANT_APP) != 0) {
        mHandler.sendMessage(mHandler.obtainMessage(MSG_EARLY_BIND));
    }
}
 
Example 2
Source File: PackageManagerShellCommand.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private int runInstallExisting() throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    int userId = UserHandle.USER_SYSTEM;
    int installFlags = 0;
    String opt;
    while ((opt = getNextOption()) != null) {
        switch (opt) {
            case "--user":
                userId = UserHandle.parseUserArg(getNextArgRequired());
                break;
            case "--ephemeral":
            case "--instant":
                installFlags |= PackageManager.INSTALL_INSTANT_APP;
                installFlags &= ~PackageManager.INSTALL_FULL_APP;
                break;
            case "--full":
                installFlags &= ~PackageManager.INSTALL_INSTANT_APP;
                installFlags |= PackageManager.INSTALL_FULL_APP;
                break;
            default:
                pw.println("Error: Unknown option: " + opt);
                return 1;
        }
    }

    final String packageName = getNextArg();
    if (packageName == null) {
        pw.println("Error: package name not specified");
        return 1;
    }

    try {
        final int res = mInterface.installExistingPackageAsUser(packageName, userId,
                installFlags, PackageManager.INSTALL_REASON_UNKNOWN);
        if (res == PackageManager.INSTALL_FAILED_INVALID_URI) {
            throw new NameNotFoundException("Package " + packageName + " doesn't exist");
        }
        pw.println("Package " + packageName + " installed for user: " + userId);
        return 0;
    } catch (RemoteException | NameNotFoundException e) {
        pw.println(e.toString());
        return 1;
    }
}