Force Mounting 2

If you have root then most likely you have write access to secondary storage. If not then use the app-specific folder. You may create the folder via built-in file manager > Android/data/net.wagic.app/files/Wagic/Res
This commit is contained in:
Anthony Calosa
2016-06-17 16:58:15 +08:00
committed by GitHub
parent 68b632857d
commit 3ef6b3a76a

View File

@@ -61,7 +61,7 @@ public class StorageOptions
if (line.startsWith("/"))
{
String[] lineElements = line.split("\\s+");
if ("vfat".equals(lineElements[2]) || "fuse".equals(lineElements[2]))
if ("vfat".equals(lineElements[2]) || "fuse".equals(lineElements[2]) || "sdcardfs".equals(lineElements[2]))
{
File mountPoint = new File(lineElements[1]);
if (!lineElements[1].equals(defaultMountPoint))
@@ -201,13 +201,43 @@ public class StorageOptions
mMounts.remove(i--);
}
if (t == 0 && Build.VERSION.SDK_INT >= 19)
{//If none is found and build version is kitkat or higher
File root = new File("/storage/sdcard0");
if (root.exists() && root.isDirectory() && root.canWrite())
mMounts.add("/storage/sdcard0");
if (isExternalStorageAvailable() && !isExternalStorageReadOnly())
mMounts.add("/storage/sdcard1");
if (t == 0 && Build.VERSION.SDK_INT >= 16)
{//if none is found lets force it for Jellybean and above...
if (System.getenv("EXTERNAL_STORAGE") != null)
{
File root = new File(System.getenv("EXTERNAL_STORAGE"));
if (root.exists() && root.isDirectory() && root.canWrite())
{
if(!isRooted())
{
File folder = new File(System.getenv("EXTERNAL_STORAGE")+"/Android/data/net.wagic.app/files");
folder.mkdirs();
mMounts.add(folder.toString());
}
else
{
mMounts.add(System.getenv("EXTERNAL_STORAGE"));
}
}
}
if (System.getenv("SECONDARY_STORAGE") != null)
{
File root = new File(System.getenv("SECONDARY_STORAGE"));
if (root.exists() && root.isDirectory() && root.canWrite())
{
if(!isRooted())
{
File folder = new File(System.getenv("SECONDARY_STORAGE")+"/Android/data/net.wagic.app/files");
folder.mkdirs();
mMounts.add(folder.toString());
}
else
{
mMounts.add(System.getenv("SECONDARY_STORAGE"));
}
}
}
}
}
@@ -224,6 +254,8 @@ public class StorageOptions
{ // TODO: /mnt/sdcard is assumed to always mean internal storage. Use this comparison until there is a better way to do this
if ("/mnt/sdcard".equalsIgnoreCase(path) || "/storage/sdcard0".equalsIgnoreCase(path))
mLabels.add("Internal SD " + "[" + path + "]");
else if (path.contains("emulated"))
mLabels.add("Emulated SD " + " [" + path + "]");
else
mLabels.add("External SD " + " [" + path + "]");
}
@@ -256,4 +288,74 @@ public class StorageOptions
}
return false;
}
/**
* Checks if the device is rooted.
*
* @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
*/
public static boolean isRooted() {
// get from build info
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
// check if /system/app/Superuser.apk is present
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
return true;
}
}
catch (Exception e1) {
// ignore
}
try {
File file = new File("/system/app/Superuser/Superuser.apk");
if (file.exists()) {
return true;
}
}
catch (Exception e1) {
// ignore
}
//SuperSU
try {
File file = new File("/system/app/SuperSU.apk");
if (file.exists()) {
return true;
}
}
catch (Exception e1) {
// ignore
}
try {
File file = new File("/system/app/SuperSU/SuperSU.apk");
if (file.exists()) {
return true;
}
}
catch (Exception e1) {
// ignore
}
// try executing commands
return canExecuteCommand("/system/xbin/which su")
|| canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
}
// executes a command on the system
private static boolean canExecuteCommand(String command) {
boolean executedSuccesfully;
try {
Runtime.getRuntime().exec(command);
executedSuccesfully = true;
}
catch (Exception e) {
executedSuccesfully = false;
}
return executedSuccesfully;
}
}