Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/image_picker/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package="io.flutter.plugins.imagepicker">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>

<application>
<provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ public class ImagePickerDelegate
@VisibleForTesting static final int REQUEST_CODE_CHOOSE_IMAGE_FROM_GALLERY = 2342;
@VisibleForTesting static final int REQUEST_CODE_TAKE_IMAGE_WITH_CAMERA = 2343;
@VisibleForTesting static final int REQUEST_EXTERNAL_IMAGE_STORAGE_PERMISSION = 2344;
@VisibleForTesting static final int REQUEST_CAMERA_IMAGE_PERMISSION = 2345;
@VisibleForTesting static final int REQUEST_CODE_CHOOSE_VIDEO_FROM_GALLERY = 2352;
@VisibleForTesting static final int REQUEST_CODE_TAKE_VIDEO_WITH_CAMERA = 2353;
@VisibleForTesting static final int REQUEST_EXTERNAL_VIDEO_STORAGE_PERMISSION = 2354;
@VisibleForTesting static final int REQUEST_CAMERA_VIDEO_PERMISSION = 2355;

@VisibleForTesting final String fileProviderName;

Expand Down Expand Up @@ -212,12 +210,6 @@ public void takeVideoWithCamera(MethodCall methodCall, MethodChannel.Result resu
return;
}

if (!permissionManager.isPermissionGranted(Manifest.permission.CAMERA)) {
permissionManager.askForPermission(
Manifest.permission.CAMERA, REQUEST_CAMERA_VIDEO_PERMISSION);
return;
}

launchTakeVideoWithCameraIntent();
}

Expand Down Expand Up @@ -268,12 +260,6 @@ public void takeImageWithCamera(MethodCall methodCall, MethodChannel.Result resu
return;
}

if (!permissionManager.isPermissionGranted(Manifest.permission.CAMERA)) {
permissionManager.askForPermission(
Manifest.permission.CAMERA, REQUEST_CAMERA_IMAGE_PERMISSION);
return;
}

launchTakeImageWithCameraIntent();
}

Expand Down Expand Up @@ -347,16 +333,6 @@ public boolean onRequestPermissionsResult(
launchPickVideoFromGalleryIntent();
}
break;
case REQUEST_CAMERA_IMAGE_PERMISSION:
if (permissionGranted) {
launchTakeImageWithCameraIntent();
}
break;
case REQUEST_CAMERA_VIDEO_PERMISSION:
if (permissionGranted) {
launchTakeVideoWithCameraIntent();
}
break;
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,46 +128,6 @@ public void takeImageWithCamera_WhenPendingResultExists_FinishesWithAlreadyActiv
verifyNoMoreInteractions(mockResult);
}

@Test
public void takeImageWithCamera_WhenHasNoCameraPermission_RequestsForPermission() {
when(mockPermissionManager.isPermissionGranted(Manifest.permission.CAMERA)).thenReturn(false);

ImagePickerDelegate delegate = createDelegate();
delegate.takeImageWithCamera(mockMethodCall, mockResult);

verify(mockPermissionManager)
.askForPermission(
Manifest.permission.CAMERA, ImagePickerDelegate.REQUEST_CAMERA_IMAGE_PERMISSION);
}

@Test
public void
takeImageWithCamera_WhenHasCameraPermission_AndAnActivityCanHandleCameraIntent_LaunchesTakeWithCameraIntent() {
when(mockPermissionManager.isPermissionGranted(Manifest.permission.CAMERA)).thenReturn(true);
when(mockIntentResolver.resolveActivity(any(Intent.class))).thenReturn(true);

ImagePickerDelegate delegate = createDelegate();
delegate.takeImageWithCamera(mockMethodCall, mockResult);

verify(mockActivity)
.startActivityForResult(
any(Intent.class), eq(ImagePickerDelegate.REQUEST_CODE_TAKE_IMAGE_WITH_CAMERA));
}

@Test
public void
takeImageWithCamera_WhenHasCameraPermission_AndNoActivityToHandleCameraIntent_FinishesWithNoCamerasAvailableError() {
when(mockPermissionManager.isPermissionGranted(Manifest.permission.CAMERA)).thenReturn(true);
when(mockIntentResolver.resolveActivity(any(Intent.class))).thenReturn(false);

ImagePickerDelegate delegate = createDelegate();
delegate.takeImageWithCamera(mockMethodCall, mockResult);

verify(mockResult)
.error("no_available_camera", "No cameras available for taking pictures.", null);
verifyNoMoreInteractions(mockResult);
}

@Test
public void
onRequestPermissionsResult_WhenReadExternalStoragePermissionDenied_FinishesWithNull() {
Expand Down Expand Up @@ -212,51 +172,6 @@ public void takeImageWithCamera_WhenHasNoCameraPermission_RequestsForPermission(
any(Intent.class), eq(ImagePickerDelegate.REQUEST_CODE_CHOOSE_VIDEO_FROM_GALLERY));
}

@Test
public void onRequestPermissionsResult_WhenCameraPermissionDenied_FinishesWithNull() {
ImagePickerDelegate delegate = createDelegateWithPendingResultAndMethodCall();

delegate.onRequestPermissionsResult(
ImagePickerDelegate.REQUEST_CAMERA_IMAGE_PERMISSION,
new String[] {Manifest.permission.CAMERA},
new int[] {PackageManager.PERMISSION_DENIED});

verify(mockResult).success(null);
verifyNoMoreInteractions(mockResult);
}

@Test
public void
onRequestTakeVideoPermissionsResult_WhenCameraPermissionGranted_LaunchesTakeVideoWithCameraIntent() {
when(mockIntentResolver.resolveActivity(any(Intent.class))).thenReturn(true);

ImagePickerDelegate delegate = createDelegateWithPendingResultAndMethodCall();
delegate.onRequestPermissionsResult(
ImagePickerDelegate.REQUEST_CAMERA_VIDEO_PERMISSION,
new String[] {Manifest.permission.CAMERA},
new int[] {PackageManager.PERMISSION_GRANTED});

verify(mockActivity)
.startActivityForResult(
any(Intent.class), eq(ImagePickerDelegate.REQUEST_CODE_TAKE_VIDEO_WITH_CAMERA));
}

@Test
public void
onRequestTakeImagePermissionsResult_WhenCameraPermissionGranted_LaunchesTakeWithCameraIntent() {
when(mockIntentResolver.resolveActivity(any(Intent.class))).thenReturn(true);

ImagePickerDelegate delegate = createDelegateWithPendingResultAndMethodCall();
delegate.onRequestPermissionsResult(
ImagePickerDelegate.REQUEST_CAMERA_IMAGE_PERMISSION,
new String[] {Manifest.permission.CAMERA},
new int[] {PackageManager.PERMISSION_GRANTED});

verify(mockActivity)
.startActivityForResult(
any(Intent.class), eq(ImagePickerDelegate.REQUEST_CODE_TAKE_IMAGE_WITH_CAMERA));
}

@Test
public void onActivityResult_WhenPickFromGalleryCanceled_FinishesWithNull() {
ImagePickerDelegate delegate = createDelegateWithPendingResultAndMethodCall();
Expand Down