1600cc4afSopenharmony_ci/* 2600cc4afSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3600cc4afSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4600cc4afSopenharmony_ci * you may not use this file except in compliance with the License. 5600cc4afSopenharmony_ci * You may obtain a copy of the License at 6600cc4afSopenharmony_ci * 7600cc4afSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8600cc4afSopenharmony_ci * 9600cc4afSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10600cc4afSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11600cc4afSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12600cc4afSopenharmony_ci * See the License for the specific language governing permissions and 13600cc4afSopenharmony_ci * limitations under the License. 14600cc4afSopenharmony_ci */ 15600cc4afSopenharmony_ci 16600cc4afSopenharmony_ci#include "installd_client.h" 17600cc4afSopenharmony_ci 18600cc4afSopenharmony_ci#include "installd/installd_load_callback.h" 19600cc4afSopenharmony_ci#include "installd_death_recipient.h" 20600cc4afSopenharmony_ci#include "iservice_registry.h" 21600cc4afSopenharmony_ci#include "system_ability_definition.h" 22600cc4afSopenharmony_ci#include "system_ability_helper.h" 23600cc4afSopenharmony_ci 24600cc4afSopenharmony_cinamespace OHOS { 25600cc4afSopenharmony_cinamespace AppExecFwk { 26600cc4afSopenharmony_cinamespace { 27600cc4afSopenharmony_ciconstexpr int16_t LOAD_SA_TIMEOUT_MS = 4 * 1000; 28600cc4afSopenharmony_ci} // namespace 29600cc4afSopenharmony_ci 30600cc4afSopenharmony_ciErrCode InstalldClient::CreateBundleDir(const std::string &bundleDir) 31600cc4afSopenharmony_ci{ 32600cc4afSopenharmony_ci if (bundleDir.empty()) { 33600cc4afSopenharmony_ci APP_LOGE("bundle dir is empty"); 34600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 35600cc4afSopenharmony_ci } 36600cc4afSopenharmony_ci 37600cc4afSopenharmony_ci return CallService(&IInstalld::CreateBundleDir, bundleDir); 38600cc4afSopenharmony_ci} 39600cc4afSopenharmony_ci 40600cc4afSopenharmony_ciErrCode InstalldClient::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath, 41600cc4afSopenharmony_ci const std::string &targetSoPath, const std::string &cpuAbi) 42600cc4afSopenharmony_ci{ 43600cc4afSopenharmony_ci if (srcModulePath.empty() || targetPath.empty()) { 44600cc4afSopenharmony_ci APP_LOGE("src module path or target path is empty"); 45600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 46600cc4afSopenharmony_ci } 47600cc4afSopenharmony_ci 48600cc4afSopenharmony_ci return CallService(&IInstalld::ExtractModuleFiles, srcModulePath, targetPath, targetSoPath, cpuAbi); 49600cc4afSopenharmony_ci} 50600cc4afSopenharmony_ci 51600cc4afSopenharmony_ciErrCode InstalldClient::ExtractFiles(const ExtractParam &extractParam) 52600cc4afSopenharmony_ci{ 53600cc4afSopenharmony_ci if (extractParam.srcPath.empty() || extractParam.targetPath.empty()) { 54600cc4afSopenharmony_ci APP_LOGE("src path or target path is empty"); 55600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 56600cc4afSopenharmony_ci } 57600cc4afSopenharmony_ci return CallService(&IInstalld::ExtractFiles, extractParam); 58600cc4afSopenharmony_ci} 59600cc4afSopenharmony_ci 60600cc4afSopenharmony_ciErrCode InstalldClient::ExtractHnpFiles(const std::string &hnpPackageInfo, const ExtractParam &extractParam) 61600cc4afSopenharmony_ci{ 62600cc4afSopenharmony_ci if (extractParam.srcPath.empty() || extractParam.targetPath.empty() || hnpPackageInfo.empty()) { 63600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 64600cc4afSopenharmony_ci } 65600cc4afSopenharmony_ci return CallService(&IInstalld::ExtractHnpFiles, hnpPackageInfo, extractParam); 66600cc4afSopenharmony_ci} 67600cc4afSopenharmony_ci 68600cc4afSopenharmony_ciErrCode InstalldClient::ProcessBundleInstallNative(const std::string &userId, const std::string &hnpRootPath, 69600cc4afSopenharmony_ci const std::string &hapPath, const std::string &cpuAbi, const std::string &packageName) 70600cc4afSopenharmony_ci{ 71600cc4afSopenharmony_ci return CallService(&IInstalld::ProcessBundleInstallNative, userId, hnpRootPath, 72600cc4afSopenharmony_ci hapPath, cpuAbi, packageName); 73600cc4afSopenharmony_ci} 74600cc4afSopenharmony_ci 75600cc4afSopenharmony_ciErrCode InstalldClient::ProcessBundleUnInstallNative(const std::string &userId, const std::string &packageName) 76600cc4afSopenharmony_ci{ 77600cc4afSopenharmony_ci return CallService(&IInstalld::ProcessBundleUnInstallNative, userId, packageName); 78600cc4afSopenharmony_ci} 79600cc4afSopenharmony_ci 80600cc4afSopenharmony_ciErrCode InstalldClient::ExecuteAOT(const AOTArgs &aotArgs, std::vector<uint8_t> &pendSignData) 81600cc4afSopenharmony_ci{ 82600cc4afSopenharmony_ci return CallService(&IInstalld::ExecuteAOT, aotArgs, pendSignData); 83600cc4afSopenharmony_ci} 84600cc4afSopenharmony_ci 85600cc4afSopenharmony_ciErrCode InstalldClient::PendSignAOT(const std::string &anFileName, const std::vector<uint8_t> &signData) 86600cc4afSopenharmony_ci{ 87600cc4afSopenharmony_ci return CallService(&IInstalld::PendSignAOT, anFileName, signData); 88600cc4afSopenharmony_ci} 89600cc4afSopenharmony_ci 90600cc4afSopenharmony_ciErrCode InstalldClient::StopAOT() 91600cc4afSopenharmony_ci{ 92600cc4afSopenharmony_ci return CallService(&IInstalld::StopAOT); 93600cc4afSopenharmony_ci} 94600cc4afSopenharmony_ci 95600cc4afSopenharmony_ciErrCode InstalldClient::RenameModuleDir(const std::string &oldPath, const std::string &newPath) 96600cc4afSopenharmony_ci{ 97600cc4afSopenharmony_ci if (oldPath.empty() || newPath.empty()) { 98600cc4afSopenharmony_ci APP_LOGE("rename path is empty"); 99600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 100600cc4afSopenharmony_ci } 101600cc4afSopenharmony_ci 102600cc4afSopenharmony_ci return CallService(&IInstalld::RenameModuleDir, oldPath, newPath); 103600cc4afSopenharmony_ci} 104600cc4afSopenharmony_ci 105600cc4afSopenharmony_ciErrCode InstalldClient::CreateBundleDataDir(const CreateDirParam &createDirParam) 106600cc4afSopenharmony_ci{ 107600cc4afSopenharmony_ci if (createDirParam.bundleName.empty() || createDirParam.userId < 0 108600cc4afSopenharmony_ci || createDirParam.uid < 0 || createDirParam.gid < 0) { 109600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 110600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 111600cc4afSopenharmony_ci } 112600cc4afSopenharmony_ci 113600cc4afSopenharmony_ci return CallService(&IInstalld::CreateBundleDataDir, createDirParam); 114600cc4afSopenharmony_ci} 115600cc4afSopenharmony_ci 116600cc4afSopenharmony_ciErrCode InstalldClient::CreateBundleDataDirWithVector(const std::vector<CreateDirParam> &createDirParams) 117600cc4afSopenharmony_ci{ 118600cc4afSopenharmony_ci return CallService(&IInstalld::CreateBundleDataDirWithVector, createDirParams); 119600cc4afSopenharmony_ci} 120600cc4afSopenharmony_ci 121600cc4afSopenharmony_ciErrCode InstalldClient::RemoveBundleDataDir( 122600cc4afSopenharmony_ci const std::string &bundleName, const int32_t userId, bool isAtomicService) 123600cc4afSopenharmony_ci{ 124600cc4afSopenharmony_ci if (bundleName.empty() || userId < 0) { 125600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 126600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 127600cc4afSopenharmony_ci } 128600cc4afSopenharmony_ci 129600cc4afSopenharmony_ci return CallService(&IInstalld::RemoveBundleDataDir, bundleName, userId, isAtomicService); 130600cc4afSopenharmony_ci} 131600cc4afSopenharmony_ci 132600cc4afSopenharmony_ciErrCode InstalldClient::RemoveModuleDataDir(const std::string &ModuleName, const int userid) 133600cc4afSopenharmony_ci{ 134600cc4afSopenharmony_ci if (ModuleName.empty() || userid < 0) { 135600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 136600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 137600cc4afSopenharmony_ci } 138600cc4afSopenharmony_ci 139600cc4afSopenharmony_ci return CallService(&IInstalld::RemoveModuleDataDir, ModuleName, userid); 140600cc4afSopenharmony_ci} 141600cc4afSopenharmony_ci 142600cc4afSopenharmony_ciErrCode InstalldClient::RemoveDir(const std::string &dir) 143600cc4afSopenharmony_ci{ 144600cc4afSopenharmony_ci if (dir.empty()) { 145600cc4afSopenharmony_ci APP_LOGE("dir removed is empty"); 146600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 147600cc4afSopenharmony_ci } 148600cc4afSopenharmony_ci 149600cc4afSopenharmony_ci return CallService(&IInstalld::RemoveDir, dir); 150600cc4afSopenharmony_ci} 151600cc4afSopenharmony_ci 152600cc4afSopenharmony_ciint64_t InstalldClient::GetDiskUsage(const std::string &dir, bool isRealPath) 153600cc4afSopenharmony_ci{ 154600cc4afSopenharmony_ci if (dir.empty()) { 155600cc4afSopenharmony_ci APP_LOGE("bundle dir is empty"); 156600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 157600cc4afSopenharmony_ci } 158600cc4afSopenharmony_ci 159600cc4afSopenharmony_ci return CallService(&IInstalld::GetDiskUsage, dir, isRealPath); 160600cc4afSopenharmony_ci} 161600cc4afSopenharmony_ci 162600cc4afSopenharmony_ciErrCode InstalldClient::CleanBundleDataDir(const std::string &bundleDir) 163600cc4afSopenharmony_ci{ 164600cc4afSopenharmony_ci if (bundleDir.empty()) { 165600cc4afSopenharmony_ci APP_LOGE("bundle dir is empty"); 166600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 167600cc4afSopenharmony_ci } 168600cc4afSopenharmony_ci 169600cc4afSopenharmony_ci return CallService(&IInstalld::CleanBundleDataDir, bundleDir); 170600cc4afSopenharmony_ci} 171600cc4afSopenharmony_ci 172600cc4afSopenharmony_ciErrCode InstalldClient::CleanBundleDataDirByName(const std::string &bundleName, const int userid, const int appIndex) 173600cc4afSopenharmony_ci{ 174600cc4afSopenharmony_ci if (bundleName.empty() || userid < 0 || appIndex < 0 || appIndex > Constants::INITIAL_SANDBOX_APP_INDEX) { 175600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 176600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 177600cc4afSopenharmony_ci } 178600cc4afSopenharmony_ci 179600cc4afSopenharmony_ci return CallService(&IInstalld::CleanBundleDataDirByName, bundleName, userid, appIndex); 180600cc4afSopenharmony_ci} 181600cc4afSopenharmony_ci 182600cc4afSopenharmony_ciErrCode InstalldClient::GetBundleStats(const std::string &bundleName, const int32_t userId, 183600cc4afSopenharmony_ci std::vector<int64_t> &bundleStats, const int32_t uid, const int32_t appIndex) 184600cc4afSopenharmony_ci{ 185600cc4afSopenharmony_ci if (bundleName.empty()) { 186600cc4afSopenharmony_ci APP_LOGE("bundleName is empty"); 187600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 188600cc4afSopenharmony_ci } 189600cc4afSopenharmony_ci 190600cc4afSopenharmony_ci return CallService(&IInstalld::GetBundleStats, bundleName, userId, bundleStats, uid, appIndex); 191600cc4afSopenharmony_ci} 192600cc4afSopenharmony_ci 193600cc4afSopenharmony_ciErrCode InstalldClient::GetAllBundleStats(const int32_t userId, 194600cc4afSopenharmony_ci std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids) 195600cc4afSopenharmony_ci{ 196600cc4afSopenharmony_ci if (uids.empty()) { 197600cc4afSopenharmony_ci APP_LOGE("uids is empty"); 198600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 199600cc4afSopenharmony_ci } 200600cc4afSopenharmony_ci 201600cc4afSopenharmony_ci return CallService(&IInstalld::GetAllBundleStats, userId, bundleStats, uids); 202600cc4afSopenharmony_ci} 203600cc4afSopenharmony_ci 204600cc4afSopenharmony_ciErrCode InstalldClient::SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl, 205600cc4afSopenharmony_ci bool isPreInstallApp, bool debug) 206600cc4afSopenharmony_ci{ 207600cc4afSopenharmony_ci if (dir.empty() || bundleName.empty() || apl.empty()) { 208600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 209600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 210600cc4afSopenharmony_ci } 211600cc4afSopenharmony_ci 212600cc4afSopenharmony_ci return CallService(&IInstalld::SetDirApl, dir, bundleName, apl, isPreInstallApp, debug); 213600cc4afSopenharmony_ci} 214600cc4afSopenharmony_ci 215600cc4afSopenharmony_ciErrCode InstalldClient::GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath) 216600cc4afSopenharmony_ci{ 217600cc4afSopenharmony_ci if (dir.empty()) { 218600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 219600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 220600cc4afSopenharmony_ci } 221600cc4afSopenharmony_ci 222600cc4afSopenharmony_ci return CallService(&IInstalld::GetBundleCachePath, dir, cachePath); 223600cc4afSopenharmony_ci} 224600cc4afSopenharmony_ci 225600cc4afSopenharmony_civoid InstalldClient::ResetInstalldProxy() 226600cc4afSopenharmony_ci{ 227600cc4afSopenharmony_ci std::lock_guard<std::mutex> lock(mutex_); 228600cc4afSopenharmony_ci if ((installdProxy_ != nullptr) && (installdProxy_->AsObject() != nullptr)) { 229600cc4afSopenharmony_ci installdProxy_->AsObject()->RemoveDeathRecipient(recipient_); 230600cc4afSopenharmony_ci } 231600cc4afSopenharmony_ci SystemAbilityHelper::UnloadSystemAbility(INSTALLD_SERVICE_ID); 232600cc4afSopenharmony_ci installdProxy_ = nullptr; 233600cc4afSopenharmony_ci} 234600cc4afSopenharmony_ci 235600cc4afSopenharmony_cibool InstalldClient::LoadInstalldService() 236600cc4afSopenharmony_ci{ 237600cc4afSopenharmony_ci { 238600cc4afSopenharmony_ci std::unique_lock<std::mutex> lock(loadSaMutex_); 239600cc4afSopenharmony_ci loadSaFinished_ = false; 240600cc4afSopenharmony_ci } 241600cc4afSopenharmony_ci auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 242600cc4afSopenharmony_ci if (systemAbilityMgr == nullptr) { 243600cc4afSopenharmony_ci APP_LOGE("Failed to get SystemAbilityManager"); 244600cc4afSopenharmony_ci return false; 245600cc4afSopenharmony_ci } 246600cc4afSopenharmony_ci sptr<InstalldLoadCallback> loadCallback = new (std::nothrow) InstalldLoadCallback(); 247600cc4afSopenharmony_ci if (loadCallback == nullptr) { 248600cc4afSopenharmony_ci APP_LOGE("Create load callback failed"); 249600cc4afSopenharmony_ci return false; 250600cc4afSopenharmony_ci } 251600cc4afSopenharmony_ci auto ret = systemAbilityMgr->LoadSystemAbility(INSTALLD_SERVICE_ID, loadCallback); 252600cc4afSopenharmony_ci if (ret != 0) { 253600cc4afSopenharmony_ci APP_LOGE("Load system ability %{public}d failed with %{public}d", INSTALLD_SERVICE_ID, ret); 254600cc4afSopenharmony_ci return false; 255600cc4afSopenharmony_ci } 256600cc4afSopenharmony_ci 257600cc4afSopenharmony_ci { 258600cc4afSopenharmony_ci std::unique_lock<std::mutex> lock(loadSaMutex_); 259600cc4afSopenharmony_ci auto waitStatus = loadSaCondition_.wait_for(lock, std::chrono::milliseconds(LOAD_SA_TIMEOUT_MS), 260600cc4afSopenharmony_ci [this]() { 261600cc4afSopenharmony_ci return loadSaFinished_; 262600cc4afSopenharmony_ci }); 263600cc4afSopenharmony_ci if (!waitStatus) { 264600cc4afSopenharmony_ci APP_LOGE("Wait for load sa timeout"); 265600cc4afSopenharmony_ci return false; 266600cc4afSopenharmony_ci } 267600cc4afSopenharmony_ci } 268600cc4afSopenharmony_ci return true; 269600cc4afSopenharmony_ci} 270600cc4afSopenharmony_ci 271600cc4afSopenharmony_cisptr<IInstalld> InstalldClient::GetInstalldProxy() 272600cc4afSopenharmony_ci{ 273600cc4afSopenharmony_ci std::lock_guard<std::mutex> lock(getProxyMutex_); 274600cc4afSopenharmony_ci if (installdProxy_ != nullptr) { 275600cc4afSopenharmony_ci APP_LOGD("installd ready"); 276600cc4afSopenharmony_ci return installdProxy_; 277600cc4afSopenharmony_ci } 278600cc4afSopenharmony_ci 279600cc4afSopenharmony_ci APP_LOGI("try to get installd proxy"); 280600cc4afSopenharmony_ci if (!LoadInstalldService()) { 281600cc4afSopenharmony_ci APP_LOGE("load installd service failed"); 282600cc4afSopenharmony_ci return nullptr; 283600cc4afSopenharmony_ci } 284600cc4afSopenharmony_ci if ((installdProxy_ == nullptr) || (installdProxy_->AsObject() == nullptr)) { 285600cc4afSopenharmony_ci APP_LOGE("the installd proxy or remote object is null"); 286600cc4afSopenharmony_ci return nullptr; 287600cc4afSopenharmony_ci } 288600cc4afSopenharmony_ci 289600cc4afSopenharmony_ci recipient_ = new (std::nothrow) InstalldDeathRecipient(); 290600cc4afSopenharmony_ci if (recipient_ == nullptr) { 291600cc4afSopenharmony_ci APP_LOGE("the death recipient is nullptr"); 292600cc4afSopenharmony_ci return nullptr; 293600cc4afSopenharmony_ci } 294600cc4afSopenharmony_ci installdProxy_->AsObject()->AddDeathRecipient(recipient_); 295600cc4afSopenharmony_ci return installdProxy_; 296600cc4afSopenharmony_ci} 297600cc4afSopenharmony_ci 298600cc4afSopenharmony_ciErrCode InstalldClient::ScanDir( 299600cc4afSopenharmony_ci const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths) 300600cc4afSopenharmony_ci{ 301600cc4afSopenharmony_ci if (dir.empty()) { 302600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 303600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 304600cc4afSopenharmony_ci } 305600cc4afSopenharmony_ci 306600cc4afSopenharmony_ci return CallService(&IInstalld::ScanDir, dir, scanMode, resultMode, paths); 307600cc4afSopenharmony_ci} 308600cc4afSopenharmony_ci 309600cc4afSopenharmony_ciErrCode InstalldClient::MoveFile(const std::string &oldPath, const std::string &newPath) 310600cc4afSopenharmony_ci{ 311600cc4afSopenharmony_ci if (oldPath.empty() || newPath.empty()) { 312600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 313600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 314600cc4afSopenharmony_ci } 315600cc4afSopenharmony_ci 316600cc4afSopenharmony_ci return CallService(&IInstalld::MoveFile, oldPath, newPath); 317600cc4afSopenharmony_ci} 318600cc4afSopenharmony_ci 319600cc4afSopenharmony_ciErrCode InstalldClient::CopyFile(const std::string &oldPath, const std::string &newPath, 320600cc4afSopenharmony_ci const std::string &signatureFilePath) 321600cc4afSopenharmony_ci{ 322600cc4afSopenharmony_ci if (oldPath.empty() || newPath.empty()) { 323600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 324600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 325600cc4afSopenharmony_ci } 326600cc4afSopenharmony_ci 327600cc4afSopenharmony_ci return CallService(&IInstalld::CopyFile, oldPath, newPath, signatureFilePath); 328600cc4afSopenharmony_ci} 329600cc4afSopenharmony_ci 330600cc4afSopenharmony_ciErrCode InstalldClient::Mkdir( 331600cc4afSopenharmony_ci const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid) 332600cc4afSopenharmony_ci{ 333600cc4afSopenharmony_ci if (dir.empty()) { 334600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 335600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 336600cc4afSopenharmony_ci } 337600cc4afSopenharmony_ci 338600cc4afSopenharmony_ci return CallService(&IInstalld::Mkdir, dir, mode, uid, gid); 339600cc4afSopenharmony_ci} 340600cc4afSopenharmony_ci 341600cc4afSopenharmony_ciErrCode InstalldClient::GetFileStat(const std::string &file, FileStat &fileStat) 342600cc4afSopenharmony_ci{ 343600cc4afSopenharmony_ci if (file.empty()) { 344600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 345600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 346600cc4afSopenharmony_ci } 347600cc4afSopenharmony_ci 348600cc4afSopenharmony_ci return CallService(&IInstalld::GetFileStat, file, fileStat); 349600cc4afSopenharmony_ci} 350600cc4afSopenharmony_ci 351600cc4afSopenharmony_ciErrCode InstalldClient::ExtractDiffFiles(const std::string &filePath, const std::string &targetPath, 352600cc4afSopenharmony_ci const std::string &cpuAbi) 353600cc4afSopenharmony_ci{ 354600cc4afSopenharmony_ci if (filePath.empty() || targetPath.empty() || cpuAbi.empty()) { 355600cc4afSopenharmony_ci APP_LOGE("file path or target path or cpuAbi is empty"); 356600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 357600cc4afSopenharmony_ci } 358600cc4afSopenharmony_ci return CallService(&IInstalld::ExtractDiffFiles, filePath, targetPath, cpuAbi); 359600cc4afSopenharmony_ci} 360600cc4afSopenharmony_ci 361600cc4afSopenharmony_ciErrCode InstalldClient::ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath, 362600cc4afSopenharmony_ci const std::string &newSoPath, int32_t uid) 363600cc4afSopenharmony_ci{ 364600cc4afSopenharmony_ci if (oldSoPath.empty() || diffFilePath.empty() || newSoPath.empty()) { 365600cc4afSopenharmony_ci APP_LOGE("old path or diff file path or new so path is empty"); 366600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 367600cc4afSopenharmony_ci } 368600cc4afSopenharmony_ci return CallService(&IInstalld::ApplyDiffPatch, oldSoPath, diffFilePath, newSoPath, uid); 369600cc4afSopenharmony_ci} 370600cc4afSopenharmony_ci 371600cc4afSopenharmony_ciErrCode InstalldClient::IsExistDir(const std::string &dir, bool &isExist) 372600cc4afSopenharmony_ci{ 373600cc4afSopenharmony_ci return CallService(&IInstalld::IsExistDir, dir, isExist); 374600cc4afSopenharmony_ci} 375600cc4afSopenharmony_ci 376600cc4afSopenharmony_ciErrCode InstalldClient::IsExistFile(const std::string &path, bool &isExist) 377600cc4afSopenharmony_ci{ 378600cc4afSopenharmony_ci return CallService(&IInstalld::IsExistFile, path, isExist); 379600cc4afSopenharmony_ci} 380600cc4afSopenharmony_ci 381600cc4afSopenharmony_ciErrCode InstalldClient::IsExistApFile(const std::string &path, bool &isExist) 382600cc4afSopenharmony_ci{ 383600cc4afSopenharmony_ci return CallService(&IInstalld::IsExistApFile, path, isExist); 384600cc4afSopenharmony_ci} 385600cc4afSopenharmony_ci 386600cc4afSopenharmony_ciErrCode InstalldClient::IsDirEmpty(const std::string &dir, bool &isDirEmpty) 387600cc4afSopenharmony_ci{ 388600cc4afSopenharmony_ci return CallService(&IInstalld::IsDirEmpty, dir, isDirEmpty); 389600cc4afSopenharmony_ci} 390600cc4afSopenharmony_ci 391600cc4afSopenharmony_ciErrCode InstalldClient::ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec) 392600cc4afSopenharmony_ci{ 393600cc4afSopenharmony_ci return CallService(&IInstalld::ObtainQuickFixFileDir, dir, dirVec); 394600cc4afSopenharmony_ci} 395600cc4afSopenharmony_ci 396600cc4afSopenharmony_ciErrCode InstalldClient::CopyFiles(const std::string &sourceDir, const std::string &destinationDir) 397600cc4afSopenharmony_ci{ 398600cc4afSopenharmony_ci return CallService(&IInstalld::CopyFiles, sourceDir, destinationDir); 399600cc4afSopenharmony_ci} 400600cc4afSopenharmony_ci 401600cc4afSopenharmony_ciErrCode InstalldClient::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, 402600cc4afSopenharmony_ci std::vector<std::string> &fileNames) 403600cc4afSopenharmony_ci{ 404600cc4afSopenharmony_ci return CallService(&IInstalld::GetNativeLibraryFileNames, filePath, cpuAbi, fileNames); 405600cc4afSopenharmony_ci} 406600cc4afSopenharmony_ci 407600cc4afSopenharmony_ciErrCode InstalldClient::VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam) 408600cc4afSopenharmony_ci{ 409600cc4afSopenharmony_ci if (codeSignatureParam.modulePath.empty()) { 410600cc4afSopenharmony_ci APP_LOGE("module path is empty"); 411600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 412600cc4afSopenharmony_ci } 413600cc4afSopenharmony_ci return CallService(&IInstalld::VerifyCodeSignature, codeSignatureParam); 414600cc4afSopenharmony_ci} 415600cc4afSopenharmony_ci 416600cc4afSopenharmony_ciErrCode InstalldClient::CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, bool &isEncryption) 417600cc4afSopenharmony_ci{ 418600cc4afSopenharmony_ci if (checkEncryptionParam.modulePath.empty()) { 419600cc4afSopenharmony_ci APP_LOGE("module path is empty"); 420600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 421600cc4afSopenharmony_ci } 422600cc4afSopenharmony_ci return CallService(&IInstalld::CheckEncryption, checkEncryptionParam, isEncryption); 423600cc4afSopenharmony_ci} 424600cc4afSopenharmony_ci 425600cc4afSopenharmony_ciErrCode InstalldClient::MoveFiles(const std::string &srcDir, const std::string &desDir) 426600cc4afSopenharmony_ci{ 427600cc4afSopenharmony_ci if (srcDir.empty() || desDir.empty()) { 428600cc4afSopenharmony_ci APP_LOGE("src dir or des dir is empty"); 429600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 430600cc4afSopenharmony_ci } 431600cc4afSopenharmony_ci return CallService(&IInstalld::MoveFiles, srcDir, desDir); 432600cc4afSopenharmony_ci} 433600cc4afSopenharmony_ci 434600cc4afSopenharmony_ci 435600cc4afSopenharmony_ciErrCode InstalldClient::ExtractDriverSoFiles(const std::string &srcPath, 436600cc4afSopenharmony_ci const std::unordered_multimap<std::string, std::string> &dirMap) 437600cc4afSopenharmony_ci{ 438600cc4afSopenharmony_ci if (srcPath.empty() || dirMap.empty()) { 439600cc4afSopenharmony_ci APP_LOGE("src path or dir map is empty"); 440600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 441600cc4afSopenharmony_ci } 442600cc4afSopenharmony_ci return CallService(&IInstalld::ExtractDriverSoFiles, srcPath, dirMap); 443600cc4afSopenharmony_ci} 444600cc4afSopenharmony_ci 445600cc4afSopenharmony_ciErrCode InstalldClient::VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam) 446600cc4afSopenharmony_ci{ 447600cc4afSopenharmony_ci if (codeSignatureParam.modulePath.empty()) { 448600cc4afSopenharmony_ci APP_LOGE("module path is empty"); 449600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 450600cc4afSopenharmony_ci } 451600cc4afSopenharmony_ci return CallService(&IInstalld::VerifyCodeSignatureForHap, codeSignatureParam); 452600cc4afSopenharmony_ci} 453600cc4afSopenharmony_ci 454600cc4afSopenharmony_ciErrCode InstalldClient::DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength, 455600cc4afSopenharmony_ci const unsigned char *profileBlock) 456600cc4afSopenharmony_ci{ 457600cc4afSopenharmony_ci if (bundleName.empty() || profileBlock == nullptr) { 458600cc4afSopenharmony_ci APP_LOGE("bundle name or profile block is empty"); 459600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 460600cc4afSopenharmony_ci } 461600cc4afSopenharmony_ci return CallService(&IInstalld::DeliverySignProfile, bundleName, profileBlockLength, profileBlock); 462600cc4afSopenharmony_ci} 463600cc4afSopenharmony_ci 464600cc4afSopenharmony_ciErrCode InstalldClient::RemoveSignProfile(const std::string &bundleName) 465600cc4afSopenharmony_ci{ 466600cc4afSopenharmony_ci if (bundleName.empty()) { 467600cc4afSopenharmony_ci APP_LOGE("bundle name is empty"); 468600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 469600cc4afSopenharmony_ci } 470600cc4afSopenharmony_ci return CallService(&IInstalld::RemoveSignProfile, bundleName); 471600cc4afSopenharmony_ci} 472600cc4afSopenharmony_ci 473600cc4afSopenharmony_civoid InstalldClient::OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject) 474600cc4afSopenharmony_ci{ 475600cc4afSopenharmony_ci { 476600cc4afSopenharmony_ci std::lock_guard<std::mutex> lock(mutex_); 477600cc4afSopenharmony_ci installdProxy_ = iface_cast<IInstalld>(remoteObject); 478600cc4afSopenharmony_ci } 479600cc4afSopenharmony_ci 480600cc4afSopenharmony_ci { 481600cc4afSopenharmony_ci std::lock_guard<std::mutex> lock(loadSaMutex_); 482600cc4afSopenharmony_ci loadSaFinished_ = true; 483600cc4afSopenharmony_ci loadSaCondition_.notify_one(); 484600cc4afSopenharmony_ci } 485600cc4afSopenharmony_ci} 486600cc4afSopenharmony_ci 487600cc4afSopenharmony_civoid InstalldClient::OnLoadSystemAbilityFail() 488600cc4afSopenharmony_ci{ 489600cc4afSopenharmony_ci { 490600cc4afSopenharmony_ci std::lock_guard<std::mutex> lock(mutex_); 491600cc4afSopenharmony_ci installdProxy_ = nullptr; 492600cc4afSopenharmony_ci } 493600cc4afSopenharmony_ci 494600cc4afSopenharmony_ci { 495600cc4afSopenharmony_ci std::lock_guard<std::mutex> lock(loadSaMutex_); 496600cc4afSopenharmony_ci loadSaFinished_ = true; 497600cc4afSopenharmony_ci loadSaCondition_.notify_one(); 498600cc4afSopenharmony_ci } 499600cc4afSopenharmony_ci} 500600cc4afSopenharmony_ci 501600cc4afSopenharmony_cibool InstalldClient::StartInstalldService() 502600cc4afSopenharmony_ci{ 503600cc4afSopenharmony_ci return GetInstalldProxy() != nullptr; 504600cc4afSopenharmony_ci} 505600cc4afSopenharmony_ci 506600cc4afSopenharmony_ciErrCode InstalldClient::ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath, 507600cc4afSopenharmony_ci const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid) 508600cc4afSopenharmony_ci{ 509600cc4afSopenharmony_ci if (hapPath.empty() || tmpSoPath.empty() || cpuAbi.empty()) { 510600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 511600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 512600cc4afSopenharmony_ci } 513600cc4afSopenharmony_ci return CallService(&IInstalld::ExtractEncryptedSoFiles, hapPath, realSoFilesPath, cpuAbi, tmpSoPath, uid); 514600cc4afSopenharmony_ci} 515600cc4afSopenharmony_ci 516600cc4afSopenharmony_ciErrCode InstalldClient::SetEncryptionPolicy(int32_t uid, const std::string &bundleName, 517600cc4afSopenharmony_ci const int32_t userId, std::string &keyId) 518600cc4afSopenharmony_ci{ 519600cc4afSopenharmony_ci if (bundleName.empty()) { 520600cc4afSopenharmony_ci APP_LOGE("bundleName is empty"); 521600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 522600cc4afSopenharmony_ci } 523600cc4afSopenharmony_ci return CallService(&IInstalld::SetEncryptionPolicy, uid, bundleName, userId, keyId); 524600cc4afSopenharmony_ci} 525600cc4afSopenharmony_ci 526600cc4afSopenharmony_ciErrCode InstalldClient::DeleteEncryptionKeyId(const std::string &bundleName, const int32_t userId) 527600cc4afSopenharmony_ci{ 528600cc4afSopenharmony_ci if (bundleName.empty()) { 529600cc4afSopenharmony_ci APP_LOGE("bundleName is empty"); 530600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 531600cc4afSopenharmony_ci } 532600cc4afSopenharmony_ci return CallService(&IInstalld::DeleteEncryptionKeyId, bundleName, userId); 533600cc4afSopenharmony_ci} 534600cc4afSopenharmony_ci 535600cc4afSopenharmony_ciErrCode InstalldClient::RemoveExtensionDir(int32_t userId, const std::vector<std::string> &extensionBundleDirs) 536600cc4afSopenharmony_ci{ 537600cc4afSopenharmony_ci if (extensionBundleDirs.empty() || userId < 0) { 538600cc4afSopenharmony_ci APP_LOGI("extensionBundleDirs empty or userId invalid"); 539600cc4afSopenharmony_ci return ERR_OK; 540600cc4afSopenharmony_ci } 541600cc4afSopenharmony_ci return CallService(&IInstalld::RemoveExtensionDir, userId, extensionBundleDirs); 542600cc4afSopenharmony_ci} 543600cc4afSopenharmony_ci 544600cc4afSopenharmony_ciErrCode InstalldClient::IsExistExtensionDir(int32_t userId, const std::string &extensionBundleDir, bool &isExist) 545600cc4afSopenharmony_ci{ 546600cc4afSopenharmony_ci if (extensionBundleDir.empty() || userId < 0) { 547600cc4afSopenharmony_ci APP_LOGE("extensionBundleDir is empty or userId is invalid"); 548600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 549600cc4afSopenharmony_ci } 550600cc4afSopenharmony_ci return CallService(&IInstalld::IsExistExtensionDir, userId, extensionBundleDir, isExist); 551600cc4afSopenharmony_ci} 552600cc4afSopenharmony_ci 553600cc4afSopenharmony_ciErrCode InstalldClient::CreateExtensionDataDir(const CreateDirParam &createDirParam) 554600cc4afSopenharmony_ci{ 555600cc4afSopenharmony_ci if (createDirParam.bundleName.empty() || createDirParam.userId < 0 556600cc4afSopenharmony_ci || createDirParam.uid < 0 || createDirParam.gid < 0 || createDirParam.extensionDirs.empty()) { 557600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 558600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 559600cc4afSopenharmony_ci } 560600cc4afSopenharmony_ci 561600cc4afSopenharmony_ci return CallService(&IInstalld::CreateExtensionDataDir, createDirParam); 562600cc4afSopenharmony_ci} 563600cc4afSopenharmony_ci 564600cc4afSopenharmony_ciErrCode InstalldClient::GetExtensionSandboxTypeList(std::vector<std::string> &typeList) 565600cc4afSopenharmony_ci{ 566600cc4afSopenharmony_ci return CallService(&IInstalld::GetExtensionSandboxTypeList, typeList); 567600cc4afSopenharmony_ci} 568600cc4afSopenharmony_ci 569600cc4afSopenharmony_ciErrCode InstalldClient::AddUserDirDeleteDfx(int32_t userId) 570600cc4afSopenharmony_ci{ 571600cc4afSopenharmony_ci return CallService(&IInstalld::AddUserDirDeleteDfx, userId); 572600cc4afSopenharmony_ci} 573600cc4afSopenharmony_ci 574600cc4afSopenharmony_ciErrCode InstalldClient::MoveHapToCodeDir(const std::string &originPath, const std::string &targetPath) 575600cc4afSopenharmony_ci{ 576600cc4afSopenharmony_ci if (originPath.empty() || targetPath.empty()) { 577600cc4afSopenharmony_ci APP_LOGE("params are invalid"); 578600cc4afSopenharmony_ci return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; 579600cc4afSopenharmony_ci } 580600cc4afSopenharmony_ci 581600cc4afSopenharmony_ci return CallService(&IInstalld::MoveHapToCodeDir, originPath, targetPath); 582600cc4afSopenharmony_ci} 583600cc4afSopenharmony_ci} // namespace AppExecFwk 584600cc4afSopenharmony_ci} // namespace OHOS 585