Skip to content

Commit

Permalink
Use PlatformException instead of plugin-specific exception types (flu…
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-kim authored Mar 2, 2021
1 parent 0436126 commit c40bf67
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 57 deletions.
5 changes: 5 additions & 0 deletions packages/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
* Update platform interface to the latest (1.0.4)
* Remove permission_handler_tizen dependency temporarily
* Migrate to Tizen 4.0

## 1.0.2

* Use `PlatformException` instead of a plugin-specific exception type
(`StorageException`)
2 changes: 1 addition & 1 deletion packages/path_provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This package is not an _endorsed_ implementation of `path_provider`. Therefore,
```yaml
dependencies:
path_provider: ^1.6.27
path_provider_tizen: ^1.0.1
path_provider_tizen: ^1.0.2
```
Then you can import `path_provider` in your Dart code:
Expand Down
28 changes: 11 additions & 17 deletions packages/path_provider/lib/src/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'dart:async';
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:flutter/services.dart';

// Native function signatures
typedef storage_get_directory = Int32 Function(
Expand All @@ -26,16 +27,6 @@ enum StorageDirectoryType {
system_ringtones,
}

class StorageException {
StorageException(this.returnCode, this.message);

final int returnCode;
final String message;

@override
String toString() => '$message ($returnCode)';
}

Storage _storageInstance;
Storage get storage => _storageInstance ??= Storage();

Expand All @@ -60,8 +51,10 @@ class Storage {
final int ret = _storageForeachDeviceSupported(
Pointer.fromFunction(_deviceSupportedCallback, 0), nullptr);
if (ret != 0) {
throw StorageException(
ret, 'Failed to execute storage_foreach_device_supported.');
throw PlatformException(
code: '$ret',
message: 'Failed to execute storage_foreach_device_supported.',
);
}
}

Expand Down Expand Up @@ -96,11 +89,12 @@ class Storage {
}) async {
final Pointer<Pointer<Utf8>> path = allocate();
try {
final int result =
_storageGetDirectory(await storageId, type.index, path);
if (result != 0) {
throw StorageException(
result, 'Failed to execute storage_get_directory.');
final int ret = _storageGetDirectory(await storageId, type.index, path);
if (ret != 0) {
throw PlatformException(
code: '$ret',
message: 'Failed to execute storage_get_directory.',
);
}
return Utf8.fromUtf8(path.value);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion packages/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: path_provider_tizen
description: Tizen implementation of the path_provider plugin
version: 1.0.1
version: 1.0.2
homepage: https://github.com/flutter-tizen/plugins

flutter:
Expand Down
6 changes: 6 additions & 0 deletions packages/url_launcher/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@
* Update url_launcher to 5.7.10
* Update platform interface to 1.0.9
* Increase the minimum framework requirement to 1.22.0

## 1.0.3

* Use `PlatformException` instead of a plugin-specific exception type
(`AppControlException`)
* Move `app_control.dart` to the implementation directory
9 changes: 6 additions & 3 deletions packages/url_launcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This package is not an _endorsed_ implementation of `url_launcher`. Therefore, y
```yaml
dependencies:
url_launcher: ^5.7.10
url_launcher_tizen: ^1.0.2
url_launcher_tizen: ^1.0.3
```
Then you can import `url_launcher` in your Dart code:
Expand All @@ -20,8 +20,6 @@ import 'package:url_launcher/url_launcher.dart';

For detailed usage, see https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher#usage.

An `AppControlException` is raised if no application on the device can launch the requested URL.

## Required privileges

To use this plugin in a Tizen application, the application manager privilege is required. Add below lines under the `<manifest>` section in your `tizen-manifest.xml` file.
Expand All @@ -33,3 +31,8 @@ To use this plugin in a Tizen application, the application manager privilege is
```

For details, see [Security and API Privileges](https://docs.tizen.org/application/dotnet/tutorials/sec-privileges).

## Notes

- A `PlatformException` is raised if no application on the device can open the provided URL.
- The `launch` method's optional parameters (e.g. `useWebView`) are not currently supported on Tizen.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:flutter/services.dart';

// Native function signatures
typedef app_control_create = Int32 Function(Pointer<Pointer<_AppControl>>);
Expand Down Expand Up @@ -38,32 +39,24 @@ const int TIZEN_ERROR_IO_ERROR = -5;

class _AppControl extends Struct {}

/// A class representing non-zero errors from the platform.
class AppControlException {
const AppControlException(this.returnCode, this.message);

final int returnCode;
final String message;

// Constants from [app_control_error_e] in `app_control.h`
static const Map<int, String> errorCodes = <int, String>{
TIZEN_ERROR_NONE: 'APP_CONTROL_ERROR_NONE',
TIZEN_ERROR_INVALID_PARAMETER: 'APP_CONTROL_ERROR_INVALID_PARAMETER',
TIZEN_ERROR_OUT_OF_MEMORY: 'APP_CONTROL_ERROR_OUT_OF_MEMORY',
TIZEN_ERROR_APPLICATION | 0x21: 'APP_CONTROL_ERROR_APP_NOT_FOUND',
TIZEN_ERROR_KEY_NOT_AVAILABLE: 'APP_CONTROL_ERROR_KEY_NOT_FOUND',
TIZEN_ERROR_KEY_REJECTED: 'APP_CONTROL_ERROR_KEY_REJECTED',
TIZEN_ERROR_APPLICATION | 0x22: 'APP_CONTROL_ERROR_INVALID_DATA_TYPE',
TIZEN_ERROR_APPLICATION | 0x23: 'APP_CONTROL_ERROR_LAUNCH_REJECTED',
TIZEN_ERROR_PERMISSION_DENIED: 'APP_CONTROL_ERROR_PERMISSION_DENIED',
TIZEN_ERROR_APPLICATION | 0x24: 'APP_CONTROL_ERROR_LAUNCH_FAILED',
TIZEN_ERROR_TIMED_OUT: 'APP_CONTROL_ERROR_TIMED_OUT',
TIZEN_ERROR_IO_ERROR: 'APP_CONTROL_ERROR_IO_ERROR',
};

@override
String toString() => '$message (${errorCodes[returnCode] ?? returnCode})';
}
// Constants from [app_control_error_e] in `app_control.h`
const Map<int, String> errorCodes = <int, String>{
TIZEN_ERROR_NONE: 'APP_CONTROL_ERROR_NONE',
TIZEN_ERROR_INVALID_PARAMETER: 'APP_CONTROL_ERROR_INVALID_PARAMETER',
TIZEN_ERROR_OUT_OF_MEMORY: 'APP_CONTROL_ERROR_OUT_OF_MEMORY',
TIZEN_ERROR_APPLICATION | 0x21: 'APP_CONTROL_ERROR_APP_NOT_FOUND',
TIZEN_ERROR_KEY_NOT_AVAILABLE: 'APP_CONTROL_ERROR_KEY_NOT_FOUND',
TIZEN_ERROR_KEY_REJECTED: 'APP_CONTROL_ERROR_KEY_REJECTED',
TIZEN_ERROR_APPLICATION | 0x22: 'APP_CONTROL_ERROR_INVALID_DATA_TYPE',
TIZEN_ERROR_APPLICATION | 0x23: 'APP_CONTROL_ERROR_LAUNCH_REJECTED',
TIZEN_ERROR_PERMISSION_DENIED: 'APP_CONTROL_ERROR_PERMISSION_DENIED',
TIZEN_ERROR_APPLICATION | 0x24: 'APP_CONTROL_ERROR_LAUNCH_FAILED',
TIZEN_ERROR_TIMED_OUT: 'APP_CONTROL_ERROR_TIMED_OUT',
TIZEN_ERROR_IO_ERROR: 'APP_CONTROL_ERROR_IO_ERROR',
};

String getErrorCode(int returnCode) =>
errorCodes.containsKey(returnCode) ? errorCodes[returnCode] : '$returnCode';

/// A wrapper class of the native App Control API.
/// Not all functions or values are supported.
Expand Down Expand Up @@ -109,7 +102,10 @@ class AppControl {
free(pHandle);

if (ret != 0) {
throw AppControlException(ret, 'Failed to execute app_control_create.');
throw PlatformException(
code: getErrorCode(ret),
message: 'Failed to execute app_control_create.',
);
}
}

Expand All @@ -118,8 +114,10 @@ class AppControl {

final int ret = _setOperation(_handle, Utf8.toUtf8(operation));
if (ret != 0) {
throw AppControlException(
ret, 'Failed to execute app_control_set_operation.');
throw PlatformException(
code: getErrorCode(ret),
message: 'Failed to execute app_control_set_operation.',
);
}
}

Expand All @@ -128,7 +126,10 @@ class AppControl {

final int ret = _setUri(_handle, Utf8.toUtf8(uri));
if (ret != 0) {
throw AppControlException(ret, 'Failed to execute app_control_set_uri.');
throw PlatformException(
code: getErrorCode(ret),
message: 'Failed to execute app_control_set_uri.',
);
}
}

Expand All @@ -137,8 +138,10 @@ class AppControl {

final int ret = _sendLaunchRequest(_handle, nullptr, nullptr);
if (ret != 0) {
throw AppControlException(
ret, 'Failed to execute app_control_send_launch_request.');
throw PlatformException(
code: getErrorCode(ret),
message: 'Failed to execute app_control_send_launch_request.',
);
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/url_launcher/lib/url_launcher_tizen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:meta/meta.dart';
import 'package:url_launcher_platform_interface/link.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

import 'app_control.dart';
import 'src/app_control.dart';

class UrlLauncherPlugin extends UrlLauncherPlatform {
static final Set<String> _supportedSchemes = <String>{
Expand All @@ -35,7 +35,6 @@ class UrlLauncherPlugin extends UrlLauncherPlatform {
@override
Future<bool> launch(
String url, {
// None of these options are used in Tizen.
@required bool useSafariVC,
@required bool useWebView,
@required bool enableJavaScript,
Expand Down
2 changes: 1 addition & 1 deletion packages/url_launcher/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: url_launcher_tizen
description: Tizen implementation of the url_launcher plugin
homepage: https://github.com/flutter-tizen/plugins
version: 1.0.2
version: 1.0.3

flutter:
plugin:
Expand Down

0 comments on commit c40bf67

Please sign in to comment.