您的位置:首页 > 移动开发 > Android开发

android 有关怎么自己添加系统级服务 java层 重点aidl

2011-11-23 22:11 411 查看
frameworks/base/core/java/android/os下面加aidl文件和frameworks/base/core/java/android/app下面加aidl文件有什么区别,不清楚

interface ICarSignalManager {
void setBacklightState(boolean state);
}


在frameworks/base/services/java的com.android.server下面

public class CarSignalManagerService extends ICarSignalManager.Stub {
......
}


在SystemServer的ServerThread的run方法中

ServiceManager.addService(Context.CAR_SIGNAL_SERVICE, new CarSignalManagerService(context));


上面的方法涉及到ServiceManager,我们这里根据那个addService来跟踪下:

public static void addService(String name, IBinder service) {
try {
getIServiceManager().addService(name, service);
} catch (RemoteException e) {
Log.e(TAG, "error in addService", e);
}
}


IServiceManager的实现类:ServiceManagerNative和ServiceManagerProxy这两个又有什么区别呢?

服务调用的地方

public CarSignalManager(Context context) {
IBinder b = ServiceManager.getService(Context.CAR_SIGNAL_SERVICE);
if (b == null) {
throw new RuntimeException("Car Signal service not available!");
}
mService = ICarSignalManager.Stub.asInterface(b);
}

CarSignalManager carSignalManager = (CarSignalManager) mContext
.getSystemService(Context.CAR_SIGNAL_SERVICE);
carSignalManager.setBacklightState(false);


ApplicationContext中

@Override
public Object getSystemService(String name) {

...
if (CAR_SIGNAL_SERVICE.equals(name)) {
return getCarSignalManager();
}
...

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐