For the Activity
source code, line 3898 (close to the bottom):
/**
* @hide
*/
public final boolean isResumed() {
return mResumed;
}
What does @hide
mean?
I found my public class ChildActivity extends Activity { ... }
cannot use/see Activity.isResumed()
. Is this normal? How can I access it?
Android has two types of APIs that are not accessible via SDK.
The first one is located in package com.android.internal. The second API type is collection of classes and methods that are marked with @hide javadoc attribute.
Starting from Android 9 (API level 28), Google introduces new restrictions on the use of non-SDK interfaces, whether directly, via reflection, or via JNI. These restrictions are applied whenever an app references a non-SDK interface or attempts to obtain its handle using reflection or JNI.
But before API level 28, the hidden methods can still be accessed via java reflection. The @hide attribute is just part of javadoc(droiddoc also), so the @hide just simply mean the method/class/field is excluded from the API docs.
For example, the checkUidPermission method in ActivityManager.java is @hide.
/** @hide */
public static int checkUidPermission(String permission, int uid) {
try {
return AppGlobals.getPackageManager()
.checkUidPermission(permission, uid);
} catch (RemoteException e) {
// Should never happen, but if it does... deny!
Slog.e(TAG, \"PackageManager is dead?!?\", e);
}
return PackageManager.PERMISSION_DENIED;
}
However, we can call it by reflection.
Class c;
c = Class.forName(\"android.app.ActivityManager\");
Method m = c.getMethod(\"checkUidPermission\", new Class[] {String.class, int.class});
Object o = m.invoke(null, new Object[]{\"android.permission.READ_CONTACTS\", 10010});
The @hide
annotation means that this interface is not part of the public API and should not be used in your code. The methods are only for internal use of the AOSP.
Google has actually started to restrict the usage of non-sdk interfaces. This includes interfaces marked with @hide
The methods are classified into four lists:
- whitelist: the SDK
- light-greylist: non SDK methods / fields that are still accessible.
- dark-greylist:
- For apps whose target SDK is below API level 28: each use of a dark greylist interface is permitted.
- For apps whose target SDK is API level 28 or higher: same behavior as blacklist
- blacklist: restricted regardless of target SDK. The platform will behave as if the interface is absent. For example, it will throw
NoSuchMethodError/NoSuchFieldException whenever the app is trying to
use it, and will not include it when the app wants to know the list of
fields/methods of a particular class.
The lists can be found here: https://android.googlesource.com/platform/prebuilts/runtime/+/master/appcompat