Android APP合规检查工具介绍

描述

一个通过拦截Java方法调用用以检测应用是否合规的工具  

一、Android Studio中引用插件miit-rule-checker

1.添加mavenCentral

 

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

 

2.添加Gradle依赖

 

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support27.1.1'
    implementation 'com.android.support.constraint1.1.2'
    testImplementation 'junit4.12'
    androidTestImplementation 'com.android.support.test1.0.2'
    androidTestImplementation 'com.android.support.test.espresso3.0.2'


    implementation 'com.jakewharton8.8.1'
    annotationProcessor 'com.jakewharton8.8.1'


    implementation 'com.alibaba2.0.23'
    implementation("org.greenrobot3.3.1")
    implementation 'com.appsflyer6.9.0'
    implementation "com.android.installreferrer2.2"
    implementation("org.greenrobot3.3.1")


    implementation 'com.squareup.okhttp35.0.0-alpha.10'
    implementation 'io.github.loper70.2.0'
}

 


二、使用方法

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


检查MIITRuleChecker内置的不合规的方法

 

MIITRuleChecker.checkDefaults()

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

比如新增一个 MainActivity 的 onCreate 方法的调用检查;
val list = MIITMethods.getDefaultMethods()
list.add(MainActivity::class.java.getDeclaredMethod("onCreate" , Bundle::class.java))
MIITRuleChecker.check(list)
 

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

APP  

 


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

 

//查看 WifiInfo class 内 getMacAddress 的调用栈堆
MIITRuleChecker.check(MIITMethods.WifiInfo.getMacAddress)
APP  

3.检查一定时间内指定方法调用次数统计
 //多个方法统计 (deadline 为从方法调用开始到多少毫秒后截至统计)
 val list = mutableListOf().apply {
          add(MIITMethods.LocationManager.getLastKnownLocation)
          add(MIITMethods.LocationManager.requestLocationUpdates)
          add(MIITMethods.Secure.getString)
      }
MIITMethodCountChecker.startCount( 20 * 1000,list)


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

 

特别注意:

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

三、内置方法表

APP

APP

 


 

  审核编辑:汤梓红

 

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分