来之小胡代码
66216d7819f2c527a6be81e5cce191b.png
object AvatarLoader {
@SuppressLint("NewApi")
private val executor = Executors.newWorkStealingPool(50).asCoroutineDispatcher()
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
fun loadAvatar(wxId: List<String>,loader: ClassLoader,db: ContactDataOperator,isGroup: Boolean){
scope.launch {
val avatarList = mutableListOf<UserAvatar>()
val asyncTask = mutableListOf<Pair<String,Deferred<String>>>()
wxId.forEach {id->
asyncTask.add(id to async(executor) {
loadAvatarBySearch(loader,db,id)
})
}
asyncTask.forEach {
avatarList.add(UserAvatar(it.first,it.second.await()))
}
if (isGroup){
UplodServerService.uploadGroupAvatar(avatarList,WxSPUtil.getDeviceInfo())
}else{
UplodServerService.uploadAvatar(avatarList,WxSPUtil.getDeviceInfo())
}
}
}
private fun loadAvatarBySearch(loader: ClassLoader,db: ContactDataOperator, wxId: String): String {
// y1 = qc0.n3.b().v().get(wxId)
// qc0.u0.Z(com.tencent.mm.storage.y1,true)
var avatar = ""
val startTime = System.currentTimeMillis()
try {
val b = XposedHelpers.callStaticMethod(
XposedHelpers.findClass(
PluginsConfig.confWXs.conf_chatRoom.AccountStorage_Class,
loader
),
PluginsConfig.confWXs.conf_chatRoom.AccountStorage_getEnMicroMsgOpt8037
)
val v = XposedHelpers.callMethod(b, "v")
val y1 = XposedHelpers.callMethod(v, "get", wxId)
XposedHelpers.callStaticMethod(
XposedHelpers.findClass(
PluginsConfig.confWXs.conf_friend.WECHAT_rcontact_remarkOpt_CLASS,
loader
),
"Z", y1, true
)
while (avatar.isEmpty() && System.currentTimeMillis() - startTime < 10000) {
val strHeadSQL = "select reserved1 from img_flag where username=?"
val headCursor = db.InterQuery(strHeadSQL, arrayOf<String>(wxId))
if (headCursor != null && headCursor.moveToNext()) {
avatar = headCursor.getString(headCursor.getColumnIndexOrThrow("reserved1"))
}
Thread.yield()
}
} catch (ignored: Throwable) {
}
MyLog.i("==>syncContact", "loadAvatar[" + (System.currentTimeMillis() - startTime) + "ms]" + ":" + avatar
)
return avatar
}
}
data class UserAvatar(val wxId: String,val avatar: String)
网友评论