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