Treat Permissions "not now" as a denial

Fixes #7713
This commit is contained in:
Moxie Marlinspike 2018-04-23 18:28:57 -07:00 committed by Greyson Parrelli
parent a5047cb17b
commit 35d158cfee

View File

@ -28,6 +28,7 @@ import org.thoughtcrime.securesms.util.ServiceUtil;
import java.lang.ref.WeakReference;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -156,7 +157,7 @@ public class Permissions {
private void executePermissionsRequestWithRationale(PermissionsRequest request) {
RationaleDialog.createFor(permissionObject.getContext(), rationaleDialogMessage, rationalDialogHeader)
.setPositiveButton(R.string.Permissions_continue, (dialog, which) -> executePermissionsRequest(request))
.setNegativeButton(R.string.Permissions_not_now, null)
.setNegativeButton(R.string.Permissions_not_now, (dialog, which) -> executeNoPermissionsRequest(request))
.show()
.getWindow()
.setLayout((int)(permissionObject.getWindowWidth() * .75), ViewGroup.LayoutParams.WRAP_CONTENT);
@ -176,6 +177,19 @@ public class Permissions {
permissionObject.requestPermissions(requestCode, requestedPermissions);
}
private void executeNoPermissionsRequest(PermissionsRequest request) {
for (String permission : requestedPermissions) {
request.addMapping(permission, true);
}
String[] permissions = filterNotGranted(permissionObject.getContext(), requestedPermissions);
int[] grantResults = Stream.of(permissions).mapToInt(permission -> PackageManager.PERMISSION_DENIED).toArray();
boolean[] showDialog = new boolean[permissions.length];
Arrays.fill(showDialog, true);
request.onResult(permissions, grantResults, showDialog);
}
}
private static void requestPermissions(@NonNull Activity activity, int requestCode, String... permissions) {