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
630
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
Spatial Rendering for Apple Vision Pro
warrenm
0
110
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
103 Early Hints
sugi_0000
1
230
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
110
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
fs2-io を試してたらバグを見つけて直した話
chencmd
0
240
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
선언형 UI에서의 상태관리
l2hyunwoo
0
170
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
210
Haze - Real time background blurring
chrisbanes
1
510
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Rails Girls Zürich Keynote
gr2m
94
13k
Into the Great Unknown - MozCon
thekraken
33
1.5k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
A better future with KSS
kneath
238
17k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
GraphQLとの向き合い方2022年版
quramy
44
13k
Mobile First: as difficult as doing things right
swwweet
222
9k
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