Skip to content

Commit d907f11

Browse files
committed
improve logging
1 parent 9686ee7 commit d907f11

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

daemon/src/main/kotlin/org/matrix/vector/daemon/utils/Workarounds.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ import org.matrix.vector.daemon.system.packageManager
1313
private const val TAG = "VectorWorkarounds"
1414
private val isLenovo = Build.MANUFACTURER.equals("lenovo", ignoreCase = true)
1515

16-
/** Retrieves all users, applying Lenovo's app cloning workaround (hides users 900-909). */
1716
fun IUserManager.getRealUsers(): List<UserInfo> {
1817
val users =
1918
runCatching { getUsers(true, true, true) }
20-
.getOrElse {
21-
getUsers(true) // Fallback for older Android versions
22-
}
23-
?.toMutableList() ?: mutableListOf()
19+
.recoverCatching { t -> if (t is NoSuchMethodError) getUsers(true) else throw t }
20+
.onFailure { Log.e(TAG, "All user retrieval attempts failed", it) }
21+
.getOrDefault(emptyList())
22+
.toMutableList()
2423

2524
if (isLenovo) {
2625
val existingIds = users.map { it.id }.toSet()
2726
for (i in 900..909) {
2827
if (i !in existingIds) {
29-
runCatching { getUserInfo(i) }.getOrNull()?.let { users.add(it) }
28+
runCatching { getUserInfo(i) }
29+
.onFailure { Log.e(TAG, "Failed to apply Lenovo's app cloning workaround", it) }
30+
.getOrNull()
31+
?.let { users.add(it) }
3032
}
3133
}
3234
}
@@ -70,6 +72,7 @@ fun performDexOptMode(packageName: String): Boolean {
7072
val exitCode = process.waitFor()
7173
exitCode == 0 && output.contains("Success")
7274
}
75+
.onFailure { Log.e(TAG, "Failed to exectute dexopt via cmd", it) }
7376
.getOrDefault(false)
7477
} else {
7578
return runCatching {
@@ -81,6 +84,7 @@ fun performDexOptMode(packageName: String): Boolean {
8184
true,
8285
null) == true
8386
}
87+
.onFailure { Log.e(TAG, "Failed to invoke IPackageManager.performDexOptMode", it) }
8488
.getOrDefault(false)
8589
}
8690
}

0 commit comments

Comments
 (0)