1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-09 03:37:03 +01:00

Display warning on find phone without companion pairing

This commit is contained in:
José Rebelo 2024-08-04 14:10:11 +01:00
parent bf6d0d0f83
commit 60d5a2ae70
2 changed files with 30 additions and 16 deletions

View File

@ -292,32 +292,45 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
@RequiresApi(Build.VERSION_CODES.Q) @RequiresApi(Build.VERSION_CODES.Q)
private void handleGBDeviceEventFindPhoneStartNotification(final boolean ring) { private void handleGBDeviceEventFindPhoneStartNotification(final boolean ring) {
LOG.info("Got handleGBDeviceEventFindPhoneStartNotification"); LOG.info("Got handleGBDeviceEventFindPhoneStartNotification");
Intent intent = new Intent(context, FindPhoneActivity.class); final CompanionDeviceManager manager = (CompanionDeviceManager) context.getSystemService(Context.COMPANION_DEVICE_SERVICE);
if (manager.getAssociations().isEmpty()) {
// On Android Q and above, we need the device to be paired as companion. If it is not, display a notification
// notifying the user and linking to further instructions
final Intent instructionsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://gadgetbridge.org/basics/pairing/companion-device/"));
final PendingIntent pi = PendingIntentUtils.getActivity(context, 0, instructionsIntent, PendingIntent.FLAG_ONE_SHOT, false);
final NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID)
.setSmallIcon(R.drawable.ic_warning)
.setOngoing(false)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pi)
.setAutoCancel(true)
.setContentTitle(context.getString(R.string.find_my_phone_notification))
.setContentText(context.getString(R.string.find_my_phone_companion_warning));
GB.notify(GB.NOTIFICATION_ID_PHONE_FIND, notification.build(), context);
return;
}
final Intent intent = new Intent(context, FindPhoneActivity.class);
intent.setPackage(BuildConfig.APPLICATION_ID); intent.setPackage(BuildConfig.APPLICATION_ID);
intent.putExtra(FindPhoneActivity.EXTRA_RING, ring); intent.putExtra(FindPhoneActivity.EXTRA_RING, ring);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntentUtils.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, false); final PendingIntent pi = PendingIntentUtils.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, false);
NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID ) final NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID)
.setSmallIcon(R.drawable.ic_notification) .setSmallIcon(R.drawable.ic_notification)
.setOngoing(false) .setOngoing(false)
.setFullScreenIntent(pi, true) .setFullScreenIntent(pi, true)
.setPriority(NotificationCompat.PRIORITY_HIGH) .setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true) .setAutoCancel(true)
.setContentTitle( context.getString( R.string.find_my_phone_notification ) ); .setGroup("BackgroundService")
.setContentTitle(context.getString(R.string.find_my_phone_notification));
notification.setGroup("BackgroundService"); GB.notify(GB.NOTIFICATION_ID_PHONE_FIND, notification.build(), context);
context.startActivity(intent);
CompanionDeviceManager manager = (CompanionDeviceManager) context.getSystemService(Context.COMPANION_DEVICE_SERVICE); LOG.debug("CompanionDeviceManager associations were found, starting intent");
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");
}
} }
@ -1218,7 +1231,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
@Override @Override
public void onSleepAsAndroidAction(String action, Bundle extras) { public void onSleepAsAndroidAction(String action, Bundle extras) {
} }
@Override @Override

View File

@ -598,6 +598,7 @@
<string name="test_notification">Test notification</string> <string name="test_notification">Test notification</string>
<string name="this_is_a_test_notification_from_gadgetbridge">This is a test notification from Gadgetbridge</string> <string name="this_is_a_test_notification_from_gadgetbridge">This is a test notification from Gadgetbridge</string>
<string name="find_my_phone_notification">Find my phone</string> <string name="find_my_phone_notification">Find my phone</string>
<string name="find_my_phone_companion_warning">Companion pairing is required for find phone. Click here for more information.</string>
<string name="bluetooth_is_not_supported_">Bluetooth is not supported.</string> <string name="bluetooth_is_not_supported_">Bluetooth is not supported.</string>
<string name="bluetooth_is_disabled_">Bluetooth is disabled.</string> <string name="bluetooth_is_disabled_">Bluetooth is disabled.</string>
<string name="tap_connected_device_for_app_mananger">Tap connected device for App manager</string> <string name="tap_connected_device_for_app_mananger">Tap connected device for App manager</string>