2011. 7. 28. 03:02

시스템 서비스에 접근하기

사용가능한 서비스 리스트 출력 예

android.os.IServiceManager sm = android.os.ServiceManagerNative.getDefault();
try {
	String[] services = sm.listServices();	
	for (int i = 0; i < services.length; i++) {
		Log.i("Services", i + " : " + services[i]);
	}
} catch (DeadObjectException e) {
	Log.i("Services", e.getMessage(), e);
}
아래는 애플리케이션에서 이용가능한 API 목록입니다. 단, 인터페이스에 접근할 수 있다고 해서 사용가능한 거랑은 다릅니다. 왜냐면 적절한 권한이 요구될 수 있기 때문입니다.

또한 출처 워낙 글이 옛날(2007. 12. 14)꺼라 인터페이스 이름이 변경된 서비스들이 있을 수 있습니다.

Window
android.view.IWindowManager windowService 
= android.view.IWindowManager.Stub.asInterface(sm.getService("window"));

Package
android.content.IPackageManager packageService 
= android.content.IPackageManager.Stub.asInterface(sm.getService("package"));

Power
android.os.IPowerManager powerService 
= android.os.IPowerManager.Stub.asInterface(sm.getService("power"));

Statistics
android.os.IStatisticsService statisticsService 
= android.os.IStatisticsService.Stub.asInterface(sm.getService("statistics")); 

Activity
android.app.IActivityManager activityService 
= android.app.IActivityManager.Stub.asInterface(sm.getService("activity"));
 
USB
android.os.IUsb usbService 
= android.os.IUsb.Stub.asInterface(sm.getService("USB"));

Alarm
android.app.IAlarmManager alarmService 
= android.app.IAlarmManager.Stub.asInterface(sm.getService("alarm"));

Content
android.content.IContentService contentService 
= android.content.IContentService.Stub.asInterface(sm.getService("content"));

Location
android.location.ILocationManager locationService 
= android.location.ILocationManager.Stub.asInterface(sm.getService("location"));

Notification
android.app.INotificationManager notificationService 
= android.app.INotificationManager.Stub.asInterface(sm.getService("notification"));

Bluetooth
org.bluez.IBluetoothService bluetoothService 
= org.bluez.IBluetoothService.Stub.asInterface(sm.getService("org.bluez.bluetooth_service"));

Phone
android.telephony.IPhone phoneService 
= android.telephony.IPhone.Stub.asInterface(sm.getService("phone"));

StatusBar
android.server.status.IStatusBar statusbarService 
= android.server.status.IStatusBar.Stub.asInterface(sm.getService("statusbar"));

Vibrator
android.os.IVibratorService vibratorService 
= android.os.IVibratorService.Stub.asInterface(ServiceManager.getService("vibrator"));

Volume
android.view.IRingerVolume volumeService 
= android.view.RingerVolumeNative.asInterface(sm.getService("volume"));
출처: 
http://davanum.wordpress.com/2007/12/14/android-accessing-the-system-services/

관련글: 
http://codemuri.tistory.com/entry/번역-안드로이드에서-숨겨진-시스템-서비스에-접근하기