Rework of permissions for SDK >= 33

This commit is contained in:
Arne 2023-10-24 04:11:40 +02:00
parent 63b1fe17d0
commit d9ae7e1959
16 changed files with 185 additions and 70 deletions

View file

@ -151,10 +151,10 @@ android {
compileSdk 34
defaultConfig {
minSdkVersion 21
minSdkVersion 23
targetSdkVersion 34
// versionNameSuffix " Experimental_(2023-10-20)" // " beta_(XXXX-XX-XX)" // activate for beta versions
// versionNameSuffix " Experimental_(2023-10-24)" // " beta_(XXXX-XX-XX)" // activate for beta versions
versionCode 138
versionName "1.7.6"
//resConfigs "en"

View file

@ -77,12 +77,13 @@ public class PermissionsActivity extends AppCompatActivity
public static String[] storage_permissions_33 = {
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO
Manifest.permission.READ_MEDIA_VIDEO,
Manifest.permission.POST_NOTIFICATIONS
};
public static String[] permissions() {
String[] p;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (Compatibility.runsThirtyThree()) {
p = storage_permissions_33;
} else {
p = storage_permissions;

View file

@ -33,6 +33,7 @@ import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.ConversationsActivity;
import eu.siacs.conversations.ui.adapter.MessageAdapter;
import eu.siacs.conversations.ui.util.PendingItem;
import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.ThemeHelper;
import eu.siacs.conversations.utils.WeakReferenceSet;
@ -135,7 +136,11 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
}
private void startStop(ImageButton playPause) {
if (ContextCompat.checkSelfPermission(messageAdapter.getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(messageAdapter.getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (Compatibility.runsThirtyThree() && ContextCompat.checkSelfPermission(messageAdapter.getActivity(), Manifest.permission.READ_MEDIA_IMAGES) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(messageAdapter.getActivity(), Manifest.permission.READ_MEDIA_AUDIO) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(messageAdapter.getActivity(), Manifest.permission.READ_MEDIA_VIDEO) != PackageManager.PERMISSION_GRANTED) {
pendingOnClickView.push(new WeakReference<>(playPause));
ActivityCompat.requestPermissions(messageAdapter.getActivity(), new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_AUDIO, Manifest.permission.READ_MEDIA_VIDEO}, ConversationsActivity.REQUEST_PLAY_PAUSE);
return;
} else if (!Compatibility.runsThirtyThree() && ContextCompat.checkSelfPermission(messageAdapter.getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(messageAdapter.getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
pendingOnClickView.push(new WeakReference<>(playPause));
ActivityCompat.requestPermissions(messageAdapter.getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, ConversationsActivity.REQUEST_PLAY_PAUSE);
return;

View file

@ -1059,9 +1059,12 @@ public class XmppConnectionService extends Service {
expireOldFiles();
deleteWebpreviewCache();
}
// move files from /monocles chat/ --> /Android/data/ for Android >= 30
if (Compatibility.runsThirty() && (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
&& ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) && !Compatibility.runsThirtyThree()) {
StorageHelper.migrateStorage(this);
} else if (Compatibility.runsThirtyThree() && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_MEDIA_IMAGES) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_MEDIA_AUDIO) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_MEDIA_VIDEO) == PackageManager.PERMISSION_GRANTED) {
StorageHelper.migrateStorage(this);
}
return START_STICKY;

View file

@ -531,7 +531,9 @@ public class ConversationFragment extends XmppFragment
return false;
}
}
if (hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.WRITE_EXTERNAL_STORAGE) && hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.READ_EXTERNAL_STORAGE)) {
if (!Compatibility.runsThirtyThree() && hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.WRITE_EXTERNAL_STORAGE) && hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.READ_EXTERNAL_STORAGE)) {
attachEditorContentToConversation(inputContentInfo.getContentUri());
} else if (Compatibility.runsThirtyThree() && hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.READ_MEDIA_IMAGES) && hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.READ_MEDIA_AUDIO) && hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.READ_MEDIA_VIDEO)){
attachEditorContentToConversation(inputContentInfo.getContentUri());
} else {
mPendingEditorContent = inputContentInfo.getContentUri();
@ -1354,7 +1356,12 @@ public class ConversationFragment extends XmppFragment
private void commitAttachments() {
final List<Attachment> attachments = mediaPreviewAdapter.getAttachments();
if (anyNeedsExternalStoragePermission(attachments) && !hasPermissions(REQUEST_COMMIT_ATTACHMENTS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (anyNeedsExternalStoragePermission(attachments) && !hasPermissions(REQUEST_COMMIT_ATTACHMENTS, Manifest.permission.WRITE_EXTERNAL_STORAGE) && !Compatibility.runsThirtyThree()) {
return;
} else if (Compatibility.runsThirtyThree() && !hasPermissions(REQUEST_COMMIT_ATTACHMENTS,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO)) {
return;
}
if (trustKeysIfNeeded(conversation, REQUEST_TRUST_KEYS_ATTACHMENTS)) {
@ -2542,19 +2549,47 @@ public class ConversationFragment extends XmppFragment
public void attachFile(final int attachmentChoice, final boolean updateRecentlyUsed) {
if (attachmentChoice == ATTACHMENT_CHOICE_RECORD_VOICE) {
if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO)) {
if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO) && !Compatibility.runsThirtyThree()) {
return;
} else if (Compatibility.runsThirtyThree() && !hasPermissions(attachmentChoice,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO)) {
return;
}
} else if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO || attachmentChoice == ATTACHMENT_CHOICE_RECORD_VIDEO) {
if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA)) {
} else if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO) {
if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA) && !Compatibility.runsThirtyThree()) {
return;
} else if (Compatibility.runsThirtyThree() && !hasPermissions(attachmentChoice,
Manifest.permission.CAMERA,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO)) {
return;
}
} else if (attachmentChoice == ATTACHMENT_CHOICE_RECORD_VIDEO) {
if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO) && !Compatibility.runsThirtyThree()) {
return;
} else if (Compatibility.runsThirtyThree() && !hasPermissions(attachmentChoice,
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO)) {
return;
}
} else if (attachmentChoice == ATTACHMENT_CHOICE_LOCATION) {
if (!hasPermissions(attachmentChoice, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)) {
return;
}
} else if (attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_FILE || attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_IMAGE || attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_VIDEO) {
if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)) {
} else if ((attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_FILE || attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_IMAGE || attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_VIDEO) && !Compatibility.runsThirtyThree()) {
if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE) && !Compatibility.runsThirtyThree()) {
return;
} else if (Compatibility.runsThirtyThree() && !hasPermissions(attachmentChoice,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO)) {
return;
}
}
@ -2695,7 +2730,7 @@ public class ConversationFragment extends XmppFragment
binding.conversationsFragment.setBackgroundColor(StyledAttributes.getColor(activity, R.attr.color_background_tertiary));
} else {
File bgfileUri = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + File.separator + APP_DIRECTORY + File.separator + "backgrounds" + File.separator + "bg.jpg");
if(bgfileUri.exists()) {
if(bgfileUri.exists()) { // TODO: Add storage permissions check!
Drawable custom_background = new BitmapDrawable(String.valueOf(bgfileUri));
getActivity().getWindow().setBackgroundDrawable(custom_background);
} else {
@ -2706,7 +2741,13 @@ public class ConversationFragment extends XmppFragment
}
public void startDownloadable(Message message) {
if (!hasPermissions(REQUEST_START_DOWNLOAD, Manifest.permission.WRITE_EXTERNAL_STORAGE) && !hasPermissions(REQUEST_START_DOWNLOAD, Manifest.permission.READ_EXTERNAL_STORAGE)) {
if (!hasPermissions(REQUEST_START_DOWNLOAD, Manifest.permission.WRITE_EXTERNAL_STORAGE) && !hasPermissions(REQUEST_START_DOWNLOAD, Manifest.permission.READ_EXTERNAL_STORAGE) && !Compatibility.runsThirtyThree()) {
this.mPendingDownloadableMessage = message;
return;
} else if (Compatibility.runsThirtyThree() && !hasPermissions(REQUEST_START_DOWNLOAD,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO)) {
this.mPendingDownloadableMessage = message;
return;
}
@ -2813,27 +2854,28 @@ public class ConversationFragment extends XmppFragment
}
private boolean hasPermissions(int requestCode, List<String> permissions) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final List<String> missingPermissions = new ArrayList<>();
for (String permission : permissions) {
if (Config.ONLY_INTERNAL_STORAGE
&& permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
continue;
}
if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
missingPermissions.add(permission);
}
final List<String> missingPermissions = new ArrayList<>();
for (String permission : permissions) {
if (!Compatibility.runsThirtyThree() && Config.ONLY_INTERNAL_STORAGE
&& permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
continue;
} else if (Compatibility.runsThirtyThree() && Config.ONLY_INTERNAL_STORAGE
&& permission.equals(Manifest.permission.READ_MEDIA_AUDIO)
&& permission.equals(Manifest.permission.READ_MEDIA_VIDEO)
&& permission.equals(Manifest.permission.READ_MEDIA_IMAGES)) {
continue;
}
if (missingPermissions.size() == 0) {
return true;
} else {
requestPermissions(
missingPermissions.toArray(new String[0]),
requestCode);
return false;
if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
missingPermissions.add(permission);
}
} else {
}
if (missingPermissions.size() == 0) {
return true;
} else {
requestPermissions(
missingPermissions.toArray(new String[0]),
requestCode);
return false;
}
}
private boolean hasPermissions(int requestCode, String... permissions) {

View file

@ -29,6 +29,7 @@
package eu.siacs.conversations.ui;
import static de.monocles.chat.ui.PermissionsActivity.permissions;
import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
import static eu.siacs.conversations.ui.SettingsActivity.HIDE_MEMORY_WARNING;
import static eu.siacs.conversations.ui.SettingsActivity.MIN_ANDROID_SDK21_SHOWN;
@ -62,6 +63,8 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import de.monocles.chat.DownloadDefaultStickers;
@ -80,6 +83,7 @@ import org.openintents.openpgp.util.OpenPgpApi;
import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
import eu.siacs.conversations.utils.Compatibility;
import io.michaelrocks.libphonenumber.android.NumberParseException;
import java.io.File;
@ -698,6 +702,13 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
setIntent(createLauncherIntent(this));
}
UpdateHelper.showPopup(this);
// SDK >= 33 permissions
if (Compatibility.runsThirtyThree()) {
ActivityCompat.requestPermissions(this,
permissions(),
1);
}
}
@Override
@ -941,6 +952,13 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
this.showLastSeen = preferences.getBoolean("last_activity", getResources().getBoolean(R.bool.last_activity));
super.onStart();
// SDK >= 33 permissions
if (Compatibility.runsThirtyThree()) {
ActivityCompat.requestPermissions(this,
permissions(),
1);
}
}
@Override

View file

@ -7,6 +7,7 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import android.Manifest;
import android.annotation.SuppressLint;
import android.graphics.BitmapFactory;
import android.app.FragmentManager;
@ -1102,6 +1103,9 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference
if (requestCode == REQUEST_DOWNLOAD_STICKERS) {
downloadStickers();
}
if (requestCode == REQUEST_IMPORT_BACKGROUND) {
openFilePicker();
}
} else {
ToastCompat.makeText(
this,

View file

@ -46,6 +46,7 @@ import eu.siacs.conversations.http.NoSSLv3SocketFactory;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.util.CustomTab;
import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.WakeLockHelper;
import me.drakeet.support.toast.ToastCompat;
@ -228,10 +229,16 @@ public class UpdaterActivity extends XmppActivity {
public boolean isStoragePermissionGranted() {
if (Build.VERSION.SDK_INT >= 23) {
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
if (!Compatibility.runsThirtyThree() && checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
return true;
} else if (Compatibility.runsThirtyThree() && checkSelfPermission(Manifest.permission.READ_MEDIA_IMAGES) == PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.READ_MEDIA_AUDIO) == PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.READ_MEDIA_VIDEO) == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
if (Compatibility.runsThirtyThree()) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.READ_MEDIA_AUDIO}, 1);
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
}
return false;
}
} else { //permission is automatically granted on sdk<23 upon installation

View file

@ -34,6 +34,7 @@ import eu.siacs.conversations.databinding.ActivityUriHandlerBinding;
import eu.siacs.conversations.http.HttpConnectionManager;
import eu.siacs.conversations.persistance.DatabaseBackend;
import eu.siacs.conversations.services.QuickConversationsService;
import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.ProvisioningUtils;
import eu.siacs.conversations.utils.SignupUtils;
import eu.siacs.conversations.utils.XmppUri;
@ -387,13 +388,12 @@ public class UriHandlerActivity extends AppCompatActivity {
}
protected boolean hasStoragePermission(int requestCode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode);
return false;
} else {
return true;
}
if (!Compatibility.runsThirtyThree() && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode);
return false;
} else if (Compatibility.runsThirtyThree() && checkSelfPermission(Manifest.permission.READ_MEDIA_IMAGES) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.READ_MEDIA_AUDIO) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.READ_MEDIA_VIDEO) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_AUDIO, Manifest.permission.READ_MEDIA_VIDEO}, requestCode);
return false;
} else {
return true;
}

View file

@ -1,5 +1,6 @@
package eu.siacs.conversations.ui;
import static de.monocles.chat.ui.PermissionsActivity.permissions;
import static eu.siacs.conversations.Config.DISALLOW_REGISTRATION_IN_UI;
import static eu.siacs.conversations.utils.PermissionUtils.allGranted;
import static eu.siacs.conversations.utils.PermissionUtils.readGranted;
@ -20,6 +21,7 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.databinding.DataBindingUtil;
import java.util.Arrays;
@ -96,6 +98,13 @@ public class WelcomeActivity extends XmppActivity implements XmppConnectionServi
recreate();
}
new InstallReferrerUtils(this);
// SDK >= 33 permissions
if (Compatibility.runsThirtyThree()) {
ActivityCompat.requestPermissions(this,
permissions(),
1);
}
}
@Override
@ -171,6 +180,13 @@ public class WelcomeActivity extends XmppActivity implements XmppConnectionServi
addInviteUri(intent);
startActivity(intent);
});
// SDK >= 33 permissions
if (Compatibility.runsThirtyThree()) {
ActivityCompat.requestPermissions(this,
permissions(),
1);
}
}
public void addInviteUri(Intent to) {
@ -254,8 +270,10 @@ public class WelcomeActivity extends XmppActivity implements XmppConnectionServi
// startActivity(new Intent(this, ImportBackupActivity.class));
break;
}
} else if (Arrays.asList(permissions).contains(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
} else if (!Compatibility.runsThirtyThree() && Arrays.asList(permissions).contains(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
ToastCompat.makeText(this, R.string.no_storage_permission, ToastCompat.LENGTH_SHORT).show();
} else if (Compatibility.runsThirtyThree() && Arrays.asList(permissions).contains(Manifest.permission.READ_MEDIA_IMAGES) && Arrays.asList(permissions).contains(Manifest.permission.READ_MEDIA_VIDEO) && Arrays.asList(permissions).contains(Manifest.permission.READ_MEDIA_AUDIO)) {
ToastCompat.makeText(this, R.string.no_media_permission, ToastCompat.LENGTH_SHORT).show();
}
}
if (readGranted(grantResults, permissions)) {

View file

@ -1,5 +1,6 @@
package eu.siacs.conversations.ui;
import static de.monocles.chat.ui.PermissionsActivity.permissions;
import static eu.siacs.conversations.ui.SettingsActivity.USE_INTERNAL_UPDATER;
import android.graphics.drawable.AnimatedImageDrawable;
@ -63,6 +64,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
@ -509,6 +511,13 @@ public abstract class XmppActivity extends ActionBarActivity {
mColorDefaultButtonText = ContextCompat.getColor(this, R.color.realwhite);
mColorWhite = ContextCompat.getColor(this, R.color.white70);
this.mUsingEnterKey = usingEnterKey();
// SDK >= 33 permissions
if (Compatibility.runsThirtyThree()) {
ActivityCompat.requestPermissions(this,
permissions(),
1);
}
}
protected boolean isCameraFeatureAvailable() {
@ -962,40 +971,31 @@ public abstract class XmppActivity extends ActionBarActivity {
}
protected boolean hasStoragePermission(int requestCode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (Compatibility.runsThirtyThree() && checkSelfPermission(Manifest.permission.READ_MEDIA_VIDEO) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.READ_MEDIA_AUDIO) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.READ_MEDIA_IMAGES) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.READ_MEDIA_AUDIO, Manifest.permission.READ_MEDIA_IMAGES}, requestCode);
return false;
} else if (!Compatibility.runsThirtyThree() && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, requestCode);
return false;
} else {
return true;
}
} else {
return true;
}
}
public boolean hasMicPermission(int requestCode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, requestCode);
return false;
} else {
return true;
}
if (checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, requestCode);
return false;
} else {
return true;
}
}
public boolean hasLocationPermission(int requestCode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, requestCode);
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, requestCode);
return false;
} else {
return true;
}
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, requestCode);
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, requestCode);
return false;
} else {
return true;
}

View file

@ -3,6 +3,7 @@ package eu.siacs.conversations.ui.adapter;
import de.monocles.chat.BobTransfer;
import de.monocles.chat.Util;
import eu.siacs.conversations.ui.widget.ClickableMovementMethod;
import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.xml.Element;
import io.ipfs.cid.Cid;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
@ -1904,7 +1905,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
public void openDownloadable(Message message) {
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (Compatibility.runsThirtyThree() && ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_MEDIA_IMAGES) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_MEDIA_AUDIO) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_MEDIA_VIDEO) != PackageManager.PERMISSION_GRANTED) {
ConversationFragment.registerPendingMessage(activity, message);
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_AUDIO, Manifest.permission.READ_MEDIA_VIDEO}, ConversationsActivity.REQUEST_OPEN_MESSAGE);
return;
} else if (!Compatibility.runsThirtyThree() && ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ConversationFragment.registerPendingMessage(activity, message);
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, ConversationsActivity.REQUEST_OPEN_MESSAGE);
return;

View file

@ -109,7 +109,7 @@ public class CallManager {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final List<String> missingPermissions = new ArrayList<>();
for (String permission : permissions) {
if (Config.ONLY_INTERNAL_STORAGE && permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE) && permission.equals(Manifest.permission.READ_EXTERNAL_STORAGE)) {
if (Config.ONLY_INTERNAL_STORAGE && permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE) && permission.equals(Manifest.permission.READ_EXTERNAL_STORAGE) || Config.ONLY_INTERNAL_STORAGE && permission.equals(Manifest.permission.READ_MEDIA_IMAGES) && permission.equals(Manifest.permission.READ_MEDIA_AUDIO) && permission.equals(Manifest.permission.READ_MEDIA_VIDEO)) {
continue;
}
if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {

View file

@ -2,6 +2,7 @@ package eu.siacs.conversations.utils;
import static eu.siacs.conversations.services.EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
@ -41,10 +42,17 @@ public class Compatibility {
Collections.singletonList("message_notification_settings");
public static boolean hasStoragePermission(Context context) {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M
|| ContextCompat.checkSelfPermission(
context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED;
if (Compatibility.runsThirtyThree()) { return ContextCompat.checkSelfPermission(
context, Manifest.permission.READ_MEDIA_IMAGES)
== PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(
context, Manifest.permission.READ_MEDIA_AUDIO)
== PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(
context, Manifest.permission.READ_MEDIA_VIDEO)
== PackageManager.PERMISSION_GRANTED; } else { return
ContextCompat.checkSelfPermission(
context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED;
}
}
public static boolean s() {

View file

@ -33,7 +33,10 @@ public class PermissionUtils {
public static boolean readGranted(int[] grantResults, String[] permission) {
for (int i = 0; i < grantResults.length; ++i) {
if (Manifest.permission.READ_EXTERNAL_STORAGE.equals(permission[i])) {
if (!Compatibility.runsThirtyThree() && Manifest.permission.READ_EXTERNAL_STORAGE.equals(permission[i])) {
return grantResults[i] == PackageManager.PERMISSION_GRANTED;
} else if (Compatibility.runsThirtyThree() && Manifest.permission.READ_MEDIA_IMAGES.equals(permission[i]) && Manifest.permission.READ_MEDIA_AUDIO.equals(permission[i]) && Manifest.permission.READ_MEDIA_VIDEO.equals(permission[i])) {
return grantResults[i] == PackageManager.PERMISSION_GRANTED;
}
}

View file

@ -1342,4 +1342,5 @@
<string name="notifications_disabled">Notifications disabled. Please activate them in your android settings.</string>
<string name="pref_show_less_avatars">Show less avatars in chats</string>
<string name="pref_show_less_avatars_summary">Only necessary avatars in conversations will be shown</string>
<string name="no_media_permission">No media storage permission</string>
</resources>