本文主要是介绍【学习笔记】通过省电的AIDL理解Biner,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原始文件
ISufadiWakeupWatcherService.aidl
package com.sufadi.framework.powersave;import android.content.Intent;
import android.content.ComponentName;
import com.sufadi.framework.powersave.ISufadiWakeupWatcherCallback;/** Copyright (C) 2013 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/
/** hide */
interface ISufadiWakeupWatcherService {void registerCallback(ISufadiWakeupWatcherCallback cb);void unregisterCallback(ISufadiWakeupWatcherCallback cb);void wakeUpBystartServiceCommon(String srcPackageName, in Intent service, in ComponentName destCn);void wakeUpByStartProcessLocked(String jsonData);void wakeUpBySuperPowerMode(in Intent intent);
}
Elipse自动生成
ISufadiWakeupWatcherService.java
/** This file is auto-generated. DO NOT MODIFY.* Original file: Z:\\androidCode\\wakeUpSp604_in\\sufadi6750_m_mp7v2\\packages\\apps\\SufadiPowerSave\\src\\com\\sufadi\\framework\\powersave\\ISufadiWakeupWatcherService.aidl*/
package com.sufadi.framework.powersave;/** Copyright (C) 2013 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*//*** hide* 居然这里的 ISufadiWakeupWatcherService.aidl 自动生成后是一个接口interface*/
public interface ISufadiWakeupWatcherService extends android.os.IInterface {/*** Local-side IPC implementation stub class.* * Sub 名称是固定*/public static abstract class Stub extends android.os.Binder implements com.sufadi.framework.powersave.ISufadiWakeupWatcherService {// ISufadiWakeupWatcherService 的全路径名称private static final java.lang.String DESCRIPTOR = "com.sufadi.framework.powersave.ISufadiWakeupWatcherService";/*** Construct the stub at attach it to the interface.** 方便类似这样的调用* if (mISufadiWakeupWatcherService == null) {ISufadiWakeupWatcherService mISufadiWakeupWatcherService = ISufadiWakeupWatcherService.Stub.asInterface(ServiceManager.getService("sufadi_wakeupwatcher"));* }*/public Stub() {this.attachInterface(this, DESCRIPTOR);}/*** Cast an IBinder object into an* com.sufadi.framework.powersave.ISufadiWakeupWatcherService interface,* generating a proxy if needed.*/public static com.sufadi.framework.powersave.ISufadiWakeupWatcherService asInterface(android.os.IBinder obj) {if ((obj == null)) {return null;}android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);if (((iin != null) && (iin instanceof com.sufadi.framework.powersave.ISufadiWakeupWatcherService))) {// 如果是同一个进程,即进程内通信,则返回Sub本身return ((com.sufadi.framework.powersave.ISufadiWakeupWatcherService) iin);}// 如果是不同进程,即跨进程通信,则返回Stub.Proxy的代理对象,见下文的Proxyreturn new com.sufadi.framework.powersave.ISufadiWakeupWatcherService.Stub.Proxy(obj);}@Overridepublic android.os.IBinder asBinder() {// 返回当前对象return this;}/*** 多进程通信回调* code:调用服务端的标志位* data:方法参数* reply:方法返回值** True:执行成功* False:执行失败*/@Overridepublic boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException {switch (code) {case INTERFACE_TRANSACTION: {reply.writeString(DESCRIPTOR);return true;}case TRANSACTION_registerCallback: {data.enforceInterface(DESCRIPTOR);com.sufadi.framework.powersave.ISufadiWakeupWatcherCallback _arg0;_arg0 = com.sufadi.framework.powersave.ISufadiWakeupWatcherCallback.Stub.asInterface(data.readStrongBinder());this.registerCallback(_arg0);reply.writeNoException();return true;}case TRANSACTION_unregisterCallback: {data.enforceInterface(DESCRIPTOR);com.sufadi.framework.powersave.ISufadiWakeupWatcherCallback _arg0;_arg0 = com.sufadi.framework.powersave.ISufadiWakeupWatcherCallback.Stub.asInterface(data.readStrongBinder());this.unregisterCallback(_arg0);reply.writeNoException();return true;}case TRANSACTION_wakeUpBystartServiceCommon: {data.enforceInterface(DESCRIPTOR);java.lang.String _arg0;_arg0 = data.readString();android.content.Intent _arg1;if ((0 != data.readInt())) {_arg1 = android.content.Intent.CREATOR.createFromParcel(data);} else {_arg1 = null;}android.content.ComponentName _arg2;if ((0 != data.readInt())) {_arg2 = android.content.ComponentName.CREATOR.createFromParcel(data);} else {_arg2 = null;}this.wakeUpBystartServiceCommon(_arg0, _arg1, _arg2);reply.writeNoException();return true;}case TRANSACTION_wakeUpByStartProcessLocked: {data.enforceInterface(DESCRIPTOR);java.lang.String _arg0;_arg0 = data.readString();this.wakeUpByStartProcessLocked(_arg0);reply.writeNoException();return true;}case TRANSACTION_wakeUpBySuperPowerMode: {data.enforceInterface(DESCRIPTOR);android.content.Intent _arg0;if ((0 != data.readInt())) {_arg0 = android.content.Intent.CREATOR.createFromParcel(data);} else {_arg0 = null;}this.wakeUpBySuperPowerMode(_arg0);reply.writeNoException();return true;}}return super.onTransact(code, data, reply, flags);}/** 多进程通信下返回 代理对象*/private static class Proxy implements com.sufadi.framework.powersave.ISufadiWakeupWatcherService {private android.os.IBinder mRemote;Proxy(android.os.IBinder remote) {mRemote = remote;}@Overridepublic android.os.IBinder asBinder() {return mRemote;}public java.lang.String getInterfaceDescriptor() {return DESCRIPTOR;}// aidl 的方法定义@Overridepublic void registerCallback(com.sufadi.framework.powersave.ISufadiWakeupWatcherCallback cb) throws android.os.RemoteException {android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeStrongBinder((((cb != null)) ? (cb.asBinder()) : (null)));mRemote.transact(Stub.TRANSACTION_registerCallback, _data, _reply, 0);_reply.readException();} finally {_reply.recycle();_data.recycle();}}@Overridepublic void unregisterCallback(com.sufadi.framework.powersave.ISufadiWakeupWatcherCallback cb) throws android.os.RemoteException {android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeStrongBinder((((cb != null)) ? (cb.asBinder()) : (null)));mRemote.transact(Stub.TRANSACTION_unregisterCallback, _data, _reply, 0);_reply.readException();} finally {_reply.recycle();_data.recycle();}}@Overridepublic void wakeUpBystartServiceCommon(java.lang.String srcPackageName, android.content.Intent service, android.content.ComponentName destCn) throws android.os.RemoteException {android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeString(srcPackageName);if ((service != null)) {_data.writeInt(1);service.writeToParcel(_data, 0);} else {_data.writeInt(0);}if ((destCn != null)) {_data.writeInt(1);destCn.writeToParcel(_data, 0);} else {_data.writeInt(0);}mRemote.transact(Stub.TRANSACTION_wakeUpBystartServiceCommon, _data, _reply, 0);_reply.readException();} finally {_reply.recycle();_data.recycle();}}@Overridepublic void wakeUpByStartProcessLocked(java.lang.String jsonData) throws android.os.RemoteException {android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeString(jsonData);mRemote.transact(Stub.TRANSACTION_wakeUpByStartProcessLocked, _data, _reply, 0);_reply.readException();} finally {_reply.recycle();_data.recycle();}}@Overridepublic void wakeUpBySuperPowerMode(android.content.Intent intent) throws android.os.RemoteException {android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();try {_data.writeInterfaceToken(DESCRIPTOR);if ((intent != null)) {_data.writeInt(1);intent.writeToParcel(_data, 0);} else {_data.writeInt(0);}mRemote.transact(Stub.TRANSACTION_wakeUpBySuperPowerMode, _data, _reply, 0);_reply.readException();} finally {_reply.recycle();_data.recycle();}}}static final int TRANSACTION_registerCallback = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);static final int TRANSACTION_unregisterCallback = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);static final int TRANSACTION_wakeUpBystartServiceCommon = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);static final int TRANSACTION_wakeUpByStartProcessLocked = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);static final int TRANSACTION_wakeUpBySuperPowerMode = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);}public void registerCallback(com.sufadi.framework.powersave.ISufadiWakeupWatcherCallback cb) throws android.os.RemoteException;public void unregisterCallback(com.sufadi.framework.powersave.ISufadiWakeupWatcherCallback cb) throws android.os.RemoteException;public void wakeUpBystartServiceCommon(java.lang.String srcPackageName, android.content.Intent service, android.content.ComponentName destCn) throws android.os.RemoteException;public void wakeUpByStartProcessLocked(java.lang.String jsonData) throws android.os.RemoteException;public void wakeUpBySuperPowerMode(android.content.Intent intent) throws android.os.RemoteException;
}
数据流程
客户端进程 实例化
private ISufadiWakeupWatcherService mISufadiWakeupWatcherService;mISufadiWakeupWatcherService = ISufadiWakeupWatcherService.Stub.asInterface(ServiceManager.getService("sufadi_wakeupwatcher"));
客户端进程 代理接口传递数据
mISufadiWakeupWatcherService.wakeUpByStartProcessLocked(sufadiAMSBuf.toString());
服务端进程 接受和处理数据
public class SufadiPowerSaveService extends Service {private ISufadiWakeupWatcherCallback mISufadiWakeupWatcherCallback = new ISufadiWakeupWatcherCallback.Stub() {
参考资料
https://www.cnblogs.com/punkisnotdead/p/5163464.html
这篇关于【学习笔记】通过省电的AIDL理解Biner的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!