2016-11-24 02:56:11 +01:00
|
|
|
package org.torproject.android.ui.hiddenservices.storage;
|
2016-11-18 00:53:49 +01:00
|
|
|
|
|
|
|
import android.os.Environment;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
public class ExternalStorage {
|
2016-12-06 23:10:36 +01:00
|
|
|
private static final String ORBOT_BACKUPS_DIR = "Orbot";
|
2016-11-18 00:53:49 +01:00
|
|
|
|
2016-11-24 02:22:41 +01:00
|
|
|
public static File getOrCreateBackupDir() {
|
|
|
|
if (!isExternalStorageWritable())
|
2016-11-18 00:53:49 +01:00
|
|
|
return null;
|
|
|
|
|
2016-12-06 23:10:36 +01:00
|
|
|
File dir = new File(Environment.getExternalStorageDirectory(), ORBOT_BACKUPS_DIR);
|
2016-11-18 00:53:49 +01:00
|
|
|
|
2016-11-24 02:22:41 +01:00
|
|
|
if (!dir.isDirectory() && !dir.mkdirs())
|
2016-11-18 00:53:49 +01:00
|
|
|
return null;
|
|
|
|
|
2016-11-24 02:22:41 +01:00
|
|
|
return dir;
|
2016-11-18 00:53:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if external storage is available for read and write */
|
2016-11-24 02:22:41 +01:00
|
|
|
public static boolean isExternalStorageWritable() {
|
2016-11-18 00:53:49 +01:00
|
|
|
String state = Environment.getExternalStorageState();
|
2016-11-24 02:22:41 +01:00
|
|
|
return Environment.MEDIA_MOUNTED.equals(state);
|
2016-11-18 00:53:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if external storage is available to at least read */
|
2016-11-24 02:22:41 +01:00
|
|
|
public static boolean isExternalStorageReadable() {
|
2016-11-18 00:53:49 +01:00
|
|
|
String state = Environment.getExternalStorageState();
|
2016-11-24 02:22:41 +01:00
|
|
|
return Environment.MEDIA_MOUNTED.equals(state) ||
|
|
|
|
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
|
2016-11-18 00:53:49 +01:00
|
|
|
}
|
|
|
|
}
|