NightscoutFoundation / xDrip

Nightscout version of xDrip+
https://jamorham.github.io/#xdrip-plus
GNU General Public License v3.0
1.4k stars 1.14k forks source link

Make xDrip compatible with latest Full Android Smartwatches #1972

Closed parapenT1sta closed 2 years ago

parapenT1sta commented 2 years ago

As per discussed on this topic, xDrip is detecting Full Android Smartwaches as Android Wear (wearOS) Smartwaches and Bluetooth Service stops after smartwatches are wrongly detected.

I have compiled a version with @tolot27 code suggestion and shared on xDrip Facebook group and this is the list of watches tested and confirmed the fix:

The patch applied on app/src/main/java/com/eveningoutpost/dexdrip/Services/Ob1G5CollectionService.java: Line 972 Before: android_wear = (getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_WATCH; After: android_wear = getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH); Adding at the top of the file: import android.content.pm.PackageManager;

The patch applied on app/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java: Lines 821 - 829 Before:

    @SuppressLint("ObsoleteSdkInt")
    private static boolean shouldServiceRun() {
        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) return false;
        final boolean result = (DexCollectionType.hasXbridgeWixel() || DexCollectionType.hasBtWixel())
                && ((!Home.get_forced_wear() && (((UiModeManager) xdrip.getAppContext().getSystemService(UI_MODE_SERVICE)).getCurrentModeType() != Configuration.UI_MODE_TYPE_WATCH))
                || PersistentStore.getBoolean(CollectionServiceStarter.pref_run_wear_collector));
        if (d) Log.d(TAG, "shouldServiceRun() returning: " + result);
        return result;
    }

After:

    @SuppressLint("ObsoleteSdkInt")
    private boolean shouldServiceRun() {
        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) return false;
        final boolean result = (DexCollectionType.hasXbridgeWixel() || DexCollectionType.hasBtWixel())
                && ((!Home.get_forced_wear() && !getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH))
                || PersistentStore.getBoolean(CollectionServiceStarter.pref_run_wear_collector));
        if (d) Log.d(TAG, "shouldServiceRun() returning: " + result);
        return result;
    }

Adding at the top of the file: import android.content.pm.PackageManager;

Files changed:

Files where Configuration.UI_MODE_TYPE_WATCH is present: https://github.com/NightscoutFoundation/xDrip/search?q=Configuration.UI_MODE_TYPE_WATCH

Navid200 commented 2 years ago

@parapenT1sta Where you asked to open an issue?