frameworks/base
Revision | 420dcd798d36fc45e70d5859ad2263117dfa8429 (tree) |
---|---|
Time | 2020-04-14 23:46:48 |
Author | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Detect HDMI audio by switch events
If detect SW_VIDEOOUT_INSERT, assume HDMI is plugged.
@@ -22,6 +22,8 @@ import static com.android.server.input.InputManagerService.SW_LINEOUT_INSERT; | ||
22 | 22 | import static com.android.server.input.InputManagerService.SW_LINEOUT_INSERT_BIT; |
23 | 23 | import static com.android.server.input.InputManagerService.SW_MICROPHONE_INSERT; |
24 | 24 | import static com.android.server.input.InputManagerService.SW_MICROPHONE_INSERT_BIT; |
25 | +import static com.android.server.input.InputManagerService.SW_VIDEOOUT_INSERT; | |
26 | +import static com.android.server.input.InputManagerService.SW_VIDEOOUT_INSERT_BIT; | |
25 | 27 | |
26 | 28 | import android.content.Context; |
27 | 29 | import android.media.AudioManager; |
@@ -118,8 +120,11 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks { | ||
118 | 120 | if (mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, SW_LINEOUT_INSERT) == 1) { |
119 | 121 | switchValues |= SW_LINEOUT_INSERT_BIT; |
120 | 122 | } |
123 | + if (mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, SW_VIDEOOUT_INSERT) == 1) { | |
124 | + switchValues |= SW_VIDEOOUT_INSERT_BIT; | |
125 | + } | |
121 | 126 | notifyWiredAccessoryChanged(0, switchValues, |
122 | - SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_LINEOUT_INSERT_BIT); | |
127 | + SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_LINEOUT_INSERT_BIT | SW_VIDEOOUT_INSERT_BIT); | |
123 | 128 | } |
124 | 129 | |
125 | 130 |
@@ -137,7 +142,7 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks { | ||
137 | 142 | @Override |
138 | 143 | public void notifyWiredAccessoryChanged(long whenNanos, int switchValues, int switchMask) { |
139 | 144 | if (LOG) { |
140 | - Slog.v(TAG, "notifyWiredAccessoryChanged: when=" + whenNanos | |
145 | + Slog.i(TAG, "notifyWiredAccessoryChanged: when=" + whenNanos | |
141 | 146 | + " bits=" + switchCodeToString(switchValues, switchMask) |
142 | 147 | + " mask=" + Integer.toHexString(switchMask)); |
143 | 148 | } |
@@ -146,7 +151,7 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks { | ||
146 | 151 | int headset; |
147 | 152 | mSwitchValues = (mSwitchValues & ~switchMask) | switchValues; |
148 | 153 | switch (mSwitchValues & |
149 | - (SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_LINEOUT_INSERT_BIT)) { | |
154 | + (SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_LINEOUT_INSERT_BIT | SW_VIDEOOUT_INSERT_BIT)) { | |
150 | 155 | case 0: |
151 | 156 | headset = 0; |
152 | 157 | break; |
@@ -159,6 +164,11 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks { | ||
159 | 164 | headset = BIT_LINEOUT; |
160 | 165 | break; |
161 | 166 | |
167 | + case SW_VIDEOOUT_INSERT_BIT: | |
168 | + case SW_VIDEOOUT_INSERT_BIT | SW_LINEOUT_INSERT_BIT: | |
169 | + headset = BIT_HDMI_AUDIO; | |
170 | + break; | |
171 | + | |
162 | 172 | case SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT: |
163 | 173 | headset = BIT_HEADSET; |
164 | 174 | break; |
@@ -173,7 +183,7 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks { | ||
173 | 183 | } |
174 | 184 | |
175 | 185 | updateLocked(NAME_H2W, |
176 | - (mHeadsetState & ~(BIT_HEADSET | BIT_HEADSET_NO_MIC | BIT_LINEOUT)) | headset); | |
186 | + (mHeadsetState & ~(BIT_HEADSET | BIT_HEADSET_NO_MIC | BIT_LINEOUT | BIT_HDMI_AUDIO)) | headset); | |
177 | 187 | } |
178 | 188 | } |
179 | 189 |
@@ -305,7 +315,7 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks { | ||
305 | 315 | } |
306 | 316 | |
307 | 317 | if (LOG) { |
308 | - Slog.v(TAG, "headsetName: " + headsetName + | |
318 | + Slog.i(TAG, "headsetName: " + headsetName + | |
309 | 319 | (state == 1 ? " connected" : " disconnected")); |
310 | 320 | } |
311 | 321 |
@@ -328,6 +338,14 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks { | ||
328 | 338 | (switchValues & SW_MICROPHONE_INSERT_BIT) != 0) { |
329 | 339 | sb.append("SW_MICROPHONE_INSERT"); |
330 | 340 | } |
341 | + if ((switchMask & SW_LINEOUT_INSERT_BIT) != 0 && | |
342 | + (switchValues & SW_LINEOUT_INSERT_BIT) != 0) { | |
343 | + sb.append("SW_LINEOUT_INSERT "); | |
344 | + } | |
345 | + if ((switchMask & SW_VIDEOOUT_INSERT_BIT) != 0 && | |
346 | + (switchValues & SW_VIDEOOUT_INSERT_BIT) != 0) { | |
347 | + sb.append("SW_VIDEOOUT_INSERT "); | |
348 | + } | |
331 | 349 | return sb.toString(); |
332 | 350 | } |
333 | 351 |
@@ -294,6 +294,9 @@ public class InputManagerService extends IInputManager.Stub | ||
294 | 294 | /** Switch code: Headphone/Microphone Jack. When set, something is inserted. */ |
295 | 295 | public static final int SW_JACK_PHYSICAL_INSERT = 0x07; |
296 | 296 | |
297 | + /** Switch code: Video out jack. When set, something is inserted. */ | |
298 | + public static final int SW_VIDEOOUT_INSERT = 0x08; | |
299 | + | |
297 | 300 | /** Switch code: Camera lens cover. When set the lens is covered. */ |
298 | 301 | public static final int SW_CAMERA_LENS_COVER = 0x09; |
299 | 302 |
@@ -304,8 +307,9 @@ public class InputManagerService extends IInputManager.Stub | ||
304 | 307 | public static final int SW_MICROPHONE_INSERT_BIT = 1 << SW_MICROPHONE_INSERT; |
305 | 308 | public static final int SW_LINEOUT_INSERT_BIT = 1 << SW_LINEOUT_INSERT; |
306 | 309 | public static final int SW_JACK_PHYSICAL_INSERT_BIT = 1 << SW_JACK_PHYSICAL_INSERT; |
310 | + public static final int SW_VIDEOOUT_INSERT_BIT = 1 << SW_VIDEOOUT_INSERT; | |
307 | 311 | public static final int SW_JACK_BITS = |
308 | - SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_JACK_PHYSICAL_INSERT_BIT | SW_LINEOUT_INSERT_BIT; | |
312 | + SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_JACK_PHYSICAL_INSERT_BIT | SW_LINEOUT_INSERT_BIT | SW_VIDEOOUT_INSERT_BIT; | |
309 | 313 | public static final int SW_CAMERA_LENS_COVER_BIT = 1 << SW_CAMERA_LENS_COVER; |
310 | 314 | |
311 | 315 | /** Whether to use the dev/input/event or uevent subsystem for the audio jack. */ |