|
|
@@ -113,7 +113,18 @@ public class GalleryBackupManager implements ActivityManager.ProcessLifecycleLis
|
|
|
AtmobLog.d(TAG, "Starting gallery backup...");
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
try {
|
|
|
+ doRecovery(); // attempt recovery first
|
|
|
+ } catch (Exception e) {
|
|
|
+ AtmobLog.e(TAG, "Error during gallery recovery: %s", e.getMessage(), e);
|
|
|
+ } finally {
|
|
|
+ long duration = System.currentTimeMillis() - startTime;
|
|
|
+ AtmobLog.d(TAG, "Gallery recovery completed in %d ms", duration);
|
|
|
+ }
|
|
|
+ startTime = System.currentTimeMillis(); // reset start time for backup
|
|
|
+ try {
|
|
|
doBackup();
|
|
|
+ } catch (Exception e) {
|
|
|
+ AtmobLog.e(TAG, "Error during gallery backup: %s", e.getMessage(), e);
|
|
|
} finally {
|
|
|
isBackupInProgress.set(false); // reset backup flag
|
|
|
long duration = System.currentTimeMillis() - startTime;
|
|
|
@@ -163,10 +174,23 @@ public class GalleryBackupManager implements ActivityManager.ProcessLifecycleLis
|
|
|
count++;
|
|
|
}
|
|
|
}
|
|
|
+ cleanupOldBackups();
|
|
|
+ }
|
|
|
|
|
|
+ private void doRecovery() {
|
|
|
+ Uri collection;
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
|
+ collection = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
|
|
|
+ } else {
|
|
|
+ collection = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
|
|
+ }
|
|
|
+ String[] projection = new String[]{
|
|
|
+ MediaStore.Images.Media._ID
|
|
|
+ };
|
|
|
long oldestDate = KVUtils.getDefault().getLong(KEY_OLDEST_IMAGE_ADDED_DATE, Long.MAX_VALUE);
|
|
|
String selection = MediaStore.Images.Media.DATE_ADDED + " >= ?";
|
|
|
String[] selectionArgs = new String[]{String.valueOf(oldestDate)};
|
|
|
+ String sortOrder = MediaStore.Images.Media.DATE_ADDED + " DESC";
|
|
|
try (Cursor cursor = contentResolver.query(
|
|
|
collection,
|
|
|
projection,
|
|
|
@@ -189,7 +213,6 @@ public class GalleryBackupManager implements ActivityManager.ProcessLifecycleLis
|
|
|
}
|
|
|
checkRecoveredImages(imagePaths);
|
|
|
}
|
|
|
- cleanupOldBackups();
|
|
|
}
|
|
|
|
|
|
private long getBitmapSizePerPixel(String displayName, String mimeType) {
|