Skip to content

Commit d95ce04

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "Make sure persistent processes are not replicated for secondary users."
2 parents 0192e96 + a4a54e2 commit d95ce04

File tree

4 files changed

+53
-18
lines changed

4 files changed

+53
-18
lines changed

core/java/android/content/pm/PackageParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,9 +3458,9 @@ public static ApplicationInfo generateApplicationInfo(Package p, int flags,
34583458
ai.disableCompatibilityMode();
34593459
}
34603460
if (stopped) {
3461-
p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3461+
ai.flags |= ApplicationInfo.FLAG_STOPPED;
34623462
} else {
3463-
p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3463+
ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
34643464
}
34653465
if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
34663466
ai.enabled = true;

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,16 +1808,18 @@ final void updateLruProcessLocked(ProcessRecord app,
18081808

18091809
final ProcessRecord getProcessRecordLocked(
18101810
String processName, int uid) {
1811-
// Temporary hack to make Settings run per user
1812-
if (uid == Process.SYSTEM_UID && !processName.equals("com.android.settings")) {
1811+
if (uid == Process.SYSTEM_UID) {
18131812
// The system gets to run in any process. If there are multiple
18141813
// processes with the same uid, just pick the first (this
18151814
// should never happen).
18161815
SparseArray<ProcessRecord> procs = mProcessNames.getMap().get(
18171816
processName);
1818-
return procs != null ? procs.valueAt(0) : null;
1817+
if (procs == null) return null;
1818+
final int N = procs.size();
1819+
for (int i = 0; i < N; i++) {
1820+
if (UserId.isSameUser(procs.keyAt(i), uid)) return procs.valueAt(i);
1821+
}
18191822
}
1820-
// uid = applyUserId(uid);
18211823
ProcessRecord proc = mProcessNames.get(processName, uid);
18221824
return proc;
18231825
}
@@ -6183,7 +6185,9 @@ private final ContentProviderHolder getContentProviderImpl(IApplicationThread ca
61836185
if (cpi == null) {
61846186
return null;
61856187
}
6186-
6188+
if (isSingleton(cpi.processName, cpi.applicationInfo)) {
6189+
userId = 0;
6190+
}
61876191
cpi.applicationInfo = getAppInfoForUser(cpi.applicationInfo, userId);
61886192

61896193
String msg;
@@ -10923,6 +10927,9 @@ private ServiceLookupResult retrieveServiceLocked(Intent service,
1092310927
return null;
1092410928
}
1092510929
if (userId > 0) {
10930+
if (isSingleton(sInfo.processName, sInfo.applicationInfo)) {
10931+
userId = 0;
10932+
}
1092610933
sInfo.applicationInfo = getAppInfoForUser(sInfo.applicationInfo, userId);
1092710934
}
1092810935
ComponentName name = new ComponentName(
@@ -11740,7 +11747,22 @@ public void updateServiceForegroundLocked(ProcessRecord proc, boolean oomAdj) {
1174011747
}
1174111748
}
1174211749
}
11743-
11750+
11751+
boolean isSingleton(String componentProcessName, ApplicationInfo aInfo) {
11752+
boolean result = false;
11753+
if (UserId.getAppId(aInfo.uid) >= Process.FIRST_APPLICATION_UID) {
11754+
result = false;
11755+
} else if (componentProcessName == aInfo.packageName) {
11756+
result = (aInfo.flags & ApplicationInfo.FLAG_PERSISTENT) != 0;
11757+
} else if ("system".equals(componentProcessName)) {
11758+
result = true;
11759+
}
11760+
if (DEBUG_MU) {
11761+
Slog.v(TAG, "isSingleton(" + componentProcessName + ", " + aInfo + ") = " + result);
11762+
}
11763+
return result;
11764+
}
11765+
1174411766
public int bindService(IApplicationThread caller, IBinder token,
1174511767
Intent service, String resolvedType,
1174611768
IServiceConnection connection, int flags, int userId) {
@@ -11808,6 +11830,11 @@ public int bindService(IApplicationThread caller, IBinder token,
1180811830
if (res.record == null) {
1180911831
return -1;
1181011832
}
11833+
if (isSingleton(res.record.processName, res.record.appInfo)) {
11834+
userId = 0;
11835+
res = retrieveServiceLocked(service, resolvedType, Binder.getCallingPid(),
11836+
Binder.getCallingUid(), 0);
11837+
}
1181111838
ServiceRecord s = res.record;
1181211839

1181311840
final long origId = Binder.clearCallingIdentity();
@@ -12740,7 +12767,11 @@ private final int broadcastIntentLocked(ProcessRecord callerApp,
1274012767
if (ai != null) {
1274112768
receivers = new ArrayList();
1274212769
ResolveInfo ri = new ResolveInfo();
12743-
ri.activityInfo = getActivityInfoForUser(ai, userId);
12770+
if (isSingleton(ai.processName, ai.applicationInfo)) {
12771+
ri.activityInfo = getActivityInfoForUser(ai, 0);
12772+
} else {
12773+
ri.activityInfo = getActivityInfoForUser(ai, userId);
12774+
}
1274412775
receivers.add(ri);
1274512776
}
1274612777
} else {
@@ -14894,16 +14925,14 @@ private ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) {
1489414925
if (info == null) return null;
1489514926
ApplicationInfo newInfo = new ApplicationInfo(info);
1489614927
newInfo.uid = applyUserId(info.uid, userId);
14897-
if (newInfo.uid >= Process.FIRST_APPLICATION_UID) {
14898-
newInfo.dataDir = USER_DATA_DIR + userId + "/"
14899-
+ info.packageName;
14900-
}
14928+
newInfo.dataDir = USER_DATA_DIR + userId + "/"
14929+
+ info.packageName;
1490114930
return newInfo;
1490214931
}
1490314932

1490414933
ActivityInfo getActivityInfoForUser(ActivityInfo aInfo, int userId) {
14905-
if (aInfo == null || aInfo.applicationInfo.uid < Process.FIRST_APPLICATION_UID
14906-
|| userId < 1) {
14934+
if (aInfo == null
14935+
|| (userId < 1 && aInfo.applicationInfo.uid < UserId.PER_USER_RANGE)) {
1490714936
return aInfo;
1490814937
}
1490914938

services/java/com/android/server/am/ActivityStack.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2345,8 +2345,9 @@ final int startActivityLocked(IApplicationThread caller,
23452345
}
23462346

23472347
if (err == ActivityManager.START_SUCCESS) {
2348+
final int userId = aInfo != null ? UserId.getUserId(aInfo.applicationInfo.uid) : 0;
23482349
Slog.i(TAG, "START {" + intent.toShortString(true, true, true, false)
2349-
+ "} from pid " + (callerApp != null ? callerApp.pid : callingPid));
2350+
+ " u=" + userId + "} from pid " + (callerApp != null ? callerApp.pid : callingPid));
23502351
}
23512352

23522353
ActivityRecord sourceRecord = null;
@@ -2943,6 +2944,9 @@ final int startActivityMayWait(IApplicationThread caller, int callingUid,
29432944
// Collect information about the target of the Intent.
29442945
ActivityInfo aInfo = resolveActivity(intent, resolvedType, startFlags,
29452946
profileFile, profileFd, userId);
2947+
if (mService.isSingleton(aInfo.processName, aInfo.applicationInfo)) {
2948+
userId = 0;
2949+
}
29462950
aInfo = mService.getActivityInfoForUser(aInfo, userId);
29472951

29482952
synchronized (mService) {

services/java/com/android/server/am/BroadcastQueue.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,10 @@ final void processNextBroadcast(boolean fromMsg) {
719719
info.activityInfo.applicationInfo.packageName,
720720
info.activityInfo.name);
721721
if (r.callingUid != Process.SYSTEM_UID) {
722-
info.activityInfo = mService.getActivityInfoForUser(info.activityInfo, UserId
723-
.getUserId(r.callingUid));
722+
boolean isSingleton = mService.isSingleton(info.activityInfo.processName,
723+
info.activityInfo.applicationInfo);
724+
int targetUserId = isSingleton ? 0 : UserId.getUserId(r.callingUid);
725+
info.activityInfo = mService.getActivityInfoForUser(info.activityInfo,targetUserId);
724726
}
725727
r.curReceiver = info.activityInfo;
726728
if (DEBUG_MU && r.callingUid > UserId.PER_USER_RANGE) {

0 commit comments

Comments
 (0)