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.6k
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
220
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
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
9
1k
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
360
Go言語でターミナルフレンドリーなAIコマンド、afaを作った/fukuokago20_afa
monochromegane
2
140
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
130
カスタムしながら理解するGraphQL Connection
yanagii
1
1.2k
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
480
Realtime API 入門
riofujimon
0
110
約9000個の自動テストの 時間を50分->10分に短縮 Flakyテストを1%以下に抑えた話
hatsu38
23
11k
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
510
Vitest Browser Mode への期待 / Vitest Browser Mode
odanado
PRO
2
1.7k
Progressive Web Apps für Desktop und Mobile mit Angular (Hands-on)
christianliebel
PRO
0
110
プロジェクト新規参入者のリードタイム短縮の観点から見る、品質の高いコードとアーキテクチャを保つメリット
d_endo
1
1k
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
How to train your dragon (web standard)
notwaldorf
88
5.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
328
21k
For a Future-Friendly Web
brad_frost
175
9.4k
The Language of Interfaces
destraynor
154
24k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Raft: Consensus for Rubyists
vanstee
136
6.6k
[RailsConf 2023] Rails as a piece of cake
palkan
51
4.9k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
How to Think Like a Performance Engineer
csswizardry
19
1.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
504
140k
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