Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Digging Into Android System Services
Search
Dave Smith
September 16, 2016
Programming
8
1.4k
Digging Into Android System Services
Walkthrough of the architecture that the Android platform uses to expose services to applications.
Dave Smith
September 16, 2016
Tweet
Share
More Decks by Dave Smith
See All by Dave Smith
Android Security Features
devunwired
4
620
ConstraintLayout, Inside and Out
devunwired
21
1.7k
Flattening Layouts with Constraints
devunwired
3
260
Hello, Brillo: ELC Edition
devunwired
0
240
Mastering CoordinatorLayout Behaviors
devunwired
16
1.3k
Hello, Brillo
devunwired
1
2k
Google Proximity Beacons Overview
devunwired
4
230
Proximity Beacons and the Nearby API
devunwired
1
1.8k
Getting Your Act Together with CoordinatorLayout
devunwired
7
460
Other Decks in Programming
See All in Programming
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Realtime API 入門
riofujimon
0
150
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
290
受け取る人から提供する人になるということ
little_rubyist
0
230
Remix on Hono on Cloudflare Workers
yusukebe
1
280
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Faster Mobile Websites
deanohume
305
30k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Happy Clients
brianwarren
98
6.7k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
A Modern Web Designer's Workflow
chriscoyier
693
190k
GitHub's CSS Performance
jonrohan
1030
460k
Gamification - CAS2011
davidbonilla
80
5k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
GraphQLとの向き合い方2022年版
quramy
43
13k
Transcript
Digging Into Android System Services Dave Smith, PE @devunwired
Why Are You Here? Trace AOSP Code Learn Platform Internals
Discover App Impact
Linux Kernel Hardware Abstraction Layer Native Services Runtime Application Framework
Applications
Linux Kernel Hardware Abstraction Layer Native Services Runtime Application Framework
Applications
Application System Server Manager Service
Application System Server Manager Service Application Manager Application Manager Application
Manager
Context.getSystemService(SERVICE_NAME)
ContextImpl SystemServiceRegistry Context AlarmManager NotificationManager LocationManager PowerManager Context.getSystemService(SERVICE_NAME)
package android.app; final class SystemServiceRegistry { ... static
{ ... registerService(Context.ACCOUNT_SERVICE, AccountManager.class, new CachedServiceFetcher<AccountManager>() { @Override public AccountManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(Context.ACCOUNT_SERVICE); IAccountManager service = IAccountManager.Stub.asInterface(b); return new AccountManager(ctx, service); } }); ... registerService(Context.ALARM_SERVICE, AlarmManager.class, new CachedServiceFetcher<AlarmManager>() { @Override public AlarmManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(Context.ALARM_SERVICE); IAlarmManager service = IAlarmManager.Stub.asInterface(b); return new AlarmManager(service, ctx); } }); ... } } SystemServiceRegistry.java
package android.app; final class SystemServiceRegistry { ... static
{ ... registerService(Context.ACCOUNT_SERVICE, AccountManager.class, new CachedServiceFetcher<AccountManager>() { @Override public AccountManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(Context.ACCOUNT_SERVICE); IAccountManager service = IAccountManager.Stub.asInterface(b); return new AccountManager(ctx, service); } }); ... registerService(Context.ALARM_SERVICE, AlarmManager.class, new CachedServiceFetcher<AlarmManager>() { @Override public AlarmManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(Context.ALARM_SERVICE); IAlarmManager service = IAlarmManager.Stub.asInterface(b); return new AlarmManager(service, ctx); } }); ... } } SystemServiceRegistry.java
Application System Server Manager Service
Binder IPC Application System Server Service Manager
Application System Server Manager Service Binder IPC AIDL Proxy Stub
Application System Server AlarmManager AlarmManagerService IAlarmManager IAlarmManager.Stub Binder IPC
IAlarmManager.aidl AlarmManager.java package android.app; ... public class AlarmManager
{ private final IAlarmManager mService; ... public void setTime(long millis) { try { mService.setTime(millis); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } } public void setTimeZone(String timeZone) { ... try { mService.setTimeZone(timeZone); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } } } package android.app; interface IAlarmManager { void set(...); boolean setTime(long millis); void setTimeZone(String zone); void remove(...); long getNextWakeFromIdleTime(); ... }
IAlarmManager.aidl AlarmManager.java package android.app; ... public class AlarmManager
{ private final IAlarmManager mService; ... public void setTime(long millis) { try { mService.setTime(millis); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } } public void setTimeZone(String timeZone) { ... try { mService.setTimeZone(timeZone); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } } } package android.app; interface IAlarmManager { void set(...); boolean setTime(long millis); void setTimeZone(String zone); void remove(...); long getNextWakeFromIdleTime(); ... }
package com.android.server; public class AlarmManagerService extends SystemService { ...
private final IBinder mService = new IAlarmManager.Stub() { @Override public boolean setTime(long millis) { getContext().enforceCallingOrSelfPermission( "android.permission.SET_TIME", "setTime"); ... } @Override public void setTimeZone(String tz) { getContext().enforceCallingOrSelfPermission( "android.permission.SET_TIME_ZONE", "setTimeZone"); ... } }; } AlarmManagerService.java IAlarmManager.aidl package android.app; interface IAlarmManager { void set(...); boolean setTime(long millis); void setTimeZone(String zone); void remove(...); long getNextWakeFromIdleTime(); ... }
Binder IPC Application Service Object
Binder IPC Application Service Object Object
public class MainActivity extends Activity implements LocationListener { @Override
protected void onResume() { super.onResume(); LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE); manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } @Override protected void onPause() { super.onPause(); LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE); manager.removeUpdates(this); } @Override public void onLocationChanged(Location location) { ... } ... }
public class MainActivity extends Activity implements LocationListener { @Override
protected void onResume() { super.onResume(); LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE); manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } @Override protected void onPause() { super.onPause(); LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE); manager.removeUpdates(this); } @Override public void onLocationChanged(Location location) { ... } ... }
Application System Server Manager Service
Application System Server Manager Service Service Manager Stub Stub
Application System Server Manager Service Service Manager IBinder Stub IBinder
Application System Server Manager Service Service Manager Proxy Stub IBinder
$ adb shell service list Found 116 services: 0 carrier_config:
[com.android.internal.telephony.ICarrierConfigLoader] 1 phone: [com.android.internal.telephony.ITelephony] 2 isms: [com.android.internal.telephony.ISms] 3 iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo] 4 simphonebook: [com.android.internal.telephony.IIccPhoneBook] 5 isub: [com.android.internal.telephony.ISub] 6 telecom: [com.android.internal.telecom.ITelecomService] 7 contexthub_service: [android.hardware.location.IContextHubService] 8 dns_listener: [android.net.metrics.IDnsEventListener] 9 connectivity_metrics_logger: [android.net.IConnectivityMetricsLogger] 10 imms: [com.android.internal.telephony.IMms] 11 media_projection: [android.media.projection.IMediaProjectionManager] 12 launcherapps: [android.content.pm.ILauncherApps] 13 shortcut: [android.content.pm.IShortcutService] 14 fingerprint: [android.hardware.fingerprint.IFingerprintService] 15 trust: [android.app.trust.ITrustManager] 16 media_router: [android.media.IMediaRouterService] 17 media_session: [android.media.session.ISessionManager] 18 restrictions: [android.content.IRestrictionsManager] 19 print: [android.print.IPrintManager] 20 graphicsstats: [android.view.IGraphicsStats] ...
package android.app; final class SystemServiceRegistry { ... static
{ ... registerService(Context.ACCOUNT_SERVICE, AccountManager.class, new CachedServiceFetcher<AccountManager>() { @Override public AccountManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(Context.ACCOUNT_SERVICE); IAccountManager service = IAccountManager.Stub.asInterface(b); return new AccountManager(ctx, service); } }); ... registerService(Context.ALARM_SERVICE, AlarmManager.class, new CachedServiceFetcher<AlarmManager>() { @Override public AlarmManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(Context.ALARM_SERVICE); IAlarmManager service = IAlarmManager.Stub.asInterface(b); return new AlarmManager(service, ctx); } }); ... } } SystemServiceRegistry.java
package android.app; final class SystemServiceRegistry { ... static
{ ... registerService(Context.ACCOUNT_SERVICE, AccountManager.class, new CachedServiceFetcher<AccountManager>() { @Override public AccountManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(Context.ACCOUNT_SERVICE); IAccountManager service = IAccountManager.Stub.asInterface(b); return new AccountManager(ctx, service); } }); ... registerService(Context.ALARM_SERVICE, AlarmManager.class, new CachedServiceFetcher<AlarmManager>() { @Override public AlarmManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(Context.ALARM_SERVICE); IAlarmManager service = IAlarmManager.Stub.asInterface(b); return new AlarmManager(service, ctx); } }); ... } } SystemServiceRegistry.java
package com.android.server; import android.content.Context; public final class SystemServer
{ ... ConnectivityServicer connectivity = new ConnectivityService( context, networkManagement, networkStats, networkPolicy); ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity); ... LocationManagerService location = new LocationManagerService(context); ServiceManager.addService(Context.LOCATION_SERVICE, location); ... } SystemServer.java
@devunwired +DaveSmithDev milehighandroid.com wiresareobsolete.com