device_info_handler.dart 1.23 KB
import 'dart:io';

import 'package:appframe/services/dispatcher.dart';
import 'package:device_info_plus/device_info_plus.dart';

class DeviceInfoHandler extends MessageHandler {
  @override
  Future<Map<String, dynamic>> handleMessage(dynamic params) async {
    var deviceInfoPlugin = DeviceInfoPlugin();

    // 测试效果,先随便响应一些数据
    if (Platform.isAndroid) {
      AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
      return {
        'abi': '${androidInfo.supportedAbis}',
        'deviceAbi': androidInfo.supportedAbis.isNotEmpty ? androidInfo.supportedAbis[0] : '',
        'benchmarkLevel': -1,
        'brand': androidInfo.brand,
        'model': androidInfo.model,
        'system': androidInfo.version.release,
        'platform': "Android",
        'cpuType': androidInfo.hardware,
        "memorySize": androidInfo.physicalRamSize,
      };
    } else if (Platform.isIOS) {
      IosDeviceInfo iosInfo = await deviceInfoPlugin.iosInfo;
      return {
        "brand": "Apple",
        "model": iosInfo.model,
        "system": iosInfo.systemVersion,
        "platform": "iOS",
        "memorySize": (iosInfo.physicalRamSize ~/ (1024 * 1024)).toString(),
      };
    } else {
      return {};
    }
  }
}