Search in sources :

Example 16 with SessionParams

use of android.content.pm.PackageInstaller.SessionParams in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerShellCommand method runRemoveSplit.

private int runRemoveSplit(String packageName, String splitName) throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    final SessionParams sessionParams = new SessionParams(SessionParams.MODE_INHERIT_EXISTING);
    sessionParams.installFlags |= PackageManager.INSTALL_REPLACE_EXISTING;
    sessionParams.appPackageName = packageName;
    final int sessionId = doCreateSession(sessionParams, null, /*installerPackageName*/
    UserHandle.USER_ALL);
    boolean abandonSession = true;
    try {
        if (doRemoveSplit(sessionId, splitName, false) != PackageInstaller.STATUS_SUCCESS) {
            return 1;
        }
        if (doCommitSession(sessionId, false) != PackageInstaller.STATUS_SUCCESS) {
            return 1;
        }
        abandonSession = false;
        pw.println("Success");
        return 0;
    } finally {
        if (abandonSession) {
            try {
                doAbandonSession(sessionId, false);
            } catch (Exception ignore) {
            }
        }
    }
}
Also used : SessionParams(android.content.pm.PackageInstaller.SessionParams) URISyntaxException(java.net.URISyntaxException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) PackageParserException(android.content.pm.PackageParser.PackageParserException) PrintWriter(java.io.PrintWriter)

Example 17 with SessionParams

use of android.content.pm.PackageInstaller.SessionParams in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerShellCommand method makeInstallParams.

private InstallParams makeInstallParams() {
    final SessionParams sessionParams = new SessionParams(SessionParams.MODE_FULL_INSTALL);
    final InstallParams params = new InstallParams();
    params.sessionParams = sessionParams;
    String opt;
    while ((opt = getNextOption()) != null) {
        switch(opt) {
            case "-l":
                sessionParams.installFlags |= PackageManager.INSTALL_FORWARD_LOCK;
                break;
            case "-r":
                sessionParams.installFlags |= PackageManager.INSTALL_REPLACE_EXISTING;
                break;
            case "-i":
                params.installerPackageName = getNextArg();
                if (params.installerPackageName == null) {
                    throw new IllegalArgumentException("Missing installer package");
                }
                break;
            case "-t":
                sessionParams.installFlags |= PackageManager.INSTALL_ALLOW_TEST;
                break;
            case "-s":
                sessionParams.installFlags |= PackageManager.INSTALL_EXTERNAL;
                break;
            case "-f":
                sessionParams.installFlags |= PackageManager.INSTALL_INTERNAL;
                break;
            case "-d":
                sessionParams.installFlags |= PackageManager.INSTALL_ALLOW_DOWNGRADE;
                break;
            case "-g":
                sessionParams.installFlags |= PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS;
                break;
            case "--dont-kill":
                sessionParams.installFlags |= PackageManager.INSTALL_DONT_KILL_APP;
                break;
            case "--originating-uri":
                sessionParams.originatingUri = Uri.parse(getNextArg());
                break;
            case "--referrer":
                sessionParams.referrerUri = Uri.parse(getNextArg());
                break;
            case "-p":
                sessionParams.mode = SessionParams.MODE_INHERIT_EXISTING;
                sessionParams.appPackageName = getNextArg();
                if (sessionParams.appPackageName == null) {
                    throw new IllegalArgumentException("Missing inherit package name");
                }
                break;
            case "-S":
                sessionParams.setSize(Long.parseLong(getNextArg()));
                break;
            case "--abi":
                sessionParams.abiOverride = checkAbiArgument(getNextArg());
                break;
            case "--ephemeral":
                sessionParams.installFlags |= PackageManager.INSTALL_EPHEMERAL;
                break;
            case "--user":
                params.userId = UserHandle.parseUserArg(getNextArgRequired());
                break;
            case "--install-location":
                sessionParams.installLocation = Integer.parseInt(getNextArg());
                break;
            case "--force-uuid":
                sessionParams.installFlags |= PackageManager.INSTALL_FORCE_VOLUME_UUID;
                sessionParams.volumeUuid = getNextArg();
                if ("internal".equals(sessionParams.volumeUuid)) {
                    sessionParams.volumeUuid = null;
                }
                break;
            case "--force-sdk":
                sessionParams.installFlags |= PackageManager.INSTALL_FORCE_SDK;
                break;
            default:
                throw new IllegalArgumentException("Unknown option " + opt);
        }
    }
    return params;
}
Also used : SessionParams(android.content.pm.PackageInstaller.SessionParams)

Example 18 with SessionParams

use of android.content.pm.PackageInstaller.SessionParams in project android_frameworks_base by AOSPA.

the class PackageInstallerService method writeSessionLocked.

private void writeSessionLocked(XmlSerializer out, PackageInstallerSession session) throws IOException {
    final SessionParams params = session.params;
    out.startTag(null, TAG_SESSION);
    writeIntAttribute(out, ATTR_SESSION_ID, session.sessionId);
    writeIntAttribute(out, ATTR_USER_ID, session.userId);
    writeStringAttribute(out, ATTR_INSTALLER_PACKAGE_NAME, session.installerPackageName);
    writeIntAttribute(out, ATTR_INSTALLER_UID, session.installerUid);
    writeLongAttribute(out, ATTR_CREATED_MILLIS, session.createdMillis);
    if (session.stageDir != null) {
        writeStringAttribute(out, ATTR_SESSION_STAGE_DIR, session.stageDir.getAbsolutePath());
    }
    if (session.stageCid != null) {
        writeStringAttribute(out, ATTR_SESSION_STAGE_CID, session.stageCid);
    }
    writeBooleanAttribute(out, ATTR_PREPARED, session.isPrepared());
    writeBooleanAttribute(out, ATTR_SEALED, session.isSealed());
    writeIntAttribute(out, ATTR_MODE, params.mode);
    writeIntAttribute(out, ATTR_INSTALL_FLAGS, params.installFlags);
    writeIntAttribute(out, ATTR_INSTALL_LOCATION, params.installLocation);
    writeLongAttribute(out, ATTR_SIZE_BYTES, params.sizeBytes);
    writeStringAttribute(out, ATTR_APP_PACKAGE_NAME, params.appPackageName);
    writeStringAttribute(out, ATTR_APP_LABEL, params.appLabel);
    writeUriAttribute(out, ATTR_ORIGINATING_URI, params.originatingUri);
    writeIntAttribute(out, ATTR_ORIGINATING_UID, params.originatingUid);
    writeUriAttribute(out, ATTR_REFERRER_URI, params.referrerUri);
    writeStringAttribute(out, ATTR_ABI_OVERRIDE, params.abiOverride);
    writeStringAttribute(out, ATTR_VOLUME_UUID, params.volumeUuid);
    // Persist app icon if changed since last written
    final File appIconFile = buildAppIconFile(session.sessionId);
    if (params.appIcon == null && appIconFile.exists()) {
        appIconFile.delete();
    } else if (params.appIcon != null && appIconFile.lastModified() != params.appIconLastModified) {
        if (LOGD)
            Slog.w(TAG, "Writing changed icon " + appIconFile);
        FileOutputStream os = null;
        try {
            os = new FileOutputStream(appIconFile);
            params.appIcon.compress(CompressFormat.PNG, 90, os);
        } catch (IOException e) {
            Slog.w(TAG, "Failed to write icon " + appIconFile + ": " + e.getMessage());
        } finally {
            IoUtils.closeQuietly(os);
        }
        params.appIconLastModified = appIconFile.lastModified();
    }
    writeGrantedRuntimePermissions(out, params.grantedRuntimePermissions);
    out.endTag(null, TAG_SESSION);
}
Also used : SessionParams(android.content.pm.PackageInstaller.SessionParams) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) AtomicFile(android.util.AtomicFile) File(java.io.File)

Example 19 with SessionParams

use of android.content.pm.PackageInstaller.SessionParams in project android_frameworks_base by AOSPA.

the class PackageInstallerService method readSessionLocked.

private PackageInstallerSession readSessionLocked(XmlPullParser in) throws IOException, XmlPullParserException {
    final int sessionId = readIntAttribute(in, ATTR_SESSION_ID);
    final int userId = readIntAttribute(in, ATTR_USER_ID);
    final String installerPackageName = readStringAttribute(in, ATTR_INSTALLER_PACKAGE_NAME);
    final int installerUid = readIntAttribute(in, ATTR_INSTALLER_UID, mPm.getPackageUid(installerPackageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, userId));
    final long createdMillis = readLongAttribute(in, ATTR_CREATED_MILLIS);
    final String stageDirRaw = readStringAttribute(in, ATTR_SESSION_STAGE_DIR);
    final File stageDir = (stageDirRaw != null) ? new File(stageDirRaw) : null;
    final String stageCid = readStringAttribute(in, ATTR_SESSION_STAGE_CID);
    final boolean prepared = readBooleanAttribute(in, ATTR_PREPARED, true);
    final boolean sealed = readBooleanAttribute(in, ATTR_SEALED);
    final SessionParams params = new SessionParams(SessionParams.MODE_INVALID);
    params.mode = readIntAttribute(in, ATTR_MODE);
    params.installFlags = readIntAttribute(in, ATTR_INSTALL_FLAGS);
    params.installLocation = readIntAttribute(in, ATTR_INSTALL_LOCATION);
    params.sizeBytes = readLongAttribute(in, ATTR_SIZE_BYTES);
    params.appPackageName = readStringAttribute(in, ATTR_APP_PACKAGE_NAME);
    params.appIcon = readBitmapAttribute(in, ATTR_APP_ICON);
    params.appLabel = readStringAttribute(in, ATTR_APP_LABEL);
    params.originatingUri = readUriAttribute(in, ATTR_ORIGINATING_URI);
    params.originatingUid = readIntAttribute(in, ATTR_ORIGINATING_UID, SessionParams.UID_UNKNOWN);
    params.referrerUri = readUriAttribute(in, ATTR_REFERRER_URI);
    params.abiOverride = readStringAttribute(in, ATTR_ABI_OVERRIDE);
    params.volumeUuid = readStringAttribute(in, ATTR_VOLUME_UUID);
    params.grantedRuntimePermissions = readGrantedRuntimePermissions(in);
    final File appIconFile = buildAppIconFile(sessionId);
    if (appIconFile.exists()) {
        params.appIcon = BitmapFactory.decodeFile(appIconFile.getAbsolutePath());
        params.appIconLastModified = appIconFile.lastModified();
    }
    return new PackageInstallerSession(mInternalCallback, mContext, mPm, mInstallThread.getLooper(), sessionId, userId, installerPackageName, installerUid, params, createdMillis, stageDir, stageCid, prepared, sealed);
}
Also used : SessionParams(android.content.pm.PackageInstaller.SessionParams) IPackageInstallerSession(android.content.pm.IPackageInstallerSession) AtomicFile(android.util.AtomicFile) File(java.io.File)

Example 20 with SessionParams

use of android.content.pm.PackageInstaller.SessionParams in project android_frameworks_base by AOSPA.

the class Pm method makeInstallParams.

private InstallParams makeInstallParams() {
    final SessionParams sessionParams = new SessionParams(SessionParams.MODE_FULL_INSTALL);
    final InstallParams params = new InstallParams();
    params.sessionParams = sessionParams;
    String opt;
    while ((opt = nextOption()) != null) {
        switch(opt) {
            case "-l":
                sessionParams.installFlags |= PackageManager.INSTALL_FORWARD_LOCK;
                break;
            case "-r":
                sessionParams.installFlags |= PackageManager.INSTALL_REPLACE_EXISTING;
                break;
            case "-i":
                params.installerPackageName = nextArg();
                if (params.installerPackageName == null) {
                    throw new IllegalArgumentException("Missing installer package");
                }
                break;
            case "-t":
                sessionParams.installFlags |= PackageManager.INSTALL_ALLOW_TEST;
                break;
            case "-s":
                sessionParams.installFlags |= PackageManager.INSTALL_EXTERNAL;
                break;
            case "-f":
                sessionParams.installFlags |= PackageManager.INSTALL_INTERNAL;
                break;
            case "-d":
                sessionParams.installFlags |= PackageManager.INSTALL_ALLOW_DOWNGRADE;
                break;
            case "-g":
                sessionParams.installFlags |= PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS;
                break;
            case "--dont-kill":
                sessionParams.installFlags |= PackageManager.INSTALL_DONT_KILL_APP;
                break;
            case "--originating-uri":
                sessionParams.originatingUri = Uri.parse(nextOptionData());
                break;
            case "--referrer":
                sessionParams.referrerUri = Uri.parse(nextOptionData());
                break;
            case "-p":
                sessionParams.mode = SessionParams.MODE_INHERIT_EXISTING;
                sessionParams.appPackageName = nextOptionData();
                if (sessionParams.appPackageName == null) {
                    throw new IllegalArgumentException("Missing inherit package name");
                }
                break;
            case "-S":
                sessionParams.setSize(Long.parseLong(nextOptionData()));
                break;
            case "--abi":
                sessionParams.abiOverride = checkAbiArgument(nextOptionData());
                break;
            case "--ephemeral":
                sessionParams.installFlags |= PackageManager.INSTALL_EPHEMERAL;
                break;
            case "--user":
                params.userId = UserHandle.parseUserArg(nextOptionData());
                break;
            case "--install-location":
                sessionParams.installLocation = Integer.parseInt(nextOptionData());
                break;
            case "--force-uuid":
                sessionParams.installFlags |= PackageManager.INSTALL_FORCE_VOLUME_UUID;
                sessionParams.volumeUuid = nextOptionData();
                if ("internal".equals(sessionParams.volumeUuid)) {
                    sessionParams.volumeUuid = null;
                }
                break;
            case "--force-sdk":
                sessionParams.installFlags |= PackageManager.INSTALL_FORCE_SDK;
                break;
            default:
                throw new IllegalArgumentException("Unknown option " + opt);
        }
    }
    return params;
}
Also used : SessionParams(android.content.pm.PackageInstaller.SessionParams)

Aggregations

SessionParams (android.content.pm.PackageInstaller.SessionParams)23 AtomicFile (android.util.AtomicFile)10 File (java.io.File)10 IOException (java.io.IOException)9 IPackageInstallerSession (android.content.pm.IPackageInstallerSession)5 FileOutputStream (java.io.FileOutputStream)5 PackageParserException (android.content.pm.PackageParser.PackageParserException)4 RemoteException (android.os.RemoteException)4 PrintWriter (java.io.PrintWriter)4 URISyntaxException (java.net.URISyntaxException)4