This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[camera] Fix crash from changing permissions (#2447)
Our listeners are called for every single permissions change, not just the first one. This resulted in multiple replies being sent to Dart and fatal crashes. Change to instead manually keep track of responses and only respond to the first call.
- Loading branch information
Michael Klimushyn
committed
Jan 10, 2020
1 parent
a1a4f21
commit 868bc6a
Showing
4 changed files
with
51 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/camera/android/src/test/java/io/flutter/plugins/camera/CameraPermissionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.flutter.plugins.camera; | ||
|
||
import static junit.framework.TestCase.assertEquals; | ||
|
||
import android.content.pm.PackageManager; | ||
import io.flutter.plugins.camera.CameraPermissions.CameraRequestPermissionsListener; | ||
import org.junit.Test; | ||
|
||
public class CameraPermissionsTest { | ||
@Test | ||
public void listener_respondsOnce() { | ||
final int[] calledCounter = {0}; | ||
CameraRequestPermissionsListener permissionsListener = | ||
new CameraRequestPermissionsListener((String code, String desc) -> calledCounter[0]++); | ||
|
||
permissionsListener.onRequestPermissionsResult( | ||
9796, null, new int[] {PackageManager.PERMISSION_DENIED}); | ||
permissionsListener.onRequestPermissionsResult( | ||
9796, null, new int[] {PackageManager.PERMISSION_GRANTED}); | ||
|
||
assertEquals(1, calledCounter[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters