Removes direct use of LocalServices.getService
To improve testability, we're relying on dependencies passed into
PackageManagerService via constructor. This change addresses all
dependencies fetched via LocalServices and context.getSystemService.
Test: atest ScanTests
Bug: 137881067
Change-Id: Ifa781fadc44996f3a88db40a956dd0e0d1f9ebb2
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index 2f30863..a707aa8 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -1557,11 +1557,7 @@
/** @return a specific user restriction that's in effect currently. */
@Override
public boolean hasUserRestriction(String restrictionKey, int userId) {
- if (!UserRestrictionsUtils.isValidRestriction(restrictionKey)) {
- return false;
- }
- Bundle restrictions = getEffectiveUserRestrictions(userId);
- return restrictions != null && restrictions.getBoolean(restrictionKey);
+ return mLocalService.hasUserRestriction(restrictionKey, userId);
}
/** @return if any user has the given restriction. */
@@ -4128,6 +4124,15 @@
return UserRestrictionsUtils.isSettingRestrictedForUser(mContext, setting, userId,
value, callingUid);
}
+
+ @Override
+ public boolean hasUserRestriction(String restrictionKey, int userId) {
+ if (!UserRestrictionsUtils.isValidRestriction(restrictionKey)) {
+ return false;
+ }
+ Bundle restrictions = getEffectiveUserRestrictions(userId);
+ return restrictions != null && restrictions.getBoolean(restrictionKey);
+ }
}
/* Remove all the users except of the system one. */