Loading services/core/java/com/android/server/am/ActiveServices.java +46 −16 Original line number Diff line number Diff line Loading @@ -568,7 +568,7 @@ public final class ActiveServices { try { final ServiceRecord.StartItem si = r.pendingStarts.get(0); startServiceInnerLocked(this, si.intent, r, false, true, si.callingId, r.startRequested); si.mCallingProcessName, r.startRequested); } catch (TransactionTooLargeException e) { // Ignore, nobody upstack cares. } Loading Loading @@ -891,8 +891,10 @@ public final class ActiveServices { // alias component name to the client, not the "target" component name, which is // what realResult contains. final ComponentName realResult = startServiceInnerLocked(r, service, callingUid, callingPid, fgRequired, callerFg, allowBackgroundActivityStarts, backgroundActivityStartsToken); startServiceInnerLocked(r, service, callingUid, callingPid, getCallingProcessNameLocked(callingUid, callingPid, callingPackage), fgRequired, callerFg, allowBackgroundActivityStarts, backgroundActivityStartsToken); if (res.aliasComponent != null && !realResult.getPackageName().startsWith("!") && !realResult.getPackageName().startsWith("?")) { Loading @@ -902,10 +904,18 @@ public final class ActiveServices { } } private String getCallingProcessNameLocked(int callingUid, int callingPid, String callingPackage) { synchronized (mAm.mPidsSelfLocked) { final ProcessRecord callingApp = mAm.mPidsSelfLocked.get(callingPid); return callingApp != null ? callingApp.processName : callingPackage; } } private ComponentName startServiceInnerLocked(ServiceRecord r, Intent service, int callingUid, int callingPid, boolean fgRequired, boolean callerFg, boolean allowBackgroundActivityStarts, @Nullable IBinder backgroundActivityStartsToken) throws TransactionTooLargeException { int callingUid, int callingPid, String callingProcessName, boolean fgRequired, boolean callerFg, boolean allowBackgroundActivityStarts, @Nullable IBinder backgroundActivityStartsToken) throws TransactionTooLargeException { NeededUriGrants neededGrants = mAm.mUgmInternal.checkGrantUriPermissionFromIntent( service, callingUid, r.packageName, r.userId); if (unscheduleServiceRestartLocked(r, callingUid, false)) { Loading @@ -917,7 +927,7 @@ public final class ActiveServices { r.delayedStop = false; r.fgRequired = fgRequired; r.pendingStarts.add(new ServiceRecord.StartItem(r, false, r.makeNextStartId(), service, neededGrants, callingUid)); service, neededGrants, callingUid, callingProcessName)); if (fgRequired) { // We are now effectively running a foreground service. Loading Loading @@ -1002,7 +1012,7 @@ public final class ActiveServices { r.allowBgActivityStartsOnServiceStart(backgroundActivityStartsToken); } ComponentName cmp = startServiceInnerLocked(smap, service, r, callerFg, addToStarting, callingUid, wasStartRequested); callingUid, callingProcessName, wasStartRequested); return cmp; } Loading Loading @@ -1120,6 +1130,8 @@ public final class ActiveServices { curPendingBringups = new ArrayList<>(); mPendingBringups.put(s, curPendingBringups); } final String callingProcessName = getCallingProcessNameLocked( callingUid, callingPid, callingPackage); curPendingBringups.add(new Runnable() { @Override public void run() { Loading Loading @@ -1152,8 +1164,8 @@ public final class ActiveServices { } else { // Starting a service try { startServiceInnerLocked(s, serviceIntent, callingUid, callingPid, fgRequired, callerFg, allowBackgroundActivityStarts, backgroundActivityStartsToken); callingProcessName, fgRequired, callerFg, allowBackgroundActivityStarts, backgroundActivityStartsToken); } catch (TransactionTooLargeException e) { /* ignore - local call */ } Loading Loading @@ -1198,8 +1210,8 @@ public final class ActiveServices { } ComponentName startServiceInnerLocked(ServiceMap smap, Intent service, ServiceRecord r, boolean callerFg, boolean addToStarting, int callingUid, boolean wasStartRequested) throws TransactionTooLargeException { boolean callerFg, boolean addToStarting, int callingUid, String callingProcessName, boolean wasStartRequested) throws TransactionTooLargeException { synchronized (mAm.mProcessStats.mLock) { final ServiceState stracker = r.getTracker(); if (stracker != null) { Loading Loading @@ -1233,7 +1245,8 @@ public final class ActiveServices { ? SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD : (wasStartRequested || !r.getConnections().isEmpty() ? SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_HOT : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM)); : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM), getShortProcessNameForStats(callingUid, callingProcessName)); if (r.startRequested && addToStarting) { boolean first = smap.mStartingBackground.size() == 0; Loading @@ -1256,6 +1269,22 @@ public final class ActiveServices { return r.name; } private @Nullable String getShortProcessNameForStats(int uid, String processName) { final String[] packages = mAm.mContext.getPackageManager().getPackagesForUid(uid); if (packages != null && packages.length == 1) { // Not the shared UID case, let's see if the package name equals to the process name. if (TextUtils.equals(packages[0], processName)) { // same name, just return null here. return null; } else if (processName != null && processName.startsWith(packages[0])) { // return the suffix of the process name return processName.substring(packages[0].length()); } } // return the full process name. return processName; } private void stopServiceLocked(ServiceRecord service, boolean enqueueOomAdj) { try { Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "stopServiceLocked()"); Loading Loading @@ -3199,7 +3228,8 @@ public final class ActiveServices { ? SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD : (wasStartRequested || hadConnections ? SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_HOT : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM)); : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM), getShortProcessNameForStats(callingUid, callerApp.processName)); if (DEBUG_SERVICE) Slog.v(TAG_SERVICE, "Bind " + s + " with " + b + ": received=" + b.intent.received Loading Loading @@ -4715,7 +4745,7 @@ public final class ActiveServices { // be called. if (r.startRequested && r.callStart && r.pendingStarts.size() == 0) { r.pendingStarts.add(new ServiceRecord.StartItem(r, false, r.makeNextStartId(), null, null, 0)); null, null, 0, null)); } sendServiceArgsLocked(r, execInFg, true); Loading Loading @@ -5689,7 +5719,7 @@ public final class ActiveServices { stopServiceLocked(sr, true); } else { sr.pendingStarts.add(new ServiceRecord.StartItem(sr, true, sr.getLastStartId(), baseIntent, null, 0)); sr.getLastStartId(), baseIntent, null, 0, null)); if (sr.app != null && sr.app.getThread() != null) { // We always run in the foreground, since this is called as // part of the "remove task" UI operation. Loading services/core/java/com/android/server/am/ServiceRecord.java +5 −2 Original line number Diff line number Diff line Loading @@ -237,6 +237,7 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN final boolean taskRemoved; final int id; final int callingId; final String mCallingProcessName; final Intent intent; final NeededUriGrants neededGrants; long deliveredTime; Loading @@ -246,14 +247,16 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN String stringName; // caching of toString StartItem(ServiceRecord _sr, boolean _taskRemoved, int _id, Intent _intent, NeededUriGrants _neededGrants, int _callingId) { StartItem(ServiceRecord _sr, boolean _taskRemoved, int _id, Intent _intent, NeededUriGrants _neededGrants, int _callingId, String callingProcessName) { sr = _sr; taskRemoved = _taskRemoved; id = _id; intent = _intent; neededGrants = _neededGrants; callingId = _callingId; mCallingProcessName = callingProcessName; } UriPermissionOwner getUriPermissionsLocked() { Loading Loading
services/core/java/com/android/server/am/ActiveServices.java +46 −16 Original line number Diff line number Diff line Loading @@ -568,7 +568,7 @@ public final class ActiveServices { try { final ServiceRecord.StartItem si = r.pendingStarts.get(0); startServiceInnerLocked(this, si.intent, r, false, true, si.callingId, r.startRequested); si.mCallingProcessName, r.startRequested); } catch (TransactionTooLargeException e) { // Ignore, nobody upstack cares. } Loading Loading @@ -891,8 +891,10 @@ public final class ActiveServices { // alias component name to the client, not the "target" component name, which is // what realResult contains. final ComponentName realResult = startServiceInnerLocked(r, service, callingUid, callingPid, fgRequired, callerFg, allowBackgroundActivityStarts, backgroundActivityStartsToken); startServiceInnerLocked(r, service, callingUid, callingPid, getCallingProcessNameLocked(callingUid, callingPid, callingPackage), fgRequired, callerFg, allowBackgroundActivityStarts, backgroundActivityStartsToken); if (res.aliasComponent != null && !realResult.getPackageName().startsWith("!") && !realResult.getPackageName().startsWith("?")) { Loading @@ -902,10 +904,18 @@ public final class ActiveServices { } } private String getCallingProcessNameLocked(int callingUid, int callingPid, String callingPackage) { synchronized (mAm.mPidsSelfLocked) { final ProcessRecord callingApp = mAm.mPidsSelfLocked.get(callingPid); return callingApp != null ? callingApp.processName : callingPackage; } } private ComponentName startServiceInnerLocked(ServiceRecord r, Intent service, int callingUid, int callingPid, boolean fgRequired, boolean callerFg, boolean allowBackgroundActivityStarts, @Nullable IBinder backgroundActivityStartsToken) throws TransactionTooLargeException { int callingUid, int callingPid, String callingProcessName, boolean fgRequired, boolean callerFg, boolean allowBackgroundActivityStarts, @Nullable IBinder backgroundActivityStartsToken) throws TransactionTooLargeException { NeededUriGrants neededGrants = mAm.mUgmInternal.checkGrantUriPermissionFromIntent( service, callingUid, r.packageName, r.userId); if (unscheduleServiceRestartLocked(r, callingUid, false)) { Loading @@ -917,7 +927,7 @@ public final class ActiveServices { r.delayedStop = false; r.fgRequired = fgRequired; r.pendingStarts.add(new ServiceRecord.StartItem(r, false, r.makeNextStartId(), service, neededGrants, callingUid)); service, neededGrants, callingUid, callingProcessName)); if (fgRequired) { // We are now effectively running a foreground service. Loading Loading @@ -1002,7 +1012,7 @@ public final class ActiveServices { r.allowBgActivityStartsOnServiceStart(backgroundActivityStartsToken); } ComponentName cmp = startServiceInnerLocked(smap, service, r, callerFg, addToStarting, callingUid, wasStartRequested); callingUid, callingProcessName, wasStartRequested); return cmp; } Loading Loading @@ -1120,6 +1130,8 @@ public final class ActiveServices { curPendingBringups = new ArrayList<>(); mPendingBringups.put(s, curPendingBringups); } final String callingProcessName = getCallingProcessNameLocked( callingUid, callingPid, callingPackage); curPendingBringups.add(new Runnable() { @Override public void run() { Loading Loading @@ -1152,8 +1164,8 @@ public final class ActiveServices { } else { // Starting a service try { startServiceInnerLocked(s, serviceIntent, callingUid, callingPid, fgRequired, callerFg, allowBackgroundActivityStarts, backgroundActivityStartsToken); callingProcessName, fgRequired, callerFg, allowBackgroundActivityStarts, backgroundActivityStartsToken); } catch (TransactionTooLargeException e) { /* ignore - local call */ } Loading Loading @@ -1198,8 +1210,8 @@ public final class ActiveServices { } ComponentName startServiceInnerLocked(ServiceMap smap, Intent service, ServiceRecord r, boolean callerFg, boolean addToStarting, int callingUid, boolean wasStartRequested) throws TransactionTooLargeException { boolean callerFg, boolean addToStarting, int callingUid, String callingProcessName, boolean wasStartRequested) throws TransactionTooLargeException { synchronized (mAm.mProcessStats.mLock) { final ServiceState stracker = r.getTracker(); if (stracker != null) { Loading Loading @@ -1233,7 +1245,8 @@ public final class ActiveServices { ? SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD : (wasStartRequested || !r.getConnections().isEmpty() ? SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_HOT : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM)); : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM), getShortProcessNameForStats(callingUid, callingProcessName)); if (r.startRequested && addToStarting) { boolean first = smap.mStartingBackground.size() == 0; Loading @@ -1256,6 +1269,22 @@ public final class ActiveServices { return r.name; } private @Nullable String getShortProcessNameForStats(int uid, String processName) { final String[] packages = mAm.mContext.getPackageManager().getPackagesForUid(uid); if (packages != null && packages.length == 1) { // Not the shared UID case, let's see if the package name equals to the process name. if (TextUtils.equals(packages[0], processName)) { // same name, just return null here. return null; } else if (processName != null && processName.startsWith(packages[0])) { // return the suffix of the process name return processName.substring(packages[0].length()); } } // return the full process name. return processName; } private void stopServiceLocked(ServiceRecord service, boolean enqueueOomAdj) { try { Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "stopServiceLocked()"); Loading Loading @@ -3199,7 +3228,8 @@ public final class ActiveServices { ? SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD : (wasStartRequested || hadConnections ? SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_HOT : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM)); : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM), getShortProcessNameForStats(callingUid, callerApp.processName)); if (DEBUG_SERVICE) Slog.v(TAG_SERVICE, "Bind " + s + " with " + b + ": received=" + b.intent.received Loading Loading @@ -4715,7 +4745,7 @@ public final class ActiveServices { // be called. if (r.startRequested && r.callStart && r.pendingStarts.size() == 0) { r.pendingStarts.add(new ServiceRecord.StartItem(r, false, r.makeNextStartId(), null, null, 0)); null, null, 0, null)); } sendServiceArgsLocked(r, execInFg, true); Loading Loading @@ -5689,7 +5719,7 @@ public final class ActiveServices { stopServiceLocked(sr, true); } else { sr.pendingStarts.add(new ServiceRecord.StartItem(sr, true, sr.getLastStartId(), baseIntent, null, 0)); sr.getLastStartId(), baseIntent, null, 0, null)); if (sr.app != null && sr.app.getThread() != null) { // We always run in the foreground, since this is called as // part of the "remove task" UI operation. Loading
services/core/java/com/android/server/am/ServiceRecord.java +5 −2 Original line number Diff line number Diff line Loading @@ -237,6 +237,7 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN final boolean taskRemoved; final int id; final int callingId; final String mCallingProcessName; final Intent intent; final NeededUriGrants neededGrants; long deliveredTime; Loading @@ -246,14 +247,16 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN String stringName; // caching of toString StartItem(ServiceRecord _sr, boolean _taskRemoved, int _id, Intent _intent, NeededUriGrants _neededGrants, int _callingId) { StartItem(ServiceRecord _sr, boolean _taskRemoved, int _id, Intent _intent, NeededUriGrants _neededGrants, int _callingId, String callingProcessName) { sr = _sr; taskRemoved = _taskRemoved; id = _id; intent = _intent; neededGrants = _neededGrants; callingId = _callingId; mCallingProcessName = callingProcessName; } UriPermissionOwner getUriPermissionsLocked() { Loading