From fae5f18058b3873a51f279217305307965386549 Mon Sep 17 00:00:00 2001 From: Zhuang Ma Date: Wed, 20 Jun 2018 08:40:19 +0800 Subject: [PATCH] Add commond to control access of non SDK API --- README.en.md | 28 ++++++++++++++++++++++++++++ README.md | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/README.en.md b/README.en.md index a4b3cb2..9ca51d1 100644 --- a/README.en.md +++ b/README.en.md @@ -83,6 +83,7 @@ Other languages: [:cn: Chinese](./README.md) * [Screen density](#screen-density-1) * [Overscan](#overscan) * [Turn off Android Debug](#turn-off-android-debug) + * [allow/forbidden access non SDK API](#allowforbidden-access-non-sdk-api) * [Show/hide status bar or navigation bar](#showhide-status-bar-or-navigation-bar) * [Utility functions](#utility-functions) * [Screenshots](#screenshots) @@ -1860,6 +1861,33 @@ So just do it on device manually: "Settings" - "Developer options" - "Android Debug". +### allow/forbidden access non SDK API + +allow access non SDK API: + +```sh +adb shell settings put global hidden_api_policy_pre_p_apps 1 +adb shell settings put global hidden_api_policy_p_apps 1 +``` + +forbidden access non SDK API: + +```sh +adb shell settings delete global hidden_api_policy_pre_p_apps +adb shell settings delete global hidden_api_policy_p_apps +``` + +*Note: Commands above don't need root privileges.* + +meaning for number in command tail: + +| value | meaning | +|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 0 | disable detect for non SDK API call. In this situation, there is no call log in logcat, and make strict mode API, detectNonSdkApiUsage() invalid. Not recommended. | +| 1 | Just warning -- allow access all non SDK API, but retain warning in logcat. You can continue to use strick mode API. | +| 2 | It is forbidden to invoke interfaces in dark grey lists and black lists. | +| 3 | It is forbidden to invoke the interface in the black list, but it is allowed to call the interface in the dark grey list. | + ### Show/hide status bar or navigation bar Settings in this section correspond with "Expanded desktop" in Cyanogenmod. diff --git a/README.md b/README.md index e04898a..fca635a 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Other languages: [:gb: English](./README.en.md) * [屏幕密度](#屏幕密度-1) * [显示区域](#显示区域) * [关闭 USB 调试模式](#关闭-usb-调试模式) + * [允许/禁止访问非 SDK API](#允许禁止访问非-sdk-api) * [状态栏和导航栏的显示隐藏](#状态栏和导航栏的显示隐藏) * [实用功能](#实用功能) * [屏幕截图](#屏幕截图) @@ -1866,6 +1867,33 @@ adb shell settings put global adb_enabled 0 去设备上手动恢复吧:「设置」-「开发者选项」-「Android 调试」。 +### 允许/禁止访问非 SDK API + +允许访问非 SDK API: + +```sh +adb shell settings put global hidden_api_policy_pre_p_apps 1 +adb shell settings put global hidden_api_policy_p_apps 1 +``` + +禁止访问非 SDK API: + +```sh +adb shell settings delete global hidden_api_policy_pre_p_apps +adb shell settings delete global hidden_api_policy_p_apps +``` + +不需要设备获得 Root 权限。 + +命令最后的数字的含义: + +| 值 | 含义 | +|----|---------------------------------------------------------------------------------------------------------------------------| +| 0 | 禁止检测非 SDK 接口的调用。该情况下,日志记录功能被禁用,并且令 strict mode API,即 detectNonSdkApiUsage() 无效。不推荐。 | +| 1 | 仅警告——允许访问所有非 SDK 接口,但保留日志中的警告信息,可继续使用 strick mode API。 | +| 2 | 禁止调用深灰名单和黑名单中的接口。 | +| 3 | 禁止调用黑名单中的接口,但允许调用深灰名单中的接口。 | + ### 状态栏和导航栏的显示隐藏 本节所说的相关设置对应 Cyanogenmod 里的「扩展桌面」。