mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-25 17:37:57 +00:00
Do not require write to read from single backup uri.
This commit is contained in:

committed by
Cody Henthorne

parent
d307db8a95
commit
6bf300ada8
@@ -8,9 +8,7 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.text.Editable;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextWatcher;
|
||||
@@ -28,7 +26,6 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.documentfile.provider.DocumentFile;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.dd.CircularProgressButton;
|
||||
@@ -52,7 +49,6 @@ import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.service.LocalBackupListener;
|
||||
import org.thoughtcrime.securesms.util.BackupUtil;
|
||||
import org.thoughtcrime.securesms.util.DateUtils;
|
||||
import org.thoughtcrime.securesms.util.StorageUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
||||
@@ -206,7 +202,7 @@ public final class RestoreBackupFragment extends BaseRegistrationFragment {
|
||||
@NonNull Uri backupUri,
|
||||
@NonNull OnBackupSearchResultListener listener)
|
||||
{
|
||||
SimpleTask.run(() -> BackupUtil.getBackupInfoForUri(context, backupUri),
|
||||
SimpleTask.run(() -> BackupUtil.getBackupInfoFromSingleUri(context, backupUri),
|
||||
listener::run);
|
||||
}
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -166,15 +167,13 @@ public class BackupUtil {
|
||||
}
|
||||
|
||||
@RequiresApi(29)
|
||||
public static @Nullable BackupInfo getBackupInfoForUri(@NonNull Context context, @NonNull Uri uri) {
|
||||
DocumentFile documentFile = DocumentFile.fromSingleUri(context, uri);
|
||||
|
||||
if (documentFile != null && documentFile.exists() && documentFile.canRead() && documentFile.canWrite() && documentFile.getName().endsWith(".backup")) {
|
||||
long backupTimestamp = getBackupTimestamp(documentFile.getName());
|
||||
public static @Nullable BackupInfo getBackupInfoFromSingleUri(@NonNull Context context, @NonNull Uri singleUri) {
|
||||
DocumentFile documentFile = DocumentFile.fromSingleUri(context, singleUri);
|
||||
|
||||
if (isBackupFileReadable(documentFile)) {
|
||||
long backupTimestamp = getBackupTimestamp(Objects.requireNonNull(documentFile.getName()));
|
||||
return new BackupInfo(backupTimestamp, documentFile.length(), documentFile.getUri());
|
||||
} else {
|
||||
logIssueWithDocumentFile(documentFile);
|
||||
Log.w(TAG, "Could not load backup info.");
|
||||
return null;
|
||||
}
|
||||
@@ -260,17 +259,21 @@ public class BackupUtil {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static void logIssueWithDocumentFile(@Nullable DocumentFile documentFile) {
|
||||
private static boolean isBackupFileReadable(@Nullable DocumentFile documentFile) {
|
||||
if (documentFile == null) {
|
||||
throw new AssertionError("We do not support platforms prior to KitKat.");
|
||||
} else if (!documentFile.exists()) {
|
||||
Log.w(TAG, "The document at the specified Uri cannot be found.");
|
||||
Log.w(TAG, "isBackupFileReadable: The document at the specified Uri cannot be found.");
|
||||
return false;
|
||||
} else if (!documentFile.canRead()) {
|
||||
Log.w(TAG, "The document at the specified Uri cannot be read.");
|
||||
} else if (!documentFile.canWrite()) {
|
||||
Log.w(TAG, "The document at the specified Uri cannot be written to.");
|
||||
} else if (!documentFile.getName().endsWith(".backup")) {
|
||||
Log.w(TAG, "The document at the specified Uri has an unsupported file extension.");
|
||||
Log.w(TAG, "isBackupFileReadable: The document at the specified Uri cannot be read.");
|
||||
return false;
|
||||
} else if (TextUtils.isEmpty(documentFile.getName()) || !documentFile.getName().endsWith(".backup")) {
|
||||
Log.w(TAG, "isBackupFileReadable: The document at the specified Uri has an unsupported file extension.");
|
||||
return false;
|
||||
} else {
|
||||
Log.i(TAG, "isBackupFileReadable: The document at the specified Uri looks like a readable backup");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user