1 /**
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  **/
16 #include <binder/IServiceManager.h>
17 #include <binder/Parcel.h>
18 #include <sys/types.h>
19 #include <sys/wait.h>
20 #include <system/audio.h>
21 #include <utils/String16.h>
22 
23 using namespace android;
24 
25 enum {
26   SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
27   GET_DEVICE_CONNECTION_STATE,
28   HANDLE_DEVICE_CONFIG_CHANGE,
29   SET_PHONE_STATE,
30   SET_RINGER_MODE,
31   SET_FORCE_USE,
32   GET_FORCE_USE,
33   GET_OUTPUT,
34   START_OUTPUT,
35   STOP_OUTPUT,
36   RELEASE_OUTPUT,
37   GET_INPUT_FOR_ATTR,
38   START_INPUT,
39   STOP_INPUT,
40   RELEASE_INPUT,
41   INIT_STREAM_VOLUME,
42   SET_STREAM_VOLUME,
43   GET_STREAM_VOLUME,
44   GET_STRATEGY_FOR_STREAM,
45   GET_OUTPUT_FOR_EFFECT,
46   REGISTER_EFFECT,
47   UNREGISTER_EFFECT,
48   IS_STREAM_ACTIVE,
49   IS_SOURCE_ACTIVE,
50   GET_DEVICES_FOR_STREAM,
51   QUERY_DEFAULT_PRE_PROCESSING,
52   SET_EFFECT_ENABLED,
53   IS_STREAM_ACTIVE_REMOTELY,
54   IS_OFFLOAD_SUPPORTED,
55   LIST_AUDIO_PORTS,
56   GET_AUDIO_PORT,
57   CREATE_AUDIO_PATCH,
58   RELEASE_AUDIO_PATCH,
59   LIST_AUDIO_PATCHES,
60   SET_AUDIO_PORT_CONFIG,
61   REGISTER_CLIENT,
62   GET_OUTPUT_FOR_ATTR,
63   ACQUIRE_SOUNDTRIGGER_SESSION,
64   RELEASE_SOUNDTRIGGER_SESSION,
65   GET_PHONE_STATE,
66   REGISTER_POLICY_MIXES,
67   START_AUDIO_SOURCE,
68   STOP_AUDIO_SOURCE,
69   SET_AUDIO_PORT_CALLBACK_ENABLED,
70   SET_MASTER_MONO,
71   GET_MASTER_MONO,
72 };
73 
getOutputForAttr()74 int getOutputForAttr() {
75   sp<IServiceManager> sm = defaultServiceManager();
76   sp<IBinder> binder = sm->getService(String16("media.audio_policy"));
77   Parcel data, reply;
78   data.writeInterfaceToken(String16("android.media.IAudioPolicyService"));
79   data.writeInt32(1);
80   audio_attributes_t attr;
81   memset(&attr, 0xff, sizeof(attr));
82   attr.flags = AUDIO_FLAG_NONE;
83   memset(attr.tags, 0x41, AUDIO_ATTRIBUTES_TAGS_MAX_SIZE);
84   data.write(&attr, sizeof(attr));
85   binder->transact(GET_OUTPUT_FOR_ATTR, data, &reply, 0);
86   return 0;
87 }
88 
main()89 int main() {
90   getOutputForAttr();
91   return 0;
92 }
93