use of android.content.pm.PackageParser.PackageLite in project android_frameworks_base by ResurrectionRemix.
the class PackageManagerShellCommand method runInstall.
private int runInstall() throws RemoteException {
final PrintWriter pw = getOutPrintWriter();
final InstallParams params = makeInstallParams();
final String inPath = getNextArg();
boolean installExternal = (params.sessionParams.installFlags & PackageManager.INSTALL_EXTERNAL) != 0;
if (params.sessionParams.sizeBytes < 0 && inPath != null) {
File file = new File(inPath);
if (file.isFile()) {
if (installExternal) {
try {
ApkLite baseApk = PackageParser.parseApkLite(file, 0);
PackageLite pkgLite = new PackageLite(null, baseApk, null, null, null);
params.sessionParams.setSize(PackageHelper.calculateInstalledSize(pkgLite, false, params.sessionParams.abiOverride));
} catch (PackageParserException | IOException e) {
pw.println("Error: Failed to parse APK file : " + e);
return 1;
}
} else {
params.sessionParams.setSize(file.length());
}
}
}
final int sessionId = doCreateSession(params.sessionParams, params.installerPackageName, params.userId);
boolean abandonSession = true;
try {
if (inPath == null && params.sessionParams.sizeBytes == 0) {
pw.println("Error: must either specify a package size or an APK file");
return 1;
}
if (doWriteSplit(sessionId, inPath, params.sessionParams.sizeBytes, "base.apk", 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) {
}
}
}
}
use of android.content.pm.PackageParser.PackageLite in project android_frameworks_base by ResurrectionRemix.
the class Pm method runInstall.
/*
* Keep this around to support existing users of the "pm install" command that may not be
* able to be updated [or, at least informed the API has changed] such as ddmlib.
*
* Moving the implementation of "pm install" to "cmd package install" changes the executing
* context. Instead of being a stand alone process, "cmd package install" runs in the
* system_server process. Due to SELinux rules, system_server cannot access many directories;
* one of which being the package install staging directory [/data/local/tmp].
*
* The use of "adb install" or "cmd package install" over "pm install" is highly encouraged.
*/
private int runInstall() throws RemoteException {
final InstallParams params = makeInstallParams();
final String inPath = nextArg();
boolean installExternal = (params.sessionParams.installFlags & PackageManager.INSTALL_EXTERNAL) != 0;
if (params.sessionParams.sizeBytes < 0 && inPath != null) {
File file = new File(inPath);
if (file.isFile()) {
if (installExternal) {
try {
ApkLite baseApk = PackageParser.parseApkLite(file, 0);
PackageLite pkgLite = new PackageLite(null, baseApk, null, null, null);
params.sessionParams.setSize(PackageHelper.calculateInstalledSize(pkgLite, false, params.sessionParams.abiOverride));
} catch (PackageParserException | IOException e) {
System.err.println("Error: Failed to parse APK file : " + e);
return 1;
}
} else {
params.sessionParams.setSize(file.length());
}
}
}
final int sessionId = doCreateSession(params.sessionParams, params.installerPackageName, params.userId);
try {
if (inPath == null && params.sessionParams.sizeBytes == 0) {
System.err.println("Error: must either specify a package size or an APK file");
return 1;
}
if (doWriteSession(sessionId, inPath, params.sessionParams.sizeBytes, "base.apk", false) != PackageInstaller.STATUS_SUCCESS) {
return 1;
}
if (doCommitSession(sessionId, false) != PackageInstaller.STATUS_SUCCESS) {
return 1;
}
System.out.println("Success");
return 0;
} finally {
try {
mInstaller.abandonSession(sessionId);
} catch (Exception ignore) {
}
}
}
use of android.content.pm.PackageParser.PackageLite in project android_frameworks_base by crdroidandroid.
the class PackageInstallerSession method calculateInstalledSize.
/**
* Calculate the final install footprint size, combining both staged and
* existing APKs together and including unpacked native code from both.
*/
private long calculateInstalledSize() throws PackageManagerException {
Preconditions.checkNotNull(mResolvedBaseFile);
final ApkLite baseApk;
try {
baseApk = PackageParser.parseApkLite(mResolvedBaseFile, 0);
} catch (PackageParserException e) {
throw PackageManagerException.from(e);
}
final List<String> splitPaths = new ArrayList<>();
for (File file : mResolvedStagedFiles) {
if (mResolvedBaseFile.equals(file))
continue;
splitPaths.add(file.getAbsolutePath());
}
for (File file : mResolvedInheritedFiles) {
if (mResolvedBaseFile.equals(file))
continue;
splitPaths.add(file.getAbsolutePath());
}
// This is kind of hacky; we're creating a half-parsed package that is
// straddled between the inherited and staged APKs.
final PackageLite pkg = new PackageLite(null, baseApk, null, splitPaths.toArray(new String[splitPaths.size()]), null);
final boolean isForwardLocked = (params.installFlags & PackageManager.INSTALL_FORWARD_LOCK) != 0;
try {
return PackageHelper.calculateInstalledSize(pkg, isForwardLocked, params.abiOverride);
} catch (IOException e) {
throw new PackageManagerException(INSTALL_FAILED_INVALID_APK, "Failed to calculate install size", e);
}
}
use of android.content.pm.PackageParser.PackageLite in project android_frameworks_base by crdroidandroid.
the class PackageManagerShellCommand method runInstall.
private int runInstall() throws RemoteException {
final PrintWriter pw = getOutPrintWriter();
final InstallParams params = makeInstallParams();
final String inPath = getNextArg();
boolean installExternal = (params.sessionParams.installFlags & PackageManager.INSTALL_EXTERNAL) != 0;
if (params.sessionParams.sizeBytes < 0 && inPath != null) {
File file = new File(inPath);
if (file.isFile()) {
if (installExternal) {
try {
ApkLite baseApk = PackageParser.parseApkLite(file, 0);
PackageLite pkgLite = new PackageLite(null, baseApk, null, null, null);
params.sessionParams.setSize(PackageHelper.calculateInstalledSize(pkgLite, false, params.sessionParams.abiOverride));
} catch (PackageParserException | IOException e) {
pw.println("Error: Failed to parse APK file : " + e);
return 1;
}
} else {
params.sessionParams.setSize(file.length());
}
}
}
final int sessionId = doCreateSession(params.sessionParams, params.installerPackageName, params.userId);
boolean abandonSession = true;
try {
if (inPath == null && params.sessionParams.sizeBytes == 0) {
pw.println("Error: must either specify a package size or an APK file");
return 1;
}
if (doWriteSplit(sessionId, inPath, params.sessionParams.sizeBytes, "base.apk", 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) {
}
}
}
}
use of android.content.pm.PackageParser.PackageLite in project platform_frameworks_base by android.
the class PackageManagerShellCommand method runInstall.
private int runInstall() throws RemoteException {
final PrintWriter pw = getOutPrintWriter();
final InstallParams params = makeInstallParams();
final String inPath = getNextArg();
if (params.sessionParams.sizeBytes < 0 && inPath != null) {
File file = new File(inPath);
if (file.isFile()) {
try {
ApkLite baseApk = PackageParser.parseApkLite(file, 0);
PackageLite pkgLite = new PackageLite(null, baseApk, null, null, null);
params.sessionParams.setSize(PackageHelper.calculateInstalledSize(pkgLite, false, params.sessionParams.abiOverride));
} catch (PackageParserException | IOException e) {
pw.println("Error: Failed to parse APK file : " + e);
return 1;
}
}
}
final int sessionId = doCreateSession(params.sessionParams, params.installerPackageName, params.userId);
boolean abandonSession = true;
try {
if (inPath == null && params.sessionParams.sizeBytes == 0) {
pw.println("Error: must either specify a package size or an APK file");
return 1;
}
if (doWriteSplit(sessionId, inPath, params.sessionParams.sizeBytes, "base.apk", 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) {
}
}
}
}
Aggregations