• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "uri_permission_manager_service.h"
17 
18 #include "hilog_wrapper.h"
19 #include "if_system_ability_manager.h"
20 #include "ipc_skeleton.h"
21 #include "iservice_registry.h"
22 #include "system_ability_definition.h"
23 
24 namespace OHOS {
25 namespace AAFwk {
26 const bool REGISTER_RESULT =
27     SystemAbility::MakeAndRegisterAbility(DelayedSingleton<UriPermissionManagerService>::GetInstance().get());
28 
UriPermissionManagerService()29 UriPermissionManagerService::UriPermissionManagerService() : SystemAbility(URI_PERMISSION_MGR_SERVICE_ID, true) {}
30 
~UriPermissionManagerService()31 UriPermissionManagerService::~UriPermissionManagerService()
32 {
33     if (impl_ != nullptr) {
34         impl_ = nullptr;
35     }
36 }
37 
OnStart()38 void UriPermissionManagerService::OnStart()
39 {
40     HILOG_INFO("UriPermissionManagerService start is triggered.");
41     if (!Init()) {
42         HILOG_ERROR("init failed.");
43         return;
44     }
45 
46     if (!registerToService_) {
47         auto systemAabilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
48         if (!systemAabilityMgr || systemAabilityMgr->AddSystemAbility(URI_PERMISSION_MGR_SERVICE_ID, impl_) != 0) {
49             HILOG_ERROR("fail to register to system ability manager");
50             return;
51         }
52         HILOG_INFO("register to system ability manager success");
53         registerToService_ = true;
54     }
55 }
56 
OnStop()57 void UriPermissionManagerService::OnStop()
58 {
59     HILOG_INFO("OnStop is called.");
60     SelfClean();
61 }
62 
IsServiceReady() const63 bool UriPermissionManagerService::IsServiceReady() const
64 {
65     return ready_;
66 }
67 
Init()68 bool UriPermissionManagerService::Init()
69 {
70     if (ready_) {
71         HILOG_WARN("init more than one time.");
72         return true;
73     }
74 
75     if (impl_ == nullptr) {
76         impl_ = new UriPermissionManagerStubImpl();
77         impl_->Init();
78     }
79     ready_ = true;
80     return true;
81 }
82 
SelfClean()83 void UriPermissionManagerService::SelfClean()
84 {
85     if (ready_) {
86         ready_ = false;
87         if (registerToService_) {
88             registerToService_ = false;
89         }
90     }
91 }
92 }  // namespace AAFwk
93 }  // namespace OHOS
94