background

Since last year, the Ministry of Industry and Information Technology (MIIT) has demanded more and more personal privacy from apps, and then major APP markets have begun to do the same. Violations can lead to the removal or failure of apps.

Technical Solution Introduction

The solution is very simple, dynamic proxy + reflection hook system service, intercept method call stack to produce Excel results. According to the need to invite

The project address

List of supported hook functions

portal

access

Add allprojects {repositories {... maven { url 'https://jitpack.io' } } }Copy the code
2. In the project's build. Gralde add implementation 'com. Making. Allenymt: PrivacySentry: 0.0.7'Copy the code
3. The initialization method is best called first in attachBaseContext!!Copy the code
4.1 Easy initialization is called in code, the earlier the better, Recommended application invokes the kotlin: PrivacySentry. Privacy. The init (this) Java: PrivacySentry. Privacy. The INSTANCE. The init (this);Copy the code
Var Builder = PrivacySentryBuilder() // Customize the output name of the file result.configResultfilename ("demo_test") // Customize the test time, Also support the initiative to stop testing PrivacySentry. Privacy. StopWatch () configWatchTime (5 * 60 * 1000) / / callback after the file output configResultCallBack (object: PrivacyResultCallBack { override fun onResultCallBack(filePath: String) { PrivacyLog.i("result file patch is $filePath") } }) PrivacySentry.Privacy.init(this, PrivacySentry. Privacy. DefaultConfigHookBuilder (builder)) Java / / PrivacySentryBuilder builder = new full version configuration PrivacySentryBuilder() // Customize the output name of the file result.configResultfilename ("buyer_privacy") Also support the initiative to stop testing PrivacySentry. Privacy. StopWatch () configWatchTime (30 * 1000) / / callback after the file output configResultCallBack (new PrivacyResultCallBack() { @Override public void onResultCallBack(@NonNull String s) { } }); PrivacySentry.Privacy.INSTANCE.init(this, PrivacySentry.Privacy.INSTANCE.defaultConfigHookBuilder(builder));Copy the code
4.3 When the privacy agreement is confirmed, this step is very important! , be sure to add kotlin: PrivacySentry. Privacy. UpdatePrivacyShow () Java: PrivacySentry. Privacy. The INSTANCE. The updatePrivacyShow ();Copy the code
5 Supports multiple processes. By default, the process name is added to the file name prefix generated by multiple processesCopy the code
portal

The results view

1. The default duration for blocking the privacy method is 3 minutes, and you can customize the duration. For the result, see demo_result. XLS in the directory. The investigation results can be viewed from two dimensions: the first is the display time of privacy protocol and the call time of sensitive methods; the second is the count of the call times of all sensitive functions. 3. Screening results observed logs, as a result, the file will be in the/storage/emulated / 0 / Android/data/yourPackgeName/files/privacy/yourFileName XLS, need to manually perform the adb pullCopy the code
portal

Here is a screenshot showing the order of privacy confirmation and privacy function calls

conclusion

When introducing SDK, do not bring the code to the online SDK test results for reference only ~Copy the code