• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALLD_SERVICE_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALLD_SERVICE_H
18 
19 #include <memory>
20 
21 #include "installd/installd_host_impl.h"
22 #include "ipc/installd_host.h"
23 #include "system_ability.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class InstalldService : public SystemAbility {
28 
29 DECLARE_SYSTEM_ABILITY(InstalldService);
30 
31 public:
32     InstalldService(int32_t saId, bool runOnCreate);
33     InstalldService();
34     virtual ~InstalldService();
35 
36     void OnStart() override;
37 
38     void OnStop() override;
39 
40     /**
41      * @brief Start the installd service.
42      * @return
43      */
44     void Start();
45     /**
46      * @brief Stop the installd service.
47      * @return
48      */
49     void Stop();
50     /**
51      * @brief Check whether if the installd service is ready.
52      * @return Returns true if the installd service is ready; returns false otherwise.
53      */
IsServiceReady()54     bool IsServiceReady() const
55     {
56         return isReady_;
57     }
58 
59 protected:
60     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
61 
62 private:
63     /**
64      * @brief Initialize the installd service context.
65      * @return Returns true if initialized successfully; returns false otherwise.
66      */
67     bool Init();
68     /**
69      * @brief Initialize to create a directory.
70      * @param path Indicates the directory path to create.
71      * @return Returns true if directory created successfully; returns false otherwise.
72      */
73     bool InitDir(const std::string &path);
74 
75 private:
76     bool isReady_ = false;
77     sptr<InstalldHostImpl> hostImpl_;
78 
79     DISALLOW_COPY_AND_MOVE(InstalldService);
80 };
81 }  // namespace AppExecFwk
82 }  // namespace OHOS
83 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALLD_SERVICE_H