1 /*
2  * Copyright (c) 2023 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 #ifndef ST_AUDIO_SOCKET_THREAD_H
16 #define ST_AUDIO_SOCKET_THREAD_H
17 
18 #include <memory>
19 #include <string>
20 
21 #include "hdf_device_desc.h"
22 #include "hdf_types.h"
23 #include "v4_0/audio_types.h"
24 #include "audio_pnp_param.h"
25 
26 namespace OHOS {
27 namespace AudioStandard {
28 using namespace std;
29 
30 class AudioSocketThread {
31 public:
32     static bool IsUpdatePnpDeviceState(AudioEvent *pnpDeviceEvent);
33     static void UpdatePnpDeviceState(AudioEvent *pnpDeviceEvent);
34     static int AudioPnpUeventOpen(int *fd);
35     static ssize_t AudioPnpReadUeventMsg(int sockFd, char *buffer, size_t length);
36     static bool AudioPnpUeventParse(const char *msg, const ssize_t strLength);
37     static void UpdateDeviceState(AudioEvent audioEvent);
38     static int32_t DetectUsbHeadsetState(AudioEvent *audioEvent);
39     static int32_t DetectAnalogHeadsetState(AudioEvent *audioEvent);
40     static int32_t DetectDPState(AudioEvent *audioEvent);
41     static AudioEvent audioSocketEvent_;
42 
43 private:
44     static int32_t SetAudioPnpServerEventValue(AudioEvent *audioEvent, struct AudioPnpUevent *audioPnpUevent);
45     static int32_t AudioAnalogHeadsetDetectDevice(struct AudioPnpUevent *audioPnpUevent);
46     static int32_t CheckUsbDesc(struct UsbDevice *usbDevice);
47     static int32_t ReadAndScanUsbDev(const char *devPath);
48     static bool FindAudioUsbDevice(const char *devName);
49     static bool AddAudioUsbDevice(const char *devName);
50     static bool CheckAudioUsbDevice(const char *devName);
51     static bool DeleteAudioUsbDevice(const char *devName);
52     static int32_t AudioUsbHeadsetDetectDevice(struct AudioPnpUevent *audioPnpUevent);
53     static inline bool IsBadName(const char *name);
54     static int32_t ScanUsbBusSubDir(const char *subDir);
55     static int32_t AudioDpDetectDevice(struct AudioPnpUevent *audioPnpUevent);
56     static int32_t AudioMicBlockDevice(struct AudioPnpUevent *audioPnpUevent);
57 };
58 
59 } // namespace AudioStandard
60 } // namespace OHOS
61 #endif // ST_AUDIO_SOCKET_THREAD_H