Android P Disables Non‑Official APIs: Overview, Testing, and Impact
The article explains how Android P disables hidden (non‑official) APIs, describes the reasons behind the restriction, outlines the grey‑list classification, provides verification steps and code examples for testing, and warns developers of the potential consequences for apps that rely on these APIs.
Android P (preview) introduces restrictions on non‑official APIs—those annotated with @hide and not documented in the SDK—preventing apps from using them via reflection, JNI, or other means.
Information : Recent AOSP commits show that apps using hidden APIs will be limited, and the system will display a toast warning.
Verification : Developers can download the Android P preview build from the official site, flash their devices, and test whether hidden APIs are blocked.
Download link: https://developer.android.com/preview/download.html
After flashing, attempts to use hidden APIs trigger a toast and log entries such as:
Accessing hidden field Landroid/os/Message;->flags:I (light greylist, JNI)
Accessing hidden method Landroid/app/ActivityThread;->currentActivityThread()Landroid/app/ActivityThread; (dark greylist, reflection)Reason for disabling : Google aims to improve app stability by reducing reliance on undocumented interfaces, as announced in February 2018.
Two grey‑list levels are defined:
Light greylist – APIs still work in the preview but may be removed later.
Dark greylist – APIs are blocked in the preview; attempts generate logcat warnings.
Consequences : In future releases, accessing dark‑greylisted APIs will cause errors or crashes. The preview logs the access method (direct, reflection, JNI) and the applicable grey‑list.
Example test : Using reflection to read the hidden field WIFI_SCAN_AVAILABLE from android.net.wifi.WifiManager prints the value and logs a dark‑greylist warning on a Pixel device running Android P preview.
WifiManager wifiManager = (WifiManager) getApplication().getSystemService(Context.WIFI_SERVICE);
Field field = wifiManager.getClass().getDeclaredField("WIFI_SCAN_AVAILABLE");
Log.d(Tag, (String) field.get(wifiManager));Other common hidden APIs were also tested; most remain light‑greylisted and still function, but Google does not guarantee future compatibility.
Summary : Both Java‑level and NDK‑level hidden APIs are now logged and warned about in Android P preview, signaling a shift toward stricter enforcement to ensure stability. Developers should audit their apps for hidden API usage and prepare for potential removal in upcoming Android releases.
JD Tech
Official JD technology sharing platform. All the cutting‑edge JD tech, innovative insights, and open‑source solutions you’re looking for, all in one place.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.