Search in sources :

Example 21 with SessionParams

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

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 22 with SessionParams

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

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)

Example 23 with SessionParams

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

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)

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