【学习笔记】通过省电的AIDL理解Biner

2024-02-09 21:38

本文主要是介绍【学习笔记】通过省电的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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/695347

相关文章

Java深度学习库DJL实现Python的NumPy方式

《Java深度学习库DJL实现Python的NumPy方式》本文介绍了DJL库的背景和基本功能,包括NDArray的创建、数学运算、数据获取和设置等,同时,还展示了如何使用NDArray进行数据预处理... 目录1 NDArray 的背景介绍1.1 架构2 JavaDJL使用2.1 安装DJL2.2 基本操

深入理解Apache Airflow 调度器(最新推荐)

《深入理解ApacheAirflow调度器(最新推荐)》ApacheAirflow调度器是数据管道管理系统的关键组件,负责编排dag中任务的执行,通过理解调度器的角色和工作方式,正确配置调度器,并... 目录什么是Airflow 调度器?Airflow 调度器工作机制配置Airflow调度器调优及优化建议最

一文带你理解Python中import机制与importlib的妙用

《一文带你理解Python中import机制与importlib的妙用》在Python编程的世界里,import语句是开发者最常用的工具之一,它就像一把钥匙,打开了通往各种功能和库的大门,下面就跟随小... 目录一、python import机制概述1.1 import语句的基本用法1.2 模块缓存机制1.

深入理解C语言的void*

《深入理解C语言的void*》本文主要介绍了C语言的void*,包括它的任意性、编译器对void*的类型检查以及需要显式类型转换的规则,具有一定的参考价值,感兴趣的可以了解一下... 目录一、void* 的类型任意性二、编译器对 void* 的类型检查三、需要显式类型转换占用的字节四、总结一、void* 的

深入理解Redis大key的危害及解决方案

《深入理解Redis大key的危害及解决方案》本文主要介绍了深入理解Redis大key的危害及解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着... 目录一、背景二、什么是大key三、大key评价标准四、大key 产生的原因与场景五、大key影响与危

深入理解C++ 空类大小

《深入理解C++空类大小》本文主要介绍了C++空类大小,规定空类大小为1字节,主要是为了保证对象的唯一性和可区分性,满足数组元素地址连续的要求,下面就来了解一下... 目录1. 保证对象的唯一性和可区分性2. 满足数组元素地址连续的要求3. 与C++的对象模型和内存管理机制相适配查看类对象内存在C++中,规

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

学习hash总结

2014/1/29/   最近刚开始学hash,名字很陌生,但是hash的思想却很熟悉,以前早就做过此类的题,但是不知道这就是hash思想而已,说白了hash就是一个映射,往往灵活利用数组的下标来实现算法,hash的作用:1、判重;2、统计次数;