Skip to content

Commit 0afadf5

Browse files
committed
fix(logging): migrate android.util.Log to project Log in GetterPort, AppManager, RustMigration
Replace all raw android.util.Log calls with the project's Log utility (3-arg form: logObjectTag, TAG, msg) in GetterPort.kt, AppManager.kt, and RustMigration.kt. Add missing ObjectTag imports and fix companion object placement in AppManager (object singletons cannot have companion objects — moved TAG/logObjectTag to direct members).
1 parent bc1d1ab commit 0afadf5

4 files changed

Lines changed: 90 additions & 60 deletions

File tree

core-getter/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ dependencies {
6060
androidTestImplementation libs.androidx.test.espresso.core
6161

6262
api project(':core-getter:rpc')
63+
implementation project(':core-utils')
6364
// Rust TLS
6465
implementation "rustls:rustls-platform-verifier:latest.release"
6566
}

core-getter/src/main/java/net/xzos/upgradeall/getter/GetterPort.kt

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package net.xzos.upgradeall.getter
22

33
import android.content.Context
4-
import android.util.Log
54
import kotlinx.coroutines.delay
65
import kotlinx.coroutines.runBlocking
76
import kotlinx.coroutines.sync.Mutex
87
import kotlinx.coroutines.sync.withLock
8+
import net.xzos.upgradeall.core.utils.log.Log
9+
import net.xzos.upgradeall.core.utils.log.ObjectTag
10+
import net.xzos.upgradeall.core.utils.log.ObjectTag.Companion.core
911
import net.xzos.upgradeall.getter.rpc.GetterService
1012
import net.xzos.upgradeall.getter.rpc.getClient
1113
import net.xzos.upgradeall.websdk.data.json.CloudConfigList
@@ -26,9 +28,9 @@ class GetterPort(
2628
service = getClient(url)
2729
}.also {
2830
if (it.isEmpty()) {
29-
Log.d("GetterPort", "runService: success")
31+
Log.d(logObjectTag, TAG, "runService: success")
3032
} else {
31-
Log.e("GetterPort", "runService(error): $it")
33+
Log.e(logObjectTag, TAG, "runService error: $it")
3234
}
3335
}
3436
}
@@ -47,15 +49,11 @@ class GetterPort(
4749

4850
suspend fun waitService(): Boolean {
4951
while (true) {
50-
if (isServiceRunning().apply {
51-
Log.d("GetterPort", "waitService: isServiceRunning $this")
52-
}
53-
) {
54-
break
55-
}
52+
if (isServiceRunning()) break
53+
Log.d(logObjectTag, TAG, "waitService: not ready, retrying...")
5654
delay(1000L)
5755
}
58-
return isServiceRunning()
56+
return true
5957
}
6058

6159
/**
@@ -71,7 +69,7 @@ class GetterPort(
7169
return@withLock service
7270
.init(dataPath, cachePath, globalExpireTime)
7371
.apply { isInit = this }
74-
.also { Log.d("GetterPort", "initInternal: $it") }
72+
.also { Log.i(logObjectTag, TAG, "init: $it") }
7573
}
7674
}
7775

@@ -81,11 +79,11 @@ class GetterPort(
8179
runBlocking {
8280
service
8381
.ping()
84-
.also { Log.d("GetterPort", "ping: $it") }
8582
.isNotEmpty()
83+
.also { Log.d(logObjectTag, TAG, "ping: $it") }
8684
}
8785
} catch (e: Exception) {
88-
Log.e("GetterPort", "ping: $e")
86+
Log.e(logObjectTag, TAG, "ping failed: $e")
8987
false
9088
}
9189
}
@@ -107,7 +105,7 @@ class GetterPort(
107105
return runBlocking {
108106
service
109107
.checkAppAvailable(hubUuid, appData, hubData)
110-
.also { Log.d("GetterPort", "checkAppAvailable: $it") }
108+
.also { Log.d(logObjectTag, TAG, "checkAppAvailable[$hubUuid]: $it") }
111109
}
112110
}
113111

@@ -120,7 +118,7 @@ class GetterPort(
120118
return runBlocking {
121119
service
122120
.getAppLatestRelease(hubUuid, appData, hubData)
123-
.also { Log.d("GetterPort", "getAppLatestRelease: $it") }
121+
.also { Log.d(logObjectTag, TAG, "getAppLatestRelease[$hubUuid]: ${it.versionNumber}") }
124122
}
125123
}
126124

@@ -133,7 +131,7 @@ class GetterPort(
133131
return runBlocking {
134132
service
135133
.getAppReleases(hubUuid, appData, hubData)
136-
.also { Log.d("GetterPort", "getAppReleases: $it") }
134+
.also { Log.d(logObjectTag, TAG, "getAppReleases[$hubUuid]: ${it.size} releases") }
137135
}
138136
}
139137

@@ -142,7 +140,7 @@ class GetterPort(
142140
return runBlocking {
143141
service
144142
.getCloudConfig(apiUrl)
145-
.also { Log.d("GetterPort", "getCloudConfig: $it") }
143+
.also { Log.d(logObjectTag, TAG, "getCloudConfig: ${it.appList.size} apps, ${it.hubList.size} hubs") }
146144
}
147145
}
148146

@@ -154,7 +152,7 @@ class GetterPort(
154152
return runBlocking {
155153
service
156154
.registerProvider(hubUuid, url)
157-
.also { Log.d("GetterPort", "registerProvider: uuid=$hubUuid url=$url result=$it") }
155+
.also { Log.i(logObjectTag, TAG, "registerProvider: uuid=$hubUuid url=$url result=$it") }
158156
}
159157
}
160158

@@ -166,7 +164,7 @@ class GetterPort(
166164
return runBlocking {
167165
service
168166
.registerDownloader(hubUuid, rpcUrl)
169-
.also { Log.d("GetterPort", "registerDownloader: uuid=$hubUuid url=$rpcUrl result=$it") }
167+
.also { Log.i(logObjectTag, TAG, "registerDownloader: uuid=$hubUuid result=$it") }
170168
}
171169
}
172170

@@ -180,7 +178,12 @@ class GetterPort(
180178
return runBlocking {
181179
service
182180
.getDownloadInfo(hubUuid, appData, hubData, assetIndex)
183-
.also { Log.d("GetterPort", "getDownloadInfo: $it") }
181+
.also { Log.d(logObjectTag, TAG, "getDownloadInfo[$hubUuid]: ${it.size} items") }
184182
}
185183
}
184+
185+
companion object {
186+
private const val TAG = "GetterPort"
187+
private val logObjectTag = ObjectTag(core, TAG)
188+
}
186189
}

core/src/main/java/net/xzos/upgradeall/core/database/migration/RustMigration.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package net.xzos.upgradeall.core.database.migration
22

3-
import android.util.Log
43
import net.xzos.upgradeall.core.database.metaDatabase
54
import net.xzos.upgradeall.core.database.table.AppEntity
65
import net.xzos.upgradeall.core.database.table.HubEntity
76
import net.xzos.upgradeall.core.database.table.extra_hub.ExtraHubEntity
7+
import net.xzos.upgradeall.core.utils.log.Log
8+
import net.xzos.upgradeall.core.utils.log.ObjectTag
9+
import net.xzos.upgradeall.core.utils.log.ObjectTag.Companion.core
810
import net.xzos.upgradeall.core.websdk.getterPort
911
import net.xzos.upgradeall.getter.AppManagerProxy
1012
import net.xzos.upgradeall.getter.ExtraHubProxy
@@ -19,6 +21,7 @@ import net.xzos.upgradeall.getter.rpc.HubRecord
1921
import java.io.File
2022

2123
private const val TAG = "RustMigration"
24+
private val logObjectTag = ObjectTag(core, TAG)
2225

2326
/**
2427
* Migrates data from the Room/SQLite database to the Rust JSONL store.
@@ -29,7 +32,7 @@ private const val TAG = "RustMigration"
2932
suspend fun migrateRoomToRust(rustDataDir: File) {
3033
val appsFile = File(rustDataDir, "apps.jsonl")
3134
if (appsFile.exists() && appsFile.length() > 0) {
32-
Log.d(TAG, "JSONL store already populated, skipping migration")
35+
Log.d(logObjectTag, TAG, "JSONL store already populated, skipping migration")
3336
return
3437
}
3538

@@ -43,11 +46,11 @@ suspend fun migrateRoomToRust(rustDataDir: File) {
4346
}
4447

4548
if (apps.isEmpty() && hubs.isEmpty()) {
46-
Log.d(TAG, "Room DB is empty, nothing to migrate")
49+
Log.d(logObjectTag, TAG, "Room DB is empty, nothing to migrate")
4750
return
4851
}
4952

50-
Log.i(TAG, "Starting Room -> Rust migration: ${apps.size} apps, ${hubs.size} hubs")
53+
Log.i(logObjectTag, TAG, "Starting Room -> Rust migration: ${apps.size} apps, ${hubs.size} hubs")
5154

5255
val service = getterPort.getService()
5356
val appProxy = AppManagerProxy(service)
@@ -57,22 +60,22 @@ suspend fun migrateRoomToRust(rustDataDir: File) {
5760
hubs.forEach { entity ->
5861
val record = entity.toHubRecord()
5962
val ok = hubProxy.saveHub(record)
60-
if (!ok) Log.w(TAG, "Failed to migrate hub: ${entity.uuid}")
63+
if (!ok) Log.w(logObjectTag, TAG, "Failed to migrate hub: ${entity.uuid}")
6164
}
6265

6366
extraHubs.forEach { entity ->
6467
val record = entity.toExtraHubRecord()
6568
val ok = extraHubProxy.saveExtraHub(record)
66-
if (!ok) Log.w(TAG, "Failed to migrate extra_hub: ${entity.id}")
69+
if (!ok) Log.w(logObjectTag, TAG, "Failed to migrate extra_hub: ${entity.id}")
6770
}
6871

6972
apps.forEach { entity ->
7073
val record = entity.toAppRecord()
7174
val saved = appProxy.saveApp(record)
72-
if (saved.id.isEmpty()) Log.w(TAG, "Failed to migrate app: ${entity.name}")
75+
if (saved.id.isEmpty()) Log.w(logObjectTag, TAG, "Failed to migrate app: ${entity.name}")
7376
}
7477

75-
Log.i(TAG, "Migration complete")
78+
Log.i(logObjectTag, TAG, "Migration complete")
7679
}
7780

7881
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)