I'm looking for some assistance in modifying Android system settings via an app.
I'm having some trouble getting a custom Android app to run properly under Kitkat 4.4.2. I'm not sure what the source of my frustrations is, but I'm thinking I'm missing some kind of security setting or trick in the Manifest.
Background: I am not a developer, but this project has fallen into my lap. Before deploying our tablets, we install our MDM and company apk to the tablet, and also run a simple program to configure some of the system settings. We perform a root on the tablet and install the SU binaries along this process.
I've added ACCESS_SUPERUSER to my manifest, but I am not being prompted by SuperSU requesting SU access for this app. Additionally, if I try to run the app, I recieve a "App isn't installed" toast message. (I replaced the application name with APPLICATION below)
Java Code
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);
Manifest
<?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 Errors
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
Seems like you need to run your app as a system app in addition to doing all the things you are doing. You are hitting the WRITE_SECURE_SETTINGS permissions issue which is explaned in detail here.
In addition, you might also want to add the following to your manifest:
<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"/>
...
My resolution needed to incorporate a few different things. The solution I ended up taking was to run the app as a superuser and it seems to properly set the system settings now. Note that I am running this application on a rooted device.
First, in the Manifest, I needed to remove this line from the application tag:
android:permission="android.permission.WRITE_SECURE_SETTINGS"
Not sure of the reasoning. It looks like you can't call secure permissions within the application tag.
In my MainActivity, I added the following su call to my try statement, and added in the settings commands beneath:
Process p = Runtime.getRuntime().exec("su");
Thanks to @The-Metal-Beard for his direction!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With