diff options
author | Suprabh Shukla <suprabh@google.com> | 2017-05-31 17:31:55 -0700 |
---|---|---|
committer | Suprabh Shukla <suprabh@google.com> | 2017-05-31 17:36:06 -0700 |
commit | 0f31f0219b4f922aa277a25f1c2a703170384e28 (patch) | |
tree | 7f1e1faa8792282887435639a725049ebd4d3c88 | |
parent | 7dbee6164702b7e55569094057a71dbe8b100f62 (diff) | |
download | android_packages_apps_PackageInstaller-0f31f0219b4f922aa277a25f1c2a703170384e28.tar.gz android_packages_apps_PackageInstaller-0f31f0219b4f922aa277a25f1c2a703170384e28.tar.bz2 android_packages_apps_PackageInstaller-0f31f0219b4f922aa277a25f1c2a703170384e28.zip |
Checking user restriction before starting install
Package installer was crashing because package manager threw a security
exception if the user restriction DISALLOW_INSTALL_APPS was set.
Test: Manual
Fixes: 62204640
Change-Id: Ic69f30c4271fad618695ab9a5b635799c1c776c5
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/com/android/packageinstaller/PackageInstallerActivity.java | 46 |
2 files changed, 26 insertions, 22 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index 9992a41f..ea28de68 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -84,6 +84,8 @@ <!-- Message presented in a dialog box when the user restriction set by the system restricts the installation of apps from unknown sources. [CHAR LIMIT=none] --> <string name="unknown_apps_user_restriction_dlg_text">Unknown apps can\'t be installed by this user</string> + <!-- Message presented in a dialog box when the user restriction set by the system restricts the installation of apps. [CHAR LIMIT=none] --> + <string name="install_apps_user_restriction_dlg_text">This user is not allowed to install apps</string> <string name="ok">OK</string> diff --git a/src/com/android/packageinstaller/PackageInstallerActivity.java b/src/com/android/packageinstaller/PackageInstallerActivity.java index 4d33a3af..1e6a6b75 100644 --- a/src/com/android/packageinstaller/PackageInstallerActivity.java +++ b/src/com/android/packageinstaller/PackageInstallerActivity.java @@ -124,6 +124,7 @@ public class PackageInstallerActivity extends Activity implements OnClickListene private static final int DLG_ANONYMOUS_SOURCE = DLG_BASE + 6; private static final int DLG_NOT_SUPPORTED_ON_WEAR = DLG_BASE + 7; private static final int DLG_EXTERNAL_SOURCE_BLOCKED = DLG_BASE + 8; + private static final int DLG_INSTALL_APPS_RESTRICTED_FOR_USER = DLG_BASE + 9; // If unknown sources are temporary allowed private boolean mAllowUnknownSources; @@ -268,6 +269,9 @@ public class PackageInstallerActivity extends Activity implements OnClickListene mPm.getApplicationLabel(mPkgInfo.applicationInfo)); case DLG_NOT_SUPPORTED_ON_WEAR: return NotSupportedOnWearDialog.newInstance(); + case DLG_INSTALL_APPS_RESTRICTED_FOR_USER: + return SimpleErrorDialog.newInstance( + R.string.install_apps_user_restriction_dlg_text); case DLG_UNKNOWN_SOURCES_RESTRICTED_FOR_USER: return SimpleErrorDialog.newInstance( R.string.unknown_apps_user_restriction_dlg_text); @@ -281,9 +285,6 @@ public class PackageInstallerActivity extends Activity implements OnClickListene @Override public void onActivityResult(int request, int result, Intent data) { - // currently just a hook for partners to implement "allow once" feature - // TODO: Use this to resume install request when user has explicitly trusted the source - // by changing the settings if (request == REQUEST_TRUST_EXTERNAL_SOURCE && result == RESULT_OK) { mAllowUnknownSources = true; @@ -330,13 +331,6 @@ public class PackageInstallerActivity extends Activity implements OnClickListene return true; } - /** - * @return whether the device admin restricts installation from unknown sources - */ - private boolean isUnknownSourcesDisallowed() { - return mUserManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES); - } - private void initiateInstall() { String pkgName = mPkgInfo.packageName; // Check if there is already a package on the device with this name @@ -468,24 +462,32 @@ public class PackageInstallerActivity extends Activity implements OnClickListene * show the appropriate dialog. */ private void checkIfAllowedAndInitiateInstall() { - if (mAllowUnknownSources || !isInstallRequestFromUnknownSource(getIntent())) { - initiateInstall(); + // Check for install apps user restriction first. + final int installAppsRestrictionSource = mUserManager.getUserRestrictionSource( + UserManager.DISALLOW_INSTALL_APPS, Process.myUserHandle()); + if ((installAppsRestrictionSource & UserManager.RESTRICTION_SOURCE_SYSTEM) != 0) { + showDialogInner(DLG_INSTALL_APPS_RESTRICTED_FOR_USER); + return; + } else if (installAppsRestrictionSource != UserManager.RESTRICTION_NOT_SET) { + startActivity(new Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS)); + finish(); return; } - // If the admin prohibits it, just show error and exit. - if (isUnknownSourcesDisallowed()) { - if ((mUserManager.getUserRestrictionSource(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, - Process.myUserHandle()) & UserManager.RESTRICTION_SOURCE_SYSTEM) != 0) { - // Someone set user restriction via UserManager#setUserRestriction. We don't want to - // break apps that might already be doing this + + if (mAllowUnknownSources || !isInstallRequestFromUnknownSource(getIntent())) { + initiateInstall(); + } else { + // Check for unknown sources restriction + final int unknownSourcesRestrictionSource = mUserManager.getUserRestrictionSource( + UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, Process.myUserHandle()); + if ((unknownSourcesRestrictionSource & UserManager.RESTRICTION_SOURCE_SYSTEM) != 0) { showDialogInner(DLG_UNKNOWN_SOURCES_RESTRICTED_FOR_USER); - return; - } else { + } else if (unknownSourcesRestrictionSource != UserManager.RESTRICTION_NOT_SET) { startActivity(new Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS)); finish(); + } else { + handleUnknownSources(); } - } else { - handleUnknownSources(); } } |