diff --git a/README.md b/README.md index 052cf864..aee2ee84 100644 --- a/README.md +++ b/README.md @@ -545,6 +545,11 @@ the problem and tap **Export .txt**. Attach the file to the issue. - **Cause:** the patch engine called a Java method that only exists from Android 13 on, and only the Samsung Health+ build reaches it. The tests run on Android 13 and newer, so they did not catch it. Confirmed on a Xiaomi phone with MIUI 13 (Android 12). - **Status:** fixed in 0.11.7, and the build now also checks the engine against Android 12. An affected user still needs to report that the build works. - **Workaround (before 0.11.7):** leave Samsung Health+ out; the other apps still build. +- :construction: **Samsung Health+ 7.2.0.041 asks for a Samsung Account even with the Local-only option** ([#32](https://github.com/LibreStatic/LibreWrist/issues/32)) + - **Cause:** this version checks for an account in more places during first-run setup. The Local-only patch only covered the first one. Without an account, setup shows the sign-in screen again after **Start**, closes with "Server error occurred (0x2F#131072)", or keeps spinning. Reproduced on an emulator. + - **Status:** the fix is in progress. It covers each of those checks and was tested from first-run setup to the dashboard with no account. +- :mag: **Blood pressure calibration fails at 99% with an SQI error on the Galaxy Watch8 Classic** ([#42](https://github.com/LibreStatic/LibreWrist/issues/42)) + - **Cause:** not known yet. The log shows that the watch delivers optical heart sensor data during the calibration, but it flags every sample as unusable, and the values look different from those of watches where blood pressure works. A test build that logs the raw sensor data is linked in the issue. [↑ Back to contents](#contents) diff --git a/catalogue/catalogue.json b/catalogue/catalogue.json index be9f52fa..29c9a01a 100644 --- a/catalogue/catalogue.json +++ b/catalogue/catalogue.json @@ -1,6 +1,6 @@ { "schema": 2, - "serial": 64, + "serial": 65, "minAppVersion": 45, "inputs": [ { @@ -2347,7 +2347,7 @@ "shealth-phone" ], "title": "Local-only mode (no Samsung Account)", - "description": "The SamsungAccountManager state getter (j3x.s0 in 7.2.0.041) reports LOG_IN, so the mandatory sign-in stop state right after OOBE never fires; the app runs account-less with no cloud sync", + "description": "The SamsungAccountManager state getter (j3x.s0 in 7.2.0.041) reports LOG_IN, so the mandatory sign-in stop state right after OOBE never fires, and the first-run wizard's two sign-in checks (HomeOobeUtil: the suspend t4g.n used by the welcome screen and the synchronous t4g.m used by each wizard screen's onResume) report that no sign-in is needed, so the wizard never opens the Samsung Account sign-in screen, and the wizard's Korean old-child account check (KcbOldChildResult) always reports that the account info was read with no error, so the wizard does not close with a server error (0x2F#131072) for lack of an account, and the consent init step (OobeConsentInitHandler) takes its \"Cms Already initialized\" branch, so the wizard does not wait forever for an account-bound consent sync; the app runs account-less with no cloud sync", "optional": true, "offByDefault": true, "ops": [ @@ -2367,6 +2367,75 @@ "SamsungAccountManager$State;->LOG_OUT:", "\"getContext(...)\"" ] + }, + { + "op": "setMethodBody", + "fileAll": [ + "\"SHEALTH#HomeOobeUtil\"" + ], + "sigRegex": "public final \\w+\\(Landroid/app/Activity;L\\w+;\\)Ljava/lang/Object;", + "body": [ + " .locals 0", + "", + " sget-object p0, Ljava/lang/Boolean;->FALSE:Ljava/lang/Boolean;", + "", + " return-object p0" + ], + "expect": 1, + "bodyAll": [ + "SamsungAccountUtils.isDeviceSignInSamsungAccountAsync" + ] + }, + { + "op": "setMethodBody", + "fileAll": [ + "\"SHEALTH#HomeOobeUtil\"" + ], + "sigRegex": "public static \\w+\\(\\)Z", + "body": [ + " .locals 1", + "", + " const/4 v0, 0x0", + "", + " return v0" + ], + "expect": 1, + "bodyAll": [ + "SamsungAccountUtils;->isDeviceSignInSamsungAccount(Landroid/content/Context;)Z" + ] + }, + { + "op": "insertInMethodAtMatch", + "fileAll": [ + "\"KcbOldChildResult(isCheckingSaInfoSuccess=\"" + ], + "sigRegex": "public constructor \\(IZZ\\)V", + "pattern": "(?P iput-boolean p2, p0, L\\w+;->\\w+:Z\\n)", + "insert": [ + " const/4 p1, 0x0", + "", + " const/4 p2, 0x1", + "", + "" + ], + "expect": 1 + }, + { + "op": "insertInMethodAtMatch", + "fileAll": [ + "\"Check Cms Flow\"" + ], + "sigRegex": "public final \\w+\\(L\\w+;\\)V", + "bodyAll": [ + "\"Cms Already initialized\"" + ], + "pattern": "(?P) if-eqz v0, :\\w+\\n\\n const-string v0, \"Cms Already initialized\"", + "insert": [ + " const/4 v0, 0x1", + "", + "" + ], + "expect": 1 } ] }, diff --git a/catalogue/catalogue.json.sig b/catalogue/catalogue.json.sig index 256bb545..2e801d6e 100644 Binary files a/catalogue/catalogue.json.sig and b/catalogue/catalogue.json.sig differ diff --git a/docs/patches.md b/docs/patches.md index 1d14557b..5d78c3f5 100644 --- a/docs/patches.md +++ b/docs/patches.md @@ -465,7 +465,7 @@ app that started the sign-in. | 10b | `shealth-capability-gates` *(optional, China build 7.00.6.012 only)* | the 7.00.x form of row 10: every inlined `service_capability_list` check (`getServiceList` + `List.contains`; 3 sites on 7.00.6.011: Vitals `xvx.J0`, Training load `t950`, fitness index `xao`) is forced true, and the per-sleep Vitals device check (`xvx.K0` on 7.00.6.011, a historical name; `wvo.Q` on the China build) returns `TRUE` | Same reason as row 10 | | 11 | `shealth-shm-providers` | the `content://com.samsung.android.shealthmonitor.sleep` and `.bp` URIs and the two `uses-permission` entries guarding them (`sleep.READ_SLEEP_APNEA_STATUS`, `bp.READ_MEASURE_FLAG`) -> `com.samsung.android.shealthmonitors.*` | The phone Health Monitor is renamed (`phone-rebrand-gms`), so Samsung Health+ asked a provider that does not exist and showed no Sleep apnea card under Sleep. Pairs with `shm-provider-callers` on the Health Monitor side | | 12 | `shealth-launcher-badge` *(optional)* | `adaptiveIconBadge`: the adaptive icons (8 on 7.2.0.041 (9 on 7.00.6.011): app icon plus widget and shortcut icons; 12 on the China build, which keeps 3 unused `mipmap-anydpi*/ic_launcher*` copies) get a small LibreWrist badge at the bottom-right of the foreground layer and, for the app icon, of the monochrome (themed) layer | The renamed copy installs next to the stock app and would otherwise look identical in the launcher | -| 13 | `shealth-oobe-local` *(optional, off by default)* | the Samsung Account state getter (`j3x.s0` in 7.2.0.041; `j9v.s0` in 7.00.6.011) reports `LOG_IN`, so the mandatory sign-in stop state right after OOBE never fires | For running the app without a Samsung Account; the first-run wizard itself has no sign-in step, this only removes the gate after it. Off by default: cloud sign-in is expected to work on the re-signed copy (the code has no signature gate); enable it (or flip `offByDefault` in the catalogue) if sign-in does not work on this device | +| 13 | `shealth-oobe-local` *(optional, off by default)* | five ops: (1) the Samsung Account state getter (`j3x.s0` in 7.2.0.041; `j9v.s0` in 7.00.6.011) reports `LOG_IN`, so the mandatory sign-in stop state right after OOBE never fires; (2) the first-run wizard's async sign-in check (`t4g.n` in 7.2.0.041, the suspend method of `HomeOobeUtil` that calls `SamsungAccountUtils.isDeviceSignInSamsungAccountAsync`) returns `false`, so the welcome screen does not send `SA_MANDATORY_GUIDE` to `HomeSaSignInActivity`; (3) its synchronous twin (`t4g.m`, the static `()Z` method of `HomeOobeUtil` that calls `SamsungAccountUtils.isDeviceSignInSamsungAccount`) returns `false`, so the `onResume` of each wizard screen does not open the sign-in screen again; (4) the `KcbOldChildResult(IZZ)` constructor (`bqi` in 7.2.0.041) stores code `0` and `isCheckingSaInfoSuccess=true`, so the Korean old-child account check does not close the app with "Server error occurred (0x2F#131072)" for lack of an account (the Korean-child flag itself is kept); (5) the consent step (`OobeConsentInitHandler`, `d9p` in 7.2.0.041) takes its "Cms Already initialized" branch and goes on to the next step, because with no account its consent sync from the server returns without a result and the wizard stays on a spinner (the app still asks for the local consents, such as location processing, and the terms state moves to `NOT_NEEDED` when the wizard finishes) | For running the app without a Samsung Account. In 7.2.0.041 the wizard checks for an account in three more places than the state getter ([#32](https://github.com/LibreStatic/LibreWrist/issues/32)): with only op 1 it opens the sign-in screen from its welcome screen, without op 3 it reopens the sign-in screen in a loop after **Start**, without op 4 it stops on the server error, and without op 5 it stays on a spinner. Tested end to end on an API 31 emulator with no Samsung Account: the wizard reaches the dashboard, and a cold start goes straight to it. Off by default: cloud sign-in is expected to work on the re-signed copy (the code has no signature gate); enable it (or flip `offByDefault` in the catalogue) if sign-in does not work on this device | | 14 | `shealth-china-account-gate` *(optional, off by default, experimental)* | regional check disabled: in the two post-sign-in OOBE paths that log `Global APK, China SACC, NO Smart Switch` (the `HomeOobeWelcomeFragment` coroutine and `HomeOobeWelcomeSplashFragment`, 2 sites on 7.2.x), the result of the account-country check (account country == `CN`) that precedes the Smart Switch restore check is forced false (`insertInMethodAtMatch`, `expect` 2), so the app no longer opens `HomeAppCloseActivity` with `OOBE_GLOBAL_APK_CHINA_SACC_APP_CLOSE` ("phone must be purchased in the country/region where your Samsung account was created") | The international build closes itself for a Samsung Account registered in mainland China ([#8](https://github.com/LibreStatic/LibreWrist/issues/8)). Only the OOBE call sites are touched: the account-country check (`ozn.Y` in 7.00.6.011) had ~20 other callers that switch China-account features (count from the 7.00.6.011 analysis). Experimental: the China/international server split is the build flavor (`fs90.u()` in 7.00.6.011, fixed at compile time), so this build keeps talking to the international servers and cloud sync for a CN account may not work; the real fix is a China build input | Anchors: semantic method names and literals of the official APK (`isEnabled()Z`, `L1()Z`, diff --git a/patcher-app/app/build.gradle.kts b/patcher-app/app/build.gradle.kts index 319c150a..f49ecba2 100644 --- a/patcher-app/app/build.gradle.kts +++ b/patcher-app/app/build.gradle.kts @@ -29,7 +29,7 @@ android { val catalogueMinApp = Regex("\"minAppVersion\":\\s*(\\d+)") .find(rootProject.file("../catalogue/catalogue.json").readText())?.groupValues?.get(1)?.toInt() ?: 1 versionCode = System.getenv("PATCHER_VERSION_CODE")?.toIntOrNull() ?: catalogueMinApp - versionName = "0.11.7" + versionName = "0.11.8" // Base URL of the raw `catalogue/` directory of the public repository (config.env CATALOGUE_URL, // or -PcatalogueUrl). Empty disables catalogue updates. Only https is accepted. val catalogueUrl = (providers.gradleProperty("catalogueUrl").orNull ?: System.getenv("CATALOGUE_URL") ?: "").trim() diff --git a/patcher-app/app/src/test/kotlin/io/openshm/patcher/AppCatalogueTest.kt b/patcher-app/app/src/test/kotlin/io/openshm/patcher/AppCatalogueTest.kt index 906d54c5..c65ed589 100644 --- a/patcher-app/app/src/test/kotlin/io/openshm/patcher/AppCatalogueTest.kt +++ b/patcher-app/app/src/test/kotlin/io/openshm/patcher/AppCatalogueTest.kt @@ -15,7 +15,7 @@ class AppCatalogueTest { @Test fun serialAndInputs() { - assertEquals(64L, c.serial) + assertEquals(65L, c.serial) assertEquals("chinaFrom / obtain.yyb need CI run 45", 45L, c.engine.minAppVersion) assertEquals( listOf( diff --git a/patcher-app/engine/src/test/kotlin/io/openshm/patcher/engine/CatalogueTest.kt b/patcher-app/engine/src/test/kotlin/io/openshm/patcher/engine/CatalogueTest.kt index 984d2330..3cf4669b 100644 --- a/patcher-app/engine/src/test/kotlin/io/openshm/patcher/engine/CatalogueTest.kt +++ b/patcher-app/engine/src/test/kotlin/io/openshm/patcher/engine/CatalogueTest.kt @@ -323,7 +323,249 @@ class CatalogueTest { assertEquals(patched, f.smali.get(path)) } + /** Local-only mode also answers the first-run wizard's two sign-in checks with false, so + * neither the welcome screen nor the onResume of a wizard screen opens the Samsung Account + * sign-in screen (issue #32). Only the two checks are replaced, the other HomeOobeUtil methods + * stay, and both verify after apply. Applying them again is not covered: the body anchors are + * gone once applied, as for the state getter op. */ + @Test fun oobeLocalWizardChecksApplyAndVerify() { + @Suppress("UNCHECKED_CAST") + val patterns = (Json.parse(String(catalogueBytes)) as Map)["patterns"] as Map + @Suppress("UNCHECKED_CAST") + val ops = (patterns["shealth-oobe-local"] as Map)["ops"] as List> + assertEquals(5, ops.size) + val path = "smali/t4g.smali" + val f = Fixture() + f.smali.put(path, OOBE_UTIL_SMALI) + val prepared = ops.subList(1, 3).map { OpRegistry.prepare(it["op"] as String, it - "op") } + for (op in prepared) assertEquals(1, op.apply(f.ctx).size) + val patched = f.smali.get(path)!! + assertFalse("isDeviceSignInSamsungAccount" in patched) + assertTrue("n(Landroid/app/Activity;Lv06;)Ljava/lang/Object;\n .locals 0\n\n" + + " sget-object p0, Ljava/lang/Boolean;->FALSE:Ljava/lang/Boolean;\n\n return-object p0\n.end method" in patched) + assertTrue("m()Z\n .locals 1\n\n const/4 v0, 0x0\n\n return v0\n.end method" in patched) + assertTrue("b(Landroid/app/Activity;Lv06;)Ljava/lang/Object;\n .locals 1" in patched) + assertTrue("l()Z\n .locals 1\n\n invoke-static {}, Ls990;->T()Z" in patched) + for (op in prepared) assertEquals(1, op.verifyApplied(f.ctx).size) + } + + /** Local-only mode makes every Korean old-child account check result report that the account + * info was read with no error, so the wizard goes on to the consents instead of closing with + * a server error when there is no Samsung Account (issue #32). The Korean-child flag is kept, + * and the other constructor is not touched. Applying it again changes nothing. */ + @Test fun oobeLocalKcbResultAppliesAndIsIdempotent() { + @Suppress("UNCHECKED_CAST") + val patterns = (Json.parse(String(catalogueBytes)) as Map)["patterns"] as Map + @Suppress("UNCHECKED_CAST") + val step = ((patterns["shealth-oobe-local"] as Map)["ops"] as List>)[3] + val path = "smali_classes4/bqi.smali" + val f = Fixture() + f.smali.put(path, KCB_RESULT_SMALI) + val op = OpRegistry.prepare(step["op"] as String, step - "op") + assertEquals(1, op.apply(f.ctx).size) + val patched = f.smali.get(path)!! + assertTrue(" .line 3\n const/4 p1, 0x0\n\n const/4 p2, 0x1\n\n iput-boolean p2, p0, Lbqi;->a:Z\n" in patched) + assertTrue(" iput-boolean p3, p0, Lbqi;->c:Z" in patched) + assertEquals(1, Regex("const/4 p2, 0x1").findAll(patched).count()) + assertTrue("(IIZ)V\n .locals 0\n\n and-int/lit8 p2, p2, 0x2" in patched) + assertEquals(1, op.verifyApplied(f.ctx).size) + val rebuilt = PatchContext(CanonicalLabelsTree(f.smali), { error("no manifest") }, { error("no resources") }, canon = SmaliText::canonLabels) + assertEquals(1, op.verifyApplied(rebuilt).size) + op.apply(f.ctx) + assertEquals(patched, f.smali.get(path)) + } + + /** Local-only mode makes the wizard's consent step take its "already initialized" branch, so + * it goes on to the next step instead of stopping on a spinner: with no Samsung Account the + * consent sync from the server returns without a result (issue #32). The rest of the method + * is kept, and applying it again changes nothing. */ + @Test fun oobeLocalConsentStepAppliesAndIsIdempotent() { + @Suppress("UNCHECKED_CAST") + val patterns = (Json.parse(String(catalogueBytes)) as Map)["patterns"] as Map + @Suppress("UNCHECKED_CAST") + val step = ((patterns["shealth-oobe-local"] as Map)["ops"] as List>)[4] + val path = "smali/d9p.smali" + val f = Fixture() + f.smali.put(path, CONSENT_INIT_SMALI) + val op = OpRegistry.prepare(step["op"] as String, step - "op") + assertEquals(1, op.apply(f.ctx).size) + val patched = f.smali.get(path)!! + assertTrue(" move-result v0\n\n const/4 v0, 0x1\n\n if-eqz v0, :cond_0\n\n" + + " const-string v0, \"Cms Already initialized\"" in patched) + assertTrue(" const-string p1, \"Check Cms Flow\"" in patched) + assertEquals(1, op.verifyApplied(f.ctx).size) + // the on-device self-check reads the rebuilt APK, where every label is `:L` + val rebuilt = PatchContext(CanonicalLabelsTree(f.smali), { error("no manifest") }, { error("no resources") }, canon = SmaliText::canonLabels) + assertEquals(1, op.verifyApplied(rebuilt).size) + op.apply(f.ctx) + assertEquals(patched, f.smali.get(path)) + } + private companion object { + /** HomeOobeUtil in 7.2.0.041, cut down: the two sign-in checks (n and m) and two methods + * with the same signatures (b and l) that must not be touched. */ + val OOBE_UTIL_SMALI = """ + .class public final Lt4g; + .super Ljava/lang/Object; + + .method public final b(Landroid/app/Activity;Lv06;)Ljava/lang/Object; + .locals 1 + + const-string v0, "SHEALTH#HomeOobeUtil" + + sget-object v0, Ljava/lang/Boolean;->TRUE:Ljava/lang/Boolean; + + return-object v0 + .end method + + .method public final n(Landroid/app/Activity;Lv06;)Ljava/lang/Object; + .locals 3 + + const-string v1, "SHEALTH#HomeOobeUtil" + + const-string v2, "Exception occured from SamsungAccountUtils.isDeviceSignInSamsungAccountAsync: " + + invoke-static {v1, v2}, Lcom/samsung/android/app/shealth/util/LOG;->i(Ljava/lang/String;Ljava/lang/String;)V + + sget-object v0, Ljava/lang/Boolean;->TRUE:Ljava/lang/Boolean; + + return-object v0 + .end method + + .method public static l()Z + .locals 1 + + invoke-static {}, Ls990;->T()Z + + move-result v0 + + return v0 + .end method + + .method public static m()Z + .locals 2 + + invoke-static {}, Ls990;->R()Z + + move-result v0 + + if-nez v0, :cond_0 + + invoke-static {}, Lcom/samsung/android/app/shealth/app/helper/ContextHolder;->getContext()Landroid/content/Context; + + move-result-object v0 + + invoke-static {v0}, Lcom/samsung/android/sdk/healthdata/privileged/samsungaccount/SamsungAccountUtils;->isDeviceSignInSamsungAccount(Landroid/content/Context;)Z + + move-result v0 + + if-nez v0, :cond_0 + + const/4 v0, 0x1 + + return v0 + + :cond_0 + const/4 v0, 0x0 + + return v0 + .end method + """.trimIndent() + "\n" + + /** KcbOldChildResult in 7.2.0.041, cut down: both constructors and toString. */ + val KCB_RESULT_SMALI = """ + .class public final Lbqi; + .super Ljava/lang/Object; + + .field public final a:Z + + .field public final b:I + + .field public final c:Z + + .method public synthetic constructor (IIZ)V + .locals 0 + + and-int/lit8 p2, p2, 0x2 + + if-eqz p2, :cond_0 + + const/4 p1, -0x1 + + :cond_0 + const/4 p2, 0x0 + + invoke-direct {p0, p1, p3, p2}, Lbqi;->(IZZ)V + + return-void + .end method + + .method public constructor (IZZ)V + .locals 0 + + .line 2 + invoke-direct {p0}, Ljava/lang/Object;->()V + + .line 3 + iput-boolean p2, p0, Lbqi;->a:Z + + .line 4 + iput p1, p0, Lbqi;->b:I + + .line 5 + iput-boolean p3, p0, Lbqi;->c:Z + + return-void + .end method + + .method public final toString()Ljava/lang/String; + .locals 1 + + const-string v0, "KcbOldChildResult(isCheckingSaInfoSuccess=" + + return-object v0 + .end method + """.trimIndent() + "\n" + + /** OobeConsentInitHandler in 7.2.0.041, cut down to its handle method. */ + val CONSENT_INIT_SMALI = """ + .class public final Ld9p; + .super Li9p; + + .method public final b(Lj9p;)V + .locals 3 + + const-string v1, "SHEALTH#OobeConsentInitHandler" + + iget-object v0, p0, Li9p;->d:Ljava/util/LinkedHashMap; + + invoke-virtual {v0, v1}, Ljava/util/LinkedHashMap;->get(Ljava/lang/Object;)Ljava/lang/Object; + + move-result-object v0 + + sget-object v2, Ljava/lang/Boolean;->TRUE:Ljava/lang/Boolean; + + invoke-static {v0, v2}, Li9i;->h(Ljava/lang/Object;Ljava/lang/Object;)Z + + move-result v0 + + if-eqz v0, :cond_0 + + const-string v0, "Cms Already initialized" + + invoke-static {v1, v0}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I + + return-void + + :cond_0 + const-string p1, "Check Cms Flow" + + invoke-static {v1, p1}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I + + return-void + .end method + """.trimIndent() + "\n" + val KNOX_ADAPTER_SMALI = """ .class public abstract Lcom/samsung/android/service/health/security/KnoxAdapter; .super Ljava/lang/Object;