diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1d85656..01c84f1 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -18,8 +18,8 @@ android { applicationId = "com.lzxnone.openloc" minSdk = 28 targetSdk = 36 - versionCode = 9 - versionName = "1.3.1" + versionCode = 10 + versionName = "1.3.2" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/lzxnone/openloc/core/service/MockLocationForegroundService.kt b/app/src/main/java/com/lzxnone/openloc/core/service/MockLocationForegroundService.kt index 5ebc944..171fab6 100644 --- a/app/src/main/java/com/lzxnone/openloc/core/service/MockLocationForegroundService.kt +++ b/app/src/main/java/com/lzxnone/openloc/core/service/MockLocationForegroundService.kt @@ -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 { diff --git a/app/src/main/java/com/lzxnone/openloc/data/preference/AppPreferences.kt b/app/src/main/java/com/lzxnone/openloc/data/preference/AppPreferences.kt index 646402b..abc0524 100644 --- a/app/src/main/java/com/lzxnone/openloc/data/preference/AppPreferences.kt +++ b/app/src/main/java/com/lzxnone/openloc/data/preference/AppPreferences.kt @@ -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 @@ -341,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) @@ -354,7 +360,6 @@ object AppPreferences { syncConfigToSystem() if (isServiceEnabled) { - appContext?.let { MockLocationForegroundService.start(it) } startTickerIfNeeded() } } @@ -380,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)) } @@ -468,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() @@ -487,8 +494,8 @@ object AppPreferences { activeLng = mockLongitude activeSpeed = 0.0f activeBearing = 0.0f - syncConfigToSystem() } + syncConfigToSystem() } fun updateRunningSpeed(speedMps: Float) { @@ -497,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 diff --git a/app/src/main/java/com/lzxnone/openloc/hook/client/ThirdPartyNlpHook.kt b/app/src/main/java/com/lzxnone/openloc/hook/client/ThirdPartyNlpHook.kt index 55946db..c2110ae 100644 --- a/app/src/main/java/com/lzxnone/openloc/hook/client/ThirdPartyNlpHook.kt +++ b/app/src/main/java/com/lzxnone/openloc/hook/client/ThirdPartyNlpHook.kt @@ -311,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) { @@ -375,9 +376,8 @@ object ThirdPartyNlpHook { return null } - val gcj = CoordinateConverter.wgs84ToGcj02(GlobalMockMemory.latitude, GlobalMockMemory.longitude) - val lat = gcj[0] - val lng = gcj[1] + val lat = GlobalMockMemory.latitude + val lng = GlobalMockMemory.longitude val alt = GlobalMockMemory.altitude val accuracy = GlobalMockMemory.accuracy val speed = GlobalMockMemory.speed diff --git a/app/src/main/java/com/lzxnone/openloc/hook/model/GlobalMockMemory.kt b/app/src/main/java/com/lzxnone/openloc/hook/model/GlobalMockMemory.kt index ed87e82..78605f8 100644 --- a/app/src/main/java/com/lzxnone/openloc/hook/model/GlobalMockMemory.kt +++ b/app/src/main/java/com/lzxnone/openloc/hook/model/GlobalMockMemory.kt @@ -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 = emptySet() @Volatile var blacklist: Set = 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)) } diff --git a/app/src/main/java/com/lzxnone/openloc/hook/system/SystemServerHook.kt b/app/src/main/java/com/lzxnone/openloc/hook/system/SystemServerHook.kt index ce7f251..1441b30 100644 --- a/app/src/main/java/com/lzxnone/openloc/hook/system/SystemServerHook.kt +++ b/app/src/main/java/com/lzxnone/openloc/hook/system/SystemServerHook.kt @@ -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 @@ -46,6 +56,11 @@ object SystemServerHook { // 已挂钩 Wi-Fi 服务的类名集合,防止重复 Hook private val hookedWifiClasses = Collections.synchronizedSet(mutableSetOf()) + 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...") @@ -90,7 +105,37 @@ 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() @@ -604,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) + } + } } diff --git a/app/src/main/java/com/lzxnone/openloc/ui/screens/settings/SettingsScreen.kt b/app/src/main/java/com/lzxnone/openloc/ui/screens/settings/SettingsScreen.kt index 42d8b7d..3b429a3 100644 --- a/app/src/main/java/com/lzxnone/openloc/ui/screens/settings/SettingsScreen.kt +++ b/app/src/main/java/com/lzxnone/openloc/ui/screens/settings/SettingsScreen.kt @@ -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), diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index c531efb..9f7c9c0 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -209,4 +209,16 @@ Location Keep-Alive Service OpenLoc Location Service Running Keeping 1Hz location & sensor simulation active in background + + + Notification Settings + Status Bar Notification + Show app icon, mock location, and motion parameters in a persistent notification while mock location is active + OpenLoc · %1$s + Running Mode + Static Mock + Custom Point + Lat: %1$.5f Lng: %2$.5f + Speed: %1$.2f m/s Bearing: %2$.0f° + X Accel: %1$.2f Y Accel: %2$.2f Z Accel: %3$.2f \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 91c0830..c89864f 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -209,6 +209,18 @@ 定位后台常驻服务 OpenLoc 定位服务运行中 正在后台保持 1Hz 连续定位与传感器拟真推送 + + + 通知设置 + 状态栏常驻通知 + 开启后,虚拟定位运行时将在任务栏常驻显示软件图标、名称、当前位置及运动参数 + OpenLoc · %1$s + 跑步模式 + 定点模拟 + 自定义坐标 + 纬度: %1$.5f 经度: %2$.5f + 速度: %1$.2f m/s 航向: %2$.0f° + X加速度: %1$.2f Y加速度: %2$.2f Z加速度: %3$.2f diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 91c0830..c89864f 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -209,6 +209,18 @@ 定位后台常驻服务 OpenLoc 定位服务运行中 正在后台保持 1Hz 连续定位与传感器拟真推送 + + + 通知设置 + 状态栏常驻通知 + 开启后,虚拟定位运行时将在任务栏常驻显示软件图标、名称、当前位置及运动参数 + OpenLoc · %1$s + 跑步模式 + 定点模拟 + 自定义坐标 + 纬度: %1$.5f 经度: %2$.5f + 速度: %1$.2f m/s 航向: %2$.0f° + X加速度: %1$.2f Y加速度: %2$.2f Z加速度: %3$.2f diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c531efb..9f7c9c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -209,4 +209,16 @@ Location Keep-Alive Service OpenLoc Location Service Running Keeping 1Hz location & sensor simulation active in background + + + Notification Settings + Status Bar Notification + Show app icon, mock location, and motion parameters in a persistent notification while mock location is active + OpenLoc · %1$s + Running Mode + Static Mock + Custom Point + Lat: %1$.5f Lng: %2$.5f + Speed: %1$.2f m/s Bearing: %2$.0f° + X Accel: %1$.2f Y Accel: %2$.2f Z Accel: %3$.2f \ No newline at end of file