Skip to content

Instantly share code, notes, and snippets.

@SureshotM6
Last active December 17, 2023 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SureshotM6/67ff45bef4d795ef7a21f8dba8d2af90 to your computer and use it in GitHub Desktop.
Save SureshotM6/67ff45bef4d795ef7a21f8dba8d2af90 to your computer and use it in GitHub Desktop.
Withings Health Mate 6.x infinite loop removal

This is a workaround for the Withings Health Mate battery drain issue described at:

Downsides

  • You'll need to uninstall the existing Withings app, meaning you'll lose any permission settings and will need to login again.
  • Google OAuth won't work, so you'll need to sign in with your Withings username/password.
  • If/when Withings fixes this, you'll need to manually uninstall your patched version (it won't auto-update).
  • On ScanWatch 2, some of these notifications won't be displayed on your watch. That would require a proper fix which is more complicated. This behavior is identical to the 6.0 app though.

Prerequisites

  • Ideally use Linux or install WSL
  • Install latest apktool
  • Install other required tools: sudo apt install patch apksigner zipalign
  • Create a dummy java keystore if you don't already have one:
keytool -genkey -v -keystore my-release-key.keystore -alias my_alias -keyalg RSA -keysize 2048 -validity 10000

Patching the infinite loop out of the APK

  • Download the latest Withings Health Mate APK (not a xapk / bundle)
  • Rename file to com.withings.wiscale2.apk
  • Run apktool d com.withings.wiscale2.apk
  • Find the smalli file containing DeviceImageFactory.java (it will be a different filename in each release due to obfusciation):
$ grep -rFl DeviceImageFactory.java com.withings.wiscale2
com.withings.wiscale2/smali_classes3/tj/b.smali
  • Patch this file with the attached patch: patch com.withings.wiscale2/smali_classes3/tj/b.smali < DeviceImageFactory.patch
  • Rebuild the APK: apktool b com.withings.wiscale2
  • zipalign and sign the APK:
zipalign -f -p 4 com.withings.wiscale2/dist/com.withings.wiscale2.apk healthmate_patched.apk
apksigner sign --ks my-release-key.keystore healthmate_patched.apk

Installing the patched APK

You will need to explicitly uninstall the stock Withings app since the signing keys are different. You can perform this step from the command line with adb if USB Debugging is enabled.

adb uninstall com.withings.wiscale2
adb install --user 0 healthmatch_patched.apk

You may want to disable auto-updates of the Withings app from the app store as well, although they will all fail due to the different signing keys. If Withings releases a 6.3 version that still has the bug, you can patch and upgrade directly without needing to uninstall your 6.1 or 6.2 patched version.

--- b.smali.orig 2023-12-17 13:53:09.394037975 -0600
+++ b.smali.new 2023-12-17 13:51:32.204035477 -0600
@@ -303,52 +303,14 @@
.line 6
const/4 v1, 0x0
- .line 7
- move v2, v1
-
.line 8
:cond_0
const/4 v3, 0x1
- .line 9
- add-int/2addr v2, v3
-
- .line 10
- int-to-float v4, v2
-
- .line 11
- invoke-virtual {p1, v4}, Landroid/graphics/Paint;->setTextSize(F)V
-
- .line 12
- .line 13
- .line 14
- invoke-virtual {p1, p0}, Landroid/graphics/Paint;->measureText(Ljava/lang/String;)F
-
- .line 15
- .line 16
- .line 17
- move-result v4
-
- .line 18
- int-to-float v5, p2
-
- .line 19
- cmpg-float v4, v4, v5
-
- .line 20
- .line 21
- if-ltz v4, :cond_0
-
.line 22
.line 23
const/4 v4, -0x1
- .line 24
- add-int/2addr v2, v4
-
- .line 25
- int-to-float v5, v2
-
.line 26
move p2, v1
@@ -393,14 +355,6 @@
.line 44
int-to-float p2, p2
- .line 45
- invoke-static {v5, p2}, Ljava/lang/Float;->min(FF)F
-
- .line 46
- .line 47
- .line 48
- move-result p2
-
.line 49
invoke-virtual {p1, p2}, Landroid/graphics/Paint;->setTextSize(F)V
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment