mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-25 12:23:20 -04:00
解冲突
Signed-off-by: chenyuyan <chenyuyan3@huawei.com> Change-Id: I2ea108cf5e5d12d1391870cbd5b3173d639602a7
This commit is contained in:
@@ -24,15 +24,20 @@ ohos_shared_library("uripermissionmanager_napi") {
|
||||
|
||||
include_dirs = []
|
||||
|
||||
deps =
|
||||
[ "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr" ]
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_runtime_error_util",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:runtime",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
if (!ability_runtime_graphics) {
|
||||
|
||||
@@ -15,14 +15,23 @@
|
||||
|
||||
#include "js_uri_perm_mgr.h"
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "ability_runtime_error_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_error_utils.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "uri.h"
|
||||
#include "uri_permission_manager_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr int32_t ERR_OK = 0;
|
||||
constexpr int32_t argCountFour = 4;
|
||||
constexpr int32_t argCountThree = 3;
|
||||
constexpr int32_t argCountTwo = 2;
|
||||
}
|
||||
class JsUriPermMgr {
|
||||
public:
|
||||
JsUriPermMgr() = default;
|
||||
@@ -33,6 +42,113 @@ public:
|
||||
HILOG_INFO("JsUriPermMgr::Finalizer is called");
|
||||
std::unique_ptr<JsUriPermMgr>(static_cast<JsUriPermMgr*>(data));
|
||||
}
|
||||
|
||||
static NativeValue* GrantUriPermission(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsUriPermMgr* me = CheckParamsAndGetThis<JsUriPermMgr>(engine, info);
|
||||
return (me != nullptr) ? me->OnGrantUriPermission(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* RevokeUriPermission(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsUriPermMgr* me = CheckParamsAndGetThis<JsUriPermMgr>(engine, info);
|
||||
return (me != nullptr) ? me->OnRevokeUriPermission(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
NativeValue* OnGrantUriPermission(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
if (info.argc != argCountThree && info.argc != argCountFour) {
|
||||
HILOG_ERROR("The number of parameter is invalid.");
|
||||
ThrowTooFewParametersError(engine);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
HILOG_DEBUG("Grant Uri Permission start");
|
||||
std::string uriStr;
|
||||
if (!OHOS::AppExecFwk::UnwrapStringFromJS2(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[0]), uriStr)) {
|
||||
HILOG_ERROR("The uriStr is invalid.");
|
||||
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
int flag = 0;
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[1]), flag)) {
|
||||
HILOG_ERROR("The flag is invalid.");
|
||||
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::string targetBundleName;
|
||||
if (!OHOS::AppExecFwk::UnwrapStringFromJS2(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[argCountTwo]), targetBundleName)) {
|
||||
HILOG_ERROR("The targetBundleName is invalid.");
|
||||
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[uriStr, flag, targetBundleName](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
Uri uri(uriStr);
|
||||
auto errCode = AAFwk::UriPermissionManagerClient::GetInstance()->GrantUriPermission(uri, flag,
|
||||
targetBundleName, 0);
|
||||
if (errCode == ERR_OK) {
|
||||
task.ResolveWithNoError(engine, engine.CreateUndefined());
|
||||
} else if (errCode == AAFwk::CHECK_PERMISSION_FAILED) {
|
||||
task.Reject(engine, CreateNoPermissionError(engine, "ohos.permission.PROXY_AUTHORIZATION_URI"));
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR,
|
||||
"Internal Error."));
|
||||
}
|
||||
};
|
||||
NativeValue* lastParam = (info.argc == argCountFour) ? info.argv[argCountThree] : nullptr;
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsUriPermMgr::OnGrantUriPermission",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnRevokeUriPermission(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
// only support 2 or 3 params (2 parameter and 1 optional callback)
|
||||
if (info.argc != argCountThree && info.argc != argCountTwo) {
|
||||
HILOG_ERROR("Invalid arguments");
|
||||
ThrowTooFewParametersError(engine);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::string uriStr;
|
||||
if (!OHOS::AppExecFwk::UnwrapStringFromJS2(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[0]), uriStr)) {
|
||||
HILOG_ERROR("The uriStr is invalid.");
|
||||
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::string bundleName;
|
||||
if (!OHOS::AppExecFwk::UnwrapStringFromJS2(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[1]), bundleName)) {
|
||||
HILOG_ERROR("The bundleName is invalid.");
|
||||
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[uriStr, bundleName](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
Uri uri(uriStr);
|
||||
auto errCode = AAFwk::UriPermissionManagerClient::GetInstance()->RevokeUriPermissionManually(uri,
|
||||
bundleName);
|
||||
if (errCode == ERR_OK) {
|
||||
task.ResolveWithNoError(engine, engine.CreateUndefined());
|
||||
} else if (errCode == AAFwk::CHECK_PERMISSION_FAILED) {
|
||||
task.Reject(engine, CreateNoPermissionError(engine,
|
||||
"Do not have permission ohos.permission.PROXY_AUTHORIZATION_URI"));
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR,
|
||||
"Internal Error."));
|
||||
}
|
||||
};
|
||||
NativeValue* lastParam = (info.argc == argCountThree) ? info.argv[argCountTwo] : nullptr;
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsUriPermMgr::OnRevokeUriPermission",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* CreateJsUriPermMgr(NativeEngine* engine, NativeValue* exportObj)
|
||||
@@ -52,6 +168,9 @@ NativeValue* CreateJsUriPermMgr(NativeEngine* engine, NativeValue* exportObj)
|
||||
std::unique_ptr<JsUriPermMgr> jsUriPermMgr = std::make_unique<JsUriPermMgr>();
|
||||
object->SetNativePointer(jsUriPermMgr.release(), JsUriPermMgr::Finalizer, nullptr);
|
||||
|
||||
const char *moduleName = "JsUriPermMgr";
|
||||
BindNativeFunction(*engine, *object, "grantUriPermission", moduleName, JsUriPermMgr::GrantUriPermission);
|
||||
BindNativeFunction(*engine, *object, "revokeUriPermission", moduleName, JsUriPermMgr::RevokeUriPermission);
|
||||
return engine->CreateUndefined();
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
|
||||
@@ -442,5 +442,27 @@ bool DistributedClient::WriteInfosToParcel(MessageParcel& data, const OHOS::AAFw
|
||||
PARCEL_WRITE_HELPER(data, Uint32, accessToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t DistributedClient::StopRemoteExtensionAbility(const Want &want, int32_t callerUid,
|
||||
uint32_t accessToken, int32_t extensionType)
|
||||
{
|
||||
HILOG_DEBUG("StopRemoteExtensionAbility enter");
|
||||
sptr<IRemoteObject> remote = GetDmsProxy();
|
||||
if (remote == nullptr) {
|
||||
HILOG_ERROR("StopRemoteExtensionAbility remote service null");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
|
||||
HILOG_ERROR("StopRemoteExtensionAbility WriteInterfaceToken failed");
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
PARCEL_WRITE_HELPER(data, Parcelable, &want);
|
||||
PARCEL_WRITE_HELPER(data, Int32, callerUid);
|
||||
PARCEL_WRITE_HELPER(data, Uint32, accessToken);
|
||||
PARCEL_WRITE_HELPER(data, Int32, extensionType);
|
||||
MessageParcel reply;
|
||||
PARCEL_TRANSACT_SYNC_RET_INT(remote, STOP_REMOTE_EXTERNSION_ABILITY, data, reply);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -107,7 +107,7 @@ constexpr char EXTENSION_PARAMS_NAME[] = "name";
|
||||
|
||||
constexpr uint32_t CHECK_MAIN_THREAD_IS_ALIVE = 1;
|
||||
|
||||
void SetNativeLibPath(const BundleInfo &bundleInfo, const HspList &hspList, AbilityRuntime::Runtime::Options &options)
|
||||
void GetNativeLibPath(const BundleInfo &bundleInfo, const HspList &hspList, AppLibPathMap &appLibPaths)
|
||||
{
|
||||
std::string patchNativeLibraryPath = bundleInfo.applicationInfo.appQuickFix.deployedAppqfInfo.nativeLibraryPath;
|
||||
if (!patchNativeLibraryPath.empty()) {
|
||||
@@ -115,7 +115,7 @@ void SetNativeLibPath(const BundleInfo &bundleInfo, const HspList &hspList, Abil
|
||||
std::string patchLibPath = LOCAL_CODE_PATH;
|
||||
patchLibPath += (patchLibPath.back() == '/') ? patchNativeLibraryPath : "/" + patchNativeLibraryPath;
|
||||
HILOG_INFO("napi patch lib path = %{private}s", patchLibPath.c_str());
|
||||
options.appLibPaths["default"].emplace_back(patchLibPath);
|
||||
appLibPaths["default"].emplace_back(patchLibPath);
|
||||
}
|
||||
|
||||
std::string nativeLibraryPath = bundleInfo.applicationInfo.nativeLibraryPath;
|
||||
@@ -126,7 +126,7 @@ void SetNativeLibPath(const BundleInfo &bundleInfo, const HspList &hspList, Abil
|
||||
std::string libPath = LOCAL_CODE_PATH;
|
||||
libPath += (libPath.back() == '/') ? nativeLibraryPath : "/" + nativeLibraryPath;
|
||||
HILOG_INFO("napi lib path = %{private}s", libPath.c_str());
|
||||
options.appLibPaths["default"].emplace_back(libPath);
|
||||
appLibPaths["default"].emplace_back(libPath);
|
||||
}
|
||||
|
||||
for (auto &hapInfo : bundleInfo.hapModuleInfos) {
|
||||
@@ -143,12 +143,13 @@ void SetNativeLibPath(const BundleInfo &bundleInfo, const HspList &hspList, Abil
|
||||
std::string patchLibPath = LOCAL_CODE_PATH;
|
||||
patchLibPath += (patchLibPath.back() == '/') ? patchNativeLibraryPath : "/" + patchNativeLibraryPath;
|
||||
HILOG_INFO("name: %{public}s, patch lib path = %{private}s", hapInfo.name.c_str(), patchLibPath.c_str());
|
||||
options.appLibPaths[appLibPathKey].emplace_back(patchLibPath);
|
||||
appLibPaths[appLibPathKey].emplace_back(patchLibPath);
|
||||
}
|
||||
|
||||
std::string libPath = LOCAL_CODE_PATH;
|
||||
libPath += (libPath.back() == '/') ? hapInfo.nativeLibraryPath : "/" + hapInfo.nativeLibraryPath;
|
||||
options.appLibPaths[appLibPathKey].emplace_back(libPath);
|
||||
HILOG_DEBUG("appLibPathKey: %{private}s, libPath: %{private}s", appLibPathKey.c_str(), libPath.c_str());
|
||||
appLibPaths[appLibPathKey].emplace_back(libPath);
|
||||
}
|
||||
|
||||
for (auto &hspInfo : hspList) {
|
||||
@@ -162,7 +163,8 @@ void SetNativeLibPath(const BundleInfo &bundleInfo, const HspList &hspList, Abil
|
||||
std::string libPath = LOCAL_CODE_PATH;
|
||||
libPath = libPath.back() == '/' ? libPath : libPath + "/";
|
||||
libPath += hspInfo.bundleName + "/" + hspInfo.nativeLibraryPath;
|
||||
options.appLibPaths[appLibPathKey].emplace_back(libPath);
|
||||
HILOG_DEBUG("appLibPathKey: %{private}s, libPath: %{private}s", appLibPathKey.c_str(), libPath.c_str());
|
||||
appLibPaths[appLibPathKey].emplace_back(libPath);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
@@ -1074,12 +1076,17 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
AbilityRuntime::ApplicationContext::GetInstance();
|
||||
applicationContext->AttachContextImpl(contextImpl);
|
||||
application_->SetApplicationContext(applicationContext);
|
||||
|
||||
HspList hspList;
|
||||
ErrCode ret = bundleMgr->GetBaseSharedBundleInfos(appInfo.bundleName, hspList);
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("GetBaseSharedBundleInfos failed: %{public}d", ret);
|
||||
}
|
||||
AppLibPathMap appLibPaths {};
|
||||
GetNativeLibPath(bundleInfo, hspList, appLibPaths);
|
||||
AbilityRuntime::JsRuntime::SetAppLibPath(appLibPaths);
|
||||
|
||||
if (isStageBased) {
|
||||
HspList hspList;
|
||||
ErrCode ret = bundleMgr->GetBaseSharedBundleInfos(appInfo.bundleName, hspList);
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("MainThread::HandleLaunchApplication GetBaseSharedBundleInfos failed: %d", ret);
|
||||
}
|
||||
// Create runtime
|
||||
auto hapPath = entryHapModuleInfo.hapPath;
|
||||
AbilityRuntime::Runtime::Options options;
|
||||
@@ -1092,7 +1099,6 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
options.isDebugVersion = bundleInfo.applicationInfo.debug;
|
||||
options.arkNativeFilePath = bundleInfo.applicationInfo.arkNativeFilePath;
|
||||
options.uid = bundleInfo.applicationInfo.uid;
|
||||
SetNativeLibPath(bundleInfo, hspList, options);
|
||||
auto runtime = AbilityRuntime::Runtime::Create(options);
|
||||
if (!runtime) {
|
||||
HILOG_ERROR("Failed to create runtime");
|
||||
@@ -1108,7 +1114,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
(std::string summary, const JsEnv::ErrorObject errorObj) {
|
||||
auto appThread = weak.promote();
|
||||
if (appThread == nullptr) {
|
||||
HILOG_ERROR("appThread is nullptr, HandleLaunchApplication failed.");
|
||||
HILOG_ERROR("appThread is nullptr.");
|
||||
return;
|
||||
}
|
||||
time_t timet;
|
||||
@@ -1122,7 +1128,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
EVENT_KEY_REASON, errorObj.name,
|
||||
EVENT_KEY_JSVM, JSVM_TYPE,
|
||||
EVENT_KEY_SUMMARY, summary);
|
||||
struct ErrorObject appExecErrorObj = {
|
||||
ErrorObject appExecErrorObj = {
|
||||
.name = errorObj.name,
|
||||
.message = errorObj.message,
|
||||
.stack = errorObj.stack
|
||||
|
||||
@@ -214,7 +214,7 @@ JsRuntime::~JsRuntime()
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<Runtime> JsRuntime::Create(const Options& options)
|
||||
std::unique_ptr<JsRuntime> JsRuntime::Create(const Options& options)
|
||||
{
|
||||
std::unique_ptr<JsRuntime> instance;
|
||||
|
||||
@@ -230,7 +230,7 @@ std::unique_ptr<Runtime> JsRuntime::Create(const Options& options)
|
||||
}
|
||||
|
||||
if (!instance->Initialize(options)) {
|
||||
return std::unique_ptr<Runtime>();
|
||||
return std::unique_ptr<JsRuntime>();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
@@ -371,6 +371,13 @@ bool JsRuntime::NotifyHotReloadPage()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsRuntime::LoadScript(const std::string& path, std::vector<uint8_t>* buffer, bool isBundle)
|
||||
{
|
||||
HILOG_DEBUG("function called.");
|
||||
CHECK_POINTER_AND_RETURN(jsEnv_, false);
|
||||
return jsEnv_->LoadScript(path, buffer, isBundle);
|
||||
}
|
||||
|
||||
std::unique_ptr<NativeReference> JsRuntime::LoadSystemModuleByEngine(NativeEngine* engine,
|
||||
const std::string& moduleName, NativeValue* const* argv, size_t argc)
|
||||
{
|
||||
@@ -490,7 +497,6 @@ bool JsRuntime::Initialize(const Options& options)
|
||||
return false;
|
||||
}
|
||||
|
||||
SetAppLibPath(options.appLibPaths);
|
||||
InitSourceMap(options);
|
||||
|
||||
if (options.isUnique) {
|
||||
@@ -538,8 +544,7 @@ bool JsRuntime::CreateJsEnv(const Options& options)
|
||||
}
|
||||
|
||||
OHOSJsEnvLogger::RegisterJsEnvLogger();
|
||||
auto jsEnvImpl = std::make_shared<OHOSJsEnvironmentImpl>();
|
||||
jsEnv_ = std::make_shared<JsEnv::JsEnvironment>(jsEnvImpl);
|
||||
jsEnv_ = std::make_shared<JsEnv::JsEnvironment>(std::make_unique<OHOSJsEnvironmentImpl>());
|
||||
if (jsEnv_ == nullptr || !jsEnv_->Initialize(pandaOption, static_cast<void*>(this))) {
|
||||
HILOG_ERROR("Initialize js environment failed.");
|
||||
return false;
|
||||
@@ -588,13 +593,23 @@ bool JsRuntime::InitLoop(const std::shared_ptr<AppExecFwk::EventRunner>& eventRu
|
||||
return true;
|
||||
}
|
||||
|
||||
void JsRuntime::SetAppLibPath(const std::map<std::string, std::vector<std::string>>& appLibPaths)
|
||||
void JsRuntime::SetAppLibPath(const AppLibPathMap& appLibPaths)
|
||||
{
|
||||
HILOG_DEBUG("Set library path.");
|
||||
|
||||
if (appLibPaths.size() == 0) {
|
||||
HILOG_WARN("There's no library path need to set.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto moduleManager = NativeModuleManager::GetInstance();
|
||||
if (moduleManager != nullptr) {
|
||||
for (const auto &appLibPath : appLibPaths) {
|
||||
moduleManager->SetAppLibPath(appLibPath.first, appLibPath.second);
|
||||
}
|
||||
if (moduleManager == nullptr) {
|
||||
HILOG_ERROR("Get module manager failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &appLibPath : appLibPaths) {
|
||||
moduleManager->SetAppLibPath(appLibPath.first, appLibPath.second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -755,10 +770,10 @@ bool JsRuntime::RunScript(const std::string& srcPath, const std::string& hapPath
|
||||
std::string vendorsPath = std::string(Constants::LOCAL_CODE_PATH) + "/" + moduleName_ + "/ets/vendors.abc";
|
||||
if (hapPath.empty()) {
|
||||
if (useCommonChunk) {
|
||||
(void)nativeEngine->RunScriptPath(commonsPath.c_str());
|
||||
(void)nativeEngine->RunScriptPath(vendorsPath.c_str());
|
||||
(void)LoadScript(commonsPath);
|
||||
(void)LoadScript(vendorsPath);
|
||||
}
|
||||
return nativeEngine->RunScriptPath(srcPath.c_str()) != nullptr;
|
||||
return LoadScript(srcPath);
|
||||
}
|
||||
|
||||
bool newCreate = false;
|
||||
@@ -789,7 +804,7 @@ bool JsRuntime::RunScript(const std::string& srcPath, const std::string& hapPath
|
||||
std::vector<uint8_t> buffer;
|
||||
buffer.assign(outStr.begin(), outStr.end());
|
||||
|
||||
return nativeEngine->RunScriptBuffer(abcPath.c_str(), buffer, isBundle_) != nullptr;
|
||||
return LoadScript(abcPath, &buffer, isBundle_);
|
||||
};
|
||||
|
||||
if (useCommonChunk) {
|
||||
|
||||
@@ -41,6 +41,8 @@ class JsEnvironment;
|
||||
struct UncaughtInfo;
|
||||
} // namespace JsEnv
|
||||
|
||||
using AppLibPathMap = std::map<std::string, std::vector<std::string>>;
|
||||
|
||||
namespace AbilityRuntime {
|
||||
class TimerTask;
|
||||
class ModSourceMap;
|
||||
@@ -52,11 +54,13 @@ inline void *DetachCallbackFunc(NativeEngine *engine, void *value, void *)
|
||||
|
||||
class JsRuntime : public Runtime {
|
||||
public:
|
||||
static std::unique_ptr<Runtime> Create(const Options& options);
|
||||
static std::unique_ptr<JsRuntime> Create(const Options& options);
|
||||
|
||||
static std::unique_ptr<NativeReference> LoadSystemModuleByEngine(NativeEngine* engine,
|
||||
const std::string& moduleName, NativeValue* const* argv, size_t argc);
|
||||
|
||||
static void SetAppLibPath(const AppLibPathMap& appLibPaths);
|
||||
|
||||
JsRuntime();
|
||||
~JsRuntime() override;
|
||||
|
||||
@@ -92,6 +96,7 @@ public:
|
||||
bool UnLoadRepairPatch(const std::string& hqfFile) override;
|
||||
bool NotifyHotReloadPage() override;
|
||||
void RegisterUncaughtExceptionHandler(JsEnv::UncaughtInfo uncaughtInfo);
|
||||
bool LoadScript(const std::string& path, std::vector<uint8_t>* buffer = nullptr, bool isBundle = false);
|
||||
|
||||
NativeEngine* GetNativeEnginePointer() const;
|
||||
panda::ecmascript::EcmaVM* GetEcmaVm() const;
|
||||
@@ -128,7 +133,6 @@ private:
|
||||
bool CreateJsEnv(const Options& options);
|
||||
void PreloadAce(const Options& options);
|
||||
void InitSourceMap(const Options& options);
|
||||
void SetAppLibPath(const std::map<std::string, std::vector<std::string>>& appLibPaths);
|
||||
bool InitLoop(const std::shared_ptr<AppExecFwk::EventRunner>& eventRunner);
|
||||
inline bool IsUseAbilityRuntime(const Options& options) const;
|
||||
};
|
||||
|
||||
@@ -43,7 +43,6 @@ public:
|
||||
std::string bundleName;
|
||||
std::string codePath;
|
||||
std::string bundleCodeDir;
|
||||
std::map<std::string, std::vector<std::string>> appLibPaths {};
|
||||
std::string hapPath;
|
||||
std::string arkNativeFilePath;
|
||||
std::shared_ptr<AppExecFwk::EventRunner> eventRunner;
|
||||
|
||||
@@ -32,32 +32,30 @@ public:
|
||||
~UriPermissionManagerClient() = default;
|
||||
|
||||
/**
|
||||
* @brief Authorize the uri permission of fromTokenId to targetTokenId.
|
||||
* @brief Authorize the uri permission of to targetBundleName.
|
||||
*
|
||||
* @param uri The file uri.
|
||||
* @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
|
||||
* @param fromTokenId The owner of uri.
|
||||
* @param targetTokenId The user of uri.
|
||||
* @param targetBundleName The user of uri.
|
||||
* @param autoremove the uri is temperarily or not
|
||||
*/
|
||||
bool GrantUriPermission(const Uri &uri, unsigned int flag, const Security::AccessToken::AccessTokenID fromTokenId,
|
||||
const Security::AccessToken::AccessTokenID targetTokenId);
|
||||
int GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove);
|
||||
|
||||
/**
|
||||
* @brief Check whether the tokenId has URI permissions.
|
||||
* @brief Clear user's uri authorization record with auto remove flag.
|
||||
*
|
||||
* @param uri The file uri.
|
||||
* @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
|
||||
* @param tokenId The user of uri.
|
||||
* @return Returns true if the verification is successful, otherwise returns false.
|
||||
* @param tokenId A tokenId of an application.
|
||||
*/
|
||||
bool VerifyUriPermission(const Uri &uri, unsigned int flag, const Security::AccessToken::AccessTokenID tokenId);
|
||||
void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId);
|
||||
|
||||
/**
|
||||
* @brief Clear user's uri authorization record.
|
||||
*
|
||||
* @param tokenId A tokenId of an application.
|
||||
* @param uri The file uri.
|
||||
* @param BundleName A BundleName of an application.
|
||||
*/
|
||||
void RemoveUriPermission(const Security::AccessToken::AccessTokenID tokenId);
|
||||
int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName);
|
||||
|
||||
private:
|
||||
sptr<IUriPermissionManager> ConnectUriPermService();
|
||||
|
||||
@@ -27,44 +27,42 @@ public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.ability.UriPermissionManager");
|
||||
|
||||
/**
|
||||
* @brief Authorize the uri permission of fromTokenId to targetTokenId.
|
||||
* @brief Authorize the uri permission to targetBundleName.
|
||||
*
|
||||
* @param uri The file uri.
|
||||
* @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
|
||||
* @param fromTokenId The owner of uri.
|
||||
* @param targetTokenId The user of uri.
|
||||
* @param targetBundleName The user of uri.
|
||||
* @param autoremove the uri is temperarily or not
|
||||
* @return Returns true if the authorization is successful, otherwise returns false.
|
||||
*/
|
||||
virtual bool GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID fromTokenId,
|
||||
const Security::AccessToken::AccessTokenID targetTokenId) = 0;
|
||||
virtual int GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check whether the tokenId has URI permissions.
|
||||
* @brief Clear user's uri authorization record with autoremove flag.
|
||||
*
|
||||
* @param uri The file uri.
|
||||
* @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
|
||||
* @param tokenId The user of uri.
|
||||
* @return Returns true if the verification is successful, otherwise returns false.
|
||||
* @param tokenId A tokenId of an application.
|
||||
* @return Returns true if the remove is successful, otherwise returns false.
|
||||
*/
|
||||
virtual bool VerifyUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID tokenId) = 0;
|
||||
virtual void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId) = 0;
|
||||
|
||||
/**
|
||||
* @brief Clear user's uri authorization record.
|
||||
*
|
||||
* @param tokenId A tokenId of an application.
|
||||
* @param uri The file uri.
|
||||
* @param bundleName bundleName of an application.
|
||||
* @return Returns true if the remove is successful, otherwise returns false.
|
||||
*/
|
||||
virtual void RemoveUriPermission(const Security::AccessToken::AccessTokenID tokenId) = 0;
|
||||
virtual int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) = 0;
|
||||
|
||||
enum UriPermMgrCmd {
|
||||
// ipc id for GrantUriPermission
|
||||
ON_GRANT_URI_PERMISSION = 0,
|
||||
|
||||
// ipc id for VerifyUriPermission
|
||||
ON_VERIFY_URI_PERMISSION,
|
||||
// ipc id for RevokeUriPermission
|
||||
ON_REVOKE_URI_PERMISSION,
|
||||
|
||||
// ipc id for RemoveUriPermission
|
||||
ON_REMOVE_URI_PERMISSION,
|
||||
ON_REVOKE_URI_PERMISSION_MANUALLY,
|
||||
};
|
||||
};
|
||||
} // namespace AAFwk
|
||||
|
||||
@@ -26,14 +26,11 @@ public:
|
||||
explicit UriPermissionManagerProxy(const sptr<IRemoteObject> &impl);
|
||||
virtual ~UriPermissionManagerProxy() = default;
|
||||
|
||||
virtual bool GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID fromTokenId,
|
||||
const Security::AccessToken::AccessTokenID targetTokenId) override;
|
||||
virtual int GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove) override;
|
||||
|
||||
virtual bool VerifyUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID tokenId) override;
|
||||
|
||||
virtual void RemoveUriPermission(const Security::AccessToken::AccessTokenID tokenId) override;
|
||||
virtual void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId) override;
|
||||
virtual int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<UriPermissionManagerProxy> delegator_;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "uri_permission_manager_client.h"
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
@@ -22,35 +23,35 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
bool UriPermissionManagerClient::GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID fromTokenId, const Security::AccessToken::AccessTokenID targetTokenId)
|
||||
int UriPermissionManagerClient::GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove)
|
||||
{
|
||||
HILOG_DEBUG("UriPermissionManagerClient::GrantUriPermission is called.");
|
||||
HILOG_DEBUG("targetBundleName :%{public}s", targetBundleName.c_str());
|
||||
auto uriPermMgr = ConnectUriPermService();
|
||||
if (uriPermMgr) {
|
||||
return uriPermMgr->GrantUriPermission(uri, flag, fromTokenId, targetTokenId);
|
||||
return uriPermMgr->GrantUriPermission(uri, flag, targetBundleName, autoremove);
|
||||
}
|
||||
return false;
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
bool UriPermissionManagerClient::VerifyUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID tokenId)
|
||||
void UriPermissionManagerClient::RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId)
|
||||
{
|
||||
HILOG_DEBUG("UriPermissionManagerClient::VerifyUriPermission is called.");
|
||||
HILOG_DEBUG("UriPermissionManagerClient::RevokeUriPermission is called.");
|
||||
auto uriPermMgr = ConnectUriPermService();
|
||||
if (uriPermMgr) {
|
||||
return uriPermMgr->VerifyUriPermission(uri, flag, tokenId);
|
||||
return uriPermMgr->RevokeUriPermission(tokenId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UriPermissionManagerClient::RemoveUriPermission(const Security::AccessToken::AccessTokenID tokenId)
|
||||
int UriPermissionManagerClient::RevokeUriPermissionManually(const Uri &uri, const std::string bundleName)
|
||||
{
|
||||
HILOG_DEBUG("UriPermissionManagerClient::RemoveUriPermission is called.");
|
||||
HILOG_DEBUG("UriPermissionManagerClient::RevokeUriPermissionManually is called.");
|
||||
auto uriPermMgr = ConnectUriPermService();
|
||||
if (uriPermMgr) {
|
||||
uriPermMgr->RemoveUriPermission(tokenId);
|
||||
return uriPermMgr->RevokeUriPermissionManually(uri, bundleName);
|
||||
}
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
sptr<IUriPermissionManager> UriPermissionManagerClient::ConnectUriPermService()
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "uri_permission_manager_proxy.h"
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "parcel.h"
|
||||
|
||||
@@ -23,75 +24,44 @@ namespace AAFwk {
|
||||
UriPermissionManagerProxy::UriPermissionManagerProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<IUriPermissionManager>(impl) {}
|
||||
|
||||
bool UriPermissionManagerProxy::GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID fromTokenId, const Security::AccessToken::AccessTokenID targetTokenId)
|
||||
int UriPermissionManagerProxy::GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove)
|
||||
{
|
||||
HILOG_DEBUG("UriPermissionManagerProxy::GrantUriPermission is called.");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(IUriPermissionManager::GetDescriptor())) {
|
||||
HILOG_ERROR("Write interface token failed.");
|
||||
return false;
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (!data.WriteParcelable(&uri)) {
|
||||
HILOG_ERROR("Write uri failed.");
|
||||
return false;
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (!data.WriteInt32(flag)) {
|
||||
HILOG_ERROR("Write flag failed.");
|
||||
return false;
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (!data.WriteInt32(fromTokenId)) {
|
||||
HILOG_ERROR("Write fromTokenId failed.");
|
||||
return false;
|
||||
if (!data.WriteString(targetBundleName)) {
|
||||
HILOG_ERROR("Write targetBundleName failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (!data.WriteInt32(targetTokenId)) {
|
||||
HILOG_ERROR("Write targetTokenId failed.");
|
||||
return false;
|
||||
if (!data.WriteInt32(autoremove)) {
|
||||
HILOG_ERROR("Write autoremove failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int error = Remote()->SendRequest(UriPermMgrCmd::ON_GRANT_URI_PERMISSION, data, reply, option);
|
||||
if (error != ERR_OK) {
|
||||
HILOG_ERROR("SendRequest fial, error: %{public}d", error);
|
||||
return false;
|
||||
return INNER_ERR;
|
||||
}
|
||||
return reply.ReadBool();
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
bool UriPermissionManagerProxy::VerifyUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID tokenId)
|
||||
void UriPermissionManagerProxy::RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId)
|
||||
{
|
||||
HILOG_DEBUG("UriPermissionManagerProxy::VerifyUriPermission is called.");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(IUriPermissionManager::GetDescriptor())) {
|
||||
HILOG_ERROR("Write interface token failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteParcelable(&uri)) {
|
||||
HILOG_ERROR("Write uri failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(flag)) {
|
||||
HILOG_ERROR("Write flag failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(tokenId)) {
|
||||
HILOG_ERROR("Write tokenId failed.");
|
||||
return false;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int error = Remote()->SendRequest(UriPermMgrCmd::ON_VERIFY_URI_PERMISSION, data, reply, option);
|
||||
if (error != ERR_OK) {
|
||||
HILOG_ERROR("SendRequest fial, error: %{public}d", error);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void UriPermissionManagerProxy::RemoveUriPermission(const Security::AccessToken::AccessTokenID tokenId)
|
||||
{
|
||||
HILOG_DEBUG("UriPermissionManagerProxy::RemoveUriPermission is called.");
|
||||
HILOG_DEBUG("UriPermissionManagerProxy::RevokeUriPermission is called.");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(IUriPermissionManager::GetDescriptor())) {
|
||||
HILOG_ERROR("Write interface token failed.");
|
||||
@@ -103,10 +73,36 @@ void UriPermissionManagerProxy::RemoveUriPermission(const Security::AccessToken:
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int error = Remote()->SendRequest(UriPermMgrCmd::ON_REMOVE_URI_PERMISSION, data, reply, option);
|
||||
int error = Remote()->SendRequest(UriPermMgrCmd::ON_REVOKE_URI_PERMISSION, data, reply, option);
|
||||
if (error != ERR_OK) {
|
||||
HILOG_ERROR("SendRequest fail, error: %{public}d", error);
|
||||
}
|
||||
}
|
||||
|
||||
int UriPermissionManagerProxy::RevokeUriPermissionManually(const Uri &uri, const std::string bundleName)
|
||||
{
|
||||
HILOG_DEBUG("UriPermissionManagerProxy::RevokeUriPermissionManually is called.");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(IUriPermissionManager::GetDescriptor())) {
|
||||
HILOG_ERROR("Write interface token failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (!data.WriteParcelable(&uri)) {
|
||||
HILOG_ERROR("Write uri failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (!data.WriteString(bundleName)) {
|
||||
HILOG_ERROR("Write bundleName failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int error = Remote()->SendRequest(UriPermMgrCmd::ON_REVOKE_URI_PERMISSION_MANUALLY, data, reply, option);
|
||||
if (error != ERR_OK) {
|
||||
HILOG_ERROR("SendRequest fail, error: %{public}d", error);
|
||||
return INNER_ERR;
|
||||
}
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -36,30 +36,27 @@ int UriPermissionManagerStub::OnRemoteRequest(
|
||||
break;
|
||||
}
|
||||
auto flag = data.ReadInt32();
|
||||
auto fromTokenId = data.ReadInt32();
|
||||
auto targetTokenId = data.ReadInt32();
|
||||
auto ret = GrantUriPermission(*uri, flag, fromTokenId, targetTokenId);
|
||||
reply.WriteBool(ret);
|
||||
auto targetBundleName = data.ReadString();
|
||||
auto autoremove = data.ReadInt32();
|
||||
int result = GrantUriPermission(*uri, flag, targetBundleName, autoremove);
|
||||
reply.WriteInt32(result);
|
||||
break;
|
||||
}
|
||||
case UriPermMgrCmd::ON_VERIFY_URI_PERMISSION : {
|
||||
case UriPermMgrCmd::ON_REVOKE_URI_PERMISSION : {
|
||||
auto tokenId = data.ReadInt32();
|
||||
RevokeUriPermission(tokenId);
|
||||
break;
|
||||
}
|
||||
case UriPermMgrCmd::ON_REVOKE_URI_PERMISSION_MANUALLY : {
|
||||
std::unique_ptr<Uri> uri(data.ReadParcelable<Uri>());
|
||||
if (!uri) {
|
||||
errCode = ERR_DEAD_OBJECT;
|
||||
HILOG_ERROR("To read uri failed.");
|
||||
break;
|
||||
}
|
||||
auto flag = data.ReadInt32();
|
||||
auto tokenId = data.ReadInt32();
|
||||
if (!VerifyUriPermission(*uri, flag, tokenId)) {
|
||||
errCode = ERR_INVALID_OPERATION;
|
||||
HILOG_ERROR("To check uri permission failed.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case UriPermMgrCmd::ON_REMOVE_URI_PERMISSION : {
|
||||
auto tokenId = data.ReadInt32();
|
||||
RemoveUriPermission(tokenId);
|
||||
auto bundleName = data.ReadString();
|
||||
int result = RevokeUriPermissionManually(*uri, bundleName);
|
||||
reply.WriteInt32(result);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
+4
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 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
|
||||
@@ -52,6 +52,8 @@ public:
|
||||
int32_t ReleaseRemoteAbility(const sptr<IRemoteObject>& connect, const AppExecFwk::ElementName &element);
|
||||
int32_t StartRemoteFreeInstall(const OHOS::AAFwk::Want& want,
|
||||
int32_t callerUid, int32_t requestCode, uint32_t accessToken, const sptr<IRemoteObject>& callback);
|
||||
int32_t StopRemoteExtensionAbility(const Want &want, int32_t callerUid,
|
||||
uint32_t accessToken, int32_t extensionType);
|
||||
enum {
|
||||
START_REMOTE_ABILITY = 1,
|
||||
CONNECT_REMOTE_ABILITY = 6,
|
||||
@@ -68,6 +70,7 @@ public:
|
||||
START_REMOTE_ABILITY_BY_CALL = 150,
|
||||
RELEASE_REMOTE_ABILITY = 151,
|
||||
START_REMOTE_FREE_INSTALL = 200,
|
||||
STOP_REMOTE_EXTERNSION_ABILITY = 225
|
||||
};
|
||||
private:
|
||||
sptr<IRemoteObject> GetDmsProxy();
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace JsEnv {
|
||||
JsEnvironment::JsEnvironment(std::shared_ptr<JsEnvironmentImpl> impl) : impl_(impl)
|
||||
|
||||
JsEnvironment::JsEnvironment(std::unique_ptr<JsEnvironmentImpl> impl) : impl_(std::move(impl))
|
||||
{
|
||||
JSENV_LOG_D("Js environment costructor.");
|
||||
}
|
||||
@@ -106,17 +107,31 @@ void JsEnvironment::RemoveTask(const std::string& name)
|
||||
}
|
||||
}
|
||||
|
||||
void JsEnvironment::InitSourceMap(const std::string bundleCodeDir, bool isStageModel)
|
||||
void JsEnvironment::InitSourceMap(const std::string& bundleCodeDir, bool isStageModel)
|
||||
{
|
||||
bindSourceMaps_ = std::make_unique<AbilityRuntime::ModSourceMap>(bundleCodeDir, isStageModel);
|
||||
bindSourceMaps_ = std::make_shared<AbilityRuntime::ModSourceMap>(bundleCodeDir, isStageModel);
|
||||
}
|
||||
|
||||
void JsEnvironment::RegisterUncaughtExceptionHandler(JsEnv::UncaughtInfo uncaughtInfo)
|
||||
{
|
||||
if ((bindSourceMaps_ != nullptr) && (engine_ != nullptr)) {
|
||||
engine_->RegisterUncaughtExceptionHandler(UncaughtExceptionCallback(uncaughtInfo.hapPath,
|
||||
uncaughtInfo.uncaughtTask, *bindSourceMaps_));
|
||||
uncaughtInfo.uncaughtTask, bindSourceMaps_));
|
||||
}
|
||||
}
|
||||
|
||||
bool JsEnvironment::LoadScript(const std::string& path, std::vector<uint8_t>* buffer, bool isBundle)
|
||||
{
|
||||
if (engine_ == nullptr) {
|
||||
JSENV_LOG_E("Invalid Native Engine.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (buffer == nullptr) {
|
||||
return engine_->RunScriptPath(path.c_str()) != nullptr;
|
||||
}
|
||||
|
||||
return engine_->RunScriptBuffer(path.c_str(), *buffer, isBundle) != nullptr;
|
||||
}
|
||||
} // namespace JsEnv
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -24,26 +24,26 @@ namespace JsEnv {
|
||||
std::string UncaughtExceptionCallback::GetNativeStrFromJsTaggedObj(NativeObject* obj, const char* key)
|
||||
{
|
||||
if (obj == nullptr) {
|
||||
JSENV_LOG_E("Failed to get value from key:%{public}s, Null NativeObject", key);
|
||||
JSENV_LOG_E("Failed to get value from key.");
|
||||
return "";
|
||||
}
|
||||
|
||||
NativeValue* value = obj->GetProperty(key);
|
||||
NativeString* valueStr = JsEnv::ConvertNativeValueTo<NativeString>(value);
|
||||
if (valueStr == nullptr) {
|
||||
JSENV_LOG_E("Failed to convert value from key:%{public}s", key);
|
||||
JSENV_LOG_E("Failed to convert value from key.");
|
||||
return "";
|
||||
}
|
||||
size_t valueStrBufLength = valueStr->GetLength();
|
||||
size_t valueStrLength = 0;
|
||||
auto valueCStr = std::make_unique<char[]>(valueStrBufLength + 1);
|
||||
if (valueCStr == nullptr) {
|
||||
JSENV_LOG_E("Failed to new valueCStr");
|
||||
JSENV_LOG_E("Failed to new valueCStr.");
|
||||
return "";
|
||||
}
|
||||
valueStr->GetCString(valueCStr.get(), valueStrBufLength + 1, &valueStrLength);
|
||||
std::string ret(valueCStr.get(), valueStrLength);
|
||||
JSENV_LOG_D("GetNativeStrFromJsTaggedObj Success %{public}s:%{public}s", key, ret.c_str());
|
||||
JSENV_LOG_D("GetNativeStrFromJsTaggedObj Success.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,6 @@ void UncaughtExceptionCallback::operator()(NativeValue* value)
|
||||
JSENV_LOG_E("errorStack is empty");
|
||||
return;
|
||||
}
|
||||
JSENV_LOG_I("JS Stack:\n%{public}s", errorStack.c_str());
|
||||
auto errorPos = AbilityRuntime::ModSourceMap::GetErrorPos(errorStack);
|
||||
std::string error;
|
||||
if (obj != nullptr) {
|
||||
@@ -78,7 +77,7 @@ void UncaughtExceptionCallback::operator()(NativeValue* value)
|
||||
}
|
||||
}
|
||||
summary += error + "Stacktrace:\n" +
|
||||
AbilityRuntime::ModSourceMap::TranslateBySourceMap(errorStack, bindSourceMaps_, hapPath_);
|
||||
AbilityRuntime::ModSourceMap::TranslateBySourceMap(errorStack, *bindSourceMaps_, hapPath_);
|
||||
if (uncaughtTask_) {
|
||||
uncaughtTask_(summary, errorObj);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class JsEnvironmentImpl;
|
||||
class JsEnvironment final {
|
||||
public:
|
||||
JsEnvironment() {}
|
||||
explicit JsEnvironment(std::shared_ptr<JsEnvironmentImpl> impl);
|
||||
explicit JsEnvironment(std::unique_ptr<JsEnvironmentImpl> impl);
|
||||
~JsEnvironment();
|
||||
|
||||
bool Initialize(const panda::RuntimeOption& pandaOption, void* jsEngine);
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
|
||||
void InitWorkerModule();
|
||||
|
||||
void InitSourceMap(std::string bundleCodeDir, bool isStageModel);
|
||||
void InitSourceMap(const std::string& bundleCodeDir, bool isStageModel);
|
||||
|
||||
void InitSyscapModule();
|
||||
|
||||
@@ -63,11 +63,12 @@ public:
|
||||
void RemoveTask(const std::string& name);
|
||||
|
||||
void RegisterUncaughtExceptionHandler(JsEnv::UncaughtInfo uncaughtInfo);
|
||||
bool LoadScript(const std::string& path, std::vector<uint8_t>* buffer = nullptr, bool isBundle = false);
|
||||
private:
|
||||
std::shared_ptr<JsEnvironmentImpl> impl_ = nullptr;
|
||||
std::unique_ptr<JsEnvironmentImpl> impl_ = nullptr;
|
||||
NativeEngine* engine_ = nullptr;
|
||||
panda::ecmascript::EcmaVM* vm_ = nullptr;
|
||||
std::unique_ptr<AbilityRuntime::ModSourceMap> bindSourceMaps_;
|
||||
std::shared_ptr<AbilityRuntime::ModSourceMap> bindSourceMaps_;
|
||||
};
|
||||
} // namespace JsEnv
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -41,8 +41,9 @@ class UncaughtExceptionCallback final {
|
||||
public:
|
||||
UncaughtExceptionCallback(const std::string hapPath,
|
||||
std::function<void(std::string summary, const JsEnv::ErrorObject errorObj)> uncaughtTask,
|
||||
AbilityRuntime::ModSourceMap& bindSourceMaps) :
|
||||
hapPath_(hapPath), uncaughtTask_(uncaughtTask), bindSourceMaps_(bindSourceMaps) {}
|
||||
std::shared_ptr<AbilityRuntime::ModSourceMap> bindSourceMaps)
|
||||
: hapPath_(hapPath), uncaughtTask_(uncaughtTask), bindSourceMaps_(bindSourceMaps)
|
||||
{}
|
||||
|
||||
virtual ~UncaughtExceptionCallback() {};
|
||||
|
||||
@@ -52,7 +53,7 @@ public:
|
||||
private:
|
||||
std::string hapPath_;
|
||||
std::function<void(std::string summary, const JsEnv::ErrorObject errorObj)> uncaughtTask_;
|
||||
AbilityRuntime::ModSourceMap& bindSourceMaps_;
|
||||
std::shared_ptr<AbilityRuntime::ModSourceMap> bindSourceMaps_;
|
||||
};
|
||||
} // namespace JsEnv
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
# 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.
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("../../../js_environment.gni")
|
||||
@@ -24,6 +24,7 @@ ohos_unittest("js_env_log_test") {
|
||||
configs = []
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:js_environment",
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
|
||||
@@ -58,8 +58,7 @@ void JsEnvironmentTest::TearDown()
|
||||
*/
|
||||
HWTEST_F(JsEnvironmentTest, JsEnvInitialize_0100, TestSize.Level0)
|
||||
{
|
||||
auto jsEnvImpl = std::make_shared<AbilityRuntime::OHOSJsEnvironmentImpl>();
|
||||
auto jsEnv = std::make_shared<JsEnvironment>(jsEnvImpl);
|
||||
auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
|
||||
ASSERT_NE(jsEnv, nullptr);
|
||||
|
||||
panda::RuntimeOption pandaOption;
|
||||
@@ -72,5 +71,55 @@ HWTEST_F(JsEnvironmentTest, JsEnvInitialize_0100, TestSize.Level0)
|
||||
auto nativeEngine = jsEnv->GetNativeEngine();
|
||||
EXPECT_NE(nativeEngine, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadScript_0100
|
||||
* @tc.desc: load script with invalid engine.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6KODF
|
||||
*/
|
||||
HWTEST_F(JsEnvironmentTest, LoadScript_0100, TestSize.Level0)
|
||||
{
|
||||
auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
|
||||
ASSERT_NE(jsEnv, nullptr);
|
||||
|
||||
EXPECT_EQ(jsEnv->LoadScript(""), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadScript_0200
|
||||
* @tc.desc: load script with invalid path.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6KODF
|
||||
*/
|
||||
HWTEST_F(JsEnvironmentTest, LoadScript_0200, TestSize.Level0)
|
||||
{
|
||||
auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
|
||||
ASSERT_NE(jsEnv, nullptr);
|
||||
|
||||
panda::RuntimeOption pandaOption;
|
||||
auto ret = jsEnv->Initialize(pandaOption, static_cast<void*>(this));
|
||||
ASSERT_EQ(ret, true);
|
||||
|
||||
EXPECT_EQ(jsEnv->LoadScript(""), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadScript_0300
|
||||
* @tc.desc: load script with specify path.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6KODF
|
||||
*/
|
||||
HWTEST_F(JsEnvironmentTest, LoadScript_0300, TestSize.Level0)
|
||||
{
|
||||
auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
|
||||
ASSERT_NE(jsEnv, nullptr);
|
||||
|
||||
panda::RuntimeOption pandaOption;
|
||||
auto ret = jsEnv->Initialize(pandaOption, static_cast<void*>(this));
|
||||
ASSERT_EQ(ret, true);
|
||||
|
||||
EXPECT_EQ(jsEnv->LoadScript("/system/etc/strip.native.min.abc"), true);
|
||||
}
|
||||
} // namespace JsEnv
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -834,7 +834,7 @@ public:
|
||||
void SetNeedBackToOtherMissionStack(bool isNeedBackToOtherMissionStack);
|
||||
std::shared_ptr<AbilityRecord> GetOtherMissionStackAbilityRecord() const;
|
||||
void SetOtherMissionStackAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord);
|
||||
void RemoveUriPermission();
|
||||
void RevokeUriPermission();
|
||||
|
||||
protected:
|
||||
void SendEvent(uint32_t msg, uint32_t timeOut);
|
||||
@@ -851,7 +851,7 @@ private:
|
||||
*/
|
||||
void GetAbilityTypeString(std::string &typeStr);
|
||||
void OnSchedulerDied(const wptr<IRemoteObject> &remote);
|
||||
void GrantUriPermission(const Want &want, int32_t userId, uint32_t targetTokenId);
|
||||
void GrantUriPermission(const Want &want, int32_t userId, std::string targetBundleName);
|
||||
int32_t GetCurrentAccountId() const;
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,6 +36,7 @@ bool AbilityConnectionProxy::WriteInterfaceToken(MessageParcel &data)
|
||||
void AbilityConnectionProxy::OnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
|
||||
{
|
||||
HILOG_INFO("OnAbilityConnectDone resultCode: %{public}d", resultCode);
|
||||
int error;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@@ -70,6 +71,7 @@ void AbilityConnectionProxy::OnAbilityConnectDone(
|
||||
|
||||
void AbilityConnectionProxy::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
|
||||
{
|
||||
HILOG_INFO("OnAbilityDisconnectDone resultCode: %{public}d", resultCode);
|
||||
int error;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@@ -100,11 +102,11 @@ AbilityConnectionStub::~AbilityConnectionStub()
|
||||
int AbilityConnectionStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
HILOG_DEBUG("AbilityConnectionStub::OnRemoteRequest OnAbilityConnectDone called.");
|
||||
HILOG_INFO("AbilityConnectionStub::OnRemoteRequest code: %{public}ud", code);
|
||||
std::u16string descriptor = AbilityConnectionStub::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
HILOG_INFO("Local descriptor is not equal to remote");
|
||||
HILOG_ERROR("Local descriptor is not equal to remote");
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1250,10 +1250,15 @@ int AbilityManagerService::StopExtensionAbility(const Want &want, const sptr<IRe
|
||||
|
||||
if (callerToken != nullptr && !VerificationAllToken(callerToken)) {
|
||||
HILOG_ERROR("%{public}s VerificationAllToken failed.", __func__);
|
||||
eventInfo.errCode = ERR_INVALID_VALUE;
|
||||
EventReport::SendExtensionEvent(EventName::STOP_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo);
|
||||
return ERR_INVALID_CALLER;
|
||||
if (!AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission()) {
|
||||
HILOG_ERROR("VerificationAllToken failed.");
|
||||
eventInfo.errCode = ERR_INVALID_VALUE;
|
||||
EventReport::SendExtensionEvent(EventName::STOP_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo);
|
||||
return ERR_INVALID_CALLER;
|
||||
}
|
||||
HILOG_DEBUG("Caller is specific system ability.");
|
||||
}
|
||||
|
||||
int32_t validUserId = GetValidUserId(userId);
|
||||
if (!JudgeMultiUserConcurrency(validUserId)) {
|
||||
HILOG_ERROR("Multi-user non-concurrent mode is not satisfied.");
|
||||
@@ -1262,6 +1267,13 @@ int AbilityManagerService::StopExtensionAbility(const Want &want, const sptr<IRe
|
||||
return ERR_CROSS_USER;
|
||||
}
|
||||
|
||||
if (callerToken != nullptr && CheckIfOperateRemote(want)) {
|
||||
auto callerUid = IPCSkeleton::GetCallingUid();
|
||||
uint32_t accessToken = IPCSkeleton::GetCallingTokenID();
|
||||
DistributedClient dmsClient;
|
||||
return dmsClient.StopRemoteExtensionAbility(want, callerUid, accessToken, eventInfo.extensionType);
|
||||
}
|
||||
|
||||
AbilityRequest abilityRequest;
|
||||
result = GenerateExtensionAbilityRequest(want, abilityRequest, callerToken, validUserId);
|
||||
if (result != ERR_OK) {
|
||||
|
||||
@@ -506,7 +506,8 @@ void AbilityRecord::ProcessForegroundAbility(bool isRecent, const AbilityRequest
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
std::string element = GetWant().GetElement().GetURI();
|
||||
HILOG_DEBUG("SUPPORT_GRAPHICS: ability record: %{public}s", element.c_str());
|
||||
GrantUriPermission(want_, GetCurrentAccountId(), applicationInfo_.accessTokenId);
|
||||
|
||||
GrantUriPermission(want_, GetCurrentAccountId(), applicationInfo_.bundleName);
|
||||
|
||||
if (isReady_) {
|
||||
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetEventHandler();
|
||||
@@ -1292,7 +1293,7 @@ void AbilityRecord::SendResult()
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
CHECK_POINTER(scheduler_);
|
||||
CHECK_POINTER(result_);
|
||||
GrantUriPermission(result_->resultWant_, GetCurrentAccountId(), applicationInfo_.accessTokenId);
|
||||
GrantUriPermission(result_->resultWant_, GetCurrentAccountId(), applicationInfo_.bundleName);
|
||||
scheduler_->SendResult(result_->requestCode_, result_->resultCode_, result_->resultWant_);
|
||||
// reset result to avoid send result next time
|
||||
result_.reset();
|
||||
@@ -1774,7 +1775,7 @@ void AbilityRecord::OnSchedulerDied(const wptr<IRemoteObject> &remote)
|
||||
return;
|
||||
}
|
||||
|
||||
RemoveUriPermission();
|
||||
RevokeUriPermission();
|
||||
if (scheduler_ != nullptr && schedulerDeathRecipient_ != nullptr) {
|
||||
auto schedulerObject = scheduler_->AsObject();
|
||||
if (schedulerObject != nullptr) {
|
||||
@@ -2077,7 +2078,7 @@ void AbilityRecord::CallRequest()
|
||||
HILOG_INFO("Call Request.");
|
||||
CHECK_POINTER(scheduler_);
|
||||
|
||||
GrantUriPermission(want_, GetCurrentAccountId(), applicationInfo_.accessTokenId);
|
||||
GrantUriPermission(want_, GetCurrentAccountId(), applicationInfo_.bundleName);
|
||||
// Async call request
|
||||
scheduler_->CallRequest();
|
||||
}
|
||||
@@ -2234,7 +2235,7 @@ void AbilityRecord::DumpAbilityInfoDone(std::vector<std::string> &infos)
|
||||
dumpCondition_.notify_all();
|
||||
}
|
||||
|
||||
void AbilityRecord::GrantUriPermission(const Want &want, int32_t userId, uint32_t targetTokenId)
|
||||
void AbilityRecord::GrantUriPermission(const Want &want, int32_t userId, std::string targetBundleName)
|
||||
{
|
||||
if ((want.GetFlags() & (Want::FLAG_AUTH_READ_URI_PERMISSION | Want::FLAG_AUTH_WRITE_URI_PERMISSION)) == 0) {
|
||||
HILOG_WARN("Do not call uriPermissionMgr.");
|
||||
@@ -2271,20 +2272,21 @@ void AbilityRecord::GrantUriPermission(const Want &want, int32_t userId, uint32_
|
||||
HILOG_ERROR("the uri does not belong to caller.");
|
||||
continue;
|
||||
}
|
||||
int autoremove = 1;
|
||||
auto ret = IN_PROCESS_CALL(upmClient->GrantUriPermission(uri, want.GetFlags(),
|
||||
callerAccessTokenId_, targetTokenId));
|
||||
targetBundleName, autoremove));
|
||||
if (ret) {
|
||||
isGrantedUriPermission_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityRecord::RemoveUriPermission()
|
||||
void AbilityRecord::RevokeUriPermission()
|
||||
{
|
||||
if (isGrantedUriPermission_) {
|
||||
HILOG_DEBUG("To remove uri permission.");
|
||||
auto upmClient = AAFwk::UriPermissionManagerClient::GetInstance();
|
||||
upmClient->RemoveUriPermission(applicationInfo_.accessTokenId);
|
||||
upmClient->RevokeUriPermission(applicationInfo_.accessTokenId);
|
||||
isGrantedUriPermission_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,10 +133,11 @@ void ConnectionRecord::CompleteConnect(int resultCode)
|
||||
abilityInfo.name, abilityInfo.moduleName);
|
||||
auto remoteObject = targetService_->GetConnRemoteObject();
|
||||
if (connCallback_) {
|
||||
HILOG_DEBUG("OnAbilityConnectDone");
|
||||
connCallback_->OnAbilityConnectDone(element, remoteObject, resultCode);
|
||||
}
|
||||
DelayedSingleton<ConnectionStateManager>::GetInstance()->AddConnection(shared_from_this());
|
||||
HILOG_INFO("result: %{public}d. connectstate:%{public}d.", resultCode, state_);
|
||||
HILOG_INFO("result: %{public}d. connectState:%{public}d.", resultCode, state_);
|
||||
}
|
||||
|
||||
void ConnectionRecord::CompleteDisconnect(int resultCode, bool isDied)
|
||||
@@ -149,10 +150,11 @@ void ConnectionRecord::CompleteDisconnect(int resultCode, bool isDied)
|
||||
AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName,
|
||||
abilityInfo.name, abilityInfo.moduleName);
|
||||
if (connCallback_) {
|
||||
HILOG_DEBUG("OnAbilityDisconnectDone");
|
||||
connCallback_->OnAbilityDisconnectDone(element, isDied ? (resultCode - 1) : resultCode);
|
||||
}
|
||||
DelayedSingleton<ConnectionStateManager>::GetInstance()->RemoveConnection(shared_from_this(), isDied);
|
||||
HILOG_INFO("result: %{public}d. connectstate:%{public}d.", resultCode, state_);
|
||||
HILOG_INFO("result: %{public}d. connectState:%{public}d.", resultCode, state_);
|
||||
}
|
||||
|
||||
void ConnectionRecord::ScheduleDisconnectAbilityDone()
|
||||
|
||||
@@ -1558,7 +1558,7 @@ void MissionListManager::CompleteTerminateAndUpdateMission(const std::shared_ptr
|
||||
CHECK_POINTER(abilityRecord);
|
||||
for (auto it : terminateAbilityList_) {
|
||||
if (it == abilityRecord) {
|
||||
abilityRecord->RemoveUriPermission();
|
||||
abilityRecord->RevokeUriPermission();
|
||||
terminateAbilityList_.remove(it);
|
||||
// update inner mission info time
|
||||
bool excludeFromMissions = abilityRecord->GetAbilityInfo().excludeFromMissions;
|
||||
@@ -1880,7 +1880,7 @@ void MissionListManager::OnTimeOut(uint32_t msgId, int64_t abilityRecordId)
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("Ability timeout,msg:%{public}d,name:%{public}s", msgId, abilityRecord->GetAbilityInfo().name.c_str());
|
||||
abilityRecord->RemoveUriPermission();
|
||||
abilityRecord->RevokeUriPermission();
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
if (abilityRecord->IsStartingWindow()) {
|
||||
|
||||
@@ -35,6 +35,7 @@ constexpr const char* PERMISSION_START_ABILITIES_FROM_BACKGROUND = "ohos.permiss
|
||||
constexpr const char* PERMISSION_START_ABILIIES_FROM_BACKGROUND = "ohos.permission.START_ABILIIES_FROM_BACKGROUND";
|
||||
constexpr const char* PERMISSION_ABILITY_BACKGROUND_COMMUNICATION = "ohos.permission.ABILITY_BACKGROUND_COMMUNICATION";
|
||||
constexpr const char* PERMISSION_MANAGER_ABILITY_FROM_GATEWAY = "ohos.permission.MANAGER_ABILITY_FROM_GATEWAY";
|
||||
constexpr const char* PERMISSION_PROXY_AUTHORIZATION_URI = "ohos.permission.PROXY_AUTHORIZATION_URI";
|
||||
} // namespace PermissionConstants
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -36,8 +36,10 @@ ohos_shared_library("libupms") {
|
||||
|
||||
sources = libupms_sources
|
||||
|
||||
deps =
|
||||
[ "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr" ]
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
@@ -65,8 +67,10 @@ ohos_static_library("libupms_static") {
|
||||
|
||||
sources = libupms_sources
|
||||
|
||||
deps =
|
||||
[ "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr" ]
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
|
||||
@@ -33,6 +33,7 @@ struct GrantInfo {
|
||||
unsigned int flag;
|
||||
const unsigned int fromTokenId;
|
||||
const unsigned int targetTokenId;
|
||||
int autoremove;
|
||||
};
|
||||
class UriPermissionManagerStubImpl : public UriPermissionManagerStub,
|
||||
public std::enable_shared_from_this<UriPermissionManagerStubImpl> {
|
||||
@@ -40,13 +41,11 @@ public:
|
||||
UriPermissionManagerStubImpl() = default;
|
||||
virtual ~UriPermissionManagerStubImpl() = default;
|
||||
|
||||
bool GrantUriPermission(const Uri &uri, unsigned int flag, const Security::AccessToken::AccessTokenID fromTokenId,
|
||||
const Security::AccessToken::AccessTokenID targetTokenId) override;
|
||||
int GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove) override;
|
||||
|
||||
bool VerifyUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID tokenId) override;
|
||||
|
||||
void RemoveUriPermission(const Security::AccessToken::AccessTokenID tokenId) override;
|
||||
void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId) override;
|
||||
int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) override;
|
||||
|
||||
private:
|
||||
sptr<AppExecFwk::IBundleMgr> ConnectBundleManager();
|
||||
@@ -54,6 +53,10 @@ private:
|
||||
int GetCurrentAccountId();
|
||||
void ClearBMSProxy();
|
||||
void ClearSMProxy();
|
||||
int GrantUriPermissionImpl(const Uri &uri, unsigned int flag,
|
||||
Security::AccessToken::AccessTokenID fromTokenId,
|
||||
Security::AccessToken::AccessTokenID targetTokenId, int autoremove);
|
||||
Security::AccessToken::AccessTokenID GetTokenIdByBundleName(const std::string bundleName);
|
||||
|
||||
class BMSOrSMDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "uri_permission_manager_stub_impl.h"
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
@@ -22,6 +23,8 @@
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "os_account_manager_wrapper.h"
|
||||
#include "permission_constants.h"
|
||||
#include "permission_verification.h"
|
||||
#include "singleton.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "want.h"
|
||||
@@ -29,20 +32,28 @@
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
const int32_t DEFAULT_USER_ID = 0;
|
||||
const int32_t ERR_OK = 0;
|
||||
using TokenId = Security::AccessToken::AccessTokenID;
|
||||
|
||||
bool UriPermissionManagerStubImpl::GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const TokenId fromTokenId, const TokenId targetTokenId)
|
||||
int UriPermissionManagerStubImpl::GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove)
|
||||
{
|
||||
auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(IPCSkeleton::GetCallingTokenID());
|
||||
if (tokenType != Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) {
|
||||
HILOG_DEBUG("caller tokenType is not native, verify failure.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((flag & (Want::FLAG_AUTH_READ_URI_PERMISSION | Want::FLAG_AUTH_WRITE_URI_PERMISSION)) == 0) {
|
||||
HILOG_WARN("UriPermissionManagerStubImpl::GrantUriPermission: The param flag is invalid.");
|
||||
return false;
|
||||
return INNER_ERR;
|
||||
}
|
||||
Uri uri_inner = uri;
|
||||
auto&& authority = uri_inner.GetAuthority();
|
||||
Security::AccessToken::AccessTokenID fromTokenId = GetTokenIdByBundleName(authority);
|
||||
Security::AccessToken::AccessTokenID targetTokenId = GetTokenIdByBundleName(targetBundleName);
|
||||
auto callerTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerTokenId);
|
||||
auto permission = PermissionVerification::GetInstance()->VerifyCallingPermission(
|
||||
AAFwk::PermissionConstants::PERMISSION_PROXY_AUTHORIZATION_URI);
|
||||
if (tokenType != Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE &&
|
||||
!permission && (fromTokenId != callerTokenId)) {
|
||||
HILOG_WARN("UriPermissionManagerStubImpl::GrantUriPermission: No permission for proxy authorization uri.");
|
||||
return CHECK_PERMISSION_FAILED;
|
||||
}
|
||||
unsigned int tmpFlag = 0;
|
||||
if (flag & Want::FLAG_AUTH_WRITE_URI_PERMISSION) {
|
||||
@@ -50,104 +61,77 @@ bool UriPermissionManagerStubImpl::GrantUriPermission(const Uri &uri, unsigned i
|
||||
} else {
|
||||
tmpFlag = Want::FLAG_AUTH_READ_URI_PERMISSION;
|
||||
}
|
||||
auto&& scheme = uri_inner.GetScheme();
|
||||
if (scheme != "file") {
|
||||
HILOG_WARN("only support file uri.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
// auto remove URI permission for clipboard
|
||||
Security::AccessToken::NativeTokenInfo nativeInfo;
|
||||
Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(callerTokenId, nativeInfo);
|
||||
HILOG_DEBUG("callerprocessName : %{public}s", nativeInfo.processName.c_str());
|
||||
if (nativeInfo.processName == "pasteboard_serv") {
|
||||
autoremove = 1;
|
||||
}
|
||||
return GrantUriPermissionImpl(uri, tmpFlag, fromTokenId, targetTokenId, autoremove);
|
||||
}
|
||||
|
||||
int UriPermissionManagerStubImpl::GrantUriPermissionImpl(const Uri &uri, unsigned int flag,
|
||||
Security::AccessToken::AccessTokenID fromTokenId,
|
||||
Security::AccessToken::AccessTokenID targetTokenId, int autoremove)
|
||||
{
|
||||
auto storageMgrProxy = ConnectStorageManager();
|
||||
if (storageMgrProxy == nullptr) {
|
||||
HILOG_ERROR("ConnectStorageManager failed");
|
||||
return false;
|
||||
return INNER_ERR;
|
||||
}
|
||||
auto uriStr = uri.ToString();
|
||||
auto ret = storageMgrProxy->CreateShareFile(uriStr, targetTokenId, tmpFlag);
|
||||
auto ret = storageMgrProxy->CreateShareFile(uriStr, targetTokenId, flag);
|
||||
if (ret != 0 && ret != -EEXIST) {
|
||||
HILOG_ERROR("storageMgrProxy failed to CreateShareFile.");
|
||||
return false;
|
||||
return INNER_ERR;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
auto search = uriMap_.find(uriStr);
|
||||
GrantInfo info = { tmpFlag, fromTokenId, targetTokenId };
|
||||
GrantInfo info = { flag, fromTokenId, targetTokenId, autoremove };
|
||||
if (search == uriMap_.end()) {
|
||||
std::list<GrantInfo> infoList = { info };
|
||||
uriMap_.emplace(uriStr, infoList);
|
||||
return true;
|
||||
return ERR_OK;
|
||||
}
|
||||
auto& infoList = search->second;
|
||||
for (auto& item : infoList) {
|
||||
if (item.fromTokenId == fromTokenId && item.targetTokenId == targetTokenId) {
|
||||
if ((tmpFlag & item.flag) == 0) {
|
||||
if ((flag & item.flag) == 0) {
|
||||
HILOG_INFO("Update uri r/w permission.");
|
||||
item.flag = tmpFlag;
|
||||
item.flag = flag;
|
||||
}
|
||||
HILOG_INFO("uri permission has granted, not to grant again.");
|
||||
return true;
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
infoList.emplace_back(info);
|
||||
return true;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
bool UriPermissionManagerStubImpl::VerifyUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID tokenId)
|
||||
{
|
||||
if ((flag & (Want::FLAG_AUTH_READ_URI_PERMISSION | Want::FLAG_AUTH_WRITE_URI_PERMISSION)) == 0) {
|
||||
HILOG_WARN("UriPermissionManagerStubImpl:::VerifyUriPermission: The param flag is invalid.");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto bms = ConnectBundleManager();
|
||||
auto uriStr = uri.ToString();
|
||||
if (bms) {
|
||||
AppExecFwk::ExtensionAbilityInfo info;
|
||||
if (!IN_PROCESS_CALL(bms->QueryExtensionAbilityInfoByUri(uriStr, GetCurrentAccountId(), info))) {
|
||||
HILOG_DEBUG("%{public}s, Fail to get extension info from bundle manager.", __func__);
|
||||
return false;
|
||||
}
|
||||
if (info.type != AppExecFwk::ExtensionAbilityType::FILESHARE) {
|
||||
HILOG_DEBUG("%{public}s, The upms only open to FILESHARE. The type is %{public}u.", __func__, info.type);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tokenId == info.applicationInfo.accessTokenId) {
|
||||
HILOG_DEBUG("The uri belongs to this application.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
auto search = uriMap_.find(uriStr);
|
||||
if (search == uriMap_.end()) {
|
||||
HILOG_DEBUG("This tokenID does not have permission for this uri.");
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int tmpFlag = 0;
|
||||
if (flag & Want::FLAG_AUTH_WRITE_URI_PERMISSION) {
|
||||
tmpFlag = Want::FLAG_AUTH_WRITE_URI_PERMISSION;
|
||||
} else {
|
||||
tmpFlag = Want::FLAG_AUTH_READ_URI_PERMISSION;
|
||||
}
|
||||
|
||||
for (const auto& item : search->second) {
|
||||
if (item.targetTokenId == tokenId &&
|
||||
(item.flag == Want::FLAG_AUTH_WRITE_URI_PERMISSION || item.flag == tmpFlag)) {
|
||||
HILOG_DEBUG("This tokenID have permission for this uri.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
HILOG_DEBUG("The application does not have permission for this URI.");
|
||||
return false;
|
||||
}
|
||||
|
||||
void UriPermissionManagerStubImpl::RemoveUriPermission(const TokenId tokenId)
|
||||
void UriPermissionManagerStubImpl::RevokeUriPermission(const TokenId tokenId)
|
||||
{
|
||||
HILOG_DEBUG("Start to remove uri permission.");
|
||||
auto callerTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
Security::AccessToken::NativeTokenInfo nativeInfo;
|
||||
Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(callerTokenId, nativeInfo);
|
||||
HILOG_DEBUG("callerprocessName : %{public}s", nativeInfo.processName.c_str());
|
||||
if (nativeInfo.processName != "fodundation") {
|
||||
HILOG_ERROR("RevokeUriPermission can only be called by foundation");
|
||||
return;
|
||||
}
|
||||
std::vector<std::string> uriList;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
for (auto iter = uriMap_.begin(); iter != uriMap_.end();) {
|
||||
auto& list = iter->second;
|
||||
for (auto it = list.begin(); it != list.end(); it++) {
|
||||
if (it->targetTokenId == tokenId) {
|
||||
if (it->targetTokenId == tokenId && it->autoremove) {
|
||||
HILOG_INFO("Erase an info form list.");
|
||||
list.erase(it);
|
||||
uriList.emplace_back(iter->first);
|
||||
@@ -173,6 +157,54 @@ void UriPermissionManagerStubImpl::RemoveUriPermission(const TokenId tokenId)
|
||||
}
|
||||
}
|
||||
|
||||
int UriPermissionManagerStubImpl::RevokeUriPermissionManually(const Uri &uri, const std::string bundleName)
|
||||
{
|
||||
HILOG_DEBUG("Start to remove uri permission manually.");
|
||||
Uri uri_inner = uri;
|
||||
auto&& authority = uri_inner.GetAuthority();
|
||||
Security::AccessToken::AccessTokenID uriTokenId = GetTokenIdByBundleName(authority);
|
||||
Security::AccessToken::AccessTokenID tokenId = GetTokenIdByBundleName(bundleName);
|
||||
auto callerTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
auto permission = PermissionVerification::GetInstance()->VerifyCallingPermission(
|
||||
AAFwk::PermissionConstants::PERMISSION_PROXY_AUTHORIZATION_URI);
|
||||
if (!permission && (uriTokenId != callerTokenId) && (tokenId != callerTokenId)) {
|
||||
HILOG_WARN("UriPermissionManagerStubImpl::RevokeUriPermission: No permission for revoke uri.");
|
||||
return CHECK_PERMISSION_FAILED;
|
||||
}
|
||||
|
||||
std::vector<std::string> uriList;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
|
||||
auto uriStr = uri.ToString();
|
||||
auto search = uriMap_.find(uriStr);
|
||||
if (search == uriMap_.end()) {
|
||||
HILOG_ERROR("URI does not exist on uri map.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
auto& list = search->second;
|
||||
for (auto it = list.begin(); it != list.end(); it++) {
|
||||
if (it->targetTokenId == tokenId) {
|
||||
HILOG_INFO("Erase an info form list.");
|
||||
auto storageMgrProxy = ConnectStorageManager();
|
||||
if (storageMgrProxy == nullptr) {
|
||||
HILOG_ERROR("ConnectStorageManager failed");
|
||||
return INNER_ERR;
|
||||
}
|
||||
uriList.emplace_back(search->first);
|
||||
if (storageMgrProxy->DeleteShareFile(tokenId, uriList) == ERR_OK) {
|
||||
list.erase(it);
|
||||
break;
|
||||
} else {
|
||||
HILOG_ERROR("DeleteShareFile failed");
|
||||
return INNER_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
sptr<AppExecFwk::IBundleMgr> UriPermissionManagerStubImpl::ConnectBundleManager()
|
||||
{
|
||||
HILOG_DEBUG("%{public}s is called.", __func__);
|
||||
@@ -205,6 +237,22 @@ sptr<AppExecFwk::IBundleMgr> UriPermissionManagerStubImpl::ConnectBundleManager(
|
||||
return bundleManager_;
|
||||
}
|
||||
|
||||
Security::AccessToken::AccessTokenID UriPermissionManagerStubImpl::GetTokenIdByBundleName(const std::string bundleName)
|
||||
{
|
||||
auto bms = ConnectBundleManager();
|
||||
if (bms == nullptr) {
|
||||
HILOG_WARN("Failed to get bms.");
|
||||
return GET_BUNDLE_MANAGER_SERVICE_FAILED;
|
||||
}
|
||||
auto bundleFlag = AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO;
|
||||
AppExecFwk::BundleInfo bundleInfo;
|
||||
if (!IN_PROCESS_CALL(bms->GetBundleInfo(bundleName, bundleFlag, bundleInfo, GetCurrentAccountId()))) {
|
||||
HILOG_WARN("To fail to get bundle info according to uri.");
|
||||
return GET_BUNDLE_INFO_FAILED;
|
||||
}
|
||||
return bundleInfo.applicationInfo.accessTokenId;
|
||||
}
|
||||
|
||||
sptr<StorageManager::IStorageManager> UriPermissionManagerStubImpl::ConnectStorageManager()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(storageMutex_);
|
||||
@@ -276,4 +324,4 @@ int UriPermissionManagerStubImpl::GetCurrentAccountId()
|
||||
return osActiveAccountIds.front();
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
@@ -37,19 +37,20 @@ public:
|
||||
UriPermissionManagerStubFuzzTest() = default;
|
||||
virtual ~UriPermissionManagerStubFuzzTest()
|
||||
{}
|
||||
bool GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID fromTokenId,
|
||||
const Security::AccessToken::AccessTokenID targetTokenId) override
|
||||
int GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
std::string targetBundleName,
|
||||
int autoremove) override
|
||||
{
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
bool VerifyUriPermission(const Uri &uri, unsigned int flag,
|
||||
const Security::AccessToken::AccessTokenID tokenId) override
|
||||
void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId) override
|
||||
{
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
void RemoveUriPermission(const Security::AccessToken::AccessTokenID tokenId) override
|
||||
{}
|
||||
};
|
||||
|
||||
uint32_t GetU32Data(const char* ptr)
|
||||
|
||||
@@ -84,6 +84,12 @@ public:
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
bool LoadScript(const std::string& path, std::vector<uint8_t>* buffer = nullptr, bool isBundle = false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
Language language;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "connection_observer_errors.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "sa_mgr_client.h"
|
||||
#include "softbus_bus_center.h"
|
||||
#include "mock_ability_connect_callback.h"
|
||||
#include "mock_ability_token.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
@@ -43,6 +44,16 @@ using namespace testing::ext;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
using OHOS::AppExecFwk::AbilityType;
|
||||
using OHOS::AppExecFwk::ExtensionAbilityType;
|
||||
bool testFlag = false;
|
||||
int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info)
|
||||
{
|
||||
constexpr int32_t retError = -1;
|
||||
constexpr int32_t retOK = 0;
|
||||
if (testFlag) {
|
||||
return retOK;
|
||||
}
|
||||
return retError;
|
||||
}
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
namespace {
|
||||
@@ -3166,5 +3177,123 @@ HWTEST_F(AbilityManagerServiceTest, MinimizeUIExtensionAbility_001, TestSize.Lev
|
||||
EXPECT_EQ(abilityMs_->MinimizeUIExtensionAbility(MockSessionInfo(0), false), ERR_INVALID_VALUE);
|
||||
HILOG_INFO("AbilityManagerServiceTest MinimizeUIExtensionAbility_001 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: StopExtensionAbility
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: AbilityManagerService StopExtensionAbility
|
||||
*/
|
||||
HWTEST_F(AbilityManagerServiceTest, StopExtensionAbility_002, TestSize.Level1)
|
||||
{
|
||||
HILOG_INFO("AbilityManagerServiceTest StopExtensionAbility_002 start");
|
||||
Want want{};
|
||||
ElementName element("device", "com.ix.hiservcie", "ServiceAbility", "entry");
|
||||
want.SetElement(element);
|
||||
auto abilityRecord = MockAbilityRecord(AbilityType::PAGE);
|
||||
abilityRecord->appIndex_ = -1;
|
||||
abilityRecord->applicationInfo_.bundleName = "com.ix.hiservcie";
|
||||
EXPECT_EQ(abilityMs_->StopExtensionAbility(want, abilityRecord->GetToken(), -1, ExtensionAbilityType::SERVICE),
|
||||
ERR_INVALID_CALLER);
|
||||
HILOG_INFO("AbilityManagerServiceTest StopExtensionAbility_002 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: StopExtensionAbility
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: AbilityManagerService StopExtensionAbility
|
||||
*/
|
||||
HWTEST_F(AbilityManagerServiceTest, StopExtensionAbility_003, TestSize.Level1)
|
||||
{
|
||||
HILOG_INFO("AbilityManagerServiceTest StopExtensionAbility_003 start");
|
||||
Want want{};
|
||||
ElementName element("device", "com.ix.hiservcie", "ServiceAbility", "entry");
|
||||
want.SetElement(element);
|
||||
auto abilityRecord = MockAbilityRecord(AbilityType::PAGE);
|
||||
abilityRecord->appIndex_ = -1;
|
||||
abilityRecord->applicationInfo_.bundleName = "com.ix.hiservcie";
|
||||
MyFlag::flag_ = 1;
|
||||
testFlag = true;
|
||||
EXPECT_EQ(abilityMs_->StopExtensionAbility(want, abilityRecord->GetToken(), -1, ExtensionAbilityType::SERVICE),
|
||||
INVALID_PARAMETERS_ERR);
|
||||
MyFlag::flag_ = 0;
|
||||
testFlag = false;
|
||||
HILOG_INFO("AbilityManagerServiceTest StopExtensionAbility_003 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: StopExtensionAbility
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: AbilityManagerService StopExtensionAbility
|
||||
*/
|
||||
HWTEST_F(AbilityManagerServiceTest, StopExtensionAbility_004, TestSize.Level1)
|
||||
{
|
||||
HILOG_INFO("AbilityManagerServiceTest StopExtensionAbility_004 start");
|
||||
Want want{};
|
||||
ElementName element("device", "com.ix.hiservcie", "ServiceAbility", "entry");
|
||||
want.SetElement(element);
|
||||
auto abilityRecord = MockAbilityRecord(AbilityType::PAGE);
|
||||
abilityRecord->appIndex_ = -1;
|
||||
abilityRecord->applicationInfo_.bundleName = "com.ix.hiservcie";
|
||||
MyFlag::flag_ = 1;
|
||||
testFlag = true;
|
||||
auto missionListManager = abilityMs_->missionListManagers_.begin()->second;
|
||||
auto userId = abilityMs_->missionListManagers_.begin()->first;
|
||||
missionListManager->terminateAbilityList_.insert(
|
||||
missionListManager->terminateAbilityList_.begin(), abilityRecord);
|
||||
HILOG_INFO("AbilityManagerServiceTest StopExtensionAbility_004 userId is %{public}d", userId);
|
||||
EXPECT_EQ(
|
||||
abilityMs_->StopExtensionAbility(want, abilityRecord->GetToken(), userId, ExtensionAbilityType::SERVICE),
|
||||
INVALID_PARAMETERS_ERR);
|
||||
MyFlag::flag_ = 0;
|
||||
testFlag = false;
|
||||
HILOG_INFO("AbilityManagerServiceTest StopExtensionAbility_004 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: StopExtensionAbility
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: AbilityManagerService StopExtensionAbility
|
||||
*/
|
||||
HWTEST_F(AbilityManagerServiceTest, StopExtensionAbility_005, TestSize.Level1)
|
||||
{
|
||||
HILOG_INFO("AbilityManagerServiceTest StopExtensionAbility_005 start");
|
||||
Want want{};
|
||||
ElementName element("", "com.ix.hiservcie", "ServiceAbility", "entry");
|
||||
want.SetElement(element);
|
||||
auto abilityRecord = MockAbilityRecord(AbilityType::PAGE);
|
||||
abilityRecord->appIndex_ = -1;
|
||||
abilityRecord->applicationInfo_.bundleName = "com.ix.hiservcie";
|
||||
MyFlag::flag_ = 1;
|
||||
EXPECT_EQ(abilityMs_->StopExtensionAbility(want, nullptr, -1, ExtensionAbilityType::SERVICE),
|
||||
RESOLVE_ABILITY_ERR);
|
||||
MyFlag::flag_ = 0;
|
||||
HILOG_INFO("AbilityManagerServiceTest StopExtensionAbility_005 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: StopExtensionAbility
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: AbilityManagerService StopExtensionAbility
|
||||
*/
|
||||
HWTEST_F(AbilityManagerServiceTest, StopExtensionAbility_006, TestSize.Level1)
|
||||
{
|
||||
HILOG_INFO("AbilityManagerServiceTest StopExtensionAbility_006 start");
|
||||
Want want{};
|
||||
ElementName element("", "com.ix.hiservcie", "ServiceAbility", "entry");
|
||||
want.SetElement(element);
|
||||
auto abilityRecord = MockAbilityRecord(AbilityType::PAGE);
|
||||
abilityRecord->appIndex_ = -1;
|
||||
abilityRecord->applicationInfo_.bundleName = "com.ix.hiservcie";
|
||||
MyFlag::flag_ = 1;
|
||||
EXPECT_EQ(abilityMs_->StopExtensionAbility(want, abilityRecord->GetToken(), -1, ExtensionAbilityType::SERVICE),
|
||||
RESOLVE_ABILITY_ERR);
|
||||
MyFlag::flag_ = 0;
|
||||
HILOG_INFO("AbilityManagerServiceTest StopExtensionAbility_006 end");
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -2087,8 +2087,8 @@ HWTEST_F(AbilityRecordTest, AbilityRecord_GrantUriPermission_001, TestSize.Level
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = GetAbilityRecord();
|
||||
Want want;
|
||||
int32_t userId = 100;
|
||||
uint32_t targetTokenId = 1;
|
||||
abilityRecord->GrantUriPermission(want, userId, targetTokenId);
|
||||
std::string targetBundleName = "name";
|
||||
abilityRecord->GrantUriPermission(want, userId, "name");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2106,8 +2106,8 @@ HWTEST_F(AbilityRecordTest, AbilityRecord_GrantUriPermission_002, TestSize.Level
|
||||
want.SetFlags(1);
|
||||
want.SetUri("datashare://ohos.samples.clock/data/storage/el2/base/haps/entry/files/test_A.txt");
|
||||
int32_t userId = 100;
|
||||
uint32_t targetTokenId = 1;
|
||||
abilityRecord->GrantUriPermission(want, userId, targetTokenId);
|
||||
std::string targetBundleName = "name";
|
||||
abilityRecord->GrantUriPermission(want, userId, targetBundleName);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2125,8 +2125,8 @@ HWTEST_F(AbilityRecordTest, AbilityRecord_GrantUriPermission_003, TestSize.Level
|
||||
want.SetFlags(1);
|
||||
want.SetUri("file://com.example.mock/data/storage/el2/base/haps/entry/files/test_A.txt");
|
||||
int32_t userId = 100;
|
||||
uint32_t targetTokenId = 1;
|
||||
abilityRecord->GrantUriPermission(want, userId, targetTokenId);
|
||||
std::string targetBundleName = "name";
|
||||
abilityRecord->GrantUriPermission(want, userId, targetBundleName);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2144,8 +2144,8 @@ HWTEST_F(AbilityRecordTest, AbilityRecord_GrantUriPermission_004, TestSize.Level
|
||||
want.SetFlags(1);
|
||||
want.SetUri("file://ohos.samples.clock/data/storage/el2/base/haps/entry/files/test_A.txt");
|
||||
int32_t userId = 100;
|
||||
uint32_t targetTokenId = 1;
|
||||
abilityRecord->GrantUriPermission(want, userId, targetTokenId);
|
||||
std::string targetBundleName = "name";
|
||||
abilityRecord->GrantUriPermission(want, userId, targetBundleName);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2159,27 +2159,26 @@ HWTEST_F(AbilityRecordTest, AbilityRecord_GrantUriPermission_004, TestSize.Level
|
||||
HWTEST_F(AbilityRecordTest, AbilityRecord_GrantUriPermission_005, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = GetAbilityRecord();
|
||||
uint32_t targetTokenId = 56;
|
||||
abilityRecord->SetCallerAccessTokenId(targetTokenId);
|
||||
Want want;
|
||||
want.SetFlags(1);
|
||||
want.SetUri("file://ohos.samples.clock/data/storage/el2/base/haps/entry/files/test_A.txt");
|
||||
int32_t userId = 100;
|
||||
abilityRecord->GrantUriPermission(want, userId, targetTokenId);
|
||||
std::string targetBundleName = "name";
|
||||
abilityRecord->GrantUriPermission(want, userId, targetBundleName);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityRecord
|
||||
* Function: RemoveUriPermission
|
||||
* SubFunction: RemoveUriPermission
|
||||
* Function: RevokeUriPermission
|
||||
* SubFunction: RevokeUriPermission
|
||||
* FunctionPoints: NA
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify AbilityRecord RemoveUriPermission
|
||||
* CaseDescription: Verify AbilityRecord RevokeUriPermission
|
||||
*/
|
||||
HWTEST_F(AbilityRecordTest, AbilityRecord_RemoveUriPermission_001, TestSize.Level1)
|
||||
HWTEST_F(AbilityRecordTest, AbilityRecord_RevokeUriPermission_001, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = GetAbilityRecord();
|
||||
abilityRecord->RemoveUriPermission();
|
||||
abilityRecord->RevokeUriPermission();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@@ -649,4 +649,26 @@ HWTEST_F(DistributedClientTest, WriteInfosToParcel_0100, TestSize.Level3)
|
||||
auto result = client->WriteInfosToParcel(data , want , callback);
|
||||
EXPECT_TRUE(result);
|
||||
GTEST_LOG_(INFO) << "DistributedClientTest WriteInfosToParcel_0100 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: StopRemoteExtensionAbility_0100
|
||||
* @tc.name: StopRemoteExtensionAbility
|
||||
* @tc.desc: StopRemoteExtensionAbility Test.
|
||||
*/
|
||||
HWTEST_F(DistributedClientTest, StopRemoteExtensionAbility_0100, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "DistributedClientTest StopRemoteExtensionAbility_0100 start";
|
||||
auto client = std::make_shared<OHOS::AAFwk::DistributedClient>();
|
||||
OHOS::AAFwk::Want want;
|
||||
constexpr int32_t callerUid = 0;
|
||||
constexpr uint32_t accessToken = 0;
|
||||
constexpr int32_t extensionType = 3;
|
||||
auto result = client->StopRemoteExtensionAbility(want, callerUid, accessToken, extensionType);
|
||||
if (client->GetDmsProxy() != nullptr) {
|
||||
EXPECT_EQ(result, OHOS::AAFwk::DMS_PERMISSION_DENIED);
|
||||
} else {
|
||||
EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR);
|
||||
}
|
||||
GTEST_LOG_(INFO) << "DistributedClientTest StopRemoteExtensionAbility_0100 end";
|
||||
}
|
||||
@@ -38,6 +38,11 @@ bool AddResource(const std::string &path, const std::vector<std::string> &overla
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RemoveResource(const std::string &path, const std::vector<std::string> &overlayPaths)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
RState UpdateResConfig(ResConfig &resConfig)
|
||||
{
|
||||
return SUCCESS;
|
||||
|
||||
@@ -100,9 +100,13 @@ HWTEST_F(JsRuntimeTest, JsRuntimeTest_0200, TestSize.Level0)
|
||||
{
|
||||
std::string appLibPathKey = TEST_BUNDLE_NAME + TEST_MODULE_NAME;
|
||||
std::string libPath = TEST_LIB_PATH;
|
||||
options_.appLibPaths[appLibPathKey].emplace_back(libPath);
|
||||
std::unique_ptr<Runtime> jsRuntime = JsRuntime::Create(options_);
|
||||
EXPECT_TRUE(jsRuntime != nullptr);
|
||||
|
||||
AppLibPathMap appLibPaths {};
|
||||
JsRuntime::SetAppLibPath(appLibPaths);
|
||||
|
||||
appLibPaths[appLibPathKey].emplace_back(libPath);
|
||||
EXPECT_NE(appLibPaths.size(), 0);
|
||||
JsRuntime::SetAppLibPath(appLibPaths);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,7 @@ ohos_unittest("static_subscriber_extension_test") {
|
||||
"${ability_runtime_native_path}/appkit/ability_runtime",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
"${ability_runtime_test_path}/mock/frameworks_kits_runtime_test",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -40,9 +41,6 @@ ohos_unittest("static_subscriber_extension_test") {
|
||||
"${ability_runtime_native_path}/ability/native/static_subscriber_extension.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/static_subscriber_stub_imp.cpp",
|
||||
"${ability_runtime_native_path}/appkit/ability_runtime/static_subscriber_extension_context.cpp",
|
||||
|
||||
#"${subscriber_extension_path}/static_subscriber_extension.cpp",
|
||||
#"remote_register_service_proxy_test.cpp",
|
||||
"static_subscriber_extension_test.cpp",
|
||||
]
|
||||
|
||||
|
||||
+1
-51
@@ -19,6 +19,7 @@
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "mock_runtime.h"
|
||||
#include "runtime.h"
|
||||
#include "static_subscriber_extension.h"
|
||||
#include "static_subscriber_extension_context.h"
|
||||
@@ -52,57 +53,6 @@ void StaticSubscriberExtensionTest::SetUp(void)
|
||||
void StaticSubscriberExtensionTest::TearDown(void)
|
||||
{}
|
||||
|
||||
class MockRuntime : public Runtime {
|
||||
public:
|
||||
MockRuntime() {};
|
||||
virtual ~MockRuntime() {};
|
||||
|
||||
Language GetLanguage() const
|
||||
{
|
||||
return language;
|
||||
};
|
||||
|
||||
void StartDebugMode(bool needBreakPoint) override
|
||||
{};
|
||||
|
||||
bool BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames) override
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
void DumpHeapSnapshot(bool isPrivate) override
|
||||
{};
|
||||
|
||||
void NotifyApplicationState(bool isBackground) override
|
||||
{};
|
||||
|
||||
void PreloadSystemModule(const std::string& moduleName) override
|
||||
{};
|
||||
|
||||
void FinishPreload() override
|
||||
{};
|
||||
|
||||
bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) override
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
bool NotifyHotReloadPage() override
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
bool UnLoadRepairPatch(const std::string& patchFile) override
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
void UpdateExtensionType(int32_t extensionType) override
|
||||
{};
|
||||
|
||||
Language language;
|
||||
};
|
||||
|
||||
class MockStaticSubscriberExtension : public StaticSubscriberExtension
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
# 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.
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
@@ -48,6 +48,7 @@ ohos_unittest("uri_permission_impl_test") {
|
||||
"ability_base:zuri",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
|
||||
|
||||
@@ -58,9 +58,9 @@ HWTEST_F(UriPermissionImplTest, Upms_GrantUriPermission_001, TestSize.Level1)
|
||||
auto uriStr = "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt";
|
||||
Uri uri(uriStr);
|
||||
unsigned int flag = 0;
|
||||
uint32_t fromTokenId = 2;
|
||||
uint32_t targetTokenId = 3;
|
||||
upms->GrantUriPermission(uri, flag, fromTokenId, targetTokenId);
|
||||
std::string targetBundleName = "name2";
|
||||
int autoremove = 1;
|
||||
upms->GrantUriPermission(uri, flag, targetBundleName, autoremove);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -75,9 +75,9 @@ HWTEST_F(UriPermissionImplTest, Upms_GrantUriPermission_002, TestSize.Level1)
|
||||
auto uriStr = "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt";
|
||||
Uri uri(uriStr);
|
||||
unsigned int flag = 1;
|
||||
uint32_t fromTokenId = 2;
|
||||
uint32_t targetTokenId = 3;
|
||||
upms->GrantUriPermission(uri, flag, fromTokenId, targetTokenId);
|
||||
std::string targetBundleName = "name2";
|
||||
int autoremove = 1;
|
||||
upms->GrantUriPermission(uri, flag, targetBundleName, autoremove);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -92,10 +92,10 @@ HWTEST_F(UriPermissionImplTest, Upms_GrantUriPermission_003, TestSize.Level1)
|
||||
auto uriStr = "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt";
|
||||
Uri uri(uriStr);
|
||||
unsigned int flag = 2;
|
||||
uint32_t fromTokenId = 2;
|
||||
uint32_t targetTokenId = 3;
|
||||
MockSystemAbilityManager::isNullptr = false;
|
||||
upms->GrantUriPermission(uri, flag, fromTokenId, targetTokenId);
|
||||
std::string targetBundleName = "name2";
|
||||
int autoremove = 1;
|
||||
upms->GrantUriPermission(uri, flag, targetBundleName, autoremove);
|
||||
MockSystemAbilityManager::isNullptr = true;
|
||||
}
|
||||
|
||||
@@ -111,11 +111,11 @@ HWTEST_F(UriPermissionImplTest, Upms_GrantUriPermission_004, TestSize.Level1)
|
||||
auto uriStr = "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt";
|
||||
Uri uri(uriStr);
|
||||
unsigned int flag = 2;
|
||||
uint32_t fromTokenId = 2;
|
||||
uint32_t targetTokenId = 3;
|
||||
std::string targetBundleName = "name2";
|
||||
int autoremove = 1;
|
||||
MockSystemAbilityManager::isNullptr = false;
|
||||
StorageManager::StorageManagerServiceMock::isZero = false;
|
||||
upms->GrantUriPermission(uri, flag, fromTokenId, targetTokenId);
|
||||
upms->GrantUriPermission(uri, flag, targetBundleName, autoremove);
|
||||
MockSystemAbilityManager::isNullptr = true;
|
||||
StorageManager::StorageManagerServiceMock::isZero = true;
|
||||
}
|
||||
@@ -132,13 +132,15 @@ HWTEST_F(UriPermissionImplTest, Upms_GrantUriPermission_005, TestSize.Level1)
|
||||
unsigned int tmpFlag = 1;
|
||||
uint32_t fromTokenId = 2;
|
||||
uint32_t targetTokenId = 3;
|
||||
GrantInfo info = { tmpFlag, fromTokenId, targetTokenId };
|
||||
std::string targetBundleName = "name2";
|
||||
int autoremove = 1;
|
||||
GrantInfo info = { tmpFlag, fromTokenId, targetTokenId, autoremove };
|
||||
std::list<GrantInfo> infoList = { info };
|
||||
auto uriStr = "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt";
|
||||
upms->uriMap_.emplace(uriStr, infoList);
|
||||
Uri uri(uriStr);
|
||||
MockSystemAbilityManager::isNullptr = false;
|
||||
upms->GrantUriPermission(uri, tmpFlag, fromTokenId, targetTokenId);
|
||||
upms->GrantUriPermission(uri, tmpFlag, targetBundleName, autoremove);
|
||||
MockSystemAbilityManager::isNullptr = true;
|
||||
}
|
||||
|
||||
@@ -154,14 +156,16 @@ HWTEST_F(UriPermissionImplTest, Upms_GrantUriPermission_006, TestSize.Level1)
|
||||
unsigned int tmpFlag = 1;
|
||||
uint32_t fromTokenId = 2;
|
||||
uint32_t targetTokenId = 3;
|
||||
GrantInfo info = { tmpFlag, fromTokenId, targetTokenId };
|
||||
std::string targetBundleName = "name2";
|
||||
int autoremove = 1;
|
||||
GrantInfo info = { tmpFlag, fromTokenId, targetTokenId, autoremove };
|
||||
std::list<GrantInfo> infoList = { info };
|
||||
auto uriStr = "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt";
|
||||
upms->uriMap_.emplace(uriStr, infoList);
|
||||
Uri uri(uriStr);
|
||||
MockSystemAbilityManager::isNullptr = false;
|
||||
unsigned int flag = 2;
|
||||
upms->GrantUriPermission(uri, flag, fromTokenId, targetTokenId);
|
||||
upms->GrantUriPermission(uri, flag, targetBundleName, autoremove);
|
||||
MockSystemAbilityManager::isNullptr = true;
|
||||
}
|
||||
|
||||
@@ -177,25 +181,26 @@ HWTEST_F(UriPermissionImplTest, Upms_GrantUriPermission_007, TestSize.Level1)
|
||||
unsigned int tmpFlag = 1;
|
||||
uint32_t fromTokenId = 2;
|
||||
uint32_t targetTokenId = 3;
|
||||
GrantInfo info = { tmpFlag, fromTokenId, targetTokenId };
|
||||
std::string targetBundleName = "name2";
|
||||
int autoremove = 1;
|
||||
GrantInfo info = { tmpFlag, fromTokenId, targetTokenId, autoremove };
|
||||
std::list<GrantInfo> infoList = { info };
|
||||
auto uriStr = "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt";
|
||||
upms->uriMap_.emplace(uriStr, infoList);
|
||||
Uri uri(uriStr);
|
||||
MockSystemAbilityManager::isNullptr = false;
|
||||
unsigned int flag = 2;
|
||||
uint32_t tokenId = 4;
|
||||
upms->GrantUriPermission(uri, flag, fromTokenId, tokenId);
|
||||
upms->GrantUriPermission(uri, flag, targetBundleName, autoremove);
|
||||
MockSystemAbilityManager::isNullptr = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: URIPermissionManagerService
|
||||
* Function: RemoveUriPermission
|
||||
* Function: RevokeUriPermission
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: URIPermissionManagerService RemoveUriPermission
|
||||
* FunctionPoints: URIPermissionManagerService RevokeUriPermission
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upms_RemoveUriPermission_001, TestSize.Level1)
|
||||
HWTEST_F(UriPermissionImplTest, Upms_RevokeUriPermission_001, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
unsigned int tmpFlag = 1;
|
||||
@@ -205,16 +210,16 @@ HWTEST_F(UriPermissionImplTest, Upms_RemoveUriPermission_001, TestSize.Level1)
|
||||
std::list<GrantInfo> infoList = { info };
|
||||
auto uriStr = "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt";
|
||||
upms->uriMap_.emplace(uriStr, infoList);
|
||||
upms->RemoveUriPermission(targetTokenId);
|
||||
upms->RevokeUriPermission(targetTokenId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: URIPermissionManagerService
|
||||
* Function: RemoveUriPermission
|
||||
* Function: RevokeUriPermission
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: URIPermissionManagerService RemoveUriPermission
|
||||
* FunctionPoints: URIPermissionManagerService RevokeUriPermission
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upms_RemoveUriPermission_002, TestSize.Level1)
|
||||
HWTEST_F(UriPermissionImplTest, Upms_RevokeUriPermission_002, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
unsigned int tmpFlag = 1;
|
||||
@@ -225,7 +230,7 @@ HWTEST_F(UriPermissionImplTest, Upms_RemoveUriPermission_002, TestSize.Level1)
|
||||
auto uriStr = "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt";
|
||||
upms->uriMap_.emplace(uriStr, infoList);
|
||||
uint32_t tokenId = 4;
|
||||
upms->RemoveUriPermission(tokenId);
|
||||
upms->RevokeUriPermission(tokenId);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
# 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.
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
@@ -33,6 +33,7 @@ ohos_unittest("uri_permission_test") {
|
||||
|
||||
external_deps = [
|
||||
"ability_base:zuri",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"storage_service:storage_manager_sa_proxy",
|
||||
]
|
||||
|
||||
@@ -51,9 +51,9 @@ HWTEST_F(UriPermissionTest, Upms_GrantUriPermission_001, TestSize.Level1)
|
||||
auto uriStr = "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt";
|
||||
Uri uri(uriStr);
|
||||
unsigned int flag = 1;
|
||||
uint32_t fromTokenId = 2;
|
||||
uint32_t targetTokenId = 3;
|
||||
upms->GrantUriPermission(uri, flag, fromTokenId, targetTokenId);
|
||||
std::string targetBundleName = "name2";
|
||||
int autoremove = 1;
|
||||
upms->GrantUriPermission(uri, flag, targetBundleName, autoremove);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -82,21 +82,22 @@ HWTEST_F(UriPermissionTest, Upms_ConnectStorageManager_001, TestSize.Level1)
|
||||
|
||||
/*
|
||||
* Feature: URIPermissionManagerService
|
||||
* Function: RemoveUriPermission
|
||||
* Function: RevokeUriPermission
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: URIPermissionManagerService RemoveUriPermission
|
||||
* FunctionPoints: URIPermissionManagerService RevokeUriPermission
|
||||
*/
|
||||
HWTEST_F(UriPermissionTest, Upms_RemoveUriPermission_001, TestSize.Level1)
|
||||
HWTEST_F(UriPermissionTest, Upms_RevokeUriPermission_001, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
unsigned int tmpFlag = 1;
|
||||
uint32_t fromTokenId = 2;
|
||||
uint32_t targetTokenId = 3;
|
||||
GrantInfo info = { tmpFlag, fromTokenId, targetTokenId };
|
||||
int autoremove = 1;
|
||||
GrantInfo info = { tmpFlag, fromTokenId, targetTokenId, autoremove };
|
||||
std::list<GrantInfo> infoList = { info };
|
||||
auto uriStr = "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt";
|
||||
upms->uriMap_.emplace(uriStr, infoList);
|
||||
upms->RemoveUriPermission(targetTokenId);
|
||||
upms->RevokeUriPermission(targetTokenId);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user