diff options
author | Christian Schneppe <christian.schneppe@pix-art.de> | 2019-12-07 21:09:57 +0100 |
---|---|---|
committer | Christian Schneppe <christian.schneppe@pix-art.de> | 2019-12-07 21:11:56 +0100 |
commit | 7ee4de1a277d8935dc8c6a378689038911644d32 (patch) | |
tree | 579390c576d57b6a70267d2014dca4631ec154bb /src/main/java/de/pixart/messenger/ui | |
parent | a80432f67110053ef6c638ea64a55ee9390f4951 (diff) |
add missing permission requests for Android P
possibly fixes #410
Diffstat (limited to '')
8 files changed, 48 insertions, 45 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index fb79da967..8abc19f88 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -135,7 +135,7 @@ import static de.pixart.messenger.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION import static de.pixart.messenger.ui.util.SoftKeyboardUtils.hideSoftKeyboard; import static de.pixart.messenger.utils.PermissionUtils.allGranted; import static de.pixart.messenger.utils.PermissionUtils.getFirstDenied; -import static de.pixart.messenger.utils.PermissionUtils.writeGranted; +import static de.pixart.messenger.utils.PermissionUtils.readGranted; import static de.pixart.messenger.xmpp.Patches.ENCRYPTION_EXCEPTIONS; public class ConversationFragment extends XmppFragment implements EditMessage.KeyboardListener, MessageAdapter.OnContactPictureLongClicked, MessageAdapter.OnContactPictureClicked { @@ -338,7 +338,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke return false; } } - if (hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + if (hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.WRITE_EXTERNAL_STORAGE) && hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.READ_EXTERNAL_STORAGE)) { attachEditorContentToConversation(inputContentInfo.getContentUri()); } else { mPendingEditorContent = inputContentInfo.getContentUri(); @@ -1014,7 +1014,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } private void commitAttachments() { - if (!hasPermissions(REQUEST_COMMIT_ATTACHMENTS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + if (!hasPermissions(REQUEST_COMMIT_ATTACHMENTS, Manifest.permission.WRITE_EXTERNAL_STORAGE) && hasPermissions(REQUEST_COMMIT_ATTACHMENTS, Manifest.permission.READ_EXTERNAL_STORAGE)) { return; } if (conversation.getNextEncryption() == Message.ENCRYPTION_AXOLOTL && trustKeysIfNeeded(REQUEST_TRUST_KEYS_ATTACHMENTS)) { @@ -1555,11 +1555,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke public void attachFile(final int attachmentChoice) { if (attachmentChoice == ATTACHMENT_CHOICE_RECORD_VOICE) { - if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO)) { + if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO)) { return; } } else if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO || attachmentChoice == ATTACHMENT_CHOICE_RECORD_VIDEO) { - if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)) { + if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA)) { return; } } else if (attachmentChoice == ATTACHMENT_CHOICE_LOCATION) { @@ -1567,7 +1567,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke 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)) { + if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)) { return; } } @@ -1664,7 +1664,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke Toast.makeText(getActivity(), res, Toast.LENGTH_SHORT).show(); } } - if (writeGranted(grantResults, permissions)) { + if (readGranted(grantResults, permissions)) { if (activity != null && activity.xmppConnectionService != null) { activity.xmppConnectionService.restartFileObserver(); } @@ -1673,7 +1673,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } public void startDownloadable(Message message) { - if (!hasPermissions(REQUEST_START_DOWNLOAD, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + if (!hasPermissions(REQUEST_START_DOWNLOAD, Manifest.permission.WRITE_EXTERNAL_STORAGE) && !hasPermissions(REQUEST_START_DOWNLOAD, Manifest.permission.READ_EXTERNAL_STORAGE)) { this.mPendingDownloadableMessage = message; return; } @@ -1728,7 +1728,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke 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)) { + if (Config.ONLY_INTERNAL_STORAGE && permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE) && permission.equals(Manifest.permission.READ_EXTERNAL_STORAGE)) { continue; } if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index f32ecf14f..fc669171f 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -83,7 +83,7 @@ import de.pixart.messenger.xmpp.pep.Avatar; import rocks.xmpp.addr.Jid; import static de.pixart.messenger.utils.PermissionUtils.allGranted; -import static de.pixart.messenger.utils.PermissionUtils.writeGranted; +import static de.pixart.messenger.utils.PermissionUtils.readGranted; public class EditAccountActivity extends OmemoActivity implements OnAccountUpdate, OnUpdateBlocklist, OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched { @@ -1576,7 +1576,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show(); } } - if (writeGranted(grantResults, permissions)) { + if (readGranted(grantResults, permissions)) { if (xmppConnectionService != null) { xmppConnectionService.restartFileObserver(); } diff --git a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java index 8d39df934..f464cc6ae 100644 --- a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java @@ -5,9 +5,6 @@ import android.content.Intent; import android.os.Bundle; import android.security.KeyChain; import android.security.KeyChainAliasCallback; -import androidx.annotation.NonNull; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AlertDialog; import android.util.Pair; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -18,6 +15,10 @@ import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.ListView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AlertDialog; + import org.openintents.openpgp.util.OpenPgpApi; import java.util.ArrayList; @@ -35,7 +36,7 @@ import de.pixart.messenger.xmpp.XmppConnection; import rocks.xmpp.addr.Jid; import static de.pixart.messenger.utils.PermissionUtils.allGranted; -import static de.pixart.messenger.utils.PermissionUtils.writeGranted; +import static de.pixart.messenger.utils.PermissionUtils.readGranted; public class ManageAccountActivity extends XmppActivity implements OnAccountUpdate, KeyChainAliasCallback, XmppConnectionService.OnAccountCreated, AccountAdapter.OnTglAccountState { @@ -222,7 +223,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show(); } } - if (writeGranted(grantResults, permissions)) { + if (readGranted(grantResults, permissions)) { if (xmppConnectionService != null) { xmppConnectionService.restartFileObserver(); } diff --git a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java index 62442830f..35cdc1e18 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java @@ -26,17 +26,28 @@ import rocks.xmpp.addr.Jid; public class ShareWithActivity extends XmppActivity implements XmppConnectionService.OnConversationUpdate { private static final int REQUEST_STORAGE_PERMISSION = 0x733f32; - private static final int REQUEST_START_NEW_CONVERSATION = 0x0501; private Conversation mPendingConversation = null; - private Share share; - private ConversationAdapter mAdapter; - private List<Conversation> mConversations = new ArrayList<>(); @Override public void onConversationUpdate() { refreshUi(); } + private class Share { + ArrayList<Uri> uris = new ArrayList<>(); + public String account; + public String contact; + public String text; + public boolean asQuote = false; + } + + private Share share; + + private static final int REQUEST_START_NEW_CONVERSATION = 0x0501; + private ConversationAdapter mAdapter; + private List<Conversation> mConversations = new ArrayList<>(); + + protected void onActivityResult(int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_START_NEW_CONVERSATION @@ -53,7 +64,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } @Override - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { if (grantResults.length > 0) if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (requestCode == REQUEST_STORAGE_PERMISSION) { @@ -186,7 +197,6 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer return; } } - startActivity(intent); finish(); } @@ -195,12 +205,4 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer xmppConnectionService.populateWithOrderedConversations(mConversations, this.share != null && this.share.uris.size() == 0, false); mAdapter.notifyDataSetChanged(); } - - private class Share { - ArrayList<Uri> uris = new ArrayList<>(); - public String account; - public String contact; - public String text; - public boolean asQuote = false; - } }
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java index 05fd94188..6b5054968 100644 --- a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java +++ b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java @@ -13,12 +13,13 @@ import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.PowerManager; -import androidx.core.app.ActivityCompat; -import androidx.appcompat.app.AlertDialog; import android.util.Log; import android.widget.TextView; import android.widget.Toast; +import androidx.appcompat.app.AlertDialog; +import androidx.core.app.ActivityCompat; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -228,12 +229,10 @@ 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) { + if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { return true; } else { - - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); + 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 diff --git a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java index d0257e44b..c75b1bc4e 100644 --- a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java +++ b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java @@ -3,20 +3,21 @@ package de.pixart.messenger.ui; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; + import de.pixart.messenger.R; import de.pixart.messenger.ui.util.IntroHelper; import static de.pixart.messenger.Config.DISALLOW_REGISTRATION_IN_UI; import static de.pixart.messenger.utils.PermissionUtils.allGranted; -import static de.pixart.messenger.utils.PermissionUtils.writeGranted; +import static de.pixart.messenger.utils.PermissionUtils.readGranted; public class WelcomeActivity extends XmppActivity { @@ -119,7 +120,7 @@ public class WelcomeActivity extends XmppActivity { Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show(); } } - if (writeGranted(grantResults, permissions)) { + if (readGranted(grantResults, permissions)) { if (xmppConnectionService != null) { xmppConnectionService.restartFileObserver(); } diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index 23b2120e3..cf23b0e7e 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -799,8 +799,8 @@ 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) { - requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode); + if (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; diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index ec5693dac..19bfb7463 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -1247,9 +1247,9 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } public void openDownloadable(Message message) { - if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + if (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}, ConversationsActivity.REQUEST_OPEN_MESSAGE); + ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, ConversationsActivity.REQUEST_OPEN_MESSAGE); return; } final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); |