Android系统在新进程中启动自定义服务过程(sta(3)

参数resolvedType是一个字符串,它表示service这个Intent的MIME类型,它是在解析Intent时用到的。在这个例子中,我们没有指定这个Intent 的MIME类型,因此,这个参数为null。

ActivityManagerProxy类的startService函数把这三个参数写入到data本地变量去,接着通过mRemote.transact函数进入到Binder驱动程序,然后Binder驱动程序唤醒正在等待Client请求的ActivityManagerService进程,最后进入到ActivityManagerService的startService函数中。

ActivityManagerService的startService函数的处理流程如下图所示:

Android系统在新进程中启动自定义服务过程(sta

在这个序列图中,一共有20个步骤,下面说明每一步。

Step 1. ActivityManagerService.startService

这个函数定义在frameworks/base/services/java/com/Android/server/am/ActivityManagerService.java文件中:

 

public final class ActivityManagerService extends ActivityManagerNative                              implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {          ......          public ComponentName startService(IApplicationThread caller, Intent service,               String resolvedType) {                   // Refuse possible leaked file descriptors              if (service != null && service.hasFileDescriptors() == true) {                 throw new IllegalArgumentException("File descriptors passed in Intent");             }                synchronized(this) {                 final int callingPid = Binder.getCallingPid();                 final int callingUid = Binder.getCallingUid();                 final long origId = Binder.clearCallingIdentity();                 ComponentName res = startServiceLocked(caller, service,                     resolvedType, callingPid, callingUid);                 Binder.restoreCallingIdentity(origId);                 return res;             }       }          ......      }  

        这里的参数caller、service和resolvedType分别对应ActivityManagerProxy.startService传进来的三个参数。

Step 2. ActivityManagerService.startServiceLocked
         这个函数同样定义在frameworks/base/services/java/com/android/server/am/ActivityManagerService.java文件中:

public final class ActivityManagerService extends ActivityManagerNative                              implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {          ......          ComponentName startServiceLocked(IApplicationThread caller,               Intent service, String resolvedType,               int callingPid, int callingUid) {           synchronized(this) {               ......                  ServiceLookupResult res =                   retrieveServiceLocked(service, resolvedType,                   callingPid, callingUid);                              ......                              ServiceRecord r = res.record;                              ......                  if (!bringUpServiceLocked(r, service.getFlags(), false)) {                   return new ComponentName("!""Service process is bad");               }               return r.name;           }       }          ......      }  

linux

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwddpy.html