always show contact permission explain dialog on Quicksy

Until now Conversations and Quicksy would only disply the dialog that explains
why we want contact read permissions after the user rejected the request once

(following Android design guidelines and `shouldShowRequestPermissionRationale()`)

However for PlayStore policy this is no longer enough and the app needs to
explain and ask for consent before starting to upload the data.

This commit now displays the explain dialog immediately before asking for the
first time.
This commit is contained in:
Daniel Gultsch 2021-04-24 08:20:27 +02:00
parent f9b292fd6a
commit ec061bedc1

View file

@ -39,6 +39,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.databinding.DataBindingUtil;
@ -731,7 +732,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
if (mRequestedContactsPermission.compareAndSet(false, true)) {
if (shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
if (QuickConversationsService.isQuicksy() || shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final AtomicBoolean requestPermission = new AtomicBoolean(false);
builder.setTitle(R.string.sync_with_contacts);
@ -740,20 +741,26 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
} else {
builder.setMessage(getString(R.string.sync_with_contacts_long, getString(R.string.app_name)));
}
builder.setPositiveButton(R.string.next, (dialog, which) -> {
@StringRes int confirmButtonText;
if (QuickConversationsService.isConversations()) {
confirmButtonText = R.string.next;
} else {
confirmButtonText = R.string.confirm;
}
builder.setPositiveButton(confirmButtonText, (dialog, which) -> {
if (requestPermission.compareAndSet(false, true)) {
requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
}
});
builder.setOnDismissListener(dialog -> {
if (requestPermission.compareAndSet(false, true)) {
if (QuickConversationsService.isConversations() && requestPermission.compareAndSet(false, true)) {
requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
}
});
builder.setCancelable(false);
builder.setCancelable(QuickConversationsService.isQuicksy());
final AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.setCanceledOnTouchOutside(QuickConversationsService.isQuicksy());
dialog.setOnShowListener(dialogInterface -> {
final TextView tv = dialog.findViewById(android.R.id.message);
if (tv != null) {