release: v1.3.1 - fix running mode bearing sync, SystemServer 1Hz push & BDLocation coorType handling
This commit is contained in:
1 parent
c8c63046bc
commit
b039f610b3
7 files changed
+110
-23
No files matched your search
@@ -18,19 +18,14 @@ android {
|
|||||||
applicationId = "com.lzxnone.openloc"
|
applicationId = "com.lzxnone.openloc"
|
||||||
minSdk = 28
|
minSdk = 28
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 8
|
versionCode = 9
|
||||||
versionName = "1.3.0"
|
versionName = "1.3.1"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|
||||||
splits {
|
base {
|
||||||
abi {
|
archivesName.set("OpenLoc-v${defaultConfig.versionName}")
|
||||||
isEnable = true
|
|
||||||
reset()
|
|
||||||
include("armeabi-v7a", "arm64-v8a", "x86", "x86_64")
|
|
||||||
isUniversalApk = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,11 @@ class LocationConfigProvider : ContentProvider() {
|
|||||||
val prefs = ctx.getSharedPreferences("openloc_prefs", Context.MODE_PRIVATE)
|
val prefs = ctx.getSharedPreferences("openloc_prefs", Context.MODE_PRIVATE)
|
||||||
|
|
||||||
val isEnabled = prefs.getBoolean("mock_service_enabled", false)
|
val isEnabled = prefs.getBoolean("mock_service_enabled", false)
|
||||||
val lat = prefs.getString("mock_latitude", "39.908722")?.toDoubleOrNull() ?: 39.908722
|
val runtime = AppPreferences.getRuntimeMockState()
|
||||||
val lng = prefs.getString("mock_longitude", "116.397496")?.toDoubleOrNull() ?: 116.397496
|
val lat = if (isEnabled) runtime.latitude else (prefs.getString("mock_latitude", "39.908722")?.toDoubleOrNull() ?: 39.908722)
|
||||||
|
val lng = if (isEnabled) runtime.longitude else (prefs.getString("mock_longitude", "116.397496")?.toDoubleOrNull() ?: 116.397496)
|
||||||
|
val speed = if (isEnabled) runtime.speed else 0.0f
|
||||||
|
val bearing = if (isEnabled) runtime.bearing else 0.0f
|
||||||
val name = prefs.getString("mock_location_name", "") ?: ""
|
val name = prefs.getString("mock_location_name", "") ?: ""
|
||||||
val mode = prefs.getString("app_mock_mode", "GLOBAL") ?: "GLOBAL"
|
val mode = prefs.getString("app_mock_mode", "GLOBAL") ?: "GLOBAL"
|
||||||
val whitelistJson = prefs.getString("whitelist_apps", "[]") ?: "[]"
|
val whitelistJson = prefs.getString("whitelist_apps", "[]") ?: "[]"
|
||||||
@@ -47,6 +50,10 @@ class LocationConfigProvider : ContentProvider() {
|
|||||||
putBoolean(ConfigContract.KEY_ENABLED, isEnabled)
|
putBoolean(ConfigContract.KEY_ENABLED, isEnabled)
|
||||||
putDouble(ConfigContract.KEY_LATITUDE, lat)
|
putDouble(ConfigContract.KEY_LATITUDE, lat)
|
||||||
putDouble(ConfigContract.KEY_LONGITUDE, lng)
|
putDouble(ConfigContract.KEY_LONGITUDE, lng)
|
||||||
|
putDouble("altitude", 50.0)
|
||||||
|
putFloat("accuracy", 5.0f)
|
||||||
|
putFloat("bearing", bearing)
|
||||||
|
putFloat("speed", speed)
|
||||||
putString(ConfigContract.KEY_LOCATION_NAME, name)
|
putString(ConfigContract.KEY_LOCATION_NAME, name)
|
||||||
putString(ConfigContract.KEY_APP_MOCK_MODE, mode)
|
putString(ConfigContract.KEY_APP_MOCK_MODE, mode)
|
||||||
putString(ConfigContract.KEY_WHITELIST_APPS, whitelistJson)
|
putString(ConfigContract.KEY_WHITELIST_APPS, whitelistJson)
|
||||||
|
|||||||
@@ -201,6 +201,19 @@ object AppPreferences {
|
|||||||
@Volatile private var activeBearing: Float = 0.0f
|
@Volatile private var activeBearing: Float = 0.0f
|
||||||
@Volatile private var hasActivePoint: Boolean = false
|
@Volatile private var hasActivePoint: Boolean = false
|
||||||
|
|
||||||
|
internal data class RuntimeMockState(
|
||||||
|
val latitude: Double,
|
||||||
|
val longitude: Double,
|
||||||
|
val speed: Float,
|
||||||
|
val bearing: Float
|
||||||
|
)
|
||||||
|
|
||||||
|
internal fun getRuntimeMockState(): RuntimeMockState {
|
||||||
|
val pushLat = if (hasActivePoint) activeLat else mockLatitude
|
||||||
|
val pushLng = if (hasActivePoint) activeLng else mockLongitude
|
||||||
|
return RuntimeMockState(pushLat, pushLng, activeSpeed, activeBearing)
|
||||||
|
}
|
||||||
|
|
||||||
private val tickerThread by lazy {
|
private val tickerThread by lazy {
|
||||||
HandlerThread("OpenLoc-1Hz-Ticker").apply { start() }
|
HandlerThread("OpenLoc-1Hz-Ticker").apply { start() }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.location.Location
|
import android.location.Location
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
|
import com.lzxnone.openloc.core.util.CoordinateConverter
|
||||||
import com.lzxnone.openloc.core.util.TraceLogger
|
import com.lzxnone.openloc.core.util.TraceLogger
|
||||||
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
||||||
@@ -374,8 +375,9 @@ object ThirdPartyNlpHook {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val lat = GlobalMockMemory.latitude
|
val gcj = CoordinateConverter.wgs84ToGcj02(GlobalMockMemory.latitude, GlobalMockMemory.longitude)
|
||||||
val lng = GlobalMockMemory.longitude
|
val lat = gcj[0]
|
||||||
|
val lng = gcj[1]
|
||||||
val alt = GlobalMockMemory.altitude
|
val alt = GlobalMockMemory.altitude
|
||||||
val accuracy = GlobalMockMemory.accuracy
|
val accuracy = GlobalMockMemory.accuracy
|
||||||
val speed = GlobalMockMemory.speed
|
val speed = GlobalMockMemory.speed
|
||||||
@@ -452,7 +454,27 @@ object ThirdPartyNlpHook {
|
|||||||
|
|
||||||
if (bdLocationClass != null) {
|
if (bdLocationClass != null) {
|
||||||
TraceLogger.i("ThirdPartyNLP", "[$packageName] Detected BDLocation, arming Baidu hooks...")
|
TraceLogger.i("ThirdPartyNLP", "[$packageName] Detected BDLocation, arming Baidu hooks...")
|
||||||
|
val getCoorTypeMethod = try {
|
||||||
|
bdLocationClass.getMethod("getCoorType")
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resolveBaiduCoords(instance: Any?): DoubleArray? {
|
||||||
|
val coorType = try {
|
||||||
|
(getCoorTypeMethod?.invoke(instance) as? String)?.lowercase()
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
return when {
|
||||||
|
coorType == "bd09mc" || (coorType != null && coorType.contains("mc")) -> null
|
||||||
|
coorType == "wgs84" -> doubleArrayOf(GlobalMockMemory.latitude, GlobalMockMemory.longitude)
|
||||||
|
coorType == "gcj02" -> CoordinateConverter.wgs84ToGcj02(GlobalMockMemory.latitude, GlobalMockMemory.longitude)
|
||||||
|
else -> CoordinateConverter.wgs84ToBd09(GlobalMockMemory.latitude, GlobalMockMemory.longitude)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastBdLogTime = 0L
|
||||||
for (method in bdLocationClass.declaredMethods) {
|
for (method in bdLocationClass.declaredMethods) {
|
||||||
when (method.name) {
|
when (method.name) {
|
||||||
"getLatitude" -> {
|
"getLatitude" -> {
|
||||||
@@ -460,7 +482,16 @@ object ThirdPartyNlpHook {
|
|||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||||
override fun afterHookedMethod(param: MethodHookParam) {
|
override fun afterHookedMethod(param: MethodHookParam) {
|
||||||
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
||||||
param.result = GlobalMockMemory.latitude
|
val orig = param.result as? Double ?: return
|
||||||
|
if (orig == Double.MIN_VALUE || orig == 0.0 || kotlin.math.abs(orig) > 90.0) return
|
||||||
|
val coords = resolveBaiduCoords(param.thisObject) ?: return
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
if (now - lastBdLogTime > 2000L) {
|
||||||
|
lastBdLogTime = now
|
||||||
|
val coorType = try { getCoorTypeMethod?.invoke(param.thisObject) as? String } catch (_: Throwable) { null }
|
||||||
|
TraceLogger.d("ThirdPartyNLP", "[$packageName] BDLocation.getLatitude orig=$orig, coorType=$coorType -> ${coords[0]}")
|
||||||
|
}
|
||||||
|
param.result = coords[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -471,7 +502,10 @@ object ThirdPartyNlpHook {
|
|||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||||
override fun afterHookedMethod(param: MethodHookParam) {
|
override fun afterHookedMethod(param: MethodHookParam) {
|
||||||
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
||||||
param.result = GlobalMockMemory.longitude
|
val orig = param.result as? Double ?: return
|
||||||
|
if (orig == Double.MIN_VALUE || orig == 0.0 || kotlin.math.abs(orig) > 180.0) return
|
||||||
|
val coords = resolveBaiduCoords(param.thisObject) ?: return
|
||||||
|
param.result = coords[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -526,7 +560,10 @@ object ThirdPartyNlpHook {
|
|||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||||
override fun afterHookedMethod(param: MethodHookParam) {
|
override fun afterHookedMethod(param: MethodHookParam) {
|
||||||
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
||||||
param.result = 61 // 61: GPS 定位成功
|
val orig = param.result as? Int
|
||||||
|
if (orig == 161 || orig == 66 || orig == 65 || orig == 68) {
|
||||||
|
param.result = 61 // 将网络/离线成功态统一伪装为 GPS 定位成功
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ object ConfigFetcher {
|
|||||||
|
|
||||||
isFetching.set(true)
|
isFetching.set(true)
|
||||||
return try {
|
return try {
|
||||||
|
// 优先走 system_server 内存隧道(携带实时推进坐标、speed 与 bearing),失败再回退 ContentProvider
|
||||||
|
fetchFromSystemServer(context, now)?.let { return it }
|
||||||
|
|
||||||
val bundle = context.contentResolver.call(
|
val bundle = context.contentResolver.call(
|
||||||
PROVIDER_URI,
|
PROVIDER_URI,
|
||||||
ConfigContract.METHOD_GET_CONFIG,
|
ConfigContract.METHOD_GET_CONFIG,
|
||||||
@@ -88,10 +91,10 @@ object ConfigFetcher {
|
|||||||
isEnabled = bundle.getBoolean(ConfigContract.KEY_ENABLED, false),
|
isEnabled = bundle.getBoolean(ConfigContract.KEY_ENABLED, false),
|
||||||
latitude = bundle.getDouble(ConfigContract.KEY_LATITUDE, 39.908722),
|
latitude = bundle.getDouble(ConfigContract.KEY_LATITUDE, 39.908722),
|
||||||
longitude = bundle.getDouble(ConfigContract.KEY_LONGITUDE, 116.397496),
|
longitude = bundle.getDouble(ConfigContract.KEY_LONGITUDE, 116.397496),
|
||||||
altitude = bundle.getDouble("altitude", 50.0),
|
altitude = bundle.getDouble("altitude", GlobalMockMemory.altitude),
|
||||||
accuracy = bundle.getFloat("accuracy", 5.0f),
|
accuracy = bundle.getFloat("accuracy", GlobalMockMemory.accuracy),
|
||||||
bearing = bundle.getFloat("bearing", 0.0f),
|
bearing = bundle.getFloat("bearing", GlobalMockMemory.bearing),
|
||||||
speed = bundle.getFloat("speed", 0.0f),
|
speed = bundle.getFloat("speed", GlobalMockMemory.speed),
|
||||||
mode = mode,
|
mode = mode,
|
||||||
whitelist = parseSet(whitelistJson),
|
whitelist = parseSet(whitelistJson),
|
||||||
blacklist = parseSet(blacklistJson),
|
blacklist = parseSet(blacklistJson),
|
||||||
|
|||||||
@@ -113,13 +113,17 @@ object GlobalMockMemory {
|
|||||||
* 生成标准可用的 Mock Location 对象
|
* 生成标准可用的 Mock Location 对象
|
||||||
*/
|
*/
|
||||||
fun createLocation(provider: String = "gps"): Location {
|
fun createLocation(provider: String = "gps"): Location {
|
||||||
|
val currentSpeed = this@GlobalMockMemory.speed
|
||||||
|
val hasValidBearing = currentSpeed > 0.1f
|
||||||
return Location(provider).apply {
|
return Location(provider).apply {
|
||||||
latitude = this@GlobalMockMemory.latitude
|
latitude = this@GlobalMockMemory.latitude
|
||||||
longitude = this@GlobalMockMemory.longitude
|
longitude = this@GlobalMockMemory.longitude
|
||||||
altitude = this@GlobalMockMemory.altitude
|
altitude = this@GlobalMockMemory.altitude
|
||||||
accuracy = this@GlobalMockMemory.accuracy
|
accuracy = this@GlobalMockMemory.accuracy
|
||||||
bearing = this@GlobalMockMemory.bearing
|
speed = currentSpeed
|
||||||
speed = this@GlobalMockMemory.speed
|
if (hasValidBearing) {
|
||||||
|
bearing = this@GlobalMockMemory.bearing
|
||||||
|
}
|
||||||
time = System.currentTimeMillis()
|
time = System.currentTimeMillis()
|
||||||
elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
|
elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
|
||||||
|
|
||||||
@@ -127,7 +131,9 @@ object GlobalMockMemory {
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
verticalAccuracyMeters = 1.5f
|
verticalAccuracyMeters = 1.5f
|
||||||
speedAccuracyMetersPerSecond = 0.1f
|
speedAccuracyMetersPerSecond = 0.1f
|
||||||
bearingAccuracyDegrees = 1.0f
|
if (hasValidBearing) {
|
||||||
|
bearingAccuracyDegrees = 1.0f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ object SystemServerHook {
|
|||||||
|
|
||||||
// 活跃监听器与其所属目标包名的映射表(以 IBinder 为 key,彻底消除 Class 静态闭包污染)
|
// 活跃监听器与其所属目标包名的映射表(以 IBinder 为 key,彻底消除 Class 静态闭包污染)
|
||||||
private val activeListeners = ConcurrentHashMap<IBinder, String>()
|
private val activeListeners = ConcurrentHashMap<IBinder, String>()
|
||||||
|
private val activeListenerInstances = ConcurrentHashMap<IBinder, Pair<Any, String>>()
|
||||||
private val activeCallbacks = ConcurrentHashMap<IBinder, String>()
|
private val activeCallbacks = ConcurrentHashMap<IBinder, String>()
|
||||||
|
private val pushExecutor = java.util.concurrent.Executors.newSingleThreadExecutor()
|
||||||
|
|
||||||
// 已挂钩 onLocationChanged 的类名集合,防止重复 Hook
|
// 已挂钩 onLocationChanged 的类名集合,防止重复 Hook
|
||||||
private val hookedListenerClasses = Collections.synchronizedSet(mutableSetOf<String>())
|
private val hookedListenerClasses = Collections.synchronizedSet(mutableSetOf<String>())
|
||||||
@@ -90,6 +92,9 @@ object SystemServerHook {
|
|||||||
} else if (extras != null) {
|
} else if (extras != null) {
|
||||||
GlobalMockMemory.updateFromBundle(extras)
|
GlobalMockMemory.updateFromBundle(extras)
|
||||||
TraceLogger.i("SystemServer", "Config Synced -> Enabled=${GlobalMockMemory.isEnabled}, Target=(${GlobalMockMemory.latitude}, ${GlobalMockMemory.longitude}), Mode=${GlobalMockMemory.mode}, Whitelist=${GlobalMockMemory.whitelist.size}, Blacklist=${GlobalMockMemory.blacklist.size}")
|
TraceLogger.i("SystemServer", "Config Synced -> Enabled=${GlobalMockMemory.isEnabled}, Target=(${GlobalMockMemory.latitude}, ${GlobalMockMemory.longitude}), Mode=${GlobalMockMemory.mode}, Whitelist=${GlobalMockMemory.whitelist.size}, Blacklist=${GlobalMockMemory.blacklist.size}")
|
||||||
|
if (GlobalMockMemory.isEnabled) {
|
||||||
|
pushLocationToActiveListeners()
|
||||||
|
}
|
||||||
param.result = true
|
param.result = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,10 +199,12 @@ object SystemServerHook {
|
|||||||
val binder = (arg as? IInterface)?.asBinder() ?: (arg as? IBinder)
|
val binder = (arg as? IInterface)?.asBinder() ?: (arg as? IBinder)
|
||||||
if (binder != null) {
|
if (binder != null) {
|
||||||
activeListeners[binder] = pkg
|
activeListeners[binder] = pkg
|
||||||
|
activeListenerInstances[binder] = arg to provider
|
||||||
TraceLogger.i("SystemServer", "Bound listener binder=$binder to pkg=$pkg")
|
TraceLogger.i("SystemServer", "Bound listener binder=$binder to pkg=$pkg")
|
||||||
try {
|
try {
|
||||||
binder.linkToDeath({
|
binder.linkToDeath({
|
||||||
activeListeners.remove(binder)
|
activeListeners.remove(binder)
|
||||||
|
activeListenerInstances.remove(binder)
|
||||||
TraceLogger.d("SystemServer", "Listener binder dead for pkg=$pkg")
|
TraceLogger.d("SystemServer", "Listener binder dead for pkg=$pkg")
|
||||||
}, 0)
|
}, 0)
|
||||||
} catch (_: Throwable) {}
|
} catch (_: Throwable) {}
|
||||||
@@ -327,6 +334,25 @@ object SystemServerHook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1Hz 配置同步时主动向已登记的目标应用监听器推送最新坐标(解决未勾选目标软件时跑步模式不动的问题)
|
||||||
|
*/
|
||||||
|
private fun pushLocationToActiveListeners() {
|
||||||
|
if (!GlobalMockMemory.isEnabled || activeListenerInstances.isEmpty()) return
|
||||||
|
pushExecutor.execute {
|
||||||
|
for ((binder, entry) in activeListenerInstances) {
|
||||||
|
val pkg = activeListeners[binder] ?: continue
|
||||||
|
if (!GlobalMockMemory.shouldMock(pkg)) continue
|
||||||
|
if (!binder.isBinderAlive) {
|
||||||
|
activeListeners.remove(binder)
|
||||||
|
activeListenerInstances.remove(binder)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sendInitialMockLocation(entry.first, entry.second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 首帧秒推辅助方法(对齐 GhostMapX Lcf.a 144-200行)
|
* 首帧秒推辅助方法(对齐 GhostMapX Lcf.a 144-200行)
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in new issue
Block a user