Skip to content

Commit

Permalink
[permission_handler] Support Tizen 4.0 (#139)
Browse files Browse the repository at this point in the history
* [permission_handler] Support Tizen 4.0

* Use ppm_request_permission instead of ppm_request_permissions
* Now the requests are executed sequentially, one by one

Signed-off-by: Boram Bae <boram21.bae@samsung.com>

* [permission_handler] Update based on review

* Change a long lambda to local function to improve readability
* Apply naming convention
* Use enum class instead of enum
* Use constexpr rather than macro

Signed-off-by: Boram Bae <boram21.bae@samsung.com>
  • Loading branch information
bbrto21 committed Jul 5, 2021
1 parent 77b30f8 commit b969b33
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 289 deletions.
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.tizen.permission_handler_tizen_example" version="1.0.0" api-version="5.5" xmlns="http://tizen.org/ns/packages">
<manifest package="org.tizen.permission_handler_tizen_example" version="1.0.0" api-version="4.0" xmlns="http://tizen.org/ns/packages">
<profile name="common"/>
<ui-application appid="org.tizen.permission_handler_tizen_example" exec="Runner.dll" type="dotnet" multiple="false" taskmanage="true" nodisplay="false" api-version="4" launch_mode="single">
<label>permission_handler_tizen_example</label>
Expand Down
2 changes: 1 addition & 1 deletion packages/permission_handler/tizen/project_def.prop
Expand Up @@ -3,7 +3,7 @@

APPNAME = permission_handler_tizen_plugin
type = sharedLib
profile = common-5.5
profile = common-4.0

# Source files
USER_SRCS += src/permission_manager.cc src/app_settings_manager.cc src/service_manager.cc src/permission_handler_tizen_plugin.cc
Expand Down
Expand Up @@ -9,15 +9,17 @@
#include "permission_manager.h"
#include "service_manager.h"

#define PERMISSION_HANDLER_CHANNEL_NAME \
"flutter.baseflow.com/permissions/methods"
namespace {
constexpr char kPermissionHandlerChannelName[] =
"flutter.baseflow.com/permissions/methods";
}

class PermissionHandlerTizenPlugin : public flutter::Plugin {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar) {
auto channel =
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
registrar->messenger(), PERMISSION_HANDLER_CHANNEL_NAME,
registrar->messenger(), kPermissionHandlerChannelName,
&flutter::StandardMethodCodec::GetInstance());

auto plugin = std::make_unique<PermissionHandlerTizenPlugin>();
Expand Down Expand Up @@ -46,16 +48,17 @@ class PermissionHandlerTizenPlugin : public flutter::Plugin {
if (std::holds_alternative<int32_t>(*arguments)) {
int permission = std::get<int32_t>(*arguments);
auto reply = result.release();
auto on_success = [reply](int status) {
reply->Success(flutter::EncodableValue(status));
auto on_success = [reply](ServiceStatus status) {
reply->Success(flutter::EncodableValue(static_cast<int>(status)));
delete reply;
};
auto on_error = [reply](const std::string &code,
const std::string &message) {
reply->Error(code, message);
delete reply;
};
service_manager_.CheckServiceStatus(permission, on_success, on_error);
service_manager_.CheckServiceStatus(
static_cast<PermissionGroup>(permission), on_success, on_error);
} else {
result->Error("MethodCall - Invalid arguments",
"arguments type of method checkServiceStatus isn't int");
Expand All @@ -65,17 +68,17 @@ class PermissionHandlerTizenPlugin : public flutter::Plugin {
if (std::holds_alternative<int32_t>(*arguments)) {
int permission = std::get<int32_t>(*arguments);
auto reply = result.release();
auto on_success = [reply](int status) {
reply->Success(flutter::EncodableValue(status));
auto on_success = [reply](PermissionStatus status) {
reply->Success(flutter::EncodableValue(static_cast<int>(status)));
delete reply;
};
auto on_error = [reply](const std::string &code,
const std::string &message) {
reply->Error(code, message);
delete reply;
};
permission_manager_.CheckPermissionStatus(permission, on_success,
on_error);
permission_manager_.CheckPermissionStatus(
static_cast<PermissionGroup>(permission), on_success, on_error);
} else {
result->Error(
"MethodCall - Invalid arguments",
Expand All @@ -84,20 +87,24 @@ class PermissionHandlerTizenPlugin : public flutter::Plugin {
} else if (method_name.compare("requestPermissions") == 0) {
const flutter::EncodableValue *arguments = method_call.arguments();
if (std::holds_alternative<flutter::EncodableList>(*arguments)) {
std::vector<int> permissions;
std::vector<PermissionGroup> permissions;
for (auto iter : std::get<flutter::EncodableList>(*arguments)) {
permissions.push_back(std::get<int32_t>(iter));
permissions.push_back(
static_cast<PermissionGroup>(std::get<int32_t>(iter)));
}
auto reply = result.release();
auto on_success = [reply](const std::map<int, int> &results) {
flutter::EncodableMap encodables;
for (auto [key, value] : results) {
encodables.emplace(flutter::EncodableValue(key),
flutter::EncodableValue(value));
}
reply->Success(flutter::EncodableValue(encodables));
delete reply;
};
auto on_success =
[reply](
const std::map<PermissionGroup, PermissionStatus> &results) {
flutter::EncodableMap encodables;
for (auto [key, value] : results) {
encodables.emplace(
flutter::EncodableValue(static_cast<int>(key)),
flutter::EncodableValue(static_cast<int>(value)));
}
reply->Success(flutter::EncodableValue(encodables));
delete reply;
};
auto on_error = [reply](const std::string &code,
const std::string &message) {
reply->Error(code, message);
Expand Down

0 comments on commit b969b33

Please sign in to comment.