use of android.companion.CompanionDeviceManager in project robolectric by robolectric.
the class ShadowCompanionDeviceManagerTest method setUp.
@Before
public void setUp() throws Exception {
companionDeviceManager = getApplicationContext().getSystemService(CompanionDeviceManager.class);
shadowCompanionDeviceManager = shadowOf(companionDeviceManager);
componentName = new ComponentName(getApplicationContext(), Application.class);
}
use of android.companion.CompanionDeviceManager in project Gadgetbridge by Freeyourgadget.
the class BondingUtil method companionDeviceManagerBond.
/**
* Uses the CompanionDeviceManager bonding method
*/
@RequiresApi(Build.VERSION_CODES.O)
private static void companionDeviceManagerBond(BondingInterface bondingInterface, final GBDeviceCandidate deviceCandidate) {
BluetoothDeviceFilter deviceFilter = new BluetoothDeviceFilter.Builder().setAddress(deviceCandidate.getMacAddress()).build();
AssociationRequest pairingRequest = new AssociationRequest.Builder().addDeviceFilter(deviceFilter).setSingleDevice(true).build();
CompanionDeviceManager manager = (CompanionDeviceManager) bondingInterface.getContext().getSystemService(Context.COMPANION_DEVICE_SERVICE);
LOG.debug(String.format("Searching for %s associations", deviceCandidate.getMacAddress()));
for (String association : manager.getAssociations()) {
LOG.debug(String.format("Already associated with: %s", association));
if (association.equals(deviceCandidate.getMacAddress())) {
LOG.info("The device has already been bonded through CompanionDeviceManager, using regular");
// If it's already "associated", we should immediately pair
// because the callback is never called (AFAIK?)
BondingUtil.bluetoothBond(bondingInterface, deviceCandidate);
return;
}
}
LOG.debug("Starting association request");
manager.associate(pairingRequest, getCompanionDeviceManagerCallback(bondingInterface), null);
}
use of android.companion.CompanionDeviceManager in project Gadgetbridge by Freeyourgadget.
the class AbstractDeviceSupport method handleGBDeviceEventFindPhoneStartNotification.
@RequiresApi(Build.VERSION_CODES.Q)
private void handleGBDeviceEventFindPhoneStartNotification() {
LOG.info("Got handleGBDeviceEventFindPhoneStartNotification");
Intent intent = new Intent(context, FindPhoneActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID).setSmallIcon(R.drawable.ic_notification).setOngoing(false).setFullScreenIntent(pi, true).setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true).setContentTitle(context.getString(R.string.find_my_phone_notification));
notification.setGroup("BackgroundService");
CompanionDeviceManager manager = (CompanionDeviceManager) context.getSystemService(Context.COMPANION_DEVICE_SERVICE);
if (manager.getAssociations().size() > 0) {
GB.notify(GB.NOTIFICATION_ID_PHONE_FIND, notification.build(), context);
context.startActivity(intent);
LOG.debug("CompanionDeviceManager associations were found, starting intent");
} else {
GB.notify(GB.NOTIFICATION_ID_PHONE_FIND, notification.build(), context);
LOG.warn("CompanionDeviceManager associations were not found, can't start intent");
}
}
Aggregations