1
2
3
4
5 package oshi.hardware.platform.mac;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import oshi.annotation.concurrent.Immutable;
11 import oshi.hardware.SoundCard;
12 import oshi.hardware.common.AbstractSoundCard;
13 import oshi.util.FileUtil;
14 import oshi.util.ParseUtil;
15
16
17
18
19 @Immutable
20 final class MacSoundCard extends AbstractSoundCard {
21
22 private static final String APPLE = "Apple Inc.";
23
24
25
26
27
28
29
30
31 MacSoundCard(String kernelVersion, String name, String codec) {
32 super(kernelVersion, name, codec);
33 }
34
35
36
37
38
39
40 public static List<SoundCard> getSoundCards() {
41 List<SoundCard> soundCards = new ArrayList<>();
42
43
44
45
46
47
48
49
50 String manufacturer = APPLE;
51 String kernelVersion = "AppleHDAController";
52 String codec = "AppleHDACodec";
53
54 boolean version = false;
55 String versionMarker = "<key>com.apple.driver.AppleHDAController</key>";
56
57 for (final String checkLine : FileUtil
58 .readFile("/System/Library/Extensions/AppleHDA.kext/Contents/Info.plist")) {
59 if (checkLine.contains(versionMarker)) {
60 version = true;
61 continue;
62 }
63 if (version) {
64 kernelVersion = "AppleHDAController "
65 + ParseUtil.getTextBetweenStrings(checkLine, "<string>", "</string>");
66 version = false;
67 }
68 }
69 soundCards.add(new MacSoundCard(kernelVersion, manufacturer, codec));
70
71 return soundCards;
72 }
73 }