1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "sys_installer_server.h"
17
18 #include "iservice_registry.h"
19 #include "log/log.h"
20 #include "securec.h"
21 #include "system_ability_definition.h"
22 #include "utils.h"
23
24 namespace OHOS {
25 namespace SysInstaller {
26 REGISTER_SYSTEM_ABILITY_BY_ID(SysInstallerServer, SYS_INSTALLER_DISTRIBUTED_SERVICE_ID, false)
27
28 using namespace Updater;
29
SysInstallerServer(int32_t systemAbilityId,bool runOnCreate)30 SysInstallerServer::SysInstallerServer(int32_t systemAbilityId, bool runOnCreate)
31 : SystemAbility(systemAbilityId, runOnCreate)
32 {
33 }
34
~SysInstallerServer()35 SysInstallerServer::~SysInstallerServer()
36 {
37 }
38
SysInstallerInit()39 int32_t SysInstallerServer::SysInstallerInit()
40 {
41 LOG(INFO) << "SysInstallerInit";
42 if (!logInit_) {
43 (void)Utils::MkdirRecursive(SYS_LOG_DIR, 0777); // 0777 : rwxrwxrwx
44 InitUpdaterLogger("SysInstaller", SYS_LOG_FILE, SYS_STAGE_FILE, SYS_ERROR_FILE);
45 logInit_ = true;
46 }
47
48 InstallerManager::GetInstance().SysInstallerInit();
49 return 0;
50 }
51
StartUpdatePackageZip(const std::string & pkgPath)52 int32_t SysInstallerServer::StartUpdatePackageZip(const std::string &pkgPath)
53 {
54 LOG(INFO) << "StartUpdatePackageZip";
55 return InstallerManager::GetInstance().StartUpdatePackageZip(pkgPath);
56 }
57
SetUpdateCallback(const sptr<ISysInstallerCallback> & updateCallback)58 int32_t SysInstallerServer::SetUpdateCallback(const sptr<ISysInstallerCallback> &updateCallback)
59 {
60 LOG(INFO) << "SetUpdateCallback";
61 return InstallerManager::GetInstance().SetUpdateCallback(updateCallback);
62 }
63
GetUpdateStatus()64 int32_t SysInstallerServer::GetUpdateStatus()
65 {
66 LOG(INFO) << "GetUpdateStatus";
67 return InstallerManager::GetInstance().GetUpdateStatus();
68 }
69
StartUpdateParaZip(const std::string & pkgPath,const std::string & location,const std::string & cfgDir)70 int32_t SysInstallerServer::StartUpdateParaZip(const std::string &pkgPath,
71 const std::string &location, const std::string &cfgDir)
72 {
73 LOG(INFO) << "StartUpdateParaZip";
74 return InstallerManager::GetInstance().StartUpdateParaZip(pkgPath, location, cfgDir);
75 }
76
StartDeleteParaZip(const std::string & location,const std::string & cfgDir)77 int32_t SysInstallerServer::StartDeleteParaZip(const std::string &location, const std::string &cfgDir)
78 {
79 LOG(INFO) << "StartDeleteParaZip";
80 return InstallerManager::GetInstance().StartDeleteParaZip(location, cfgDir);
81 }
82
OnStart()83 void SysInstallerServer::OnStart()
84 {
85 LOG(INFO) << "OnStart";
86 bool res = Publish(this);
87 if (!res) {
88 LOG(ERROR) << "OnStart failed";
89 }
90
91 return;
92 }
93
OnStop()94 void SysInstallerServer::OnStop()
95 {
96 LOG(INFO) << "OnStop";
97 }
98 } // namespace SysInstaller
99 } // namespace OHOS
100