AndroidManifest——add custom permission

来源:互联网 发布:ioc java 编辑:程序博客网 时间:2024/05/19 02:31

1、首先,在Android系统源代码中,给API接口添加权限的位置为:frameworks/base/core/res/AndroidManifest.xml

2、添加自定义权限的语法规则为:(frameworks/base/core/res/AndroidManifest.xml)

<permission android:name="android.permission.SYSTEMCONTROL"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="normal"
        android:description="@string/system_ctl"
        android:label="normal" />

<permission-group android:name="android.permission-group.SYSTEM_TOOLS"
        android:label="@string/permgrouplab_systemTools"
        android:icon="@drawable/perm_group_system_tools"
        android:description="@string/permgroupdesc_systemTools"
        android:priority="100" />

3、在frameworks/base/core/res/res/values/string.xml中添加:

<string name="system_ctl">is access to system control!</string>

<string name="permgrouplab_systemTools">System tools</string>
<string name="permgroupdesc_systemTools">Lower-level access and controls of the system.</string>等2中相关的信息

4、然后,在源码中添加完权限之后,在eclipse中写用到这些权限的API的测试用例时,需要在测试项目的AndroidManifest.xml中写上:


5、API接口类的方法中的框架为:

public class SystemControl {static Context mContext = null;private static final String TAG = "systemcontrol";private static final boolean DBG = true;        public SystemControl(Context mCont) {mContext = mCont;}        public static String checkSystemUpdate(String cfgFile) {String res = null;if (mContext == null)return res;if (mContext.checkCallingOrSelfPermission("android.permission.SYSTEMCONTROL") != PackageManager.PERMISSION_GRANTED) {if (DBG)Log.d(TAG, "is not have permission");return res;}if (DBG)Log.d(TAG,"============== checkSystemUpdate() ==================\n");                 /*write function*/                  return res;}
6、在测试的时候,可以适当的添加一下Log.i(“dd”,"ddd");Log.e(" "," ");来进行调试。

0 0
原创粉丝点击