1 /*
2 * Copyright (c) 2021-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 <cstdio>
17 #include <cstdlib>
18 #include <cstring>
19 #include <iostream>
20 #include <securec.h>
21 #include <unistd.h>
22
23 #include "audio_errors.h"
24 #include "audio_system_manager.h"
25 #include "audio_log.h"
26
27 using namespace std;
28 using namespace OHOS;
29 using namespace OHOS::AudioStandard;
30
31 namespace AudioPolicyTest {
32 const int FIRST_ARG = 1;
33 const int SECOND_ARG = 2;
34 const int THIRD_ARG = 3;
35 const int FOURTH_ARG = 4;
36 const int FIFTH_ARG = 5;
37 const int SIXTH_ARG = 6;
38 const int SEVENTH_ARG = 7;
39 const int EIGHTH_ARG = 8;
40 const int NINTH_ARG = 9;
41 const int TENTH_ARG = 10;
42 const int ELEVENTH_ARG = 11;
43 const int TWELFTH_ARG = 12;
44 const int OPT_ARG_BASE = 10;
45 const int OPT_SHORT_LEN = 3;
46 const int OPT_GET_VOL_FACTOR = 1;
47 const int OPT_GET_SS_VOL = 2;
48 }
49
PrintUsage(void)50 static void PrintUsage(void)
51 {
52 cout << "NAME" << endl << endl;
53 cout << "\taudio_policy_test - Audio Policy Test " << endl << endl;
54 cout << "SYNOPSIS" << endl << endl;
55 cout << "\t#include <audio_system_manager.h>" << endl << endl;
56 cout << "\t./audio_policy_test [OPTIONS]..." << endl << endl;
57 cout << "DESCRIPTION" << endl << endl;
58 cout << "\tControls audio volume, audio routing, audio mute" << endl << endl;
59 cout << "-V\n\tSets Volume for streams, -S to setStream" << endl << endl;
60 cout << "-v\n\tGets Volume for streams, -S to setStream" << endl << endl;
61 cout << "-S\n\tSet stream type" << endl << endl;
62 cout << "\tSupported Streams are" << endl << endl;
63 cout << "\t4\tMUSIC" << endl << endl;
64 cout << "\t3\tRING" << endl << endl;
65 cout << "-D\n\tSets Device Active" << endl << endl;
66 cout << "\tSupported Devices are" << endl << endl;
67 cout << "\t2\tSPEAKER" << endl << endl;
68 cout << "\t7\tBLUETOOTH_SCO" << endl << endl;
69 cout << "-d\n\tGets Device Active" << endl << endl;
70 cout << "-M\n\tSets Mute for streams, -S to setStream" << endl << endl;
71 cout << "-m\n\tGets Mute for streams, -S to setStream" << endl << endl;
72 cout << "-U\n\t Mutes the Microphone" << endl << endl;
73 cout << "-u\n\t Checks if the Microphone is muted " << endl << endl;
74 cout << "-R\n\tSets RingerMode" << endl << endl;
75 cout << "-r\n\tGets RingerMode status" << endl << endl;
76 cout << "-C\n\tSets AudioScene" << endl << endl;
77 cout << "-c\n\tGets AudioScene status" << endl << endl;
78 cout << "-N\n\tSet the discount volume factor" << endl << endl;
79 cout << "-n\n\tGet the discount volume factor or Get single stream volume" << endl << endl;
80 cout << "-s\n\tGet Stream Status" << endl << endl;
81 cout << "AUTHOR" << endl << endl;
82 cout << "\tWritten by Sajeesh Sidharthan and Anurup M" << endl << endl;
83 }
84
ShowAudioDeviceDescriptorsVector(std::vector<sptr<AudioDeviceDescriptor>> & audioDeviceDescriptorsVector)85 static void ShowAudioDeviceDescriptorsVector(std::vector<sptr<AudioDeviceDescriptor>> &audioDeviceDescriptorsVector)
86 {
87 int vectorLen = audioDeviceDescriptorsVector.size();
88 for (int i = 0; i < vectorLen; i ++) {
89 cout << "------------show Audio Device Descriptors Vector------------" << endl;
90 cout << "deviceRole: " << audioDeviceDescriptorsVector[i]->deviceRole_ << endl;
91 cout << "deviceType: " << audioDeviceDescriptorsVector[i]->deviceType_ << endl;
92 cout << "interruptGroupId: " << audioDeviceDescriptorsVector[i]->interruptGroupId_ << endl;
93 cout << "volumeGroupId: " << audioDeviceDescriptorsVector[i]->volumeGroupId_ << endl;
94 cout << "networkId: " << audioDeviceDescriptorsVector[i]->networkId_ << endl;
95 }
96 }
97
ShowAudioRendererFilter(sptr<AudioRendererFilter> audioRendererFilter)98 static void ShowAudioRendererFilter(sptr<AudioRendererFilter> audioRendererFilter)
99 {
100 cout << "------------show Audio Renderer Filter------------" << endl;
101 cout << "uid: " << audioRendererFilter->uid << endl;
102 cout << "contentType: " << audioRendererFilter->rendererInfo.contentType << endl;
103 cout << "streamUsage: " << audioRendererFilter->rendererInfo.streamUsage << endl;
104 cout << "rendererFlags: " << audioRendererFilter->rendererInfo.rendererFlags << endl;
105 cout << "streamId: " << audioRendererFilter->streamId << endl;
106 }
107
HandleGetDevices(int argc,char * argv[],char option)108 static void HandleGetDevices(int argc, char *argv[], char option)
109 {
110 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
111 if ((option != 'g' && option != 'G') || argc != AudioPolicyTest::THIRD_ARG) {
112 cout << "GetDevices invalid argv["<< argc <<"] "<< endl;
113 }
114 cout << "GetDevices() flag: " << argv[AudioPolicyTest::SECOND_ARG] << endl;
115 int32_t intValue = atoi(argv[AudioPolicyTest::SECOND_ARG]);
116 DeviceFlag deviceFlag = static_cast<DeviceFlag>(intValue);
117 std::vector<sptr<AudioDeviceDescriptor>> audioDeviceDescriptorsVector;
118 audioDeviceDescriptorsVector = audioSystemMgr->GetDevices(deviceFlag);
119 cout << "GetDevices(Output Devices) Result: " << endl;
120 ShowAudioDeviceDescriptorsVector(audioDeviceDescriptorsVector);
121 }
122
CallSelectOutputDevice(char option,std::vector<sptr<AudioDeviceDescriptor>> & audioDeviceDescriptorsVector,sptr<AudioRendererFilter> audioRendererFilter)123 static void CallSelectOutputDevice(char option, std::vector<sptr<AudioDeviceDescriptor>> &audioDeviceDescriptorsVector,
124 sptr<AudioRendererFilter> audioRendererFilter)
125 {
126 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
127 if (option == 'o') {
128 int result = audioSystemMgr->SelectOutputDevice(audioDeviceDescriptorsVector);
129 cout << "SelectOutputDevice Result: " << result << endl;
130 } else {
131 int result = audioSystemMgr->SelectOutputDevice(audioRendererFilter, audioDeviceDescriptorsVector);
132 cout << "SelectOutputDevice by filter Result: " << result << endl;
133 }
134 }
135
CreateAudioDeviceDescriptorVector(char * argv[],std::vector<sptr<AudioDeviceDescriptor>> & audioDeviceDescriptorsVector)136 static void CreateAudioDeviceDescriptorVector(char *argv[],
137 std::vector<sptr<AudioDeviceDescriptor>> &audioDeviceDescriptorsVector)
138 {
139 sptr<AudioDeviceDescriptor> audioDeviceDescriptor = new(std::nothrow) AudioDeviceDescriptor();
140 int32_t intValue = atoi(argv[AudioPolicyTest::SECOND_ARG]);
141 audioDeviceDescriptor->deviceRole_ = static_cast<DeviceRole>(intValue);
142 intValue = atoi(argv[AudioPolicyTest::THIRD_ARG]);
143 audioDeviceDescriptor->deviceType_ = static_cast<DeviceType>(intValue);
144 intValue = atoi(argv[AudioPolicyTest::FOURTH_ARG]);
145 audioDeviceDescriptor->interruptGroupId_ = intValue;
146 intValue = atoi(argv[AudioPolicyTest::FIFTH_ARG]);
147 audioDeviceDescriptor->volumeGroupId_ = intValue;
148 audioDeviceDescriptor->networkId_ = std::string(argv[AudioPolicyTest::SIXTH_ARG]);
149 audioDeviceDescriptorsVector.push_back(audioDeviceDescriptor);
150 ShowAudioDeviceDescriptorsVector(audioDeviceDescriptorsVector);
151 }
152
HandleSelectOutputDevice(int argc,char * argv[],char opt)153 static void HandleSelectOutputDevice(int argc, char* argv[], char opt)
154 {
155 if (argc == AudioPolicyTest::SEVENTH_ARG) {
156 std::vector<sptr<AudioDeviceDescriptor>> audioDeviceDescriptorsVector;
157 CreateAudioDeviceDescriptorVector(argv, audioDeviceDescriptorsVector);
158
159 CallSelectOutputDevice(opt, audioDeviceDescriptorsVector, nullptr);
160 } else if (argc == AudioPolicyTest::TWELFTH_ARG) {
161 std::vector<sptr<AudioDeviceDescriptor>> audioDeviceDescriptorsVector;
162 CreateAudioDeviceDescriptorVector(argv, audioDeviceDescriptorsVector);
163
164 sptr<AudioRendererFilter> audioRendererFilter = new(std::nothrow) AudioRendererFilter();
165 int32_t intValue = atoi(argv[AudioPolicyTest::SEVENTH_ARG]);
166 audioRendererFilter->uid = static_cast<DeviceRole>(intValue);
167 intValue = atoi(argv[AudioPolicyTest::EIGHTH_ARG]);
168 audioRendererFilter->rendererInfo.contentType = static_cast<ContentType>(intValue);
169 intValue = atoi(argv[AudioPolicyTest::NINTH_ARG]);
170 audioRendererFilter->rendererInfo.streamUsage = static_cast<StreamUsage>(intValue);
171 intValue = atoi(argv[AudioPolicyTest::TENTH_ARG]);
172 audioRendererFilter->rendererInfo.rendererFlags = intValue;
173 intValue = atoi(argv[AudioPolicyTest::ELEVENTH_ARG]);
174 audioRendererFilter->streamId = intValue;
175 ShowAudioRendererFilter(audioRendererFilter);
176 CallSelectOutputDevice(opt, audioDeviceDescriptorsVector, audioRendererFilter);
177 } else {
178 cout << "------------Please input right arg Num------------" << endl;
179 cout << "The arg order: " << endl;
180 cout << "audioDevice(deviceRole, deviceType, networkId, interruptGroupId, volumeGroupId)" << endl;
181 cout << "audioRendererFilter(uid,contentType,streamUsage,rendererFlags,streamId)" << endl;
182 }
183 }
184
CallSelectInputDevice(char option,std::vector<sptr<AudioDeviceDescriptor>> & audioDeviceDescriptorsVector,sptr<AudioCapturerFilter> audioCapturerFilter)185 static void CallSelectInputDevice(char option, std::vector<sptr<AudioDeviceDescriptor>> &audioDeviceDescriptorsVector,
186 sptr<AudioCapturerFilter> audioCapturerFilter)
187 {
188 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
189 if (option == 'i') {
190 int result = audioSystemMgr->SelectInputDevice(audioDeviceDescriptorsVector);
191 cout << "SelectInputDevice Result: " << result << endl;
192 } else {
193 int result = audioSystemMgr->SelectInputDevice(audioCapturerFilter, audioDeviceDescriptorsVector);
194 cout << "SelectInputDevice by filter Result: " << result << endl;
195 }
196 }
197
198
HandleSelectInputDevice(int argc,char * argv[],char opt)199 static void HandleSelectInputDevice(int argc, char* argv[], char opt)
200 {
201 if (argc == AudioPolicyTest::SEVENTH_ARG) {
202 std::vector<sptr<AudioDeviceDescriptor>> audioDeviceDescriptorsVector;
203 CreateAudioDeviceDescriptorVector(argv, audioDeviceDescriptorsVector);
204
205 CallSelectInputDevice(opt, audioDeviceDescriptorsVector, nullptr);
206 } else if (argc == AudioPolicyTest::EIGHTH_ARG) {
207 std::vector<sptr<AudioDeviceDescriptor>> audioDeviceDescriptorsVector;
208 CreateAudioDeviceDescriptorVector(argv, audioDeviceDescriptorsVector);
209
210 sptr<AudioCapturerFilter> audioCapturerFilter = new(std::nothrow) AudioCapturerFilter();
211 int32_t intValue = atoi(argv[AudioPolicyTest::SEVENTH_ARG]);
212 audioCapturerFilter->uid = intValue;
213 cout << "------------show Audio Capturer Filter------------" << endl;
214 cout << "uid: " << audioCapturerFilter->uid << endl;
215 CallSelectInputDevice(opt, audioDeviceDescriptorsVector, audioCapturerFilter);
216 } else {
217 cout << "------------Please input right arg Num------------" << endl;
218 cout << "The arg order: " << endl;
219 cout << "audioDevice(deviceRole, deviceType, networkId, interruptGroupId, volumeGroupId)" << endl;
220 cout << "audioCapturerFilter(uid)" << endl;
221 }
222 }
223
HandleVolume(int argc,char * argv[],int streamType,char option)224 static void HandleVolume(int argc, char* argv[], int streamType, char option)
225 {
226 AudioSystemManager* audioSystemMgr = AudioSystemManager::GetInstance();
227 std::string networkId = LOCAL_NETWORK_ID;
228
229 if ((option != 'v' && option != 'V') || argc > AudioPolicyTest::FOURTH_ARG) {
230 cout << "HandVolume invalid argv[" << argc << "] " << endl;
231 }
232 if (option == 'v' && argc == AudioPolicyTest::THIRD_ARG) {
233 networkId = argv[AudioPolicyTest::SECOND_ARG];
234 cout << "handle volume networkId: " << networkId << endl;
235 std::vector<sptr<VolumeGroupInfo>> groups = audioSystemMgr->GetVolumeGroups(networkId);
236 if (groups.size() > 0) {
237 int32_t groupId = groups[0]->volumeGroupId_;
238 std::shared_ptr<AudioGroupManager> groupManager = audioSystemMgr->GetGroupManager(groupId);
239 float volume = groupManager->GetVolume(static_cast<AudioVolumeType>(streamType));
240 cout << "Get Volume : " << volume << endl;
241 }
242 } else if (option == 'V' && argc == AudioPolicyTest::FOURTH_ARG) {
243 networkId = argv[AudioPolicyTest::THIRD_ARG];
244 cout << "handle volume networkId: " << networkId << endl;
245 std::vector<sptr<VolumeGroupInfo>> groups = audioSystemMgr->GetVolumeGroups(networkId);
246 if (groups.size() > 0) {
247 int32_t groupId = groups[0]->volumeGroupId_;
248 std::shared_ptr<AudioGroupManager> groupManager = audioSystemMgr->GetGroupManager(groupId);
249
250 float volume = strtof(optarg, nullptr);
251 cout << "Set Volume : " << volume << endl;
252 int32_t result = groupManager->SetVolume(static_cast<AudioVolumeType>(streamType), volume);
253 cout << "Set Volume Result: " << result << endl;
254 }
255 } else {
256 cout << "wrong parms " << endl;
257 }
258 }
259
HandleMute(int streamType,char option)260 static void HandleMute(int streamType, char option)
261 {
262 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
263 if (option == 'm') {
264 bool muteStatus = audioSystemMgr->IsStreamMute(static_cast<AudioVolumeType>(streamType));
265 cout << "Get Mute : " << muteStatus << endl;
266 } else {
267 int mute = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE);
268 cout << "Set Mute : " << mute << endl;
269 int32_t result = audioSystemMgr->SetMute(static_cast<AudioVolumeType>(streamType),
270 (mute) ? true : false);
271 cout << "Set Mute Result: " << result << endl;
272 }
273 }
274
HandleMicMute(char option)275 static void HandleMicMute(char option)
276 {
277 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
278 if (option == 'u') {
279 bool muteStatus = audioSystemMgr->IsMicrophoneMute();
280 cout << "Is Mic Mute : " << muteStatus << endl;
281 } else {
282 int mute = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE);
283 cout << "Set Mic Mute : " << mute << endl;
284 int32_t result = audioSystemMgr->SetMicrophoneMute((mute) ? true : false);
285 cout << "Set Mic Mute Result: " << result << endl;
286 }
287 }
288
SetStreamType(int & streamType)289 static void SetStreamType(int &streamType)
290 {
291 streamType = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE);
292 cout << "Set Stream : " << streamType << endl;
293 }
294
IsStreamActive()295 static void IsStreamActive()
296 {
297 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
298 int streamType = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE);
299 cout << "Stream Active: " << audioSystemMgr->IsStreamActive(
300 static_cast<AudioVolumeType>(streamType)) << endl;
301 }
302
SetDeviceActive(int argc,char * argv[])303 static void SetDeviceActive(int argc, char *argv[])
304 {
305 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
306 int active = -1;
307 int device = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE);
308 cout << "Set Device : " << device << endl;
309
310 if (optind < argc && *argv[optind] != '-') {
311 active = strtol(argv[optind], nullptr, AudioPolicyTest::OPT_ARG_BASE);
312 optind++;
313 }
314 cout << "Active : " << active << endl << endl;
315
316 int32_t result = audioSystemMgr->SetDeviceActive(ActiveDeviceType(device),
317 (active) ? true : false);
318 cout << "Set DeviceActive Result: " << result << endl;
319 }
320
IsDeviceActive()321 static void IsDeviceActive()
322 {
323 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
324 int device = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE);
325 bool devActiveStatus = audioSystemMgr->IsDeviceActive(ActiveDeviceType(device));
326 cout << "GetDevice Active : " << devActiveStatus << endl;
327 }
328
SetAudioParamter(int argc,char * argv[])329 static void SetAudioParamter(int argc, char* argv[])
330 {
331 std::string key = "";
332 std::string value = "";
333 if (argc == AudioPolicyTest::FOURTH_ARG) {
334 key = argv[AudioPolicyTest::SECOND_ARG];
335 value = argv[AudioPolicyTest::THIRD_ARG];
336 AudioSystemManager* audioSystemMgr = AudioSystemManager::GetInstance();
337 audioSystemMgr->SetAudioParameter(key, value);
338 cout << "SetAudioParameter for key " << key << "; value: " << value << endl;
339 }
340 }
341
GetAudioParamter(int argc,char * argv[])342 static void GetAudioParamter(int argc, char* argv[])
343 {
344 std::string key = "";
345 if (argc == AudioPolicyTest::THIRD_ARG) {
346 key = argv[AudioPolicyTest::SECOND_ARG];
347 AudioSystemManager* audioSystemMgr = AudioSystemManager::GetInstance();
348 std::string value = audioSystemMgr->GetAudioParameter(key);
349 cout << "GetAudioParameter for key " << key << "; result: " << value << endl;
350 }
351 }
352
HandleRingerMode(char option)353 static void HandleRingerMode(char option)
354 {
355 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
356 if (option == 'r') {
357 int ringMode = static_cast<int32_t>(audioSystemMgr->GetRingerMode());
358 cout << "Get Ringer Mode : " << ringMode << endl;
359 } else {
360 int ringMode = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE);
361 cout << "Set Ringer Mode : " << ringMode << endl;
362 audioSystemMgr->SetRingerMode(static_cast<AudioRingerMode>(ringMode));
363 }
364 }
365
HandleAudioScene(char option)366 static void HandleAudioScene(char option)
367 {
368 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
369 if (option == 'c') {
370 int scene = static_cast<int32_t>(audioSystemMgr->GetAudioScene());
371 cout << "Get Audio Scene : " << scene << endl;
372 } else {
373 int scene = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE);
374 cout << "Set Audio Scene : " << scene << endl;
375 audioSystemMgr->SetAudioScene(static_cast<AudioScene>(scene));
376 }
377 }
378
NoValueError()379 static void NoValueError()
380 {
381 char option[AudioPolicyTest::OPT_SHORT_LEN];
382 cout << "option ";
383 int len = snprintf_s(option, sizeof(option), sizeof(option) - 1, "-%c", optopt);
384 if (len <= 0) {
385 cout << "NoValueError: snprintf_s error : buffer allocation fails";
386 return;
387 }
388
389 cout << option << " needs a value" << endl << endl;
390 PrintUsage();
391 }
392
UnknownOptionError()393 static void UnknownOptionError()
394 {
395 char option[AudioPolicyTest::OPT_SHORT_LEN];
396 int len = snprintf_s(option, sizeof(option), sizeof(option) - 1, "-%c", optopt);
397 if (len <= 0) {
398 cout << "unknown option: snprintf_s error : buffer allocation fails";
399 return;
400 }
401 cout << "unknown option: " << option << endl;
402 PrintUsage();
403 }
404
HandleUpdateStreamState(int type,char * seg1)405 static void HandleUpdateStreamState(int type, char *seg1)
406 {
407 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
408 cout << "HandleUpdateStreamState : Runing " << seg1 << endl;
409
410 const int32_t uid = atoi(seg1);
411 cout << "HandleUpdateStreamState : uid : " << uid << endl;
412 if (uid == 0) {
413 return;
414 }
415
416 StreamSetState sate = StreamSetState::STREAM_PAUSE;
417 AudioStreamType stype = AudioStreamType::STREAM_MEDIA;
418 int32_t result = 0;
419 if (type == 0) {
420 cout << "type :: Stream_Pause :: " << type << endl;
421 } else {
422 sate = StreamSetState::STREAM_RESUME;
423 cout << "type :: Stream_Resume :: " << type << endl;
424 }
425 result = audioSystemMgr->UpdateStreamState(uid, sate, stype);
426 cout << "result : " << result << endl;
427 }
428
HandleSingleStreamVolumeOption(int argc,char * argv[],char opt)429 static void HandleSingleStreamVolumeOption(int argc, char* argv[], char opt)
430 {
431 if (argc != AudioPolicyTest::FOURTH_ARG) {
432 cout << "Incorrect number of test commands." << endl;
433 return;
434 }
435
436 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
437 int32_t streamId = atoi(argv[AudioPolicyTest::SECOND_ARG]);
438 if (opt == 'N') {
439 float volume = atof(argv[AudioPolicyTest::THIRD_ARG]);
440 if (volume < 0 || volume > 1.0f) {
441 cout << "volume out of range." << endl;
442 return;
443 }
444 audioSystemMgr->SetLowPowerVolume(streamId, volume);
445 cout << "Set low power volume :" << volume << endl;
446 } else {
447 int32_t opt_flag = atoi(argv[AudioPolicyTest::THIRD_ARG]);
448 if (opt_flag == AudioPolicyTest::OPT_GET_VOL_FACTOR) {
449 float volume = audioSystemMgr->GetLowPowerVolume(streamId);
450 cout << "Get discounted volume factor: " << volume << endl;
451 } else if (opt_flag == AudioPolicyTest::OPT_GET_SS_VOL) {
452 float volume = audioSystemMgr->GetSingleStreamVolume(streamId);
453 cout << "Get single stream volume: " << volume << endl;
454 } else {
455 cout << "invalid operation." << endl;
456 }
457 }
458 }
459
HandleGetVolumeGroups(int argc,char * argv[])460 static void HandleGetVolumeGroups(int argc, char* argv[])
461 {
462 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
463 if (argc == AudioPolicyTest::THIRD_ARG) {
464 std::string networkId = argv[AudioPolicyTest::SECOND_ARG];
465 cout << "networkId: "<< networkId << endl;
466 std::vector<sptr<VolumeGroupInfo>> volumeGroups = audioSystemMgr->GetVolumeGroups(networkId);
467 for (auto iter : volumeGroups) {
468 cout << "===============id:" << iter->volumeGroupId_ << "=================" << endl;
469 cout << "name: " << iter->groupName_ << endl;
470 cout << "networkId: " << iter->networkId_ << endl;
471 cout << "connectType: " << iter->connectType_ << endl;
472 cout << "mappingId: " << iter->mappingId_ << endl;
473 }
474 }
475 }
main(int argc,char * argv[])476 int main(int argc, char* argv[])
477 {
478 int opt = 0;
479 if (((argc >= AudioPolicyTest::SECOND_ARG) && !strcmp(argv[AudioPolicyTest::FIRST_ARG], "--help")) ||
480 (argc == AudioPolicyTest::FIRST_ARG)) {
481 PrintUsage();
482 return ERR_INVALID_PARAM;
483 }
484
485 int streamType = static_cast<int32_t>(AudioVolumeType::STREAM_MUSIC);
486 while ((opt = getopt(argc, argv, ":V:U:S:D:M:R:C:X:Z:d:s:T:vmrucOoIiGgNntp")) != -1) {
487 switch (opt) {
488 case 'G':
489 case 'g':
490 HandleGetDevices(argc, argv, opt);
491 break;
492 case 'O':
493 case 'o':
494 HandleSelectOutputDevice(argc, argv, opt);
495 break;
496 case 'I':
497 case 'i':
498 HandleSelectInputDevice(argc, argv, opt);
499 break;
500 case 'V':
501 case 'v':
502 HandleVolume(argc, argv, streamType, opt);
503 break;
504 case 'M':
505 case 'm':
506 HandleMute(streamType, opt);
507 break;
508 case 'U':
509 case 'u':
510 HandleMicMute(opt);
511 break;
512 case 'S':
513 SetStreamType(streamType);
514 break;
515 case 's':
516 IsStreamActive();
517 break;
518 case 'D':
519 SetDeviceActive(argc, argv);
520 break;
521 case 'd':
522 IsDeviceActive();
523 break;
524 case 'R':
525 case 'r':
526 HandleRingerMode(opt);
527 break;
528 case 'C':
529 case 'c':
530 HandleAudioScene(opt);
531 break;
532 case 'X':
533 HandleUpdateStreamState(0, optarg);
534 break;
535 case 'Z':
536 HandleUpdateStreamState(1, optarg);
537 break;
538 case 'N':
539 case 'n':
540 HandleSingleStreamVolumeOption(argc, argv, opt);
541 break;
542 case ':':
543 NoValueError();
544 break;
545 case '?':
546 UnknownOptionError();
547 break;
548 case 'T':
549 SetAudioParamter(argc, argv);
550 break;
551 case 't':
552 GetAudioParamter(argc, argv);
553 break;
554 case 'p':
555 HandleGetVolumeGroups(argc, argv);
556 break;
557 default:
558 break;
559 }
560 }
561
562 return 0;
563 }
564