mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-26 01:10:39 +00:00
unified granting camera permission on Android
This commit is contained in:
parent
e91d0f88c7
commit
0e5762b88e
3 changed files with 52 additions and 37 deletions
8
test_driver/integration_driver.dart
Normal file
8
test_driver/integration_driver.dart
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import 'package:integration_test/integration_test_driver_extended.dart';
|
||||||
|
|
||||||
|
import 'utils/grant_camera_permission.dart';
|
||||||
|
|
||||||
|
Future<void> main() async {
|
||||||
|
await grantCameraPermission();
|
||||||
|
await integrationDriver();
|
||||||
|
}
|
|
@ -1,42 +1,15 @@
|
||||||
import 'dart:developer';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:integration_test/integration_test_driver_extended.dart';
|
import 'package:integration_test/integration_test_driver_extended.dart';
|
||||||
|
|
||||||
|
import 'utils/grant_camera_permission.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
await grantCameraPermission();
|
||||||
final bool adbExists = Process.runSync('which', <String>['adb']).exitCode == 0;
|
|
||||||
if (!adbExists) {
|
|
||||||
log(r'This test needs ADB to exist on the $PATH. Skipping...');
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
final deviceId = await Process.run('adb', ["-s", 'shell', 'devices']).then((value) {
|
|
||||||
if (value.stdout is String) {
|
|
||||||
return RegExp(r"(?:List of devices attached\n)([A-Z0-9]*)(?:\sdevice\n)")
|
|
||||||
.firstMatch(value.stdout as String)!
|
|
||||||
.group(1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (deviceId == null) {
|
|
||||||
log('This test needs at least one device connected');
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
await Process.run('adb', [
|
|
||||||
"-s",
|
|
||||||
deviceId, // https://github.com/flutter/flutter/issues/86295#issuecomment-1192766368
|
|
||||||
'shell',
|
|
||||||
'pm',
|
|
||||||
'grant',
|
|
||||||
'com.vodemn.lightmeter.dev',
|
|
||||||
'android.permission.CAMERA'
|
|
||||||
]);
|
|
||||||
await integrationDriver(
|
await integrationDriver(
|
||||||
onScreenshot: (name, bytes, [args]) async {
|
onScreenshot: (name, bytes, [args]) async {
|
||||||
final File image = await File('screenshots/$name.png').create(recursive: true);
|
final File image = await File('screenshots/TEST_$name.png').create(recursive: true);
|
||||||
image.writeAsBytesSync(bytes);
|
image.writeAsBytesSync(bytes);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} catch (e) {
|
|
||||||
log('Error occured: $e');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
34
test_driver/utils/grant_camera_permission.dart
Normal file
34
test_driver/utils/grant_camera_permission.dart
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import 'dart:developer';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
Future<void> grantCameraPermission() async {
|
||||||
|
try {
|
||||||
|
final bool adbExists = Process.runSync('which', <String>['adb']).exitCode == 0;
|
||||||
|
if (!adbExists) {
|
||||||
|
log(r'This test needs ADB to exist on the $PATH. Skipping...');
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
final deviceId = await Process.run('adb', ["-s", 'shell', 'devices']).then((value) {
|
||||||
|
if (value.stdout is String) {
|
||||||
|
return RegExp(r"(?:List of devices attached\n)([A-Z0-9]*)(?:\sdevice\n)")
|
||||||
|
.firstMatch(value.stdout as String)!
|
||||||
|
.group(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (deviceId == null) {
|
||||||
|
log('This test needs at least one device connected');
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
await Process.run('adb', [
|
||||||
|
"-s",
|
||||||
|
deviceId, // https://github.com/flutter/flutter/issues/86295#issuecomment-1192766368
|
||||||
|
'shell',
|
||||||
|
'pm',
|
||||||
|
'grant',
|
||||||
|
'com.vodemn.lightmeter.dev',
|
||||||
|
'android.permission.CAMERA'
|
||||||
|
]);
|
||||||
|
} catch (e) {
|
||||||
|
log('Error occured: $e');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue