mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 04:25:18 +00:00
Restored camera permission check for avatar change action.
This commit is contained in:
parent
a1778c9503
commit
e352869aeb
@ -4,23 +4,20 @@ import android.Manifest;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.core.app.ShareCompat;
|
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import com.theartofdev.edmodo.cropper.CropImage;
|
import com.theartofdev.edmodo.cropper.CropImage;
|
||||||
import com.theartofdev.edmodo.cropper.CropImageView;
|
import com.theartofdev.edmodo.cropper.CropImageView;
|
||||||
|
|
||||||
import network.loki.messenger.R;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
|
||||||
import org.thoughtcrime.securesms.util.ExternalStorageUtil;
|
import org.thoughtcrime.securesms.util.ExternalStorageUtil;
|
||||||
import org.thoughtcrime.securesms.util.FileProviderUtil;
|
import org.thoughtcrime.securesms.util.FileProviderUtil;
|
||||||
import org.thoughtcrime.securesms.util.IntentUtils;
|
import org.thoughtcrime.securesms.util.IntentUtils;
|
||||||
@ -30,6 +27,8 @@ import java.io.IOException;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import network.loki.messenger.R;
|
||||||
|
|
||||||
import static android.provider.MediaStore.EXTRA_OUTPUT;
|
import static android.provider.MediaStore.EXTRA_OUTPUT;
|
||||||
|
|
||||||
public final class AvatarSelection {
|
public final class AvatarSelection {
|
||||||
@ -69,7 +68,9 @@ public final class AvatarSelection {
|
|||||||
*/
|
*/
|
||||||
public static File startAvatarSelection(Activity activity, boolean includeClear, boolean attemptToIncludeCamera) {
|
public static File startAvatarSelection(Activity activity, boolean includeClear, boolean attemptToIncludeCamera) {
|
||||||
File captureFile = null;
|
File captureFile = null;
|
||||||
if (attemptToIncludeCamera) {
|
boolean hasCameraPermission = ContextCompat
|
||||||
|
.checkSelfPermission(activity, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
if (attemptToIncludeCamera && hasCameraPermission) {
|
||||||
try {
|
try {
|
||||||
captureFile = File.createTempFile("avatar-capture", ".jpg", ExternalStorageUtil.getImageDir(activity));
|
captureFile = File.createTempFile("avatar-capture", ".jpg", ExternalStorageUtil.getImageDir(activity));
|
||||||
} catch (IOException | NoExternalStorageException e) {
|
} catch (IOException | NoExternalStorageException e) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.thoughtcrime.securesms.loki.activities
|
package org.thoughtcrime.securesms.loki.activities
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
@ -38,6 +39,7 @@ import org.thoughtcrime.securesms.loki.utilities.fadeOut
|
|||||||
import org.thoughtcrime.securesms.loki.utilities.push
|
import org.thoughtcrime.securesms.loki.utilities.push
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp
|
import org.thoughtcrime.securesms.mms.GlideApp
|
||||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||||
|
import org.thoughtcrime.securesms.permissions.Permissions
|
||||||
import org.thoughtcrime.securesms.profiles.AvatarHelper
|
import org.thoughtcrime.securesms.profiles.AvatarHelper
|
||||||
import org.thoughtcrime.securesms.profiles.ProfileMediaConstraints
|
import org.thoughtcrime.securesms.profiles.ProfileMediaConstraints
|
||||||
import org.thoughtcrime.securesms.util.BitmapDecodingException
|
import org.thoughtcrime.securesms.util.BitmapDecodingException
|
||||||
@ -153,6 +155,11 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
|
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults)
|
||||||
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Updating
|
// region Updating
|
||||||
@ -246,8 +253,14 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showEditProfilePictureUI() {
|
private fun showEditProfilePictureUI() {
|
||||||
|
// Ask for an optional camera permission.
|
||||||
|
Permissions.with(this)
|
||||||
|
.request(Manifest.permission.CAMERA)
|
||||||
|
.onAnyResult {
|
||||||
tempFile = AvatarSelection.startAvatarSelection(this, false, true)
|
tempFile = AvatarSelection.startAvatarSelection(this, false, true)
|
||||||
}
|
}
|
||||||
|
.execute()
|
||||||
|
}
|
||||||
|
|
||||||
private fun copyPublicKey() {
|
private fun copyPublicKey() {
|
||||||
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
|
@ -46,6 +46,7 @@ import org.thoughtcrime.securesms.components.RemovableEditableMediaView;
|
|||||||
import org.thoughtcrime.securesms.components.ThumbnailView;
|
import org.thoughtcrime.securesms.components.ThumbnailView;
|
||||||
import org.thoughtcrime.securesms.components.location.SignalMapView;
|
import org.thoughtcrime.securesms.components.location.SignalMapView;
|
||||||
import org.thoughtcrime.securesms.components.location.SignalPlace;
|
import org.thoughtcrime.securesms.components.location.SignalPlace;
|
||||||
|
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
||||||
import org.thoughtcrime.securesms.giph.ui.GiphyActivity;
|
import org.thoughtcrime.securesms.giph.ui.GiphyActivity;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.mediasend.MediaSendActivity;
|
import org.thoughtcrime.securesms.mediasend.MediaSendActivity;
|
||||||
@ -54,6 +55,8 @@ import org.thoughtcrime.securesms.providers.BlobProvider;
|
|||||||
import org.thoughtcrime.securesms.providers.DeprecatedPersistentBlobProvider;
|
import org.thoughtcrime.securesms.providers.DeprecatedPersistentBlobProvider;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||||
|
import org.thoughtcrime.securesms.util.ExternalStorageUtil;
|
||||||
|
import org.thoughtcrime.securesms.util.FileProviderUtil;
|
||||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
@ -65,6 +68,7 @@ import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
|||||||
import org.thoughtcrime.securesms.util.views.Stub;
|
import org.thoughtcrime.securesms.util.views.Stub;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -73,6 +77,8 @@ import java.util.concurrent.ExecutionException;
|
|||||||
|
|
||||||
import network.loki.messenger.R;
|
import network.loki.messenger.R;
|
||||||
|
|
||||||
|
import static android.provider.MediaStore.EXTRA_OUTPUT;
|
||||||
|
|
||||||
|
|
||||||
public class AttachmentManager {
|
public class AttachmentManager {
|
||||||
|
|
||||||
@ -112,7 +118,6 @@ public class AttachmentManager {
|
|||||||
thumbnail.setOnClickListener(new ThumbnailClickListener());
|
thumbnail.setOnClickListener(new ThumbnailClickListener());
|
||||||
documentView.getBackground().setColorFilter(ThemeUtil.getThemedColor(context, R.attr.conversation_item_bubble_background), PorterDuff.Mode.MULTIPLY);
|
documentView.getBackground().setColorFilter(ThemeUtil.getThemedColor(context, R.attr.conversation_item_bubble_background), PorterDuff.Mode.MULTIPLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear(@NonNull GlideRequests glideRequests, boolean animate) {
|
public void clear(@NonNull GlideRequests glideRequests, boolean animate) {
|
||||||
@ -443,17 +448,21 @@ public class AttachmentManager {
|
|||||||
.withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_camera_permission_in_order_to_take_photos_but_it_has_been_permanently_denied))
|
.withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_camera_permission_in_order_to_take_photos_but_it_has_been_permanently_denied))
|
||||||
.onAllGranted(() -> {
|
.onAllGranted(() -> {
|
||||||
try {
|
try {
|
||||||
|
File captureFile = File.createTempFile(
|
||||||
|
"conversation-capture",
|
||||||
|
".jpg",
|
||||||
|
ExternalStorageUtil.getImageDir(activity));
|
||||||
|
Uri captureUri = FileProviderUtil.getUriFor(context, captureFile);
|
||||||
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
|
captureIntent.putExtra(EXTRA_OUTPUT, captureUri);
|
||||||
|
captureIntent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||||
if (captureIntent.resolveActivity(activity.getPackageManager()) != null) {
|
if (captureIntent.resolveActivity(activity.getPackageManager()) != null) {
|
||||||
if (captureUri == null) {
|
|
||||||
captureUri = DeprecatedPersistentBlobProvider.getInstance(context).createForExternal(context, MediaUtil.IMAGE_JPEG);
|
|
||||||
}
|
|
||||||
Log.d(TAG, "captureUri path is " + captureUri.getPath());
|
Log.d(TAG, "captureUri path is " + captureUri.getPath());
|
||||||
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, captureUri);
|
this.captureUri = captureUri;
|
||||||
activity.startActivityForResult(captureIntent, requestCode);
|
activity.startActivityForResult(captureIntent, requestCode);
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException | NoExternalStorageException e) {
|
||||||
Log.w(TAG, ioe);
|
throw new RuntimeException("Error creating image capture intent.", e);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
|
@ -171,7 +171,7 @@ public class Permissions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (String permission : requestedPermissions) {
|
for (String permission : requestedPermissions) {
|
||||||
request.addMapping(permission, permissionObject.shouldShouldPermissionRationale(permission));
|
request.addMapping(permission, permissionObject.shouldShowPermissionRationale(permission));
|
||||||
}
|
}
|
||||||
|
|
||||||
permissionObject.requestPermissions(requestCode, requestedPermissions);
|
permissionObject.requestPermissions(requestCode, requestedPermissions);
|
||||||
@ -240,7 +240,7 @@ public class Permissions {
|
|||||||
|
|
||||||
for (int i=0;i<permissions.length;i++) {
|
for (int i=0;i<permissions.length;i++) {
|
||||||
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
|
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
|
||||||
shouldShowRationaleDialog[i] = context.shouldShouldPermissionRationale(permissions[i]);
|
shouldShowRationaleDialog[i] = context.shouldShowPermissionRationale(permissions[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +259,7 @@ public class Permissions {
|
|||||||
private abstract static class PermissionObject {
|
private abstract static class PermissionObject {
|
||||||
|
|
||||||
abstract Context getContext();
|
abstract Context getContext();
|
||||||
abstract boolean shouldShouldPermissionRationale(String permission);
|
abstract boolean shouldShowPermissionRationale(String permission);
|
||||||
abstract boolean hasAll(String... permissions);
|
abstract boolean hasAll(String... permissions);
|
||||||
abstract void requestPermissions(int requestCode, String... permissions);
|
abstract void requestPermissions(int requestCode, String... permissions);
|
||||||
|
|
||||||
@ -287,7 +287,7 @@ public class Permissions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldShouldPermissionRationale(String permission) {
|
public boolean shouldShowPermissionRationale(String permission) {
|
||||||
return ActivityCompat.shouldShowRequestPermissionRationale(activity, permission);
|
return ActivityCompat.shouldShowRequestPermissionRationale(activity, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +316,7 @@ public class Permissions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldShouldPermissionRationale(String permission) {
|
public boolean shouldShowPermissionRationale(String permission) {
|
||||||
return fragment.shouldShowRequestPermissionRationale(permission);
|
return fragment.shouldShowRequestPermissionRationale(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user