From 02dca611b0c3c03946f9c42d91bffe4ecdf1022a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Mon, 22 Aug 2022 23:53:38 +0100 Subject: [PATCH] Add companion device list to debug activity --- .../activities/DebugActivity.java | 35 +++++++++++++++++++ app/src/main/res/layout/activity_debug.xml | 8 +++++ 2 files changed, 43 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java index 7555eca97..dc03ce80e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java @@ -26,6 +26,7 @@ import android.app.DatePickerDialog; import android.app.PendingIntent; import android.appwidget.AppWidgetHost; import android.appwidget.AppWidgetManager; +import android.companion.CompanionDeviceManager; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -34,6 +35,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; @@ -68,6 +70,7 @@ import java.io.File; import java.io.Serializable; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -107,6 +110,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol; import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; +import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.WidgetPreferenceStorage; public class DebugActivity extends AbstractGBActivity { @@ -602,6 +606,37 @@ public class DebugActivity extends AbstractGBActivity { } }); + Button showCompanionDevices = findViewById(R.id.showCompanionDevices); + showCompanionDevices.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? View.VISIBLE : View.GONE); + showCompanionDevices.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + LOG.warn("Android version < O, companion devices not supported"); + return; + } + + final CompanionDeviceManager manager = (CompanionDeviceManager) GBApplication.getContext().getSystemService(Context.COMPANION_DEVICE_SERVICE); + final List associations = new ArrayList<>(manager.getAssociations()); + Collections.sort(associations); + String companionDevicesList = String.format(Locale.ROOT, "%d companion devices", associations.size()); + if (!associations.isEmpty()) { + companionDevicesList += "\n\n" + StringUtils.join("\n", associations.toArray(new String[0])); + } + + new AlertDialog.Builder(DebugActivity.this) + .setCancelable(false) + .setTitle("Companion Devices") + .setMessage(companionDevicesList) + .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }) + .show(); + } + }); + Button showStatusFitnessAppTracking = findViewById(R.id.showStatusFitnessAppTracking); final int delay = 2 * 1000; diff --git a/app/src/main/res/layout/activity_debug.xml b/app/src/main/res/layout/activity_debug.xml index 9de38248b..c95d42cb0 100644 --- a/app/src/main/res/layout/activity_debug.xml +++ b/app/src/main/res/layout/activity_debug.xml @@ -272,6 +272,14 @@ android:text="@string/pref_device_action_phone_gps_location_listener_stop" grid:layout_columnSpan="2" grid:layout_gravity="fill_horizontal" /> + +