2 Commits
13 changed files with 477 additions and 52 deletions

No files matched your search

+4 -9
View File
@@ -18,19 +18,14 @@ android {
applicationId = "com.lzxnone.openloc"
minSdk = 28
targetSdk = 36
versionCode = 8
versionName = "1.3.0"
versionCode = 10
versionName = "1.3.2"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
splits {
abi {
isEnable = true
reset()
include("armeabi-v7a", "arm64-v8a", "x86", "x86_64")
isUniversalApk = true
}
base {
archivesName.set("OpenLoc-v${defaultConfig.versionName}")
}
@@ -30,8 +30,11 @@ class LocationConfigProvider : ContentProvider() {
val prefs = ctx.getSharedPreferences("openloc_prefs", Context.MODE_PRIVATE)
val isEnabled = prefs.getBoolean("mock_service_enabled", false)
val lat = prefs.getString("mock_latitude", "39.908722")?.toDoubleOrNull() ?: 39.908722
val lng = prefs.getString("mock_longitude", "116.397496")?.toDoubleOrNull() ?: 116.397496
val runtime = AppPreferences.getRuntimeMockState()
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 mode = prefs.getString("app_mock_mode", "GLOBAL") ?: "GLOBAL"
val whitelistJson = prefs.getString("whitelist_apps", "[]") ?: "[]"
@@ -47,6 +50,10 @@ class LocationConfigProvider : ContentProvider() {
putBoolean(ConfigContract.KEY_ENABLED, isEnabled)
putDouble(ConfigContract.KEY_LATITUDE, lat)
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_APP_MOCK_MODE, mode)
putString(ConfigContract.KEY_WHITELIST_APPS, whitelistJson)
@@ -1,5 +1,6 @@
package com.lzxnone.openloc.core.service
import android.app.AlarmManager
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
@@ -8,8 +9,10 @@ import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.graphics.BitmapFactory
import android.os.Build
import android.os.IBinder
import android.os.SystemClock
import androidx.core.app.NotificationCompat
import com.lzxnone.openloc.MainActivity
import com.lzxnone.openloc.R
@@ -24,16 +27,17 @@ class MockLocationForegroundService : Service() {
override fun onCreate() {
super.onCreate()
AppPreferences.init(applicationContext)
createNotificationChannel()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (!AppPreferences.isServiceEnabled) {
if (!AppPreferences.isServiceEnabled || !AppPreferences.isNotificationEnabled) {
stopSelf()
return START_NOT_STICKY
}
val notification = buildNotification()
val notification = buildNotification(this)
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(
@@ -54,6 +58,27 @@ class MockLocationForegroundService : Service() {
return START_STICKY
}
override fun onTaskRemoved(rootIntent: Intent?) {
if (AppPreferences.isServiceEnabled && AppPreferences.isNotificationEnabled) {
try {
val restartIntent = Intent(applicationContext, MockLocationForegroundService::class.java)
val pendingIntentFlags = PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
PendingIntent.getForegroundService(applicationContext, RESTART_REQUEST_CODE, restartIntent, pendingIntentFlags)
} else {
PendingIntent.getService(applicationContext, RESTART_REQUEST_CODE, restartIntent, pendingIntentFlags)
}
val alarmManager = getSystemService(Context.ALARM_SERVICE) as? AlarmManager
alarmManager?.set(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + 1000L,
pendingIntent
)
} catch (_: Throwable) {}
}
super.onTaskRemoved(rootIntent)
}
private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager ?: return
@@ -68,29 +93,54 @@ class MockLocationForegroundService : Service() {
}
}
private fun buildNotification(): Notification {
val launchIntent = Intent(this, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
}
val pendingIntent = PendingIntent.getActivity(
this,
0,
launchIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
return NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getString(R.string.service_keepalive_title))
.setContentText(getString(R.string.service_keepalive_desc))
.setOngoing(true)
.setSilent(true)
.setContentIntent(pendingIntent)
.build()
}
companion object {
private const val CHANNEL_ID = "openloc_keepalive"
private const val NOTIFICATION_ID = 10086
private const val RESTART_REQUEST_CODE = 10087
fun buildNotification(context: Context): Notification {
val launchIntent = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
}
val pendingIntent = PendingIntent.getActivity(
context,
0,
launchIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
val title = context.getString(R.string.service_keepalive_title)
val desc = context.getString(R.string.service_keepalive_desc)
val largeIcon = try {
BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher_round)
} catch (_: Throwable) {
null
}
return NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.apply {
if (largeIcon != null) {
setLargeIcon(largeIcon)
}
}
.setContentTitle(title)
.setContentText(desc)
.setOngoing(true)
.setOnlyAlertOnce(true)
.setSilent(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent)
.build()
}
fun updateNotification(context: Context) {
if (!AppPreferences.isServiceEnabled || !AppPreferences.isNotificationEnabled) return
try {
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager ?: return
manager.notify(NOTIFICATION_ID, buildNotification(context))
} catch (_: Throwable) {}
}
fun start(context: Context) {
try {
@@ -16,7 +16,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import com.lzxnone.openloc.R
import com.lzxnone.openloc.core.service.MockLocationForegroundService
import com.lzxnone.openloc.core.util.SearchResult
import com.lzxnone.openloc.core.util.TraceLogger
import com.lzxnone.openloc.data.model.FavoriteItem
@@ -96,6 +95,7 @@ object AppPreferences {
private const val KEY_DYNAMIC_COLOR = "dynamic_color"
private const val KEY_LANGUAGE = "language"
private const val KEY_SERVICE_ENABLED = "mock_service_enabled"
private const val KEY_NOTIFICATION_ENABLED = "enable_notification"
private lateinit var prefs: SharedPreferences
@Volatile
@@ -167,12 +167,17 @@ object AppPreferences {
var isSensorSimulationEnabled by mutableStateOf(true)
private set
var isRunningModeEnabled by mutableStateOf(true)
var isRunningModeEnabled by mutableStateOf(false)
private set
private val processToken = android.os.Binder()
var runningSpeedMps by androidx.compose.runtime.mutableFloatStateOf(3.0f)
private set
var isNotificationEnabled by mutableStateOf(false)
private set
var isStealthEnabled by mutableStateOf(true)
private set
@@ -201,6 +206,19 @@ object AppPreferences {
@Volatile private var activeBearing: Float = 0.0f
@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 {
HandlerThread("OpenLoc-1Hz-Ticker").apply { start() }
}
@@ -328,8 +346,9 @@ object AppPreferences {
isGnssSimulationEnabled = prefs.getBoolean(KEY_ENABLE_GNSS_SIMULATION, true)
isNetworkCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_NETWORK_CAMOUFLAGE, true)
isSensorSimulationEnabled = prefs.getBoolean(KEY_ENABLE_SENSOR_SIMULATION, true)
isRunningModeEnabled = prefs.getBoolean(KEY_RUNNING_MODE_ENABLED, true)
isRunningModeEnabled = prefs.getBoolean(KEY_RUNNING_MODE_ENABLED, false)
runningSpeedMps = prefs.getFloat(KEY_RUNNING_SPEED, 3.0f).coerceIn(1.0f, 8.0f)
isNotificationEnabled = prefs.getBoolean(KEY_NOTIFICATION_ENABLED, false)
isStealthEnabled = prefs.getBoolean(KEY_ENABLE_STEALTH, true)
isDevCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_DEV_CAMOUFLAGE, true)
isAutoCheckUpdateEnabled = prefs.getBoolean(KEY_AUTO_CHECK_UPDATE, true)
@@ -341,7 +360,6 @@ object AppPreferences {
syncConfigToSystem()
if (isServiceEnabled) {
appContext?.let { MockLocationForegroundService.start(it) }
startTickerIfNeeded()
}
}
@@ -367,6 +385,10 @@ object AppPreferences {
putString(GlobalMockMemory.EXTRA_LOCATION_NAME, mockLocationName)
putString(GlobalMockMemory.EXTRA_MODE, appMockMode.name)
putBoolean(GlobalMockMemory.EXTRA_SENSOR_SIMULATION, isSensorSimulationEnabled)
putBoolean(GlobalMockMemory.EXTRA_NOTIFICATION_ENABLED, isNotificationEnabled)
putBoolean(GlobalMockMemory.EXTRA_RUNNING_MODE_ENABLED, isRunningModeEnabled)
putBoolean(GlobalMockMemory.EXTRA_JITTER_ENABLED, isJitterEnabled)
putBinder("process_token", processToken)
putStringArrayList(GlobalMockMemory.EXTRA_WHITELIST, ArrayList(whitelistApps))
putStringArrayList(GlobalMockMemory.EXTRA_BLACKLIST, ArrayList(blacklistApps))
}
@@ -455,11 +477,9 @@ object AppPreferences {
hasActivePoint = true
}
syncConfigToSystem()
appContext?.let { MockLocationForegroundService.start(it) }
startTickerIfNeeded()
} else {
stopTicker()
appContext?.let { MockLocationForegroundService.stop(it) }
activeSpeed = 0.0f
activeBearing = 0.0f
syncConfigToSystem()
@@ -474,8 +494,8 @@ object AppPreferences {
activeLng = mockLongitude
activeSpeed = 0.0f
activeBearing = 0.0f
syncConfigToSystem()
}
syncConfigToSystem()
}
fun updateRunningSpeed(speedMps: Float) {
@@ -484,6 +504,12 @@ object AppPreferences {
prefs.edit().putFloat(KEY_RUNNING_SPEED, clamped).apply()
}
fun updateNotificationEnabled(enabled: Boolean) {
isNotificationEnabled = enabled
prefs.edit().putBoolean(KEY_NOTIFICATION_ENABLED, enabled).apply()
syncConfigToSystem()
}
fun addSearchHistory(item: SearchResult) {
val updated = (listOf(item) + searchHistory.filterNot { it.name == item.name && it.latitude == item.latitude }).take(10)
searchHistory = updated
@@ -4,6 +4,7 @@ import android.content.Context
import android.location.Location
import android.os.Bundle
import android.os.SystemClock
import com.lzxnone.openloc.core.util.CoordinateConverter
import com.lzxnone.openloc.core.util.TraceLogger
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
import com.lzxnone.openloc.hook.model.GlobalMockMemory
@@ -310,6 +311,7 @@ object ThirdPartyNlpHook {
"getAccuracy" -> hookGetter(method, packageName) { GlobalMockMemory.accuracy }
"getSpeed" -> hookGetter(method, packageName) { GlobalMockMemory.speed }
"getBearing" -> hookGetter(method, packageName) { GlobalMockMemory.bearing }
"getDirection" -> hookGetter(method, packageName) { GlobalMockMemory.bearing.toDouble() }
"getProvider" -> hookGetter(method, packageName) { "gps" }
"isMockGps" -> hookGetter(method, packageName) { 0 }
"getName", "getAddress" -> hookGetter(method, packageName) {
@@ -452,7 +454,27 @@ object ThirdPartyNlpHook {
if (bdLocationClass != null) {
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) {
when (method.name) {
"getLatitude" -> {
@@ -460,7 +482,16 @@ object ThirdPartyNlpHook {
XposedBridge.hookMethod(method, object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) {
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() {
override fun afterHookedMethod(param: MethodHookParam) {
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() {
override fun afterHookedMethod(param: MethodHookParam) {
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)
return try {
// 优先走 system_server 内存隧道(携带实时推进坐标、speed 与 bearing),失败再回退 ContentProvider
fetchFromSystemServer(context, now)?.let { return it }
val bundle = context.contentResolver.call(
PROVIDER_URI,
ConfigContract.METHOD_GET_CONFIG,
@@ -88,10 +91,10 @@ object ConfigFetcher {
isEnabled = bundle.getBoolean(ConfigContract.KEY_ENABLED, false),
latitude = bundle.getDouble(ConfigContract.KEY_LATITUDE, 39.908722),
longitude = bundle.getDouble(ConfigContract.KEY_LONGITUDE, 116.397496),
altitude = bundle.getDouble("altitude", 50.0),
accuracy = bundle.getFloat("accuracy", 5.0f),
bearing = bundle.getFloat("bearing", 0.0f),
speed = bundle.getFloat("speed", 0.0f),
altitude = bundle.getDouble("altitude", GlobalMockMemory.altitude),
accuracy = bundle.getFloat("accuracy", GlobalMockMemory.accuracy),
bearing = bundle.getFloat("bearing", GlobalMockMemory.bearing),
speed = bundle.getFloat("speed", GlobalMockMemory.speed),
mode = mode,
whitelist = parseSet(whitelistJson),
blacklist = parseSet(blacklistJson),
@@ -27,6 +27,9 @@ object GlobalMockMemory {
const val EXTRA_WHITELIST = "whitelist"
const val EXTRA_BLACKLIST = "blacklist"
const val EXTRA_SENSOR_SIMULATION = "enable_sensor_simulation"
const val EXTRA_NOTIFICATION_ENABLED = "enable_notification"
const val EXTRA_RUNNING_MODE_ENABLED = "running_mode_enabled"
const val EXTRA_JITTER_ENABLED = "enable_jitter"
@Volatile var isEnabled: Boolean = false
@Volatile var latitude: Double = 39.908722
@@ -40,6 +43,9 @@ object GlobalMockMemory {
@Volatile var whitelist: Set<String> = emptySet()
@Volatile var blacklist: Set<String> = emptySet()
@Volatile var enableSensorSimulation: Boolean = true
@Volatile var enableNotification: Boolean = false
@Volatile var runningModeEnabled: Boolean = false
@Volatile var enableJitter: Boolean = true
fun updateFromBundle(bundle: Bundle) {
isEnabled = bundle.getBoolean(EXTRA_ENABLED, isEnabled)
@@ -52,6 +58,9 @@ object GlobalMockMemory {
mode = bundle.getString(EXTRA_MODE, mode) ?: mode
locationName = bundle.getString(EXTRA_LOCATION_NAME, locationName) ?: locationName
enableSensorSimulation = bundle.getBoolean(EXTRA_SENSOR_SIMULATION, enableSensorSimulation)
enableNotification = bundle.getBoolean(EXTRA_NOTIFICATION_ENABLED, enableNotification)
runningModeEnabled = bundle.getBoolean(EXTRA_RUNNING_MODE_ENABLED, runningModeEnabled)
enableJitter = bundle.getBoolean(EXTRA_JITTER_ENABLED, enableJitter)
val whiteListArray = bundle.getStringArrayList(EXTRA_WHITELIST)
if (whiteListArray != null) {
@@ -76,6 +85,9 @@ object GlobalMockMemory {
putString(EXTRA_MODE, mode)
putString(EXTRA_LOCATION_NAME, locationName)
putBoolean(EXTRA_SENSOR_SIMULATION, enableSensorSimulation)
putBoolean(EXTRA_NOTIFICATION_ENABLED, enableNotification)
putBoolean(EXTRA_RUNNING_MODE_ENABLED, runningModeEnabled)
putBoolean(EXTRA_JITTER_ENABLED, enableJitter)
putStringArrayList(EXTRA_WHITELIST, ArrayList(whitelist))
putStringArrayList(EXTRA_BLACKLIST, ArrayList(blacklist))
}
@@ -113,13 +125,17 @@ object GlobalMockMemory {
* 生成标准可用的 Mock Location 对象
*/
fun createLocation(provider: String = "gps"): Location {
val currentSpeed = this@GlobalMockMemory.speed
val hasValidBearing = currentSpeed > 0.1f
return Location(provider).apply {
latitude = this@GlobalMockMemory.latitude
longitude = this@GlobalMockMemory.longitude
altitude = this@GlobalMockMemory.altitude
accuracy = this@GlobalMockMemory.accuracy
bearing = this@GlobalMockMemory.bearing
speed = this@GlobalMockMemory.speed
speed = currentSpeed
if (hasValidBearing) {
bearing = this@GlobalMockMemory.bearing
}
time = System.currentTimeMillis()
elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
@@ -127,7 +143,9 @@ object GlobalMockMemory {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
verticalAccuracyMeters = 1.5f
speedAccuracyMetersPerSecond = 0.1f
bearingAccuracyDegrees = 1.0f
if (hasValidBearing) {
bearingAccuracyDegrees = 1.0f
}
}
}
}
@@ -1,10 +1,20 @@
package com.lzxnone.openloc.hook.system
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.graphics.drawable.Icon
import android.location.Location
import android.os.Binder
import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.os.IInterface
import com.lzxnone.openloc.R
import com.lzxnone.openloc.core.util.TraceLogger
import com.lzxnone.openloc.hook.model.GlobalMockMemory
import de.robv.android.xposed.XC_MethodHook
@@ -36,7 +46,9 @@ object SystemServerHook {
// 活跃监听器与其所属目标包名的映射表(以 IBinder 为 key,彻底消除 Class 静态闭包污染)
private val activeListeners = ConcurrentHashMap<IBinder, String>()
private val activeListenerInstances = ConcurrentHashMap<IBinder, Pair<Any, String>>()
private val activeCallbacks = ConcurrentHashMap<IBinder, String>()
private val pushExecutor = java.util.concurrent.Executors.newSingleThreadExecutor()
// 已挂钩 onLocationChanged 的类名集合,防止重复 Hook
private val hookedListenerClasses = Collections.synchronizedSet(mutableSetOf<String>())
@@ -44,6 +56,11 @@ object SystemServerHook {
// 已挂钩 Wi-Fi 服务的类名集合,防止重复 Hook
private val hookedWifiClasses = Collections.synchronizedSet(mutableSetOf<String>())
private const val SYSTEM_NOTIFICATION_CHANNEL_ID = "openloc_system_keepalive"
private const val SYSTEM_NOTIFICATION_ID = 10086
@Volatile private var systemContext: Context? = null
@Volatile private var linkedProcessToken: IBinder? = null
fun hook(classLoader: ClassLoader) {
XposedBridge.log("[OpenLoc] [SystemServer] Initializing GhostMapX architecture in system_server...")
@@ -88,8 +105,41 @@ object SystemServerHook {
extras.putAll(GlobalMockMemory.toBundle())
param.result = true
} else if (extras != null) {
if (systemContext == null) {
systemContext = try {
XposedHelpers.getObjectField(param.thisObject, "mContext") as? Context
} catch (_: Throwable) {
null
} ?: resolveSystemContext(classLoader)
}
GlobalMockMemory.updateFromBundle(extras)
val token = extras.getBinder("process_token")
if (token != null && token !== linkedProcessToken) {
linkedProcessToken = token
try {
token.linkToDeath({
if (linkedProcessToken === token) {
linkedProcessToken = null
}
if (GlobalMockMemory.isEnabled && GlobalMockMemory.enableNotification) {
postSystemNotification(isProcessAlive = false)
}
}, 0)
} catch (_: Throwable) {
if (GlobalMockMemory.isEnabled && GlobalMockMemory.enableNotification) {
postSystemNotification(isProcessAlive = false)
}
}
}
if (GlobalMockMemory.isEnabled && GlobalMockMemory.enableNotification) {
postSystemNotification(isProcessAlive = true)
} else {
cancelSystemNotification()
}
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
}
}
@@ -194,10 +244,12 @@ object SystemServerHook {
val binder = (arg as? IInterface)?.asBinder() ?: (arg as? IBinder)
if (binder != null) {
activeListeners[binder] = pkg
activeListenerInstances[binder] = arg to provider
TraceLogger.i("SystemServer", "Bound listener binder=$binder to pkg=$pkg")
try {
binder.linkToDeath({
activeListeners.remove(binder)
activeListenerInstances.remove(binder)
TraceLogger.d("SystemServer", "Listener binder dead for pkg=$pkg")
}, 0)
} catch (_: Throwable) {}
@@ -327,6 +379,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行)
*/
@@ -578,4 +649,141 @@ object SystemServerHook {
}
return null
}
private fun resolveSystemContext(classLoader: ClassLoader): Context? {
return try {
val atClass = XposedHelpers.findClass("android.app.ActivityThread", classLoader)
val at = XposedHelpers.callStaticMethod(atClass, "currentActivityThread")
XposedHelpers.callMethod(at, "getSystemContext") as? Context
} catch (_: Throwable) {
null
}
}
private fun postSystemNotification(isProcessAlive: Boolean = true) {
val sysCtx = systemContext ?: return
val identity = Binder.clearCallingIdentity()
try {
val manager = sysCtx.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager ?: return
val openLocCtx = try {
sysCtx.createPackageContext("com.lzxnone.openloc", Context.CONTEXT_IGNORE_SECURITY)
} catch (_: Throwable) {
sysCtx
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
SYSTEM_NOTIFICATION_CHANNEL_ID,
openLocCtx.getString(R.string.service_keepalive_channel_name),
NotificationManager.IMPORTANCE_LOW
).apply {
setShowBadge(false)
}
manager.createNotificationChannel(channel)
}
val launchIntent = Intent().apply {
setClassName("com.lzxnone.openloc", "com.lzxnone.openloc.MainActivity")
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
}
val pendingIntent = PendingIntent.getActivity(
sysCtx,
0,
launchIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
val modeText = if (GlobalMockMemory.runningModeEnabled) {
openLocCtx.getString(R.string.notification_mode_running)
} else {
openLocCtx.getString(R.string.notification_mode_static)
}
val title = openLocCtx.getString(R.string.notification_title_format, modeText)
val locationName = GlobalMockMemory.locationName.takeIf { it.isNotBlank() }
?: openLocCtx.getString(R.string.notification_location_unnamed)
val coordLine = openLocCtx.getString(
R.string.notification_coord_line,
GlobalMockMemory.latitude,
GlobalMockMemory.longitude
)
val displaySpeed = if (isProcessAlive) GlobalMockMemory.speed else 0.0f
val displayBearing = if (isProcessAlive && GlobalMockMemory.speed > 0.05f) GlobalMockMemory.bearing else 0.0f
val speedBearingLine = openLocCtx.getString(
R.string.notification_speed_bearing_line,
displaySpeed,
displayBearing
)
val (accelX, accelY, accelZ) = if (GlobalMockMemory.enableSensorSimulation && displaySpeed > 0.05f) {
val clampedSpeed = displaySpeed.coerceIn(0.3f, 6.0f)
val stepFreq = (1.65f + (clampedSpeed - 1.0f) * 0.22f).coerceIn(1.3f, 3.2f)
val nowSec = System.currentTimeMillis() / 1000.0
val phase = (nowSec * 2.0 * Math.PI * stepFreq) % (2.0 * Math.PI)
val impactAmp = 1.2f + (clampedSpeed - 0.3f) * 0.65f
val swayAmp = 0.25f + (clampedSpeed - 0.3f) * 0.12f
val ax = swayAmp * kotlin.math.sin(phase * 0.5).toFloat()
val ay = swayAmp * 0.5f * kotlin.math.sin(phase * 0.5).toFloat()
val az = 9.81f + impactAmp * (0.72 * kotlin.math.sin(phase) + 0.28 * kotlin.math.sin(2.0 * phase)).toFloat()
Triple(ax, ay, az)
} else {
Triple(0.0f, 0.0f, 9.81f)
}
val accelLine = openLocCtx.getString(
R.string.notification_accel_line,
accelX,
accelY,
accelZ
)
val fullText = "$locationName\n$coordLine\n$speedBearingLine\n$accelLine"
val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Notification.Builder(sysCtx, SYSTEM_NOTIFICATION_CHANNEL_ID)
} else {
@Suppress("DEPRECATION")
Notification.Builder(sysCtx)
}
val smallIcon = Icon.createWithResource("com.lzxnone.openloc", R.mipmap.ic_launcher)
val largeIcon = try {
BitmapFactory.decodeResource(openLocCtx.resources, R.mipmap.ic_launcher_round)
} catch (_: Throwable) {
null
}
builder.setSmallIcon(smallIcon)
.apply {
if (largeIcon != null) {
setLargeIcon(largeIcon)
}
}
.setContentTitle(title)
.setContentText(locationName)
.setStyle(Notification.BigTextStyle().bigText(fullText))
.setOngoing(true)
.setOnlyAlertOnce(true)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent)
manager.notify(SYSTEM_NOTIFICATION_ID, builder.build())
} catch (t: Throwable) {
TraceLogger.e("SystemServer", "postSystemNotification failed: ${t.message}")
} finally {
Binder.restoreCallingIdentity(identity)
}
}
private fun cancelSystemNotification() {
val sysCtx = systemContext ?: return
val identity = Binder.clearCallingIdentity()
try {
val manager = sysCtx.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager ?: return
manager.cancel(SYSTEM_NOTIFICATION_ID)
} catch (_: Throwable) {
} finally {
Binder.restoreCallingIdentity(identity)
}
}
}
@@ -1,8 +1,13 @@
package com.lzxnone.openloc.ui.screens.settings
import android.Manifest
import android.app.Activity
import android.content.pm.PackageManager
import android.os.Build
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
@@ -33,6 +38,7 @@ import androidx.compose.material.icons.filled.DarkMode
import androidx.compose.material.icons.filled.DeveloperMode
import androidx.compose.material.icons.filled.Explore
import androidx.compose.material.icons.filled.Key
import androidx.compose.material.icons.filled.Notifications
import androidx.compose.material.icons.filled.SatelliteAlt
import androidx.compose.material.icons.filled.Security
import androidx.compose.material.icons.filled.Translate
@@ -96,6 +102,11 @@ fun SettingsScreen(
val scrollState = rememberScrollState()
val coroutineScope = rememberCoroutineScope()
val context = LocalContext.current
val notificationPermissionLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.RequestPermission()
) { granted ->
AppPreferences.updateNotificationEnabled(granted)
}
// 控制各个面板显示状态
var showLanguageSheet by remember { mutableStateOf(false) }
@@ -316,7 +327,6 @@ fun SettingsScreen(
) {
SettingSwitchItem(
title = stringResource(id = R.string.settings_sensor_simulation_title),
description = stringResource(id = R.string.settings_sensor_simulation_desc),
icon = Icons.Filled.Vibration,
checked = AppPreferences.isSensorSimulationEnabled,
onCheckedChange = { AppPreferences.updateSensorSimulationEnabled(it) }
@@ -346,7 +356,6 @@ fun SettingsScreen(
Column {
SettingSwitchItem(
title = stringResource(id = R.string.settings_running_mode_title),
description = stringResource(id = R.string.settings_running_mode_desc),
icon = Icons.Filled.Explore,
checked = runningEnabled,
onCheckedChange = { AppPreferences.updateRunningModeEnabled(it) }
@@ -422,6 +431,30 @@ fun SettingsScreen(
}
}
// ------------------ 2.6 通知设置板块 ------------------
Text(
text = stringResource(id = R.string.settings_category_notification),
style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold),
color = MaterialTheme.colorScheme.primary,
modifier = Modifier.padding(start = 4.dp, top = 4.dp)
)
Card(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(16.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface),
elevation = CardDefaults.cardElevation(defaultElevation = 1.dp)
) {
SettingSwitchItem(
title = stringResource(id = R.string.settings_notification_enabled_title),
icon = Icons.Default.Notifications,
checked = AppPreferences.isNotificationEnabled,
onCheckedChange = { enabled ->
AppPreferences.updateNotificationEnabled(enabled)
}
)
}
// ------------------ 3. 地图与搜索服务板块 ------------------
Text(
text = stringResource(id = R.string.settings_category_map_service),
+12
View File
@@ -209,4 +209,16 @@
<string name="service_keepalive_channel_name">Location Keep-Alive Service</string>
<string name="service_keepalive_title">OpenLoc Location Service Running</string>
<string name="service_keepalive_desc">Keeping 1Hz location &amp; sensor simulation active in background</string>
<!-- Notification Settings -->
<string name="settings_category_notification">Notification Settings</string>
<string name="settings_notification_enabled_title">Status Bar Notification</string>
<string name="settings_notification_enabled_desc">Show app icon, mock location, and motion parameters in a persistent notification while mock location is active</string>
<string name="notification_title_format">OpenLoc · %1$s</string>
<string name="notification_mode_running">Running Mode</string>
<string name="notification_mode_static">Static Mock</string>
<string name="notification_location_unnamed">Custom Point</string>
<string name="notification_coord_line">Lat: %1$.5f Lng: %2$.5f</string>
<string name="notification_speed_bearing_line">Speed: %1$.2f m/s Bearing: %2$.0f°</string>
<string name="notification_accel_line">X Accel: %1$.2f Y Accel: %2$.2f Z Accel: %3$.2f</string>
</resources>
@@ -209,6 +209,18 @@
<string name="service_keepalive_channel_name">定位后台常驻服务</string>
<string name="service_keepalive_title">OpenLoc 定位服务运行中</string>
<string name="service_keepalive_desc">正在后台保持 1Hz 连续定位与传感器拟真推送</string>
<!-- 通知设置 -->
<string name="settings_category_notification">通知设置</string>
<string name="settings_notification_enabled_title">状态栏常驻通知</string>
<string name="settings_notification_enabled_desc">开启后,虚拟定位运行时将在任务栏常驻显示软件图标、名称、当前位置及运动参数</string>
<string name="notification_title_format">OpenLoc · %1$s</string>
<string name="notification_mode_running">跑步模式</string>
<string name="notification_mode_static">定点模拟</string>
<string name="notification_location_unnamed">自定义坐标</string>
<string name="notification_coord_line">纬度: %1$.5f 经度: %2$.5f</string>
<string name="notification_speed_bearing_line">速度: %1$.2f m/s 航向: %2$.0f°</string>
<string name="notification_accel_line">X加速度: %1$.2f Y加速度: %2$.2f Z加速度: %3$.2f</string>
</resources>
+12
View File
@@ -209,6 +209,18 @@
<string name="service_keepalive_channel_name">定位后台常驻服务</string>
<string name="service_keepalive_title">OpenLoc 定位服务运行中</string>
<string name="service_keepalive_desc">正在后台保持 1Hz 连续定位与传感器拟真推送</string>
<!-- 通知设置 -->
<string name="settings_category_notification">通知设置</string>
<string name="settings_notification_enabled_title">状态栏常驻通知</string>
<string name="settings_notification_enabled_desc">开启后,虚拟定位运行时将在任务栏常驻显示软件图标、名称、当前位置及运动参数</string>
<string name="notification_title_format">OpenLoc · %1$s</string>
<string name="notification_mode_running">跑步模式</string>
<string name="notification_mode_static">定点模拟</string>
<string name="notification_location_unnamed">自定义坐标</string>
<string name="notification_coord_line">纬度: %1$.5f 经度: %2$.5f</string>
<string name="notification_speed_bearing_line">速度: %1$.2f m/s 航向: %2$.0f°</string>
<string name="notification_accel_line">X加速度: %1$.2f Y加速度: %2$.2f Z加速度: %3$.2f</string>
</resources>
+12
View File
@@ -209,4 +209,16 @@
<string name="service_keepalive_channel_name">Location Keep-Alive Service</string>
<string name="service_keepalive_title">OpenLoc Location Service Running</string>
<string name="service_keepalive_desc">Keeping 1Hz location &amp; sensor simulation active in background</string>
<!-- Notification Settings -->
<string name="settings_category_notification">Notification Settings</string>
<string name="settings_notification_enabled_title">Status Bar Notification</string>
<string name="settings_notification_enabled_desc">Show app icon, mock location, and motion parameters in a persistent notification while mock location is active</string>
<string name="notification_title_format">OpenLoc · %1$s</string>
<string name="notification_mode_running">Running Mode</string>
<string name="notification_mode_static">Static Mock</string>
<string name="notification_location_unnamed">Custom Point</string>
<string name="notification_coord_line">Lat: %1$.5f Lng: %2$.5f</string>
<string name="notification_speed_bearing_line">Speed: %1$.2f m/s Bearing: %2$.0f°</string>
<string name="notification_accel_line">X Accel: %1$.2f Y Accel: %2$.2f Z Accel: %3$.2f</string>
</resources>