mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
Description:adapte grant extension
Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: yuwenze <yuaqiang1@huawei.com> Change-Id: Ie412645002cb275a3687c8a3b335d8c1d562cdc4
This commit is contained in:
@@ -778,19 +778,8 @@ void CallOnRequestPermissionsFromUserResult(int requestCode, const std::vector<s
|
||||
return;
|
||||
}
|
||||
|
||||
uv_work_t *work = new (std::nothrow) uv_work_t;
|
||||
if (work == nullptr) {
|
||||
HILOG_ERROR("%{public}s, work==null.", __func__);
|
||||
return;
|
||||
}
|
||||
OnRequestPermissionsFromUserResultCallback *onRequestPermissionCB =
|
||||
new (std::nothrow) OnRequestPermissionsFromUserResultCallback;
|
||||
if (onRequestPermissionCB == nullptr) {
|
||||
HILOG_ERROR("%{public}s, the string vector permissions is empty.", __func__);
|
||||
delete work;
|
||||
work = nullptr;
|
||||
return;
|
||||
}
|
||||
uv_work_t *work = new uv_work_t;
|
||||
OnRequestPermissionsFromUserResultCallback *onRequestPermissionCB = new OnRequestPermissionsFromUserResultCallback;
|
||||
onRequestPermissionCB->requestCode = requestCode;
|
||||
onRequestPermissionCB->permissions = permissions;
|
||||
onRequestPermissionCB->grantResults = grantResults;
|
||||
|
||||
@@ -303,12 +303,14 @@ bool InnerWrapWantParamsRemoteObject(
|
||||
auto value = wantParams.GetParam(key);
|
||||
AAFwk::IRemoteObjectWrap *remoteObjectIWrap = AAFwk::IRemoteObjectWrap::Query(value);
|
||||
if (remoteObjectIWrap == nullptr) {
|
||||
HILOG_ERROR("%{public}s remoteObjectIWrap is nullptr.", __func__);
|
||||
return false;
|
||||
}
|
||||
auto remoteObject = AAFwk::RemoteObjectWrap::UnBox(remoteObjectIWrap);
|
||||
auto jsValue = NAPI_ohos_rpc_CreateJsRemoteObject(env, remoteObject);
|
||||
HILOG_DEBUG("%{public}s called, jsRemoteObject:%{public}p.", __func__, jsValue);
|
||||
if (jsValue == nullptr) {
|
||||
HILOG_ERROR("%{public}s jsValue is nullptr.", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ ohos_shared_library("ability_context_native") {
|
||||
sources = [
|
||||
"ability_runtime/ability_connection.cpp",
|
||||
"ability_runtime/ability_context_impl.cpp",
|
||||
"ability_runtime/authorization_result.cpp",
|
||||
"ability_runtime/connection_manager.cpp",
|
||||
"ability_runtime/js_extension_context.cpp",
|
||||
"ability_runtime/local_call_container.cpp",
|
||||
@@ -50,11 +51,13 @@ ohos_shared_library("ability_context_native") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:configuration",
|
||||
"ability_base:want",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:runtime",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtoken_callback_sdk",
|
||||
"faultloggerd:lib_dfx_dump_catcher",
|
||||
"hichecker_native:libhichecker",
|
||||
"hitrace_native:hitrace_meter",
|
||||
|
||||
@@ -19,10 +19,14 @@
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "authorization_result.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "connection_manager.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "permission_list_state.h"
|
||||
#include "remote_object_wrapper.h"
|
||||
#include "string_wrapper.h"
|
||||
#include "want_params_wrapper.h"
|
||||
|
||||
using OHOS::Security::AccessToken::AccessTokenKit;
|
||||
using OHOS::Security::AccessToken::PermissionListState;
|
||||
@@ -35,6 +39,8 @@ const std::string GRANT_ABILITY_BUNDLE_NAME = "com.ohos.permissionmanager";
|
||||
const std::string GRANT_ABILITY_ABILITY_NAME = "com.ohos.permissionmanager.GrantAbility";
|
||||
const std::string PERMISSION_KEY = "ohos.user.grant.permission";
|
||||
const std::string STATE_KEY = "ohos.user.grant.permission.state";
|
||||
const std::string TOKEN_KEY = "ohos.ability.params.token";
|
||||
const std::string CALLBACK_KEY = "ohos.ability.params.callback";
|
||||
|
||||
std::string AbilityContextImpl::GetBaseDir() const
|
||||
{
|
||||
@@ -367,10 +373,10 @@ sptr<IRemoteObject> AbilityContextImpl::GetToken()
|
||||
}
|
||||
|
||||
void AbilityContextImpl::RequestPermissionsFromUser(const std::vector<std::string> &permissions,
|
||||
int requestCode, PermissionRequestTask &&task)
|
||||
PermissionRequestTask &&task)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
if (permissions.empty() || requestCode < 0) {
|
||||
if (permissions.empty()) {
|
||||
HILOG_ERROR("%{public}s. The params are invalid.", __func__);
|
||||
return;
|
||||
}
|
||||
@@ -406,10 +412,13 @@ void AbilityContextImpl::RequestPermissionsFromUser(const std::vector<std::strin
|
||||
want.SetElementName(GRANT_ABILITY_BUNDLE_NAME, GRANT_ABILITY_ABILITY_NAME);
|
||||
want.SetParam(PERMISSION_KEY, permissions);
|
||||
want.SetParam(STATE_KEY, permissionsState);
|
||||
permissionRequestCallbacks_.insert(make_pair(requestCode, std::move(task)));
|
||||
HILOG_DEBUG("%{public}s. Start calling StartAbility.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, requestCode);
|
||||
HILOG_INFO("%{public}s. End calling StartAbility. ret=%{public}d", __func__, err);
|
||||
want.SetParam(TOKEN_KEY, token_);
|
||||
sptr<IRemoteObject> remoteObject = new AuthorizationResult(std::move(task));
|
||||
want.SetParam(CALLBACK_KEY, remoteObject);
|
||||
|
||||
HILOG_DEBUG("%{public}s. Start calling StartExtension.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, -1);
|
||||
HILOG_INFO("%{public}s. End calling StartExtension. ret=%{public}d", __func__, err);
|
||||
} else {
|
||||
HILOG_DEBUG("%{public}s. No dynamic popup required.", __func__);
|
||||
if (task) {
|
||||
@@ -418,19 +427,6 @@ void AbilityContextImpl::RequestPermissionsFromUser(const std::vector<std::strin
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityContextImpl::OnRequestPermissionsFromUserResult(
|
||||
int requestCode, const std::vector<std::string> &permissions, const std::vector<int> &permissionsState)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s. Start calling OnRequestPermissionsFromUserResult.", __func__);
|
||||
auto iter = permissionRequestCallbacks_.find(requestCode);
|
||||
if (iter != permissionRequestCallbacks_.end() && iter->second) {
|
||||
auto task = iter->second;
|
||||
task(permissions, permissionsState);
|
||||
permissionRequestCallbacks_.erase(iter);
|
||||
HILOG_DEBUG("%{public}s. End calling OnRequestPermissionsFromUserResult.", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
ErrCode AbilityContextImpl::RestoreWindowStage(NativeEngine& engine, NativeValue* contentStorage)
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "authorization_result.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
void AuthorizationResult::GrantResultsCallback(const std::vector<std::string> &permissions,
|
||||
const std::vector<int> &grantResults)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
if (task_) {
|
||||
HILOG_DEBUG("%{public}s callback client function.", __func__);
|
||||
task_(permissions, grantResults);
|
||||
}
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -611,23 +611,6 @@ ErrCode Ability::StartAbility(const Want &want, AbilityStartSetting abilityStart
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called back after permissions are requested by using
|
||||
* AbilityContext.requestPermissionsFromUser(java.lang.String[],int).
|
||||
*
|
||||
* @param requestCode Indicates the request code passed to this method from
|
||||
* AbilityContext.requestPermissionsFromUser(java.lang.String[],int).
|
||||
* @param permissions Indicates the list of permissions requested by using
|
||||
* AbilityContext.requestPermissionsFromUser(java.lang.String[],int). This parameter cannot be null.
|
||||
* @param grantResults Indicates the granting results of the corresponding permissions requested using
|
||||
* AbilityContext.requestPermissionsFromUser(java.lang.String[],int). The value 0 indicates that a
|
||||
* permission is granted, and the value -1 indicates not.
|
||||
*
|
||||
*/
|
||||
void Ability::OnRequestPermissionsFromUserResult(
|
||||
int requestCode, const std::vector<std::string> &permissions, const std::vector<int> &grantResults)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief Obtains the MIME type matching the data specified by the URI of the Data ability. This method should be
|
||||
* implemented by a Data ability. Data abilities supports general data types, including text, HTML, and JPEG.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "authorization_result.h"
|
||||
#include "bundle_constants.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "iservice_registry.h"
|
||||
@@ -25,6 +26,9 @@
|
||||
#include "sys_mgr_client.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "remote_object_wrapper.h"
|
||||
#include "string_wrapper.h"
|
||||
#include "want_params_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@@ -34,6 +38,8 @@ const std::string GRANT_ABILITY_BUNDLE_NAME = "com.ohos.permissionmanager";
|
||||
const std::string GRANT_ABILITY_ABILITY_NAME = "com.ohos.permissionmanager.GrantAbility";
|
||||
const std::string PERMISSION_KEY = "ohos.user.grant.permission";
|
||||
const std::string STATE_KEY = "ohos.user.grant.permission.state";
|
||||
const std::string TOKEN_KEY = "ohos.ability.params.token";
|
||||
const std::string CALLBACK_KEY = "ohos.ability.params.callback";
|
||||
}
|
||||
|
||||
ErrCode AbilityContext::StartAbility(const AAFwk::Want &want, int requestCode)
|
||||
@@ -388,7 +394,7 @@ void AbilityContext::GetPermissionDes(const std::string &permissionName, std::st
|
||||
}
|
||||
|
||||
void AbilityContext::RequestPermissionsFromUser(std::vector<std::string> &permissions,
|
||||
std::vector<int> &permissionsState, int requestCode)
|
||||
std::vector<int> &permissionsState, PermissionRequestTask &&task)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin.", __func__);
|
||||
if (permissions.size() == 0) {
|
||||
@@ -396,16 +402,14 @@ void AbilityContext::RequestPermissionsFromUser(std::vector<std::string> &permis
|
||||
return;
|
||||
}
|
||||
|
||||
if (requestCode < 0) {
|
||||
HILOG_ERROR("AbilityContext::RequestPermissionsFromUser requestCode should be >= 0");
|
||||
return;
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
want.SetElementName(GRANT_ABILITY_BUNDLE_NAME, GRANT_ABILITY_ABILITY_NAME);
|
||||
want.SetParam(PERMISSION_KEY, permissions);
|
||||
want.SetParam(STATE_KEY, permissionsState);
|
||||
StartAbility(want, requestCode);
|
||||
want.SetParam(TOKEN_KEY, token_);
|
||||
sptr<IRemoteObject> remoteObject = new AbilityRuntime::AuthorizationResult(std::move(task));
|
||||
want.SetParam(CALLBACK_KEY, remoteObject);
|
||||
StartAbility(want, -1);
|
||||
HILOG_DEBUG("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
|
||||
@@ -243,18 +243,7 @@ void AbilityImpl::SendResult(int requestCode, int resultCode, const Want &result
|
||||
return;
|
||||
}
|
||||
|
||||
if (resultData.HasParameter(PERMISSION_KEY)) {
|
||||
std::vector<std::string> permissions = resultData.GetStringArrayParam(PERMISSION_KEY);
|
||||
std::vector<int> grantedResult(permissions.size(), -1);
|
||||
if (resultCode > 0) {
|
||||
grantedResult = resultData.GetIntArrayParam(GRANTED_RESULT_KEY);
|
||||
HILOG_DEBUG("%{public}s Get user granted result.", __func__);
|
||||
}
|
||||
ability_->OnRequestPermissionsFromUserResult(requestCode, permissions, grantedResult);
|
||||
} else {
|
||||
ability_->OnAbilityResult(requestCode, resultCode, resultData);
|
||||
}
|
||||
|
||||
ability_->OnAbilityResult(requestCode, resultCode, resultData);
|
||||
// for api5 FeatureAbility::startAbilityForResult
|
||||
ability_->OnFeatureAbilityResult(requestCode, resultCode, resultData);
|
||||
HILOG_DEBUG("%{public}s end.", __func__);
|
||||
|
||||
@@ -43,7 +43,6 @@ using NAPICallOnRequestPermissionsFromUserResult = void (*)(int requestCode,
|
||||
|
||||
std::shared_ptr<AbilityProcess> AbilityProcess::instance_ = nullptr;
|
||||
std::map<Ability *, std::map<int, CallbackInfo>> AbilityProcess::abilityResultMap_;
|
||||
std::map<Ability *, std::map<int, CallbackInfo>> AbilityProcess::abilityRequestPermissionsForUserMap_;
|
||||
std::mutex AbilityProcess::mutex_;
|
||||
std::shared_ptr<AbilityProcess> AbilityProcess::GetInstance()
|
||||
{
|
||||
@@ -217,66 +216,26 @@ void AbilityProcess::RequestPermissionsFromUser(
|
||||
HILOG_DEBUG("%{public}s. permissions size: %{public}zu. permissionsState size: %{public}zu",
|
||||
__func__, param.permission_list.size(), permissionsState.size());
|
||||
|
||||
auto requestCode = param.requestCode;
|
||||
if (ret != TypePermissionOper::DYNAMIC_OPER) {
|
||||
HILOG_DEBUG("%{public}s. No dynamic popup required.", __func__);
|
||||
(void)CaullFunc(param.requestCode, param.permission_list, permissionsState, callbackInfo);
|
||||
(void)CaullFunc(requestCode, param.permission_list, permissionsState, callbackInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
ability->RequestPermissionsFromUser(param.permission_list, permissionsState, param.requestCode);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_l(mutex_);
|
||||
std::map<int, CallbackInfo> map;
|
||||
auto it = abilityRequestPermissionsForUserMap_.find(ability);
|
||||
if (it == abilityRequestPermissionsForUserMap_.end()) {
|
||||
HILOG_INFO("AbilityProcess::RequestPermissionsFromUser ability: is not in the "
|
||||
"abilityRequestPermissionsForUserMap_");
|
||||
} else {
|
||||
HILOG_INFO("AbilityProcess::RequestPermissionsFromUser ability: is in the "
|
||||
"abilityRequestPermissionsForUserMap_");
|
||||
map = it->second;
|
||||
auto task = [self = GetInstance(), requestCode, callbackInfo]
|
||||
(const std::vector<std::string> &permissions, const std::vector<int> &grantResults) mutable {
|
||||
if (!self) {
|
||||
HILOG_ERROR("%{public}s: self is nullptr.", __func__);
|
||||
return;
|
||||
}
|
||||
if (!self->CaullFunc(requestCode, permissions, grantResults, callbackInfo)) {
|
||||
HILOG_ERROR("%{public}s: call function failed.", __func__);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
map[param.requestCode] = callbackInfo;
|
||||
abilityRequestPermissionsForUserMap_[ability] = map;
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityProcess::OnRequestPermissionsFromUserResult(Ability *ability, int requestCode,
|
||||
const std::vector<std::string> &permissions, const std::vector<int> &permissionsState)
|
||||
{
|
||||
HILOG_INFO("AbilityProcess::OnRequestPermissionsFromUserResult begin");
|
||||
if (ability == nullptr) {
|
||||
HILOG_ERROR("AbilityProcess::OnRequestPermissionsFromUserResult ability is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock_l(mutex_);
|
||||
|
||||
auto it = abilityRequestPermissionsForUserMap_.find(ability);
|
||||
if (it == abilityRequestPermissionsForUserMap_.end()) {
|
||||
HILOG_ERROR("AbilityProcess::OnRequestPermissionsFromUserResult ability: is not in the "
|
||||
"abilityRequestPermissionsForUserMap_");
|
||||
return;
|
||||
}
|
||||
std::map<int, CallbackInfo> map = it->second;
|
||||
|
||||
auto callback = map.find(requestCode);
|
||||
if (callback == map.end()) {
|
||||
HILOG_ERROR("AbilityProcess::OnRequestPermissionsFromUserResult requestCode: %{public}d is not in the map",
|
||||
requestCode);
|
||||
return;
|
||||
}
|
||||
CallbackInfo callbackInfo = callback->second;
|
||||
if (!CaullFunc(requestCode, permissions, permissionsState, callbackInfo)) {
|
||||
HILOG_ERROR("AbilityProcess::OnRequestPermissionsFromUserResult call function failed.");
|
||||
return;
|
||||
}
|
||||
map.erase(requestCode);
|
||||
|
||||
abilityRequestPermissionsForUserMap_[ability] = map;
|
||||
HILOG_INFO("AbilityProcess::OnRequestPermissionsFromUserResult end");
|
||||
ability->RequestPermissionsFromUser(param.permission_list, permissionsState, std::move(task));
|
||||
}
|
||||
|
||||
bool AbilityProcess::CaullFunc(int requestCode, const std::vector<std::string> &permissions,
|
||||
|
||||
@@ -684,19 +684,6 @@ sptr<IRemoteObject> JsAbility::CallRequest()
|
||||
return remoteCallee_;
|
||||
}
|
||||
|
||||
void JsAbility::OnRequestPermissionsFromUserResult(
|
||||
int requestCode, const std::vector<std::string> &permissions, const std::vector<int> &grantResults)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> context = GetAbilityContext();
|
||||
if (context == nullptr) {
|
||||
HILOG_WARN("JsAbility not attached to any runtime context!");
|
||||
return;
|
||||
}
|
||||
context->OnRequestPermissionsFromUserResult(requestCode, permissions, grantResults);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
void JsAbility::CallObjectMethod(const char *name, NativeValue *const *argv, size_t argc)
|
||||
{
|
||||
HILOG_INFO("JsAbility::CallObjectMethod(%{public}s", name);
|
||||
|
||||
@@ -964,8 +964,7 @@ NativeValue* JsAbilityContext::OnRequestPermissionsFromUser(NativeEngine& engine
|
||||
HILOG_WARN("context is released");
|
||||
asyncTask->Reject(engine, CreateJsError(engine, 1, "context is released!"));
|
||||
} else {
|
||||
curRequestCode_ = (curRequestCode_ == INT_MAX) ? 0 : (curRequestCode_ + 1);
|
||||
context->RequestPermissionsFromUser(permissionList, curRequestCode_, std::move(task));
|
||||
context->RequestPermissionsFromUser(permissionList, std::move(task));
|
||||
}
|
||||
HILOG_INFO("OnRequestPermissionsFromUser is called end");
|
||||
return result;
|
||||
|
||||
@@ -533,19 +533,17 @@ std::string ContextContainer::GetProcessName()
|
||||
/**
|
||||
* @brief Requests certain permissions from the system.
|
||||
* This method is called for permission request. This is an asynchronous method. When it is executed,
|
||||
* the Ability.onRequestPermissionsFromUserResult(int, String[], int[]) method will be called back.
|
||||
* the task will be called back.
|
||||
*
|
||||
* @param permissions Indicates the list of permissions to be requested. This parameter cannot be null.
|
||||
* @param permissionsState Indicates the list of permissions' state to be requested. This parameter cannot be null.
|
||||
* @param requestCode Indicates the request code to be passed to the Ability.onRequestPermissionsFromUserResult(int,
|
||||
* String[], int[]) callback method. This code cannot be a negative number.
|
||||
*
|
||||
* @param task The callback or promise fo js interface.
|
||||
*/
|
||||
void ContextContainer::RequestPermissionsFromUser(std::vector<std::string> &permissions,
|
||||
std::vector<int> &permissionsState, int requestCode)
|
||||
std::vector<int> &permissionsState, PermissionRequestTask &&task)
|
||||
{
|
||||
if (baseContext_ != nullptr) {
|
||||
baseContext_->RequestPermissionsFromUser(permissions, permissionsState, requestCode);
|
||||
baseContext_->RequestPermissionsFromUser(permissions, permissionsState, std::move(task));
|
||||
} else {
|
||||
HILOG_ERROR("ContextContainer::RequestPermissionsFromUser baseContext_ is nullptr");
|
||||
}
|
||||
|
||||
@@ -728,16 +728,14 @@ std::string ContextDeal::GetCallingBundle()
|
||||
/**
|
||||
* @brief Requests certain permissions from the system.
|
||||
* This method is called for permission request. This is an asynchronous method. When it is executed,
|
||||
* the Ability.onRequestPermissionsFromUserResult(int, String[], int[]) method will be called back.
|
||||
* the task will be called back.
|
||||
*
|
||||
* @param permissions Indicates the list of permissions to be requested. This parameter cannot be null.
|
||||
* @param permissionsState Indicates the list of permissions' state to be requested. This parameter cannot be null.
|
||||
* @param requestCode Indicates the request code to be passed to the Ability.onRequestPermissionsFromUserResult(int,
|
||||
* String[], int[]) callback method. This code cannot be a negative number.
|
||||
*
|
||||
* @param task The callback or promise fo js interface.
|
||||
*/
|
||||
void ContextDeal::RequestPermissionsFromUser(std::vector<std::string> &permissions, std::vector<int> &permissionsState,
|
||||
int requestCode) {}
|
||||
PermissionRequestTask &&task) {}
|
||||
|
||||
/**
|
||||
* @brief Starts a new ability with special ability start setting.
|
||||
|
||||
@@ -176,30 +176,13 @@ public:
|
||||
/**
|
||||
* @brief Requests certain permissions from the system.
|
||||
* This method is called for permission request. This is an asynchronous method. When it is executed,
|
||||
* the OnRequestPermissionsFromUserResult(int, vector<string>, vector<int>) method will be called back.
|
||||
* the task will be called back.
|
||||
*
|
||||
* @param permissions Indicates the list of permissions to be requested. This parameter cannot be null.
|
||||
* @param requestCode Indicates the request code to be passed to the OnRequestPermissionsFromUserResult(int,
|
||||
* vector<string>, vector<int>) callback method. This code cannot be a negative number.
|
||||
* @param task The callback or promise fo js interface.
|
||||
*/
|
||||
virtual void RequestPermissionsFromUser(const std::vector<std::string> &permissions,
|
||||
int requestCode, PermissionRequestTask &&task) = 0;
|
||||
|
||||
/**
|
||||
* @brief Called back after permissions are requested by using
|
||||
* RequestPermissionsFromUser(vector<string>, int, PermissionRequestTask).
|
||||
*
|
||||
* @param requestCode Indicates the request code passed to this method from
|
||||
* RequestPermissionsFromUser(vector<string>, int, PermissionRequestTask).
|
||||
* @param permissions Indicates the list of permissions requested by using
|
||||
* RequestPermissionsFromUser(vector<string>, int, PermissionRequestTask).
|
||||
* @param grantResults Indicates the granting results of the corresponding permissions requested using
|
||||
* RequestPermissionsFromUser(vector<string>, int, PermissionRequestTask). The value 0 indicates that a
|
||||
* permission is granted, and the value -1 indicates not.
|
||||
*/
|
||||
virtual void OnRequestPermissionsFromUserResult(
|
||||
int requestCode, const std::vector<std::string> &permissions, const std::vector<int> &grantResults) = 0;
|
||||
PermissionRequestTask &&task) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get ContentStorage.
|
||||
|
||||
@@ -81,10 +81,7 @@ public:
|
||||
|
||||
sptr<IRemoteObject> GetToken() override;
|
||||
|
||||
void RequestPermissionsFromUser(const std::vector<std::string> &permissions,
|
||||
int requestCode, PermissionRequestTask &&task) override;
|
||||
void OnRequestPermissionsFromUserResult(
|
||||
int requestCode, const std::vector<std::string> &permissions, const std::vector<int> &grantResults) override;
|
||||
void RequestPermissionsFromUser(const std::vector<std::string> &permissions, PermissionRequestTask &&task) override;
|
||||
|
||||
ErrCode RestoreWindowStage(NativeEngine& engine, NativeValue* contentStorage) override;
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_AUTHORIZATION_RESULT_H
|
||||
#define OHOS_ABILITY_RUNTIME_AUTHORIZATION_RESULT_H
|
||||
|
||||
#include "ability_context.h"
|
||||
#include "base/security/access_token/interfaces/innerkits/token_callback/include/token_callback_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class AuthorizationResult : public Security::AccessToken::TokenCallbackStub {
|
||||
public:
|
||||
explicit AuthorizationResult(PermissionRequestTask&& task) : task_(task) {}
|
||||
virtual ~AuthorizationResult() = default;
|
||||
|
||||
virtual void GrantResultsCallback(const std::vector<std::string> &permissions,
|
||||
const std::vector<int> &grantResults) override;
|
||||
|
||||
private:
|
||||
PermissionRequestTask task_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_AUTHORIZATION_RESULT_H
|
||||
@@ -266,22 +266,6 @@ public:
|
||||
*/
|
||||
virtual void OnDisconnect(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called back after permissions are requested by using
|
||||
* AbilityContext.requestPermissionsFromUser(java.lang.String[],int).
|
||||
*
|
||||
* @param requestCode Indicates the request code passed to this method from
|
||||
* AbilityContext.requestPermissionsFromUser(java.lang.String[],int).
|
||||
* @param permissions Indicates the list of permissions requested by using
|
||||
* AbilityContext.requestPermissionsFromUser(java.lang.String[],int). This parameter cannot be null.
|
||||
* @param grantResults Indicates the granting results of the corresponding permissions requested using
|
||||
* AbilityContext.requestPermissionsFromUser(java.lang.String[],int). The value 0 indicates that a
|
||||
* permission is granted, and the value -1 indicates not.
|
||||
*
|
||||
*/
|
||||
virtual void OnRequestPermissionsFromUserResult(
|
||||
int requestCode, const std::vector<std::string> &permissions, const std::vector<int> &grantResults);
|
||||
|
||||
/**
|
||||
* @brief Obtains the MIME type matching the data specified by the URI of the Data ability. This method should be
|
||||
* implemented by a Data ability. Data abilities supports general data types, including text, HTML, and JPEG.
|
||||
|
||||
@@ -414,15 +414,14 @@ public:
|
||||
/**
|
||||
* @brief Requests certain permissions from the system.
|
||||
* This method is called for permission request. This is an asynchronous method. When it is executed,
|
||||
* the Ability.onRequestPermissionsFromUserResult(int, String[], int[]) method will be called back.
|
||||
* the task will be called back.
|
||||
*
|
||||
* @param permissions Indicates the list of permissions to be requested. This parameter cannot be null.
|
||||
* @param permissionsState Indicates the list of permissions' state to be requested. This parameter cannot be null.
|
||||
* @param requestCode Indicates the request code to be passed to the Ability.onRequestPermissionsFromUserResult(int,
|
||||
* String[], int[]) callback method. This code cannot be a negative number.
|
||||
* @param task The callback or promise fo js interface.
|
||||
*/
|
||||
virtual void RequestPermissionsFromUser(std::vector<std::string> &permissions, std::vector<int> &permissionsState,
|
||||
int requestCode) override;
|
||||
PermissionRequestTask &&task) override;
|
||||
|
||||
/**
|
||||
* @brief Deletes the specified private file associated with the application.
|
||||
|
||||
@@ -37,8 +37,6 @@ public:
|
||||
void AddAbilityResultCallback(Ability *ability, CallAbilityParam ¶m, int32_t errCode, CallbackInfo &callback);
|
||||
|
||||
void RequestPermissionsFromUser(Ability *ability, CallAbilityPermissionParam ¶m, CallbackInfo callbackInfo);
|
||||
void OnRequestPermissionsFromUserResult(Ability *ability, int requestCode,
|
||||
const std::vector<std::string> &permissions, const std::vector<int> &grantResults);
|
||||
|
||||
private:
|
||||
bool CaullFunc(int requestCode, const std::vector<std::string> &permissions,
|
||||
@@ -48,7 +46,6 @@ private:
|
||||
static std::mutex mutex_;
|
||||
static std::shared_ptr<AbilityProcess> instance_;
|
||||
static std::map<Ability *, std::map<int, CallbackInfo>> abilityResultMap_;
|
||||
static std::map<Ability *, std::map<int, CallbackInfo>> abilityRequestPermissionsForUserMap_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -53,8 +53,6 @@ public:
|
||||
void OnNewWant(const Want &want) override;
|
||||
|
||||
void OnAbilityResult(int requestCode, int resultCode, const Want &resultData) override;
|
||||
void OnRequestPermissionsFromUserResult(
|
||||
int requestCode, const std::vector<std::string> &permissions, const std::vector<int> &grantResults) override;
|
||||
|
||||
sptr<IRemoteObject> CallRequest() override;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ class DataShareHelper;
|
||||
namespace AppExecFwk {
|
||||
using Want = OHOS::AAFwk::Want;
|
||||
using AbilityStartSetting = AAFwk::AbilityStartSetting;
|
||||
using PermissionRequestTask = std::function<void(const std::vector<std::string>&, const std::vector<int>&)>;
|
||||
// Request permissions for user
|
||||
#define OHOS_REQUEST_PERMISSION_BUNDLENAME "com.ohos.systemui"
|
||||
#define OHOS_REQUEST_PERMISSION_ABILITY_NAME "com.ohos.systemui.systemdialog.MainAbility"
|
||||
@@ -417,16 +418,14 @@ public:
|
||||
/**
|
||||
* @brief Requests certain permissions from the system.
|
||||
* This method is called for permission request. This is an asynchronous method. When it is executed,
|
||||
* the Ability.onRequestPermissionsFromUserResult(int, String[], int[]) method will be called back.
|
||||
* the task will be called back.
|
||||
*
|
||||
* @param permissions Indicates the list of permissions to be requested. This parameter cannot be null.
|
||||
* @param permissionsState Indicates the list of permissions' state to be requested. This parameter cannot be null.
|
||||
* @param requestCode Indicates the request code to be passed to the Ability.onRequestPermissionsFromUserResult(int,
|
||||
* String[], int[]) callback method. This code cannot be a negative number.
|
||||
*
|
||||
* @param task The callback or promise fo js interface.
|
||||
*/
|
||||
virtual void RequestPermissionsFromUser(std::vector<std::string> &permissions, std::vector<int> &permissionsState,
|
||||
int requestCode) = 0;
|
||||
PermissionRequestTask &&task) = 0;
|
||||
|
||||
/**
|
||||
* @brief Starts a new ability with special ability start setting.
|
||||
|
||||
@@ -304,16 +304,14 @@ public:
|
||||
/**
|
||||
* @brief Requests certain permissions from the system.
|
||||
* This method is called for permission request. This is an asynchronous method. When it is executed,
|
||||
* the Ability.onRequestPermissionsFromUserResult(int, String[], int[]) method will be called back.
|
||||
* the task will be called back.
|
||||
*
|
||||
* @param permissions Indicates the list of permissions to be requested. This parameter cannot be null.
|
||||
* @param permissionsState Indicates the list of permissions' state to be requested. This parameter cannot be null.
|
||||
* @param requestCode Indicates the request code to be passed to the Ability.onRequestPermissionsFromUserResult(int,
|
||||
* String[], int[]) callback method. This code cannot be a negative number.
|
||||
*
|
||||
* @param task The callback or promise fo js interface.
|
||||
*/
|
||||
void RequestPermissionsFromUser(std::vector<std::string> &permissions, std::vector<int> &permissionsState,
|
||||
int requestCode) override;
|
||||
PermissionRequestTask &&task) override;
|
||||
|
||||
/**
|
||||
* @brief Creates a Context object for an application with the given bundle name.
|
||||
|
||||
@@ -404,15 +404,14 @@ public:
|
||||
/**
|
||||
* @brief Requests certain permissions from the system.
|
||||
* This method is called for permission request. This is an asynchronous method. When it is executed,
|
||||
* the Ability.onRequestPermissionsFromUserResult(int, String[], int[]) method will be called back.
|
||||
* the task will be called back.
|
||||
*
|
||||
* @param permissions Indicates the list of permissions to be requested. This parameter cannot be null.
|
||||
* @param permissionsState Indicates the list of permissions' state to be requested. This parameter cannot be null.
|
||||
* @param requestCode Indicates the request code to be passed to the Ability.onRequestPermissionsFromUserResult(int,
|
||||
* String[], int[]) callback method. This code cannot be a negative number.
|
||||
* @param task The callback or promise fo js interface.
|
||||
*/
|
||||
void RequestPermissionsFromUser(std::vector<std::string> &permissions, std::vector<int> &permissionsState,
|
||||
int requestCode) override;
|
||||
PermissionRequestTask &&task) override;
|
||||
|
||||
/**
|
||||
* @brief Starts a new ability with special ability start setting.
|
||||
|
||||
@@ -90,12 +90,6 @@ void Ability::StartAbility(const Want &want, AbilityStartSetting abilityStartSet
|
||||
return;
|
||||
}
|
||||
|
||||
void Ability::OnRequestPermissionsFromUserResult(
|
||||
int requestCode, const std::vector<std::string> &permissions, const std::vector<int> &grantResults)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::string Ability::GetType(const Uri &uri)
|
||||
{
|
||||
std::string value("\nullptr");
|
||||
|
||||
@@ -118,33 +118,5 @@ HWTEST_F(AbilityPermissionTest, AaFwk_AbilityPermissionTest_VerifyPermission_010
|
||||
|
||||
context_->VerifyPermission(permission_name, 0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AaFwk_AbilityPermissionTest_RequestPermissionsFromUser_0100
|
||||
* @tc.name: RequestPermissionsFromUser
|
||||
* @tc.desc: Verify that requestpermissionsfromuser is called.
|
||||
*/
|
||||
HWTEST_F(
|
||||
AbilityPermissionTest, AaFwk_AbilityPermissionTest_RequestPermissionsFromUser_0100, Function | MediumTest | Level1)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
EXPECT_EQ(true, context_ != nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
|
||||
std::string name = "hello";
|
||||
appInfo->bundleName = name;
|
||||
std::vector<std::string> permissions;
|
||||
permissions.emplace_back("permission_1");
|
||||
permissions.emplace_back("permission_2");
|
||||
permissions.emplace_back("permission_3");
|
||||
std::vector<int> permissionsState(permissions.size(), -1);
|
||||
|
||||
std::shared_ptr<ContextDeal> deal = std::make_shared<ContextDeal>();
|
||||
deal->SetApplicationInfo(appInfo);
|
||||
context_->AttachBaseContext(deal);
|
||||
context_->RequestPermissionsFromUser(permissions, permissionsState, 1004);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user