forked from flutter-tizen/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tizen_app_manager] Add tizen_app_manager package (flutter-tizen#325)
* initial commit of application_manager plugin * modify related yml file and fix lint errors * rename pacakge: from tizen_application_manager to tizen_app_manager * add integration_test and fix dart analysis issues * Fix code review issues and add documents * integrate test pages code to main dart * split launch/terminate event stream * fix style format issues * modify README and fix typo * use get_error_message() and fix some review issues * fix conflict file * fix some tizen native code issue * Fix API documents and code review issues * fix dart analysis issue * fix some minor issues
- Loading branch information
Showing
29 changed files
with
1,824 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
.dart_tool/ | ||
|
||
.packages | ||
.pub/ | ||
|
||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## 0.1.0 | ||
|
||
* Initial release. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright (c) 2022 Samsung Electronics Co., Ltd. All rights reserved. | ||
|
||
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 names of the copyright holders nor the names of the | ||
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 OWNER 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# tizen_app_manager | ||
|
||
[](https://pub.dev/packages/tizen_app_manager) | ||
|
||
Tizen application manager API. Used for getting installed app info and getting running context info of specific app. | ||
|
||
## Usage | ||
|
||
To use this package, add `tizen_app_manager` as a dependency in your `pubspec.yaml` file. | ||
|
||
```yaml | ||
dependencies: | ||
tizen_app_manager: ^0.1.0 | ||
``` | ||
### Retrieving current app info | ||
To retrieve information of the current app, get app ID with `currentAppId` and then get `AppInfo` with `getAppInfo` method. | ||
|
||
```dart | ||
var appId = await AppManager.currentAppId; | ||
var appInfo = await AppManager.getAppInfo(appId); | ||
``` | ||
|
||
### Retrieving all apps info | ||
|
||
To retrieve information of all apps installed on a Tizen device, use `getInstalledApps` method. | ||
|
||
```dart | ||
var apps = await AppManager.getInstalledApps(); | ||
for (var app in apps) { | ||
// Handle each app's info. | ||
} | ||
``` | ||
|
||
### Getting app running context | ||
|
||
To get specific app running context, create `AppRunningContext` instance. | ||
|
||
```dart | ||
var appId = await AppManager.currentAppId; | ||
var appContext = AppRunningContext(appId: appId); | ||
``` | ||
|
||
### Monitoring app events | ||
|
||
You can listen for app state change by subscribing to the stream. | ||
|
||
```dart | ||
final List<StreamSubscription<AppRunningContext>> _subscriptions = | ||
<StreamSubscription<AppRunningContext>>[]; | ||
@override | ||
void initState() { | ||
super.initState(); | ||
_subscriptions.add(AppManager.onAppLaunched | ||
.listen((AppRunningContext event) { | ||
// Handle the launched event. | ||
... | ||
event.dispose(); | ||
})); | ||
_subscriptions.add(AppManager.onAppTerminated | ||
.listen((AppRunningContext event) { | ||
// Handle the terminated event. | ||
... | ||
event.dispose(); | ||
})); | ||
} | ||
@override | ||
void dispose() { | ||
super.dispose(); | ||
_subscriptions.forEach((StreamSubscription subscription) => subscription.cancel()); | ||
_subscriptions.clear(); | ||
} | ||
``` | ||
|
||
## Required privileges | ||
|
||
The following privilege is required to invoke `AppRunningContext.resume()`. Add required privileges in `tizen-manifest.xml` of your application. | ||
|
||
```xml | ||
<privileges> | ||
<privilege>http://tizen.org/privilege/appmanager.launch</privilege> | ||
</privileges> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# 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 | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Web related | ||
lib/generated_plugin_registrant.dart | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Android Studio will place build artifacts here | ||
/android/app/debug | ||
/android/app/profile | ||
/android/app/release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# tizen_app_manager_example | ||
|
||
Demonstrates how to use the tizen_app_manager plugin. | ||
|
||
## Getting Started | ||
|
||
To run this app on your Tizen device, use [flutter-tizen](https://github.com/flutter-tizen/flutter-tizen). |
34 changes: 34 additions & 0 deletions
34
packages/tizen_app_manager/example/integration_test/tizen_app_manager_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2022 Samsung Electronics Co., Ltd. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:tizen_app_manager/app_manager.dart'; | ||
|
||
import 'package:tizen_app_manager_example/main.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
testWidgets('Can get current app info', (WidgetTester tester) async { | ||
// These test are based on the example app. | ||
final String appId = await AppManager.currentAppId; | ||
expect(appId, 'com.example.tizen_app_manager_example'); | ||
final AppInfo appInfo = await AppManager.getAppInfo(appId); | ||
expect(appInfo.packageId, 'com.example.tizen_app_manager_example'); | ||
expect(appInfo.label, 'tizen_app_manager_example'); | ||
expect(appInfo.appType, 'dotnet'); | ||
}); | ||
|
||
testWidgets('Can get current app running context', | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget(const MyApp()); | ||
|
||
final String appId = await AppManager.currentAppId; | ||
final AppRunningContext context = AppRunningContext(appId: appId); | ||
expect(context.appState, AppState.foreground); | ||
expect(context.processId, isPositive); | ||
expect(context.isTerminated, isFalse); | ||
}); | ||
} |
Oops, something went wrong.