Преглед изворни кода

[new]增加手机使用情况统计插件

zk пре 6 месеци
родитељ
комит
3d967b2d37
23 измењених фајлова са 503 додато и 0 уклоњено
  1. 33 0
      plugins/mobile_use_statistics/.gitignore
  2. 33 0
      plugins/mobile_use_statistics/.metadata
  3. 3 0
      plugins/mobile_use_statistics/CHANGELOG.md
  4. 1 0
      plugins/mobile_use_statistics/LICENSE
  5. 15 0
      plugins/mobile_use_statistics/README.md
  6. 4 0
      plugins/mobile_use_statistics/analysis_options.yaml
  7. 9 0
      plugins/mobile_use_statistics/android/.gitignore
  8. 52 0
      plugins/mobile_use_statistics/android/build.gradle
  9. 1 0
      plugins/mobile_use_statistics/android/settings.gradle
  10. 2 0
      plugins/mobile_use_statistics/android/src/main/AndroidManifest.xml
  11. 38 0
      plugins/mobile_use_statistics/android/src/main/java/com/atmob/mobile_use_statistics/MobileUseStatisticsPlugin.java
  12. 29 0
      plugins/mobile_use_statistics/android/src/test/java/com/atmob/mobile_use_statistics/MobileUseStatisticsPluginTest.java
  13. 38 0
      plugins/mobile_use_statistics/ios/.gitignore
  14. 0 0
      plugins/mobile_use_statistics/ios/Assets/.gitkeep
  15. 19 0
      plugins/mobile_use_statistics/ios/Classes/MobileUseStatisticsPlugin.swift
  16. 14 0
      plugins/mobile_use_statistics/ios/Resources/PrivacyInfo.xcprivacy
  17. 29 0
      plugins/mobile_use_statistics/ios/mobile_use_statistics.podspec
  18. 3 0
      plugins/mobile_use_statistics/lib/flutter_mobile_statistics.dart
  19. 9 0
      plugins/mobile_use_statistics/lib/src/event/event.dart
  20. 18 0
      plugins/mobile_use_statistics/lib/src/mobile_use_statistics.dart
  21. 36 0
      plugins/mobile_use_statistics/lib/src/mobile_use_statistics_method_channel.dart
  22. 45 0
      plugins/mobile_use_statistics/lib/src/mobile_use_statistics_platform_interface.dart
  23. 72 0
      plugins/mobile_use_statistics/pubspec.yaml

+ 33 - 0
plugins/mobile_use_statistics/.gitignore

@@ -0,0 +1,33 @@
+# Miscellaneous
+*.class
+*.log
+*.pyc
+*.swp
+.DS_Store
+.atom/
+.build/
+.buildlog/
+.history
+.svn/
+.swiftpm/
+migrate_working_dir/
+
+# IntelliJ related
+*.iml
+*.ipr
+*.iws
+.idea/
+
+# The .vscode folder contains launch configuration and tasks you configure in
+# VS Code which you may wish to be included in version control, so this line
+# is commented out by default.
+#.vscode/
+
+# Flutter/Dart/Pub related
+# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
+/pubspec.lock
+**/doc/api/
+.dart_tool/
+.flutter-plugins
+.flutter-plugins-dependencies
+build/

+ 33 - 0
plugins/mobile_use_statistics/.metadata

@@ -0,0 +1,33 @@
+# This file tracks properties of this Flutter project.
+# Used by Flutter tool to assess capabilities and perform upgrades etc.
+#
+# This file should be version controlled and should not be manually edited.
+
+version:
+  revision: "c23637390482d4cf9598c3ce3f2be31aa7332daf"
+  channel: "[user-branch]"
+
+project_type: plugin
+
+# Tracks metadata for the flutter migrate command
+migration:
+  platforms:
+    - platform: root
+      create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
+      base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
+    - platform: android
+      create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
+      base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
+    - platform: ios
+      create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
+      base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
+
+  # User provided section
+
+  # List of Local paths (relative to this file) that should be
+  # ignored by the migrate tool.
+  #
+  # Files that are not part of the templates will be ignored by default.
+  unmanaged_files:
+    - 'lib/main.dart'
+    - 'ios/Runner.xcodeproj/project.pbxproj'

+ 3 - 0
plugins/mobile_use_statistics/CHANGELOG.md

@@ -0,0 +1,3 @@
+## 0.0.1
+
+* TODO: Describe initial release.

+ 1 - 0
plugins/mobile_use_statistics/LICENSE

@@ -0,0 +1 @@
+TODO: Add your license here.

+ 15 - 0
plugins/mobile_use_statistics/README.md

@@ -0,0 +1,15 @@
+# mobile_use_statistics
+
+手机使用情况统计插件
+
+## Getting Started
+
+This project is a starting point for a Flutter
+[plug-in package](https://flutter.dev/to/develop-plugins),
+a specialized package that includes platform-specific implementation code for
+Android and/or iOS.
+
+For help getting started with Flutter development, view the
+[online documentation](https://docs.flutter.dev), which offers tutorials,
+samples, guidance on mobile development, and a full API reference.
+

+ 4 - 0
plugins/mobile_use_statistics/analysis_options.yaml

@@ -0,0 +1,4 @@
+include: package:flutter_lints/flutter.yaml
+
+# Additional information about this file can be found at
+# https://dart.dev/guides/language/analysis-options

+ 9 - 0
plugins/mobile_use_statistics/android/.gitignore

@@ -0,0 +1,9 @@
+*.iml
+.gradle
+/local.properties
+/.idea/workspace.xml
+/.idea/libraries
+.DS_Store
+/build
+/captures
+.cxx

+ 52 - 0
plugins/mobile_use_statistics/android/build.gradle

@@ -0,0 +1,52 @@
+group = "com.atmob.mobile_use_statistics"
+version = "1.0"
+
+buildscript {
+    repositories {
+        google()
+        mavenCentral()
+    }
+
+    dependencies {
+        classpath("com.android.tools.build:gradle:8.7.0")
+    }
+}
+
+rootProject.allprojects {
+    repositories {
+        google()
+        mavenCentral()
+    }
+}
+
+apply plugin: "com.android.library"
+
+android {
+    namespace = "com.atmob.mobile_use_statistics"
+
+    compileSdk = 35
+
+    compileOptions {
+        sourceCompatibility = JavaVersion.VERSION_11
+        targetCompatibility = JavaVersion.VERSION_11
+    }
+
+    defaultConfig {
+        minSdk = 21
+    }
+
+    dependencies {
+        testImplementation("junit:junit:4.13.2")
+        testImplementation("org.mockito:mockito-core:5.0.0")
+    }
+
+    testOptions {
+        unitTests.all {
+            testLogging {
+                events "passed", "skipped", "failed", "standardOut", "standardError"
+                outputs.upToDateWhen { false }
+                showStandardStreams = true
+            }
+        }
+    }
+}

+ 1 - 0
plugins/mobile_use_statistics/android/settings.gradle

@@ -0,0 +1 @@
+rootProject.name = 'mobile_use_statistics'

+ 2 - 0
plugins/mobile_use_statistics/android/src/main/AndroidManifest.xml

@@ -0,0 +1,2 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.atmob.mobile_use_statistics"></manifest>

+ 38 - 0
plugins/mobile_use_statistics/android/src/main/java/com/atmob/mobile_use_statistics/MobileUseStatisticsPlugin.java

@@ -0,0 +1,38 @@
+package com.atmob.mobile_use_statistics;
+
+import androidx.annotation.NonNull;
+
+import io.flutter.embedding.engine.plugins.FlutterPlugin;
+import io.flutter.plugin.common.MethodCall;
+import io.flutter.plugin.common.MethodChannel;
+import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
+import io.flutter.plugin.common.MethodChannel.Result;
+
+/** MobileUseStatisticsPlugin */
+public class MobileUseStatisticsPlugin implements FlutterPlugin, MethodCallHandler {
+  /// The MethodChannel that will the communication between Flutter and native Android
+  ///
+  /// This local reference serves to register the plugin with the Flutter Engine and unregister it
+  /// when the Flutter Engine is detached from the Activity
+  private MethodChannel channel;
+
+  @Override
+  public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
+    channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "mobile_use_statistics");
+    channel.setMethodCallHandler(this);
+  }
+
+  @Override
+  public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
+    if (call.method.equals("getPlatformVersion")) {
+      result.success("Android " + android.os.Build.VERSION.RELEASE);
+    } else {
+      result.notImplemented();
+    }
+  }
+
+  @Override
+  public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
+    channel.setMethodCallHandler(null);
+  }
+}

+ 29 - 0
plugins/mobile_use_statistics/android/src/test/java/com/atmob/mobile_use_statistics/MobileUseStatisticsPluginTest.java

@@ -0,0 +1,29 @@
+package com.atmob.mobile_use_statistics;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import io.flutter.plugin.common.MethodCall;
+import io.flutter.plugin.common.MethodChannel;
+import org.junit.Test;
+
+/**
+ * This demonstrates a simple unit test of the Java portion of this plugin's implementation.
+ *
+ * Once you have built the plugin's example app, you can run these tests from the command
+ * line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or
+ * you can run them directly from IDEs that support JUnit such as Android Studio.
+ */
+
+public class MobileUseStatisticsPluginTest {
+  @Test
+  public void onMethodCall_getPlatformVersion_returnsExpectedValue() {
+    MobileUseStatisticsPlugin plugin = new MobileUseStatisticsPlugin();
+
+    final MethodCall call = new MethodCall("getPlatformVersion", null);
+    MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
+    plugin.onMethodCall(call, mockResult);
+
+    verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE);
+  }
+}

+ 38 - 0
plugins/mobile_use_statistics/ios/.gitignore

@@ -0,0 +1,38 @@
+.idea/
+.vagrant/
+.sconsign.dblite
+.svn/
+
+.DS_Store
+*.swp
+profile
+
+DerivedData/
+build/
+GeneratedPluginRegistrant.h
+GeneratedPluginRegistrant.m
+
+.generated/
+
+*.pbxuser
+*.mode1v3
+*.mode2v3
+*.perspectivev3
+
+!default.pbxuser
+!default.mode1v3
+!default.mode2v3
+!default.perspectivev3
+
+xcuserdata
+
+*.moved-aside
+
+*.pyc
+*sync/
+Icon?
+.tags*
+
+/Flutter/Generated.xcconfig
+/Flutter/ephemeral/
+/Flutter/flutter_export_environment.sh

+ 0 - 0
plugins/mobile_use_statistics/ios/Assets/.gitkeep


+ 19 - 0
plugins/mobile_use_statistics/ios/Classes/MobileUseStatisticsPlugin.swift

@@ -0,0 +1,19 @@
+import Flutter
+import UIKit
+
+public class MobileUseStatisticsPlugin: NSObject, FlutterPlugin {
+  public static func register(with registrar: FlutterPluginRegistrar) {
+    let channel = FlutterMethodChannel(name: "mobile_use_statistics", binaryMessenger: registrar.messenger())
+    let instance = MobileUseStatisticsPlugin()
+    registrar.addMethodCallDelegate(instance, channel: channel)
+  }
+
+  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
+    switch call.method {
+    case "getPlatformVersion":
+      result("iOS " + UIDevice.current.systemVersion)
+    default:
+      result(FlutterMethodNotImplemented)
+    }
+  }
+}

+ 14 - 0
plugins/mobile_use_statistics/ios/Resources/PrivacyInfo.xcprivacy

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>NSPrivacyTrackingDomains</key>
+	<array/>
+	<key>NSPrivacyAccessedAPITypes</key>
+	<array/>
+	<key>NSPrivacyCollectedDataTypes</key>
+	<array/>
+	<key>NSPrivacyTracking</key>
+	<false/>
+</dict>
+</plist>

+ 29 - 0
plugins/mobile_use_statistics/ios/mobile_use_statistics.podspec

@@ -0,0 +1,29 @@
+#
+# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
+# Run `pod lib lint mobile_use_statistics.podspec` to validate before publishing.
+#
+Pod::Spec.new do |s|
+  s.name             = 'mobile_use_statistics'
+  s.version          = '0.0.1'
+  s.summary          = '手机使用情况统计插件'
+  s.description      = <<-DESC
+手机使用情况统计插件
+                       DESC
+  s.homepage         = 'http://example.com'
+  s.license          = { :file => '../LICENSE' }
+  s.author           = { 'Your Company' => 'email@example.com' }
+  s.source           = { :path => '.' }
+  s.source_files = 'Classes/**/*'
+  s.dependency 'Flutter'
+  s.platform = :ios, '12.0'
+
+  # Flutter.framework does not contain a i386 slice.
+  s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
+  s.swift_version = '5.0'
+
+  # If your plugin requires a privacy manifest, for example if it uses any
+  # required reason APIs, update the PrivacyInfo.xcprivacy file to describe your
+  # plugin's privacy impact, and then uncomment this line. For more information,
+  # see https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
+  # s.resource_bundles = {'mobile_use_statistics_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
+end

+ 3 - 0
plugins/mobile_use_statistics/lib/flutter_mobile_statistics.dart

@@ -0,0 +1,3 @@
+library mobile_use_statistics;
+
+export 'package:mobile_use_statistics/src/mobile_use_statistics.dart';

+ 9 - 0
plugins/mobile_use_statistics/lib/src/event/event.dart

@@ -0,0 +1,9 @@
+//每一次的屏幕事件
+//startTime 解锁屏幕时间
+//endTime 锁屏时间,可能为0 ,0 说明当前在使用没有锁屏
+class Event {
+  int startTime;
+  int endTime;
+
+  Event({required this.startTime, required this.endTime});
+}

+ 18 - 0
plugins/mobile_use_statistics/lib/src/mobile_use_statistics.dart

@@ -0,0 +1,18 @@
+import 'package:mobile_use_statistics/src/event/event.dart';
+
+import 'mobile_use_statistics_platform_interface.dart';
+
+class MobileUseStatistics {
+  Future<List<Event>?> getLockScreenStatistics() {
+    return MobileUseStatisticsPlatform.instance.getLockScreenStatistics();
+  }
+
+  Future<bool> hasUseStatisticsPermission() {
+    return MobileUseStatisticsPlatform.instance.hasUseStatisticsPermission();
+  }
+
+  Future<bool> requestUseStatisticsPermission() {
+    return MobileUseStatisticsPlatform.instance
+        .requestUseStatisticsPermission();
+  }
+}

+ 36 - 0
plugins/mobile_use_statistics/lib/src/mobile_use_statistics_method_channel.dart

@@ -0,0 +1,36 @@
+import 'package:flutter/foundation.dart';
+import 'package:flutter/services.dart';
+import 'package:mobile_use_statistics/src/event/event.dart';
+
+import 'mobile_use_statistics_platform_interface.dart';
+
+/// An implementation of [MobileUseStatisticsPlatform] that uses method channels.
+class MethodChannelMobileUseStatistics extends MobileUseStatisticsPlatform {
+  /// The method channel used to interact with the native platform.
+  @visibleForTesting
+  final methodChannel = const MethodChannel('mobile_use_statistics');
+
+  @override
+  Future<List<Event>?> getLockScreenStatistics() async {
+    final version = await methodChannel.invokeMethod<List<Event>?>(
+      'getLockScreenStatistics',
+    );
+    return version;
+  }
+
+  @override
+  Future<bool> hasUseStatisticsPermission() async {
+    final hasPermission = await methodChannel.invokeMethod<bool>(
+      'hasUseStatisticsPermission',
+    );
+    return hasPermission ?? false;
+  }
+
+  @override
+  Future<bool> requestUseStatisticsPermission() async {
+    final hasPermission = await methodChannel.invokeMethod<bool>(
+      'requestUseStatisticsPermission',
+    );
+    return hasPermission ?? false;
+  }
+}

+ 45 - 0
plugins/mobile_use_statistics/lib/src/mobile_use_statistics_platform_interface.dart

@@ -0,0 +1,45 @@
+import 'package:mobile_use_statistics/src/event/event.dart';
+import 'package:plugin_platform_interface/plugin_platform_interface.dart';
+
+import 'mobile_use_statistics_method_channel.dart';
+
+abstract class MobileUseStatisticsPlatform extends PlatformInterface {
+  /// Constructs a MobileUseStatisticsPlatform.
+  MobileUseStatisticsPlatform() : super(token: _token);
+
+  static final Object _token = Object();
+
+  static MobileUseStatisticsPlatform _instance =
+      MethodChannelMobileUseStatistics();
+
+  /// The default instance of [MobileUseStatisticsPlatform] to use.
+  ///
+  /// Defaults to [MethodChannelMobileUseStatistics].
+  static MobileUseStatisticsPlatform get instance => _instance;
+
+  /// Platform-specific implementations should set this with their own
+  /// platform-specific class that extends [MobileUseStatisticsPlatform] when
+  /// they register themselves.
+  static set instance(MobileUseStatisticsPlatform instance) {
+    PlatformInterface.verifyToken(instance, _token);
+    _instance = instance;
+  }
+
+  Future<List<Event>?> getLockScreenStatistics() async {
+    throw UnimplementedError(
+      'getLockScreenStatistics() has not been implemented.',
+    );
+  }
+
+  Future<bool> hasUseStatisticsPermission() async {
+    throw UnimplementedError(
+      'hasUseStatisticsPermission() has not been implemented.',
+    );
+  }
+
+  Future<bool> requestUseStatisticsPermission() async {
+    throw UnimplementedError(
+      'requestUseStatisticsPermission() has not been implemented.',
+    );
+  }
+}

+ 72 - 0
plugins/mobile_use_statistics/pubspec.yaml

@@ -0,0 +1,72 @@
+name: mobile_use_statistics
+description: "手机使用情况统计插件"
+version: 0.0.1
+homepage:
+
+environment:
+  sdk: ^3.7.2
+  flutter: '>=3.3.0'
+
+dependencies:
+  flutter:
+    sdk: flutter
+  plugin_platform_interface: ^2.0.2
+
+dev_dependencies:
+  flutter_test:
+    sdk: flutter
+  flutter_lints: ^5.0.0
+
+# For information on the generic Dart part of this file, see the
+# following page: https://dart.dev/tools/pub/pubspec
+
+# The following section is specific to Flutter packages.
+flutter:
+  # This section identifies this Flutter project as a plugin project.
+  # The 'pluginClass' specifies the class (in Java, Kotlin, Swift, Objective-C, etc.)
+  # which should be registered in the plugin registry. This is required for
+  # using method channels.
+  # The Android 'package' specifies package in which the registered class is.
+  # This is required for using method channels on Android.
+  # The 'ffiPlugin' specifies that native code should be built and bundled.
+  # This is required for using `dart:ffi`.
+  # All these are used by the tooling to maintain consistency when
+  # adding or updating assets for this project.
+  plugin:
+    platforms:
+      android:
+        package: com.atmob.mobile_use_statistics
+        pluginClass: MobileUseStatisticsPlugin
+      ios:
+        pluginClass: MobileUseStatisticsPlugin
+
+  # To add assets to your plugin package, add an assets section, like this:
+  # assets:
+  #   - images/a_dot_burr.jpeg
+  #   - images/a_dot_ham.jpeg
+  #
+  # For details regarding assets in packages, see
+  # https://flutter.dev/to/asset-from-package
+  #
+  # An image asset can refer to one or more resolution-specific "variants", see
+  # https://flutter.dev/to/resolution-aware-images
+
+  # To add custom fonts to your plugin package, add a fonts section here,
+  # in this "flutter" section. Each entry in this list should have a
+  # "family" key with the font family name, and a "fonts" key with a
+  # list giving the asset and other descriptors for the font. For
+  # example:
+  # fonts:
+  #   - family: Schyler
+  #     fonts:
+  #       - asset: fonts/Schyler-Regular.ttf
+  #       - asset: fonts/Schyler-Italic.ttf
+  #         style: italic
+  #   - family: Trajan Pro
+  #     fonts:
+  #       - asset: fonts/TrajanPro.ttf
+  #       - asset: fonts/TrajanPro_Bold.ttf
+  #         weight: 700
+  #
+  # For details regarding fonts in packages, see
+  # https://flutter.dev/to/font-from-package