From 58c2a21143dd312911b36a6831337bca5bc5b795 Mon Sep 17 00:00:00 2001 From: sunyaozu Date: Tue, 22 Mar 2022 15:47:18 +0800 Subject: [PATCH] add interface permission Signed-off-by: sunyaozu --- bundle.json | 4 ++- frameworks/intl/BUILD.gn | 1 + frameworks/intl/include/locale_config.h | 1 + frameworks/intl/src/locale_config.cpp | 40 +++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index e325ccc..cd2f254 100644 --- a/bundle.json +++ b/bundle.json @@ -48,13 +48,15 @@ "ram": "", "deps": { "components": [ + "ipc_core", "syspara", "utils", "tel_core_service_api", + "libaccesstoken_sdk", "libhilog", "ace_napi", "base", - "common" + "common" ], "third_party": [ "icu", diff --git a/frameworks/intl/BUILD.gn b/frameworks/intl/BUILD.gn index fc47dfb..e748b0d 100755 --- a/frameworks/intl/BUILD.gn +++ b/frameworks/intl/BUILD.gn @@ -94,6 +94,7 @@ ohos_shared_library("intl_util") { "//third_party/libxml2:xml2", ] external_deps = [ + "access_token:libaccesstoken_sdk", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "startup_l2:syspara", diff --git a/frameworks/intl/include/locale_config.h b/frameworks/intl/include/locale_config.h index ad04400..2c0c48b 100644 --- a/frameworks/intl/include/locale_config.h +++ b/frameworks/intl/include/locale_config.h @@ -96,6 +96,7 @@ private: static std::set validHcTag; static bool listsInitialized; static bool InitializeLists(); + static bool CheckPermission(); }; } // namespace I18n } // namespace Global diff --git a/frameworks/intl/src/locale_config.cpp b/frameworks/intl/src/locale_config.cpp index 519eb09..7b569d4 100755 --- a/frameworks/intl/src/locale_config.cpp +++ b/frameworks/intl/src/locale_config.cpp @@ -13,9 +13,12 @@ * limitations under the License. */ #include +#include "accesstoken_kit.h" #ifdef TEL_CORE_SERVICE_EXISTS #include "core_service_client.h" #endif +#include "hilog/log.h" +#include "ipc_skeleton.h" #include "libxml/parser.h" #include "locale_info.h" #include "localebuilder.h" @@ -36,7 +39,9 @@ namespace OHOS { namespace Global { namespace I18n { using namespace std; +using namespace OHOS::HiviewDFX; +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "LocaleConfig" }; const char *LocaleConfig::LANGUAGE_KEY = "persist.sys.language"; const char *LocaleConfig::LOCALE_KEY = "persist.sys.locale"; const char *LocaleConfig::HOUR_KEY = "persist.sys.is24Hour"; @@ -340,8 +345,34 @@ string LocaleConfig::GetSystemLocale() return ""; } +bool LocaleConfig::CheckPermission() +{ + Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); + int result = Security::AccessToken::PermissionState::PERMISSION_GRANTED; + if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken) + == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { + result = Security::AccessToken::AccessTokenKit::VerifyNativeToken(callerToken, + "ohos.permission.UPDATE_CONFIGURATION"); + } else if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken) + == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) { + result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, + "ohos.permission.UPDATE_CONFIGURATION"); + } else { + HiLog::Info(LABEL, "Invlid tokenID"); + return false; + } + if (result != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + HiLog::Info(LABEL, "Verify permission failed"); + return false; + } + return true; +} + bool LocaleConfig::SetSystemLanguage(const string &language) { + if (!CheckPermission()) { + return false; + } if (!IsValidTag(language)) { return false; } @@ -350,6 +381,9 @@ bool LocaleConfig::SetSystemLanguage(const string &language) bool LocaleConfig::SetSystemRegion(const string ®ion) { + if (!CheckPermission()) { + return false; + } if (!IsValidRegion(region)) { return false; } @@ -379,6 +413,9 @@ bool LocaleConfig::SetSystemRegion(const string ®ion) bool LocaleConfig::SetSystemLocale(const string &locale) { + if (!CheckPermission()) { + return false; + } if (!IsValidTag(locale)) { return false; } @@ -862,6 +899,9 @@ bool LocaleConfig::Is24HourClock() bool LocaleConfig::Set24HourClock(bool option) { + if (!CheckPermission()) { + return false; + } std::string optionStr = ""; if (option) { optionStr = "true"; -- GitLab