FileDocCategorySizeDatePackage
AlsaDevicesParser.javaAPI DocAndroid 5.1 API9395Thu Mar 12 22:22:08 GMT 2015android.alsa

AlsaDevicesParser

public class AlsaDevicesParser extends Object
hide
Retrieves information from an ALSA "devices" file.

Fields Summary
private static final String
TAG
private static final int
kIndex_CardDeviceField
private static final int
kStartIndex_CardNum
private static final int
kEndIndex_CardNum
private static final int
kStartIndex_DeviceNum
private static final int
kEndIndex_DeviceNum
private static final int
kStartIndex_Type
private static LineTokenizer
mTokenizer
private boolean
mHasCaptureDevices
private boolean
mHasPlaybackDevices
private boolean
mHasMIDIDevices
private Vector
deviceRecords_
Constructors Summary
public AlsaDevicesParser()

    
Methods Summary
public voidLog()

        int numDevRecs = getNumDeviceRecords();
        for (int index = 0; index < numDevRecs; ++index) {
            Slog.w(TAG, "usb:" + getDeviceRecordAt(index).textFormat());
        }
    
public android.alsa.AlsaDevicesParser$AlsaDeviceRecordgetDeviceRecordAt(int index)

        return deviceRecords_.get(index);
    
public intgetNumDeviceRecords()

        return deviceRecords_.size();
    
public booleanhasCaptureDevices()

        return mHasCaptureDevices;
    
public booleanhasCaptureDevices(int card)

        for (int index = 0; index < deviceRecords_.size(); index++) {
            AlsaDeviceRecord deviceRecord = deviceRecords_.get(index);
            if (deviceRecord.mCardNum == card &&
                deviceRecord.mDeviceType == AlsaDeviceRecord.kDeviceType_Audio &&
                deviceRecord.mDeviceDir == AlsaDeviceRecord.kDeviceDir_Capture) {
                return true;
            }
        }
        return false;
    
public booleanhasMIDIDevices()

        return mHasMIDIDevices;
    
public booleanhasMIDIDevices(int card)

        for (int index = 0; index < deviceRecords_.size(); index++) {
            AlsaDeviceRecord deviceRecord = deviceRecords_.get(index);
            if (deviceRecord.mCardNum == card &&
                deviceRecord.mDeviceType == AlsaDeviceRecord.kDeviceType_MIDI) {
                return true;
            }
        }
        return false;
    
public booleanhasPlaybackDevices()

        return mHasPlaybackDevices;
    
public booleanhasPlaybackDevices(int card)

        for (int index = 0; index < deviceRecords_.size(); index++) {
            AlsaDeviceRecord deviceRecord = deviceRecords_.get(index);
            if (deviceRecord.mCardNum == card &&
                deviceRecord.mDeviceType == AlsaDeviceRecord.kDeviceType_Audio &&
                deviceRecord.mDeviceDir == AlsaDeviceRecord.kDeviceDir_Playback) {
                return true;
            }
        }
        return false;
    
private booleanisLineDeviceRecord(java.lang.String line)


        
        return line.charAt(kIndex_CardDeviceField) == '[";
    
public voidscan()

        deviceRecords_.clear();

        final String devicesFilePath = "/proc/asound/devices";
        File devicesFile = new File(devicesFilePath);
        try {
            FileReader reader = new FileReader(devicesFile);
            BufferedReader bufferedReader = new BufferedReader(reader);
            String line = "";
            while ((line = bufferedReader.readLine()) != null) {
                if (isLineDeviceRecord(line)) {
                    AlsaDeviceRecord deviceRecord = new AlsaDeviceRecord();
                    deviceRecord.parse(line);
                    deviceRecords_.add(deviceRecord);
                }
            }
            reader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }