1 /*
2  * Copyright (c) 2021 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 "test_audio_ability.h"
17 
18 #include "hilog/log.h"
19 #include "iremote_object.h"
20 #include "system_ability_definition.h"
21 
22 using namespace OHOS;
23 using namespace OHOS::HiviewDFX;
24 
25 REGISTER_SYSTEM_ABILITY_BY_ID(TestAudioAbility, 1499, true);
26 
TestAudioAbility(int32_t saId,bool runOnCreate)27 TestAudioAbility::TestAudioAbility(int32_t saId, bool runOnCreate) : SystemAbility(saId, runOnCreate)
28 {
29     HiLog::Info(label_, "%{public}s called", __func__);
30 }
31 
~TestAudioAbility()32 TestAudioAbility::~TestAudioAbility()
33 {
34     HiLog::Info(label_, "%{public}s called", __func__);
35 }
36 
GetBaseSystemAbility(int32_t systemAbilityId)37 sptr<IRemoteObject> TestAudioAbility::GetBaseSystemAbility(int32_t systemAbilityId)
38 {
39     sptr<IRemoteObject> object = GetSystemAbility(systemAbilityId);
40     return object;
41 }
42 
AddVolume(int volume)43 int TestAudioAbility::AddVolume(int volume)
44 {
45     HiLog::Info(label_, "TestAudioAbility:: %{public}s called, volume = %{public}d", __func__, volume);
46     return (volume + 1);
47 }
48 
ReduceVolume(int volume)49 int32_t TestAudioAbility::ReduceVolume(int volume)
50 {
51     HiLog::Info(label_, "TestAudioAbility:: %{public}s called, volume = %{public}d", __func__, volume);
52     return (volume - 1);
53 }
54 
TestRpcInt32(int32_t value)55 int32_t TestAudioAbility::TestRpcInt32(int32_t value)
56 {
57     return value;
58 }
59 
TestRpcUInt32(uint32_t value)60 uint32_t TestAudioAbility::TestRpcUInt32(uint32_t value)
61 {
62     return value;
63 }
64 
TestRpcInt64(int64_t value)65 int64_t TestAudioAbility::TestRpcInt64(int64_t value)
66 {
67     return value;
68 }
69 
TestRpcUInt64(uint64_t value)70 uint64_t TestAudioAbility::TestRpcUInt64(uint64_t value)
71 {
72     return value;
73 }
74 
TestRpcFloat(float value)75 float TestAudioAbility::TestRpcFloat(float value)
76 {
77     return value;
78 }
79 
TestRpcDouble(double value)80 double TestAudioAbility::TestRpcDouble(double value)
81 {
82     return value;
83 }
84 
TestRpcString16(const std::u16string & name)85 const std::u16string TestAudioAbility::TestRpcString16(const std::u16string& name)
86 {
87     return name;
88 }
89 
OnStart()90 void TestAudioAbility::OnStart()
91 {
92     HiLog::Info(label_, "%{public}s called", __func__);
93     bool res = Publish(this);
94     if (res == false) {
95         HiLog::Error(label_, "%{public}s:fail to onstart res = %{public}d", __func__, res);
96     }
97     AddSystemAbilityListener(DISTRIBUTED_SCHED_SA_ID);
98     AddSystemAbilityListener(SOFTBUS_SERVER_SA_ID);
99     AddSystemAbilityListener(RES_SCHED_SYS_ABILITY_ID);
100     AddSystemAbilityListener(BACKGROUND_TASK_MANAGER_SERVICE_ID);
101     return;
102 }
103 
OnStop()104 void TestAudioAbility::OnStop()
105 {
106 }
107 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)108 void TestAudioAbility::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
109 {
110     HiLog::Info(label_, "OnAddSystemAbility systemAbilityId:%{public}d added!", systemAbilityId);
111 }
112 
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)113 void TestAudioAbility::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
114 {
115     HiLog::Info(label_, "OnRemoveSystemAbility systemAbilityId:%{public}d removed!", systemAbilityId);
116 }