-
Notifications
You must be signed in to change notification settings - Fork 52
[permission_handler] Refactor the C++ code #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
swift-kim
merged 2 commits into
flutter-tizen:master
from
swift-kim:refactor-permission-handler
May 18, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ## NEXT | ||
|
|
||
| * Code refactoring. | ||
|
|
||
| ## 1.2.0 | ||
|
|
||
| * Update permission_handler to 8.3.0. | ||
|
|
||
164 changes: 62 additions & 102 deletions
164
packages/permission_handler/tizen/src/app_settings_manager.cc
This file contains hidden or 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 |
|---|---|---|
| @@ -1,126 +1,86 @@ | ||
| // Copyright 2021 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. | ||
|
|
||
| #include "app_settings_manager.h" | ||
|
|
||
| #include <app_common.h> | ||
| #include <app_control.h> | ||
| #include <package_manager.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "log.h" | ||
|
|
||
| namespace { | ||
| constexpr char kPackageID[] = "pkgId"; | ||
| constexpr char kSettingAppID[] = "com.samsung.clocksetting.apps"; | ||
|
|
||
| class AppPermissions { | ||
| public: | ||
| AppPermissions() { Init(); } | ||
|
|
||
| ~AppPermissions() { Deinit(); } | ||
|
|
||
| bool Launch(const std::string& package_name) { | ||
| if (package_name.length() == 0) { | ||
| return false; | ||
| } | ||
|
|
||
| int ret = app_control_add_extra_data(app_control_, kPackageID, | ||
| package_name.c_str()); | ||
| if (ret != APP_CONTROL_ERROR_NONE) { | ||
| LOG_ERROR("Failed to add key[%s]:value[%s]", kPackageID, | ||
| package_name.c_str()); | ||
| return false; | ||
| } | ||
|
|
||
| ret = app_control_send_launch_request(app_control_, nullptr, nullptr); | ||
| if (ret != APP_CONTROL_ERROR_NONE) { | ||
| LOG_ERROR("Failed to send launch request setting"); | ||
| return false; | ||
| } | ||
| return true; | ||
|
|
||
| constexpr char kSettingAppId[] = "com.samsung.clocksetting.apps"; | ||
|
|
||
| std::string GetPackageName() { | ||
| char* app_id; | ||
| int ret = app_get_id(&app_id); | ||
| if (ret != APP_ERROR_NONE) { | ||
| LOG_ERROR("The app ID is not found."); | ||
| return ""; | ||
| } | ||
|
|
||
| private: | ||
| void Init() { | ||
| int ret = app_control_create(&app_control_); | ||
| if (ret != APP_CONTROL_ERROR_NONE) { | ||
| LOG_ERROR("Failed to create app control handle"); | ||
| } | ||
|
|
||
| ret = app_control_set_app_id(app_control_, kSettingAppID); | ||
| if (ret != APP_CONTROL_ERROR_NONE) { | ||
| LOG_ERROR("Failed to set app id[%s]", kSettingAppID); | ||
| } | ||
| package_info_h package_info; | ||
| ret = package_info_create(app_id, &package_info); | ||
| free(app_id); | ||
| if (ret != PACKAGE_MANAGER_ERROR_NONE) { | ||
| LOG_ERROR("Failed to create a package info handle."); | ||
| return ""; | ||
| } | ||
|
|
||
| void Deinit() { | ||
| if (app_control_) { | ||
| app_control_destroy(app_control_); | ||
| app_control_ = nullptr; | ||
| } | ||
| char* package_name; | ||
| ret = package_info_get_package(package_info, &package_name); | ||
| package_info_destroy(package_info); | ||
| if (ret != PACKAGE_MANAGER_ERROR_NONE) { | ||
| LOG_ERROR("Failed to get the package name."); | ||
| return ""; | ||
| } | ||
|
|
||
| app_control_h app_control_{nullptr}; | ||
| }; | ||
|
|
||
| class PackageName { | ||
| public: | ||
| PackageName() { Init(); } | ||
|
|
||
| ~PackageName() { Deinit(); } | ||
|
|
||
| char* Get() { return package_name_; } | ||
|
|
||
| private: | ||
| void Init() { | ||
| int ret = app_get_id(&app_id_); | ||
| if (ret != APP_ERROR_NONE || app_id_ == nullptr) { | ||
| LOG_ERROR("Failed to get app id"); | ||
| return; | ||
| } | ||
|
|
||
| ret = package_info_create(app_id_, &package_info_); | ||
| if (ret != PACKAGE_MANAGER_ERROR_NONE || package_info_ == nullptr) { | ||
| LOG_ERROR("Failed to create package info handle"); | ||
| } | ||
| ret = package_info_get_package(package_info_, &package_name_); | ||
| if (ret != PACKAGE_MANAGER_ERROR_NONE || package_name_ == nullptr) { | ||
| LOG_ERROR("Failed to get package name"); | ||
| } | ||
| std::string result = std::string(package_name); | ||
| free(package_name); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| bool AppSettingsManager::OpenAppSettings() { | ||
| std::string package_name = GetPackageName(); | ||
| if (package_name.empty()) { | ||
| return false; | ||
| } | ||
|
|
||
| void Deinit() { | ||
| if (app_id_) { | ||
| free(app_id_); | ||
| app_id_ = nullptr; | ||
| } | ||
|
|
||
| if (package_info_) { | ||
| package_info_destroy(package_info_); | ||
| package_info_ = nullptr; | ||
| } | ||
|
|
||
| if (package_name_) { | ||
| free(package_name_); | ||
| package_name_ = nullptr; | ||
| } | ||
| app_control_h app_control; | ||
| int ret = app_control_create(&app_control); | ||
| if (ret != APP_CONTROL_ERROR_NONE) { | ||
| LOG_ERROR("Failed to create an app control handle."); | ||
| return false; | ||
| } | ||
|
|
||
| char* app_id_{nullptr}; | ||
| package_info_h package_info_{nullptr}; | ||
| char* package_name_{nullptr}; | ||
| }; | ||
| } // namespace | ||
| ret = app_control_set_app_id(app_control, kSettingAppId); | ||
| if (ret != APP_CONTROL_ERROR_NONE) { | ||
| LOG_ERROR("Failed to set an app ID."); | ||
| app_control_destroy(app_control); | ||
| return false; | ||
| } | ||
|
|
||
| AppSettingsManager::AppSettingsManager() { | ||
| app_permissions_ = std::make_unique<AppPermissions>(); | ||
| PackageName pkg_name; | ||
| char* name = pkg_name.Get(); | ||
| if (name == nullptr) { | ||
| return; | ||
| ret = app_control_add_extra_data(app_control, "pkgId", package_name.c_str()); | ||
| if (ret != APP_CONTROL_ERROR_NONE) { | ||
| LOG_ERROR("Failed to add extra data."); | ||
| app_control_destroy(app_control); | ||
| return false; | ||
| } | ||
| package_name_ = std::string(name); | ||
| } | ||
|
|
||
| AppSettingsManager::~AppSettingsManager() {} | ||
| ret = app_control_send_launch_request(app_control, nullptr, nullptr); | ||
| app_control_destroy(app_control); | ||
| if (ret != APP_CONTROL_ERROR_NONE) { | ||
| LOG_ERROR("Failed to send a launch request."); | ||
| return false; | ||
| } | ||
|
|
||
| bool AppSettingsManager::OpenAppSettings() { | ||
| return app_permissions_->Launch(package_name_); | ||
| return true; | ||
| } |
24 changes: 8 additions & 16 deletions
24
packages/permission_handler/tizen/src/app_settings_manager.h
This file contains hidden or 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 |
|---|---|---|
| @@ -1,24 +1,16 @@ | ||
| #ifndef APP_SETTINGS_MANAGER_H_ | ||
| #define APP_SETTINGS_MANAGER_H_ | ||
| // Copyright 2021 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. | ||
|
|
||
| #include <functional> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| namespace { | ||
| class AppPermissions; | ||
| } | ||
| #ifndef FLUTTER_PLUGIN_APP_SETTINGS_MANAGER_H_ | ||
| #define FLUTTER_PLUGIN_APP_SETTINGS_MANAGER_H_ | ||
|
|
||
| class AppSettingsManager { | ||
| public: | ||
| AppSettingsManager(); | ||
| ~AppSettingsManager(); | ||
| AppSettingsManager() {} | ||
| ~AppSettingsManager() {} | ||
|
|
||
| bool OpenAppSettings(); | ||
|
|
||
| private: | ||
| std::unique_ptr<AppPermissions> app_permissions_; | ||
| std::string package_name_; | ||
| }; | ||
|
|
||
| #endif // APP_SETTINGS_MANAGER_H_ | ||
| #endif // FLUTTER_PLUGIN_APP_SETTINGS_MANAGER_H_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.