Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/app-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@ jobs:
working-directory: ./App
run: ./gradlew testDebugUnitTest

# 缓存并准备CoreADI
- name: Cache CoreADI asset
id: cache-coreadi
uses: actions/cache@v4
with:
path: App/app/src/main/assets/coreadi/CoreADI.x86_64
key: coreadi-2eafc3c79c7f41a8afbfbeaaf23ee5dab5ad5bda55ec8e54dbc0ddf1d20ce630

- name: Install p7zip
if: steps.cache-coreadi.outputs.cache-hit != 'true'
run: |
sudo apt-get update
sudo apt-get install -y p7zip-full

- name: Extract CoreADI
if: steps.cache-coreadi.outputs.cache-hit != 'true'
run: |
python3 tools/extract_coreadi.py --dest App/app/src/main/assets/coreadi

- name: Verify CoreADI Asset
run: |
COREADI_FILE="App/app/src/main/assets/coreadi/CoreADI.x86_64"
if [ ! -f "$COREADI_FILE" ]; then
echo "Error: CoreADI asset not found at $COREADI_FILE"
exit 1
fi
echo "CoreADI asset verified: $(sha256sum "$COREADI_FILE")"

- name: Build Debug APK
working-directory: ./App
run: ./gradlew assembleDebug
Expand Down
56 changes: 54 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ on:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag_name:
description: '发布版本号 / Release Tag (例如 v1.0.0-beta.1)'
required: false
default: ''
type: string

jobs:
build-and-release:
Expand All @@ -17,6 +23,22 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4

# 确定版本 Tag(支持通过 Git 推送 Tag,或在网页端 Run workflow 手动输入 Tag)
- name: Determine Release Tag
run: |
TAG="${{ inputs.tag_name }}"
if [ -z "$TAG" ]; then
if [ "${{ github.ref_type }}" = "tag" ]; then
TAG="${{ github.ref_name }}"
else
echo "Error: 当前是在分支上运行,且未在 Run workflow 中输入 tag_name!"
echo "GitHub Release 必须绑定一个版本 Tag(例如 v1.0.0-beta.1)。"
exit 1
fi
fi
echo "TARGET_TAG=$TAG" >> $GITHUB_ENV
echo "Target Release Tag is: $TAG"

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand All @@ -27,6 +49,34 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x App/gradlew

# 缓存并准备CoreADI
- name: Cache CoreADI asset
id: cache-coreadi
uses: actions/cache@v4
with:
path: App/app/src/main/assets/coreadi/CoreADI.x86_64
key: coreadi-2eafc3c79c7f41a8afbfbeaaf23ee5dab5ad5bda55ec8e54dbc0ddf1d20ce630

- name: Install p7zip
if: steps.cache-coreadi.outputs.cache-hit != 'true'
run: |
sudo apt-get update
sudo apt-get install -y p7zip-full

- name: Extract CoreADI
if: steps.cache-coreadi.outputs.cache-hit != 'true'
run: |
python3 tools/extract_coreadi.py --dest App/app/src/main/assets/coreadi

- name: Verify CoreADI Asset
run: |
COREADI_FILE="App/app/src/main/assets/coreadi/CoreADI.x86_64"
if [ ! -f "$COREADI_FILE" ]; then
echo "Error: CoreADI asset not found at $COREADI_FILE"
exit 1
fi
echo "CoreADI asset verified: $(sha256sum "$COREADI_FILE")"

# 正式 Release 编译
- name: Build Android Release APK
working-directory: ./App
Expand Down Expand Up @@ -83,7 +133,7 @@ jobs:
fi

# 5. 执行 apksigner 写入正式签名
OUT_APK="release-assets/YuiTag-App-${{ github.ref_name }}.apk"
OUT_APK="release-assets/YuiTag-App-${TARGET_TAG}.apk"
echo "Running apksigner..."
"$APKSIGNER" sign \
--ks release.jks \
Expand All @@ -105,8 +155,10 @@ jobs:
- name: Create GitHub Release (Draft)
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TARGET_TAG }}
name: ${{ env.TARGET_TAG }}
draft: true
prerelease: ${{ contains(github.ref_name, 'beta') || contains(github.ref_name, 'rc') || contains(github.ref_name, 'alpha') }}
prerelease: ${{ contains(env.TARGET_TAG, 'beta') || contains(env.TARGET_TAG, 'rc') || contains(env.TARGET_TAG, 'alpha') || contains(env.TARGET_TAG, 'dev') || contains(env.TARGET_TAG, 'preview') }}
generate_release_notes: true
files: |
release-assets/*.apk
5 changes: 5 additions & 0 deletions App/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ Thumbs.db
*.jks
*.p12
*.pem
!app/src/main/res/raw/*.pem
*.log

# 本地私有脚本与说明
build.ps1
AGENTS.md

# CoreADI
app/src/main/assets/coreadi/CoreADI.x86_64

7 changes: 4 additions & 3 deletions App/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId = "com.reiyy.yuitag"
minSdk = 31
targetSdk = 35
versionCode = 2
versionName = "1.0.0"
versionCode = 3
versionName = "1.0.0-beta.2"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -82,6 +82,8 @@ dependencies {

// Gson (theme config JSON serialization)
implementation("com.google.code.gson:gson:2.11.0")
// OkHttp (Apple GrandSlam & FindMy direct API)
implementation("com.squareup.okhttp3:okhttp:4.12.0")

// AboutLibraries (自动化开源许可)
implementation(libs.aboutlibraries.compose.m3)
Expand All @@ -91,5 +93,4 @@ dependencies {
androidTestImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.room.testing)
}
1 change: 1 addition & 0 deletions App/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/Theme.YuiTagApp">

<service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.reiyy.yuitag.apple.account

import com.google.gson.annotations.SerializedName

/**
* Account information extracted from Apple's SPD payload after SRP authentication.
*/
data class AccountInfo(
@SerializedName("account_name") val accountName: String? = null,
@SerializedName("first_name") val firstName: String? = null,
@SerializedName("last_name") val lastName: String? = null,
@SerializedName("trusted_device_2fa") var trustedDevice2fa: Boolean = false,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.reiyy.yuitag.apple.account

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.util.UUID

/**
* Persistent state for a single Apple account — identity, credentials,
* login state, and tokens (PET, ADSID, searchPartyToken).
*/
class AppleAccount(
uid: String? = null,
devid: String? = null,
) {
var uid: String = uid ?: UUID.randomUUID().toString()
private set
var devid: String = devid ?: UUID.randomUUID().toString()
private set

var username: String? = null
var password: String? = null

var accountInfo: AccountInfo? = null
internal set

var loginState: LoginState = LoginState.LOGGED_OUT
private set

private var _loginStateData: MutableMap<String, Any?> = mutableMapOf()
val loginStateData: Map<String, Any?> get() = _loginStateData

fun loginStateString(key: String): String? = _loginStateData[key] as? String

fun getDsid(): String? = loginStateString("dsid")?.takeIf { it.isNotBlank() }

@Suppress("UNCHECKED_CAST")
fun getSearchPartyToken(): String? {
val mobileme = _loginStateData["mobileme_data"] as? Map<String, Any?> ?: return null
val tokens = mobileme["tokens"] as? Map<String, Any?> ?: return null
return tokens["searchPartyToken"] as? String
}

fun setLoginState(state: LoginState, data: Map<String, Any?>?) {
if (state.value < loginState.value) {
accountInfo = null
}
loginState = state
_loginStateData = data?.toMutableMap() ?: mutableMapOf()
}

fun exportToJson(): String {
val map = mapOf(
"ids" to mapOf("uid" to uid, "devid" to devid),
"account" to mapOf(
"username" to username,
"password" to password,
"info" to accountInfo
),
"login_state" to mapOf(
"state" to loginState.value,
"data" to _loginStateData
)
)
return GSON.toJson(map)
}

companion object {
private val GSON = Gson()

@Suppress("UNCHECKED_CAST")
fun restoreFromJson(json: String): AppleAccount = try {
val type = object : TypeToken<Map<String, Any?>>() {}.type
val map: Map<String, Any?> = GSON.fromJson(json, type)
val ids = map["ids"] as? Map<String, Any?> ?: emptyMap()
val account = map["account"] as? Map<String, Any?> ?: emptyMap()
val login = map["login_state"] as? Map<String, Any?> ?: emptyMap()

val acc = AppleAccount(
uid = ids["uid"] as? String,
devid = ids["devid"] as? String,
)
acc.username = account["username"] as? String
acc.password = account["password"] as? String

account["info"]?.let { infoMap ->
val infoJson = GSON.toJson(infoMap)
acc.accountInfo = GSON.fromJson(infoJson, AccountInfo::class.java)
}

val stateNum = (login["state"] as? Number)?.toInt() ?: LoginState.LOGGED_OUT.value
acc.loginState = LoginState.fromValue(stateNum)
val d = login["data"] as? Map<String, Any?>
acc._loginStateData = d?.toMutableMap() ?: mutableMapOf()
acc
} catch (e: Exception) {
throw IllegalArgumentException("Failed to restore AppleAccount from JSON: ${e.message}", e)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.reiyy.yuitag.apple.account

import android.content.Context
import android.content.SharedPreferences
import com.reiyy.yuitag.apple.anisette.AnisetteClient
import com.reiyy.yuitag.apple.anisette.AnisetteProvider
import com.reiyy.yuitag.apple.anisette.createAndroidAnisetteProvider
import com.reiyy.yuitag.apple.gsa.GsaClient
import com.reiyy.yuitag.apple.http.HttpTransport
import com.reiyy.yuitag.apple.http.OkHttpTransport
import com.reiyy.yuitag.apple.mobileme.MobileMeClient
import com.reiyy.yuitag.apple.reports.LocationReportsClient
import com.reiyy.yuitag.ble.FileLog

/**
* Singleton managing Apple ID credentials, Anisette emulation, and network clients.
*/
class AppleAccountManager private constructor(private val appContext: Context) {

private val prefs: SharedPreferences =
appContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)

val http: HttpTransport = OkHttpTransport()

val anisetteProvider: AnisetteProvider by lazy {
createAndroidAnisetteProvider(appContext, http)
}

val anisetteClient: AnisetteClient by lazy {
AnisetteClient(anisetteProvider)
}

val gsaClient: GsaClient by lazy {
GsaClient(http, anisetteClient)
}

val mobileMeClient: MobileMeClient by lazy {
MobileMeClient(http, anisetteClient)
}

val reportsClient: LocationReportsClient by lazy {
LocationReportsClient(http, anisetteClient)
}

private var currentAccount: AppleAccount = loadAccount()

fun getAccount(): AppleAccount = currentAccount

@Synchronized
fun saveAccount(account: AppleAccount) {
currentAccount = account
prefs.edit().putString(KEY_ACCOUNT_JSON, account.exportToJson()).apply()
FileLog.i(TAG, "AppleAccount saved, state: ${account.loginState}")
}

@Synchronized
fun clearAccount() {
currentAccount = AppleAccount()
prefs.edit().remove(KEY_ACCOUNT_JSON).apply()
FileLog.i(TAG, "AppleAccount cleared")
}

fun isLoggedIn(): Boolean =
currentAccount.loginState == LoginState.LOGGED_IN && currentAccount.getSearchPartyToken() != null

fun createLoginService(): AppleLoginService {
// 每次登录创建全新实例,避免旧会话残留或 2FA 死锁
val freshAccount = AppleAccount()
return AppleLoginService(
account = freshAccount,
http = http,
anisette = anisetteClient,
gsa = gsaClient,
mobileMe = mobileMeClient,
)
}

private fun loadAccount(): AppleAccount {
val json = prefs.getString(KEY_ACCOUNT_JSON, null)
if (!json.isNullOrEmpty()) {
try {
return AppleAccount.restoreFromJson(json)
} catch (e: Exception) {
FileLog.w(TAG, "Failed to restore AppleAccount from prefs: ${e.message}")
}
}
return AppleAccount()
}

companion object {
private const val TAG = "AppleAccountManager"
private const val PREF_NAME = "yuitag_apple_account"
private const val KEY_ACCOUNT_JSON = "apple_account_json"

@Volatile
private var INSTANCE: AppleAccountManager? = null

fun getInstance(context: Context): AppleAccountManager {
return INSTANCE ?: synchronized(this) {
INSTANCE ?: AppleAccountManager(context.applicationContext).also { INSTANCE = it }
}
}
}
}
Loading
Loading