Example usage for android.content.pm PackageManager INSTALL_SUCCEEDED

List of usage examples for android.content.pm PackageManager INSTALL_SUCCEEDED

Introduction

In this page you can find the example usage for android.content.pm PackageManager INSTALL_SUCCEEDED.

Prototype

int INSTALL_SUCCEEDED

To view the source code for android.content.pm PackageManager INSTALL_SUCCEEDED.

Click Source Link

Document

Installation return code: this is passed in the PackageInstaller#EXTRA_LEGACY_STATUS on success.

Usage

From source file:com.android.packageinstaller.PackageInstallerActivity.java

void setPmResult(int pmResult) {
    Intent result = new Intent();
    result.putExtra(Intent.EXTRA_INSTALL_RESULT, pmResult);
    setResult(pmResult == PackageManager.INSTALL_SUCCEEDED ? RESULT_OK : RESULT_FIRST_USER, result);
}

From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java

private void installMdmOnManagedProfile() throws ProvisioningException {
    ProvisionLogger.logd("Installing mobile device management app " + mParams.deviceAdminComponentName
            + " on managed profile");

    try {//from  w w w.  ja v  a2s . c  o m
        int status = mIpm.installExistingPackageAsUser(mParams.deviceAdminComponentName.getPackageName(),
                mManagedProfileOrUserInfo.id);
        switch (status) {
        case PackageManager.INSTALL_SUCCEEDED:
            return;
        case PackageManager.INSTALL_FAILED_USER_RESTRICTED:
            // Should not happen because we're not installing a restricted user
            throw raiseError("Could not install mobile device management app on managed "
                    + "profile because the user is restricted");
        case PackageManager.INSTALL_FAILED_INVALID_URI:
            // Should not happen because we already checked
            throw raiseError("Could not install mobile device management app on managed "
                    + "profile because the package could not be found");
        default:
            throw raiseError("Could not install mobile device management app on managed "
                    + "profile. Unknown status: " + status);
        }
    } catch (RemoteException neverThrown) {
        // Never thrown, as we are making local calls.
        ProvisionLogger.loge("This should not happen.", neverThrown);
    }
}

From source file:android.content.pm.PackageParser.java

private Package parseBaseApk(File apkFile, AssetManager assets, int flags) throws PackageParserException {
    final String apkPath = apkFile.getAbsolutePath();

    String volumeUuid = null;//from www  .  ja  va 2 s. c o  m
    if (apkPath.startsWith(MNT_EXPAND)) {
        final int end = apkPath.indexOf('/', MNT_EXPAND.length());
        volumeUuid = apkPath.substring(MNT_EXPAND.length(), end);
    }

    mParseError = PackageManager.INSTALL_SUCCEEDED;
    mArchiveSourcePath = apkFile.getAbsolutePath();

    if (DEBUG_JAR)
        Slog.d(TAG, "Scanning base APK: " + apkPath);

    final int cookie = loadApkIntoAssetManager(assets, apkPath, flags);

    Resources res = null;
    XmlResourceParser parser = null;
    try {
        res = new Resources(assets, mMetrics, null);
        assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                Build.VERSION.RESOURCES_SDK_INT);
        parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);

        final String[] outError = new String[1];
        final Package pkg = parseBaseApk(res, parser, flags, outError);
        if (pkg == null) {
            throw new PackageParserException(mParseError,
                    apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]);
        }

        pkg.volumeUuid = volumeUuid;
        pkg.applicationInfo.volumeUuid = volumeUuid;
        pkg.baseCodePath = apkPath;
        pkg.mSignatures = null;

        return pkg;

    } catch (PackageParserException e) {
        throw e;
    } catch (Exception e) {
        throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION,
                "Failed to read manifest from " + apkPath, e);
    } finally {
        IoUtils.closeQuietly(parser);
    }
}

From source file:android.content.pm.PackageParser.java

private void parseSplitApk(Package pkg, int splitIndex, AssetManager assets, int flags)
        throws PackageParserException {
    final String apkPath = pkg.splitCodePaths[splitIndex];
    final File apkFile = new File(apkPath);

    mParseError = PackageManager.INSTALL_SUCCEEDED;
    mArchiveSourcePath = apkPath;/*  w  w  w  .  j  a  v a 2 s.  c o  m*/

    if (DEBUG_JAR)
        Slog.d(TAG, "Scanning split APK: " + apkPath);

    final int cookie = loadApkIntoAssetManager(assets, apkPath, flags);

    Resources res = null;
    XmlResourceParser parser = null;
    try {
        res = new Resources(assets, mMetrics, null);
        assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                Build.VERSION.RESOURCES_SDK_INT);
        parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);

        final String[] outError = new String[1];
        pkg = parseSplitApk(pkg, res, parser, flags, splitIndex, outError);
        if (pkg == null) {
            throw new PackageParserException(mParseError,
                    apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]);
        }

    } catch (PackageParserException e) {
        throw e;
    } catch (Exception e) {
        throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION,
                "Failed to read manifest from " + apkPath, e);
    } finally {
        IoUtils.closeQuietly(parser);
    }
}