• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 "inter_ipc_service.h"
17 #include "access_token.h"
18 #include "accesstoken_kit.h"
19 #include "common/sharing_log.h"
20 #include "configuration/include/config.h"
21 #include "context/context_manager.h"
22 #include "event/event_manager.h"
23 #include "hap_token_info.h"
24 #include "inter_ipc_service_death_listener.h"
25 #include "interaction/interaction.h"
26 #include "interaction/interaction_manager.h"
27 #include "interaction/interprocess/ipc_msg_adapter.h"
28 #include "interaction/scene/base_scene.h"
29 #include "ipc_skeleton.h"
30 #include "mediachannel/channel_manager.h"
31 #include "nativetoken_kit.h"
32 #include "scheduler/scheduler.h"
33 #include "token_setproc.h"
34 #include "system_ability_definition.h"
35 
36 namespace OHOS {
37 namespace Sharing {
38 
REGISTER_SYSTEM_ABILITY_BY_ID(InterIpcService,SHARING_SERVICE_TEMP_SA_ID,true)39 REGISTER_SYSTEM_ABILITY_BY_ID(InterIpcService, SHARING_SERVICE_TEMP_SA_ID, true)
40 
41 InterIpcService::InterIpcService(int32_t systemAbilityId, bool runOnCreate)
42     : SystemAbility(systemAbilityId, runOnCreate)
43 {
44     SHARING_LOGD("trace.");
45 }
46 
~InterIpcService()47 InterIpcService::~InterIpcService()
48 {
49     SHARING_LOGD("trace.");
50 }
51 
OnDump()52 void InterIpcService::OnDump()
53 {
54     SHARING_LOGD("trace.");
55 }
56 
OnStart()57 void InterIpcService::OnStart()
58 {
59     SHARING_LOGD("trace.");
60     if (Publish(this)) {
61         SHARING_LOGD("success.");
62         EventManager::GetInstance().Init();
63         EventManager::GetInstance().StartEventLoop();
64         Scheduler::GetInstance();
65         Config::GetInstance().Init();
66         InteractionManager::GetInstance().Init();
67         ContextManager::GetInstance().Init();
68         ChannelManager::GetInstance().Init();
69     } else {
70         SHARING_LOGD("failed.");
71     }
72 }
73 
OnStop()74 void InterIpcService::OnStop()
75 {
76     SHARING_LOGD("trace.");
77 }
78 
RecordProcessIdByKvStore()79 void InterIpcService::RecordProcessIdByKvStore()
80 {
81     SHARING_LOGD("trace.");
82     int32_t pid = getpid();
83     SHARING_LOGD("open KvStore.");
84     kvOperator_.OpenKvStore();
85 
86     nlohmann::json jsObj;
87     jsObj[VALID_PID] = std::to_string(pid);
88     jsObj[ENABLE_HARDWARE] = true;
89 
90     SharingValue::Ptr values = nullptr;
91     auto ret = Config::GetInstance().GetConfig("codec", "forceSWDecoder", "isEnable", values);
92     if (ret == CONFIGURE_ERROR_NONE) {
93         bool value;
94         values->GetValue<bool>(value);
95         jsObj[ENABLE_HARDWARE] = static_cast<bool>(!value);
96     }
97 
98     kvOperator_.PutValues(SHARING_INFOS, jsObj.dump());
99     SHARING_LOGD("kv put value, pid: %{public}d.", pid);
100 
101     kvOperator_.CloseKvStore();
102 }
103 
104 } // namespace Sharing
105 } // namespace OHOS