@@ -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
0 commit comments