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