health_kit_api.dart 2.32 KB
import 'package:pigeon/pigeon.dart';

class HealthAuthorization {
  /// -1: AppleHealth不可用, 0: 需要请求授权, 1: 已被授权且能获取到部分数据, 2: 已被拒绝或者没有数据
  final int status;
  final bool hasData;

  HealthAuthorization({required this.status, required this.hasData});
}

/// The user's current Huawei Health activity-ring goals.
///
/// Units: move is kcal, exercise is seconds, and stand is hours.
class HealthActivityGoal {
  HealthActivityGoal({
    this.move,
    this.step,
    this.stand,
    this.exercise,
  });

  int? move;
  int? step;
  int? stand;
  int? exercise;
}

/// One workout record read from Health Service Kit.
class HealthWorkoutDataPoint {
  HealthWorkoutDataPoint({
    required this.startTime,
    required this.endTime,
    required this.activityType,
  });

  /// Unix timestamp in seconds.
  int startTime;

  /// Unix timestamp in seconds.
  int endTime;

  /// The native Health Service Kit exercise-type identifier.
  int activityType;
}

@ConfigurePigeon(
  PigeonOptions(
    dartOut: 'lib/pigeon/health_kit_api.g.dart',
    dartPackageName: 'doublefeel_flutter',
    dartOptions: DartOptions(),
    kotlinOut:
        'android/app/src/main/kotlin/com/doublefeel/app/pigeon/HealthKitApi.kt',
    kotlinOptions: KotlinOptions(
      package: 'com.doublefeel.app.pigeon',
    ),
    swiftOut: 'ios/Runner/Pigeon/HealthKitApi.swift',
    swiftOptions: SwiftOptions(),
    // arkTSOut: 'ohos/entry/src/main/ets/pigeon/HealthKitApi.ets',
    copyrightHeader: 'pigeon/copyright.txt',
  ),
)
@HostApi()
abstract class HealthKitHostApi {
  /// Opens Huawei Health client authorization UI. Returns whether user granted.
  @async
  HealthAuthorization checkHealthAppAuthorization();

  @async
  bool requestHealthClientAuthorization();

  /// Requests Huawei Health to upload the user's latest data to its cloud.
  ///
  /// This only triggers the Health app's configured device-to-cloud sync; it
  /// does not wait for, or return, the subsequently available cloud data.
  @async
  bool syncHealthDataToCloud();

  /// Reads the current activity-ring goals from Huawei Health on OHOS.
  @async
  HealthActivityGoal? readActivityGoal();

  /// Reads workout records in the supplied Unix-seconds time range on OHOS.
  @async
  List<HealthWorkoutDataPoint> readWorkoutData(int startTime, int endTime);
}