I was able to use root explorer to go into the settings.db under /data/data/com.android.providers.settings/databases to change the permissions to get access. Now my question is how to I change permissions to the database through code?
I manually changed the permissions with root explorer. Now I need to figure out how to do it in my app. I have no idea how I would do it. I am pretty new to Android development and really new to B4A.
I guess it would help if I told it what folder/file to change permissions on. Not sure how to do that. Tried the below but it didn't work either.
Dim p As Phone
Dim sb As StringBuilder
sb.Initialize
p.Shell("chmod 999 /data/data/com.android.providers.settings/databases/settings.db", Null, sb, Null)
I think this should be the right code but it doesn't work. Please a little help here.
B4X:
Dim p As Phone
Dim sb As StringBuilder
sb.Initialize
p.Shell("chmod 777 /data/data/com.android.providers.settings/databases/settings.db", Null, sb, Null)
From what I read by searching Google, Shell commands are not part of the SDK and thus what you are doing can't be relied upon to work.
However, I found a post saying:
Java doesn't have native support for platform dependent operations like chmod. However, Android provides utilities for some of these operations via android.os.FileUtils. The FileUtils class is not part of the public SDK and is therefore not supported. So, use this at your own risk:
Really? WOW I thought this would be a no brainer for you guys. I am pretty sure this will work. I am just missing something simple. From ADB I typed "ADB SHELL" then enter. Which gave me the $ prompt and then typed "SU" and then enter. Which gave me the # prompt.
Then typed "chmod 777 /data/data/com.android.providers.settings/databases/settings.db". And it worked fine. Since my app already has SU access I would think that just sending the shell command "chmod 777 /data/data/com.android.providers.settings/databases/settings.db" would work.
I am using the B4A Help viewer and didn't see anything at first but from one of the links I saw another link. It usually is pretty good at showing the links.
Ok. I followed the tutorial. I used Eclipse to create a new library. I called it chmod. I added to the B4A library. When it tries to compile I get a undeclared variable error 'chmod'. I am not sure if the code below is the problem or not.
B4X:
package chmod.chmod;
import java.io.File;
import java.lang.reflect.Method;
public class Chmod {
public int chmod(File path, int mode) throws Exception {
Class fileUtils = Class.forName("android.os.FileUtils");
Method setPermissions =
fileUtils.getMethod("setPermissions", String.class, int.class, int.class, int.class);
return (Integer) setPermissions.invoke(null, path.getAbsolutePath(), mode, -1, -1);
}
}