【Android】service call intent 分析

Android之Service自启动流程 Service自动重启原理  无论Service是启动还是绑定成功后,都会调用ActiveServices的serviceDoneExecutingLocked方法,来看一下这个方法的实现。 void serviceDoneExecutingLocked(ServiceRecord r, int type, int startId, int res) { boolean i... 阅读详情

service.cpp里有对intent的处理

188                        } else if (strcmp(argv[optind], "intent") == 0) {
189
190                        	char* action = NULL;
191                        	char* dataArg = NULL;
192                        	char* type = NULL;
193                        	int launchFlags = 0;
194                        	char* component = NULL;
195                        	int categoryCount = 0;
196                        	char* categories[16];
197
198                        	char* context1 = NULL;
199
200                            optind++;
201
202                        	while (optind < argc)
203                        	{
204                        		char* key = strtok_r(argv[optind], "=", &context1);
205                        		char* value = strtok_r(NULL, "=", &context1);
206
207                                // we have reached the end of the XXX=XXX args.
208                                if (key == NULL) break;
209
210                        		if (strcmp(key, "action") == 0)
211                        		{
212                        			action = value;
213                        		}
214                        		else if (strcmp(key, "data") == 0)
215                        		{
216                        			dataArg = value;
217                        		}
218                        		else if (strcmp(key, "type") == 0)
219                        		{
220                        			type = value;
221                        		}
222                        		else if (strcmp(key, "launchFlags") == 0)
223                        		{
224                        			launchFlags = atoi(value);
225                        		}
226                        		else if (strcmp(key, "component") == 0)
227                        		{
228                        			component = value;
229                        		}
230                        		else if (strcmp(key, "categories") == 0)
231                        		{
232                        			char* context2 = NULL;
233                        			int categoryCount = 0;
234                        			categories[categoryCount] = strtok_r(value, ",", &context2);
235
236                        			while (categories[categoryCount] != NULL)
237                        			{
238                        				categoryCount++;
239                        				categories[categoryCount] = strtok_r(NULL, ",", &context2);
240                        			}
241                        		}
242
243                                optind++;
244                        	}
245
246                            writeString16(data, action);
247                            writeString16(data, dataArg);
248                            writeString16(data, type);
249                       		data.writeInt32(launchFlags);
250                            writeString16(data, component);
251
252                            if (categoryCount > 0)
253                            {
254                                data.writeInt32(categoryCount);
255                                for (int i = 0 ; i < categoryCount ; i++)
256                                {
257                                    writeString16(data, categories[i]);
258                                }
259                            }
260                            else
261                            {
262                                data.writeInt32(0);
263                            }
264
265                            // for now just set the extra field to be null.
266                       		data.writeInt32(-1);
267                        } else {
268                            aerr << "service: unknown option " << argv[optind] << endl;
269                            wantsUsage = true;
270                            result = 10;
271                            break;
272                        }

我们尝试进行调用,
准备使用service call 使用如下调用功能
       Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);           
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);             
        getPackageManager().queryIntentActivities(mainIntent, 0);


 $ service call package 42 intent action=android.intent.action.MAIN cat
egories=android.intent.category.LAUNCHER i32 0 i32 0
             
Result: Parcel(
  0x00000000: fffffffd 00000019 006e0055 006e006b '........U.n.k.n.'
  0x00000010: 0077006f 0020006e 00520055 00200049 'o.w.n. .U.R.I. .'
  0x00000020: 00790074 00650070 0020003a 00340037 't.y.p.e.:. .7.4.'
  0x00000030: 00310037 00300032 00000034          '7.1.2.0.4...    ')

出错了

log
01-09 02:52:17.500 1075-1980/? W/System.err: java.lang.IllegalArgumentException: Unknown URI type: 7471204
01-09 02:52:17.501 1075-1980/? W/System.err:     at android.net.Uri$1.createFromParcel(Uri.java:1779)
01-09 02:52:17.501 1075-1980/? W/System.err:     at android.net.Uri$1.createFromParcel(Uri.java:1769)
01-09 02:52:17.501 1075-1980/? W/System.err:     at android.content.Intent.readFromParcel(Intent.java:8680)
01-09 02:52:17.501 1075-1980/? W/System.err:     at android.content.Intent.<init>(Intent.java:8675)
01-09 02:52:17.501 1075-1980/? W/System.err:     at android.content.Intent$1.createFromParcel(Intent.java:8666)
01-09 02:52:17.501 1075-1980/? W/System.err:     at android.content.Intent$1.createFromParcel(Intent.java:8665)
01-09 02:52:17.501 1075-1980/? W/System.err:     at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:662)
01-09 02:52:17.501 1075-1980/? W/System.err:     at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:3732)
01-09 02:52:17.501 1075-1980/? W/System.err:     at android.os.Binder.execTransact(Binder.java:577)

查看

Intent.java

    public static final Parcelable.Creator<Intent> CREATOR
            = new Parcelable.Creator<Intent>() {
        public Intent createFromParcel(Parcel in) {
            return new Intent(in);
        }
        public Intent[] newArray(int size) {
            return new Intent[size];
        }
    };

    /** @hide */
    protected Intent(Parcel in) {
        readFromParcel(in);
    }

    public void readFromParcel(Parcel in) {
        setAction(in.readString());
        mData = Uri.CREATOR.createFromParcel(in);
        mType = in.readString();
        mFlags = in.readInt();
        mPackage = in.readString();
        mComponent = ComponentName.readFromParcel(in);

        if (in.readInt() != 0) {
            mSourceBounds = Rect.CREATOR.createFromParcel(in);
        }

        int N = in.readInt();
        if (N > 0) {
            mCategories = new ArraySet<String>();
            int i;
            for (i=0; i<N; i++) {
                mCategories.add(in.readString().intern());
            }
        } else {
            mCategories = null;
        }

        if (in.readInt() != 0) {
            mSelector = new Intent(in);
        }

        if (in.readInt() != 0) {
            mClipData = new ClipData(in);
        }
        mContentUserHint = in.readInt();
        mExtras = in.readBundle();
    }

Uri.java
   public static final Parcelable.Creator<Uri> CREATOR
            = new Parcelable.Creator<Uri>() {
        public Uri createFromParcel(Parcel in) {
            int type = in.readInt();
            switch (type) {
                case NULL_TYPE_ID: return null;
                case StringUri.TYPE_ID: return StringUri.readFrom(in);
                case OpaqueUri.TYPE_ID: return OpaqueUri.readFrom(in);
                case HierarchicalUri.TYPE_ID:
                    return HierarchicalUri.readFrom(in);
            }

            throw new IllegalArgumentException("Unknown URI type: " + type);
        }

        public Uri[] newArray(int size) {
            return new Uri[size];
        }
    };


service.cpp里写parcel数据没有按照intent标准去写导致的问题,
我们按照intent的格式去写数据就可以。但是这样的调用还是显得比较繁琐,没有直接在应用层调用方便。

           附,IPackageManager.java里的处理 @Override public android.content.pm.ParceledListSlice queryIntentActivities(android.content.Intent intent, java.lang.String resolvedType, int flags, int userId) throws android.os.RemoteException
            {
                android.os.Parcel _data = android.os.Parcel.obtain();
                android.os.Parcel _reply = android.os.Parcel.obtain();
                android.content.pm.ParceledListSlice _result;
                try {
                    _data.writeInterfaceToken(DESCRIPTOR);
                    if ((intent!=null)) {
                        _data.writeInt(1);
                        intent.writeToParcel(_data, 0);
                    }
                    else {
                        _data.writeInt(0);
                    }
                    _data.writeString(resolvedType);
                    _data.writeInt(flags);
                    _data.writeInt(userId);
                    mRemote.transact(Stub.TRANSACTION_queryIntentActivities, _data, _reply, 0);
                    _reply.readException();
                    if ((0!=_reply.readInt())) {
                        _result = android.content.pm.ParceledListSlice.CREATOR.createFromParcel(_reply);
                    }
                    else {
                        _result = null;
                    }
                }
                finally {
                    _reply.recycle();
                    _data.recycle();
                }
                return _result;
            }

    static final int TRANSACTION_queryIntentActivities = (android.os.IBinder.FIRST_CALL_TRANSACTION + 41);


                case TRANSACTION_queryIntentActivities:
                {
                    data.enforceInterface(DESCRIPTOR);
                    android.content.Intent _arg0;
                    if ((0!=data.readInt())) {
                        _arg0 = android.content.Intent.CREATOR.createFromParcel(data);
                    }
                    else {
                        _arg0 = null;
                    }
                    java.lang.String _arg1;
                    _arg1 = data.readString();
                    int _arg2;
                    _arg2 = data.readInt();
                    int _arg3;
                    _arg3 = data.readInt();
                    android.content.pm.ParceledListSlice _result = this.queryIntentActivities(_arg0, _arg1, _arg2, _arg3);
                    reply.writeNoException();
                    if ((_result!=null)) {
                        reply.writeInt(1);
                        _result.writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
                    }
                    else {
                        reply.writeInt(0);
                    }
                    return true;
                }

获取intent数据出错
                    _arg0 = android.content.Intent.CREATOR.createFromParcel(data);


@Override public android.content.pm.ParceledListSlice queryIntentActivities(android.content.Intent intent, java.lang.String resolvedType, int flags, int userId) throws android.os.RemoteException

            {
                android.os.Parcel _data = android.os.Parcel.obtain();
                android.os.Parcel _reply = android.os.Parcel.obtain();
                android.content.pm.ParceledListSlice _result;
                try {
                    _data.writeInterfaceToken(DESCRIPTOR);
                    if ((intent!=null)) {
                        _data.writeInt(1);
                        intent.writeToParcel(_data, 0);
                    }
                    else {
                        _data.writeInt(0);
                    }
                    _data.writeString(resolvedType);
                    _data.writeInt(flags);
                    _data.writeInt(userId);
                    mRemote.transact(Stub.TRANSACTION_queryIntentActivities, _data, _reply, 0);
                    _reply.readException();
                    if ((0!=_reply.readInt())) {
                        _result = android.content.pm.ParceledListSlice.CREATOR.createFromParcel(_reply);
                    }
                    else {
                        _result = null;
                    }
                }
                finally {
                    _reply.recycle();
                    _data.recycle();
                }
                return _result;
            }

    static final int TRANSACTION_queryIntentActivities = (android.os.IBinder.FIRST_CALL_TRANSACTION + 41);


                case TRANSACTION_queryIntentActivities:
                {
                    data.enforceInterface(DESCRIPTOR);
                    android.content.Intent _arg0;
                    if ((0!=data.readInt())) {
                        _arg0 = android.content.Intent.CREATOR.createFromParcel(data);
                    }
                    else {
                        _arg0 = null;
                    }
                    java.lang.String _arg1;
                    _arg1 = data.readString();
                    int _arg2;
                    _arg2 = data.readInt();
                    int _arg3;
                    _arg3 = data.readInt();
                    android.content.pm.ParceledListSlice _result = this.queryIntentActivities(_arg0, _arg1, _arg2, _arg3);
                    reply.writeNoException();
                    if ((_result!=null)) {
                        reply.writeInt(1);
                        _result.writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
                    }
                    else {
                        reply.writeInt(0);
                    }
                    return true;
                }

获取intent数据出错
                    _arg0 = android.content.Intent.CREATOR.createFromParcel(data);

安卓中通过intent组件跳转到系统联系人编辑界面,及具体案例分析 本人对于intent的用法的一些总结,在此抛砖引玉,还望大家多提建议,共勉!!! 阅读详情

相关推荐

MTK Android12-13 -Intent Filter Verification Service 停止运行

分析源码、参考资料解决 Intent Filter Verification Service 停止运行 错误这里其实其实延伸来看就是屏蔽部分包名ANR、崩溃弹框的解决方案。

十年饮冰,难凉热血 3686

使用service call进行安卓调试

service 是一种方便好用的调试工具,同时它的使用功能也有一定局限性。

qq_33163046的博客 4635

android 服务 Service PendingIntent 通知

android的服务以及通知的小例子 个人存档 代码笔记见http://blog.sina.com.cn/s/blog_70356c200100y9pf.html

android—调试命令service

在android中,可以利用service命令去做很多调试工作,例如service list命令显示系统当前所有在service manager注册的service,其命令具体使用如下,# service service Usage: service [-h|-?] service list service check SERVICE service cal

lyf's blog 3835

LPDDR5时序精调:深入解析Read Gate Training的两种模式

本文深入解析了LPDDR5内存中关键的Read Gate Training技术,详细对比了RDQS Toggle Mode(翻转模式)与Enhanced RDQS Mode(增强模式)的工作原理、时序参数及适用场景。文章阐述了在高速数据传输下精准校准时序的必要性,并提供了两种模式的实战选型指南与系统级调试思路,帮助工程师优化内存性能与稳定性。

weixin_29219189的博客 376

STM32G4系列数字LLC控制程序开发实战

本文详细介绍了基于STM32G4系列MCU的数字LLC控制程序开发全流程。从开发环境搭建、中断服务函数设计,到核心的电压环PID算法、Burst模式控制、状态机设计以及软启动优化,提供了完整的实战代码和关键参数调试经验,帮助开发者高效实现高性能数字电源控制。

weixin_29185493的博客 288

Android关于service call 直接调用方法分析

service call 可以增加输入参数,但是无法获取返回值,例如这样运行,packageName就是test。因此铁定是server call 调用了enable因此打开了蓝牙功能。很明显这个编号就是6是enable,8是disable,符合预期。希望通过命令的方式控制蓝牙打开与关闭,通过网上搜索我们都能搜到。

qq_30883899的博客 1374

康耐视VisionPro必学技巧:用CogCopyRegionTool实现图像拼接与局部替换

本文深入探讨了康耐视VisionPro中CogCopyRegionTool的高级应用,重点解析如何利用其精确的像素级复制与坐标对齐功能,实现工业视觉中的多相机图像拼接与印刷品局部替换。通过实战案例与代码示例,详细指导了从坐标标定、画布创建到顺序复制的完整流程,并分享了性能优化与常见避坑指南,帮助工程师高效解决复杂图像合成难题。

weixin_29204121的博客 505

Android通过 service call 命令调用 phone 的 AIDL 服务

mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); mTelephonyManager.setPreferredNetworkType(subId, selectNetworkMode); Context.java public static final String TELEPHONY_SERVICE = "phone"; 通过 service list 查找 phone 服务对应的 aidl adb

zhangqi6627的专栏 2475

【SLAM】探索explore_lite在移动机器人自主建图中的高效边界检测策略

本文深入解析了explore_lite在移动机器人自主建图中的应用,重点探讨了其高效的贪婪边界检测策略。该工具包专为资源受限平台设计,通过直接利用SLAM生成的地图信息,以极低的计算开销实现快速、稳定的未知区域探索,并与move_base导航框架无缝协作,是轻量级机器人自主探索的优选方案。

purple的博客 1076

从LLaMA到LLaMA-MoE:轻量级混合专家模型构建与实战指南

混合专家(Mixture-of-Experts, MoE)是一种先进的神经网络架构,其核心原理是通过门控网络动态地为不同输入选择不同的专家子网络进行计算,从而实现模型容量的指数级扩展,同时保持推理时的计算量基本不变。这种稀疏激活的特性赋予了MoE极高的技术价值,使其成为解决大模型训练与推理成本矛盾的关键技术之一,在自然语言处理、多模态学习等场景中展现出巨大潜力。本文聚焦于**LLaMA-MoE**这一具体实践,深入探讨了如何基于成熟的稠密模型(如LLaMA),通过**专家构建**与**持续预训练**两大关键

weixin_28730549的博客 569

Android Service

service中也有一系列生命周期的方法: IBinder onBinder(Intent intent) void onCreate() void onDestroy() int onStartCommand(Intent intent, int flags, int startId) boolean onUnbind(Intent intent)public class MyServ

qq_33038763的博客 439

PLDM入门(七):FRU Data Format

每个字段为TLV(Type-Length-Value)格式,具体类型、长度范围和值定义需参考。通过条件过滤(记录句柄、类型、字段类型等)分块获取FRU记录数据(可选功能)。整个FRU数据表由多个FRU记录数据块组成,每个数据块对应表2的结构(即包含。决定,每个字段按顺序排列(Type→Length→Value)通过分块传输方式写入FRU记录表数据(需终端支持写入操作)。(文档未提供表5内容,需结合标准文档完整版)。、字段数量、编码类型及具体字段的TLV数据)。无请求数据(空请求)。

weixin_44032634的博客 1772

安卓Intent 详解

欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3959204.html 【正文】 Intent组件虽然不是四大组件,但却是连接四大组件的桥梁,学习好这个知识,也非常的重要。 一、什么是Intent 1、Intent的概念: Android中提供了Intent机制来协助应用间的交互与通讯,或者采用更准确的说法是,Intent不仅可用于应用程序之间...

rainbowcode的博客 9316

K型热电偶分度表读取方法

K型热电偶分度表读取方法

guaizaiguaizai的博客 5968

Android CCodec (十七) 硬件解码调用分析-1(基于V4l2)

简单的分析V4L2DecodeComponent和其相关内容,后续针对解码调用单独分析。

给大佬递杯卡布奇诺的博客 6600

Android Service启动过程中onStartCommand(Intent intent, int flags, int startId)方法中intent为null问题分析

    最近app出现了两三次由于Service的onStartCommand(intent, flags, startId)方法中获取intent携带参数时抛出的Intent.getIntExtra() on a null object异常,intent空指针。这个错误是因为没有对onStartCommand()方法的flags参数深入理解造成的。 错误原因:intent为null的原因是该in...

xie_sining的博客 3556

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Android 5.0 禁止使用隐式Intent来启动Service.异常:service intent must be explicit

Android 5.0 禁止使用隐式Intent来启动Service.异常:service intent must be explicit

丛宏洁的博客 2789

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Android 5.0之后隐式声明Intent 启动Service引发的问题

一.概述 Android系统升级到5.0之后做了不少的变化(5.0变化),开发人员一定要注意这些变化,要不然就有的折腾了.这次最大的变化应该是把Dalvik虚拟机改成了ART(Android Runtime),后续会专门讲解这一块.其他的都是一些零碎的问题,例如前段时间发了一篇Android 5.0之后修改了HashMap的实现(传送门).这篇主要讲一下遇到跟Service相关的问题.

Jesse的专栏 3万+

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

【Android】Intent

Intent实现组件间通信(Activity/Service/BroadcastReceiver),封装操作指令与数据传输逻辑。

贫道绝缘子的博客 1086

android intent 机制,Android Intent详解

一、什么是Intent1、Intent的概念:Android提供了Intent机制来协助应用间的交互与通讯,Intent不仅可以应用于应用程序之间,也可以应用程序内部的activity、server、broadcastreceive之间。 Intent:目的,意图Intent是一种运行时绑定机制(runtime binding),他能在程序运行的过程中连接两个不同的组件。通过Intent,你的程序...

weixin_30270475的博客 635

Android中Intent连接不同组件的原理

一、什么是Intent1、概念Intent翻译过来是”意图、目的”的意思,是连接四大组件的桥梁,作为中介传输信息.2、类型Intent分为两种,显示和隐示.显示需要指定目标组件信息,隐示则只需要指定被目标组件响应的信息(action和category等信息).3、属性component(组件):目的组件 action(动作):用来表现意图的行动 category(类别):用来表现动作的类别

Dennis-Android的博客 3424

Android 8.0 启动后台service 出错 IllegalStateException: Not allowed to start service Intent

安卓8.0手机线上报错: java.lang.IllegalStateException:Fatal Exception thrown on Scheduler. 2 io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.void run()(HandlerScheduler.java:1...

kdsde的专栏 1万+

Android 8.0 启动Service适配(Not allowed to start service Intent)

问题现象: App出现异常: java.lang.IllegalStateException: Not allowed to start service Intent xxxx app is in background uid UidRecord App直接崩溃。 问题原因: App targetSdkVersion>= 26的情况下,用户允许App开机自启动,App被杀死或...

gxlgxjhll的博客 1万+

Activity、Intent、Service 三者的关系深度解析

"Intent实现了调用方与被调方的完全解耦,比如Activity不需要知道具体哪个Service会处理请求":"通过AndroidManifest的<intent-filter>声明,系统可以统一管理组件可见性":"基于Binder的Intent传递机制,使得APP间的组件调用成为可能":"PendingIntent等衍生设计支持通知栏等系统级交互"系统通过Activity栈管理导航(先进后出):用户交互的窗口单元(一个屏幕界面):Android应用的"门面担当":Android系统的"通信大使"

斗锋在干嘛的博客 1072

Android Service重启恢复(Service进程重启)原理解析

Android系统中,APP进程被杀后,等一会经常发现进程又起来了,这个现象同APP中Service的使用有很大关系,本文指的Service是通过startService启动的,而不是通binderSertvice启动的,binderSertvice是通Activity显示界面相关的,如果两者统一进程,binderSertvice的影响可以忽略,如果不是同一进程,Service会被重启,毕竟业务都...

weixin_33946605的博客 1520
上一篇: [Android]service list与dumpsys -l的结果差异分析
下一篇: 【Android】killProcessesWithOpenFiles回顾
aaajj
博客等级 码龄19年 559粉丝 544原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值