From 4d54d442d569dd30f650cc26efdab36ff19c6a85 Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Wed, 2 Aug 2023 14:48:54 +0300 Subject: [PATCH] [sensors-plus] Start implementation package sensors_plus. OMP#OS-17084 --- example/app_run.sh | 131 ++++++++++++++++++ .../sensors_plus_aurora/.gitignore | 30 ++++ .../sensors_plus_aurora/.metadata | 30 ++++ .../sensors_plus_aurora/README.md | 22 +++ .../sensors_plus_aurora/analysis_options.yaml | 4 + .../sensors_plus_aurora/aurora/CMakeLists.txt | 26 ++++ .../include/sensors_plus_aurora/globals.h | 15 ++ .../sensors_plus_aurora_plugin.h | 23 +++ .../aurora/sensors_plus_aurora_plugin.cpp | 43 ++++++ .../lib/sensors_plus_aurora.dart | 8 ++ .../sensors_plus_aurora_method_channel.dart | 17 +++ ...ensors_plus_aurora_platform_interface.dart | 29 ++++ .../sensors_plus_aurora/pubspec.yaml | 26 ++++ ...nsors_plus_aurora_method_channel_test.dart | 27 ++++ .../test/sensors_plus_aurora_test.dart | 32 +++++ 15 files changed, 463 insertions(+) create mode 100755 example/app_run.sh create mode 100644 packages/sensors_plus/sensors_plus_aurora/.gitignore create mode 100644 packages/sensors_plus/sensors_plus_aurora/.metadata create mode 100644 packages/sensors_plus/sensors_plus_aurora/README.md create mode 100644 packages/sensors_plus/sensors_plus_aurora/analysis_options.yaml create mode 100644 packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt create mode 100644 packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/globals.h create mode 100644 packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h create mode 100644 packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp create mode 100644 packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart create mode 100644 packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart create mode 100644 packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart create mode 100644 packages/sensors_plus/sensors_plus_aurora/pubspec.yaml create mode 100644 packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart create mode 100644 packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart diff --git a/example/app_run.sh b/example/app_run.sh new file mode 100755 index 0000000..4457e55 --- /dev/null +++ b/example/app_run.sh @@ -0,0 +1,131 @@ +#!/bin/bash + +## Copyright (c) 2023. Open Mobile Platform LLC. +## License: Proprietary. +## +## SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +# SPDX-License-Identifier: BSD-3-Clause +## Contact: https://community.omprussia.ru/open-source +## +## This file is part of the Aurora OS Application Template project. +## +## Redistribution and use in source and binary forms, +## with or without modification, are permitted provided +## that the following conditions are met: +## +## * Redistributions of source code must retain the above copyright notice, +## this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright notice, +## this list of conditions and the following disclaimer +## in the documentation and/or other materials provided with the distribution. +## * Neither the name of the copyright holder nor the names of its contributors +## may be used to endorse or promote products derived from this software +## without specific prior written permission. +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +## FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +## IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +## OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +## LOSS OF USE, DATA, OR PROFITS; +## OR BUSINESS INTERRUPTION) +## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +## WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) +## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +## Build example, sign rpm, upload/install/run rpm to device + +## Usage +## +## chmod +x ./run.sh +## +## ./run.sh \ +## -d : \ +## -s /home/user/sign/folder + +sudo echo 'Start...'; + +## Flutter path +FLUTTER="$HOME/.local/opt/flutter/bin/flutter" + +## https://developer.auroraos.ru/doc/software_development/psdk/setup +## Install Platform SDK path +## You may not have set the PSDK_DIR environment variable. +## export PSDK_DIR=$HOME/AuroraPlatformSDK/sdks/aurora_psdk + +while getopts d:s: flag; do + case "${flag}" in + d) device=${OPTARG} ;; + s) sign=${OPTARG} ;; + *) + echo "usage: $0 [-d] [-s]" >&2 + exit 1 + ;; + esac +done + +## Update dependency +$FLUTTER pub get + +## Generate internationalizing +$FLUTTER pub run build_runner build + +## Run ffigen +# $FLUTTER pub run ffigen + +## Build aurora example app +{ + $FLUTTER build aurora --release +} || { + exit 1; +} + +if [ -n "$sign" ]; then + + key=$(ls "$sign"/*key.pem) + + if [ -z "$key" ]; then + echo "Key *key.pem not found." + exit + fi + + cert=$(ls "$sign"/*cert.pem) + + if [ -z "$cert" ]; then + echo "Key *cert.pem not found." + exit + fi + + ## Sign rpm system key + "$PSDK_DIR"/sdk-chroot rpmsign-external sign \ + --key "$key" \ + --cert "$cert" \ + build/aurora/arm/release/RPMS/*.rpm +fi + +if [ -n "$device" ]; then + + PACKAGE="ru.auroraos.flutter_example_packages" + + IFS=':' read -ra ADDR <<< "$device" + + D_IP="${ADDR[0]}" + D_PASS="${ADDR[1]}" + + # shellcheck disable=SC2012 + rpm=$(ls "$PWD"/build/aurora/arm/release/RPMS/*.rpm | sort -r | head -n 1) + + # upload rpm + scp "$rpm" defaultuser@"$D_IP:/home/defaultuser/Downloads" + + # install rpm + ssh -t defaultuser@"$D_IP" "echo $D_PASS | devel-su pkcon -y install-local /home/defaultuser/Downloads/$PACKAGE*.rpm" + + # run application + ssh -t defaultuser@"$D_IP" "/usr/bin/$PACKAGE" +fi diff --git a/packages/sensors_plus/sensors_plus_aurora/.gitignore b/packages/sensors_plus/sensors_plus_aurora/.gitignore new file mode 100644 index 0000000..96486fd --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +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/ +.packages +build/ diff --git a/packages/sensors_plus/sensors_plus_aurora/.metadata b/packages/sensors_plus/sensors_plus_aurora/.metadata new file mode 100644 index 0000000..641645c --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/.metadata @@ -0,0 +1,30 @@ +# 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. + +version: + revision: 135454af32477f815a7525073027a3ff9eff1bfd + channel: aurora + +project_type: plugin + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 135454af32477f815a7525073027a3ff9eff1bfd + base_revision: 135454af32477f815a7525073027a3ff9eff1bfd + - platform: aurora + create_revision: 135454af32477f815a7525073027a3ff9eff1bfd + base_revision: 135454af32477f815a7525073027a3ff9eff1bfd + + # 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' diff --git a/packages/sensors_plus/sensors_plus_aurora/README.md b/packages/sensors_plus/sensors_plus_aurora/README.md new file mode 100644 index 0000000..6bcd18c --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/README.md @@ -0,0 +1,22 @@ +# sensors_plus_aurora + +The Aurora implementation of [`sensors_plus`](https://pub.dev/packages/sensors_plus). + +## Usage + +This package is not an _endorsed_ implementation of `sensors_plus`. +Therefore, you have to include `sensors_plus_aurora` alongside `sensors_plus` as dependencies in your `pubspec.yaml` file. + +**pubspec.yaml** + +```yaml +dependencies: + sensors_plus: ^3.0.2 + sensors_plus_aurora: ^0.0.0 # @todo Not published +``` + +***.dart** + +```dart +// @todo +``` diff --git a/packages/sensors_plus/sensors_plus_aurora/analysis_options.yaml b/packages/sensors_plus/sensors_plus_aurora/analysis_options.yaml new file mode 100644 index 0000000..9e47db5 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/analysis_options.yaml @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +# SPDX-License-Identifier: BSD-3-Clause + +include: package:flutter_lints/flutter.yaml diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt b/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt new file mode 100644 index 0000000..fce5f12 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt @@ -0,0 +1,26 @@ +# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.10) + +set(PROJECT_NAME sensors_plus_aurora) +set(PLUGIN_NAME sensors_plus_aurora_platform_plugin) + +project(${PROJECT_NAME} LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-psabi") +set(CMAKE_CXX_FLAGS_RELEASE "-O3") + +find_package(PkgConfig REQUIRED) +pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) + +add_library(${PLUGIN_NAME} SHARED sensors_plus_aurora_plugin.cpp) + +set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) +target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::FlutterEmbedder) + +target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) +target_compile_definitions(${PLUGIN_NAME} PRIVATE PLUGIN_IMPL) diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/globals.h b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/globals.h new file mode 100644 index 0000000..e07cf5f --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/globals.h @@ -0,0 +1,15 @@ +/** + * SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_GLOBALS_H +#define FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_GLOBALS_H + +#ifdef PLUGIN_IMPL +#define PLUGIN_EXPORT __attribute__((visibility("default"))) +#else +#define PLUGIN_EXPORT +#endif + +#endif /* FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_GLOBALS_H */ diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h new file mode 100644 index 0000000..a429249 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h @@ -0,0 +1,23 @@ +/** + * SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H +#define FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H + +#include +#include + +class PLUGIN_EXPORT SensorsPlusAuroraPlugin final : public PluginInterface +{ +public: + void RegisterWithRegistrar(PluginRegistrar ®istrar) override; + +private: + void onMethodCall(const MethodCall &call); + void onGetPlatformVersion(const MethodCall &call); + void unimplemented(const MethodCall &call); +}; + +#endif /* FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H */ diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp new file mode 100644 index 0000000..20224e0 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp @@ -0,0 +1,43 @@ +/** + * SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include + +void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) +{ + registrar.RegisterMethodChannel("sensors_plus_aurora", + MethodCodecType::Standard, + [this](const MethodCall &call) { this->onMethodCall(call); }); +} + +void SensorsPlusAuroraPlugin::onMethodCall(const MethodCall &call) +{ + const auto &method = call.GetMethod(); + + if (method == "getPlatformVersion") { + onGetPlatformVersion(call); + return; + } + + unimplemented(call); +} + +void SensorsPlusAuroraPlugin::onGetPlatformVersion(const MethodCall &call) +{ + utsname uname_data{}; + uname(&uname_data); + + std::string preamble = "Aurora (Linux): "; + std::string version = preamble + uname_data.version; + + call.SendSuccessResponse(version); +} + +void SensorsPlusAuroraPlugin::unimplemented(const MethodCall &call) +{ + call.SendSuccessResponse(nullptr); +} diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart new file mode 100644 index 0000000..bb338af --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart @@ -0,0 +1,8 @@ + +import 'sensors_plus_aurora_platform_interface.dart'; + +class SensorsPlusAurora { + Future getPlatformVersion() { + return SensorsPlusAuroraPlatform.instance.getPlatformVersion(); + } +} diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart new file mode 100644 index 0000000..3276f07 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart @@ -0,0 +1,17 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'sensors_plus_aurora_platform_interface.dart'; + +/// An implementation of [SensorsPlusAuroraPlatform] that uses method channels. +class MethodChannelSensorsPlusAurora extends SensorsPlusAuroraPlatform { + /// The method channel used to interact with the native platform. + @visibleForTesting + final methodChannel = const MethodChannel('sensors_plus_aurora'); + + @override + Future getPlatformVersion() async { + final version = await methodChannel.invokeMethod('getPlatformVersion'); + return version; + } +} diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart new file mode 100644 index 0000000..b3f71e4 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart @@ -0,0 +1,29 @@ +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'sensors_plus_aurora_method_channel.dart'; + +abstract class SensorsPlusAuroraPlatform extends PlatformInterface { + /// Constructs a SensorsPlusAuroraPlatform. + SensorsPlusAuroraPlatform() : super(token: _token); + + static final Object _token = Object(); + + static SensorsPlusAuroraPlatform _instance = MethodChannelSensorsPlusAurora(); + + /// The default instance of [SensorsPlusAuroraPlatform] to use. + /// + /// Defaults to [MethodChannelSensorsPlusAurora]. + static SensorsPlusAuroraPlatform get instance => _instance; + + /// Platform-specific implementations should set this with their own + /// platform-specific class that extends [SensorsPlusAuroraPlatform] when + /// they register themselves. + static set instance(SensorsPlusAuroraPlatform instance) { + PlatformInterface.verifyToken(instance, _token); + _instance = instance; + } + + Future getPlatformVersion() { + throw UnimplementedError('platformVersion() has not been implemented.'); + } +} diff --git a/packages/sensors_plus/sensors_plus_aurora/pubspec.yaml b/packages/sensors_plus/sensors_plus_aurora/pubspec.yaml new file mode 100644 index 0000000..f78c456 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/pubspec.yaml @@ -0,0 +1,26 @@ +# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +# SPDX-License-Identifier: BSD-3-Clause + +name: sensors_plus_aurora +description: A new Flutter plugin project. +version: 0.0.1 + +environment: + sdk: '>=2.18.6 <3.0.0' + flutter: ">=3.0.0" + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + +flutter: + plugin: + platforms: + aurora: + pluginClass: SensorsPlusAuroraPlugin diff --git a/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart b/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart new file mode 100644 index 0000000..8b01cf9 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause + +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:sensors_plus_aurora/sensors_plus_aurora_method_channel.dart'; + +void main() { + MethodChannelSensorsPlusAurora platform = MethodChannelSensorsPlusAurora(); + const MethodChannel channel = MethodChannel('sensors_plus_aurora'); + + TestWidgetsFlutterBinding.ensureInitialized(); + + setUp(() { + channel.setMockMethodCallHandler((MethodCall methodCall) async { + return '42'; + }); + }); + + tearDown(() { + channel.setMockMethodCallHandler(null); + }); + + test('getPlatformVersion', () async { + expect(await platform.getPlatformVersion(), '42'); + }); +} diff --git a/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart b/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart new file mode 100644 index 0000000..59beaa1 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart @@ -0,0 +1,32 @@ +// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause + +import 'package:flutter_test/flutter_test.dart'; +import 'package:sensors_plus_aurora/sensors_plus_aurora.dart'; +import 'package:sensors_plus_aurora/sensors_plus_aurora_platform_interface.dart'; +import 'package:sensors_plus_aurora/sensors_plus_aurora_method_channel.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +class MockSensorsPlusAuroraPlatform + with MockPlatformInterfaceMixin + implements SensorsPlusAuroraPlatform { + + @override + Future getPlatformVersion() => Future.value('42'); +} + +void main() { + final SensorsPlusAuroraPlatform initialPlatform = SensorsPlusAuroraPlatform.instance; + + test('$MethodChannelSensorsPlusAurora is the default instance', () { + expect(initialPlatform, isInstanceOf()); + }); + + test('getPlatformVersion', () async { + SensorsPlusAurora sensorsPlusAuroraPlugin = SensorsPlusAurora(); + MockSensorsPlusAuroraPlatform fakePlatform = MockSensorsPlusAuroraPlatform(); + SensorsPlusAuroraPlatform.instance = fakePlatform; + + expect(await sensorsPlusAuroraPlugin.getPlatformVersion(), '42'); + }); +}