通过将应用程序放在/system/app 中来获取 Android 系统权限? [英] Get Android system permissions by putting app in /system/app?
问题描述
尝试使用来自 AOSP 的一些较新的 Android API,我发现一些需要 android.permission.BLUETOOTH_PRIVILEGED 权限.根据 docs,该权限不适用于第三方党申请."
Experimenting with some newer Android APIs from the AOSP, I have found some that require the android.permission.BLUETOOTH_PRIVILEGED permission. According to the docs, the permission "is not available to third party applications."
我在别处读到过,您可以通过在/system/app 目录中安装您的应用程序来获得对 root 设备的系统级权限.我已经在我扎根的 Nexus 5 上尝试过这个,但我的应用程序仍然没有获得所需的权限.(请参阅下面的代码和 LogCat 输出.)
I have read elsewhere that you can get system level permissions on a rooted device by installing your app in the /system/app directory. I have tried this on my rooted Nexus 5, but my app still does not get the desired privilege. (See code and LogCat output below.)
我听说过的另一种选择是构建您自己的自定义 Android ROM,然后使用相同的密钥对应用程序进行签名.我可以这样做,但如果可能的话,我强烈希望能够使用库存图像.
An alternative I have heard is to build your own custom Android ROM, then sign the app with the same key. I could do this, but would strongly prefer to be able to use a stock image if it is possible.
那是什么?是否可以在带有库存图像的有根电话上获得系统级权限?如果是这样,我做错了什么吗?
So which is it? Is it possible to get system level permissions on a rooted phone with a stock image? If so, am I doing something wrong?
活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ((this.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
Log.d(TAG, "This is a system application");
}
else {
Log.d(TAG, "This is not a system application");
}
if (getApplicationContext().checkCallingOrSelfPermission("android.permission.BLUETOOTH_PRIVILEGED") == PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "I have android.permission.BLUETOOTH_PRIVILEGED");
}
else {
Log.d(TAG, "I do not have android.permission.BLUETOOTH_PRIVILEGED");
}
...
}
LogCat 输出:
W/PackageManager( 788): Not granting permission android.permission.BLUETOOTH_PRIVILEGED to package com.radiusnetworks.testapp (protectionLevel=18 flags=0x8be47)
I/ActivityManager( 788): Start proc com.radiusnetworks.testapp for activity com.radiusnetworks.testapp/.MainActivity: pid=3124 uid=10075 gids={50075, 3002, 3001}
D/MainActivity( 3124): This is a system application
D/MainActivity( 3124): I do not have android.permission.BLUETOOTH_PRIVILEGED
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.radiusnetworks.testapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission
android:name="android.permission.BLUETOOTH_PRIVILEGED"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.radiusnetworks.testapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
推荐答案
从 Android 4.4 开始,特权应用程序必须放在/system/priv-app 而不是/system/app 中.一旦我将我的应用程序移到那里,它就按预期获得了特权.
As of Android 4.4, Privileged Apps must be put in /system/priv-app instead of /system/app. Once I moved my app there, it got the privilege as expected.
参见此处:AOSP 特权与系统应用
这篇关于通过将应用程序放在/system/app 中来获取 Android 系统权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!