Skip to content

Commit

Permalink
Enable the camera only if permission is granted
Browse files Browse the repository at this point in the history
  • Loading branch information
dautovicharis committed Dec 5, 2023
1 parent 1222c30 commit 804d2c2
Showing 1 changed file with 8 additions and 1 deletion.
@@ -1,7 +1,9 @@
package org.thoughtcrime.securesms.mediasend;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.net.Uri;
import android.os.Bundle;
Expand All @@ -12,6 +14,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

Expand Down Expand Up @@ -214,6 +217,10 @@ private boolean isCameraFirst() {
return !isGalleryFirst();
}

private boolean hasCameraPermission() {
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
}

private void handleSave() {
ImageEditorFragment fragment = (ImageEditorFragment) getSupportFragmentManager().findFragmentByTag(IMAGE_EDITOR);
if (fragment == null) {
Expand Down Expand Up @@ -284,6 +291,6 @@ public void onToolbarNavigationClicked() {

@Override
public boolean isCameraEnabled() {
return true;
return hasCameraPermission();
}
}

0 comments on commit 804d2c2

Please sign in to comment.