Example usage for android.content.pm PackageManager INSTALL_FAILED_USER_RESTRICTED

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

Introduction

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

Prototype

int INSTALL_FAILED_USER_RESTRICTED

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

Click Source Link

Document

Installation failed return code: this is passed in the PackageInstaller#EXTRA_LEGACY_STATUS if the system failed to install the package because the user is restricted from installing apps.

Usage

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 .  java2s. 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);
    }
}