Android APP合规检查,你可能需要这个工具~

虽迟但到,这是一个通过拦截Java方法调用用以检测应用是否合规的工具,如果你的APP正饱受监管部门或应用市场时不时下发整改通知的折磨,那么用它来检查你的代码以及引用的三方库是再好不过的选择了!

如何引入

Step 1. 添加 mavenCentral

gradle 复制代码
allprojects {
    	repositories {
    		...
    	 mavenCentral()
    	}
    }

Step 2. 添加 Gradle 依赖

gradle 复制代码
dependencies {
        ...
        implementation 'io.github.loper7:miit-rule-checker:0.1.1'
    }

如何使用

检查APP内是否存在不合规的方法调用

检查MIITRuleChecker内置的不合规的方法,具体可见下方方法列表

kotlin 复制代码
 MIITRuleChecker.checkDefaults()

如果内置的方法不满足当前需求,可自定义方法添加到list中进行检查;

比如新增一个 MainActivity 的 onCreate 方法的调用检查;

kotlin 复制代码
val list = MIITMethods.getDefaultMethods()
list.add(MainActivity::class.java.getDeclaredMethod("onCreate" , Bundle::class.java)) MIITRuleChecker.check(list)

当然,如果你想检查多个内置方法外的方法,只需要创建一个新的集合,往集合里放你想检查的方法member,然后传入 MIITRuleChecker.check()内即可。

log打印如下所示:

检查指定方法调用并查看调用栈堆

kotlin 复制代码
//查看 WifiInfo class 内 getMacAddress 的调用栈堆
MIITRuleChecker.check(MIITMethods.WifiInfo.getMacAddress)

log打印如下所示:

检查一定时间内指定方法调用次数统计

kotlin 复制代码
//多个方法统计 (deadline 为从方法调用开始到多少毫秒后截至统计)
val list = mutableListOf<Member?>().apply {
add(MIITMethods.LocationManager.getLastKnownLocation)
add(MIITMethods.LocationManager.requestLocationUpdates)
add(MIITMethods.Secure.getString)
}
MIITMethodCountChecker.startCount(list , 20 * 1000)

//单个方法统计(deadline 为从方法调用开始到多少毫秒后截至统计)
MIITMethodCountChecker.startCount(MIITMethods.LocationManager.getLastKnownLocation , deadline = 20 * 1000)

log打印如下所示:

检查完成并完成整改后务必移除方法 miit-rule-checker 库内的所有方法调用,将库一起移除最好

内置方法表

内置常量 对应的系统方法 备注
MIITMethods.WifiInfo.getMacAddress android.net.wifi.WifiInfo.getMacAddress() 获取MAC地址
MIITMethods.WifiInfo.getIpAddress android.net.wifi.WifiInfo.getIpAddress() 获取IP地址
MIITMethods.LocationManager.getLastKnownLocation android.location.LocationManager.getLastKnownLocation(String) 获取上次定位的地址
MIITMethods.LocationManager.requestLocationUpdates android.location.LocationManager.requestLocationUpdates(String,Long,Float,LocationListener)
MIITMethods.NetworkInterface.getHardwareAddress java.net.NetworkInterface.getHardwareAddress() 获取主机地址
MIITMethods.ApplicationPackageManager.getInstalledPackages android.app.ApplicationPackageManager.getInstalledPackages(Int) 获取已安装的应用
MIITMethods.ApplicationPackageManager.getInstalledApplications android.app.ApplicationPackageManager.getInstalledApplications(Int) 获取已安装的应用
MIITMethods.ApplicationPackageManager.getInstallerPackageName android.app.ApplicationPackageManager.getInstallerPackageName(String) 获取应用安装来源
MIITMethods.ApplicationPackageManager.getPackageInfo android.app.ApplicationPackageManager.getPackageInfo(String,Int) 获取应用信息
MIITMethods.PackageManager.getInstalledPackages android.content.pm.PackageManager.getInstalledPackages(Int) 获取已安装的应用
MIITMethods.PackageManager.getInstalledApplications android.content.pm.PackageManager.getInstalledApplications(Int) 获取已安装的应用
MIITMethods.PackageManager.getInstallerPackageName android.content.pm.PackageManager.getInstallerPackageName(String) 获取应用安装来源
MIITMethods.PackageManager.getPackageInfo android.content.pm.PackageManager.getPackageInfo(String,Int) 获取应用信息
MIITMethods.PackageManager.getPackageInfo1 android.content.pm.PackageManager.getPackageInfo(String,PackageInfoFlags) 获取应用信息(版本号大于33)
MIITMethods.PackageManager.getPackageInfo2 android.content.pm.PackageManager.getPackageInfo(VersionedPackage,Int) 获取应用信息(版本号大于26)
MIITMethods.PackageManager.getPackageInfo3 android.content.pm.PackageManager.getPackageInfo(VersionedPackage,PackageInfoFlags) 获取应用信息(版本号大于33)
MIITMethods.Secure.getString android.provider.Settings.Secure.getString(ContentResolver,String) 获取androidId
MIITMethods.TelephonyManager.getDeviceId android.telephony.TelephonyManager.getDeviceId() 获取 DeviceId
MIITMethods.TelephonyManager.getDeviceIdWithInt android.telephony.TelephonyManager.getDeviceId(Int) 获取 DeviceId
MIITMethods.TelephonyManager.getImei android.telephony.TelephonyManager.getImei() 获取 Imei
MIITMethods.TelephonyManager.getImeiWithInt android.telephony.TelephonyManager.getImei(Int) 获取 Imei
MIITMethods.TelephonyManager.getSubscriberId android.telephony.TelephonyManager.getSubscriberId() 获取 SubscriberId

相关文章

Github

联系我

相关推荐
爬虫程序猿17 分钟前
利用爬虫按关键字搜索淘宝商品实战指南
android·爬虫
顾北川_野44 分钟前
Android ttyS2无法打开该如何配置 + ttyS0和ttyS1可以
android·fpga开发
小和尚同志2 小时前
全网影视一网打尽!8.2K Star 的 LibreTV 让你甩开追剧烦恼
开源·github
说私域2 小时前
开源链动2+1模式与AI智能名片融合下的S2B2C商城小程序源码:重构大零售时代新生态
人工智能·重构·开源
国服第二切图仔2 小时前
基于文心开源大模型ERNIE-4.5-0.3B-Paddle私有化部署并构建一个企业智能客服系统
百度·开源·智能客服·知识库·文心大模型·paddle·gitcode
wzj_what_why_how4 小时前
Android网络层架构:统一错误处理的问题分析到解决方案与设计实现
android·架构
千里马学框架4 小时前
User手机上如何抓取界面的布局uiautomatorviewer
android·智能手机·aosp·uiautomator·布局抓取·user版本
ai小鬼头4 小时前
AIStarter 3.2.0更新!一键离线导入+高速下载,熊哥教你轻松玩转AI工具
人工智能·程序员·github
阿巴~阿巴~4 小时前
操作系统核心技术剖析:从Android驱动模型到鸿蒙微内核的国产化实践
android·华为·harmonyos
码字的字节5 小时前
阿里开源WebSailor:超越闭源模型的网络智能体新星
开源·阿里·websailor·网络智能体