当前位置: 首页 > news >正文

Android manifest清单文件意外权限来源和合并规则

问题背景

当自写APP发现无缘无故多申请了多个权限,其中一个就是:android.permission.WAKE_LOCK. 一想就知道如果并非自己在APP main中引入的,那就是依赖的库清单文件导入进来的.

定位问题

定位手段

1.manifest-merger-buildVariant-report.txt

根据其内容可知, WAKE_LOCK 权限来源于work-runtime-2.7.0的库依赖,其清单文件中的25行5-68个字符.

uses-permission#android.permission.WAKE_LOCK
ADDED from [androidx.work:work-runtime:2.7.0] /home/user/.gradle/caches/transforms-3/603a5a760e085f6144531debd6660c46/transformed/work-runtime-2.7.0/AndroidManifest.xml:25:5-68

2.自编AndroidManifest.xml中选中Merged manifest, 通过查看预览merge视图定位来源.

从上视图查看就更加直观了.选中被merge进来的元素,右侧会预览显示merging log. 直接双击该行被引入的元素, 会自动跳转到对应work-runtime的清单文件中.

其内容如下:

<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2016 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="androidx.work" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="31" />

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

    <application>
        <provider
            android:name="androidx.startup.InitializationProvider"
            android:authorities="${applicationId}.androidx-startup"
            android:exported="false"
            tools:node="merge" >
            <meta-data
                android:name="androidx.work.WorkManagerInitializer"
                android:value="androidx.startup" />
        </provider>

        <service
            android:name="androidx.work.impl.background.systemalarm.SystemAlarmService"
            android:directBootAware="false"
            android:enabled="@bool/enable_system_alarm_service_default"
            android:exported="false"
            tools:targetApi="n" />
        <service
            android:name="androidx.work.impl.background.systemjob.SystemJobService"
            android:directBootAware="false"
            android:enabled="@bool/enable_system_job_service_default"
            android:exported="true"
            android:permission="android.permission.BIND_JOB_SERVICE"
            tools:targetApi="n" />
        <service
            android:name="androidx.work.impl.foreground.SystemForegroundService"
            android:directBootAware="false"
            android:enabled="@bool/enable_system_foreground_service_default"
            android:exported="false"
            tools:targetApi="n" />

        <receiver
            android:name="androidx.work.impl.utils.ForceStopRunnable$BroadcastReceiver"
            android:directBootAware="false"
            android:enabled="true"
            android:exported="false"
            tools:targetApi="n" />
        <receiver
            android:name="androidx.work.impl.background.systemalarm.ConstraintProxy$BatteryChargingProxy"
            android:directBootAware="false"
            android:enabled="false"
            android:exported="false"
            tools:targetApi="n" >
            <intent-filter>
                <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
                <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="androidx.work.impl.background.systemalarm.ConstraintProxy$BatteryNotLowProxy"
            android:directBootAware="false"
            android:enabled="false"
            android:exported="false"
            tools:targetApi="n" >
            <intent-filter>
                <action android:name="android.intent.action.BATTERY_OKAY" />
                <action android:name="android.intent.action.BATTERY_LOW" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="androidx.work.impl.background.systemalarm.ConstraintProxy$StorageNotLowProxy"
            android:directBootAware="false"
            android:enabled="false"
            android:exported="false"
            tools:targetApi="n" >
            <intent-filter>
                <action android:name="android.intent.action.DEVICE_STORAGE_LOW" />
                <action android:name="android.intent.action.DEVICE_STORAGE_OK" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="androidx.work.impl.background.systemalarm.ConstraintProxy$NetworkStateProxy"
            android:directBootAware="false"
            android:enabled="false"
            android:exported="false"
            tools:targetApi="n" >
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="androidx.work.impl.background.systemalarm.RescheduleReceiver"
            android:directBootAware="false"
            android:enabled="false"
            android:exported="false"
            tools:targetApi="n" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.TIME_SET" />
                <action android:name="android.intent.action.TIMEZONE_CHANGED" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="androidx.work.impl.background.systemalarm.ConstraintProxyUpdateReceiver"
            android:directBootAware="false"
            android:enabled="@bool/enable_system_alarm_service_default"
            android:exported="false"
            tools:targetApi="n" >
            <intent-filter>
                <action android:name="androidx.work.impl.background.systemalarm.UpdateProxies" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="androidx.work.impl.diagnostics.DiagnosticsReceiver"
            android:directBootAware="false"
            android:enabled="true"
            android:exported="true"
            android:permission="android.permission.DUMP"
            tools:targetApi="n" >
            <intent-filter>
                <action android:name="androidx.work.diagnostics.REQUEST_DIAGNOSTICS" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

从清单文件中可知,其中被默认引入了很多androidx相关的能力, 尽管我们自己定义的demo的AndroidManifest.xml很简单.

这时候可能根据自身情况看是否引入了过多不必要的dependencies依赖库.

3.清单文件合并规则

更多清单文件的合并规则,可以参考android开发者网站官方说明.

管理清单文件  |  Android Studio  |  Android Developers

(完)

相关文章:

  • 设计模式之桥接模式
  • 单片机原理及应用复习
  • AI前沿技术探索:智能化浪潮下的创新与应用
  • 首套真题解析!安徽211难度适中!两门课!
  • 第十三章 进程与线程
  • 冒泡排序与快速排序
  • 基于昇腾910B训练万亿参数的语言模型简介
  • Maven打包错误:无效的源发行版:17
  • 字符串和字节串
  • linux 利用 ~$() 构造数字
  • 【TB作品】MSP430G2553单片机,智能储物柜
  • R 语言入门学习笔记:软件安装踩坑记录——删除所有包以及彻底解决库包被安装到 C 盘用户目录下的问题,以及一些其他需要注意的点
  • 设计模式-原型模式
  • Java(八)——String类
  • Redis 哨兵(Sentinel)
  • 并发——线程
  • Linux-struct list_head的快速使用
  • 流媒体内网穿透/组网/视频协议转换EasyNTS上云网关如何更改密码?
  • 阿里云部署nodejs
  • 2024蓝桥杯国赛C++研究生组游记+个人题解
  • 长期对组织隐瞒真实年龄,广元市城发集团原董事韩治成被双开
  • 优秀“博主”在上海杨浦购房最高补贴200万元,有何条件?
  • 明明睡够了,怎么还有黑眼圈?可能是身体在求救
  • 中国海警依法驱离日非法进入我钓鱼岛领海船只
  • 国家矿山安全监察局发布《煤矿瓦斯防治能力评估办法》
  • 韩国法院将李在明所涉案件重审日期延至大选后