-
-
Notifications
You must be signed in to change notification settings - Fork 457
Add minimal Huawei Hagrid WSP support #1408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
shisoratsu
wants to merge
1
commit into
oliexdev:master
Choose a base branch
from
shisoratsu:huawei-hagrid-pr1-minimal-wsp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
.../app/src/main/java/com/health/openscale/core/bluetooth/libs/HuaweiHagridSecretProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * openScale | ||
| * Copyright (C) 2026 openScale contributors | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.health.openscale.core.bluetooth.libs | ||
|
|
||
| /** | ||
| * Replaceable source for Huawei Hagrid CAK/C1/C2 key material. | ||
| * | ||
| * Implementations must not log raw secret values. The upstream app only uses | ||
| * explicitly configured settings here; private Huawei Health extraction tools | ||
| * are outside this boundary. | ||
| */ | ||
| interface HuaweiHagridSecretProvider { | ||
| val id: String | ||
|
|
||
| fun load( | ||
| getString: (String) -> String?, | ||
| warn: (String) -> Unit | ||
| ): HuaweiHagridWspLib.HagridSecrets? | ||
|
|
||
| class DriverSettings( | ||
| private val cakKey: String, | ||
| private val c1Key: String, | ||
| private val c2Key: String | ||
| ) : HuaweiHagridSecretProvider { | ||
| override val id: String = "driver-settings" | ||
|
|
||
| override fun load( | ||
| getString: (String) -> String?, | ||
| warn: (String) -> Unit | ||
| ): HuaweiHagridWspLib.HagridSecrets? { | ||
| val cak = settingsHexOrNull(getString, warn, cakKey, 16) | ||
| val c1 = settingsHexOrNull(getString, warn, c1Key, 16) | ||
| val c2 = settingsHexOrNull(getString, warn, c2Key, 16) | ||
| if (cak == null && c1 == null && c2 == null) return null | ||
| if (cak == null || c1 == null || c2 == null) { | ||
| warn("Incomplete Huawei Hagrid secrets; require CAK, C1, and C2 hex settings") | ||
| return null | ||
| } | ||
| return runCatching { HuaweiHagridWspLib.HagridSecrets(cak, c1, c2) } | ||
| .getOrElse { error -> | ||
| warn("Invalid Huawei Hagrid secrets: ${error.message}") | ||
| null | ||
| } | ||
| } | ||
|
|
||
| private fun settingsHexOrNull( | ||
| getString: (String) -> String?, | ||
| warn: (String) -> Unit, | ||
| key: String, | ||
| expectedBytes: Int | ||
| ): ByteArray? { | ||
| val raw = getString(key)?.trim().orEmpty() | ||
| if (raw.isEmpty()) return null | ||
| val hex = raw.filter { it.isDigit() || it.lowercaseChar() in 'a'..'f' } | ||
| if (hex.length != expectedBytes * 2) { | ||
| warn("Ignoring Huawei Hagrid setting $key: expected ${expectedBytes * 2} hex digits, got ${hex.length}") | ||
| return null | ||
| } | ||
| return runCatching { | ||
| ByteArray(expectedBytes) { index -> | ||
| hex.substring(index * 2, index * 2 + 2).toInt(16).toByte() | ||
| } | ||
| }.getOrElse { error -> | ||
| warn("Ignoring Huawei Hagrid setting $key: ${error.message}") | ||
| null | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add this into HuaweiHagridWspLib.kt so we have only one lib file.