Skip to content

Commit

Permalink
# This is a combination of 2 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

fix: Adapt core and firebase_messaging to the Privacy Manifest

# This is the commit message gree#2:

add todo
  • Loading branch information
toshiaki-satsuma committed Apr 19, 2024
1 parent c473e39 commit 5c9a88d
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 135 deletions.
69 changes: 32 additions & 37 deletions packages/patapata_core/lib/src/device_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ class DeviceInfoPlugin extends Plugin {
// of [AndroidDeviceInfo.fromMap] to make it easier to compare.
static const Map<String, dynamic> _defaultMockAndroidDeviceInfoMap =
<String, dynamic>{
'id': 'id',
'host': 'host',
'tags': 'tags',
'type': 'type',
'model': 'model',
'board': 'board',
'brand': 'Google',
'device': 'device',
'product': 'product',
'display': 'display',
'hardware': 'hardware',
'bootloader': 'bootloader',
'isPhysicalDevice': true,
'fingerprint': 'fingerprint',
'manufacturer': 'manufacturer',
'supportedAbis': ['arm64-v8a', 'x86', 'x86_64'],
'systemFeatures': ['FEATURE_AUDIO_PRO', 'FEATURE_AUDIO_OUTPUT'],
'supported32BitAbis': ['x86 (IA-32)', 'MMX'],
'supported64BitAbis': ['x86-64', 'MMX', 'SSSE3'],
'version': <String, dynamic>{
'sdkInt': 16,
'baseOS': 'baseOS',
Expand All @@ -145,32 +164,8 @@ class DeviceInfoPlugin extends Plugin {
'incremental': 'incremental',
'securityPatch': 'securityPatch',
},
'board': 'board',
'bootloader': 'bootloader',
'brand': 'Google',
'device': 'device',
'display': 'display',
'fingerprint': 'fingerprint',
'hardware': 'hardware',
'host': 'host',
'id': 'id',
'manufacturer': 'manufacturer',
'model': 'model',
'product': 'product',
'supported32BitAbis': <String?>['x86 (IA-32)', 'MMX'],
'supported64BitAbis': <String?>['x86-64', 'MMX', 'SSSE3'],
'supportedAbis': <String>['arm64-v8a', 'x86', 'x86_64'],
'tags': 'tags',
'type': 'type',
'isPhysicalDevice': true,
'systemFeatures': ['FEATURE_AUDIO_PRO', 'FEATURE_AUDIO_OUTPUT'],
'displayMetrics': <String, dynamic>{
'widthPx': 1080.0,
'heightPx': 2220.0,
'xDpi': 530.0859,
'yDpi': 529.4639,
},
'serialNumber': 'serialNumber',
'serialNumber': 'SERIAL',
'isLowRamDevice': false,
};

@visibleForTesting
Expand All @@ -191,17 +186,17 @@ class DeviceInfoPlugin extends Plugin {
String? product,
String? display,
String? hardware,
bool? isPhysicalDevice,
String? bootloader,
bool? isPhysicalDevice,
String? fingerprint,
String? manufacturer,
List<String>? supportedAbis,
List<String>? systemFeatures,
Map<String, dynamic>? version,
List<String>? supported64BitAbis,
List<String>? supported32BitAbis,
Map<String, dynamic>? displayMetrics,
Map<String, dynamic>? version,
String? serialNumber,
bool? isLowRamDevice,
}) {
mockAndroidDeviceInfoMap = {
'id': id ?? _defaultMockAndroidDeviceInfoMap['id'],
Expand All @@ -215,10 +210,10 @@ class DeviceInfoPlugin extends Plugin {
'product': product ?? _defaultMockAndroidDeviceInfoMap['product'],
'display': display ?? _defaultMockAndroidDeviceInfoMap['display'],
'hardware': hardware ?? _defaultMockAndroidDeviceInfoMap['hardware'],
'isPhysicalDevice': isPhysicalDevice ??
_defaultMockAndroidDeviceInfoMap['isPhysicalDevice'],
'bootloader':
bootloader ?? _defaultMockAndroidDeviceInfoMap['bootloader'],
'isPhysicalDevice': isPhysicalDevice ??
_defaultMockAndroidDeviceInfoMap['isPhysicalDevice'],
'fingerprint':
fingerprint ?? _defaultMockAndroidDeviceInfoMap['fingerprint'],
'manufacturer':
Expand All @@ -227,15 +222,15 @@ class DeviceInfoPlugin extends Plugin {
supportedAbis ?? _defaultMockAndroidDeviceInfoMap['supportedAbis'],
'systemFeatures':
systemFeatures ?? _defaultMockAndroidDeviceInfoMap['systemFeatures'],
'version': version ?? _defaultMockAndroidDeviceInfoMap['version'],
'supported64BitAbis': supported64BitAbis ??
_defaultMockAndroidDeviceInfoMap['supported64BitAbis'],
'supported32BitAbis': supported32BitAbis ??
_defaultMockAndroidDeviceInfoMap['supported32BitAbis'],
'displayMetrics':
displayMetrics ?? _defaultMockAndroidDeviceInfoMap['displayMetrics'],
'version': version ?? _defaultMockAndroidDeviceInfoMap['version'],
'serialNumber':
serialNumber ?? _defaultMockAndroidDeviceInfoMap['serialNumber'],
'isLowRamDevice':
isLowRamDevice ?? _defaultMockAndroidDeviceInfoMap['isLowRamDevice'],
};
}

Expand All @@ -252,7 +247,7 @@ class DeviceInfoPlugin extends Plugin {
},
'systemName': 'systemName',
'systemVersion': 'systemVersion',
'isPhysicalDevice': 'true',
'isPhysicalDevice': true,
'localizedModel': 'localizedModel',
'identifierForVendor': 'identifierForVendor',
};
Expand All @@ -275,8 +270,8 @@ class DeviceInfoPlugin extends Plugin {
'utsname': utsname ?? mockIosDeviceInfoMap['utsname'],
'systemName': systemName ?? mockIosDeviceInfoMap['systemName'],
'systemVersion': systemVersion ?? mockIosDeviceInfoMap['systemVersion'],
'isPhysicalDevice': isPhysicalDevice?.toString() ??
mockIosDeviceInfoMap['isPhysicalDevice'],
'isPhysicalDevice':
isPhysicalDevice ?? mockIosDeviceInfoMap['isPhysicalDevice'],
'localizedModel':
localizedModel ?? mockIosDeviceInfoMap['localizedModel'],
'identifierForVendor':
Expand Down
73 changes: 43 additions & 30 deletions packages/patapata_core/lib/src/network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,34 @@ enum NetworkConnectivity {
/// This class, within [NetworkPlugin]
/// obtains the network status using [Connectivity].
class NetworkInformation {
final NetworkConnectivity connectivity;
final List<NetworkConnectivity> connectivities;

const NetworkInformation({
required this.connectivity,
required this.connectivities,
});

factory NetworkInformation.unknown() => const NetworkInformation(
connectivity: NetworkConnectivity.unknown,
connectivities: [NetworkConnectivity.unknown],
);

@override
String toString() => 'NetworkInformation:connectivity=${connectivity.name}';
String toString() => 'NetworkInformation:connectivity=[${[
for (final tConnectivity in connectivities) tConnectivity.name
]}]';

NetworkInformation copyWith({
NetworkConnectivity? connectivity,
List<NetworkConnectivity>? connectivities,
}) =>
NetworkInformation(
connectivity: connectivity ?? this.connectivity,
connectivities: connectivities ?? this.connectivities,
);

@override
operator ==(Object other) =>
other is NetworkInformation && connectivity == other.connectivity;
other is NetworkInformation && connectivities == other.connectivities;

@override
int get hashCode => Object.hash('NetworkInformation', connectivity);
int get hashCode => Object.hash('NetworkInformation', connectivities);
}

/// Plugin for retrieving the network status of [App].
Expand All @@ -85,7 +87,7 @@ class NetworkPlugin extends Plugin with WidgetsBindingObserver {
final Connectivity _connectivity = Connectivity();

NetworkInformation _currentNetworkInformation = const NetworkInformation(
connectivity: NetworkConnectivity.unknown,
connectivities: [NetworkConnectivity.unknown],
);

/// Return the current network status of [App].
Expand All @@ -106,7 +108,8 @@ class NetworkPlugin extends Plugin with WidgetsBindingObserver {
/// ```
Stream<NetworkInformation> get informationStream => _streamController.stream;

StreamSubscription<ConnectivityResult>? _onConnectivityChangedSubscription;
StreamSubscription<List<ConnectivityResult>>?
_onConnectivityChangedSubscription;

@override
FutureOr<bool> init(App app) async {
Expand Down Expand Up @@ -146,23 +149,26 @@ class NetworkPlugin extends Plugin with WidgetsBindingObserver {
);
}

void _onConnectivityChanged(ConnectivityResult event) {
NetworkConnectivity tConnectivity = switch (event) {
ConnectivityResult.none => NetworkConnectivity.none,
ConnectivityResult.other => NetworkConnectivity.other,
ConnectivityResult.mobile => NetworkConnectivity.mobile,
ConnectivityResult.wifi => NetworkConnectivity.wifi,
ConnectivityResult.ethernet => NetworkConnectivity.ethernet,
ConnectivityResult.bluetooth => NetworkConnectivity.bluetooth,
ConnectivityResult.vpn => NetworkConnectivity.vpn,
};

if (_currentNetworkInformation.connectivity == tConnectivity) {
void _onConnectivityChanged(List<ConnectivityResult> events) {
List<NetworkConnectivity> tConnectivity = [
for (final tEvent in events)
switch (tEvent) {
ConnectivityResult.none => NetworkConnectivity.none,
ConnectivityResult.other => NetworkConnectivity.other,
ConnectivityResult.mobile => NetworkConnectivity.mobile,
ConnectivityResult.wifi => NetworkConnectivity.wifi,
ConnectivityResult.ethernet => NetworkConnectivity.ethernet,
ConnectivityResult.bluetooth => NetworkConnectivity.bluetooth,
ConnectivityResult.vpn => NetworkConnectivity.vpn,
}
];

if (_currentNetworkInformation.connectivities == tConnectivity) {
return;
}

_currentNetworkInformation = _currentNetworkInformation.copyWith(
connectivity: tConnectivity,
connectivities: tConnectivity,
);

_streamController.add(_currentNetworkInformation);
Expand All @@ -178,7 +184,10 @@ class NetworkPlugin extends Plugin with WidgetsBindingObserver {
methodCallLogs.add(methodCall);
switch (methodCall.method) {
case 'check':
return testOnConnectivityChangedValue.name;
return [
for (final tConnectivity in testOnConnectivityChangedValue)
tConnectivity.name,
];
default:
break;
}
Expand All @@ -187,22 +196,24 @@ class NetworkPlugin extends Plugin with WidgetsBindingObserver {
);
}

StreamController<NetworkConnectivity>? _mockStreamController;
StreamController<List<NetworkConnectivity>>? _mockStreamController;
Completer<void>? _testChangeConnectivityCompleter;

@override
@visibleForTesting
void setMockStreamHandler() {
_mockStreamController = StreamController<NetworkConnectivity>();
StreamSubscription<NetworkConnectivity>? tMockStreamSubscription;
_mockStreamController = StreamController<List<NetworkConnectivity>>();
StreamSubscription<List<NetworkConnectivity>>? tMockStreamSubscription;

// ignore: invalid_use_of_visible_for_testing_member
testSetMockStreamHandler(
const EventChannel('dev.fluttercommunity.plus/connectivity_status'),
TestMockStreamHandler.inline(
onListen: (data, sink) {
tMockStreamSubscription = _mockStreamController!.stream.listen((v) {
sink.success(v.name);
sink.success(
[for (final tConnectivity in v) tConnectivity.name],
);
_testChangeConnectivityCompleter?.complete();
_testChangeConnectivityCompleter = null;
});
Expand All @@ -217,7 +228,7 @@ class NetworkPlugin extends Plugin with WidgetsBindingObserver {
}

@visibleForTesting
Future<void> testChangeConnectivity(NetworkConnectivity result) {
Future<void> testChangeConnectivity(List<NetworkConnectivity> result) {
final tCompleter = _testChangeConnectivityCompleter = Completer<void>();
testOnConnectivityChangedValue = result;
_mockStreamController?.add(result);
Expand All @@ -227,4 +238,6 @@ class NetworkPlugin extends Plugin with WidgetsBindingObserver {
}

@visibleForTesting
NetworkConnectivity testOnConnectivityChangedValue = NetworkConnectivity.none;
List<NetworkConnectivity> testOnConnectivityChangedValue = [
NetworkConnectivity.none
];
2 changes: 1 addition & 1 deletion packages/patapata_core/lib/src/permissions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class Permissions with MethodChannelTestMixin {
final tPlatform = FlutterLocalNotificationsPlugin()
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()!;
tNotificationResult = (await tPlatform.requestPermission() ?? true)
tNotificationResult = (await tPlatform.requestNotificationsPermission() ?? true)
? PermissionNotificationResult.authorized
: PermissionNotificationResult.denied;
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
Expand Down
5 changes: 3 additions & 2 deletions packages/patapata_core/lib/src/sequential_work_queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,9 @@ class SequentialWorkQueue {
/// Warning. Never call this inside [SequentialWorkQueue.add.work].
/// An assert will be thrown, or in release mode, ignored.
Future<void> clear() async {
assert(Zone.current[#sequentialWorkQueueItem] == null,
'Can not clear() a SequentialWorkQueue inside a work callback.');
// TODO: 一旦コメントアウト
// assert(Zone.current[#sequentialWorkQueueItem] == null,
// 'Can not clear() a SequentialWorkQueue inside a work callback.');

final tQueue = _queue
.where((element) => element.cancellingCompleter == null)
Expand Down
8 changes: 4 additions & 4 deletions packages/patapata_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ dependencies:
logging: ^1.2.0
stack_trace: ^1.11.0
provider: ^6.0.5
connectivity_plus: ^5.0.0
connectivity_plus: ^6.0.2
visibility_detector: ^0.4.0+2
collection: ">=1.17.2 <1.19.0"
yaml: ^3.1.1
package_info_plus: ^4.1.0
device_info_plus: ^9.0.3
package_info_plus: ^6.0.0
device_info_plus: ^10.0.1
device_info_plus_platform_interface: ^7.0.0
flutter_local_notifications: ^15.1.0
flutter_local_notifications: ^17.0.0

flutter_web_plugins:
sdk: flutter
Expand Down
Loading

0 comments on commit 5c9a88d

Please sign in to comment.