use of android.os.ParcelUuid in project android_frameworks_base by crdroidandroid.
the class BluetoothGatt method registerApp.
/**
* Register an application callback to start using GATT.
*
* <p>This is an asynchronous call. The callback {@link BluetoothGattCallback#onAppRegistered}
* is used to notify success or failure if the function returns true.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param callback GATT callback handler that will receive asynchronous callbacks.
* @return If true, the callback will be called to notify success or failure,
* false on immediate error
*/
private boolean registerApp(BluetoothGattCallback callback) {
if (DBG)
Log.d(TAG, "registerApp()");
if (mService == null)
return false;
mCallback = callback;
UUID uuid = UUID.randomUUID();
if (DBG)
Log.d(TAG, "registerApp() - UUID=" + uuid);
try {
mService.registerClient(new ParcelUuid(uuid), mBluetoothGattCallback);
} catch (RemoteException e) {
Log.e(TAG, "", e);
return false;
}
return true;
}
use of android.os.ParcelUuid in project android_frameworks_base by crdroidandroid.
the class CachedBluetoothDevice method updateProfiles.
private boolean updateProfiles() {
ParcelUuid[] uuids = mDevice.getUuids();
if (uuids == null)
return false;
ParcelUuid[] localUuids = mLocalAdapter.getUuids();
if (localUuids == null)
return false;
/**
* Now we know if the device supports PBAP, update permissions...
*/
processPhonebookAccess();
mProfileManager.updateProfiles(uuids, localUuids, mProfiles, mRemovedProfiles, mLocalNapRoleConnected, mDevice);
if (DEBUG) {
Log.e(TAG, "updating profiles for " + mDevice.getAliasName());
BluetoothClass bluetoothClass = mDevice.getBluetoothClass();
if (bluetoothClass != null)
Log.v(TAG, "Class: " + bluetoothClass.toString());
Log.v(TAG, "UUID:");
for (ParcelUuid uuid : uuids) {
Log.v(TAG, " " + uuid);
}
}
return true;
}
use of android.os.ParcelUuid in project android_frameworks_base by crdroidandroid.
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;
}
}
}
use of android.os.ParcelUuid in project android_frameworks_base by crdroidandroid.
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);
}
use of android.os.ParcelUuid in project android_frameworks_base by crdroidandroid.
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);
}
Aggregations