Search in sources :

Example 91 with ParcelUuid

use of android.os.ParcelUuid in project platform_frameworks_base by android.

the class ScanRecordTest method testParser.

@SmallTest
public void testParser() {
    byte[] scanRecord = new byte[] { // advertising flags
    0x02, // advertising flags
    0x01, // advertising flags
    0x1a, // 16 bit service uuids
    0x05, // 16 bit service uuids
    0x02, // 16 bit service uuids
    0x0b, // 16 bit service uuids
    0x11, // 16 bit service uuids
    0x0a, // 16 bit service uuids
    0x11, // name
    0x04, // name
    0x09, // name
    0x50, // name
    0x65, // name
    0x64, // tx power level
    0x02, // tx power level
    0x0A, // tx power level
    (byte) 0xec, // service data
    0x05, // service data
    0x16, // service data
    0x0b, // service data
    0x11, // service data
    0x50, // service data
    0x64, // manufacturer specific data
    0x05, // manufacturer specific data
    (byte) 0xff, // manufacturer specific data
    (byte) 0xe0, // manufacturer specific data
    0x00, // manufacturer specific data
    0x02, // manufacturer specific data
    0x15, // an unknown data type won't cause trouble
    0x03, // an unknown data type won't cause trouble
    0x50, // an unknown data type won't cause trouble
    0x01, // an unknown data type won't cause trouble
    0x02 };
    ScanRecord data = ScanRecord.parseFromBytes(scanRecord);
    assertEquals(0x1a, data.getAdvertiseFlags());
    ParcelUuid uuid1 = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
    ParcelUuid uuid2 = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
    assertTrue(data.getServiceUuids().contains(uuid1));
    assertTrue(data.getServiceUuids().contains(uuid2));
    assertEquals("Ped", data.getDeviceName());
    assertEquals(-20, data.getTxPowerLevel());
    assertTrue(data.getManufacturerSpecificData().get(0x00E0) != null);
    assertArrayEquals(new byte[] { 0x02, 0x15 }, data.getManufacturerSpecificData().get(0x00E0));
    assertTrue(data.getServiceData().containsKey(uuid2));
    assertArrayEquals(new byte[] { 0x50, 0x64 }, data.getServiceData().get(uuid2));
}
Also used : ParcelUuid(android.os.ParcelUuid) ScanRecord(android.bluetooth.le.ScanRecord) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 92 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by DirtyUnicorns.

the class GenericSoundModelTest method testUpdateGenericSoundModel.

@SmallTest
public void testUpdateGenericSoundModel() throws Exception {
    GenericSoundModel model = new_sound_model();
    // Update sound model
    soundTriggerService.updateSoundModel(model);
    loadedModelUuids.add(model.uuid);
    // Confirm it was updated
    GenericSoundModel returnedModel = soundTriggerService.getSoundModel(new ParcelUuid(model.uuid));
    assertEquals(model, returnedModel);
}
Also used : ParcelUuid(android.os.ParcelUuid) GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 93 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by DirtyUnicorns.

the class GenericSoundModelTest method testStartStopGenericSoundModel.

@LargeTest
public void testStartStopGenericSoundModel() throws Exception {
    GenericSoundModel model = new_sound_model();
    boolean captureTriggerAudio = true;
    boolean allowMultipleTriggers = true;
    RecognitionConfig config = new RecognitionConfig(captureTriggerAudio, allowMultipleTriggers, null, null);
    TestRecognitionStatusCallback spyCallback = spy(new TestRecognitionStatusCallback());
    // Update and start sound model recognition
    soundTriggerService.updateSoundModel(model);
    loadedModelUuids.add(model.uuid);
    int r = soundTriggerService.startRecognition(new ParcelUuid(model.uuid), spyCallback, config);
    assertEquals("Could Not Start Recognition with code: " + r, android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
    // Stop recognition
    r = soundTriggerService.stopRecognition(new ParcelUuid(model.uuid), spyCallback);
    assertEquals("Could Not Stop Recognition with code: " + r, android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
}
Also used : ParcelUuid(android.os.ParcelUuid) GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) RecognitionConfig(android.hardware.soundtrigger.SoundTrigger.RecognitionConfig) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 94 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by DirtyUnicorns.

the class GenericSoundModelTest method testTriggerGenericSoundModel.

@LargeTest
public void testTriggerGenericSoundModel() throws Exception {
    GenericSoundModel model = new_sound_model();
    boolean captureTriggerAudio = true;
    boolean allowMultipleTriggers = true;
    RecognitionConfig config = new RecognitionConfig(captureTriggerAudio, allowMultipleTriggers, null, null);
    TestRecognitionStatusCallback spyCallback = spy(new TestRecognitionStatusCallback());
    // Update and start sound model
    soundTriggerService.updateSoundModel(model);
    loadedModelUuids.add(model.uuid);
    soundTriggerService.startRecognition(new ParcelUuid(model.uuid), spyCallback, config);
    // Send trigger to stub HAL
    Socket socket = new Socket(InetAddress.getLocalHost(), 14035);
    DataOutputStream out = new DataOutputStream(socket.getOutputStream());
    out.writeBytes("trig " + model.uuid.toString() + "\r\n");
    out.flush();
    socket.close();
    // Verify trigger was received
    verify(spyCallback, timeout(100)).onGenericSoundTriggerDetected(any());
}
Also used : ParcelUuid(android.os.ParcelUuid) GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) DataOutputStream(java.io.DataOutputStream) RecognitionConfig(android.hardware.soundtrigger.SoundTrigger.RecognitionConfig) Socket(java.net.Socket) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 95 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by DirtyUnicorns.

the class GenericSoundModelTest method testFuzzGenericSoundModel.

/**
     * Tests a more complicated pattern of loading, unloading, triggering, starting and stopping
     * recognition. Intended to find unexpected errors that occur in unexpected states.
     */
@LargeTest
public void testFuzzGenericSoundModel() throws Exception {
    int numModels = 2;
    final int STATUS_UNLOADED = 0;
    final int STATUS_LOADED = 1;
    final int STATUS_STARTED = 2;
    class ModelInfo {

        int status;

        GenericSoundModel model;

        public ModelInfo(GenericSoundModel model, int status) {
            this.status = status;
            this.model = model;
        }
    }
    Random predictableRandom = new Random(100);
    ArrayList modelInfos = new ArrayList<ModelInfo>();
    for (int i = 0; i < numModels; i++) {
        // Create sound model
        byte[] data = new byte[1024];
        predictableRandom.nextBytes(data);
        UUID modelUuid = UUID.randomUUID();
        UUID mVendorUuid = UUID.randomUUID();
        GenericSoundModel model = new GenericSoundModel(modelUuid, mVendorUuid, data);
        ModelInfo modelInfo = new ModelInfo(model, STATUS_UNLOADED);
        modelInfos.add(modelInfo);
    }
    boolean captureTriggerAudio = true;
    boolean allowMultipleTriggers = true;
    RecognitionConfig config = new RecognitionConfig(captureTriggerAudio, allowMultipleTriggers, null, null);
    TestRecognitionStatusCallback spyCallback = spy(new TestRecognitionStatusCallback());
    int numOperationsToRun = 100;
    for (int i = 0; i < numOperationsToRun; i++) {
        // Select a random model
        int modelInfoIndex = predictableRandom.nextInt(modelInfos.size());
        ModelInfo modelInfo = (ModelInfo) modelInfos.get(modelInfoIndex);
        // Perform a random operation
        int operation = predictableRandom.nextInt(5);
        if (operation == 0 && modelInfo.status == STATUS_UNLOADED) {
            // Update and start sound model
            soundTriggerService.updateSoundModel(modelInfo.model);
            loadedModelUuids.add(modelInfo.model.uuid);
            modelInfo.status = STATUS_LOADED;
        } else if (operation == 1 && modelInfo.status == STATUS_LOADED) {
            // Start the sound model
            int r = soundTriggerService.startRecognition(new ParcelUuid(modelInfo.model.uuid), spyCallback, config);
            assertEquals("Could Not Start Recognition with code: " + r, android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
            modelInfo.status = STATUS_STARTED;
        } else if (operation == 2 && modelInfo.status == STATUS_STARTED) {
            // Send trigger to stub HAL
            Socket socket = new Socket(InetAddress.getLocalHost(), 14035);
            DataOutputStream out = new DataOutputStream(socket.getOutputStream());
            out.writeBytes("trig " + modelInfo.model.uuid + "\r\n");
            out.flush();
            socket.close();
            // Verify trigger was received
            verify(spyCallback, timeout(100)).onGenericSoundTriggerDetected(any());
            reset(spyCallback);
        } else if (operation == 3 && modelInfo.status == STATUS_STARTED) {
            // Stop recognition
            int r = soundTriggerService.stopRecognition(new ParcelUuid(modelInfo.model.uuid), spyCallback);
            assertEquals("Could Not Stop Recognition with code: " + r, android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
            modelInfo.status = STATUS_LOADED;
        } else if (operation == 4 && modelInfo.status != STATUS_UNLOADED) {
            // Delete sound model
            soundTriggerService.deleteSoundModel(new ParcelUuid(modelInfo.model.uuid));
            loadedModelUuids.remove(modelInfo.model.uuid);
            // Confirm it was deleted
            GenericSoundModel returnedModel = soundTriggerService.getSoundModel(new ParcelUuid(modelInfo.model.uuid));
            assertEquals(null, returnedModel);
            modelInfo.status = STATUS_UNLOADED;
        }
    }
}
Also used : ParcelUuid(android.os.ParcelUuid) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) Random(java.util.Random) RecognitionConfig(android.hardware.soundtrigger.SoundTrigger.RecognitionConfig) UUID(java.util.UUID) Socket(java.net.Socket) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

ParcelUuid (android.os.ParcelUuid)147 SmallTest (android.test.suitebuilder.annotation.SmallTest)43 RemoteException (android.os.RemoteException)29 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)23 GenericSoundModel (android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)20 Parcel (android.os.Parcel)20 ScanFilter (android.bluetooth.le.ScanFilter)19 RecognitionConfig (android.hardware.soundtrigger.SoundTrigger.RecognitionConfig)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 ScanRecord (android.bluetooth.le.ScanRecord)10 BluetoothDevice (android.bluetooth.BluetoothDevice)9 Socket (java.net.Socket)9 DataOutputStream (java.io.DataOutputStream)8 ByteBuffer (java.nio.ByteBuffer)8 SparseArray (android.util.SparseArray)6 RequiresPermission (android.annotation.RequiresPermission)5 BluetoothClass (android.bluetooth.BluetoothClass)5 BluetoothLeScanner (android.bluetooth.le.BluetoothLeScanner)5 ScanCallback (android.bluetooth.le.ScanCallback)5