无法在模拟器上安装Android App作为系统应用程序来获取WRITE_APN_SETTINGS的SecurityException

时间:2014-08-22 22:43:20

标签: android permissions android-emulator root

我有一个Android应用程序,我想用它来设置APN设置。这需要android.permission.WRITE_APN_SETTINGS权限,该权限仅授予使用与操作系统本身相同的私钥签名的系统应用程序或应用程序。我只会在模拟器(或者可能是root设备)上使用它,因此能够将其实际部署到我无法控制的设备上并不是一个问题。我正在反对并推动API 19。

尽管将我的APK推送到/system/app/目录并设置chmod 0644,但当我尝试运行该应用时,我仍会在 java.lang.SecurityException: No permission to write APN settings: Neither user 10052 nor current process has android.permission.WRITE_APN_SETTINGS.中获得adb logcat

我还尝试使用db shell "su -c am start -n com.example.proxysetter/.MainActivity"运行该应用但没有运气。

除了从源代码编译和签署我自己的Android图像之外的任何建议? (不太理想。)我很确定我不需要提供.odex文件,即使/system/app/中的其他内容都有。{/ p>

以下是我将APK推送到模拟器时所遵循的步骤:

ant debug
adb remount
adb push bin/MainActivity-debug.apk /system/app/
adb shell chmod 0644 /system/app/MainActivity-debug.apk

我没有使用adb reboot重新启动模拟器,因为它不适用于模拟器,如果我手动终止模拟器并重新启动它,该应用程序不会出现在我的模拟器中应用列表。

我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.exampld.proxysetter"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="18"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.WRITE_APN_SETTINGS"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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>

堆栈跟踪:

I/ActivityManager(  384): Start proc com.example.proxysetter for activity com.example.proxysetter/.MainActivity: pid=1082 uid=10052 gids={50052}
D/dalvikvm( 1082): Not late-enabling CheckJNI (already on)
D/dalvikvm(  384): GC_FOR_ALLOC freed 340K, 15% free 6420K/7468K, paused 91ms, total 93ms
D/dalvikvm( 1082): GC_FOR_ALLOC freed 70K, 10% free 3571K/3968K, paused 30ms, total 32ms
E/DatabaseUtils(  535): Writing exception to parcel
E/DatabaseUtils(  535): java.lang.SecurityException: No permission to write APN settings: Neither user 10052 nor current process has android.permission.WRITE_APN_SETTINGS.
E/DatabaseUtils(  535):     at android.app.ContextImpl.enforce(ContextImpl.java:1685)
E/DatabaseUtils(  535):     at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1714)
E/DatabaseUtils(  535):     at com.android.providers.telephony.TelephonyProvider.checkPermission(TelephonyProvider.java:735)
E/DatabaseUtils(  535):     at com.android.providers.telephony.TelephonyProvider.query(TelephonyProvider.java:462)
E/DatabaseUtils(  535):     at android.content.ContentProvider.query(ContentProvider.java:857)
E/DatabaseUtils(  535):     at android.content.ContentProvider$Transport.query(ContentProvider.java:200)
E/DatabaseUtils(  535):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
E/DatabaseUtils(  535):     at android.os.Binder.execTransact(Binder.java:404)
E/DatabaseUtils(  535):     at dalvik.system.NativeStart.run(Native Method)
D/AndroidRuntime( 1082): Shutting down VM
W/dalvikvm( 1082): threadid=1: thread exiting with uncaught exception (group=0xb1a41ba8)
E/AndroidRuntime( 1082): FATAL EXCEPTION: main
E/AndroidRuntime( 1082): Process: com.example.proxysetter, PID: 1082
E/AndroidRuntime( 1082): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.proxysetter/com.example.proxysetter.MainActivity}: java.lang.SecurityException: No permission to write APN settings: Neither user 10052 nor current process has android.permission.WRITE_APN_SETTINGS.
E/AndroidRuntime( 1082):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
E/AndroidRuntime( 1082):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
E/AndroidRuntime( 1082):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
E/AndroidRuntime( 1082):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/AndroidRuntime( 1082):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 1082):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 1082):    at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 1082):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1082):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 1082):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 1082):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 1082):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1082): Caused by: java.lang.SecurityException: No permission to write APN settings: Neither user 10052 nor current process has android.permission.WRITE_APN_SETTINGS.
E/AndroidRuntime( 1082):    at android.os.Parcel.readException(Parcel.java:1465)
E/AndroidRuntime( 1082):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
E/AndroidRuntime( 1082):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
E/AndroidRuntime( 1082):    at android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
E/AndroidRuntime( 1082):    at android.content.ContentResolver.query(ContentResolver.java:461)
E/AndroidRuntime( 1082):    at android.content.ContentResolver.query(ContentResolver.java:404)
E/AndroidRuntime( 1082):    at com.example.proxysetter.MainActivity.setAPN(MainActivity.java:28)
E/AndroidRuntime( 1082):    at com.example.proxysetter.MainActivity.onCreate(MainActivity.java:19)
E/AndroidRuntime( 1082):    at android.app.Activity.performCreate(Activity.java:5231)
E/AndroidRuntime( 1082):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime( 1082):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
E/AndroidRuntime( 1082):    ... 11 more
W/ActivityManager(  384):   Force finishing activity com.example.proxysetter/.MainActivity

1 个答案:

答案 0 :(得分:1)

对于那些想知道:

a)我写了一个错字;对于API 19+,您想要推送到/ system / priv-app。

b)我可以通过将system.img挂载为ext4并在系统映像上安装应用程序来安装应用程序。我将系统映像目录复制到一个新位置,修改了system.img,然后编辑了foo.avd / config.ini以指向我修改过的系统映像目录。