It is necessary ...
1) Get the database from data/data/com.android.provider.settings/databases/settings.db
2) Next you need to add a new line to it.
3) Put the modified database in place.
How to perform the first item? First I request root
access
try { java.lang.Process p = Runtime.getRuntime().exec("su"); } catch (IOException e){}
A confirmation window appears issuing root
, click "Access". Further, in theory, this code should be executed
try { File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if (sd.canWrite()) { String currentDBPath = "/data/data/" + "com.android.providers.settings" + "/databases/settings.db"; String backupDBPath = "data.db"; File currentDB = new File(currentDBPath); File backupDB = new File(sd, backupDBPath); if (currentDB.exists()) { FileChannel src = new FileInputStream(currentDB).getChannel(); FileChannel dst = new FileOutputStream(backupDB).getChannel(); dst.transferFrom(src, 0, src.size()); src.close(); dst.close(); }}} catch (Exception e) { Toast.makeText(MainActivity.this, e.toString(), 1).show(); }
But, in Toast
writes:
.....EACCESS: Permission denied
Added permissions to AndroidManifest.xml
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ru.albatros.testroot" > <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_SUPERUSER"/> ...
And it gives nothing . How? The application got root
, but still there is no permission. I'm testing on Android 5.1.1 (CyanogenMod 12.1, custom firmware). Help, it turns out, is more complicated than I thought.
settings put system <key> <value>
without any manipulations I add immediately to the database - Flippy