Example usage for android.content.pm PackageManager INSTALL_FAILED_INVALID_URI

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

Introduction

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

Prototype

int INSTALL_FAILED_INVALID_URI

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

Click Source Link

Document

Installation return code: this is passed in the PackageInstaller#EXTRA_LEGACY_STATUS if the URI passed in is invalid.

Usage

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

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mPm = getPackageManager();//  w  w w  . j  a va  2 s .  c o  m
    mInstaller = mPm.getPackageInstaller();
    mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);

    final Intent intent = getIntent();
    mOriginatingUid = getOriginatingUid(intent);

    final Uri packageUri;

    if (PackageInstaller.ACTION_CONFIRM_PERMISSIONS.equals(intent.getAction())) {
        final int sessionId = intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, -1);
        final PackageInstaller.SessionInfo info = mInstaller.getSessionInfo(sessionId);
        if (info == null || !info.sealed || info.resolvedBaseCodePath == null) {
            Log.w(TAG, "Session " + mSessionId + " in funky state; ignoring");
            finish();
            return;
        }

        mSessionId = sessionId;
        packageUri = Uri.fromFile(new File(info.resolvedBaseCodePath));
        mOriginatingURI = null;
        mReferrerURI = null;
    } else {
        mSessionId = -1;
        packageUri = intent.getData();
        mOriginatingURI = intent.getParcelableExtra(Intent.EXTRA_ORIGINATING_URI);
        mReferrerURI = intent.getParcelableExtra(Intent.EXTRA_REFERRER);
    }

    // if there's nothing to do, quietly slip into the ether
    if (packageUri == null) {
        Log.w(TAG, "Unspecified source");
        setPmResult(PackageManager.INSTALL_FAILED_INVALID_URI);
        finish();
        return;
    }

    if (DeviceUtils.isWear(this)) {
        showDialogInner(DLG_NOT_SUPPORTED_ON_WEAR);
        return;
    }

    //set view
    setContentView(R.layout.install_start);
    mInstallConfirm = findViewById(R.id.install_confirm_panel);
    mInstallConfirm.setVisibility(View.INVISIBLE);
    mOk = (Button) findViewById(R.id.ok_button);
    mCancel = (Button) findViewById(R.id.cancel_button);
    mOk.setOnClickListener(this);
    mCancel.setOnClickListener(this);

    // Block the install attempt on the Unknown Sources setting if necessary.
    final boolean requestFromUnknownSource = isInstallRequestFromUnknownSource(intent);
    if (!requestFromUnknownSource) {
        processPackageUri(packageUri);
        return;
    }

    // If the admin prohibits it, or we're running in a managed profile, just show error
    // and exit. Otherwise show an option to take the user to Settings to change the setting.
    final boolean isManagedProfile = mUserManager.isManagedProfile();
    if (!isUnknownSourcesAllowedByAdmin()) {
        startActivity(new Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS));
        clearCachedApkIfNeededAndFinish();
    } else if (!isUnknownSourcesEnabled() && isManagedProfile) {
        showDialogInner(DLG_ADMIN_RESTRICTS_UNKNOWN_SOURCES);
    } else if (!isUnknownSourcesEnabled()) {
        // Ask user to enable setting first

        showDialogInner(DLG_UNKNOWN_SOURCES);
    } else {
        processPackageUri(packageUri);
    }
}

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 ww w  .  j  a v  a  2 s. 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:com.android.packageinstaller.PackageInstallerActivity.java

private void processPackageUri(final Uri packageUri) {
    mPackageURI = packageUri;//from  ww  w  .j ava  2 s  .  co  m

    final String scheme = packageUri.getScheme();
    final PackageUtil.AppSnippet as;

    switch (scheme) {
    case SCHEME_PACKAGE: {
        try {
            mPkgInfo = mPm.getPackageInfo(packageUri.getSchemeSpecificPart(),
                    PackageManager.GET_PERMISSIONS | PackageManager.GET_UNINSTALLED_PACKAGES);
        } catch (NameNotFoundException e) {
        }
        if (mPkgInfo == null) {
            Log.w(TAG, "Requested package " + packageUri.getScheme()
                    + " not available. Discontinuing installation");
            showDialogInner(DLG_PACKAGE_ERROR);
            setPmResult(PackageManager.INSTALL_FAILED_INVALID_APK);
            return;
        }
        as = new PackageUtil.AppSnippet(mPm.getApplicationLabel(mPkgInfo.applicationInfo),
                mPm.getApplicationIcon(mPkgInfo.applicationInfo));
    }
        break;

    case SCHEME_FILE: {
        File sourceFile = new File(packageUri.getPath());
        PackageParser.Package parsed = PackageUtil.getPackageInfo(sourceFile);

        // Check for parse errors
        if (parsed == null) {
            Log.w(TAG, "Parse error when parsing manifest. Discontinuing installation");
            showDialogInner(DLG_PACKAGE_ERROR);
            setPmResult(PackageManager.INSTALL_FAILED_INVALID_APK);
            return;
        }
        mPkgInfo = PackageParser.generatePackageInfo(parsed, null, PackageManager.GET_PERMISSIONS, 0, 0, null,
                new PackageUserState());
        as = PackageUtil.getAppSnippet(this, mPkgInfo.applicationInfo, sourceFile);
    }
        break;

    case SCHEME_CONTENT: {
        mStagingAsynTask = new StagingAsyncTask();
        mStagingAsynTask.execute(packageUri);
        return;
    }

    default: {
        Log.w(TAG, "Unsupported scheme " + scheme);
        setPmResult(PackageManager.INSTALL_FAILED_INVALID_URI);
        clearCachedApkIfNeededAndFinish();
        return;
    }
    }

    PackageUtil.initSnippetForNewApp(this, as, R.id.app_snippet);

    initiateInstall();
}