Settings change for device-wide unknown sources block.

Update the "Install unknown apps" preferences to display the option is
disabled if the global user restriction for unknown apps is turned on.

Test: Manual test, disallowing installs in TestDPC disables installing
unknown sources apps. Also:
atest packages/apps/Settings/tests/robotests/src/com/android/settings/applications/appinfo/ExternalSourcesDetailsTest.java
Bug: 111335021
Change-Id: I235e5fd110e296ed43aa89d7a5ec0d48470c4023
This commit is contained in:
Irina Dumitrescu
2018-09-11 15:19:38 +01:00
parent 744cb8b18f
commit e9c8a0f264
2 changed files with 148 additions and 13 deletions

View File

@@ -80,21 +80,20 @@ public class ExternalSourcesDetails extends AppInfoWithHeader
}
public static CharSequence getPreferenceSummary(Context context, AppEntry entry) {
final UserHandle userHandle = UserHandle.getUserHandleForUid(entry.info.uid);
final UserManager um = UserManager.get(context);
final int userRestrictionSource = um.getUserRestrictionSource(
UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES,
UserHandle.getUserHandleForUid(entry.info.uid));
switch (userRestrictionSource) {
case UserManager.RESTRICTION_SOURCE_DEVICE_OWNER:
case UserManager.RESTRICTION_SOURCE_PROFILE_OWNER:
return context.getString(R.string.disabled_by_admin);
case UserManager.RESTRICTION_SOURCE_SYSTEM:
return context.getString(R.string.disabled);
UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, userHandle)
| um.getUserRestrictionSource(
UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY,
userHandle);
if ((userRestrictionSource & UserManager.RESTRICTION_SOURCE_SYSTEM) != 0) {
return context.getString(R.string.disabled_by_admin);
} else if (userRestrictionSource != 0) {
return context.getString(R.string.disabled);
}
final InstallAppsState appsState = new AppStateInstallAppsBridge(context, null, null)
.createInstallAppsStateFor(entry.info.packageName, entry.info.uid);
return context.getString(appsState.canInstallApps()
? R.string.app_permission_summary_allowed
: R.string.app_permission_summary_not_allowed);
@@ -119,6 +118,10 @@ public class ExternalSourcesDetails extends AppInfoWithHeader
return true;
}
mSwitchPref.checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
if (!mSwitchPref.isDisabledByAdmin()) {
mSwitchPref.checkRestrictionAndSetDisabled(
UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY);
}
if (mSwitchPref.isDisabledByAdmin()) {
return true;
}