[KnowledgePoint]_[PendingIntent]_[broadcastAnywhere]

深入理解与应用:Android PendingIntent 实战指南 Intent 本身是一种消息传递对象,它封装了应用程序想要执行的操作的信息,包括组件名称、数据、动作、类别、标志和额外数据。而 PendingIntent 是对 Intent 的封装,它提供了一种机制,使得第三方应用可以使用该 Intent 在将来某个时间点执行操作。区别在于,普通的 Intent 一旦被发送就会立即执行,而 PendingIntent 则会被延迟执行。当系统接收一个 PendingIntent 时,会将其视为原始请求方的请求,并在合适的时机执行该 Intent。 阅读详情

[1]PendingIntent核心:异步激发intent
PendingIntent的理解:延迟执行intent

官方文档:PendingIntent By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself (with the same permissions and identity). As such, you should be careful about how you build the PendingIntent: almost always, for example, the base Intent you supply should have the component name explicitly set to one of your own components, to ensure it is ultimately sent there and nowhere else.
大意:应用A将PendingIntent发送给应用B让应用B以应用A自己的权限和身份执行指定的操作(Intent),即B此时有了越权操作,是A赋予的

  • 根据官方文档的介绍可以想到,当我们拿到PendingIntent,修改了其中的Intent(PendingIntent本质上只是延迟激发intent),就可以用他的权限来开那些未导出的活动、服务、广播

官方文档:intent.fillIn Copy the contents of other in to this object, but only where fields are not defined by this object. For purposes of a field being defined, the following pieces of data in the Intent are considered to be separate fields:
大意:将other的内复制到这个对象中,但是要求这个对象内的字段为空。

  • intent.fillIn方法:
    大部分属性字段 只有原始intent的mAction为空或者设置的flags不为0才可以覆盖,有两个比较特殊mComponent 、mSelector 必须设置标志flags才可以修改,但是一般开发人员不会主动设置。所以出现几种情况:
  1. 双空(mAction、mComponent为空),可以给intent赋值,启动特定组件
  2. 更改可以更改的属性,故意造成数据异常,可以实现拒绝服务等其他行为
    @FillInFlags
    public int fillIn(@NonNull Intent other, @FillInFlags int flags) {
        int changes = 0;
        boolean mayHaveCopiedUris = false;
        if (other.mAction != null                 
                && (mAction == null || (flags&FILL_IN_ACTION) != 0)) {        //只有原始intent的mAction为空或者设置的flags不为0才可以覆盖
            mAction = other.mAction;                                           //other是用来改变原始intent内容的
            changes |= FILL_IN_ACTION;
        }
        if ((other.mData != null || other.mType != null)
                && ((mData == null && mType == null)
                        || (flags&FILL_IN_DATA) != 0)) {
            mData = other.mData;
            mType = other.mType;
            changes |= FILL_IN_DATA;
            mayHaveCopiedUris = true;
        }
        if (other.mCategories != null
                && (mCategories == null || (flags&FILL_IN_CATEGORIES) != 0)) {
            if (other.mCategories != null) {
                mCategories = new ArraySet<String>(other.mCategories);
            }
            changes |= FILL_IN_CATEGORIES;
        }
      .........
        // Selector is special: it can only be set if explicitly allowed, 
        // for the same reason as the component name.
        if (other.mSelector != null && (flags&FILL_IN_SELECTOR) != 0) {
            if (mPackage == null) {
                mSelector = new Intent(other.mSelector);
                mPackage = null;
                changes |= FILL_IN_SELECTOR;
            }
        }
      .........
        // Component is special: it can -only- be set if explicitly allowed,
        // since otherwise the sender could force the intent somewhere the
        // originator didn't intend.
        if (other.mComponent != null && (flags&FILL_IN_COMPONENT) != 0) {
            mComponent = other.mComponent;
            changes |= FILL_IN_COMPONENT;
        }
        return changes;
    }

实例1:android 4.4.2中系统settings->addAccount()存在"双空"PendingIntent的漏洞

我们应该知道的:除了人工点击settings->添加账户来触发addAccount()方法


13671484-209838883d7b48b0.png
1.png

settings已经提供了接口让我们,在代码里就可以触发申请添加账户

源码位置:/packages/apps/Settings/src/com/android/settings/accounts/AddAccountSettings.java

178    @Override
179    protected void onSaveInstanceState(Bundle outState) {
180        super.onSaveInstanceState(outState);
181        outState.putBoolean(KEY_ADD_CALLED, mAddAccountCalled);
182        if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "saved");
183    }
184
185    private void addAccount(String accountType) {
186        Bundle addAccountOptions = new Bundle();
187        mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(), 0);        //双空PendingIntent出现的地方
188        addAccountOptions.putParcelable(KEY_CALLER_IDENTITY, mPendingIntent);
189        addAccountOptions.putBoolean(EXTRA_HAS_MULTIPLE_USERS, Utils.hasMultipleUsers(this));
190        AccountManager.get(this).addAccount(
191                accountType,
192                null, /* authTokenType */
193                null, /* requiredFeatures */
194                addAccountOptions,
195                null,
196                mCallback,
197                null /* handler */);
198        mAddAccountCalled  = true;
199    }
200}

Questions:

  • 怎么由PendingIntent对象修改intent对象
    [Anwser] intent.fillIn
  • 没有找到AddAccountSettings.java类在哪里定义导出?
    [Anwser] 源码位置:/packages/apps/Settings/AndroidManifest.xml
        <activity android:name="com.android.settings.accounts.AddAccountSettings"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/header_add_an_account"
            android:taskAffinity="com.android.settings"
            android:parentActivityName="Settings$ManageAccountsSettingsActivity">
            <intent-filter>      //有意图过滤intent-filter但是没有android:exported="false"就是默认可以导出
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.settings.ADD_ACCOUNT_SETTINGS" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

[1] https://my.oschina.net/youranhongcha/blog/196933

Intent和PendingIntent的区别 简单的总结了Intent和PendtingIntent的区别,经常与alermanger 和notificationmanager一起使用。 立即下载

相关推荐

企业数字化转型AI大模型赋能智能体平台及AI场景应用规划方案(生态合作版).pptx

企业数字化转型AI大模型赋能智能体平台及AI场景应用规划方案(生态合作版).pptx

PendingIntent详解

PendingIntent可以看作是对Intent的一个封装,但它不是立刻执行某个行为, 而是满足某些条件或触发某些事件后才执行指定的行为。 PendingIntent的获取 PendingIntent获取有三种方式:通过Activity,Service,BroadcastReceiver获取. 1. 你可以通过getActivity(Context context, int req...

xxdw1992的博客 3万+

【东华大学oj】找到最大数(一维数组->中等)

一天,老师布置了一个作业,要求对一串数字各不相同的数字串进行排序,大的在前,小的在后。接着,我从数字串中的第二个数字开始往后找,找到最大的一个,然后与第二个数字交换,这样的话我就能够确定排序后数字串中的第二个数字;明明研究发现,他的这个想法中最重要的一环就是在一串数字中找到最大的那个,然后与第一个数字交换,可是明明毕竟刚刚开始学习程序设计不久,无法写出较复杂的程序,所以明明想让你这位程序设计专家帮他的忙,帮助他把这段核心程序写出来,然后明明只需模仿着写就可以了。时间限制: 1S类别: 一维数组->中等。

的博客 526

Android笔记(十七):PendingIntent简介

介绍PendingIntent,并结合实例进行说明。

userhu2012的博客 6415

ST7789驱动实战:从SPI时序到RGB565显示的完整配置解析

本文详细解析了ST7789液晶驱动芯片的SPI时序配置与RGB565显示实现,从数据手册解读到代码实战,涵盖SPI接口配置、关键寄存器设置及完整初始化流程。通过优化DMA传输和常见问题排查,帮助开发者高效驱动ST7789显示屏,适用于嵌入式显示项目开发。

weixin_29162439的博客 186

LaTeX双栏浮动结构实战:用dblfloatfix解决跨栏图表排版难题

本文深入探讨了LaTeX双栏浮动结构在学术论文排版中的常见问题,特别是IEEE会议论文中的跨栏图表定位难题。通过介绍dblfloatfix包的整合解决方案,帮助用户实现精准的底部定位和浮动顺序保持,提升排版效率与质量。

weixin_30872499的博客 444

Android基础——PendingIntent理解

1. PendingIntent认识 PendIntent其实是Intent的封装,这就带来了几个问题: 为什么要有PendingIntent?与Intent有什么区别? PendingIntent的应用场景主要有哪些? 它的内部是如何实现的? 1.1 与Intent的区别 Intent 是意图的意思。Android 中的 Intent 正是取自这个意思,它是一个消息对象,通过它,Andr...

zhewen的博客 3万+

接入 deepseek 实现AI智能问诊

必须包含user角色,用于传递用户输入。system角色可选,用于设置对话背景。多轮对话需要将历史记录添加到messages中。

weixin_51326478的博客 6545

简单聊聊 PendingIntent 与 Intent 的区别

到这里,PendingIntent的内容就讲完了,相信你对PendingIntent的理解已经超过绝大部分同学,你认同吗?

m0_64420071的博客 1986

蓝牙开发那些事之ceva controller代码解读

对比ceva的经典蓝牙和ble的controller在软件上的差异点

袁赟的博客 1094

零基础入门篇③ PyCharm使用指南(个性化设置、开发必备插件、常用快捷键)

Python从入门到精通👉零基础入门篇③

hacker707的博客 4378

PendingIntent简介

是 Android 中的一种特殊的 Intent,用于在应用外部(例如其他应用或系统组件)延迟执行操作。它封装了一个 Intent 和一个操作(如广播、服务、活动),并允许其他应用或系统以应用的权限执行这些操作。

weixin_51715508的博客 818

解析 RABAX during SAPGUI Logon 错误及其解决方案

登录用户关联了初始启动程序,该程序由于未处理的异常导致运行时错误。在 ST22 查看错误的程序名和错误行。修复初始程序代码中的逻辑问题。重新部署修复后的代码。示例代码:防止未处理的异常TRY." 模拟逻辑处理ENDTRY.此代码通过 TRY-CATCH 块捕获潜在错误,避免程序崩溃。是 SAP 系统中常见的运行时错误,其根源可能涉及多个方面,包括用户配置、系统状态、数据库连接和自定义开发等。通过结合 ST22、SM21 等诊断工具,以及完善的代码实践和系统监控,可以有效预防和解决此类问题。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1786

PendingIntent

PendingIntent可以看作是对Intent的一个封装,但它不是立刻执行某个行为, 而是满足某些条件或触发某些事件后才执行指定的行为。 PendingIntent的获取 PendingIntent获取有三种方式:通过Activity,Service,BroadcastReceiver获取. 1. 你可以通过getActivity(Context context, i...

weixin_30783913的博客 406

蓝鸟四轴飞控系统C程序V3.0(基础版本)深度解读

2. 解析遥控通道数据(油门 / 横滚 / 俯仰 / 偏航),转换为标准化值(-1000~+1000);3. 封装PID初始化(PID_Init,配置KP/KI/KD、输出限幅、积分限幅);,包含姿态角(Attitude_Data.Roll/Pitch/Yaw)、角速度(Gyro_Data.X/Y/Z)、遥控值(RC_Data[0~5])、电池电压(Bat_Volt)、电机PWM值(Motor_PWM[0~3])、系统状态(Sys_State),校验和通过Check_Sum()函数计算;

搏博的专栏 344

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Android中pendingIntent的深入理解

pendingIntent字面意义:等待的,未决定的Intent。  pendingIntent对象,使用方法类的静态方法 :      getActivity(Context, int, Intent, int)------->跳转到一个activity组件、     getBroadcast(Context, int, Intent, int)------>打开一个...

datou1209的博客 508

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Android中PendingIntent的使用

比如,可以在用户点击通知栏的通知时,通过PendingIntent启动一个指定的Activity。比如,可以在用户点击通知栏的通知时,通过PendingIntent启动一个指定的Service。在Android开发中,PendingIntent是一种特殊的Intent,用于在将来的某个时间点执行某个操作。比如,可以在设定的时间点触发一个闹钟,通过PendingIntent执行相应的操作。总之,PendingIntent可以在特定的时间点执行某个操作,常用于与通知、闹钟、定时任务等相关的场景。

Rair的博客 1703

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

PendingIntent 基本用法

pendingIntent 字面意义:延迟的intent,等待的,未决定的Intent。主要用来在某个事件完成后执行特定的Action。pendingIntent是一种特殊的Intent。 主要的区别在于Intent的执行立刻的,而pendingIntent的执行不是立刻的。 pendingIntent执行的操作实质上是参数传进来的Intent的操作, 但是使用pendingIntent的

maybetomorrow_L的博客 1412

android PendingIntent理解

public static void startActivityForService(Context context, MediaInfo mediaInfo) { Intent intent = new Intent(context, ScreenshotResultActivity.class); intent.putExtra(EXTRA_MEDIA_INFO, mediaInfo); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.add

折翅鵬的博客 1万+

Android中intent与pendingIntent的区别

转转 于http://blog.youkuaiyun.com/yuzhiboyi/article/details/8484771 pendingIntent字面意义:等待的,未决定的Intent。 要得到一个pendingIntent对象,使用方法类的静态方法 getActivity(Context, int, Intent, int),getBroadcast(Context, int, Intent

价值只会迟到,但价值绝不会缺席 720

PendingIntent 概述

  PendingIntent 是某个不确定的时刻发生的意图, 而Intent 是立刻发生。PendingIntent  典型的应用场景是给 RemoteViews 添加单击事件, 因为RemoteViews 运行在远程进程中, 因此 RemoteViews 不同于普通的View, 所以无法直接通过 setOnClickListener 方法来设置单击事件。 PendingIntent 通过sen...

yuyang_1995 307
上一篇: [Knowledge]_[apk signature签名]
下一篇: [knowledgePoint]_[create and simple use fragment]
Dr. 熊
博客等级 码龄10年 29粉丝 140原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值