2

我正在寻找一些帮助,通过应用程序修改Android系统设置。Android应用程序无法修改系统设置

我在自定义Android应用程序在Kitkat 4.4.2下正常运行时遇到了一些麻烦。我不确定我的挫折源头是什么,但我在思考我错过了Manifest中的某种安全设置或欺骗。

背景:我不是开发者,但是这个项目已经落入我的大腿。在部署我们的平板电脑之前,我们将MDM和公司apk安装到平板电脑上,并运行一个简单的程序来配置一些系统设置。我们在平板电脑上执行一个根并在此过程中安装SU二进制文件。

我已将ACCESS_SUPERUSER添加到我的清单中,但我没有被SuperSU提示请求SU访问此应用程序。此外,如果我尝试运行该应用程序,则会收到“应用程序未安装”Toast消息。 (我取代了应用程序的名称与下面的应用)

的Java代码

Settings.Global.putInt(MainActivity.this.getContentResolver(), Settings.Global.INSTALL_NON_MARKET_APPS, 1); 
Settings.Global.putInt(MainActivity.this.getContentResolver(), Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 1); 
Settings.Secure.putInt(MainActivity.this.getContentResolver(), Settings.Secure.LOCK_PATERN_ENABLED, 0); 
Settings.Secure.putInt(MainActivity.this.getContentResolver(), Settings.Secure.LOCK_PATTERN_VISIBLE, 0); 
Settings.System.putInt(MainActivity.this.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 300000); 
Settings.Secure.putInt(MainActivity.this.getContentResolver(), Settings.Global.ADB_ENABLED, 0); 

清单

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

    <uses-sdk 
     android:minSdkVersion="19" 
     android:targetSdkVersion="19" /> 

    <uses-permission android:name="android.permission.ACCESS_SUPERUSER"/> 
    <uses-permission android:name="android.permission.WRITE_SETTINGS"/> 
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" 
     android:persistent="false" 
     android:permission="android.permission.WRITE_SECURE_SETTINGS" 
     android:exported="true" > 
     <activity 
      android:name="com.example.APPLICATION.MainActivity" 
      android:label="@string/app_name" 
      android:exported="true" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 


</manifest> 

logcat的错误

11-20 17:17:51.749: E/Launcher(686): Launcher does not have the permission to launch Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.APPLICATION/.MainActivity }. Make sure to create a MAIN intent-filter for the corresponding activity or use the exported attribute for this activity. tag=ApplicationInfo(title=SetSet id=-1 type=0 container=-1 screen=-1 cellX=-1 cellY=-1 spanX=1 spanY=1 dropPos=null) intent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.setset/.MainActivity }

11-20 17:32:16.169: E/AndroidRuntime(4744): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.setset/com.example.APPLICATION.MainActivity}: java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS

回答

1

我的决心。我最终采取的解决方案是以超级用户身份运行该应用程序,并且现在似乎正确设置了系统设置。请注意,我正在根设备上运行此应用程序。

首先,在清单中,我需要删除此行从应用程序标签:

android:permission="android.permission.WRITE_SECURE_SETTINGS" 

不知道的推理。看起来你不能在应用程序标签中调用安全权限。

在我的MainActivity,我添加了下面苏呼我try语句,并在设置中添加下面的命令:

Process p = Runtime.getRuntime().exec("su"); 

感谢@本 - 金属 - 比尔德为他的方向!

2

好像你需要运行你的应用程序作为系统应用程序,除了做你正在做的所有事情。您遇到了WRITE_SECURE_SETTINGS权限问题,详细解释如下:here

此外,你可能还需要添加以下到您的清单:纳入一些不同的东西需要

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
... 
coreApp="true" 
android:sharedUserId="android.uid.system"> 

<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/> 
... 
+0

对不起,我没有注意到我已经试过把它安装到'/ system/app'和'/ system/priv-app'文件夹中,但是我收到了类似的结果。 我也尝试添加标签'android:sharedUserId =“android.uid.system”'到我的清单中,但它似乎没有什么区别。 – DontCopyThatFloppy 2014-11-21 16:01:11

+0

更新了我的答案 – C0D3LIC1OU5 2014-11-21 16:11:21

+0

太好了,谢谢@ The-Metal-Beard。尽管遇到新的情况。在将apk安装到'/ system/app'并重新启动之后,我没有在设备上看到该应用程序。它也没有在设置>>应用程序>>预加载下列出。有没有从以前的安装,这阻止了这种残留?另外,试图执行'adb install'会给我以下错误:'失败[INSTALL_FAILED_SHARED_USER_INCOMPATIBLE]' – DontCopyThatFloppy 2014-11-21 17:16:08