• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "query_erms_manager.h"
17 
18 #include "ability_record.h"
19 #include "hilog_tag_wrapper.h"
20 #include "hitrace_meter.h"
21 
22 namespace OHOS {
23 namespace AAFwk {
QueryERMSManager()24 QueryERMSManager::QueryERMSManager() {}
25 
~QueryERMSManager()26 QueryERMSManager::~QueryERMSManager() {}
27 
GetInstance()28 QueryERMSManager &QueryERMSManager::GetInstance()
29 {
30     static QueryERMSManager manager;
31     return manager;
32 }
33 
HandleOnQueryERMSSuccess(int32_t recordId,const std::string & appId,const std::string & startTime,const AtomicServiceStartupRule & rule)34 void QueryERMSManager::HandleOnQueryERMSSuccess(int32_t recordId, const std::string &appId,
35     const std::string &startTime, const AtomicServiceStartupRule &rule)
36 {
37     TAG_LOGI(AAFwkTag::QUERY_ERMS, "query ERMS succeeded");
38     QueryERMSObserverManager::GetInstance().OnQueryFinished(
39         recordId, appId, startTime, rule, ERR_OK);
40 }
41 
HandleOnQueryERMSFail(int32_t recordId,const std::string & appId,const std::string & startTime,const AtomicServiceStartupRule & rule,int resultCode)42 void QueryERMSManager::HandleOnQueryERMSFail(int32_t recordId, const std::string &appId, const std::string &startTime,
43     const AtomicServiceStartupRule &rule, int resultCode)
44 {
45     TAG_LOGI(AAFwkTag::QUERY_ERMS, "query ERMS failed,resultCode=%{public}d", resultCode);
46     QueryERMSObserverManager::GetInstance().OnQueryFinished(
47         recordId, appId, startTime, rule, resultCode);
48 }
49 
HandleQueryERMSResult(int32_t recordId,const std::string & appId,const std::string & startTime,const AtomicServiceStartupRule & rule,int32_t resultCode)50 void QueryERMSManager::HandleQueryERMSResult(int32_t recordId, const std::string &appId, const std::string &startTime,
51     const AtomicServiceStartupRule &rule, int32_t resultCode)
52 {
53     if (resultCode == ERR_OK) {
54         HandleOnQueryERMSSuccess(recordId, appId, startTime, rule);
55         return;
56     }
57     HandleOnQueryERMSFail(recordId, appId, startTime, rule, resultCode);
58 }
59 
OnQueryFinished(int32_t recordId,const std::string & appId,const std::string & startTime,const AtomicServiceStartupRule & rule,int32_t resultCode)60 void QueryERMSManager::OnQueryFinished(int32_t recordId, const std::string &appId, const std::string &startTime,
61     const AtomicServiceStartupRule &rule, int32_t resultCode)
62 {
63     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
64     TAG_LOGI(AAFwkTag::QUERY_ERMS, "resultCode: %{public}d", resultCode);
65 
66     HandleQueryERMSResult(recordId, appId, startTime, rule, resultCode);
67 }
68 
AddQueryERMSObserver(sptr<IRemoteObject> callerToken,sptr<AbilityRuntime::IQueryERMSObserver> observer)69 int QueryERMSManager::AddQueryERMSObserver(sptr<IRemoteObject> callerToken,
70     sptr<AbilityRuntime::IQueryERMSObserver> observer)
71 {
72     TAG_LOGI(AAFwkTag::QUERY_ERMS, "called");
73     if (callerToken == nullptr) {
74         TAG_LOGE(AAFwkTag::QUERY_ERMS, "callerToken is null");
75         return ERR_INVALID_VALUE;
76     }
77     auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
78     if (abilityRecord == nullptr) {
79         TAG_LOGE(AAFwkTag::QUERY_ERMS, "ability record is null");
80         return ERR_INVALID_VALUE;
81     }
82     return QueryERMSObserverManager::GetInstance().AddObserver(abilityRecord->GetRecordId(),
83         observer);
84 }
85 }  // namespace AAFwk
86 }  // namespace OHOS
87