Skip to content

Commit

Permalink
[tizen_app_manager] Add tizen_app_manager package (flutter-tizen#325)
Browse files Browse the repository at this point in the history
* 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
jkpu authored Feb 21, 2022
1 parent 3196114 commit 1becadd
Show file tree
Hide file tree
Showing 29 changed files with 1,824 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
- packages/share_plus/**/*
'p: tizen_app_control':
- packages/tizen_app_control/**/*
'p: tizen_app_manager':
- packages/tizen_app_manager/**/*
'p: tizen_audio_manager':
- packages/tizen_audio_manager/**/*
'p: url_launcher':
Expand Down
1 change: 1 addition & 0 deletions .github/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins:
share_plus: ["wearable-5.5"]
shared_preferences: ["wearable-5.5", "tv-6.0"]
sqflite: ["wearable-5.5", "tv-6.0"]
tizen_app_manager: ["wearable-5.5", "tv-6.0"]
tizen_audio_manager: ["wearable-5.5", "tv-6.0"]
wakelock: ["wearable-5.5"]

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
| [**shared_preferences_tizen**](packages/shared_preferences) | [shared_preferences](https://github.com/flutter/plugins/tree/master/packages/shared_preferences) (1st-party) | [![pub package](https://img.shields.io/pub/v/shared_preferences_tizen.svg)](https://pub.dev/packages/shared_preferences_tizen) | No |
| [**sqflite_tizen**](packages/sqflite) | [sqflite](https://github.com/tekartik/sqflite) (3rd-party) | [![pub package](https://img.shields.io/pub/v/sqflite_tizen.svg)](https://pub.dev/packages/sqflite_tizen) | No |
| [**tizen_app_control**](packages/tizen_app_control) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/tizen_app_control.svg)](https://pub.dev/packages/tizen_app_control) | N/A |
| [**tizen_app_manager**](packages/tizen_app_manager) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/tizen_app_manager.svg)](https://pub.dev/packages/tizen_app_manager) | N/A |
| [**tizen_audio_manager**](packages/tizen_audio_manager) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/tizen_audio_manager.svg)](https://pub.dev/packages/tizen_audio_manager) | N/A |
| [**tizen_notification**](packages/tizen_notification) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/tizen_notification.svg)](https://pub.dev/packages/tizen_notification) | N/A |
| [**url_launcher_tizen**](packages/url_launcher) | [url_launcher](https://github.com/flutter/plugins/tree/master/packages/url_launcher) (1st-party) | [![pub package](https://img.shields.io/pub/v/url_launcher_tizen.svg)](https://pub.dev/packages/url_launcher_tizen) | No |
Expand Down Expand Up @@ -66,6 +67,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
| [**shared_preferences_tizen**](packages/shared_preferences) | ✔️ | ✔️ | ✔️ | ✔️ |
| [**sqflite_tizen**](packages/sqflite) | ✔️ | ✔️ | ✔️ | ✔️ |
| [**tizen_app_control**](packages/tizen_app_control) | ✔️ | ✔️ | ✔️ | ✔️ |
| [**tizen_app_manager**](packages/tizen_app_manager) | ✔️ | ✔️ | ✔️ | ✔️ |
| [**tizen_audio_manager**](packages/tizen_audio_manager) | ✔️ | ✔️ | ✔️ | ✔️ |
| [**tizen_notification**](packages/tizen_notification) || ✔️ | ✔️ | ✔️ | API not supported |
| [**url_launcher_tizen**](packages/url_launcher) | ✔️ || ✔️ || No browser app |
Expand Down
7 changes: 7 additions & 0 deletions packages/tizen_app_manager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.dart_tool/

.packages
.pub/

build/
4 changes: 4 additions & 0 deletions packages/tizen_app_manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 0.1.0

* Initial release.

25 changes: 25 additions & 0 deletions packages/tizen_app_manager/LICENSE
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.
88 changes: 88 additions & 0 deletions packages/tizen_app_manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# tizen_app_manager

[![pub package](https://img.shields.io/pub/v/tizen_app_manager.svg)](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>
```
46 changes: 46 additions & 0 deletions packages/tizen_app_manager/example/.gitignore
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
7 changes: 7 additions & 0 deletions packages/tizen_app_manager/example/README.md
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).
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);
});
}
Loading

0 comments on commit 1becadd

Please sign in to comment.