@SystemApi @hide @NonNull @TargetApi
来源:互联网 发布:易建联发展联盟数据 编辑:程序博客网 时间:2024/04/30 10:32
- Android中SystemApi hide NonNull TargetApi
- SystemApi hide PrivateApi
- NonNull TargetApi
- 参考信息
Android中@SystemApi @hide @NonNull @TargetApi
我们时常在Android源代码中看到的注释,如SystemApi hide NonNull TargetApi 那么它呢么具体代表什么意思?
@SystemApi @hide @PrivateApi
有关@SystemApi的信息可以首先参见这个链接 ;@SystemApi 是 @PrivateApi的别名;使用@hide标记的API可以不使用@SystemApi进行标;但是当使用@SystemApi标记的API则必须使用@hide
在Android源码中,有两种类型的API无法通过标准的SDK进行访问
如下图所示;
- 位于com.android.internal包中的
- 类/方法 被 @hide修饰的
值得注意的是:隐藏的方法(使用@hide修饰的)仍然可以通过java 反射机制进行访问;@hide标识只是javadoc的一部分(也是Android doc的一部分),所以@hide修饰符仅仅指示了method/class/field 不会被暴露到API中。
例如ActivityManager.java 中的方法checkUidPermission 是被@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;}
但是我们可以通过java的反射机制来访问
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});
下面来看看@SystemApi 和@hide的不同之处
如上文所示:使用@hide修饰的method/class/field,我们仍然何以通过java反射机制进行访问。
但是使用@SystemApi修饰的method/class/field,无法通过java 反射机制进行访问(会触发invocationTargetException异常)
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);Method method = manager.getClass() .getMethod("getPrivilegedConfiguredNetworks");List<WifiConfiguration> configs = (List<WifiConfiguration>)method.invoke(manager);
列出源码
/** * Start AccessPoint mode with the specified * configuration. If the radio is already running in * AP mode, update the new configuration * Note that starting in access point mode disables station * mode operation * @param wifiConfig SSID, security and channel details as * part of WifiConfiguration * @return {@code true} if the operation succeeds, {@code false} otherwise * * @hide Dont open up yet */public boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) { try { mService.setWifiApEnabled(wifiConfig, enabled); return true; } catch (RemoteException e) { return false; }}/** @hide */@SystemApipublic List<WifiConfiguration> getPrivilegedConfiguredNetworks() { try { return mService.getPrivilegedConfiguredNetworks(); } catch (RemoteException e) { return null; }
@NonNull @TargetApi
TargetApi & NonNull如下图所示:
TargetApi
NonNull
TargetApi的常见用法是指定当前class/method/field所使用的api版本,也就是所谓的android 4.4/5.0/5.1/
NonNull常见用于修饰参数,用于表明该参数不为空!
参考信息
github rename PrivateApi to SystemApi
Stackoverflow SystemApi
Stackoverflow @hide
- @SystemApi @hide @NonNull @TargetApi
- Android中的@SystemApi@hide等
- @TargetAPI
- Java SystemApi
- nonnull, nullable
- android @TargetApi
- Android--@TargetApi
- @TargetApi 问题
- Android 关于@NonNull
- nonnull、泛型、__kindof
- AFN文件上传 appendPartWithFileData:<#(nonnull NSData *)#> name:<#(nonnull NSString *)#>
- iOS修行---nonnull,nullable修饰
- 学习(二)(@NonNull的作用)
- [Android]annottation @NonNull and @interface
- @SuppressLint or @TargetApi
- @TargetApi and @SuppressLint
- @SuppressWarinings, @TargetApi, @SuppressLint, @ViewInject
- android 版本兼容 @TargetApi
- Xrdp: Ubuntu使用Xrdp协议重新连接存在的会话
- android的消息处理机制(图+源码分析)——Looper,Handler,Message
- ffmpeg 裁剪视频
- 红亚2015-3月杯季赛 CTF题部分writeup
- iOS---iOS9中获取通讯录的方法:Contacts. framework简单使用
- @SystemApi @hide @NonNull @TargetApi
- Mysql技术内幕知识点摘录
- MySql基础知识
- 【笔记】利用css3特性实现扑克效果
- 中小企业及创业团队云上监控方法
- java 跨越访问 (jquery,jsonp)
- http://blog.jobbole.com/78960/
- Code-Based Configuration (EF6 onwards)
- 【索引】索引五种扫描方式至索引范围扫描