release: v1.3.2 - system_server persistent notification, TencentLocation getDirection hook & settings cleanup

This commit is contained in:
LZX committed 2026-11-15 19:41:55 +08:00
1 parent b039f610b3
commit cc60b0de15
11 files changed
+374 -36

No files matched your search

+2 -2
View File
@@ -18,8 +18,8 @@ android {
applicationId = "com.lzxnone.openloc" applicationId = "com.lzxnone.openloc"
minSdk = 28 minSdk = 28
targetSdk = 36 targetSdk = 36
versionCode = 9 versionCode = 10
versionName = "1.3.1" versionName = "1.3.2"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
} }
@@ -1,5 +1,6 @@
package com.lzxnone.openloc.core.service package com.lzxnone.openloc.core.service
import android.app.AlarmManager
import android.app.Notification import android.app.Notification
import android.app.NotificationChannel import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
@@ -8,8 +9,10 @@ import android.app.Service
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.ServiceInfo import android.content.pm.ServiceInfo
import android.graphics.BitmapFactory
import android.os.Build import android.os.Build
import android.os.IBinder import android.os.IBinder
import android.os.SystemClock
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import com.lzxnone.openloc.MainActivity import com.lzxnone.openloc.MainActivity
import com.lzxnone.openloc.R import com.lzxnone.openloc.R
@@ -24,16 +27,17 @@ class MockLocationForegroundService : Service() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
AppPreferences.init(applicationContext)
createNotificationChannel() createNotificationChannel()
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (!AppPreferences.isServiceEnabled) { if (!AppPreferences.isServiceEnabled || !AppPreferences.isNotificationEnabled) {
stopSelf() stopSelf()
return START_NOT_STICKY return START_NOT_STICKY
} }
val notification = buildNotification() val notification = buildNotification(this)
try { try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground( startForeground(
@@ -54,6 +58,27 @@ class MockLocationForegroundService : Service() {
return START_STICKY 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() { private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager ?: return 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 { companion object {
private const val CHANNEL_ID = "openloc_keepalive" private const val CHANNEL_ID = "openloc_keepalive"
private const val NOTIFICATION_ID = 10086 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) { fun start(context: Context) {
try { try {
@@ -16,7 +16,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.graphics.toArgb
import com.lzxnone.openloc.R 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.SearchResult
import com.lzxnone.openloc.core.util.TraceLogger import com.lzxnone.openloc.core.util.TraceLogger
import com.lzxnone.openloc.data.model.FavoriteItem 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_DYNAMIC_COLOR = "dynamic_color"
private const val KEY_LANGUAGE = "language" private const val KEY_LANGUAGE = "language"
private const val KEY_SERVICE_ENABLED = "mock_service_enabled" private const val KEY_SERVICE_ENABLED = "mock_service_enabled"
private const val KEY_NOTIFICATION_ENABLED = "enable_notification"
private lateinit var prefs: SharedPreferences private lateinit var prefs: SharedPreferences
@Volatile @Volatile
@@ -167,12 +167,17 @@ object AppPreferences {
var isSensorSimulationEnabled by mutableStateOf(true) var isSensorSimulationEnabled by mutableStateOf(true)
private set private set
var isRunningModeEnabled by mutableStateOf(true) var isRunningModeEnabled by mutableStateOf(false)
private set private set
private val processToken = android.os.Binder()
var runningSpeedMps by androidx.compose.runtime.mutableFloatStateOf(3.0f) var runningSpeedMps by androidx.compose.runtime.mutableFloatStateOf(3.0f)
private set private set
var isNotificationEnabled by mutableStateOf(false)
private set
var isStealthEnabled by mutableStateOf(true) var isStealthEnabled by mutableStateOf(true)
private set private set
@@ -341,8 +346,9 @@ object AppPreferences {
isGnssSimulationEnabled = prefs.getBoolean(KEY_ENABLE_GNSS_SIMULATION, true) isGnssSimulationEnabled = prefs.getBoolean(KEY_ENABLE_GNSS_SIMULATION, true)
isNetworkCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_NETWORK_CAMOUFLAGE, true) isNetworkCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_NETWORK_CAMOUFLAGE, true)
isSensorSimulationEnabled = prefs.getBoolean(KEY_ENABLE_SENSOR_SIMULATION, 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) 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) isStealthEnabled = prefs.getBoolean(KEY_ENABLE_STEALTH, true)
isDevCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_DEV_CAMOUFLAGE, true) isDevCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_DEV_CAMOUFLAGE, true)
isAutoCheckUpdateEnabled = prefs.getBoolean(KEY_AUTO_CHECK_UPDATE, true) isAutoCheckUpdateEnabled = prefs.getBoolean(KEY_AUTO_CHECK_UPDATE, true)
@@ -354,7 +360,6 @@ object AppPreferences {
syncConfigToSystem() syncConfigToSystem()
if (isServiceEnabled) { if (isServiceEnabled) {
appContext?.let { MockLocationForegroundService.start(it) }
startTickerIfNeeded() startTickerIfNeeded()
} }
} }
@@ -380,6 +385,10 @@ object AppPreferences {
putString(GlobalMockMemory.EXTRA_LOCATION_NAME, mockLocationName) putString(GlobalMockMemory.EXTRA_LOCATION_NAME, mockLocationName)
putString(GlobalMockMemory.EXTRA_MODE, appMockMode.name) putString(GlobalMockMemory.EXTRA_MODE, appMockMode.name)
putBoolean(GlobalMockMemory.EXTRA_SENSOR_SIMULATION, isSensorSimulationEnabled) 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_WHITELIST, ArrayList(whitelistApps))
putStringArrayList(GlobalMockMemory.EXTRA_BLACKLIST, ArrayList(blacklistApps)) putStringArrayList(GlobalMockMemory.EXTRA_BLACKLIST, ArrayList(blacklistApps))
} }
@@ -468,11 +477,9 @@ object AppPreferences {
hasActivePoint = true hasActivePoint = true
} }
syncConfigToSystem() syncConfigToSystem()
appContext?.let { MockLocationForegroundService.start(it) }
startTickerIfNeeded() startTickerIfNeeded()
} else { } else {
stopTicker() stopTicker()
appContext?.let { MockLocationForegroundService.stop(it) }
activeSpeed = 0.0f activeSpeed = 0.0f
activeBearing = 0.0f activeBearing = 0.0f
syncConfigToSystem() syncConfigToSystem()
@@ -487,8 +494,8 @@ object AppPreferences {
activeLng = mockLongitude activeLng = mockLongitude
activeSpeed = 0.0f activeSpeed = 0.0f
activeBearing = 0.0f activeBearing = 0.0f
syncConfigToSystem()
} }
syncConfigToSystem()
} }
fun updateRunningSpeed(speedMps: Float) { fun updateRunningSpeed(speedMps: Float) {
@@ -497,6 +504,12 @@ object AppPreferences {
prefs.edit().putFloat(KEY_RUNNING_SPEED, clamped).apply() 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) { fun addSearchHistory(item: SearchResult) {
val updated = (listOf(item) + searchHistory.filterNot { it.name == item.name && it.latitude == item.latitude }).take(10) val updated = (listOf(item) + searchHistory.filterNot { it.name == item.name && it.latitude == item.latitude }).take(10)
searchHistory = updated searchHistory = updated
@@ -311,6 +311,7 @@ object ThirdPartyNlpHook {
"getAccuracy" -> hookGetter(method, packageName) { GlobalMockMemory.accuracy } "getAccuracy" -> hookGetter(method, packageName) { GlobalMockMemory.accuracy }
"getSpeed" -> hookGetter(method, packageName) { GlobalMockMemory.speed } "getSpeed" -> hookGetter(method, packageName) { GlobalMockMemory.speed }
"getBearing" -> hookGetter(method, packageName) { GlobalMockMemory.bearing } "getBearing" -> hookGetter(method, packageName) { GlobalMockMemory.bearing }
"getDirection" -> hookGetter(method, packageName) { GlobalMockMemory.bearing.toDouble() }
"getProvider" -> hookGetter(method, packageName) { "gps" } "getProvider" -> hookGetter(method, packageName) { "gps" }
"isMockGps" -> hookGetter(method, packageName) { 0 } "isMockGps" -> hookGetter(method, packageName) { 0 }
"getName", "getAddress" -> hookGetter(method, packageName) { "getName", "getAddress" -> hookGetter(method, packageName) {
@@ -375,9 +376,8 @@ object ThirdPartyNlpHook {
return null return null
} }
val gcj = CoordinateConverter.wgs84ToGcj02(GlobalMockMemory.latitude, GlobalMockMemory.longitude) val lat = GlobalMockMemory.latitude
val lat = gcj[0] val lng = GlobalMockMemory.longitude
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
@@ -27,6 +27,9 @@ object GlobalMockMemory {
const val EXTRA_WHITELIST = "whitelist" const val EXTRA_WHITELIST = "whitelist"
const val EXTRA_BLACKLIST = "blacklist" const val EXTRA_BLACKLIST = "blacklist"
const val EXTRA_SENSOR_SIMULATION = "enable_sensor_simulation" 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 isEnabled: Boolean = false
@Volatile var latitude: Double = 39.908722 @Volatile var latitude: Double = 39.908722
@@ -40,6 +43,9 @@ object GlobalMockMemory {
@Volatile var whitelist: Set<String> = emptySet() @Volatile var whitelist: Set<String> = emptySet()
@Volatile var blacklist: Set<String> = emptySet() @Volatile var blacklist: Set<String> = emptySet()
@Volatile var enableSensorSimulation: Boolean = true @Volatile var enableSensorSimulation: Boolean = true
@Volatile var enableNotification: Boolean = false
@Volatile var runningModeEnabled: Boolean = false
@Volatile var enableJitter: Boolean = true
fun updateFromBundle(bundle: Bundle) { fun updateFromBundle(bundle: Bundle) {
isEnabled = bundle.getBoolean(EXTRA_ENABLED, isEnabled) isEnabled = bundle.getBoolean(EXTRA_ENABLED, isEnabled)
@@ -52,6 +58,9 @@ object GlobalMockMemory {
mode = bundle.getString(EXTRA_MODE, mode) ?: mode mode = bundle.getString(EXTRA_MODE, mode) ?: mode
locationName = bundle.getString(EXTRA_LOCATION_NAME, locationName) ?: locationName locationName = bundle.getString(EXTRA_LOCATION_NAME, locationName) ?: locationName
enableSensorSimulation = bundle.getBoolean(EXTRA_SENSOR_SIMULATION, enableSensorSimulation) 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) val whiteListArray = bundle.getStringArrayList(EXTRA_WHITELIST)
if (whiteListArray != null) { if (whiteListArray != null) {
@@ -76,6 +85,9 @@ object GlobalMockMemory {
putString(EXTRA_MODE, mode) putString(EXTRA_MODE, mode)
putString(EXTRA_LOCATION_NAME, locationName) putString(EXTRA_LOCATION_NAME, locationName)
putBoolean(EXTRA_SENSOR_SIMULATION, enableSensorSimulation) 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_WHITELIST, ArrayList(whitelist))
putStringArrayList(EXTRA_BLACKLIST, ArrayList(blacklist)) putStringArrayList(EXTRA_BLACKLIST, ArrayList(blacklist))
} }
@@ -1,10 +1,20 @@
package com.lzxnone.openloc.hook.system 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.location.Location
import android.os.Binder import android.os.Binder
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.IBinder import android.os.IBinder
import android.os.IInterface import android.os.IInterface
import com.lzxnone.openloc.R
import com.lzxnone.openloc.core.util.TraceLogger import com.lzxnone.openloc.core.util.TraceLogger
import com.lzxnone.openloc.hook.model.GlobalMockMemory import com.lzxnone.openloc.hook.model.GlobalMockMemory
import de.robv.android.xposed.XC_MethodHook import de.robv.android.xposed.XC_MethodHook
@@ -46,6 +56,11 @@ object SystemServerHook {
// 已挂钩 Wi-Fi 服务的类名集合,防止重复 Hook // 已挂钩 Wi-Fi 服务的类名集合,防止重复 Hook
private val hookedWifiClasses = Collections.synchronizedSet(mutableSetOf<String>()) 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) { fun hook(classLoader: ClassLoader) {
XposedBridge.log("[OpenLoc] [SystemServer] Initializing GhostMapX architecture in system_server...") XposedBridge.log("[OpenLoc] [SystemServer] Initializing GhostMapX architecture in system_server...")
@@ -90,7 +105,37 @@ object SystemServerHook {
extras.putAll(GlobalMockMemory.toBundle()) extras.putAll(GlobalMockMemory.toBundle())
param.result = true param.result = true
} else if (extras != null) { } else if (extras != null) {
if (systemContext == null) {
systemContext = try {
XposedHelpers.getObjectField(param.thisObject, "mContext") as? Context
} catch (_: Throwable) {
null
} ?: resolveSystemContext(classLoader)
}
GlobalMockMemory.updateFromBundle(extras) 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}") 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) { if (GlobalMockMemory.isEnabled) {
pushLocationToActiveListeners() pushLocationToActiveListeners()
@@ -604,4 +649,141 @@ object SystemServerHook {
} }
return null 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 package com.lzxnone.openloc.ui.screens.settings
import android.Manifest
import android.app.Activity import android.app.Activity
import android.content.pm.PackageManager
import android.os.Build import android.os.Build
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.border import androidx.compose.foundation.border
import androidx.compose.foundation.clickable 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.DeveloperMode
import androidx.compose.material.icons.filled.Explore import androidx.compose.material.icons.filled.Explore
import androidx.compose.material.icons.filled.Key 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.SatelliteAlt
import androidx.compose.material.icons.filled.Security import androidx.compose.material.icons.filled.Security
import androidx.compose.material.icons.filled.Translate import androidx.compose.material.icons.filled.Translate
@@ -96,6 +102,11 @@ fun SettingsScreen(
val scrollState = rememberScrollState() val scrollState = rememberScrollState()
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
val context = LocalContext.current val context = LocalContext.current
val notificationPermissionLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.RequestPermission()
) { granted ->
AppPreferences.updateNotificationEnabled(granted)
}
// 控制各个面板显示状态 // 控制各个面板显示状态
var showLanguageSheet by remember { mutableStateOf(false) } var showLanguageSheet by remember { mutableStateOf(false) }
@@ -316,7 +327,6 @@ fun SettingsScreen(
) { ) {
SettingSwitchItem( SettingSwitchItem(
title = stringResource(id = R.string.settings_sensor_simulation_title), title = stringResource(id = R.string.settings_sensor_simulation_title),
description = stringResource(id = R.string.settings_sensor_simulation_desc),
icon = Icons.Filled.Vibration, icon = Icons.Filled.Vibration,
checked = AppPreferences.isSensorSimulationEnabled, checked = AppPreferences.isSensorSimulationEnabled,
onCheckedChange = { AppPreferences.updateSensorSimulationEnabled(it) } onCheckedChange = { AppPreferences.updateSensorSimulationEnabled(it) }
@@ -346,7 +356,6 @@ fun SettingsScreen(
Column { Column {
SettingSwitchItem( SettingSwitchItem(
title = stringResource(id = R.string.settings_running_mode_title), title = stringResource(id = R.string.settings_running_mode_title),
description = stringResource(id = R.string.settings_running_mode_desc),
icon = Icons.Filled.Explore, icon = Icons.Filled.Explore,
checked = runningEnabled, checked = runningEnabled,
onCheckedChange = { AppPreferences.updateRunningModeEnabled(it) } 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. 地图与搜索服务板块 ------------------ // ------------------ 3. 地图与搜索服务板块 ------------------
Text( Text(
text = stringResource(id = R.string.settings_category_map_service), 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_channel_name">Location Keep-Alive Service</string>
<string name="service_keepalive_title">OpenLoc Location Service Running</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> <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> </resources>
@@ -209,6 +209,18 @@
<string name="service_keepalive_channel_name">定位后台常驻服务</string> <string name="service_keepalive_channel_name">定位后台常驻服务</string>
<string name="service_keepalive_title">OpenLoc 定位服务运行中</string> <string name="service_keepalive_title">OpenLoc 定位服务运行中</string>
<string name="service_keepalive_desc">正在后台保持 1Hz 连续定位与传感器拟真推送</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> </resources>
+12
View File
@@ -209,6 +209,18 @@
<string name="service_keepalive_channel_name">定位后台常驻服务</string> <string name="service_keepalive_channel_name">定位后台常驻服务</string>
<string name="service_keepalive_title">OpenLoc 定位服务运行中</string> <string name="service_keepalive_title">OpenLoc 定位服务运行中</string>
<string name="service_keepalive_desc">正在后台保持 1Hz 连续定位与传感器拟真推送</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> </resources>
+12
View File
@@ -209,4 +209,16 @@
<string name="service_keepalive_channel_name">Location Keep-Alive Service</string> <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_title">OpenLoc Location Service Running</string>
<string name="service_keepalive_desc">Keeping 1Hz location &amp; sensor simulation active in background</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> </resources>