Browse Source

[sensors-plus] Start implementation package sensors_plus. OMP#OS-17084

merge-requests/27/head
Vitaliy Zarubin 2 years ago
parent
commit
4d54d442d5
  1. 131
      example/app_run.sh
  2. 30
      packages/sensors_plus/sensors_plus_aurora/.gitignore
  3. 30
      packages/sensors_plus/sensors_plus_aurora/.metadata
  4. 22
      packages/sensors_plus/sensors_plus_aurora/README.md
  5. 4
      packages/sensors_plus/sensors_plus_aurora/analysis_options.yaml
  6. 26
      packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt
  7. 15
      packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/globals.h
  8. 23
      packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h
  9. 43
      packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp
  10. 8
      packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart
  11. 17
      packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart
  12. 29
      packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart
  13. 26
      packages/sensors_plus/sensors_plus_aurora/pubspec.yaml
  14. 27
      packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart
  15. 32
      packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart

131
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 <community@omp.ru>
# 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 <ip>:<password> \
## -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

30
packages/sensors_plus/sensors_plus_aurora/.gitignore vendored

@ -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/

30
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'

22
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
```

4
packages/sensors_plus/sensors_plus_aurora/analysis_options.yaml

@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
# SPDX-License-Identifier: BSD-3-Clause
include: package:flutter_lints/flutter.yaml

26
packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt

@ -0,0 +1,26 @@
# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
# 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)

15
packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/globals.h

@ -0,0 +1,15 @@
/**
* SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
* 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 */

23
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 <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H
#define FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H
#include <flutter/plugin-interface.h>
#include <sensors_plus_aurora/globals.h>
class PLUGIN_EXPORT SensorsPlusAuroraPlugin final : public PluginInterface
{
public:
void RegisterWithRegistrar(PluginRegistrar &registrar) 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 */

43
packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp

@ -0,0 +1,43 @@
/**
* SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <sensors_plus_aurora/sensors_plus_aurora_plugin.h>
#include <flutter/method-channel.h>
#include <sys/utsname.h>
void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar &registrar)
{
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);
}

8
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<String?> getPlatformVersion() {
return SensorsPlusAuroraPlatform.instance.getPlatformVersion();
}
}

17
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<String?> getPlatformVersion() async {
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
}
}

29
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<String?> getPlatformVersion() {
throw UnimplementedError('platformVersion() has not been implemented.');
}
}

26
packages/sensors_plus/sensors_plus_aurora/pubspec.yaml

@ -0,0 +1,26 @@
# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
# 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

27
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 <community@omp.ru>
// 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');
});
}

32
packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart

@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
// 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<String?> getPlatformVersion() => Future.value('42');
}
void main() {
final SensorsPlusAuroraPlatform initialPlatform = SensorsPlusAuroraPlatform.instance;
test('$MethodChannelSensorsPlusAurora is the default instance', () {
expect(initialPlatform, isInstanceOf<MethodChannelSensorsPlusAurora>());
});
test('getPlatformVersion', () async {
SensorsPlusAurora sensorsPlusAuroraPlugin = SensorsPlusAurora();
MockSensorsPlusAuroraPlatform fakePlatform = MockSensorsPlusAuroraPlatform();
SensorsPlusAuroraPlatform.instance = fakePlatform;
expect(await sensorsPlusAuroraPlugin.getPlatformVersion(), '42');
});
}
Loading…
Cancel
Save