Java Code Examples for android.os.ParcelUuid#getUuid()

The following examples show how to use android.os.ParcelUuid#getUuid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScanFilter.java    From Android-Scanner-Compat-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check if the uuid pattern is contained in a list of parcel uuids.
 */
private static boolean matchesServiceUuids(@Nullable final ParcelUuid uuid,
										   @Nullable final ParcelUuid parcelUuidMask,
										   @Nullable final List<ParcelUuid> uuids) {
	if (uuid == null) {
		return true;
	}
	if (uuids == null) {
		return false;
	}

	for (final ParcelUuid parcelUuid : uuids) {
		final UUID uuidMask = parcelUuidMask == null ? null : parcelUuidMask.getUuid();
		if (matchesServiceUuid(uuid.getUuid(), uuidMask, parcelUuid.getUuid())) {
			return true;
		}
	}
	return false;
}
 
Example 2
Source File: ScanFilterCompat.java    From AndroidBleManager with Apache License 2.0 6 votes vote down vote up
private boolean matchesServiceUuids(ParcelUuid uuid, ParcelUuid parcelUuidMask,
                                    List<ParcelUuid> uuids) {
    if (uuid == null) {
        return true;
    }
    if (uuids == null) {
        return false;
    }

    for (ParcelUuid parcelUuid : uuids) {
        UUID uuidMask = parcelUuidMask == null ? null : parcelUuidMask.getUuid();
        if (matchesServiceUuid(uuid.getUuid(), uuidMask, parcelUuid.getUuid())) {
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: ScanFilter.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
private static boolean matchesServiceUuids(ParcelUuid uuid, ParcelUuid parcelUuidMask,
                                           List<ParcelUuid> uuids) {
    if (uuid == null) {
        return true;
    }
    if (uuids == null) {
        return false;
    }

    for (ParcelUuid parcelUuid : uuids) {
        UUID uuidMask = parcelUuidMask == null ? null : parcelUuidMask.getUuid();
        if (matchesServiceUuid(uuid.getUuid(), uuidMask, parcelUuid.getUuid())) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: BluetoothUuid.java    From BLExplorer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise.
 */
public static boolean is16BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L);
}
 
Example 5
Source File: BluetoothUuidCompat.java    From AndroidBleManager with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 32 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 32 bit uuid, false otherwise.
 */
public static boolean is32BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    if (is16BitUuid(parcelUuid)) {
        return false;
    }
    return ((uuid.getMostSignificantBits() & 0xFFFFFFFFL) == 0x1000L);
}
 
Example 6
Source File: BluetoothUuidCompat.java    From AndroidBleManager with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise.
 */
public static boolean is16BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L);
}
 
Example 7
Source File: UuidFilterScanCallback.java    From BLE with Apache License 2.0 5 votes vote down vote up
@Override
public BluetoothLeDevice onFilter(BluetoothLeDevice bluetoothLeDevice) {
    BluetoothLeDevice tempDevice = null;
    if (bluetoothLeDevice != null && bluetoothLeDevice.getDevice() != null
            && bluetoothLeDevice.getDevice().getUuids() != null
            && bluetoothLeDevice.getDevice().getUuids().length > 0) {
        for (ParcelUuid parcelUuid : bluetoothLeDevice.getDevice().getUuids()) {
            if (uuid != null && uuid == parcelUuid.getUuid()) {
                tempDevice = bluetoothLeDevice;
            }
        }
    }
    return tempDevice;
}
 
Example 8
Source File: BluetoothUuid.java    From EFRConnect-android with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise.
 */
public static boolean is16BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L);
}
 
Example 9
Source File: AccessMessage.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected AccessMessage(final Parcel source) {
    super(source);
    final ParcelUuid parcelUuid = source.readParcelable(ParcelUuid.class.getClassLoader());
    if (parcelUuid != null) {
        label = parcelUuid.getUuid();
    }
    lowerTransportAccessPdu = readSparseArrayToParcelable(source);
    accessPdu = source.createByteArray();
    transportPdu = source.createByteArray();
}
 
Example 10
Source File: BluetoothUuid.java    From physical-web with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise.
 */
public static boolean is16BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    return (uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L;
}
 
Example 11
Source File: Group.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private UUID readVirtualLabelFromParcelable(Parcel in, final int address) {
    if (MeshAddress.isValidVirtualAddress(address)) {
        final ParcelUuid parcelUuid = in.readParcelable(ParcelUuid.class.getClassLoader());
        if (parcelUuid != null) {
            return parcelUuid.getUuid();
        }
    }
    return null;
}
 
Example 12
Source File: BluetoothUuid.java    From BLExplorer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 32 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 32 bit uuid, false otherwise.
 */
public static boolean is32BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    if (is16BitUuid(parcelUuid)) {
        return false;
    }
    return ((uuid.getMostSignificantBits() & 0xFFFFFFFFL) == 0x1000L);
}
 
Example 13
Source File: BluetoothUuid.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 32 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 32 bit uuid, false otherwise.
 */
public static boolean is32BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    if (is16BitUuid(parcelUuid)) {
        return false;
    }
    return ((uuid.getMostSignificantBits() & 0xFFFFFFFFL) == 0x1000L);
}
 
Example 14
Source File: BluetoothUuid.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise.
 */
public static boolean is16BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L);
}
 
Example 15
Source File: BluetoothCentralTest.java    From blessed-android with MIT License 4 votes vote down vote up
@Test
public void scanForPeripheralsWithServicesTest() throws Exception {
    application.grantPermissions(Manifest.permission.ACCESS_COARSE_LOCATION);
    UUID BLP_SERVICE_UUID = UUID.fromString("00001810-0000-1000-8000-00805f9b34fb");
    central.scanForPeripheralsWithServices(new UUID[]{BLP_SERVICE_UUID});

    // Make sure startScan is called
    ArgumentCaptor<List> scanFiltersCaptor = ArgumentCaptor.forClass(List.class);
    ArgumentCaptor<ScanSettings> scanSettingsCaptor = ArgumentCaptor.forClass(ScanSettings.class);
    ArgumentCaptor<ScanCallback> scanCallbackCaptor = ArgumentCaptor.forClass(ScanCallback.class);
    verify(scanner).startScan(scanFiltersCaptor.capture(), scanSettingsCaptor.capture(), scanCallbackCaptor.capture());

    // Verify there is only 1 filter set
    List<ScanFilter> filters = scanFiltersCaptor.getValue();
    assertEquals(1, filters.size());

    // Verify the filter contains the UUID we added
    ScanFilter uuidFilter = filters.get(0);
    ParcelUuid parcelUuid = uuidFilter.getServiceUuid();
    UUID uuid = parcelUuid.getUuid();
    assertEquals(BLP_SERVICE_UUID.toString(), uuid.toString());

    // Grab the scan callback that is used
    Field field = BluetoothCentral.class.getDeclaredField("scanByServiceUUIDCallback");
    field.setAccessible(true);
    ScanCallback scanCallback = (ScanCallback) field.get(central);

    // Fake scan result
    ScanResult scanResult = mock(ScanResult.class);
    BluetoothDevice device = mock(BluetoothDevice.class);
    when(device.getAddress()).thenReturn("00:00:00:00");
    when(scanResult.getDevice()).thenReturn(device);
    scanCallback.onScanResult(CALLBACK_TYPE_ALL_MATCHES, scanResult);

    // See if we get it back
    ArgumentCaptor<BluetoothPeripheral> bluetoothPeripheralCaptor = ArgumentCaptor.forClass(BluetoothPeripheral.class);
    ArgumentCaptor<ScanResult> scanResultCaptor = ArgumentCaptor.forClass(ScanResult.class);
    verify(callback).onDiscoveredPeripheral(bluetoothPeripheralCaptor.capture(), scanResultCaptor.capture());

    assertEquals(scanResultCaptor.getValue(), scanResult);
    assertEquals(bluetoothPeripheralCaptor.getValue().getAddress(), "00:00:00:00");
}
 
Example 16
Source File: BluetoothUuid.java    From BLExplorer with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Extract the Service Identifier or the actual uuid from the Parcel Uuid.
 * For example, if 0000110B-0000-1000-8000-00805F9B34FB is the parcel Uuid,
 * this function will return 110B
 *
 * @param parcelUuid
 * @return the service identifier.
 */
public static int getServiceIdentifierFromParcelUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    long value = (uuid.getMostSignificantBits() & 0x0000FFFF00000000L) >>> 32;
    return (int) value;
}
 
Example 17
Source File: BluetoothUuid.java    From physical-web with Apache License 2.0 2 votes vote down vote up
/**
 * Extract the Service Identifier or the actual uuid from the Parcel Uuid. For example, if
 * 0000110B-0000-1000-8000-00805F9B34FB is the parcel Uuid, this function will return 110B
 *
 * @param parcelUuid
 * @return the service identifier.
 */
public static int getServiceIdentifierFromParcelUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    long value = (uuid.getMostSignificantBits() & 0x0000FFFF00000000L) >>> 32;
    return (int) value;
}
 
Example 18
Source File: BluetoothUuidCompat.java    From AndroidBleManager with Apache License 2.0 2 votes vote down vote up
/**
 * Extract the Service Identifier or the actual uuid from the Parcel Uuid.
 * For example, if 0000110B-0000-1000-8000-00805F9B34FB is the parcel Uuid,
 * this function will return 110B
 *
 * @param parcelUuid
 * @return the service identifier.
 */
public static int getServiceIdentifierFromParcelUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    long value = (uuid.getMostSignificantBits() & 0x0000FFFF00000000L) >>> 32;
    return (int) value;
}
 
Example 19
Source File: BluetoothUuid.java    From EFRConnect-android with Apache License 2.0 2 votes vote down vote up
/**
 * Extract the Service Identifier or the actual uuid from the Parcel Uuid. For example, if
 * 0000110B-0000-1000-8000-00805F9B34FB is the parcel Uuid, this function will return 110B
 *
 * @param parcelUuid
 * @return the service identifier.
 */
public static int getServiceIdentifierFromParcelUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    long value = (uuid.getMostSignificantBits() & 0x0000FFFF00000000L) >>> 32;
    return (int) value;
}
 
Example 20
Source File: BluetoothUuid.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Extract the Service Identifier or the actual uuid from the Parcel Uuid.
 * For example, if 0000110B-0000-1000-8000-00805F9B34FB is the parcel Uuid,
 * this function will return 110B
 *
 * @param parcelUuid
 * @return the service identifier.
 */
public static int getServiceIdentifierFromParcelUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    long value = (uuid.getMostSignificantBits() & 0xFFFFFFFF00000000L) >>> 32;
    return (int) value;
}