当前位置:   article > 正文

Android 关于系统Context.getSystemService(String arg0)获取系统服务的详细剖析-getSystemService_mcontext.getsystemservice

mcontext.getsystemservice


前段时间在写系统 launcher 的时候,客户需要引入一个天气模块,起初我只是用了一个百度的车联网的天气api,发现调用次数有限制,并且很多家客户觉得

这个天气模块效果还挺不错的,都想在自己的产品上加上我这个模块,我就想了想该怎么坐,满足所有的需求,并且也方便其他同时引用我这个模块,我就花

了一下午的时间,在网上爬了一个javascript的接口,然后在自己的网站服务器上再多做了一个动态代理,相当于我本地请求到我自己的网站服务器,我的服务

器在做一次转发请求拿到数据,本地设备端通过这个动态代理获取天气数据,此数据没有任何限制,不限制ip,不限制次数,相当实用,解决了API的问题,接

下来需要解决引用的问题,就是代码的复用性和灵活性,这时候我就想了一个比较简便的方法,就是自己封装一个jar包,在任何应用里面或者web里面都可以

引用它,因为只更新到了 1.0 版本,暂时只支持 android 端,后续可能会更新到兼容其他平台,然后关于jar的调用也非常的简单实用,测试之后感觉非常不

错,而且也非常小,调用端不用考虑定位和网络问题,下面奉上demo,关于系统Context.getSystemService(String 

arg0),后面会抛砖引玉带出来,给大家讲。


我封装的jar包:



jar 构架:



demo 调用:

  1. package com.example.rmt.weather.test;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import rmt.weather.core.WeatherInfo;
  5. import rmt.weather.core.util.WeatherInfoCallBack;
  6. import rmt.weather.core.util.WeatherManager;
  7. import android.os.Bundle;
  8. import android.os.Handler;
  9. import android.view.View;
  10. import android.view.View.OnClickListener;
  11. import android.widget.TextView;
  12. import android.app.Activity;
  13. public class MainActivity extends Activity implements WeatherInfoCallBack{
  14. private TextView release,getWeather,reset_init,net_message,gps_message,weather_message,
  15. count_message;
  16. private String net_status,gps_status,weather_status,date_status;
  17. private int count = 0;
  18. private Handler mHandler = new Handler(){
  19. public void handleMessage(android.os.Message msg) {
  20. if(msg.what==0){
  21. net_message.setText(net_status);
  22. gps_message.setText(gps_status);
  23. weather_message.setText(weather_status);
  24. count_message.setText("第"+count+"次更新天气信息\r\r\r\r"+date_status);
  25. }else{
  26. net_message.setText("");
  27. gps_message.setText("");
  28. weather_message.setText("");
  29. count_message.setText("");
  30. }
  31. };
  32. };
  33. @Override
  34. protected void onCreate(Bundle savedInstanceState) {
  35. super.onCreate(savedInstanceState);
  36. setContentView(R.layout.activity_main);
  37. initWeatherManager();
  38. initView();
  39. }
  40. /**
  41. * jar:需要注册的权限
  42. * <uses-permission android:name="android.permission.INTERNET" />
  43. * <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  44. * <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  45. * <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  46. * */
  47. /**
  48. * jar:需要注册的组件
  49. * <receiver android:name="rmt.weather.core.WeatherUpdateReceiver"/>
  50. * <service android:name="rmt.weather.core.WeatherService"/>
  51. * */
  52. private void initView(){
  53. release = (TextView) findViewById(R.id.release);
  54. getWeather = (TextView) findViewById(R.id.get_weather);
  55. reset_init = (TextView) findViewById(R.id.reset_init);
  56. net_message = (TextView) findViewById(R.id.net_message);
  57. gps_message = (TextView) findViewById(R.id.gps_message);
  58. weather_message = (TextView) findViewById(R.id.weather_message);
  59. count_message = (TextView) findViewById(R.id.count_message);
  60. release.setOnClickListener(listener);
  61. getWeather.setOnClickListener(listener);
  62. reset_init.setOnClickListener(listener);
  63. }
  64. /**
  65. * initWeatherManager()
  66. * 初始化天气管理服务
  67. * 用于初次初始化应用,调用一次
  68. * */
  69. private void initWeatherManager(){
  70. WeatherManager.getWeatherManager().init(this);
  71. WeatherManager.getWeatherManager().setWeatherInfoCallBack(this);
  72. }
  73. /**
  74. * resetWeather()
  75. * 重新初始化天气管理服务
  76. * 用于休眠结束之后再次开机
  77. * */
  78. private void resetWeather(){
  79. initWeatherManager();
  80. }
  81. /**
  82. * releaseAll()
  83. * 释放所有内存
  84. * 用于休眠前调用,调用一次
  85. * */
  86. private void releaseAll(){
  87. count = 0;
  88. WeatherManager.getWeatherManager().releaseAll();
  89. mHandler.sendEmptyMessage(1);
  90. }
  91. /**
  92. * getWeatherInfo()
  93. * 获取当前的天
  94. * 跨定时服务即时获取天气信息
  95. * */
  96. private void getWeatherInfo(){
  97. WeatherManager.getWeatherManager().getWeatherInfo();
  98. }
  99. private OnClickListener listener = new OnClickListener() {
  100. @Override
  101. public void onClick(View arg0) {
  102. if(arg0.getId()==R.id.release){
  103. // 释放
  104. releaseAll();
  105. }else if(arg0.getId()==R.id.get_weather){
  106. // 即时获取当前城市天气
  107. getWeatherInfo();
  108. }else{
  109. // 重新初始化管理
  110. resetWeather();
  111. }
  112. }
  113. };
  114. private String getTime() {
  115. SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
  116. return sdf.format(new Date(System.currentTimeMillis()));
  117. }
  118. private String getWeek() {
  119. SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
  120. return sdf.format(new Date(System.currentTimeMillis()));
  121. }
  122. private String getDate() {
  123. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  124. return sdf.format(new Date(System.currentTimeMillis()));
  125. }
  126. private String getDateString(){
  127. return getDate()+" "+getTime()+" "+getWeek();
  128. }
  129. /**
  130. * WeatherInfoCallBack- CallBackWeatherInfo(WeatherInfo arg0)
  131. * 天气信息数据回调
  132. * */
  133. @Override
  134. public void CallBackWeatherInfo(WeatherInfo arg0) {
  135. String b = "天气信息 >>>>>> ";
  136. date_status = getDateString();
  137. weather_status = b+arg0.toString();
  138. count++;
  139. mHandler.sendEmptyMessage(0);
  140. }
  141. /**
  142. * WeatherInfoCallBack- CallBackGPSInfo(boolean arg0)
  143. * GPS 定位状态回调
  144. * */
  145. @Override
  146. public void CallBackGPSInfo(boolean arg0) {
  147. String b = "GPS定位:";
  148. if(arg0){
  149. b = b+"成功";
  150. }else{
  151. b = b+"失败";
  152. }
  153. gps_status = b;
  154. mHandler.sendEmptyMessage(0);
  155. }
  156. /**
  157. * WeatherInfoCallBack- CallBackNetWorkInfo(boolean arg0)
  158. * 网络状态回调
  159. * */
  160. @Override
  161. public void CallBackNetWorkInfo(boolean arg0) {
  162. String b = "网络:";
  163. if(arg0){
  164. b = b+"正常";
  165. }else{
  166. b = b+"无网络";
  167. }
  168. net_status = b;
  169. mHandler.sendEmptyMessage(0);
  170. }
  171. }

下面开始说关于系统Context.getSystemService(String arg0),在jar里面我采用了系统alarm服务,我们就以这个服务为例

  1. private void startAlarm(){
  2. manager = (AlarmManager)mContext.getSystemService( Context.ALARM_SERVICE);
  3. int time = 30*60*1000;
  4. long triggerAtTime = SystemClock.elapsedRealtime();
  5. Intent intent = new Intent(mContext,WeatherUpdateReceiver.class);
  6. PendingIntent pi = PendingIntent.getBroadcast(mContext,0,intent,0);
  7. manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,triggerAtTime,time,pi);
  8. }


Context.getSystemService(String arg0) 函数:

  1. * @see #WINDOW_SERVICE
  2. * @see android.view.WindowManager
  3. * @see #LAYOUT_INFLATER_SERVICE
  4. * @see android.view.LayoutInflater
  5. * @see #ACTIVITY_SERVICE
  6. * @see android.app.ActivityManager
  7. * @see #POWER_SERVICE
  8. * @see android.os.PowerManager
  9. * @see #ALARM_SERVICE
  10. * @see android.app.AlarmManager
  11. * @see #NOTIFICATION_SERVICE
  12. * @see android.app.NotificationManager
  13. * @see #KEYGUARD_SERVICE
  14. * @see android.app.KeyguardManager
  15. * @see #LOCATION_SERVICE
  16. * @see android.location.LocationManager
  17. * @see #SEARCH_SERVICE
  18. * @see android.app.SearchManager
  19. * @see #SENSOR_SERVICE
  20. * @see android.hardware.SensorManager
  21. * @see #STORAGE_SERVICE
  22. * @see android.os.storage.StorageManager
  23. * @see #VIBRATOR_SERVICE
  24. * @see android.os.Vibrator
  25. * @see #CONNECTIVITY_SERVICE
  26. * @see android.net.ConnectivityManager
  27. * @see #WIFI_SERVICE
  28. * @see android.net.wifi.WifiManager
  29. * @see #AUDIO_SERVICE
  30. * @see android.media.AudioManager
  31. * @see #MEDIA_ROUTER_SERVICE
  32. * @see android.media.MediaRouter
  33. * @see #TELEPHONY_SERVICE
  34. * @see android.telephony.TelephonyManager
  35. * @see #TELEPHONY_SUBSCRIPTION_SERVICE
  36. * @see android.telephony.SubscriptionManager
  37. * @see #INPUT_METHOD_SERVICE
  38. * @see android.view.inputmethod.InputMethodManager
  39. * @see #UI_MODE_SERVICE
  40. * @see android.app.UiModeManager
  41. * @see #DOWNLOAD_SERVICE
  42. * @see android.app.DownloadManager
  43. * @see #BATTERY_SERVICE
  44. * @see android.os.BatteryManager
  45. * @see #JOB_SCHEDULER_SERVICE
  46. * @see android.app.job.JobScheduler
  47. */
  48. public abstract Object getSystemService(@ServiceName @NonNull String name);

这个函数会由子类ContextImpl来执行,而在ContextImpl类系统服务会在这里 registerService ,所以当我们获取系统服务的时候会通过 这个类来间接得到实例

Contextimpl:

  1. @Override
  2. public Object getSystemService(String name) {
  3. // 这是HashMap对象 HashMap<String, ServiceFetcher> ContextImpl.SYSTEM_SERVICE_MAP
  4. ServiceFetcher fetcher = SYSTEM_SERVICE_MAP.get(name);
  5. return fetcher == null ? null : fetcher.getService(this);
  6. }

Contextimpl 内部类 ServiceFetcher

  1. static class ServiceFetcher {
  2. int mContextCacheIndex = -1;
  3. /**
  4. * Main entrypoint; only override if you don't need caching.
  5. */
  6. public Object getService(ContextImpl ctx) {
  7. ArrayList<Object> cache = ctx.mServiceCache;
  8. Object service;
  9. synchronized (cache) {
  10. if (cache.size() == 0) {
  11. // Initialize the cache vector on first access.
  12. // At this point sNextPerContextServiceCacheIndex
  13. // is the number of potential services that are
  14. // cached per-Context.
  15. for (int i = 0; i < sNextPerContextServiceCacheIndex; i++) {
  16. cache.add(null);
  17. }
  18. } else {
  19. service = cache.get(mContextCacheIndex);
  20. if (service != null) {
  21. return service;
  22. }
  23. }
  24. service = createService(ctx);
  25. cache.set(mContextCacheIndex, service);
  26. return service;
  27. }
  28. }
  29. /**
  30. * Override this to create a new per-Context instance of the
  31. * service. getService() will handle locking and caching.
  32. */
  33. public Object createService(ContextImpl ctx) {
  34. throw new RuntimeException("Not implemented");
  35. }
  36. }

这里得到集合里面的实例对象,其中SYSTEM_SERVICE_MAP这个系统服务集合的每个对象都来自这个函数

  1. private static void registerService(String serviceName, ServiceFetcher fetcher) {
  2. if (!(fetcher instanceof StaticServiceFetcher)) {
  3. fetcher.mContextCacheIndex = sNextPerContextServiceCacheIndex++;
  4. }
  5. SYSTEM_SERVICE_MAP.put(serviceName, fetcher);
  6. }
这个函数被下面这些需要注册的系统服务调用

  1. static {
  2. registerService(ACCESSIBILITY_SERVICE, new ServiceFetcher() {
  3. public Object getService(ContextImpl ctx) {
  4. return AccessibilityManager.getInstance(ctx);
  5. }});
  6. registerService(CAPTIONING_SERVICE, new ServiceFetcher() {
  7. public Object getService(ContextImpl ctx) {
  8. return new CaptioningManager(ctx);
  9. }});
  10. registerService(ACCOUNT_SERVICE, new ServiceFetcher() {
  11. public Object createService(ContextImpl ctx) {
  12. IBinder b = ServiceManager.getService(ACCOUNT_SERVICE);
  13. IAccountManager service = IAccountManager.Stub.asInterface(b);
  14. return new AccountManager(ctx, service);
  15. }});
  16. registerService(ACTIVITY_SERVICE, new ServiceFetcher() {
  17. public Object createService(ContextImpl ctx) {
  18. return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler());
  19. }});
  20. registerService(ALARM_SERVICE, new ServiceFetcher() {
  21. public Object createService(ContextImpl ctx) {
  22. IBinder b = ServiceManager.getService(ALARM_SERVICE);
  23. IAlarmManager service = IAlarmManager.Stub.asInterface(b);
  24. return new AlarmManager(service, ctx);
  25. }});
  26. registerService(AUDIO_SERVICE, new ServiceFetcher() {
  27. public Object createService(ContextImpl ctx) {
  28. return new AudioManager(ctx);
  29. }});
  30. /// M: Add AudioProfile service @{
  31. if (SystemProperties.get("ro.mtk_audio_profiles").equals("1") == true
  32. && SystemProperties.get("ro.mtk_bsp_package").equals("1") == false) {
  33. registerService(AUDIO_PROFILE_SERVICE, new ServiceFetcher() {
  34. public Object createService(ContextImpl ctx) {
  35. return new AudioProfileManager(ctx);
  36. } });
  37. }
  38. /// @}
  39. registerService(MEDIA_ROUTER_SERVICE, new ServiceFetcher() {
  40. public Object createService(ContextImpl ctx) {
  41. return new MediaRouter(ctx);
  42. }});
  43. /// M: Add Mobile Service @{
  44. if (MobileManagerUtils.isSupported()) {
  45. registerService(MOBILE_SERVICE, new ServiceFetcher() {
  46. public Object createService(ContextImpl ctx) {
  47. MobileManager mobileMgr = null;
  48. try {
  49. IBinder b = ServiceManager.getService(MOBILE_SERVICE);
  50. IMobileManagerService service = IMobileManagerService.Stub.asInterface(b);
  51. mobileMgr = new MobileManager(ctx, service);
  52. } catch (Exception e) {
  53. e.printStackTrace();
  54. }
  55. return mobileMgr;
  56. } });
  57. }
  58. /// @}
  59. registerService(BLUETOOTH_SERVICE, new ServiceFetcher() {
  60. public Object createService(ContextImpl ctx) {
  61. return new BluetoothManager(ctx);
  62. }});
  63. registerService(HDMI_CONTROL_SERVICE, new StaticServiceFetcher() {
  64. public Object createStaticService() {
  65. IBinder b = ServiceManager.getService(HDMI_CONTROL_SERVICE);
  66. return new HdmiControlManager(IHdmiControlService.Stub.asInterface(b));
  67. }});
  68. registerService(CLIPBOARD_SERVICE, new ServiceFetcher() {
  69. public Object createService(ContextImpl ctx) {
  70. return new ClipboardManager(ctx.getOuterContext(),
  71. ctx.mMainThread.getHandler());
  72. }});
  73. registerService(CONNECTIVITY_SERVICE, new ServiceFetcher() {
  74. public Object createService(ContextImpl ctx) {
  75. IBinder b = ServiceManager.getService(CONNECTIVITY_SERVICE);
  76. return new ConnectivityManager(IConnectivityManager.Stub.asInterface(b));
  77. }});
  78. registerService(COUNTRY_DETECTOR, new StaticServiceFetcher() {
  79. public Object createStaticService() {
  80. IBinder b = ServiceManager.getService(COUNTRY_DETECTOR);
  81. return new CountryDetector(ICountryDetector.Stub.asInterface(b));
  82. }});
  83. registerService(DEVICE_POLICY_SERVICE, new ServiceFetcher() {
  84. public Object createService(ContextImpl ctx) {
  85. return DevicePolicyManager.create(ctx, ctx.mMainThread.getHandler());
  86. }});
  87. registerService(DOWNLOAD_SERVICE, new ServiceFetcher() {
  88. public Object createService(ContextImpl ctx) {
  89. return new DownloadManager(ctx.getContentResolver(), ctx.getPackageName());
  90. }});
  91. registerService(BATTERY_SERVICE, new ServiceFetcher() {
  92. public Object createService(ContextImpl ctx) {
  93. return new BatteryManager();
  94. }});
  95. registerService(NFC_SERVICE, new ServiceFetcher() {
  96. public Object createService(ContextImpl ctx) {
  97. return new NfcManager(ctx);
  98. }});
  99. registerService(DROPBOX_SERVICE, new StaticServiceFetcher() {
  100. public Object createStaticService() {
  101. return createDropBoxManager();
  102. }});
  103. registerService(INPUT_SERVICE, new StaticServiceFetcher() {
  104. public Object createStaticService() {
  105. return InputManager.getInstance();
  106. }});
  107. registerService(DISPLAY_SERVICE, new ServiceFetcher() {
  108. @Override
  109. public Object createService(ContextImpl ctx) {
  110. return new DisplayManager(ctx.getOuterContext());
  111. }});
  112. registerService(INPUT_METHOD_SERVICE, new StaticServiceFetcher() {
  113. public Object createStaticService() {
  114. return InputMethodManager.getInstance();
  115. }});
  116. registerService(TEXT_SERVICES_MANAGER_SERVICE, new ServiceFetcher() {
  117. public Object createService(ContextImpl ctx) {
  118. return TextServicesManager.getInstance();
  119. }});
  120. registerService(KEYGUARD_SERVICE, new ServiceFetcher() {
  121. public Object getService(ContextImpl ctx) {
  122. // TODO: why isn't this caching it? It wasn't
  123. // before, so I'm preserving the old behavior and
  124. // using getService(), instead of createService()
  125. // which would do the caching.
  126. return new KeyguardManager();
  127. }});
  128. registerService(LAYOUT_INFLATER_SERVICE, new ServiceFetcher() {
  129. public Object createService(ContextImpl ctx) {
  130. return PolicyManager.makeNewLayoutInflater(ctx.getOuterContext());
  131. }});
  132. registerService(LOCATION_SERVICE, new ServiceFetcher() {
  133. public Object createService(ContextImpl ctx) {
  134. IBinder b = ServiceManager.getService(LOCATION_SERVICE);
  135. return new LocationManager(ctx, ILocationManager.Stub.asInterface(b));
  136. }});
  137. registerService(NETWORK_POLICY_SERVICE, new ServiceFetcher() {
  138. @Override
  139. public Object createService(ContextImpl ctx) {
  140. return new NetworkPolicyManager(INetworkPolicyManager.Stub.asInterface(
  141. ServiceManager.getService(NETWORK_POLICY_SERVICE)));
  142. }
  143. });
  144. registerService(NOTIFICATION_SERVICE, new ServiceFetcher() {
  145. public Object createService(ContextImpl ctx) {
  146. final Context outerContext = ctx.getOuterContext();
  147. return new NotificationManager(
  148. new ContextThemeWrapper(outerContext,
  149. Resources.selectSystemTheme(0,
  150. outerContext.getApplicationInfo().targetSdkVersion,
  151. com.android.internal.R.style.Theme_Dialog,
  152. com.android.internal.R.style.Theme_Holo_Dialog,
  153. com.android.internal.R.style.Theme_DeviceDefault_Dialog,
  154. com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog)),
  155. ctx.mMainThread.getHandler());
  156. }});
  157. registerService(NSD_SERVICE, new ServiceFetcher() {
  158. @Override
  159. public Object createService(ContextImpl ctx) {
  160. IBinder b = ServiceManager.getService(NSD_SERVICE);
  161. INsdManager service = INsdManager.Stub.asInterface(b);
  162. return new NsdManager(ctx.getOuterContext(), service);
  163. }});
  164. // Note: this was previously cached in a static variable, but
  165. // constructed using mMainThread.getHandler(), so converting
  166. // it to be a regular Context-cached service...
  167. registerService(POWER_SERVICE, new ServiceFetcher() {
  168. public Object createService(ContextImpl ctx) {
  169. IBinder b = ServiceManager.getService(POWER_SERVICE);
  170. IPowerManager service = IPowerManager.Stub.asInterface(b);
  171. if (service == null) {
  172. Log.wtf(TAG, "Failed to get power manager service.");
  173. }
  174. return new PowerManager(ctx.getOuterContext(),
  175. service, ctx.mMainThread.getHandler());
  176. }});
  177. registerService(SEARCH_SERVICE, new ServiceFetcher() {
  178. public Object createService(ContextImpl ctx) {
  179. return new SearchManager(ctx.getOuterContext(),
  180. ctx.mMainThread.getHandler());
  181. }});
  182. /// M: register search engine service @{
  183. registerService(SEARCH_ENGINE_SERVICE, new ServiceFetcher() {
  184. public Object createService(ContextImpl ctx) {
  185. return new SearchEngineManager(ctx);
  186. } });
  187. /// @}
  188. registerService(SENSOR_SERVICE, new ServiceFetcher() {
  189. public Object createService(ContextImpl ctx) {
  190. return new SystemSensorManager(ctx.getOuterContext(),
  191. ctx.mMainThread.getHandler().getLooper());
  192. }});
  193. registerService(STATUS_BAR_SERVICE, new ServiceFetcher() {
  194. public Object createService(ContextImpl ctx) {
  195. return new StatusBarManager(ctx.getOuterContext());
  196. }});
  197. registerService(STORAGE_SERVICE, new ServiceFetcher() {
  198. public Object createService(ContextImpl ctx) {
  199. try {
  200. return new StorageManager(
  201. ctx.getContentResolver(), ctx.mMainThread.getHandler().getLooper());
  202. } catch (RemoteException rex) {
  203. Log.e(TAG, "Failed to create StorageManager", rex);
  204. return null;
  205. }
  206. }});
  207. registerService(TELEPHONY_SERVICE, new ServiceFetcher() {
  208. public Object createService(ContextImpl ctx) {
  209. return new TelephonyManager(ctx.getOuterContext());
  210. }});
  211. registerService(TELEPHONY_SUBSCRIPTION_SERVICE, new ServiceFetcher() {
  212. public Object createService(ContextImpl ctx) {
  213. return new SubscriptionManager(ctx.getOuterContext());
  214. }});
  215. registerService(TELECOM_SERVICE, new ServiceFetcher() {
  216. public Object createService(ContextImpl ctx) {
  217. return new TelecomManager(ctx.getOuterContext());
  218. }});
  219. registerService(UI_MODE_SERVICE, new ServiceFetcher() {
  220. public Object createService(ContextImpl ctx) {
  221. return new UiModeManager();
  222. }});
  223. registerService(USB_SERVICE, new ServiceFetcher() {
  224. public Object createService(ContextImpl ctx) {
  225. IBinder b = ServiceManager.getService(USB_SERVICE);
  226. return new UsbManager(ctx, IUsbManager.Stub.asInterface(b));
  227. }});
  228. registerService(SERIAL_SERVICE, new ServiceFetcher() {
  229. public Object createService(ContextImpl ctx) {
  230. IBinder b = ServiceManager.getService(SERIAL_SERVICE);
  231. return new SerialManager(ctx, ISerialManager.Stub.asInterface(b));
  232. }});
  233. registerService(VIBRATOR_SERVICE, new ServiceFetcher() {
  234. public Object createService(ContextImpl ctx) {
  235. return new SystemVibrator(ctx);
  236. }});
  237. registerService(WALLPAPER_SERVICE, WALLPAPER_FETCHER);
  238. registerService(WIFI_SERVICE, new ServiceFetcher() {
  239. public Object createService(ContextImpl ctx) {
  240. IBinder b = ServiceManager.getService(WIFI_SERVICE);
  241. IWifiManager service = IWifiManager.Stub.asInterface(b);
  242. return new WifiManager(ctx.getOuterContext(), service);
  243. }});
  244. registerService(WIFI_P2P_SERVICE, new ServiceFetcher() {
  245. public Object createService(ContextImpl ctx) {
  246. IBinder b = ServiceManager.getService(WIFI_P2P_SERVICE);
  247. IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b);
  248. return new WifiP2pManager(service);
  249. }});
  250. registerService(WIFI_SCANNING_SERVICE, new ServiceFetcher() {
  251. public Object createService(ContextImpl ctx) {
  252. IBinder b = ServiceManager.getService(WIFI_SCANNING_SERVICE);
  253. IWifiScanner service = IWifiScanner.Stub.asInterface(b);
  254. return new WifiScanner(ctx.getOuterContext(), service);
  255. }});
  256. registerService(WIFI_RTT_SERVICE, new ServiceFetcher() {
  257. public Object createService(ContextImpl ctx) {
  258. IBinder b = ServiceManager.getService(WIFI_RTT_SERVICE);
  259. IRttManager service = IRttManager.Stub.asInterface(b);
  260. return new RttManager(ctx.getOuterContext(), service);
  261. }});
  262. registerService(ETHERNET_SERVICE, new ServiceFetcher() {
  263. public Object createService(ContextImpl ctx) {
  264. IBinder b = ServiceManager.getService(ETHERNET_SERVICE);
  265. IEthernetManager service = IEthernetManager.Stub.asInterface(b);
  266. return new EthernetManager(ctx.getOuterContext(), service);
  267. }});
  268. registerService(WINDOW_SERVICE, new ServiceFetcher() {
  269. Display mDefaultDisplay;
  270. public Object getService(ContextImpl ctx) {
  271. Display display = ctx.mDisplay;
  272. if (display == null) {
  273. if (mDefaultDisplay == null) {
  274. DisplayManager dm = (DisplayManager)ctx.getOuterContext().
  275. getSystemService(Context.DISPLAY_SERVICE);
  276. mDefaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY);
  277. }
  278. display = mDefaultDisplay;
  279. }
  280. return new WindowManagerImpl(display);
  281. }});
  282. registerService(USER_SERVICE, new ServiceFetcher() {
  283. public Object createService(ContextImpl ctx) {
  284. IBinder b = ServiceManager.getService(USER_SERVICE);
  285. IUserManager service = IUserManager.Stub.asInterface(b);
  286. return new UserManager(ctx, service);
  287. }});
  288. registerService(APP_OPS_SERVICE, new ServiceFetcher() {
  289. public Object createService(ContextImpl ctx) {
  290. IBinder b = ServiceManager.getService(APP_OPS_SERVICE);
  291. IAppOpsService service = IAppOpsService.Stub.asInterface(b);
  292. return new AppOpsManager(ctx, service);
  293. }});
  294. registerService(CAMERA_SERVICE, new ServiceFetcher() {
  295. public Object createService(ContextImpl ctx) {
  296. return new CameraManager(ctx);
  297. }
  298. });
  299. registerService(LAUNCHER_APPS_SERVICE, new ServiceFetcher() {
  300. public Object createService(ContextImpl ctx) {
  301. IBinder b = ServiceManager.getService(LAUNCHER_APPS_SERVICE);
  302. ILauncherApps service = ILauncherApps.Stub.asInterface(b);
  303. return new LauncherApps(ctx, service);
  304. }
  305. });
  306. registerService(RESTRICTIONS_SERVICE, new ServiceFetcher() {
  307. public Object createService(ContextImpl ctx) {
  308. IBinder b = ServiceManager.getService(RESTRICTIONS_SERVICE);
  309. IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b);
  310. return new RestrictionsManager(ctx, service);
  311. }
  312. });
  313. registerService(PRINT_SERVICE, new ServiceFetcher() {
  314. public Object createService(ContextImpl ctx) {
  315. IBinder iBinder = ServiceManager.getService(Context.PRINT_SERVICE);
  316. IPrintManager service = IPrintManager.Stub.asInterface(iBinder);
  317. return new PrintManager(ctx.getOuterContext(), service, UserHandle.myUserId(),
  318. UserHandle.getAppId(Process.myUid()));
  319. }});
  320. registerService(CONSUMER_IR_SERVICE, new ServiceFetcher() {
  321. public Object createService(ContextImpl ctx) {
  322. return new ConsumerIrManager(ctx);
  323. }});
  324. registerService(MEDIA_SESSION_SERVICE, new ServiceFetcher() {
  325. public Object createService(ContextImpl ctx) {
  326. return new MediaSessionManager(ctx);
  327. }
  328. });
  329. registerService(TRUST_SERVICE, new ServiceFetcher() {
  330. public Object createService(ContextImpl ctx) {
  331. IBinder b = ServiceManager.getService(TRUST_SERVICE);
  332. return new TrustManager(b);
  333. }
  334. });
  335. registerService(FINGERPRINT_SERVICE, new ServiceFetcher() {
  336. public Object createService(ContextImpl ctx) {
  337. IBinder binder = ServiceManager.getService(FINGERPRINT_SERVICE);
  338. IFingerprintService service = IFingerprintService.Stub.asInterface(binder);
  339. return new FingerprintManager(ctx.getOuterContext(), service);
  340. }
  341. });
  342. registerService(TV_INPUT_SERVICE, new ServiceFetcher() {
  343. public Object createService(ContextImpl ctx) {
  344. IBinder iBinder = ServiceManager.getService(TV_INPUT_SERVICE);
  345. ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder);
  346. return new TvInputManager(service, UserHandle.myUserId());
  347. }
  348. });
  349. registerService(NETWORK_SCORE_SERVICE, new ServiceFetcher() {
  350. public Object createService(ContextImpl ctx) {
  351. return new NetworkScoreManager(ctx);
  352. }
  353. });
  354. registerService(USAGE_STATS_SERVICE, new ServiceFetcher() {
  355. public Object createService(ContextImpl ctx) {
  356. IBinder iBinder = ServiceManager.getService(USAGE_STATS_SERVICE);
  357. IUsageStatsManager service = IUsageStatsManager.Stub.asInterface(iBinder);
  358. return new UsageStatsManager(ctx.getOuterContext(), service);
  359. }
  360. });
  361. registerService(JOB_SCHEDULER_SERVICE, new ServiceFetcher() {
  362. public Object createService(ContextImpl ctx) {
  363. IBinder b = ServiceManager.getService(JOB_SCHEDULER_SERVICE);
  364. return new JobSchedulerImpl(IJobScheduler.Stub.asInterface(b));
  365. }});
  366. registerService(PERSISTENT_DATA_BLOCK_SERVICE, new ServiceFetcher() {
  367. public Object createService(ContextImpl ctx) {
  368. IBinder b = ServiceManager.getService(PERSISTENT_DATA_BLOCK_SERVICE);
  369. IPersistentDataBlockService persistentDataBlockService =
  370. IPersistentDataBlockService.Stub.asInterface(b);
  371. if (persistentDataBlockService != null) {
  372. return new PersistentDataBlockManager(persistentDataBlockService);
  373. } else {
  374. // not supported
  375. return null;
  376. }
  377. }
  378. });
  379. registerService(MEDIA_PROJECTION_SERVICE, new ServiceFetcher() {
  380. public Object createService(ContextImpl ctx) {
  381. return new MediaProjectionManager(ctx);
  382. }
  383. });
  384. registerService(APPWIDGET_SERVICE, new ServiceFetcher() {
  385. public Object createService(ContextImpl ctx) {
  386. IBinder b = ServiceManager.getService(APPWIDGET_SERVICE);
  387. return new AppWidgetManager(ctx, IAppWidgetService.Stub.asInterface(b));
  388. } });
  389. /// M: comment @{ add PerfService
  390. registerService(MTK_PERF_SERVICE, new ServiceFetcher() {
  391. public Object createService(ContextImpl ctx) {
  392. IPerfServiceWrapper perfServiceMgr = null;
  393. try {
  394. perfServiceMgr = new PerfServiceWrapper(ctx);
  395. } catch (Exception e) {
  396. e.printStackTrace();
  397. }
  398. return perfServiceMgr;
  399. } });
  400. /// @}
  401. /// M: Add SensorHubService @{
  402. if ("1".equals(SystemProperties.get("ro.mtk_sensorhub_support"))) {
  403. registerService(ISensorHubManager.SENSORHUB_SERVICE, new ServiceFetcher() {
  404. public Object createService(ContextImpl ctx) {
  405. ISensorHubManager sensorhubMgr = null;
  406. try {
  407. IBinder b = ServiceManager.getService(ISensorHubManager.SENSORHUB_SERVICE);
  408. ISensorHubService service = ISensorHubService.Stub.asInterface(b);
  409. sensorhubMgr = new SensorHubManager(service);
  410. } catch (Exception e) {
  411. e.printStackTrace();
  412. }
  413. return sensorhubMgr;
  414. }
  415. });
  416. }
  417. /// @}
  418. /// M: comment @{ add RnsService
  419. if ("1".equals(SystemProperties.get("ro.mtk_epdg_support"))) {
  420. registerService(RNS_SERVICE, new ServiceFetcher() {
  421. public Object createService(ContextImpl ctx) {
  422. IBinder b = ServiceManager.getService(RNS_SERVICE);
  423. return new RnsManager(IRnsManager.Stub.asInterface(b));
  424. } });
  425. }
  426. /// @}
  427. }


这就是我们平常调用Context.getSystemService(String arg0),因为每个系统服务实例来自 ArrayList<Object> cache = ctx.mServiceCache; 现在知道为什么调

用getSystemService(String arg0)这个函数需要强转类型了吗?因为它返回的是一个Object,所以需要强转


还有就是系统服务的管理类,我们可以看到 registerService 被调用的时候发现 IBinder b = ServiceManager.getService(ACCOUNT_SERVICE) 这样的代码

ServiceManager:

  1. /*
  2. * Copyright (C) 2007 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package android.os;
  17. import com.android.internal.os.BinderInternal;
  18. import android.util.Log;
  19. import java.util.HashMap;
  20. import java.util.Map;
  21. /** @hide */
  22. public final class ServiceManager {
  23. private static final String TAG = "ServiceManager";
  24. private static IServiceManager sServiceManager;
  25. private static HashMap<String, IBinder> sCache = new HashMap<String, IBinder>();
  26. private static IServiceManager getIServiceManager() {
  27. if (sServiceManager != null) {
  28. return sServiceManager;
  29. }
  30. // Find the service manager
  31. sServiceManager = ServiceManagerNative.asInterface(BinderInternal.getContextObject());
  32. return sServiceManager;
  33. }
  34. /**
  35. * Returns a reference to a service with the given name.
  36. *
  37. * @param name the name of the service to get
  38. * @return a reference to the service, or <code>null</code> if the service doesn't exist
  39. */
  40. public static IBinder getService(String name) {
  41. try {
  42. IBinder service = sCache.get(name);
  43. if (service != null) {
  44. return service;
  45. } else {
  46. return getIServiceManager().getService(name);
  47. }
  48. } catch (RemoteException e) {
  49. Log.e(TAG, "error in getService", e);
  50. }
  51. return null;
  52. }
  53. /**
  54. * Place a new @a service called @a name into the service
  55. * manager.
  56. *
  57. * @param name the name of the new service
  58. * @param service the service object
  59. */
  60. public static void addService(String name, IBinder service) {
  61. try {
  62. getIServiceManager().addService(name, service, false);
  63. } catch (RemoteException e) {
  64. Log.e(TAG, "error in addService", e);
  65. }
  66. }
  67. /**
  68. * Place a new @a service called @a name into the service
  69. * manager.
  70. *
  71. * @param name the name of the new service
  72. * @param service the service object
  73. * @param allowIsolated set to true to allow isolated sandboxed processes
  74. * to access this service
  75. */
  76. public static void addService(String name, IBinder service, boolean allowIsolated) {
  77. try {
  78. getIServiceManager().addService(name, service, allowIsolated);
  79. } catch (RemoteException e) {
  80. Log.e(TAG, "error in addService", e);
  81. }
  82. }
  83. /**
  84. * Retrieve an existing service called @a name from the
  85. * service manager. Non-blocking.
  86. */
  87. public static IBinder checkService(String name) {
  88. try {
  89. IBinder service = sCache.get(name);
  90. if (service != null) {
  91. return service;
  92. } else {
  93. return getIServiceManager().checkService(name);
  94. }
  95. } catch (RemoteException e) {
  96. Log.e(TAG, "error in checkService", e);
  97. return null;
  98. }
  99. }
  100. /**
  101. * Return a list of all currently running services.
  102. */
  103. public static String[] listServices() throws RemoteException {
  104. try {
  105. return getIServiceManager().listServices();
  106. } catch (RemoteException e) {
  107. Log.e(TAG, "error in listServices", e);
  108. return null;
  109. }
  110. }
  111. /**
  112. * This is only intended to be called when the process is first being brought
  113. * up and bound by the activity manager. There is only one thread in the process
  114. * at that time, so no locking is done.
  115. *
  116. * @param cache the cache of service references
  117. * @hide
  118. */
  119. public static void initServiceCache(Map<String, IBinder> cache) {
  120. if (sCache.size() != 0) {
  121. throw new IllegalStateException("setServiceCache may only be called once");
  122. }
  123. sCache.putAll(cache);
  124. }
  125. }

ServiceManagerNative

  1. /*
  2. * Copyright (C) 2006 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package android.os;
  17. import java.util.ArrayList;
  18. /**
  19. * Native implementation of the service manager. Most clients will only
  20. * care about getDefault() and possibly asInterface().
  21. * @hide
  22. */
  23. public abstract class ServiceManagerNative extends Binder implements IServiceManager
  24. {
  25. /**
  26. * Cast a Binder object into a service manager interface, generating
  27. * a proxy if needed.
  28. */
  29. static public IServiceManager asInterface(IBinder obj)
  30. {
  31. if (obj == null) {
  32. return null;
  33. }
  34. IServiceManager in =
  35. (IServiceManager)obj.queryLocalInterface(descriptor);
  36. if (in != null) {
  37. return in;
  38. }
  39. return new ServiceManagerProxy(obj);
  40. }
  41. public ServiceManagerNative()
  42. {
  43. attachInterface(this, descriptor);
  44. }
  45. public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
  46. {
  47. try {
  48. switch (code) {
  49. case IServiceManager.GET_SERVICE_TRANSACTION: {
  50. data.enforceInterface(IServiceManager.descriptor);
  51. String name = data.readString();
  52. IBinder service = getService(name);
  53. reply.writeStrongBinder(service);
  54. return true;
  55. }
  56. case IServiceManager.CHECK_SERVICE_TRANSACTION: {
  57. data.enforceInterface(IServiceManager.descriptor);
  58. String name = data.readString();
  59. IBinder service = checkService(name);
  60. reply.writeStrongBinder(service);
  61. return true;
  62. }
  63. case IServiceManager.ADD_SERVICE_TRANSACTION: {
  64. data.enforceInterface(IServiceManager.descriptor);
  65. String name = data.readString();
  66. IBinder service = data.readStrongBinder();
  67. boolean allowIsolated = data.readInt() != 0;
  68. addService(name, service, allowIsolated);
  69. return true;
  70. }
  71. case IServiceManager.LIST_SERVICES_TRANSACTION: {
  72. data.enforceInterface(IServiceManager.descriptor);
  73. String[] list = listServices();
  74. reply.writeStringArray(list);
  75. return true;
  76. }
  77. case IServiceManager.SET_PERMISSION_CONTROLLER_TRANSACTION: {
  78. data.enforceInterface(IServiceManager.descriptor);
  79. IPermissionController controller
  80. = IPermissionController.Stub.asInterface(
  81. data.readStrongBinder());
  82. setPermissionController(controller);
  83. return true;
  84. }
  85. }
  86. } catch (RemoteException e) {
  87. }
  88. return false;
  89. }
  90. public IBinder asBinder()
  91. {
  92. return this;
  93. }
  94. }
  95. class ServiceManagerProxy implements IServiceManager {
  96. public ServiceManagerProxy(IBinder remote) {
  97. mRemote = remote;
  98. }
  99. public IBinder asBinder() {
  100. return mRemote;
  101. }
  102. public IBinder getService(String name) throws RemoteException {
  103. Parcel data = Parcel.obtain();
  104. Parcel reply = Parcel.obtain();
  105. data.writeInterfaceToken(IServiceManager.descriptor);
  106. data.writeString(name);
  107. mRemote.transact(GET_SERVICE_TRANSACTION, data, reply, 0);
  108. IBinder binder = reply.readStrongBinder();
  109. reply.recycle();
  110. data.recycle();
  111. return binder;
  112. }
  113. public IBinder checkService(String name) throws RemoteException {
  114. Parcel data = Parcel.obtain();
  115. Parcel reply = Parcel.obtain();
  116. data.writeInterfaceToken(IServiceManager.descriptor);
  117. data.writeString(name);
  118. mRemote.transact(CHECK_SERVICE_TRANSACTION, data, reply, 0);
  119. IBinder binder = reply.readStrongBinder();
  120. reply.recycle();
  121. data.recycle();
  122. return binder;
  123. }
  124. public void addService(String name, IBinder service, boolean allowIsolated)
  125. throws RemoteException {
  126. Parcel data = Parcel.obtain();
  127. Parcel reply = Parcel.obtain();
  128. data.writeInterfaceToken(IServiceManager.descriptor);
  129. data.writeString(name);
  130. data.writeStrongBinder(service);
  131. data.writeInt(allowIsolated ? 1 : 0);
  132. mRemote.transact(ADD_SERVICE_TRANSACTION, data, reply, 0);
  133. reply.recycle();
  134. data.recycle();
  135. }
  136. public String[] listServices() throws RemoteException {
  137. ArrayList<String> services = new ArrayList<String>();
  138. int n = 0;
  139. while (true) {
  140. Parcel data = Parcel.obtain();
  141. Parcel reply = Parcel.obtain();
  142. data.writeInterfaceToken(IServiceManager.descriptor);
  143. data.writeInt(n);
  144. n++;
  145. try {
  146. boolean res = mRemote.transact(LIST_SERVICES_TRANSACTION, data, reply, 0);
  147. if (!res) {
  148. break;
  149. }
  150. } catch (RuntimeException e) {
  151. // The result code that is returned by the C++ code can
  152. // cause the call to throw an exception back instead of
  153. // returning a nice result... so eat it here and go on.
  154. break;
  155. }
  156. services.add(reply.readString());
  157. reply.recycle();
  158. data.recycle();
  159. }
  160. String[] array = new String[services.size()];
  161. services.toArray(array);
  162. return array;
  163. }
  164. public void setPermissionController(IPermissionController controller)
  165. throws RemoteException {
  166. Parcel data = Parcel.obtain();
  167. Parcel reply = Parcel.obtain();
  168. data.writeInterfaceToken(IServiceManager.descriptor);
  169. data.writeStrongBinder(controller.asBinder());
  170. mRemote.transact(SET_PERMISSION_CONTROLLER_TRANSACTION, data, reply, 0);
  171. reply.recycle();
  172. data.recycle();
  173. }
  174. private IBinder mRemote;
  175. }

IServiceManager

  1. /*
  2. * Copyright (C) 2006 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package android.os;
  17. /**
  18. * Basic interface for finding and publishing system services.
  19. *
  20. * An implementation of this interface is usually published as the
  21. * global context object, which can be retrieved via
  22. * BinderNative.getContextObject(). An easy way to retrieve this
  23. * is with the static method BnServiceManager.getDefault().
  24. *
  25. * @hide
  26. */
  27. public interface IServiceManager extends IInterface
  28. {
  29. /**
  30. * Retrieve an existing service called @a name from the
  31. * service manager. Blocks for a few seconds waiting for it to be
  32. * published if it does not already exist.
  33. */
  34. public IBinder getService(String name) throws RemoteException;
  35. /**
  36. * Retrieve an existing service called @a name from the
  37. * service manager. Non-blocking.
  38. */
  39. public IBinder checkService(String name) throws RemoteException;
  40. /**
  41. * Place a new @a service called @a name into the service
  42. * manager.
  43. */
  44. public void addService(String name, IBinder service, boolean allowIsolated)
  45. throws RemoteException;
  46. /**
  47. * Return a list of all currently running services.
  48. */
  49. public String[] listServices() throws RemoteException;
  50. /**
  51. * Assign a permission controller to the service manager. After set, this
  52. * interface is checked before any services are added.
  53. */
  54. public void setPermissionController(IPermissionController controller)
  55. throws RemoteException;
  56. static final String descriptor = "android.os.IServiceManager";
  57. int GET_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION;
  58. int CHECK_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+1;
  59. int ADD_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+2;
  60. int LIST_SERVICES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+3;
  61. int CHECK_SERVICES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+4;
  62. int SET_PERMISSION_CONTROLLER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+5;
  63. }


 IInterface

  1. /*
  2. * Copyright (C) 2006 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package android.os;
  17. /**
  18. * Base class for Binder interfaces. When defining a new interface,
  19. * you must derive it from IInterface.
  20. */
  21. public interface IInterface
  22. {
  23. /**
  24. * Retrieve the Binder object associated with this interface.
  25. * You must use this instead of a plain cast, so that proxy objects
  26. * can return the correct result.
  27. */
  28. public IBinder asBinder();
  29. }

这就是大致的流程,关于获取系统服务的实例,我也把相关的源码贴上了,大家可以了解一下。

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号