|
@@ -59,9 +59,15 @@ import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Various utilities that make auto upload tick
|
|
|
|
+ */
|
|
public class FilesSyncHelper {
|
|
public class FilesSyncHelper {
|
|
public static final String TAG = "FileSyncHelper";
|
|
public static final String TAG = "FileSyncHelper";
|
|
|
|
|
|
|
|
+ public static final String GLOBAL = "global";
|
|
|
|
+ public static final String SYNCEDFOLDERINITIATED = "syncedFolderIntitiated_";
|
|
|
|
+
|
|
public static int ContentSyncJobId = 315;
|
|
public static int ContentSyncJobId = 315;
|
|
|
|
|
|
public static void insertAllDBEntriesForSyncedFolder(SyncedFolder syncedFolder) {
|
|
public static void insertAllDBEntriesForSyncedFolder(SyncedFolder syncedFolder) {
|
|
@@ -73,13 +79,13 @@ public class FilesSyncHelper {
|
|
double currentTimeInSeconds = currentTime / 1000.0;
|
|
double currentTimeInSeconds = currentTime / 1000.0;
|
|
String currentTimeString = Long.toString((long) currentTimeInSeconds);
|
|
String currentTimeString = Long.toString((long) currentTimeInSeconds);
|
|
|
|
|
|
- String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + syncedFolder.getId();
|
|
|
|
|
|
+ String syncedFolderInitiatedKey = SYNCEDFOLDERINITIATED + syncedFolder.getId();
|
|
boolean dryRun = TextUtils.isEmpty(arbitraryDataProvider.getValue
|
|
boolean dryRun = TextUtils.isEmpty(arbitraryDataProvider.getValue
|
|
- ("global", syncedFolderInitiatedKey));
|
|
|
|
|
|
+ (GLOBAL, syncedFolderInitiatedKey));
|
|
|
|
|
|
if (MediaFolder.IMAGE == syncedFolder.getType()) {
|
|
if (MediaFolder.IMAGE == syncedFolder.getType()) {
|
|
if (dryRun) {
|
|
if (dryRun) {
|
|
- arbitraryDataProvider.storeOrUpdateKeyValue("global", syncedFolderInitiatedKey,
|
|
|
|
|
|
+ arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey,
|
|
currentTimeString);
|
|
currentTimeString);
|
|
} else {
|
|
} else {
|
|
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI
|
|
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI
|
|
@@ -91,7 +97,7 @@ public class FilesSyncHelper {
|
|
} else if (MediaFolder.VIDEO == syncedFolder.getType()) {
|
|
} else if (MediaFolder.VIDEO == syncedFolder.getType()) {
|
|
|
|
|
|
if (dryRun) {
|
|
if (dryRun) {
|
|
- arbitraryDataProvider.storeOrUpdateKeyValue("global", syncedFolderInitiatedKey,
|
|
|
|
|
|
+ arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey,
|
|
currentTimeString);
|
|
currentTimeString);
|
|
} else {
|
|
} else {
|
|
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Video.Media.INTERNAL_CONTENT_URI,
|
|
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Video.Media.INTERNAL_CONTENT_URI,
|
|
@@ -104,13 +110,13 @@ public class FilesSyncHelper {
|
|
try {
|
|
try {
|
|
|
|
|
|
if (dryRun) {
|
|
if (dryRun) {
|
|
- arbitraryDataProvider.storeOrUpdateKeyValue("global", syncedFolderInitiatedKey,
|
|
|
|
|
|
+ arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey,
|
|
currentTimeString);
|
|
currentTimeString);
|
|
} else {
|
|
} else {
|
|
FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
|
|
FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
|
|
Path path = Paths.get(syncedFolder.getLocalPath());
|
|
Path path = Paths.get(syncedFolder.getLocalPath());
|
|
|
|
|
|
- String dateInitiated = arbitraryDataProvider.getValue("global",
|
|
|
|
|
|
+ String dateInitiated = arbitraryDataProvider.getValue(GLOBAL,
|
|
syncedFolderInitiatedKey);
|
|
syncedFolderInitiatedKey);
|
|
|
|
|
|
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
|
|
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
|
|
@@ -135,7 +141,7 @@ public class FilesSyncHelper {
|
|
}
|
|
}
|
|
|
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- Log.d(TAG, "Something went wrong while indexing files for auto upload");
|
|
|
|
|
|
+ Log.e(TAG, "Something went wrong while indexing files for auto upload " + e.getLocalizedMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -175,8 +181,8 @@ public class FilesSyncHelper {
|
|
path = path + "%";
|
|
path = path + "%";
|
|
}
|
|
}
|
|
|
|
|
|
- String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + syncedFolder.getId();
|
|
|
|
- String dateInitiated = arbitraryDataProvider.getValue("global", syncedFolderInitiatedKey);
|
|
|
|
|
|
+ String syncedFolderInitiatedKey = SYNCEDFOLDERINITIATED + syncedFolder.getId();
|
|
|
|
+ String dateInitiated = arbitraryDataProvider.getValue(GLOBAL, syncedFolderInitiatedKey);
|
|
|
|
|
|
cursor = context.getContentResolver().query(uri, projection, MediaStore.MediaColumns.DATA + " LIKE ?",
|
|
cursor = context.getContentResolver().query(uri, projection, MediaStore.MediaColumns.DATA + " LIKE ?",
|
|
new String[]{path}, null);
|
|
new String[]{path}, null);
|
|
@@ -265,7 +271,6 @@ public class FilesSyncHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
if (hasImageFolders || hasVideoFolders) {
|
|
if (hasImageFolders || hasVideoFolders) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
scheduleJobOnN(hasImageFolders, hasVideoFolders, force);
|
|
scheduleJobOnN(hasImageFolders, hasVideoFolders, force);
|
|
@@ -275,7 +280,6 @@ public class FilesSyncHelper {
|
|
cancelJobOnN();
|
|
cancelJobOnN();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public static void scheduleFilesSyncIfNeeded() {
|
|
public static void scheduleFilesSyncIfNeeded() {
|
|
@@ -302,8 +306,7 @@ public class FilesSyncHelper {
|
|
boolean force) {
|
|
boolean force) {
|
|
JobScheduler jobScheduler = MainApp.getAppContext().getSystemService(JobScheduler.class);
|
|
JobScheduler jobScheduler = MainApp.getAppContext().getSystemService(JobScheduler.class);
|
|
|
|
|
|
- if (((android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) && (hasImageFolders || hasVideoFolders)) &&
|
|
|
|
- (!isContentObserverJobScheduled() || force)) {
|
|
|
|
|
|
+ if ((hasImageFolders || hasVideoFolders) && (!isContentObserverJobScheduled() || force)) {
|
|
JobInfo.Builder builder = new JobInfo.Builder(ContentSyncJobId, new ComponentName(MainApp.getAppContext(),
|
|
JobInfo.Builder builder = new JobInfo.Builder(ContentSyncJobId, new ComponentName(MainApp.getAppContext(),
|
|
NContentObserverJob.class.getName()));
|
|
NContentObserverJob.class.getName()));
|
|
builder.addTriggerContentUri(new JobInfo.TriggerContentUri(android.provider.MediaStore.
|
|
builder.addTriggerContentUri(new JobInfo.TriggerContentUri(android.provider.MediaStore.
|