From eb7646d26afdcaa22680b166a4a110016bf85303 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Wed, 9 Nov 2016 19:20:37 +0100 Subject: [PATCH] Pebble: Fix vanished Health system apps (for affected users) This code also allows us to add new system apps which will then appended to the current list of previous Gadgetbridge users. --- .../AbstractAppManagerFragment.java | 42 ++++++++----------- .../appmanager/AppManagerFragmentCache.java | 7 ++++ .../AppManagerFragmentInstalledApps.java | 30 ++++++++----- ...AppManagerFragmentInstalledWatchfaces.java | 19 ++++----- 4 files changed, 51 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java index 95a1b76a4..bd4670c3f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java @@ -46,7 +46,7 @@ public abstract class AbstractAppManagerFragment extends Fragment { = "nodomain.freeyourgadget.gadgetbridge.appmanager.action.refresh_applist"; private static final Logger LOG = LoggerFactory.getLogger(AbstractAppManagerFragment.class); - protected abstract void refreshList(); + protected abstract List getSystemAppsInCategory(); protected abstract String getSortFilename(); @@ -62,6 +62,23 @@ public abstract class AbstractAppManagerFragment extends Fragment { AppManagerActivity.rewriteAppOrderFile(getSortFilename(), uuidList); } + protected void refreshList() { + appList.clear(); + ArrayList uuids = AppManagerActivity.getUuidsFromFile(getSortFilename()); + List systemApps = getSystemAppsInCategory(); + boolean needsRewrite = false; + for (GBDeviceApp systemApp : systemApps) { + if (!uuids.contains(systemApp.getUUID())) { + uuids.add(systemApp.getUUID()); + needsRewrite = true; + } + } + if (needsRewrite) { + AppManagerActivity.rewriteAppOrderFile(getSortFilename(), uuids); + } + appList.addAll(getCachedApps(uuids)); + } + private void refreshListFromPebble(Intent intent) { appList.clear(); int appCount = intent.getIntExtra("app_count", 0); @@ -103,29 +120,6 @@ public abstract class AbstractAppManagerFragment extends Fragment { private GBDeviceAppAdapter mGBDeviceAppAdapter; protected GBDevice mGBDevice = null; - protected List getSystemApps() { - List systemApps = new ArrayList<>(); - //systemApps.add(new GBDeviceApp(UUID.fromString("4dab81a6-d2fc-458a-992c-7a1f3b96a970"), "Sports (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); - //systemApps.add(new GBDeviceApp(UUID.fromString("cf1e816a-9db0-4511-bbb8-f60c48ca8fac"), "Golf (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); - systemApps.add(new GBDeviceApp(UUID.fromString("1f03293d-47af-4f28-b960-f2b02a6dd757"), "Music (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); - systemApps.add(new GBDeviceApp(UUID.fromString("b2cae818-10f8-46df-ad2b-98ad2254a3c1"), "Notifications (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); - systemApps.add(new GBDeviceApp(UUID.fromString("67a32d95-ef69-46d4-a0b9-854cc62f97f9"), "Alarms (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); - systemApps.add(new GBDeviceApp(UUID.fromString("18e443ce-38fd-47c8-84d5-6d0c775fbe55"), "Watchfaces (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); - - if (mGBDevice != null && !"aplite".equals(PebbleUtils.getPlatformName(mGBDevice.getModel()))) { - systemApps.add(new GBDeviceApp(UUID.fromString("0863fc6a-66c5-4f62-ab8a-82ed00a98b5d"), "Send Text (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); - systemApps.add(new GBDeviceApp(PebbleProtocol.UUID_PEBBLE_HEALTH, "Health (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); - } - - return systemApps; - } - - protected List getSystemWatchfaces() { - List systemWatchfaces = new ArrayList<>(); - systemWatchfaces.add(new GBDeviceApp(UUID.fromString("8f3c8686-31a1-4f5f-91f5-01600c9bdc59"), "Tic Toc (System)", "Pebble Inc.", "", GBDeviceApp.Type.WATCHFACE_SYSTEM)); - return systemWatchfaces; - } - protected List getCachedApps(List uuids) { List cachedAppList = new ArrayList<>(); File cachePath; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentCache.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentCache.java index fbf42e94d..8423ffbe8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentCache.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentCache.java @@ -1,5 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities.appmanager; +import java.util.List; + import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp; public class AppManagerFragmentCache extends AbstractAppManagerFragment { @@ -14,6 +16,11 @@ public class AppManagerFragmentCache extends AbstractAppManagerFragment { return true; } + @Override + protected List getSystemAppsInCategory() { + return null; + } + @Override public String getSortFilename() { return "pbwcacheorder.txt"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentInstalledApps.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentInstalledApps.java index d968f713f..d49e9e21a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentInstalledApps.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentInstalledApps.java @@ -1,23 +1,31 @@ package nodomain.freeyourgadget.gadgetbridge.activities.appmanager; import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp; +import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol; +import nodomain.freeyourgadget.gadgetbridge.util.PebbleUtils; public class AppManagerFragmentInstalledApps extends AbstractAppManagerFragment { + @Override - protected void refreshList() { - appList.clear(); - ArrayList uuids = AppManagerActivity.getUuidsFromFile(getSortFilename()); - if (uuids.isEmpty()) { - appList.addAll(getSystemApps()); - for (GBDeviceApp gbDeviceApp : appList) { - uuids.add(gbDeviceApp.getUUID()); - } - AppManagerActivity.rewriteAppOrderFile(getSortFilename(), uuids); - } else { - appList.addAll(getCachedApps(uuids)); + protected List getSystemAppsInCategory() { + List systemApps = new ArrayList<>(); + //systemApps.add(new GBDeviceApp(UUID.fromString("4dab81a6-d2fc-458a-992c-7a1f3b96a970"), "Sports (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); + //systemApps.add(new GBDeviceApp(UUID.fromString("cf1e816a-9db0-4511-bbb8-f60c48ca8fac"), "Golf (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); + systemApps.add(new GBDeviceApp(UUID.fromString("1f03293d-47af-4f28-b960-f2b02a6dd757"), "Music (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); + systemApps.add(new GBDeviceApp(UUID.fromString("b2cae818-10f8-46df-ad2b-98ad2254a3c1"), "Notifications (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); + systemApps.add(new GBDeviceApp(UUID.fromString("67a32d95-ef69-46d4-a0b9-854cc62f97f9"), "Alarms (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); + systemApps.add(new GBDeviceApp(UUID.fromString("18e443ce-38fd-47c8-84d5-6d0c775fbe55"), "Watchfaces (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); + + if (mGBDevice != null && !"aplite".equals(PebbleUtils.getPlatformName(mGBDevice.getModel()))) { + systemApps.add(new GBDeviceApp(UUID.fromString("0863fc6a-66c5-4f62-ab8a-82ed00a98b5d"), "Send Text (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); + systemApps.add(new GBDeviceApp(PebbleProtocol.UUID_PEBBLE_HEALTH, "Health (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); } + + return systemApps; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentInstalledWatchfaces.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentInstalledWatchfaces.java index 289c6656c..a0df8d893 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentInstalledWatchfaces.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerFragmentInstalledWatchfaces.java @@ -1,23 +1,18 @@ package nodomain.freeyourgadget.gadgetbridge.activities.appmanager; import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp; public class AppManagerFragmentInstalledWatchfaces extends AbstractAppManagerFragment { + @Override - protected void refreshList() { - appList.clear(); - ArrayList uuids = AppManagerActivity.getUuidsFromFile(getSortFilename()); - if (uuids.isEmpty()) { - appList.addAll(getSystemWatchfaces()); - for (GBDeviceApp gbDeviceApp : appList) { - uuids.add(gbDeviceApp.getUUID()); - } - AppManagerActivity.rewriteAppOrderFile(getSortFilename(), uuids); - } else { - appList.addAll(getCachedApps(uuids)); - } + protected List getSystemAppsInCategory() { + List systemWatchfaces = new ArrayList<>(); + systemWatchfaces.add(new GBDeviceApp(UUID.fromString("8f3c8686-31a1-4f5f-91f5-01600c9bdc59"), "Tic Toc (System)", "Pebble Inc.", "", GBDeviceApp.Type.WATCHFACE_SYSTEM)); + return systemWatchfaces; } @Override