Merge "Multi-user Data Saver fixes:" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e877d2d791
@@ -442,42 +442,51 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
*
|
*
|
||||||
* @return whether any uid has been added to {@link #mRestrictBackgroundWhitelistUids}.
|
* @return whether any uid has been added to {@link #mRestrictBackgroundWhitelistUids}.
|
||||||
*/
|
*/
|
||||||
boolean addDefaultRestrictBackgroundWhitelistUids() {
|
boolean addDefaultRestrictBackgroundWhitelistUidsLocked() {
|
||||||
final SystemConfig sysConfig = SystemConfig.getInstance();
|
|
||||||
final PackageManager pm = mContext.getPackageManager();
|
|
||||||
final List<UserInfo> users = mUserManager.getUsers();
|
final List<UserInfo> users = mUserManager.getUsers();
|
||||||
final int numberUsers = users.size();
|
final int numberUsers = users.size();
|
||||||
|
|
||||||
|
boolean changed = false;
|
||||||
|
for (int i = 0; i < numberUsers; i++) {
|
||||||
|
final UserInfo user = users.get(i);
|
||||||
|
changed = addDefaultRestrictBackgroundWhitelistUidsLocked(user.id) || changed;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean addDefaultRestrictBackgroundWhitelistUidsLocked(int userId) {
|
||||||
|
final SystemConfig sysConfig = SystemConfig.getInstance();
|
||||||
|
final PackageManager pm = mContext.getPackageManager();
|
||||||
final ArraySet<String> allowDataUsage = sysConfig.getAllowInDataUsageSave();
|
final ArraySet<String> allowDataUsage = sysConfig.getAllowInDataUsageSave();
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
for (int i = 0; i < allowDataUsage.size(); i++) {
|
for (int i = 0; i < allowDataUsage.size(); i++) {
|
||||||
final String pkg = allowDataUsage.valueAt(i);
|
final String pkg = allowDataUsage.valueAt(i);
|
||||||
if (LOGD)
|
if (LOGD)
|
||||||
Slog.d(TAG, "checking restricted background whitelisting for package " + pkg);
|
Slog.d(TAG, "checking restricted background whitelisting for package " + pkg
|
||||||
|
+ " and user " + userId);
|
||||||
final ApplicationInfo app;
|
final ApplicationInfo app;
|
||||||
try {
|
try {
|
||||||
app = pm.getApplicationInfo(pkg, PackageManager.MATCH_SYSTEM_ONLY);
|
app = pm.getApplicationInfoAsUser(pkg, PackageManager.MATCH_SYSTEM_ONLY, userId);
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
// Should not happen
|
// Should not happen
|
||||||
Slog.wtf(TAG, "No ApplicationInfo for package " + pkg);
|
Slog.wtf(TAG, "No ApplicationInfo for package " + pkg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!app.isPrivilegedApp()) {
|
if (!app.isPrivilegedApp()) {
|
||||||
Slog.w(TAG, "getAllowInDataUsageSave() returned non-privileged app: " + pkg);
|
Slog.wtf(TAG, "pm.getApplicationInfoAsUser() returned non-privileged app: " + pkg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int j = 0; j < numberUsers; j++) {
|
final int uid = UserHandle.getUid(userId, app.uid);
|
||||||
final UserInfo user = users.get(j);
|
mDefaultRestrictBackgroundWhitelistUids.append(uid, true);
|
||||||
final int uid = UserHandle.getUid(user.id, app.uid);
|
if (LOGD)
|
||||||
mDefaultRestrictBackgroundWhitelistUids.append(uid, true);
|
Slog.d(TAG, "Adding uid " + uid + " (user " + userId + ") to default restricted "
|
||||||
if (LOGD) Slog.d(TAG, "revoked whistelist status for uid " + uid + ": "
|
+ "background whitelist. Revoked status: "
|
||||||
+ mRestrictBackgroundWhitelistRevokedUids.get(uid));
|
+ mRestrictBackgroundWhitelistRevokedUids.get(uid));
|
||||||
if (!mRestrictBackgroundWhitelistRevokedUids.get(uid)) {
|
if (!mRestrictBackgroundWhitelistRevokedUids.get(uid)) {
|
||||||
Slog.i(TAG, "adding default package " + pkg + " (uid " + uid + " for user "
|
Slog.i(TAG, "adding default package " + pkg + " (uid " + uid + " for user "
|
||||||
+ user.id + ") to restrict background whitelist");
|
+ userId + ") to restrict background whitelist");
|
||||||
mRestrictBackgroundWhitelistUids.append(uid, true);
|
mRestrictBackgroundWhitelistUids.append(uid, true);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
@@ -546,7 +555,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
// read policy from disk
|
// read policy from disk
|
||||||
readPolicyLocked();
|
readPolicyLocked();
|
||||||
|
|
||||||
if (addDefaultRestrictBackgroundWhitelistUids()) {
|
if (addDefaultRestrictBackgroundWhitelistUidsLocked()) {
|
||||||
writePolicyLocked();
|
writePolicyLocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -734,7 +743,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
// Remove any persistable state for the given user; both cleaning up after a
|
// Remove any persistable state for the given user; both cleaning up after a
|
||||||
// USER_REMOVED, and one last sanity check during USER_ADDED
|
// USER_REMOVED, and one last sanity check during USER_ADDED
|
||||||
removeUserStateLocked(userId);
|
removeUserStateLocked(userId);
|
||||||
// Update global restrict for new user
|
if (action == ACTION_USER_ADDED) {
|
||||||
|
// Add apps that are whitelisted by default.
|
||||||
|
addDefaultRestrictBackgroundWhitelistUidsLocked(userId);
|
||||||
|
}
|
||||||
|
// Update global restrict for that user
|
||||||
updateRulesForGlobalChangeLocked(true);
|
updateRulesForGlobalChangeLocked(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1751,6 +1764,16 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
writePolicy = true;
|
writePolicy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove entries from revoked default restricted background UID whitelist
|
||||||
|
for (int i = mRestrictBackgroundWhitelistRevokedUids.size() - 1; i >= 0; i--) {
|
||||||
|
final int uid = mRestrictBackgroundWhitelistRevokedUids.keyAt(i);
|
||||||
|
if (UserHandle.getUserId(uid) == userId) {
|
||||||
|
mRestrictBackgroundWhitelistRevokedUids.removeAt(i);
|
||||||
|
writePolicy = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove associated UID policies
|
// Remove associated UID policies
|
||||||
int[] uids = new int[0];
|
int[] uids = new int[0];
|
||||||
for (int i = 0; i < mUidPolicy.size(); i++) {
|
for (int i = 0; i < mUidPolicy.size(); i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user