Loading core/java/com/android/internal/alsa/AlsaCardsParser.java +54 −1 Original line number Original line Diff line number Diff line Loading @@ -94,6 +94,12 @@ public class AlsaCardsParser { public String textFormat() { public String textFormat() { return mCardName + " : " + mCardDescription; return mCardName + " : " + mCardDescription; } } public void log(int listIndex) { Slog.d(TAG, "" + listIndex + " [" + mCardNum + " " + mCardName + " : " + mCardDescription + " usb:" + mIsUsb); } } } public AlsaCardsParser() {} public AlsaCardsParser() {} Loading Loading @@ -169,9 +175,41 @@ public class AlsaCardsParser { // return -1 if none found // return -1 if none found public int getDefaultUsbCard() { public int getDefaultUsbCard() { // save the current list of devices ArrayList<AlsaCardsParser.AlsaCardRecord> prevRecs = mCardRecords; if (DEBUG) { LogDevices("Previous Devices:", prevRecs); } // get the new list of devices scan(); if (DEBUG) { LogDevices("Current Devices:", mCardRecords); } // Calculate the difference between the old and new device list ArrayList<AlsaCardRecord> newRecs = getNewCardRecords(prevRecs); if (DEBUG) { LogDevices("New Devices:", newRecs); } // Choose the most-recently added EXTERNAL card // Choose the most-recently added EXTERNAL card // Check recently added devices for (AlsaCardRecord rec : newRecs) { if (DEBUG) { Slog.d(TAG, rec.mCardName + " card:" + rec.mCardNum + " usb:" + rec.mIsUsb); } if (rec.mIsUsb) { // Found it return rec.mCardNum; } } // or return the first added EXTERNAL card? // or return the first added EXTERNAL card? for (AlsaCardRecord rec : mCardRecords) { for (AlsaCardRecord rec : prevRecs) { if (DEBUG) { Slog.d(TAG, rec.mCardName + " card:" + rec.mCardNum + " usb:" + rec.mIsUsb); } if (rec.mIsUsb) { if (rec.mIsUsb) { return rec.mCardNum; return rec.mCardNum; } } Loading @@ -183,11 +221,17 @@ public class AlsaCardsParser { public int getDefaultCard() { public int getDefaultCard() { // return an external card if possible // return an external card if possible int card = getDefaultUsbCard(); int card = getDefaultUsbCard(); if (DEBUG) { Slog.d(TAG, "getDefaultCard() default usb card:" + card); } if (card < 0 && getNumCardRecords() > 0) { if (card < 0 && getNumCardRecords() > 0) { // otherwise return the (internal) card with the highest number // otherwise return the (internal) card with the highest number card = getCardRecordAt(getNumCardRecords() - 1).mCardNum; card = getCardRecordAt(getNumCardRecords() - 1).mCardNum; } } if (DEBUG) { Slog.d(TAG, " returns card:" + card); } return card; return card; } } Loading Loading @@ -222,4 +266,13 @@ public class AlsaCardsParser { } } } } } } static public void LogDevices(String caption, ArrayList<AlsaCardRecord> deviceList) { Slog.d(TAG, caption + " ----------------"); int listIndex = 0; for (AlsaCardRecord device : deviceList) { device.log(listIndex++); } Slog.d(TAG, "----------------"); } } } services/usb/java/com/android/server/usb/UsbAlsaManager.java +24 −21 Original line number Original line Diff line number Diff line Loading @@ -212,6 +212,10 @@ public final class UsbAlsaManager { } } private AlsaDevice waitForAlsaDevice(int card, int device, int type) { private AlsaDevice waitForAlsaDevice(int card, int device, int type) { if (DEBUG) { Slog.e(TAG, "waitForAlsaDevice(c:" + card + " d:" + device + ")"); } AlsaDevice testDevice = new AlsaDevice(type, card, device); AlsaDevice testDevice = new AlsaDevice(type, card, device); // This value was empirically determined. // This value was empirically determined. Loading Loading @@ -292,7 +296,8 @@ public final class UsbAlsaManager { */ */ /* package */ UsbAudioDevice selectAudioCard(int card) { /* package */ UsbAudioDevice selectAudioCard(int card) { if (DEBUG) { if (DEBUG) { Slog.d(TAG, "selectAudioCard() card:" + card); Slog.d(TAG, "selectAudioCard() card:" + card + " isCardUsb(): " + mCardsParser.isCardUsb(card)); } } if (!mCardsParser.isCardUsb(card)) { if (!mCardsParser.isCardUsb(card)) { // Don't. AudioPolicyManager has logic for falling back to internal devices. // Don't. AudioPolicyManager has logic for falling back to internal devices. Loading @@ -304,6 +309,10 @@ public final class UsbAlsaManager { boolean hasPlayback = mDevicesParser.hasPlaybackDevices(card); boolean hasPlayback = mDevicesParser.hasPlaybackDevices(card); boolean hasCapture = mDevicesParser.hasCaptureDevices(card); boolean hasCapture = mDevicesParser.hasCaptureDevices(card); if (DEBUG) { Slog.d(TAG, "usb: hasPlayback:" + hasPlayback + " hasCapture:" + hasCapture); } int deviceClass = int deviceClass = (mCardsParser.isCardUsb(card) (mCardsParser.isCardUsb(card) ? UsbAudioDevice.kAudioDeviceClass_External ? UsbAudioDevice.kAudioDeviceClass_External Loading @@ -320,10 +329,6 @@ public final class UsbAlsaManager { return null; return null; } } if (DEBUG) { Slog.d(TAG, "usb: hasPlayback:" + hasPlayback + " hasCapture:" + hasCapture); } UsbAudioDevice audioDevice = UsbAudioDevice audioDevice = new UsbAudioDevice(card, device, hasPlayback, hasCapture, deviceClass); new UsbAudioDevice(card, device, hasPlayback, hasCapture, deviceClass); AlsaCardsParser.AlsaCardRecord cardRecord = mCardsParser.getCardRecordFor(card); AlsaCardsParser.AlsaCardRecord cardRecord = mCardsParser.getCardRecordFor(card); Loading @@ -339,7 +344,6 @@ public final class UsbAlsaManager { if (DEBUG) { if (DEBUG) { Slog.d(TAG, "UsbAudioManager.selectDefaultDevice()"); Slog.d(TAG, "UsbAudioManager.selectDefaultDevice()"); } } mCardsParser.scan(); return selectAudioCard(mCardsParser.getDefaultCard()); return selectAudioCard(mCardsParser.getDefaultCard()); } } Loading @@ -361,27 +365,22 @@ public final class UsbAlsaManager { isAudioDevice = true; isAudioDevice = true; } } } } if (DEBUG) { Slog.d(TAG, " isAudioDevice: " + isAudioDevice); } if (!isAudioDevice) { if (!isAudioDevice) { return; return; } } ArrayList<AlsaCardsParser.AlsaCardRecord> prevScanRecs = mCardsParser.getScanRecords(); int addedCard = mCardsParser.getDefaultUsbCard(); mCardsParser.scan(); int addedCard = -1; ArrayList<AlsaCardsParser.AlsaCardRecord> newScanRecs = mCardsParser.getNewCardRecords(prevScanRecs); if (newScanRecs.size() > 0) { // This is where we select the just connected device // NOTE - to switch to prefering the first-connected device, just always // take the else clause below. addedCard = newScanRecs.get(0).mCardNum; } else { addedCard = mCardsParser.getDefaultUsbCard(); } // If the default isn't a USB device, let the existing "select internal mechanism" // If the default isn't a USB device, let the existing "select internal mechanism" // handle the selection. // handle the selection. if (DEBUG) { Slog.d(TAG, " mCardsParser.isCardUsb(" + addedCard + ") = " + mCardsParser.isCardUsb(addedCard)); } if (mCardsParser.isCardUsb(addedCard)) { if (mCardsParser.isCardUsb(addedCard)) { UsbAudioDevice audioDevice = selectAudioCard(addedCard); UsbAudioDevice audioDevice = selectAudioCard(addedCard); if (audioDevice != null) { if (audioDevice != null) { Loading Loading @@ -429,6 +428,10 @@ public final class UsbAlsaManager { } } } } } } if (DEBUG) { Slog.d(TAG, "deviceAdded() - done"); } } } /* package */ void usbDeviceRemoved(UsbDevice usbDevice) { /* package */ void usbDeviceRemoved(UsbDevice usbDevice) { Loading Loading
core/java/com/android/internal/alsa/AlsaCardsParser.java +54 −1 Original line number Original line Diff line number Diff line Loading @@ -94,6 +94,12 @@ public class AlsaCardsParser { public String textFormat() { public String textFormat() { return mCardName + " : " + mCardDescription; return mCardName + " : " + mCardDescription; } } public void log(int listIndex) { Slog.d(TAG, "" + listIndex + " [" + mCardNum + " " + mCardName + " : " + mCardDescription + " usb:" + mIsUsb); } } } public AlsaCardsParser() {} public AlsaCardsParser() {} Loading Loading @@ -169,9 +175,41 @@ public class AlsaCardsParser { // return -1 if none found // return -1 if none found public int getDefaultUsbCard() { public int getDefaultUsbCard() { // save the current list of devices ArrayList<AlsaCardsParser.AlsaCardRecord> prevRecs = mCardRecords; if (DEBUG) { LogDevices("Previous Devices:", prevRecs); } // get the new list of devices scan(); if (DEBUG) { LogDevices("Current Devices:", mCardRecords); } // Calculate the difference between the old and new device list ArrayList<AlsaCardRecord> newRecs = getNewCardRecords(prevRecs); if (DEBUG) { LogDevices("New Devices:", newRecs); } // Choose the most-recently added EXTERNAL card // Choose the most-recently added EXTERNAL card // Check recently added devices for (AlsaCardRecord rec : newRecs) { if (DEBUG) { Slog.d(TAG, rec.mCardName + " card:" + rec.mCardNum + " usb:" + rec.mIsUsb); } if (rec.mIsUsb) { // Found it return rec.mCardNum; } } // or return the first added EXTERNAL card? // or return the first added EXTERNAL card? for (AlsaCardRecord rec : mCardRecords) { for (AlsaCardRecord rec : prevRecs) { if (DEBUG) { Slog.d(TAG, rec.mCardName + " card:" + rec.mCardNum + " usb:" + rec.mIsUsb); } if (rec.mIsUsb) { if (rec.mIsUsb) { return rec.mCardNum; return rec.mCardNum; } } Loading @@ -183,11 +221,17 @@ public class AlsaCardsParser { public int getDefaultCard() { public int getDefaultCard() { // return an external card if possible // return an external card if possible int card = getDefaultUsbCard(); int card = getDefaultUsbCard(); if (DEBUG) { Slog.d(TAG, "getDefaultCard() default usb card:" + card); } if (card < 0 && getNumCardRecords() > 0) { if (card < 0 && getNumCardRecords() > 0) { // otherwise return the (internal) card with the highest number // otherwise return the (internal) card with the highest number card = getCardRecordAt(getNumCardRecords() - 1).mCardNum; card = getCardRecordAt(getNumCardRecords() - 1).mCardNum; } } if (DEBUG) { Slog.d(TAG, " returns card:" + card); } return card; return card; } } Loading Loading @@ -222,4 +266,13 @@ public class AlsaCardsParser { } } } } } } static public void LogDevices(String caption, ArrayList<AlsaCardRecord> deviceList) { Slog.d(TAG, caption + " ----------------"); int listIndex = 0; for (AlsaCardRecord device : deviceList) { device.log(listIndex++); } Slog.d(TAG, "----------------"); } } }
services/usb/java/com/android/server/usb/UsbAlsaManager.java +24 −21 Original line number Original line Diff line number Diff line Loading @@ -212,6 +212,10 @@ public final class UsbAlsaManager { } } private AlsaDevice waitForAlsaDevice(int card, int device, int type) { private AlsaDevice waitForAlsaDevice(int card, int device, int type) { if (DEBUG) { Slog.e(TAG, "waitForAlsaDevice(c:" + card + " d:" + device + ")"); } AlsaDevice testDevice = new AlsaDevice(type, card, device); AlsaDevice testDevice = new AlsaDevice(type, card, device); // This value was empirically determined. // This value was empirically determined. Loading Loading @@ -292,7 +296,8 @@ public final class UsbAlsaManager { */ */ /* package */ UsbAudioDevice selectAudioCard(int card) { /* package */ UsbAudioDevice selectAudioCard(int card) { if (DEBUG) { if (DEBUG) { Slog.d(TAG, "selectAudioCard() card:" + card); Slog.d(TAG, "selectAudioCard() card:" + card + " isCardUsb(): " + mCardsParser.isCardUsb(card)); } } if (!mCardsParser.isCardUsb(card)) { if (!mCardsParser.isCardUsb(card)) { // Don't. AudioPolicyManager has logic for falling back to internal devices. // Don't. AudioPolicyManager has logic for falling back to internal devices. Loading @@ -304,6 +309,10 @@ public final class UsbAlsaManager { boolean hasPlayback = mDevicesParser.hasPlaybackDevices(card); boolean hasPlayback = mDevicesParser.hasPlaybackDevices(card); boolean hasCapture = mDevicesParser.hasCaptureDevices(card); boolean hasCapture = mDevicesParser.hasCaptureDevices(card); if (DEBUG) { Slog.d(TAG, "usb: hasPlayback:" + hasPlayback + " hasCapture:" + hasCapture); } int deviceClass = int deviceClass = (mCardsParser.isCardUsb(card) (mCardsParser.isCardUsb(card) ? UsbAudioDevice.kAudioDeviceClass_External ? UsbAudioDevice.kAudioDeviceClass_External Loading @@ -320,10 +329,6 @@ public final class UsbAlsaManager { return null; return null; } } if (DEBUG) { Slog.d(TAG, "usb: hasPlayback:" + hasPlayback + " hasCapture:" + hasCapture); } UsbAudioDevice audioDevice = UsbAudioDevice audioDevice = new UsbAudioDevice(card, device, hasPlayback, hasCapture, deviceClass); new UsbAudioDevice(card, device, hasPlayback, hasCapture, deviceClass); AlsaCardsParser.AlsaCardRecord cardRecord = mCardsParser.getCardRecordFor(card); AlsaCardsParser.AlsaCardRecord cardRecord = mCardsParser.getCardRecordFor(card); Loading @@ -339,7 +344,6 @@ public final class UsbAlsaManager { if (DEBUG) { if (DEBUG) { Slog.d(TAG, "UsbAudioManager.selectDefaultDevice()"); Slog.d(TAG, "UsbAudioManager.selectDefaultDevice()"); } } mCardsParser.scan(); return selectAudioCard(mCardsParser.getDefaultCard()); return selectAudioCard(mCardsParser.getDefaultCard()); } } Loading @@ -361,27 +365,22 @@ public final class UsbAlsaManager { isAudioDevice = true; isAudioDevice = true; } } } } if (DEBUG) { Slog.d(TAG, " isAudioDevice: " + isAudioDevice); } if (!isAudioDevice) { if (!isAudioDevice) { return; return; } } ArrayList<AlsaCardsParser.AlsaCardRecord> prevScanRecs = mCardsParser.getScanRecords(); int addedCard = mCardsParser.getDefaultUsbCard(); mCardsParser.scan(); int addedCard = -1; ArrayList<AlsaCardsParser.AlsaCardRecord> newScanRecs = mCardsParser.getNewCardRecords(prevScanRecs); if (newScanRecs.size() > 0) { // This is where we select the just connected device // NOTE - to switch to prefering the first-connected device, just always // take the else clause below. addedCard = newScanRecs.get(0).mCardNum; } else { addedCard = mCardsParser.getDefaultUsbCard(); } // If the default isn't a USB device, let the existing "select internal mechanism" // If the default isn't a USB device, let the existing "select internal mechanism" // handle the selection. // handle the selection. if (DEBUG) { Slog.d(TAG, " mCardsParser.isCardUsb(" + addedCard + ") = " + mCardsParser.isCardUsb(addedCard)); } if (mCardsParser.isCardUsb(addedCard)) { if (mCardsParser.isCardUsb(addedCard)) { UsbAudioDevice audioDevice = selectAudioCard(addedCard); UsbAudioDevice audioDevice = selectAudioCard(addedCard); if (audioDevice != null) { if (audioDevice != null) { Loading Loading @@ -429,6 +428,10 @@ public final class UsbAlsaManager { } } } } } } if (DEBUG) { Slog.d(TAG, "deviceAdded() - done"); } } } /* package */ void usbDeviceRemoved(UsbDevice usbDevice) { /* package */ void usbDeviceRemoved(UsbDevice usbDevice) { Loading