Skip to content

Commit

Permalink
api33: storage and audio permission not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Oct 2, 2023
1 parent 08a5381 commit 90f9090
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 0 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" />

<uses-permission android:name="android.permission.CAMERA" />
Expand Down
2 changes: 1 addition & 1 deletion src/org/thoughtcrime/securesms/mms/AttachmentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public static void selectImage(Activity activity, int requestCode) {

public static void selectAudio(Activity activity, int requestCode) {
Permissions.with(activity)
.request(Permissions.audioPermissions())
.request(Manifest.permission.READ_EXTERNAL_STORAGE)
.ifNecessary()
.withPermanentDenialDialog(activity.getString(R.string.perm_explain_access_to_storage_denied))
.onAllGranted(() -> selectMediaType(activity, "audio/*", null, requestCode))
Expand Down
20 changes: 12 additions & 8 deletions src/org/thoughtcrime/securesms/permissions/Permissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ public static String[] galleryPermissions() {
}
}

public static String audioPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
return Manifest.permission.READ_MEDIA_AUDIO;
} else {
return Manifest.permission.READ_EXTERNAL_STORAGE;
}
}

private static final Map<Integer, PermissionsRequest> OUTSTANDING = new LRUCache<>(2);

public static PermissionsBuilder with(@NonNull Activity activity) {
Expand Down Expand Up @@ -151,6 +143,18 @@ public PermissionsBuilder onSomePermanentlyDenied(Consumer<List<String>> somePer
}

public void execute() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE does not exist on modern androids
// as file access is done by pickers
String[] r = requestedPermissions;
Arrays.sort(r);
if ( (r.length == 1 && (r[0].equals(Manifest.permission.READ_EXTERNAL_STORAGE) || r[0].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)))
|| (r.length == 2 && r[0].equals(Manifest.permission.READ_EXTERNAL_STORAGE) && r[1].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE))) {
allGrantedListener.run();
return;
}
}

PermissionsRequest request = new PermissionsRequest(allGrantedListener, anyDeniedListener, anyPermanentlyDeniedListener, anyResultListener,
someGrantedListener, someDeniedListener, somePermanentlyDeniedListener);

Expand Down

0 comments on commit 90f9090

Please sign in to comment.