不能让Android应用程序安装为系统应用上的模拟器,让过去的WRITE_APN_SETTINGS SecurityException异常 [英] Can't get Android App installed as System App on emulator to get past SecurityException for WRITE_APN_SETTINGS

查看:2802
本文介绍了不能让Android应用程序安装为系统应用上的模拟器,让过去的WRITE_APN_SETTINGS SecurityException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,我要用来设置​​APN设置。这就要求 android.permission.WRITE_APN_SETTINGS 许可,也就是只授予系统应用或使用相同的私钥作为操作系统本身的签名。我只打算使用这个模拟器上(或者一个根深蒂固的设备),所以能够以它在我的控制范围之外的实际部署的设备是不是一个问题。我反对建设,推动以API 19。

尽管推我的APK到 /系统/应用/ 目录,并设置搭配chmod 0644 ,我仍然得到 java.lang.SecurityException异常:没有写APN设置权限:用户都不10052也不当前进程具有android.permission.WRITE_APN_SETTINGS 亚行logcat 当我尝试运行应用程序。

我也试过用分贝shell中运行应用程序苏-c上午开始-n com.example.proxysetter / .MainActivity,没有运气。

比编译和从源代码签名我自己的Andr​​oid形象等有什么建议? (不理想。)我是pretty肯定我并不需要提供 .odex 文件即使在一切/系统/应用/ 有它。

下面是推动APK时模拟器我一直在关注,到目前为止的步骤:

 蚂蚁调试
亚行重新装入
亚行推斌/ MainActivity-debug.apk /系统/应用/
亚行外壳搭配chmod 0644 /system/app/MainActivity-debug.apk

我不使用重新启动模拟器亚行重新启动,因为它并不适用于模拟器的工作,如果我手动终止仿真器并重新启动它,应用程序没有按' ŧ出现在我的应用程序列表。

和我的表现:

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.exampld.proxysetter
    安卓版code =1
    机器人:=的versionName1.0>    <用途-SDK
        安卓的minSdkVersion =18
        机器人:targetSdkVersion =19/>
    <使用许可权的android:NAME =android.permission.WRITE_APN_SETTINGS/>    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名字=。MainActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
    < /用途>< /清单>

和堆栈跟踪:

  I / ActivityManager(384):启动PROC com.example.proxysetter的活动com.example.proxysetter / .MainActivity:PID = 1082 UID = 10052导报= {} 50052
D / dalvikvm(1082):不晚启用CheckJNI(已上)
D / dalvikvm(384):GC_FOR_ALLOC释放340K,15%的可用6420K / 7468K,暂停91ms,总93ms
D / dalvikvm(1082):GC_FOR_ALLOC释放70K,10%免费3571K / 3968K,暂停30毫秒,32毫秒总
E / DatabaseUtils(535):写入例外包裹
E / DatabaseUtils(535):java.lang.SecurityException异常:没有写APN设置权限:用户都不10052也不当前进程具有android.permission.WRITE_APN_SETTINGS。
E / DatabaseUtils(535):在android.app.ContextImpl.enforce(ContextImpl.java:1685)
E / DatabaseUtils(535):在android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1714)
E / DatabaseUtils(535):在com.android.providers.telephony.TelephonyProvider.checkPermission(TelephonyProvider.java:735)
E / DatabaseUtils(535):在com.android.providers.telephony.TelephonyProvider.query(TelephonyProvider.java:462)
E / DatabaseUtils(535):在android.content.ContentProvider.query(ContentProvider.java:857)
E / DatabaseUtils(535):在android.content.ContentProvider $ Transport.query(ContentProvider.java:200)
E / DatabaseUtils(535):在android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
E / DatabaseUtils(535):在android.os.Binder.execTransact(Binder.java:404)
E / DatabaseUtils(535):在dalvik.system.NativeStart.run(本机方法)
D / AndroidRuntime(1082):关闭VM
W / dalvikvm(1082):主题ID = 1:螺纹未捕获的异常(组= 0xb1a41ba8)退出
E / AndroidRuntime(1082):致命异常:主要
E / AndroidRuntime(1082):工艺:com.example.proxysetter,PID:1082
E / AndroidRuntime(1082):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.proxysetter / com.example.proxysetter.MainActivity}:java.lang.SecurityException异常:没有写APN设置权限:用户都不10052也不当前进程android.permission.WRITE_APN_SETTINGS。
E / AndroidRuntime(1082):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
E / AndroidRuntime(1082):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
E / AndroidRuntime(1082):在android.app.ActivityThread.access $ 800(ActivityThread.java:135)
E / AndroidRuntime(1082):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1196)
E / AndroidRuntime(1082):在android.os.Handler.dispatchMessage(Handler.java:102)
E / AndroidRuntime(1082):在android.os.Looper.loop(Looper.java:136)
E / AndroidRuntime(1082):在android.app.ActivityThread.main(ActivityThread.java:5017)
E / AndroidRuntime(1082):在java.lang.reflect.Method.invokeNative(本机方法)
E / AndroidRuntime(1082):在java.lang.reflect.Method.invoke(Method.java:515)
E / AndroidRuntime(1082):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)
E / AndroidRuntime(1082):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E / AndroidRuntime(1082):在dalvik.system.NativeStart.main(本机方法)
E / AndroidRuntime(1082):java.lang.SecurityException异常:没有写APN设置权限:由引起用户都不10052也不当前进程具有android.permission.WRITE_APN_SETTINGS。
E / AndroidRuntime(1082):在android.os.Parcel.readException(Parcel.java:1465)
E / AndroidRuntime(1082):在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
E / AndroidRuntime(1082):在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
E / AndroidRuntime(1082):在android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
E / AndroidRuntime(1082):在android.content.ContentResolver.query(ContentResolver.java:461)
E / AndroidRuntime(1082):在android.content.ContentResolver.query(ContentResolver.java:404)
E / AndroidRuntime(1082):在com.example.proxysetter.MainActivity.setAPN(MainActivity.java:28)
E / AndroidRuntime(1082):在com.example.proxysetter.MainActivity.onCreate(MainActivity.java:19)
E / AndroidRuntime(1082):在android.app.Activity.performCreate(Activity.java:5231)
E / AndroidRuntime(1082):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E / AndroidRuntime(1082):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
E / AndroidRuntime(1082):11 ...更多
W / ActivityManager(384):强制完成活动com.example.proxysetter / .MainActivity


解决方案

对于那些想知道:

A)我做了一个错字;为API 19+要推到/系统/私法应用。

二)我是能够通过安装system.img为ext4并安装系统映像上的应用程序来安装应用程序。我复制系统映像目录到一个新的位置,修改system.img然后进行编辑foo.avd / config.ini文件指向我修改的系统映像目录中。

I have an Android app which I want to use to set the APN settings. This requires the android.permission.WRITE_APN_SETTINGS permission, which is only granted to System apps or apps signed with the same private key as the OS itself. I'm only going to be using this on an emulator (or maybe a rooted device), so being able to actually deploy it to devices outside of my control isn't a concern. I'm building against and pushing to API 19.

Despite pushing my APK to the /system/app/ directory and setting chmod 0644, I still get java.lang.SecurityException: No permission to write APN settings: Neither user 10052 nor current process has android.permission.WRITE_APN_SETTINGS. in adb logcat when I try to run the app.

I've also tried running the app using db shell "su -c am start -n com.example.proxysetter/.MainActivity" with no luck.

Any suggestions other than compiling and signing my own Android image from source? (Not ideal.) I'm pretty sure I don't need to provide a .odex file even though everything else in /system/app/ has it.

Here are the steps I've been following so far when pushing the APK to the emulator:

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

I don't reboot the emulator using adb reboot because it doesn't work for emulators, and if I manually kill the emulator and relaunch it, the app doesn't appear in my app list.

And my manifest:

<?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>

And the stack trace:

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

解决方案

For those wondering:

a) I made a typo; for API 19+ you want to push to /system/priv-app.

b) I was able to install the app by mounting system.img as ext4 and installing the app on the system image. I copied the system image directory into a new location, modified system.img and then edited foo.avd/config.ini to point to my modified system image directory.

这篇关于不能让Android应用程序安装为系统应用上的模拟器,让过去的WRITE_APN_SETTINGS SecurityException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆