diff --git a/interfaces/innerkits/appexecfwk_base/include/application_info.h b/interfaces/innerkits/appexecfwk_base/include/application_info.h index eaf77afb..aba06abf 100644 --- a/interfaces/innerkits/appexecfwk_base/include/application_info.h +++ b/interfaces/innerkits/appexecfwk_base/include/application_info.h @@ -69,6 +69,7 @@ struct CompatibleApplicationInfo : public Parcelable { uint32_t iconId = 0; uint32_t labelId = 0; uint32_t descriptionId = 0; + uint32_t accessTokenId = 0; bool systemApp = false; @@ -95,6 +96,7 @@ struct ApplicationInfo : public Parcelable { int32_t labelId = 0; int32_t iconId = 0; int32_t descriptionId = 0; + uint32_t accessTokenId = 0; std::string deviceId; // should auto-get self device id. std::string signatureKey; // the public key info of this application. bool isSystemApp = false; diff --git a/interfaces/innerkits/appexecfwk_base/include/permission_def.h b/interfaces/innerkits/appexecfwk_base/include/permission_def.h index 08147197..50fc0dff 100644 --- a/interfaces/innerkits/appexecfwk_base/include/permission_def.h +++ b/interfaces/innerkits/appexecfwk_base/include/permission_def.h @@ -37,6 +37,23 @@ struct PermissionDef : public Parcelable { virtual bool Marshalling(Parcel &parcel) const override; static PermissionDef *Unmarshalling(Parcel &parcel); }; + +struct PermissionDefine : public Parcelable { + std::string permissionName; + std::string bundleName; + int grantMode = 0; + int availableLevel = 1; + bool provisionEnable = true; + bool distributedSceneEnable = false; + std::string label; + int labelId = 0; + std::string description; + int descriptionId = 0; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static PermissionDefine *Unmarshalling(Parcel &parcel); +}; } // namespace AppExecFwk } // namespace OHOS #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_PERMISSION_DEF_H diff --git a/interfaces/innerkits/appexecfwk_base/src/application_info.cpp b/interfaces/innerkits/appexecfwk_base/src/application_info.cpp index 9e24d75c..0cc261f1 100644 --- a/interfaces/innerkits/appexecfwk_base/src/application_info.cpp +++ b/interfaces/innerkits/appexecfwk_base/src/application_info.cpp @@ -38,6 +38,7 @@ const std::string APPLICATION_ICON_PATH = "iconPath"; const std::string APPLICATION_LABEL = "label"; const std::string APPLICATION_LABEL_ID = "labelId"; const std::string APPLICATION_DESCRIPTION_ID = "descriptionId"; +const std::string APPLICATION_ACCESSTOKEN_ID = "accessTokenId"; const std::string APPLICATION_ICON_ID = "iconId"; const std::string APPLICATION_DEVICE_ID = "deviceId"; const std::string APPLICATION_SIGNATURE_KEY = "signatureKey"; @@ -117,6 +118,7 @@ bool ApplicationInfo::ReadFromParcel(Parcel &parcel) labelId = parcel.ReadInt32(); iconId = parcel.ReadInt32(); descriptionId = parcel.ReadInt32(); + accessTokenId = parcel.ReadUint32(); flags = parcel.ReadInt32(); uid = parcel.ReadInt32(); @@ -204,6 +206,7 @@ bool ApplicationInfo::Marshalling(Parcel &parcel) const WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, labelId); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, iconId); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, descriptionId); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, accessTokenId); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, flags); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid); @@ -270,6 +273,7 @@ void to_json(nlohmann::json &jsonObject, const ApplicationInfo &applicationInfo) {APPLICATION_LABEL, applicationInfo.label}, {APPLICATION_LABEL_ID, applicationInfo.labelId}, {APPLICATION_DESCRIPTION_ID, applicationInfo.descriptionId}, + {APPLICATION_ACCESSTOKEN_ID, applicationInfo.accessTokenId}, {APPLICATION_ICON_ID, applicationInfo.iconId}, {APPLICATION_DEVICE_ID, applicationInfo.deviceId}, {APPLICATION_SIGNATURE_KEY, applicationInfo.signatureKey}, @@ -355,6 +359,14 @@ void from_json(const nlohmann::json &jsonObject, ApplicationInfo &applicationInf false, parseResult, ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + APPLICATION_ACCESSTOKEN_ID, + applicationInfo.accessTokenId, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, APPLICATION_ICON_ID, @@ -556,6 +568,7 @@ void ApplicationInfo::ConvertToCompatibleApplicationInfo(CompatibleApplicationIn compatibleApplicationInfo.iconId = iconId; compatibleApplicationInfo.labelId = labelId; compatibleApplicationInfo.descriptionId = descriptionId; + compatibleApplicationInfo.accessTokenId = accessTokenId; compatibleApplicationInfo.permissions = permissions; compatibleApplicationInfo.moduleInfos = moduleInfos; compatibleApplicationInfo.supportedModes = supportedModes; diff --git a/interfaces/innerkits/appexecfwk_base/src/compatible_application_info.cpp b/interfaces/innerkits/appexecfwk_base/src/compatible_application_info.cpp index 74d4000c..9f14302f 100644 --- a/interfaces/innerkits/appexecfwk_base/src/compatible_application_info.cpp +++ b/interfaces/innerkits/appexecfwk_base/src/compatible_application_info.cpp @@ -48,6 +48,7 @@ bool CompatibleApplicationInfo::ReadFromParcel(Parcel& parcel) supportedModes = parcel.ReadInt32(); iconId = parcel.ReadInt32(); descriptionId = parcel.ReadInt32(); + accessTokenId = parcel.ReadUint32(); labelId = parcel.ReadInt32(); isCompressNativeLibs = parcel.ReadBool(); @@ -114,6 +115,7 @@ bool CompatibleApplicationInfo::Marshalling(Parcel& parcel) const WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportedModes); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, iconId); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, descriptionId); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, accessTokenId); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, labelId); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isCompressNativeLibs); const auto permissionSize = static_cast(permissions.size()); @@ -147,6 +149,7 @@ void CompatibleApplicationInfo::ConvertToApplicationInfo(ApplicationInfo& applic applicationInfo.iconId = iconId; applicationInfo.labelId = labelId; applicationInfo.descriptionId = descriptionId; + applicationInfo.accessTokenId = accessTokenId; applicationInfo.permissions = permissions; applicationInfo.moduleInfos = moduleInfos; applicationInfo.supportedModes = supportedModes; diff --git a/interfaces/innerkits/appexecfwk_base/src/permission_def.cpp b/interfaces/innerkits/appexecfwk_base/src/permission_def.cpp index 962a0b41..5cacd763 100644 --- a/interfaces/innerkits/appexecfwk_base/src/permission_def.cpp +++ b/interfaces/innerkits/appexecfwk_base/src/permission_def.cpp @@ -59,5 +59,46 @@ bool PermissionDef::Marshalling(Parcel &parcel) const WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, descriptionId); return true; } + +bool PermissionDefine::ReadFromParcel(Parcel &parcel) +{ + permissionName = Str16ToStr8(parcel.ReadString16()); + bundleName = Str16ToStr8(parcel.ReadString16()); + label = Str16ToStr8(parcel.ReadString16()); + description = Str16ToStr8(parcel.ReadString16()); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, availableLevel); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, provisionEnable); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, distributedSceneEnable); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, grantMode); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, labelId); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, descriptionId); + return true; +} + +PermissionDefine *PermissionDefine::Unmarshalling(Parcel &parcel) +{ + PermissionDefine *info = new (std::nothrow) PermissionDefine(); + if (info && !info->ReadFromParcel(parcel)) { + APP_LOGW("read from parcel failed"); + delete info; + info = nullptr; + } + return info; +} + +bool PermissionDefine::Marshalling(Parcel &parcel) const +{ + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(permissionName)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(label)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(description)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, availableLevel); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, provisionEnable); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, distributedSceneEnable); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, grantMode); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, labelId); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, descriptionId); + return true; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/kits/appkit/napi/bundlemgr/bundle_mgr.cpp b/kits/appkit/napi/bundlemgr/bundle_mgr.cpp index 663e3a3d..b913941d 100644 --- a/kits/appkit/napi/bundlemgr/bundle_mgr.cpp +++ b/kits/appkit/napi/bundlemgr/bundle_mgr.cpp @@ -147,6 +147,10 @@ static void ConvertApplicationInfo(napi_env env, napi_value objAppInfo, const Ap env, napi_create_string_utf8(env, appInfo.codePath.c_str(), NAPI_AUTO_LENGTH, &nCodePath)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objAppInfo, "codePath", nCodePath)); + napi_value nAccessTokenId; + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, appInfo.accessTokenId, &nAccessTokenId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objAppInfo, "accessTokenId", nAccessTokenId)); + napi_value nDescription; NAPI_CALL_RETURN_VOID( env, napi_create_string_utf8(env, appInfo.description.c_str(), NAPI_AUTO_LENGTH, &nDescription)); diff --git a/services/bundlemgr/include/bundle_permission_mgr.h b/services/bundlemgr/include/bundle_permission_mgr.h index 8ef3cd57..1bc2dc2f 100644 --- a/services/bundlemgr/include/bundle_permission_mgr.h +++ b/services/bundlemgr/include/bundle_permission_mgr.h @@ -102,6 +102,13 @@ public: static bool RequestPermissionFromUser( const std::string &bundleName, const std::string &permissionName, const int userId); + static uint32_t CreateTokenId( + const InnerBundleInfo &innerBundleInfo, const std::string bundleName, const int32_t userId); + + static int32_t DeleteTokenId(const uint32_t tokenId); + + static int32_t GrantedRequestPermissions(const InnerBundleInfo &innerBundleInfo, const int32_t userId); + private: /** * @brief Add the defPermissions to permission kit. @@ -168,6 +175,11 @@ private: * @return Returns 0 if the reqPermissions removed successfully; returns -1 otherwise. */ static int RemoveSystemGrantedReqPermissions(const std::string &bundleName); + + static bool ConvertPermissionDef(const Security::Permission::PermissionDef &permDef, PermissionDef &permissionDef); + static bool ConvertPermissionDef( + Security::Permission::PermissionDef &permDef, const DefPermission &defPermission, + const std::string &bundleName); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/include/common_profile.h b/services/bundlemgr/include/common_profile.h index bd5b65bc..494431d0 100644 --- a/services/bundlemgr/include/common_profile.h +++ b/services/bundlemgr/include/common_profile.h @@ -100,11 +100,18 @@ const std::string BUNDLE_MODULE_PROFILE_KEY_JS = "js"; const std::string BUNDLE_MODULE_PROFILE_KEY_COMMON_EVENTS = "commonEvents"; const std::string BUNDLE_MODULE_PROFILE_KEY_SHORTCUTS = "shortcuts"; const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS = "defPermissions"; +const std::string BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS = "definePermissions"; const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_NAME = "name"; const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_GRANTMODE = "grantMode"; const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_GRANTMODE_USER_GRANT = "user_grant"; const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_GRANTMODE_SYSTEM_GRANT = "system_grant"; const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_AVAILABLESCOPE = "availableScope"; +const std::string BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_AVAILABLELEVEL = "availableLevel"; +const std::string BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_AVAILABLELEVEL_NORMAL = "normal"; +const std::string BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_AVAILABLELEVEL_SYSTEM_BASIC = "system_basic"; +const std::string BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_AVAILABLELEVEL_SYSTEM_CORE = "system_core"; +const std::string BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_PROVISION_ANABLE = "provisionEnable"; +const std::string BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_DISTRIBUTED_SCENE_ENABLE = "distributedSceneEnable"; const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_AVAILABLESCOPE_SIGNATURE = "signature"; const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_AVAILABLESCOPE_PRIVILEGED = "privileged"; const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_AVAILABLESCOPE_RESTRICTED = "restricted"; @@ -113,6 +120,7 @@ const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_LABEL_ID = "labelId" const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_DESCRIPTION = "description"; const std::string BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_DESCRIPTION_ID = "descriptionId"; const std::string BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS = "reqPermissions"; +const std::string BUNDLE_MODULE_PROFILE_KEY_REQUEST_PERMISSIONS = "requestPermissions"; const std::string BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_NAME = "name"; const std::string BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_REASON = "reason"; const std::string BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_USEDSCENE = "usedScene"; diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index a3a8f419..4842061e 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -50,6 +50,18 @@ struct DefPermission { int32_t descriptionId; }; +struct DefinePermission { + std::string name; + std::string grantMode; + std::string availableLevel; + bool provisionEnable; + bool distributedSceneEnable = false; + std::string label; + int32_t labelId; + std::string description; + int32_t descriptionId; +}; + struct UsedScene { std::vector ability; std::string when; @@ -61,6 +73,12 @@ struct ReqPermission { UsedScene usedScene; }; +struct RequestPermission { + std::string name; + std::string reason; + UsedScene usedScene; +}; + struct InnerModuleInfo { std::string modulePackage; std::string moduleName; @@ -81,6 +99,8 @@ struct InnerModuleInfo { std::vector reqCapabilities; std::vector reqPermissions; std::vector defPermissions; + std::vector requestPermissions; + std::vector definePermissions; std::vector abilityKeys; std::vector skillKeys; }; @@ -815,6 +835,15 @@ public: return defPermissions; } + std::vector GetDefinePermissions() const + { + std::vector definePermissions; + if (innerModuleInfos_.count(currentPackage_) == 1) { + definePermissions = innerModuleInfos_.at(currentPackage_).definePermissions; + } + return definePermissions; + } + std::vector GetReqPermissions() const { std::vector reqPermissions; @@ -824,6 +853,15 @@ public: return reqPermissions; } + std::vector GetRequestPermissions() const + { + std::vector requestPermissions; + if (innerModuleInfos_.count(currentPackage_) == 1) { + requestPermissions = innerModuleInfos_.at(currentPackage_).requestPermissions; + } + return requestPermissions; + } + bool FindModule(std::string modulePackage) const { return (innerModuleInfos_.find(modulePackage) != innerModuleInfos_.end()); @@ -1241,6 +1279,17 @@ public: } return moduleVec; } + + uint32_t GetAccessTokenId(const int32_t userId) const + { + InnerBundleUserInfo userInfo; + if (GetInnerBundleUserInfo(userId, userInfo)) { + return userInfo.accessTokenId; + } + return 0; + } + + void SetAccessTokenId(uint32_t accessToken, const int32_t userId); private: void GetBundleWithAbilities( int32_t flags, BundleInfo &bundleInfo, int32_t userId = Constants::UNSPECIFIED_USERID) const; @@ -1288,6 +1337,8 @@ void from_json(const nlohmann::json &jsonObject, Skill &skill); void from_json(const nlohmann::json &jsonObject, Distro &distro); void from_json(const nlohmann::json &jsonObject, ReqPermission &ReqPermission); void from_json(const nlohmann::json &jsonObject, DefPermission &DefPermission); +void from_json(const nlohmann::json &jsonObject, RequestPermission &requestPermission); +void from_json(const nlohmann::json &jsonObject, DefinePermission &definePermission); void from_json(const nlohmann::json &jsonObject, InstallMark &installMark); } // namespace AppExecFwk diff --git a/services/bundlemgr/include/inner_bundle_user_info.h b/services/bundlemgr/include/inner_bundle_user_info.h index 49d6997b..078f9e72 100644 --- a/services/bundlemgr/include/inner_bundle_user_info.h +++ b/services/bundlemgr/include/inner_bundle_user_info.h @@ -25,7 +25,7 @@ struct InnerBundleUserInfo { BundleUserInfo bundleUserInfo; int32_t uid = Constants::INVALID_UID; std::vector gids; - int32_t accessTokenId = Constants::INVALID_ACCESS_TOKEN_ID; + uint32_t accessTokenId = 0; std::string bundleName; // The time(unix time) will be recalculated diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 524f9d23..dc114d27 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -37,8 +37,8 @@ #include "bundle_verify_mgr.h" namespace OHOS { namespace AppExecFwk { +using namespace OHOS::Security; namespace { - bool UninstallApplicationProcesses(const std::string &bundleName, const int uid) { APP_LOGI("uninstall kill running processes, app name is %{public}s", bundleName.c_str()); @@ -179,6 +179,9 @@ ErrCode BaseBundleInstaller::InnerProcessBundleInstall(std::unordered_mapAddInnerBundleInfo(bundleName_, info)) { APP_LOGE("add bundle %{public}s info failed", bundleName_.c_str()); + if (BundlePermissionMgr::DeleteTokenId(tokenId) != ERR_OK) { + APP_LOGE("delete accessToken failed"); + } dataMgr_->UpdateBundleInstallState(bundleName_, InstallState::UNINSTALL_START); dataMgr_->UpdateBundleInstallState(bundleName_, InstallState::UNINSTALL_SUCCESS); return ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR; diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index a9c496a7..27090273 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -559,7 +559,8 @@ bool BundleMgrHostImpl::DumpInfos( case DumpFlag::DUMP_BUNDLE_INFO: { BundleInfo bundleInfo; ret = GetBundleInfo( - bundleName, BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, userId); + bundleName, BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_APPLICATION_INFO_WITH_PERMISSION, + bundleInfo, userId); std::vector innerBundleUserInfos; if (!GetBundleUserInfos(bundleName, userId, innerBundleUserInfos)) { APP_LOGI("get all userInfo in bundle(%{public}s) failed", bundleName.c_str()); diff --git a/services/bundlemgr/src/bundle_permission_mgr.cpp b/services/bundlemgr/src/bundle_permission_mgr.cpp index 03a5b3bc..d3d56dfd 100644 --- a/services/bundlemgr/src/bundle_permission_mgr.cpp +++ b/services/bundlemgr/src/bundle_permission_mgr.cpp @@ -22,13 +22,13 @@ namespace OHOS { namespace AppExecFwk { - using namespace OHOS::Security; - namespace { +const uint32_t DEFAULT_ACCESSTOKENID = 100; +} // convert the Permission::PermissionDef struct to // AppExecFwk::PermissionDef struct that can be used in IPC process -bool ConvertPermissionDef(const Permission::PermissionDef &permDef, PermissionDef &permissionDef) +bool BundlePermissionMgr::ConvertPermissionDef(const Permission::PermissionDef &permDef, PermissionDef &permissionDef) { permissionDef.permissionName = permDef.permissionName; permissionDef.bundleName = permDef.bundleName; @@ -42,7 +42,7 @@ bool ConvertPermissionDef(const Permission::PermissionDef &permDef, PermissionDe } // Convert from the struct DefPermission that parsed from config.json -bool ConvertPermissionDef( +bool BundlePermissionMgr::ConvertPermissionDef( Permission::PermissionDef &permDef, const DefPermission &defPermission, const std::string &bundleName) { permDef.permissionName = defPermission.name; @@ -80,7 +80,21 @@ bool ConvertPermissionDef( return true; } -} // namespace +uint32_t BundlePermissionMgr::CreateTokenId( + const InnerBundleInfo &innerBundleInfo, const std::string bundleName, const int32_t userId) +{ + return DEFAULT_ACCESSTOKENID; +} + +int32_t BundlePermissionMgr::DeleteTokenId(const uint32_t tokenId) +{ + return 0; +} + +int32_t BundlePermissionMgr::GrantedRequestPermissions(const InnerBundleInfo &innerBundleInfo, const int32_t userId) +{ + return 0; +} bool BundlePermissionMgr::InitPermissions() { diff --git a/services/bundlemgr/src/bundle_profile.cpp b/services/bundlemgr/src/bundle_profile.cpp index 1399be02..47a1cd69 100644 --- a/services/bundlemgr/src/bundle_profile.cpp +++ b/services/bundlemgr/src/bundle_profile.cpp @@ -297,6 +297,8 @@ struct Module { std::vector shortcuts; std::vector defPermissions; std::vector reqPermissions; + std::vector definePermissions; + std::vector requestPermissions; std::string mainAbility; std::string srcPath; }; @@ -1640,6 +1642,22 @@ void from_json(const nlohmann::json &jsonObject, Module &module) false, parseResult, ArrayType::OBJECT); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS, + module.definePermissions, + JsonType::ARRAY, + false, + parseResult, + ArrayType::OBJECT); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + BUNDLE_MODULE_PROFILE_KEY_REQUEST_PERMISSIONS, + module.requestPermissions, + JsonType::ARRAY, + false, + parseResult, + ArrayType::OBJECT); GetValueIfFindKey(jsonObject, jsonObjectEnd, BUNDLE_MODULE_PROFILE_KEY_MAIN_ABILITY, @@ -1920,6 +1938,8 @@ bool TransformToInfo(const ProfileReader::ConfigJson &configJson, InnerModuleInf innerModuleInfo.reqCapabilities = configJson.module.reqCapabilities; innerModuleInfo.defPermissions = configJson.module.defPermissions; innerModuleInfo.reqPermissions = configJson.module.reqPermissions; + innerModuleInfo.definePermissions = configJson.module.definePermissions; + innerModuleInfo.requestPermissions = configJson.module.requestPermissions; innerModuleInfo.mainAbility = configJson.module.mainAbility; innerModuleInfo.srcPath = configJson.module.srcPath; return true; diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index 626a747e..b5fa9e75 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -55,6 +55,8 @@ const std::string MODULE_DISTRO = "distro"; const std::string MODULE_REQ_CAPABILITIES = "reqCapabilities"; const std::string MODULE_REQ_PERMS = "reqPermissions"; const std::string MODULE_DEF_PERMS = "defPermissions"; +const std::string MODULE_REQUEST_PERMS = "requestPermissions"; +const std::string MODULE_DEFINE_PERMS = "definePermissions"; const std::string MODULE_DATA_DIR = "moduleDataDir"; const std::string MODULE_RES_PATH = "moduleResPath"; const std::string MODULE_ABILITY_KEYS = "abilityKeys"; @@ -320,6 +322,32 @@ void to_json(nlohmann::json &jsonObject, const DefPermission &defPermission) }; } +void to_json(nlohmann::json &jsonObject, const RequestPermission &requestPermission) +{ + jsonObject = nlohmann::json { + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_NAME, requestPermission.name}, + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_REASON, requestPermission.reason}, + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_USEDSCENE, requestPermission.usedScene} + }; +} + +void to_json(nlohmann::json &jsonObject, const DefinePermission &definePermission) +{ + jsonObject = nlohmann::json { + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_NAME, definePermission.name}, + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_GRANTMODE, definePermission.grantMode}, + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_AVAILABLELEVEL, definePermission.availableLevel}, + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_PROVISION_ANABLE, + definePermission.provisionEnable}, + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_DISTRIBUTED_SCENE_ENABLE, + definePermission.distributedSceneEnable}, + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_LABEL, definePermission.label}, + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_LABEL_ID, definePermission.labelId}, + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_DESCRIPTION, definePermission.description}, + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_DESCRIPTION_ID, definePermission.descriptionId} + }; +} + void to_json(nlohmann::json &jsonObject, const InnerModuleInfo &info) { jsonObject = nlohmann::json { @@ -340,6 +368,8 @@ void to_json(nlohmann::json &jsonObject, const InnerModuleInfo &info) {MODULE_REQ_CAPABILITIES, info.reqCapabilities}, {MODULE_REQ_PERMS, info.reqPermissions}, {MODULE_DEF_PERMS, info.defPermissions}, + {MODULE_REQUEST_PERMS, info.requestPermissions}, + {MODULE_DEFINE_PERMS, info.definePermissions}, {MODULE_ABILITY_KEYS, info.abilityKeys}, {MODULE_SKILL_KEYS, info.skillKeys}, {MODULE_MAIN_ABILITY, info.mainAbility}, @@ -560,6 +590,22 @@ void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info) false, ProfileReader::parseResult, ArrayType::OBJECT); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + MODULE_REQUEST_PERMS, + info.requestPermissions, + JsonType::ARRAY, + false, + ProfileReader::parseResult, + ArrayType::OBJECT); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + MODULE_DEFINE_PERMS, + info.definePermissions, + JsonType::ARRAY, + false, + ProfileReader::parseResult, + ArrayType::OBJECT); GetValueIfFindKey>(jsonObject, jsonObjectEnd, MODULE_ABILITY_KEYS, @@ -759,6 +805,35 @@ void from_json(const nlohmann::json &jsonObject, ReqPermission &reqPermission) ArrayType::NOT_ARRAY); } +void from_json(const nlohmann::json &jsonObject, RequestPermission &requestPermission) +{ + const auto &jsonObjectEnd = jsonObject.end(); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_NAME, + requestPermission.name, + JsonType::STRING, + true, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_REASON, + requestPermission.reason, + JsonType::STRING, + false, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_USEDSCENE, + requestPermission.usedScene, + JsonType::OBJECT, + false, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); +} + void from_json(const nlohmann::json &jsonObject, DefPermission &defPermission) { const auto &jsonObjectEnd = jsonObject.end(); @@ -820,6 +895,83 @@ void from_json(const nlohmann::json &jsonObject, DefPermission &defPermission) ArrayType::NOT_ARRAY); } +void from_json(const nlohmann::json &jsonObject, DefinePermission &definePermission) +{ + const auto &jsonObjectEnd = jsonObject.end(); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_NAME, + definePermission.name, + JsonType::STRING, + true, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_GRANTMODE, + definePermission.grantMode, + JsonType::STRING, + false, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_AVAILABLELEVEL, + definePermission.availableLevel, + JsonType::STRING, + false, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_PROVISION_ANABLE, + definePermission.provisionEnable, + JsonType::BOOLEAN, + false, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS_DISTRIBUTED_SCENE_ENABLE, + definePermission.distributedSceneEnable, + JsonType::BOOLEAN, + false, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_LABEL, + definePermission.label, + JsonType::STRING, + false, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_LABEL_ID, + definePermission.labelId, + JsonType::NUMBER, + false, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_DESCRIPTION, + definePermission.description, + JsonType::STRING, + false, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_DESCRIPTION_ID, + definePermission.descriptionId, + JsonType::NUMBER, + false, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); +} + void from_json(const nlohmann::json &jsonObject, InstallMark &installMark) { const auto &jsonObjectEnd = jsonObject.end(); @@ -1369,6 +1521,7 @@ void InnerBundleInfo::GetApplicationInfo(int32_t flags, int32_t userId, Applicat appInfo = baseApplicationInfo_; appInfo.enabled = innerBundleUserInfo.bundleUserInfo.enabled; appInfo.uid = innerBundleUserInfo.uid; + appInfo.accessTokenId = innerBundleUserInfo.accessTokenId; for (const auto &info : innerModuleInfos_) { ModuleInfo moduleInfo; moduleInfo.moduleName = info.second.moduleName; @@ -1383,6 +1536,10 @@ void InnerBundleInfo::GetApplicationInfo(int32_t flags, int32_t userId, Applicat info.second.reqPermissions.end(), std::back_inserter(appInfo.permissions), [](const auto &p) { return p.name; }); + std::transform(info.second.requestPermissions.begin(), + info.second.requestPermissions.end(), + std::back_inserter(appInfo.permissions), + [](const auto &p) { return p.name; }); } if ((static_cast(flags) & GET_APPLICATION_INFO_WITH_METADATA) == GET_APPLICATION_INFO_WITH_METADATA && info.second.metaData.customizeData.size() > 0) { @@ -1419,6 +1576,14 @@ void InnerBundleInfo::GetBundleInfo(int32_t flags, BundleInfo &bundleInfo, int32 info.second.defPermissions.end(), std::back_inserter(bundleInfo.defPermissions), [](const auto &p) { return p.name; }); + std::transform(info.second.requestPermissions.begin(), + info.second.requestPermissions.end(), + std::back_inserter(bundleInfo.reqPermissions), + [](const auto &p) { return p.name; }); + std::transform(info.second.definePermissions.begin(), + info.second.definePermissions.end(), + std::back_inserter(bundleInfo.defPermissions), + [](const auto &p) { return p.name; }); } bundleInfo.hapModuleNames.emplace_back(info.second.modulePackage); auto hapmoduleinfo = FindHapModuleInfo(info.second.modulePackage, userId); @@ -1583,6 +1748,17 @@ void InnerBundleInfo::SetBundleInstallTime(const int64_t time, int32_t userId) infoItem->second.updateTime = time; } +void InnerBundleInfo::SetAccessTokenId(uint32_t accessToken, const int32_t userId) +{ + auto& key = NameAndUserIdToKey(GetBundleName(), userId); + auto infoItem = innerBundleUserInfos_.find(key); + if (infoItem == innerBundleUserInfos_.end()) { + return; + } + + infoItem->second.accessTokenId = accessToken; +} + void InnerBundleInfo::SetBundleUpdateTime(const int64_t time, int32_t userId) { auto& key = NameAndUserIdToKey(GetBundleName(), userId); diff --git a/services/bundlemgr/src/inner_bundle_user_info.cpp b/services/bundlemgr/src/inner_bundle_user_info.cpp index 7be4b72e..cde74954 100644 --- a/services/bundlemgr/src/inner_bundle_user_info.cpp +++ b/services/bundlemgr/src/inner_bundle_user_info.cpp @@ -60,7 +60,7 @@ void from_json(const nlohmann::json& jsonObject, InnerBundleUserInfo& innerBundl false, parseResult, ArrayType::NUMBER); - GetValueIfFindKey(jsonObject, + GetValueIfFindKey(jsonObject, jsonObjectEnd, INNER_BUNDLE_USER_INFO_ACCESS_TOKEN_ID, innerBundleUserInfo.accessTokenId,