Skip to content

Commit

Permalink
fix storage access framework
Browse files Browse the repository at this point in the history
  • Loading branch information
newhinton committed Aug 12, 2022
1 parent 5e4d411 commit 49c299e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import ca.pkay.rcloneexplorer.R;
import ca.pkay.rcloneexplorer.RcloneRcd;
import ca.pkay.rcloneexplorer.util.FLog;
import ca.pkay.rcloneexplorer.util.FlagsUtil;


public class RcdService extends Service implements RcloneRcd.JobsUpdateHandler {
Expand Down Expand Up @@ -176,7 +177,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
private void showNotification() {
Intent foregroundIntent = new Intent(this, RcdService.class);
foregroundIntent.setAction(ACTION_START_FOREGROUND);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, FlagsUtil.Companion.getFlagImmutable());

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_rclone_logo)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package ca.pkay.rcloneexplorer;

import static android.provider.DocumentsContract.Document.COLUMN_DISPLAY_NAME;
import static android.provider.DocumentsContract.Document.COLUMN_LAST_MODIFIED;
import static android.provider.DocumentsContract.Document.COLUMN_SIZE;
import static android.provider.DocumentsContract.Document.MIME_TYPE_DIR;

import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.ContentResolver;
Expand All @@ -25,19 +30,13 @@
import android.system.ErrnoException;
import android.system.OsConstants;
import android.util.LruCache;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceManager;
import ca.pkay.rcloneexplorer.Items.FileItem;
import ca.pkay.rcloneexplorer.Items.RemoteItem;
import ca.pkay.rcloneexplorer.RcloneRcd.ListItem;
import ca.pkay.rcloneexplorer.Services.RcdService;
import ca.pkay.rcloneexplorer.util.FLog;
import io.github.x0b.safdav.provider.SingleRootProvider;
import java9.util.concurrent.CompletableFuture;

import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -58,10 +57,13 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import static android.provider.DocumentsContract.Document.COLUMN_DISPLAY_NAME;
import static android.provider.DocumentsContract.Document.COLUMN_LAST_MODIFIED;
import static android.provider.DocumentsContract.Document.COLUMN_SIZE;
import static android.provider.DocumentsContract.Document.MIME_TYPE_DIR;
import ca.pkay.rcloneexplorer.Items.FileItem;
import ca.pkay.rcloneexplorer.Items.RemoteItem;
import ca.pkay.rcloneexplorer.RcloneRcd.ListItem;
import ca.pkay.rcloneexplorer.Services.RcdService;
import ca.pkay.rcloneexplorer.util.FLog;
import io.github.x0b.safdav.provider.SingleRootProvider;
import java9.util.concurrent.CompletableFuture;

// Beta quality notes
//
Expand Down Expand Up @@ -276,7 +278,7 @@ public Cursor queryRoots(@Nullable String[] projection) {
FLog.v(TAG, "queryRoots: no remote data change");
}
}, asyncExc);
String summary = context.getString(R.string.virtual_content_provider_summary, remotes.size());
String summary = context.getResources().getQuantityString(R.plurals.virtual_content_provider_summary, remotes.size());
return buildRoot(R.mipmap.ic_launcher, R.string.app_name, summary, flags);
} else {
FLog.v(TAG, "queryRoots: VCP loading");
Expand Down Expand Up @@ -1234,9 +1236,6 @@ private Cursor getRemotesAsCursor(@NonNull String[] projection, @Nullable String
}
for (RemoteItem item : remotes.values()) {
// Exclude from results - no need to loop back
if (RemoteItem.SAFW == item.getType()) {
continue;
}
if (null != remoteName && remoteName.equals(item.getName())) {
if (remoteName.equals(item.getName())) {
cursor.addRow(getForProjection(item, projection));
Expand Down Expand Up @@ -1388,16 +1387,21 @@ synchronized void reloadRemotesIfRequired() {
if (lastModified > configModifiedTimestamp) {
configModifiedTimestamp = lastModified;
FLog.d(TAG, "reloadRemotesIfRequired(): requesting new remote config data");
Set<String> oldRemotes = remotes.keySet();
ArrayList<String> newRemotes = new ArrayList<String>();
for (RemoteItem remoteItem : rclone.getRemotes()) {
if (RemoteItem.SAFW == remoteItem.getType() || RemoteItem.LOCAL == remoteItem.getType()) {
continue;
}
remotes.put(remoteItem.getName(), remoteItem);
newRemotes.add(remoteItem.getName());
}
// Remove remotes that no longer exist. If instead
// remotes.clear() were to be used, 'remotes' would need to be
// locked for all access while it is being updated.
oldRemotes.removeAll(remotes.keySet());
for (String oldRemote : oldRemotes) {
remotes.remove(oldRemote);
for (String remote : remotes.keySet()) {
if(!newRemotes.contains(remote)){
remotes.remove(remote);
}
}
FLog.v(TAG, "reloadRemotesIfRequired(): remote config data updated");
}
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/ca/pkay/rcloneexplorer/util/FlagsUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ca.pkay.rcloneexplorer.util

import android.app.PendingIntent
import android.os.Build

class FlagsUtil {

companion object {

fun getFlagImmutable() : Int {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.FLAG_IMMUTABLE
} else {
0
}
}

fun getFlagImmutable(flag: Int) : Int {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.FLAG_IMMUTABLE and flag
} else {
flag
}
}
}

}
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,10 @@
<string name="saf_uri_permission_error">Invalid permission - can not access storage</string>
<string name="saf_uri_permission_already_added">Storage or a subfolder is already added</string>
<string name="saf_uri_permission_no_support">Third party not yet supported. Open an issue with the affected app name.</string>
<string name="virtual_content_provider_summary">%1$d Remotes available</string>
<plurals name="virtual_content_provider_summary">
<item quantity="one">One Remote available</item>
<item quantity="other">%1$d Remotes available</item>
</plurals>
<string name="virtual_content_provider_exception_advice">Check your network connection</string>
<string name="virtual_content_provider_exception_error">Support info: \n%1$s</string>
<string name="virtual_content_provider_null_content">Could not get remote or directory content. You may find more information in the log file.</string>
Expand Down

0 comments on commit 49c299e

Please sign in to comment.