feat: Initial commit of OpenLoc
No files matched your search
@@ -0,0 +1,24 @@
|
||||
package com.lzxnone.openloc
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.lzxnone.openloc", appContext.packageName)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission
|
||||
android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||
tools:ignore="QueryAllPackagesPermission" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.OpenLoc">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.OpenLoc">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Xposed / LSPosed 模块标识 -->
|
||||
<meta-data
|
||||
android:name="xposedmodule"
|
||||
android:value="true" />
|
||||
<meta-data
|
||||
android:name="xposeddescription"
|
||||
android:value="@string/xposed_description" />
|
||||
<meta-data
|
||||
android:name="xposedminversion"
|
||||
android:value="82" />
|
||||
<meta-data
|
||||
android:name="xposedscope"
|
||||
android:resource="@array/xposed_scope" />
|
||||
|
||||
<!-- 跨进程配置共享 Provider -->
|
||||
<provider
|
||||
android:name=".core.provider.LocationConfigProvider"
|
||||
android:authorities="com.lzxnone.openloc.provider"
|
||||
android:exported="true"
|
||||
tools:ignore="ExportedContentProvider" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1 @@
|
||||
com.lzxnone.openloc.hook.HookEntry
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.lzxnone.openloc
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.lzxnone.openloc.data.preference.AppLanguage
|
||||
import com.lzxnone.openloc.data.preference.AppPreferences
|
||||
import com.lzxnone.openloc.ui.screens.MainScreen
|
||||
import com.lzxnone.openloc.ui.theme.OpenLocTheme
|
||||
import java.util.Locale
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
override fun attachBaseContext(newBase: Context) {
|
||||
AppPreferences.init(newBase)
|
||||
val appLanguage = AppPreferences.appLanguage
|
||||
val localizedContext = createLocalizedContext(newBase, appLanguage)
|
||||
super.attachBaseContext(localizedContext)
|
||||
}
|
||||
|
||||
override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
|
||||
if (overrideConfiguration != null) {
|
||||
val appLanguage = AppPreferences.appLanguage
|
||||
val locale = getLocaleForLanguage(appLanguage)
|
||||
overrideConfiguration.setLocale(locale)
|
||||
}
|
||||
super.applyOverrideConfiguration(overrideConfiguration)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
AppPreferences.init(applicationContext)
|
||||
updateActivityLocale(this, AppPreferences.appLanguage)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
val currentLanguage = AppPreferences.appLanguage
|
||||
val baseContext = LocalContext.current
|
||||
|
||||
val localizedContext = remember(currentLanguage, baseContext) {
|
||||
createLocalizedContext(baseContext, currentLanguage)
|
||||
}
|
||||
|
||||
CompositionLocalProvider(
|
||||
LocalContext provides localizedContext,
|
||||
LocalConfiguration provides localizedContext.resources.configuration,
|
||||
androidx.activity.compose.LocalActivityResultRegistryOwner provides this
|
||||
) {
|
||||
OpenLocTheme {
|
||||
MainScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getLocaleForLanguage(language: AppLanguage): Locale {
|
||||
return when (language) {
|
||||
AppLanguage.SYSTEM -> {
|
||||
val systemLocales = Resources.getSystem().configuration.locales
|
||||
if (!systemLocales.isEmpty) systemLocales[0] else Locale.getDefault()
|
||||
}
|
||||
AppLanguage.ZH -> Locale.SIMPLIFIED_CHINESE
|
||||
AppLanguage.EN -> Locale.ENGLISH
|
||||
}
|
||||
}
|
||||
|
||||
fun updateActivityLocale(activity: Activity, language: AppLanguage) {
|
||||
val locale = getLocaleForLanguage(language)
|
||||
Locale.setDefault(locale)
|
||||
val resources = activity.resources
|
||||
val config = Configuration(resources.configuration)
|
||||
config.setLocale(locale)
|
||||
config.setLayoutDirection(locale)
|
||||
@Suppress("DEPRECATION")
|
||||
resources.updateConfiguration(config, resources.displayMetrics)
|
||||
@Suppress("DEPRECATION")
|
||||
activity.applicationContext.resources.updateConfiguration(config, activity.applicationContext.resources.displayMetrics)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户选择的语言构建 Localized Context
|
||||
*/
|
||||
fun createLocalizedContext(context: Context, language: AppLanguage): Context {
|
||||
val locale = getLocaleForLanguage(language)
|
||||
Locale.setDefault(locale)
|
||||
val config = Configuration(context.resources.configuration)
|
||||
config.setLocale(locale)
|
||||
config.setLayoutDirection(locale)
|
||||
return context.createConfigurationContext(config)
|
||||
}
|
||||
|
||||
/**
|
||||
* 为 Dialog / BottomSheet 提供强制局部语言环境的 Composable 容器
|
||||
*/
|
||||
@Composable
|
||||
fun LocalizedDialogContent(context: Context = LocalContext.current, content: @Composable () -> Unit) {
|
||||
val appLanguage = AppPreferences.appLanguage
|
||||
val localized = remember(appLanguage, context) {
|
||||
createLocalizedContext(context, appLanguage)
|
||||
}
|
||||
CompositionLocalProvider(
|
||||
LocalContext provides localized,
|
||||
LocalConfiguration provides localized.resources.configuration
|
||||
) {
|
||||
content()
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true, name = "Light Theme")
|
||||
@Composable
|
||||
fun MainScreenPreviewLight() {
|
||||
OpenLocTheme {
|
||||
MainScreen()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.lzxnone.openloc.core.provider
|
||||
|
||||
/**
|
||||
* 跨进程数据共享契约常量
|
||||
*/
|
||||
object ConfigContract {
|
||||
const val AUTHORITY = "com.lzxnone.openloc.provider"
|
||||
val CONTENT_URI = "content://$AUTHORITY"
|
||||
|
||||
const val METHOD_GET_CONFIG = "get_mock_config"
|
||||
|
||||
const val KEY_ENABLED = "key_is_enabled"
|
||||
const val KEY_LATITUDE = "key_latitude"
|
||||
const val KEY_LONGITUDE = "key_longitude"
|
||||
const val KEY_LOCATION_NAME = "key_location_name"
|
||||
const val KEY_APP_MOCK_MODE = "key_app_mock_mode"
|
||||
const val KEY_WHITELIST_APPS = "key_whitelist_apps"
|
||||
const val KEY_BLACKLIST_APPS = "key_blacklist_apps"
|
||||
const val KEY_ENABLE_JITTER = "key_enable_jitter"
|
||||
const val KEY_ENABLE_GNSS_SIMULATION = "key_enable_gnss_simulation"
|
||||
const val KEY_ENABLE_NETWORK_CAMOUFLAGE = "key_enable_network_camouflage"
|
||||
const val KEY_ENABLE_SENSOR_SIMULATION = "key_enable_sensor_simulation"
|
||||
const val KEY_ENABLE_STEALTH = "key_enable_stealth"
|
||||
const val KEY_ENABLE_DEV_CAMOUFLAGE = "key_enable_dev_camouflage"
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.lzxnone.openloc.core.provider
|
||||
|
||||
import android.content.ContentProvider
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import com.lzxnone.openloc.data.preference.AppPreferences
|
||||
|
||||
/**
|
||||
* 跨进程配置共享服务提供者
|
||||
*
|
||||
* 目标 App 进程内的 Hook 代码通过调用此 Provider 的 call 方法,
|
||||
* 实时拉取 OpenLoc 中用户配置的最新总开关与虚拟坐标。
|
||||
*/
|
||||
class LocationConfigProvider : ContentProvider() {
|
||||
|
||||
override fun onCreate(): Boolean {
|
||||
context?.let { ctx ->
|
||||
AppPreferences.init(ctx.applicationContext)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun call(method: String, arg: String?, extras: Bundle?): Bundle? {
|
||||
if (method == ConfigContract.METHOD_GET_CONFIG) {
|
||||
val ctx = context ?: return null
|
||||
// 确保读取到最新存储
|
||||
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 name = prefs.getString("mock_location_name", "") ?: ""
|
||||
val mode = prefs.getString("app_mock_mode", "GLOBAL") ?: "GLOBAL"
|
||||
val whitelistJson = prefs.getString("whitelist_apps", "[]") ?: "[]"
|
||||
val blacklistJson = prefs.getString("blacklist_apps", "[]") ?: "[]"
|
||||
val isJitter = prefs.getBoolean("enable_jitter", true)
|
||||
val isGnss = prefs.getBoolean("enable_gnss_simulation", true)
|
||||
val isNetwork = prefs.getBoolean("enable_network_camouflage", true)
|
||||
val isSensor = prefs.getBoolean("enable_sensor_simulation", true)
|
||||
val isStealth = prefs.getBoolean("enable_stealth", true)
|
||||
val isDevCamouflage = prefs.getBoolean("enable_dev_camouflage", true)
|
||||
|
||||
return Bundle().apply {
|
||||
putBoolean(ConfigContract.KEY_ENABLED, isEnabled)
|
||||
putDouble(ConfigContract.KEY_LATITUDE, lat)
|
||||
putDouble(ConfigContract.KEY_LONGITUDE, lng)
|
||||
putString(ConfigContract.KEY_LOCATION_NAME, name)
|
||||
putString(ConfigContract.KEY_APP_MOCK_MODE, mode)
|
||||
putString(ConfigContract.KEY_WHITELIST_APPS, whitelistJson)
|
||||
putString(ConfigContract.KEY_BLACKLIST_APPS, blacklistJson)
|
||||
putBoolean(ConfigContract.KEY_ENABLE_JITTER, isJitter)
|
||||
putBoolean(ConfigContract.KEY_ENABLE_GNSS_SIMULATION, isGnss)
|
||||
putBoolean(ConfigContract.KEY_ENABLE_NETWORK_CAMOUFLAGE, isNetwork)
|
||||
putBoolean(ConfigContract.KEY_ENABLE_SENSOR_SIMULATION, isSensor)
|
||||
putBoolean(ConfigContract.KEY_ENABLE_STEALTH, isStealth)
|
||||
putBoolean(ConfigContract.KEY_ENABLE_DEV_CAMOUFLAGE, isDevCamouflage)
|
||||
}
|
||||
}
|
||||
return super.call(method, arg, extras)
|
||||
}
|
||||
|
||||
override fun query(
|
||||
uri: Uri,
|
||||
projection: Array<out String>?,
|
||||
selection: String?,
|
||||
selectionArgs: Array<out String>?,
|
||||
sortOrder: String?
|
||||
): Cursor? = null
|
||||
|
||||
override fun getType(uri: Uri): String? = null
|
||||
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
||||
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
||||
override fun update(
|
||||
uri: Uri,
|
||||
values: ContentValues?,
|
||||
selection: String?,
|
||||
selectionArgs: Array<out String>?
|
||||
): Int = 0
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.lzxnone.openloc.core.util
|
||||
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.atan2
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
import kotlin.math.sqrt
|
||||
|
||||
/**
|
||||
* 中国标准坐标系转换工具
|
||||
* WGS-84: GPS原始地球坐标系(国际标准,Android系统硬件与系统底层LocationManager输出标准)
|
||||
* GCJ-02: 火星坐标系(中国国测局标准,高德地图、腾讯地图、谷歌中国采用)
|
||||
* BD-09: 百度坐标系(百度地图在GCJ-02基础上进一步加偏采用)
|
||||
*/
|
||||
object CoordinateConverter {
|
||||
|
||||
private const val X_PI = 3.14159265358979324 * 3000.0 / 180.0
|
||||
private const val PI = 3.1415926535897932384626
|
||||
private const val A = 6378245.0 // 长半轴
|
||||
private const val EE = 0.00669342162296594323 // 扁率平方
|
||||
|
||||
/**
|
||||
* 判断坐标是否在中国境外(境外不进行火星加偏)
|
||||
*/
|
||||
fun outOfChina(lat: Double, lng: Double): Boolean {
|
||||
if (lng < 72.004 || lng > 137.8347) return true
|
||||
if (lat < 0.8293 || lat > 55.8271) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* WGS-84 转 GCJ-02 (高德/腾讯/国测局)
|
||||
* 用于将真实设备 GPS 坐标转换后精准打在 OpenLoc 的高德瓦片底图上
|
||||
*/
|
||||
fun wgs84ToGcj02(lat: Double, lng: Double): DoubleArray {
|
||||
if (outOfChina(lat, lng)) {
|
||||
return doubleArrayOf(lat, lng)
|
||||
}
|
||||
var dLat = transformLat(lng - 105.0, lat - 35.0)
|
||||
var dLng = transformLng(lng - 105.0, lat - 35.0)
|
||||
val radLat = lat / 180.0 * PI
|
||||
var magic = sin(radLat)
|
||||
magic = 1 - EE * magic * magic
|
||||
val sqrtMagic = sqrt(magic)
|
||||
dLat = (dLat * 180.0) / ((A * (1 - EE)) / (magic * sqrtMagic) * PI)
|
||||
dLng = (dLng * 180.0) / (A / sqrtMagic * cos(radLat) * PI)
|
||||
return doubleArrayOf(lat + dLat, lng + dLng)
|
||||
}
|
||||
|
||||
/**
|
||||
* GCJ-02 转 WGS-84
|
||||
* 用于将用户在 OpenLoc 高德瓦片上点击的火星坐标还原为国际 WGS-84 标准坐标,
|
||||
* 传递给目标应用(如百度地图、高德地图、微信等),防止目标应用二次加偏造成几百米严重偏差。
|
||||
*/
|
||||
fun gcj02ToWgs84(lat: Double, lng: Double): DoubleArray {
|
||||
if (outOfChina(lat, lng)) {
|
||||
return doubleArrayOf(lat, lng)
|
||||
}
|
||||
var dLat = transformLat(lng - 105.0, lat - 35.0)
|
||||
var dLng = transformLng(lng - 105.0, lat - 35.0)
|
||||
val radLat = lat / 180.0 * PI
|
||||
var magic = sin(radLat)
|
||||
magic = 1 - EE * magic * magic
|
||||
val sqrtMagic = sqrt(magic)
|
||||
dLat = (dLat * 180.0) / ((A * (1 - EE)) / (magic * sqrtMagic) * PI)
|
||||
dLng = (dLng * 180.0) / (A / sqrtMagic * cos(radLat) * PI)
|
||||
val mgLat = lat + dLat
|
||||
val mgLng = lng + dLng
|
||||
return doubleArrayOf(lat * 2 - mgLat, lng * 2 - mgLng)
|
||||
}
|
||||
|
||||
/**
|
||||
* WGS-84 直接转 BD-09 (百度坐标系)
|
||||
*/
|
||||
fun wgs84ToBd09(lat: Double, lng: Double): DoubleArray {
|
||||
val gcj = wgs84ToGcj02(lat, lng)
|
||||
return gcj02ToBd09(gcj[0], gcj[1])
|
||||
}
|
||||
|
||||
/**
|
||||
* GCJ-02 转 BD-09 (百度坐标系)
|
||||
*/
|
||||
fun gcj02ToBd09(lat: Double, lng: Double): DoubleArray {
|
||||
val z = sqrt(lng * lng + lat * lat) + 0.00002 * sin(lat * X_PI)
|
||||
val theta = atan2(lat, lng) + 0.000003 * cos(lng * X_PI)
|
||||
val bdLng = z * cos(theta) + 0.0065
|
||||
val bdLat = z * sin(theta) + 0.006
|
||||
return doubleArrayOf(bdLat, bdLng)
|
||||
}
|
||||
|
||||
/**
|
||||
* BD-09 转 GCJ-02
|
||||
*/
|
||||
fun bd09ToGcj02(lat: Double, lng: Double): DoubleArray {
|
||||
val x = lng - 0.0065
|
||||
val y = lat - 0.006
|
||||
val z = sqrt(x * x + y * y) - 0.00002 * sin(y * X_PI)
|
||||
val theta = atan2(y, x) - 0.000003 * cos(x * X_PI)
|
||||
val gcjLng = z * cos(theta)
|
||||
val gcjLat = z * sin(theta)
|
||||
return doubleArrayOf(gcjLat, gcjLng)
|
||||
}
|
||||
|
||||
/**
|
||||
* BD-09 转 WGS-84
|
||||
*/
|
||||
fun bd09ToWgs84(lat: Double, lng: Double): DoubleArray {
|
||||
val gcj = bd09ToGcj02(lat, lng)
|
||||
return gcj02ToWgs84(gcj[0], gcj[1])
|
||||
}
|
||||
|
||||
private fun transformLat(x: Double, y: Double): Double {
|
||||
var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(abs(x))
|
||||
ret += (20.0 * sin(6.0 * x * PI) + 20.0 * sin(2.0 * x * PI)) * 2.0 / 3.0
|
||||
ret += (20.0 * sin(y * PI) + 40.0 * sin(y / 3.0 * PI)) * 2.0 / 3.0
|
||||
ret += (160.0 * sin(y / 12.0 * PI) + 320 * sin(y * PI / 30.0)) * 2.0 / 3.0
|
||||
return ret
|
||||
}
|
||||
|
||||
private fun transformLng(x: Double, y: Double): Double {
|
||||
var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x))
|
||||
ret += (20.0 * sin(6.0 * x * PI) + 20.0 * sin(2.0 * x * PI)) * 2.0 / 3.0
|
||||
ret += (20.0 * sin(x * PI) + 40.0 * sin(x / 3.0 * PI)) * 2.0 / 3.0
|
||||
ret += (150.0 * sin(x / 12.0 * PI) + 300.0 * sin(x / 30.0 * PI)) * 2.0 / 3.0
|
||||
return ret
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.lzxnone.openloc.core.util
|
||||
|
||||
/**
|
||||
* 模块激活状态判定桩
|
||||
*
|
||||
* 在 Xposed / LSPosed 架构中,应用本体与 Hook 模块共享此方法:
|
||||
* - 默认情况下,该方法返回 false(表示未激活或当前未被框架注入)。
|
||||
* - 当 Xposed / LSPosed 加载本模块并注入本应用进程时,会 Hook 此方法令其恒返回 true。
|
||||
*/
|
||||
object HookStatus {
|
||||
@JvmStatic
|
||||
fun isModuleActive(): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,611 @@
|
||||
package com.lzxnone.openloc.core.util
|
||||
|
||||
import android.content.Context
|
||||
import android.location.Address
|
||||
import android.location.Geocoder
|
||||
import android.os.Build
|
||||
import com.lzxnone.openloc.data.preference.AppPreferences
|
||||
import com.lzxnone.openloc.data.preference.SearchProvider
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.json.JSONObject
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.net.URLEncoder
|
||||
import java.util.Locale
|
||||
import kotlin.coroutines.resume
|
||||
|
||||
/**
|
||||
* 搜索结果数据结构 (经纬度统一存储为国际标准 WGS-84)
|
||||
*/
|
||||
data class SearchResult(
|
||||
val name: String,
|
||||
val address: String,
|
||||
val latitude: Double,
|
||||
val longitude: Double
|
||||
)
|
||||
|
||||
/**
|
||||
* 搜索响应封装,包含结果列表与错误状态
|
||||
*/
|
||||
data class SearchResponse(
|
||||
val results: List<SearchResult>,
|
||||
val errorMessage: String? = null // null 正常,"NO_API_KEY", "KEY_INVALID: ...", "NETWORK_ERROR: ..."
|
||||
)
|
||||
|
||||
/**
|
||||
* 地理编码、逆地理编码与多源搜索服务工具类
|
||||
* 支持商用源(高德 Web 服务、百度地图 Web 服务)及免 Key 免费源(Photon、Nominatim)
|
||||
*/
|
||||
object LocationResolver {
|
||||
|
||||
/**
|
||||
* 测试指定提供商的 API Key / AK 是否有效
|
||||
* @return Pair(isSuccess, errorMessage)
|
||||
*/
|
||||
suspend fun testApiKey(provider: SearchProvider, key: String): Pair<Boolean, String?> = withContext(Dispatchers.IO) {
|
||||
val trimmedKey = key.trim()
|
||||
if (trimmedKey.isEmpty()) {
|
||||
return@withContext Pair(false, "KEY_EMPTY")
|
||||
}
|
||||
|
||||
try {
|
||||
when (provider) {
|
||||
SearchProvider.AMAP -> {
|
||||
val encoded = URLEncoder.encode("Beijing", "UTF-8")
|
||||
val urlStr = "https://restapi.amap.com/v3/place/text?keywords=$encoded&key=$trimmedKey&offset=1&page=1"
|
||||
val conn = (URL(urlStr).openConnection() as HttpURLConnection).apply {
|
||||
requestMethod = "GET"
|
||||
connectTimeout = 4000
|
||||
readTimeout = 4000
|
||||
}
|
||||
if (conn.responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val body = conn.inputStream.bufferedReader().use { it.readText() }
|
||||
val json = JSONObject(body)
|
||||
val status = json.optString("status")
|
||||
if (status == "1") {
|
||||
Pair(true, null)
|
||||
} else {
|
||||
val info = json.optString("info")
|
||||
val infocode = json.optString("infocode")
|
||||
Pair(false, "$info ($infocode)")
|
||||
}
|
||||
} else {
|
||||
Pair(false, "HTTP ${conn.responseCode}")
|
||||
}
|
||||
}
|
||||
SearchProvider.BAIDU -> {
|
||||
val encoded = URLEncoder.encode("Beijing", "UTF-8")
|
||||
val urlStr = "https://api.map.baidu.com/place/v2/suggestion?query=$encoded®ion=%E5%85%A8%E5%9B%BD&output=json&ak=$trimmedKey"
|
||||
val conn = (URL(urlStr).openConnection() as HttpURLConnection).apply {
|
||||
requestMethod = "GET"
|
||||
connectTimeout = 4000
|
||||
readTimeout = 4000
|
||||
}
|
||||
if (conn.responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val body = conn.inputStream.bufferedReader().use { it.readText() }
|
||||
val json = JSONObject(body)
|
||||
val status = json.optInt("status", -1)
|
||||
if (status == 0) {
|
||||
Pair(true, null)
|
||||
} else {
|
||||
val msg = json.optString("message")
|
||||
Pair(false, "$msg ($status)")
|
||||
}
|
||||
} else {
|
||||
Pair(false, "HTTP ${conn.responseCode}")
|
||||
}
|
||||
}
|
||||
else -> Pair(true, null)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Pair(false, e.localizedMessage ?: "NETWORK_ERROR")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 逆地理编码:将坐标反查为人类可读地名
|
||||
*/
|
||||
suspend fun resolveLocationName(
|
||||
context: Context,
|
||||
wgsLat: Double,
|
||||
wgsLng: Double
|
||||
): String = withContext(Dispatchers.IO) {
|
||||
val provider = AppPreferences.searchProvider
|
||||
|
||||
// 通道 1: 高德地图逆地理服务 (当选定高德且配置了 Key 时)
|
||||
if (provider == SearchProvider.AMAP && AppPreferences.amapApiKey.isNotBlank()) {
|
||||
try {
|
||||
val gcj = CoordinateConverter.wgs84ToGcj02(wgsLat, wgsLng)
|
||||
val urlString = "https://restapi.amap.com/v3/geocode/regeo?location=${gcj[1]},${gcj[0]}&key=${AppPreferences.amapApiKey}&extensions=all"
|
||||
val connection = (URL(urlString).openConnection() as HttpURLConnection).apply {
|
||||
requestMethod = "GET"
|
||||
connectTimeout = 3000
|
||||
readTimeout = 3000
|
||||
}
|
||||
|
||||
if (connection.responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val responseBody = connection.inputStream.bufferedReader().use { it.readText() }
|
||||
val json = JSONObject(responseBody)
|
||||
if (json.optString("status") == "1") {
|
||||
val regeocode = json.optJSONObject("regeocode")
|
||||
if (regeocode != null) {
|
||||
val pois = regeocode.optJSONArray("pois")
|
||||
if (pois != null && pois.length() > 0) {
|
||||
val firstPoi = pois.getJSONObject(0)
|
||||
val poiName = firstPoi.optString("name")
|
||||
if (poiName.isNotBlank()) return@withContext poiName
|
||||
}
|
||||
val formattedAddress = regeocode.optString("formatted_address")
|
||||
if (formattedAddress.isNotBlank()) return@withContext formattedAddress
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
// 通道 2: 百度地图逆地理服务 (当选定百度且配置了 AK 时)
|
||||
if (provider == SearchProvider.BAIDU && AppPreferences.baiduApiKey.isNotBlank()) {
|
||||
try {
|
||||
val urlString = "https://api.map.baidu.com/reverse_geocoding/v3/?ak=${AppPreferences.baiduApiKey}&output=json&coordtype=wgs84ll&location=$wgsLat,$wgsLng"
|
||||
val connection = (URL(urlString).openConnection() as HttpURLConnection).apply {
|
||||
requestMethod = "GET"
|
||||
connectTimeout = 3000
|
||||
readTimeout = 3000
|
||||
}
|
||||
|
||||
if (connection.responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val responseBody = connection.inputStream.bufferedReader().use { it.readText() }
|
||||
val json = JSONObject(responseBody)
|
||||
if (json.optInt("status", -1) == 0) {
|
||||
val result = json.optJSONObject("result")
|
||||
if (result != null) {
|
||||
val pois = result.optJSONArray("pois")
|
||||
if (pois != null && pois.length() > 0) {
|
||||
val firstPoi = pois.getJSONObject(0)
|
||||
val poiName = firstPoi.optString("name")
|
||||
if (poiName.isNotBlank()) return@withContext poiName
|
||||
}
|
||||
val formattedAddress = result.optString("formatted_address")
|
||||
if (formattedAddress.isNotBlank()) return@withContext formattedAddress
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
// 通道 3: 原生 Android Geocoder
|
||||
try {
|
||||
if (Geocoder.isPresent()) {
|
||||
val geocoder = Geocoder(context, Locale.getDefault())
|
||||
val addresses: List<Address> = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
suspendCancellableCoroutine { continuation ->
|
||||
try {
|
||||
geocoder.getFromLocation(wgsLat, wgsLng, 1, object : Geocoder.GeocodeListener {
|
||||
override fun onGeocode(results: MutableList<Address>) {
|
||||
continuation.resume(results)
|
||||
}
|
||||
|
||||
override fun onError(errorMessage: String?) {
|
||||
continuation.resume(emptyList())
|
||||
}
|
||||
})
|
||||
} catch (_: Exception) {
|
||||
continuation.resume(emptyList())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
try {
|
||||
geocoder.getFromLocation(wgsLat, wgsLng, 1) ?: emptyList()
|
||||
} catch (_: Exception) {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
if (addresses.isNotEmpty()) {
|
||||
val address = addresses[0]
|
||||
val feature = address.featureName
|
||||
val thoroughfare = address.thoroughfare
|
||||
val subLocality = address.subLocality
|
||||
val locality = address.locality
|
||||
|
||||
val name = when {
|
||||
!feature.isNullOrBlank() && feature != thoroughfare && feature != subLocality -> feature
|
||||
!thoroughfare.isNullOrBlank() -> thoroughfare
|
||||
!subLocality.isNullOrBlank() -> "${locality ?: ""} $subLocality".trim()
|
||||
!locality.isNullOrBlank() -> locality
|
||||
else -> address.getAddressLine(0) ?: ""
|
||||
}
|
||||
if (name.isNotBlank()) {
|
||||
return@withContext name
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (_: Throwable) {}
|
||||
|
||||
// 最终兜底:格式化经纬度显示
|
||||
String.format(Locale.getDefault(), "%.5f, %.5f", wgsLat, wgsLng)
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一地点与坐标搜索入口
|
||||
*/
|
||||
suspend fun searchPlaces(context: Context, query: String): SearchResponse = withContext(Dispatchers.IO) {
|
||||
val trimmed = query.trim()
|
||||
if (trimmed.isEmpty()) return@withContext SearchResponse(emptyList(), null)
|
||||
|
||||
// 1. 纯经纬度坐标输入格式检查(如 "30.54, 114.32")
|
||||
val parts = trimmed.split(",", ",", " ", "、").filter { it.isNotBlank() }
|
||||
if (parts.size >= 2) {
|
||||
val lat = parts[0].toDoubleOrNull()
|
||||
val lng = parts[1].toDoubleOrNull()
|
||||
if (lat != null && lng != null && lat in -90.0..90.0 && lng in -180.0..180.0) {
|
||||
return@withContext SearchResponse(
|
||||
results = listOf(
|
||||
SearchResult(
|
||||
name = String.format(Locale.getDefault(), "%.6f, %.6f", lat, lng),
|
||||
address = context.getString(com.lzxnone.openloc.R.string.location_search_coord_format, lng, lat),
|
||||
latitude = lat,
|
||||
longitude = lng
|
||||
)
|
||||
),
|
||||
errorMessage = null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 根据当前选定的搜索引擎提供商分流
|
||||
val provider = AppPreferences.searchProvider
|
||||
when (provider) {
|
||||
SearchProvider.AMAP -> searchAmap(trimmed)
|
||||
SearchProvider.BAIDU -> searchBaidu(trimmed)
|
||||
SearchProvider.PHOTON -> searchPhoton(trimmed)
|
||||
SearchProvider.NOMINATIM -> searchNominatim(trimmed)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 高德地图 (AMap) 搜索实现
|
||||
*/
|
||||
private fun searchAmap(query: String): SearchResponse {
|
||||
val apiKey = AppPreferences.amapApiKey
|
||||
if (apiKey.isBlank()) {
|
||||
return SearchResponse(emptyList(), "NO_API_KEY")
|
||||
}
|
||||
|
||||
try {
|
||||
val encodedQuery = URLEncoder.encode(query, "UTF-8")
|
||||
val tipUrl = "https://restapi.amap.com/v3/assistant/inputtips?keywords=$encodedQuery&key=$apiKey"
|
||||
val connection = (URL(tipUrl).openConnection() as HttpURLConnection).apply {
|
||||
requestMethod = "GET"
|
||||
connectTimeout = 4000
|
||||
readTimeout = 4000
|
||||
}
|
||||
|
||||
if (connection.responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val responseBody = connection.inputStream.bufferedReader().use { it.readText() }
|
||||
val json = JSONObject(responseBody)
|
||||
val status = json.optString("status")
|
||||
val info = json.optString("info")
|
||||
val infocode = json.optString("infocode")
|
||||
|
||||
if (status != "1") {
|
||||
return SearchResponse(emptyList(), "KEY_INVALID: $info ($infocode)")
|
||||
}
|
||||
|
||||
val tips = json.optJSONArray("tips")
|
||||
val results = mutableListOf<SearchResult>()
|
||||
if (tips != null) {
|
||||
for (i in 0 until tips.length()) {
|
||||
val tip = tips.getJSONObject(i)
|
||||
val name = tip.optString("name")
|
||||
val district = tip.optString("district")
|
||||
val address = tip.optString("address")
|
||||
val locStr = tip.optString("location")
|
||||
|
||||
if (locStr.isNotBlank() && locStr.contains(",")) {
|
||||
val locParts = locStr.split(",")
|
||||
val gcjLng = locParts[0].toDoubleOrNull()
|
||||
val gcjLat = locParts.getOrNull(1)?.toDoubleOrNull()
|
||||
if (gcjLat != null && gcjLng != null) {
|
||||
val wgs = CoordinateConverter.gcj02ToWgs84(gcjLat, gcjLng)
|
||||
val fullAddr = listOf(district, address)
|
||||
.filter { it.isNotBlank() && it != "[]" }
|
||||
.joinToString(" ")
|
||||
|
||||
results.add(
|
||||
SearchResult(
|
||||
name = name,
|
||||
address = fullAddr.ifBlank { name },
|
||||
latitude = wgs[0],
|
||||
longitude = wgs[1]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (results.isEmpty()) {
|
||||
val searchUrl = "https://restapi.amap.com/v3/place/text?keywords=$encodedQuery&key=$apiKey&offset=15&page=1"
|
||||
val searchConn = (URL(searchUrl).openConnection() as HttpURLConnection).apply {
|
||||
requestMethod = "GET"
|
||||
connectTimeout = 4000
|
||||
readTimeout = 4000
|
||||
}
|
||||
if (searchConn.responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val sBody = searchConn.inputStream.bufferedReader().use { it.readText() }
|
||||
val sJson = JSONObject(sBody)
|
||||
if (sJson.optString("status") == "1") {
|
||||
val pois = sJson.optJSONArray("pois")
|
||||
if (pois != null) {
|
||||
for (i in 0 until pois.length()) {
|
||||
val poi = pois.getJSONObject(i)
|
||||
val name = poi.optString("name")
|
||||
val pname = poi.optString("pname")
|
||||
val cityname = poi.optString("cityname")
|
||||
val adname = poi.optString("adname")
|
||||
val address = poi.optString("address")
|
||||
val locStr = poi.optString("location")
|
||||
|
||||
if (locStr.isNotBlank() && locStr.contains(",")) {
|
||||
val locParts = locStr.split(",")
|
||||
val gcjLng = locParts[0].toDoubleOrNull()
|
||||
val gcjLat = locParts.getOrNull(1)?.toDoubleOrNull()
|
||||
if (gcjLat != null && gcjLng != null) {
|
||||
val wgs = CoordinateConverter.gcj02ToWgs84(gcjLat, gcjLng)
|
||||
val fullAddr = listOf(pname, cityname, adname, address)
|
||||
.filter { it.isNotBlank() && it != "[]" }
|
||||
.joinToString(" ")
|
||||
|
||||
results.add(
|
||||
SearchResult(
|
||||
name = name,
|
||||
address = fullAddr.ifBlank { name },
|
||||
latitude = wgs[0],
|
||||
longitude = wgs[1]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SearchResponse(results, null)
|
||||
} else {
|
||||
return SearchResponse(emptyList(), "HTTP_ERROR: ${connection.responseCode}")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
return SearchResponse(emptyList(), "NETWORK_ERROR: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 百度地图 (Baidu) 搜索实现
|
||||
*/
|
||||
private fun searchBaidu(query: String): SearchResponse {
|
||||
val apiKey = AppPreferences.baiduApiKey
|
||||
if (apiKey.isBlank()) {
|
||||
return SearchResponse(emptyList(), "NO_API_KEY")
|
||||
}
|
||||
|
||||
try {
|
||||
val encodedQuery = URLEncoder.encode(query, "UTF-8")
|
||||
val urlString = "https://api.map.baidu.com/place/v2/suggestion?query=$encodedQuery®ion=%E5%85%A8%E5%9B%BD&output=json&ak=$apiKey"
|
||||
val connection = (URL(urlString).openConnection() as HttpURLConnection).apply {
|
||||
requestMethod = "GET"
|
||||
connectTimeout = 4000
|
||||
readTimeout = 4000
|
||||
}
|
||||
|
||||
if (connection.responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val responseBody = connection.inputStream.bufferedReader().use { it.readText() }
|
||||
val json = JSONObject(responseBody)
|
||||
val status = json.optInt("status", -1)
|
||||
val message = json.optString("message")
|
||||
|
||||
if (status != 0) {
|
||||
return SearchResponse(emptyList(), "KEY_INVALID: $message ($status)")
|
||||
}
|
||||
|
||||
val results = mutableListOf<SearchResult>()
|
||||
val resultList = json.optJSONArray("result")
|
||||
if (resultList != null) {
|
||||
for (i in 0 until resultList.length()) {
|
||||
val item = resultList.getJSONObject(i)
|
||||
val name = item.optString("name")
|
||||
val province = item.optString("province")
|
||||
val city = item.optString("city")
|
||||
val district = item.optString("district")
|
||||
val address = item.optString("address")
|
||||
val loc = item.optJSONObject("location")
|
||||
|
||||
if (loc != null) {
|
||||
val bdLat = loc.optDouble("lat", Double.NaN)
|
||||
val bdLng = loc.optDouble("lng", Double.NaN)
|
||||
if (!bdLat.isNaN() && !bdLng.isNaN()) {
|
||||
// 百度坐标系 (BD-09) 转换为标准 WGS-84
|
||||
val wgs = CoordinateConverter.bd09ToWgs84(bdLat, bdLng)
|
||||
val fullAddr = listOf(province, city, district, address)
|
||||
.filter { it.isNotBlank() }
|
||||
.distinct()
|
||||
.joinToString(" ")
|
||||
|
||||
results.add(
|
||||
SearchResult(
|
||||
name = name,
|
||||
address = fullAddr.ifBlank { name },
|
||||
latitude = wgs[0],
|
||||
longitude = wgs[1]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (results.isEmpty()) {
|
||||
// 降级使用 place/v2/search 检索
|
||||
val searchUrl = "https://api.map.baidu.com/place/v2/search?query=$encodedQuery®ion=%E5%85%A8%E5%9B%BD&output=json&ak=$apiKey&page_size=15&page_num=0"
|
||||
val searchConn = (URL(searchUrl).openConnection() as HttpURLConnection).apply {
|
||||
requestMethod = "GET"
|
||||
connectTimeout = 4000
|
||||
readTimeout = 4000
|
||||
}
|
||||
if (searchConn.responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val sBody = searchConn.inputStream.bufferedReader().use { it.readText() }
|
||||
val sJson = JSONObject(sBody)
|
||||
val sResults = sJson.optJSONArray("results")
|
||||
if (sResults != null) {
|
||||
for (i in 0 until sResults.length()) {
|
||||
val item = sResults.getJSONObject(i)
|
||||
val name = item.optString("name")
|
||||
val address = item.optString("address")
|
||||
val loc = item.optJSONObject("location")
|
||||
if (loc != null) {
|
||||
val bdLat = loc.optDouble("lat", Double.NaN)
|
||||
val bdLng = loc.optDouble("lng", Double.NaN)
|
||||
if (!bdLat.isNaN() && !bdLng.isNaN()) {
|
||||
val wgs = CoordinateConverter.bd09ToWgs84(bdLat, bdLng)
|
||||
results.add(
|
||||
SearchResult(
|
||||
name = name,
|
||||
address = address.ifBlank { name },
|
||||
latitude = wgs[0],
|
||||
longitude = wgs[1]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SearchResponse(results, null)
|
||||
} else {
|
||||
return SearchResponse(emptyList(), "HTTP_ERROR: ${connection.responseCode}")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
return SearchResponse(emptyList(), "NETWORK_ERROR: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Photon (基于 OpenStreetMap) 免 Key 极速搜索实现
|
||||
*/
|
||||
private fun searchPhoton(query: String): SearchResponse {
|
||||
try {
|
||||
val encodedQuery = URLEncoder.encode(query, "UTF-8")
|
||||
val urlString = "https://photon.komoot.io/api/?q=$encodedQuery&limit=20&lang=zh"
|
||||
val connection = (URL(urlString).openConnection() as HttpURLConnection).apply {
|
||||
requestMethod = "GET"
|
||||
connectTimeout = 5000
|
||||
readTimeout = 5000
|
||||
setRequestProperty("User-Agent", "OpenLoc/1.0 (Android)")
|
||||
}
|
||||
|
||||
if (connection.responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val body = connection.inputStream.bufferedReader().use { it.readText() }
|
||||
val json = JSONObject(body)
|
||||
val features = json.optJSONArray("features")
|
||||
val results = mutableListOf<SearchResult>()
|
||||
|
||||
if (features != null) {
|
||||
for (i in 0 until features.length()) {
|
||||
val feat = features.getJSONObject(i)
|
||||
val props = feat.optJSONObject("properties") ?: continue
|
||||
val geom = feat.optJSONObject("geometry") ?: continue
|
||||
val coords = geom.optJSONArray("coordinates") ?: continue
|
||||
|
||||
if (coords.length() >= 2) {
|
||||
val lng = coords.getDouble(0) // Photon 返回 [lon, lat] (WGS-84)
|
||||
val lat = coords.getDouble(1)
|
||||
|
||||
val name = props.optString("name")
|
||||
val street = props.optString("street")
|
||||
val district = props.optString("district")
|
||||
val city = props.optString("city")
|
||||
val state = props.optString("state")
|
||||
val country = props.optString("country")
|
||||
|
||||
val fullAddress = listOf(country, state, city, district, street)
|
||||
.filter { it.isNotBlank() }
|
||||
.distinct()
|
||||
.joinToString(" ")
|
||||
|
||||
if (name.isNotBlank()) {
|
||||
results.add(
|
||||
SearchResult(
|
||||
name = name,
|
||||
address = fullAddress.ifBlank { name },
|
||||
latitude = lat,
|
||||
longitude = lng
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SearchResponse(results, null)
|
||||
} else {
|
||||
return SearchResponse(emptyList(), "HTTP_ERROR: ${connection.responseCode}")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
return SearchResponse(emptyList(), "NETWORK_ERROR: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Nominatim (OpenStreetMap 官方) 免 Key 搜索实现
|
||||
*/
|
||||
private fun searchNominatim(query: String): SearchResponse {
|
||||
try {
|
||||
val encodedQuery = URLEncoder.encode(query, "UTF-8")
|
||||
val urlString = "https://nominatim.openstreetmap.org/search?q=$encodedQuery&format=json&addressdetails=1&limit=20&accept-language=zh"
|
||||
val connection = (URL(urlString).openConnection() as HttpURLConnection).apply {
|
||||
requestMethod = "GET"
|
||||
connectTimeout = 6000
|
||||
readTimeout = 6000
|
||||
setRequestProperty("User-Agent", "OpenLoc/1.0 (Android)")
|
||||
}
|
||||
|
||||
if (connection.responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val body = connection.inputStream.bufferedReader().use { it.readText() }
|
||||
val array = org.json.JSONArray(body)
|
||||
val results = mutableListOf<SearchResult>()
|
||||
|
||||
for (i in 0 until array.length()) {
|
||||
val item = array.getJSONObject(i)
|
||||
val displayName = item.optString("display_name")
|
||||
val name = item.optString("name").ifBlank { displayName.split(",").firstOrNull() ?: displayName }
|
||||
val lat = item.optString("lat").toDoubleOrNull()
|
||||
val lng = item.optString("lon").toDoubleOrNull()
|
||||
|
||||
if (lat != null && lng != null) {
|
||||
results.add(
|
||||
SearchResult(
|
||||
name = name,
|
||||
address = displayName,
|
||||
latitude = lat,
|
||||
longitude = lng
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return SearchResponse(results, null)
|
||||
} else {
|
||||
return SearchResponse(emptyList(), "HTTP_ERROR: ${connection.responseCode}")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
return SearchResponse(emptyList(), "NETWORK_ERROR: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.lzxnone.openloc.data.model
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* 收藏夹地点条目数据结构
|
||||
* 经纬度统一存储为国际标准 WGS-84
|
||||
*/
|
||||
data class FavoriteItem(
|
||||
val id: String = UUID.randomUUID().toString(),
|
||||
val name: String,
|
||||
val address: String,
|
||||
val latitude: Double,
|
||||
val longitude: Double,
|
||||
val timestamp: Long = System.currentTimeMillis()
|
||||
)
|
||||
@@ -0,0 +1,501 @@
|
||||
package com.lzxnone.openloc.data.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableLongStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
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.util.SearchResult
|
||||
import com.lzxnone.openloc.data.model.FavoriteItem
|
||||
|
||||
enum class ThemeMode(@param:StringRes val titleRes: Int) {
|
||||
SYSTEM(R.string.settings_theme_mode_system),
|
||||
LIGHT(R.string.settings_theme_mode_light),
|
||||
DARK(R.string.settings_theme_mode_dark)
|
||||
}
|
||||
|
||||
enum class SearchProvider(
|
||||
val id: String,
|
||||
@param:StringRes val titleRes: Int,
|
||||
val requiresKey: Boolean
|
||||
) {
|
||||
AMAP("amap", R.string.search_provider_amap, requiresKey = true),
|
||||
BAIDU("baidu", R.string.search_provider_baidu, requiresKey = true),
|
||||
PHOTON("photon", R.string.search_provider_photon, requiresKey = false),
|
||||
NOMINATIM("nominatim", R.string.search_provider_nominatim, requiresKey = false);
|
||||
|
||||
companion object {
|
||||
fun fromId(id: String): SearchProvider {
|
||||
return entries.firstOrNull { it.id.equals(id, ignoreCase = true) } ?: AMAP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class AppLanguage(val tag: String, @param:StringRes val titleRes: Int) {
|
||||
SYSTEM("", R.string.settings_language_system),
|
||||
ZH("zh-CN", R.string.settings_language_zh),
|
||||
EN("en", R.string.settings_language_en);
|
||||
|
||||
companion object {
|
||||
fun fromTag(tag: String): AppLanguage {
|
||||
return entries.firstOrNull { it.tag.equals(tag, ignoreCase = true) } ?: SYSTEM
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预设质感主题色列表
|
||||
*/
|
||||
val PresetThemeColors = listOf(
|
||||
Color(0xFF0061A4), // 科技蓝(默认)
|
||||
Color(0xFF006D44), // 薄荷森绿
|
||||
Color(0xFF6750A4), // 优雅紫
|
||||
Color(0xFFA04100), // 活力橙
|
||||
Color(0xFF006874), // 深邃青
|
||||
Color(0xFFB3261E), // 热情红
|
||||
Color(0xFF984061), // 玫瑰粉
|
||||
Color(0xFF5A5F67) // 沉稳灰
|
||||
)
|
||||
|
||||
/**
|
||||
* 应用虚拟定位生效模式
|
||||
*/
|
||||
enum class AppMockMode {
|
||||
GLOBAL, // 全局模式:整机所有应用生效
|
||||
BLACKLIST, // 黑名单模式:黑名单内应用保持真实定位,其余生效虚拟
|
||||
WHITELIST; // 白名单模式:仅白名单内应用生效虚拟,其余保持真实定位
|
||||
|
||||
companion object {
|
||||
fun fromId(id: String): AppMockMode {
|
||||
return entries.firstOrNull { it.name.equals(id, ignoreCase = true) } ?: GLOBAL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object AppPreferences {
|
||||
private const val PREF_NAME = "openloc_prefs"
|
||||
private const val KEY_THEME_MODE = "theme_mode"
|
||||
private const val KEY_THEME_COLOR = "theme_color"
|
||||
private const val KEY_DYNAMIC_COLOR = "dynamic_color"
|
||||
private const val KEY_LANGUAGE = "language"
|
||||
private const val KEY_SERVICE_ENABLED = "mock_service_enabled"
|
||||
|
||||
private lateinit var prefs: SharedPreferences
|
||||
|
||||
var themeMode by mutableStateOf(ThemeMode.SYSTEM)
|
||||
private set
|
||||
|
||||
var themeColor by mutableLongStateOf(0xFF0061A4)
|
||||
private set
|
||||
|
||||
var isDynamicColor by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
private const val KEY_MOCK_LATITUDE = "mock_latitude"
|
||||
private const val KEY_MOCK_LONGITUDE = "mock_longitude"
|
||||
private const val KEY_MOCK_LOCATION_NAME = "mock_location_name"
|
||||
private const val KEY_HAS_USER_SET_LOCATION = "has_user_set_location"
|
||||
private const val KEY_SEARCH_HISTORY = "search_history"
|
||||
private const val KEY_SEARCH_PROVIDER = "search_provider"
|
||||
private const val KEY_AMAP_API_KEY = "amap_api_key"
|
||||
private const val KEY_BAIDU_API_KEY = "baidu_api_key"
|
||||
private const val KEY_FAVORITES = "favorites"
|
||||
private const val KEY_APP_MOCK_MODE = "app_mock_mode"
|
||||
private const val KEY_WHITELIST_APPS = "whitelist_apps"
|
||||
private const val KEY_BLACKLIST_APPS = "blacklist_apps"
|
||||
private const val KEY_ENABLE_JITTER = "enable_jitter"
|
||||
private const val KEY_ENABLE_GNSS_SIMULATION = "enable_gnss_simulation"
|
||||
private const val KEY_ENABLE_NETWORK_CAMOUFLAGE = "enable_network_camouflage"
|
||||
private const val KEY_ENABLE_SENSOR_SIMULATION = "enable_sensor_simulation"
|
||||
private const val KEY_ENABLE_STEALTH = "enable_stealth"
|
||||
private const val KEY_ENABLE_DEV_CAMOUFLAGE = "enable_dev_camouflage"
|
||||
|
||||
var appLanguage by mutableStateOf(AppLanguage.SYSTEM)
|
||||
private set
|
||||
|
||||
var searchProvider by mutableStateOf(SearchProvider.AMAP)
|
||||
private set
|
||||
|
||||
var appMockMode by mutableStateOf(AppMockMode.GLOBAL)
|
||||
private set
|
||||
|
||||
var whitelistApps by mutableStateOf<Set<String>>(emptySet())
|
||||
private set
|
||||
|
||||
var blacklistApps by mutableStateOf<Set<String>>(emptySet())
|
||||
private set
|
||||
|
||||
var isJitterEnabled by mutableStateOf(true)
|
||||
private set
|
||||
|
||||
var isGnssSimulationEnabled by mutableStateOf(true)
|
||||
private set
|
||||
|
||||
var isNetworkCamouflageEnabled by mutableStateOf(true)
|
||||
private set
|
||||
|
||||
var isSensorSimulationEnabled by mutableStateOf(true)
|
||||
private set
|
||||
|
||||
var isStealthEnabled by mutableStateOf(true)
|
||||
private set
|
||||
|
||||
var isDevCamouflageEnabled by mutableStateOf(true)
|
||||
private set
|
||||
|
||||
var mockLatitude by androidx.compose.runtime.mutableDoubleStateOf(39.908722)
|
||||
private set
|
||||
|
||||
var mockLongitude by androidx.compose.runtime.mutableDoubleStateOf(116.397496)
|
||||
private set
|
||||
|
||||
var mockLocationName by mutableStateOf("")
|
||||
private set
|
||||
|
||||
var hasUserSetLocation by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
var isServiceEnabled by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
var searchHistory by mutableStateOf<List<SearchResult>>(emptyList())
|
||||
private set
|
||||
|
||||
var favorites by mutableStateOf<List<FavoriteItem>>(emptyList())
|
||||
private set
|
||||
|
||||
var amapApiKey by mutableStateOf("")
|
||||
private set
|
||||
|
||||
var baiduApiKey by mutableStateOf("")
|
||||
private set
|
||||
|
||||
fun init(context: Context) {
|
||||
prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
|
||||
|
||||
val modeOrdinal = prefs.getInt(KEY_THEME_MODE, ThemeMode.SYSTEM.ordinal)
|
||||
themeMode = ThemeMode.entries.getOrElse(modeOrdinal) { ThemeMode.SYSTEM }
|
||||
|
||||
themeColor = prefs.getLong(KEY_THEME_COLOR, 0xFF0061A4)
|
||||
isDynamicColor = prefs.getBoolean(KEY_DYNAMIC_COLOR, false)
|
||||
|
||||
val langTag = prefs.getString(KEY_LANGUAGE, "") ?: ""
|
||||
appLanguage = AppLanguage.fromTag(langTag)
|
||||
|
||||
val providerId = prefs.getString(KEY_SEARCH_PROVIDER, SearchProvider.AMAP.id) ?: SearchProvider.AMAP.id
|
||||
searchProvider = SearchProvider.fromId(providerId)
|
||||
|
||||
hasUserSetLocation = prefs.getBoolean(KEY_HAS_USER_SET_LOCATION, false)
|
||||
mockLatitude = prefs.getString(KEY_MOCK_LATITUDE, "39.908722")?.toDoubleOrNull() ?: 39.908722
|
||||
mockLongitude = prefs.getString(KEY_MOCK_LONGITUDE, "116.397496")?.toDoubleOrNull() ?: 116.397496
|
||||
mockLocationName = prefs.getString(KEY_MOCK_LOCATION_NAME, "") ?: ""
|
||||
|
||||
isServiceEnabled = prefs.getBoolean(KEY_SERVICE_ENABLED, false)
|
||||
|
||||
val historyJson = prefs.getString(KEY_SEARCH_HISTORY, "[]") ?: "[]"
|
||||
searchHistory = parseSearchHistory(historyJson)
|
||||
|
||||
val favoritesJson = prefs.getString(KEY_FAVORITES, "[]") ?: "[]"
|
||||
favorites = parseFavorites(favoritesJson)
|
||||
|
||||
amapApiKey = prefs.getString(KEY_AMAP_API_KEY, "") ?: ""
|
||||
baiduApiKey = prefs.getString(KEY_BAIDU_API_KEY, "") ?: ""
|
||||
|
||||
val modeStr = prefs.getString(KEY_APP_MOCK_MODE, AppMockMode.GLOBAL.name) ?: AppMockMode.GLOBAL.name
|
||||
appMockMode = AppMockMode.fromId(modeStr)
|
||||
|
||||
val whitelistJson = prefs.getString(KEY_WHITELIST_APPS, "[]") ?: "[]"
|
||||
whitelistApps = parsePackageSet(whitelistJson)
|
||||
|
||||
val blacklistJson = prefs.getString(KEY_BLACKLIST_APPS, "[]") ?: "[]"
|
||||
blacklistApps = parsePackageSet(blacklistJson)
|
||||
|
||||
isJitterEnabled = prefs.getBoolean(KEY_ENABLE_JITTER, true)
|
||||
isGnssSimulationEnabled = prefs.getBoolean(KEY_ENABLE_GNSS_SIMULATION, true)
|
||||
isNetworkCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_NETWORK_CAMOUFLAGE, true)
|
||||
isSensorSimulationEnabled = prefs.getBoolean(KEY_ENABLE_SENSOR_SIMULATION, true)
|
||||
isStealthEnabled = prefs.getBoolean(KEY_ENABLE_STEALTH, true)
|
||||
isDevCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_DEV_CAMOUFLAGE, true)
|
||||
}
|
||||
|
||||
fun updateMockLocation(latitude: Double, longitude: Double, name: String = "", isUserManual: Boolean = true) {
|
||||
mockLatitude = latitude
|
||||
mockLongitude = longitude
|
||||
if (name.isNotEmpty()) {
|
||||
mockLocationName = name
|
||||
}
|
||||
if (isUserManual) {
|
||||
hasUserSetLocation = true
|
||||
}
|
||||
prefs.edit()
|
||||
.putBoolean(KEY_HAS_USER_SET_LOCATION, hasUserSetLocation)
|
||||
.putString(KEY_MOCK_LATITUDE, latitude.toString())
|
||||
.putString(KEY_MOCK_LONGITUDE, longitude.toString())
|
||||
.putString(KEY_MOCK_LOCATION_NAME, mockLocationName)
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun updateThemeMode(mode: ThemeMode) {
|
||||
themeMode = mode
|
||||
prefs.edit().putInt(KEY_THEME_MODE, mode.ordinal).apply()
|
||||
}
|
||||
|
||||
fun updateThemeColor(color: Color) {
|
||||
val colorLong = (color.toArgb().toLong() and 0xFFFFFFFFL)
|
||||
themeColor = colorLong
|
||||
prefs.edit().putLong(KEY_THEME_COLOR, colorLong).apply()
|
||||
}
|
||||
|
||||
fun updateDynamicColor(enabled: Boolean) {
|
||||
isDynamicColor = enabled
|
||||
prefs.edit().putBoolean(KEY_DYNAMIC_COLOR, enabled).apply()
|
||||
}
|
||||
|
||||
fun updateAppLanguage(language: AppLanguage) {
|
||||
appLanguage = language
|
||||
prefs.edit().putString(KEY_LANGUAGE, language.tag).apply()
|
||||
}
|
||||
|
||||
fun updateServiceEnabled(enabled: Boolean) {
|
||||
isServiceEnabled = enabled
|
||||
prefs.edit().putBoolean(KEY_SERVICE_ENABLED, enabled).apply()
|
||||
}
|
||||
|
||||
fun addSearchHistory(item: SearchResult) {
|
||||
val updated = (listOf(item) + searchHistory.filterNot { it.name == item.name && it.latitude == item.latitude }).take(10)
|
||||
searchHistory = updated
|
||||
saveSearchHistory(updated)
|
||||
}
|
||||
|
||||
fun removeSearchHistory(item: SearchResult) {
|
||||
val updated = searchHistory.filterNot { it.name == item.name && it.latitude == item.latitude }
|
||||
searchHistory = updated
|
||||
saveSearchHistory(updated)
|
||||
}
|
||||
|
||||
fun clearSearchHistory() {
|
||||
searchHistory = emptyList()
|
||||
saveSearchHistory(emptyList())
|
||||
}
|
||||
|
||||
private fun saveSearchHistory(list: List<SearchResult>) {
|
||||
val array = org.json.JSONArray()
|
||||
for (item in list) {
|
||||
val obj = org.json.JSONObject().apply {
|
||||
put("name", item.name)
|
||||
put("address", item.address)
|
||||
put("lat", item.latitude)
|
||||
put("lng", item.longitude)
|
||||
}
|
||||
array.put(obj)
|
||||
}
|
||||
prefs.edit().putString(KEY_SEARCH_HISTORY, array.toString()).apply()
|
||||
}
|
||||
|
||||
private fun parseSearchHistory(jsonStr: String): List<SearchResult> {
|
||||
return try {
|
||||
val array = org.json.JSONArray(jsonStr)
|
||||
val list = mutableListOf<SearchResult>()
|
||||
for (i in 0 until array.length()) {
|
||||
val obj = array.getJSONObject(i)
|
||||
list.add(
|
||||
SearchResult(
|
||||
name = obj.getString("name"),
|
||||
address = obj.optString("address"),
|
||||
latitude = obj.getDouble("lat"),
|
||||
longitude = obj.getDouble("lng")
|
||||
)
|
||||
)
|
||||
}
|
||||
list
|
||||
} catch (_: Exception) {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
fun addFavorite(item: FavoriteItem) {
|
||||
val updated = listOf(item) + favorites.filterNot { it.id == item.id }
|
||||
favorites = updated
|
||||
saveFavorites(updated)
|
||||
}
|
||||
|
||||
fun removeFavorite(id: String) {
|
||||
val updated = favorites.filterNot { it.id == id }
|
||||
favorites = updated
|
||||
saveFavorites(updated)
|
||||
}
|
||||
|
||||
fun updateFavorite(item: FavoriteItem) {
|
||||
val updated = favorites.map { if (it.id == item.id) item else it }
|
||||
favorites = updated
|
||||
saveFavorites(updated)
|
||||
}
|
||||
|
||||
fun moveFavorite(fromIndex: Int, toIndex: Int) {
|
||||
if (fromIndex == toIndex || fromIndex !in favorites.indices || toIndex !in favorites.indices) return
|
||||
val list = favorites.toMutableList()
|
||||
val item = list.removeAt(fromIndex)
|
||||
list.add(toIndex, item)
|
||||
favorites = list
|
||||
saveFavorites(list)
|
||||
}
|
||||
|
||||
private fun saveFavorites(list: List<FavoriteItem>) {
|
||||
val array = org.json.JSONArray()
|
||||
for (item in list) {
|
||||
val obj = org.json.JSONObject().apply {
|
||||
put("id", item.id)
|
||||
put("name", item.name)
|
||||
put("address", item.address)
|
||||
put("lat", item.latitude)
|
||||
put("lng", item.longitude)
|
||||
put("timestamp", item.timestamp)
|
||||
}
|
||||
array.put(obj)
|
||||
}
|
||||
prefs.edit().putString(KEY_FAVORITES, array.toString()).apply()
|
||||
}
|
||||
|
||||
private fun parseFavorites(jsonStr: String): List<FavoriteItem> {
|
||||
return try {
|
||||
val array = org.json.JSONArray(jsonStr)
|
||||
val list = mutableListOf<FavoriteItem>()
|
||||
for (i in 0 until array.length()) {
|
||||
val obj = array.getJSONObject(i)
|
||||
list.add(
|
||||
FavoriteItem(
|
||||
id = obj.optString("id", java.util.UUID.randomUUID().toString()),
|
||||
name = obj.getString("name"),
|
||||
address = obj.optString("address", ""),
|
||||
latitude = obj.getDouble("lat"),
|
||||
longitude = obj.getDouble("lng"),
|
||||
timestamp = obj.optLong("timestamp", System.currentTimeMillis())
|
||||
)
|
||||
)
|
||||
}
|
||||
list
|
||||
} catch (_: Exception) {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSearchProvider(provider: SearchProvider) {
|
||||
searchProvider = provider
|
||||
prefs.edit().putString(KEY_SEARCH_PROVIDER, provider.id).apply()
|
||||
}
|
||||
|
||||
fun updateAmapApiKey(key: String) {
|
||||
amapApiKey = key.trim()
|
||||
prefs.edit().putString(KEY_AMAP_API_KEY, amapApiKey).apply()
|
||||
}
|
||||
|
||||
fun updateBaiduApiKey(key: String) {
|
||||
baiduApiKey = key.trim()
|
||||
prefs.edit().putString(KEY_BAIDU_API_KEY, baiduApiKey).apply()
|
||||
}
|
||||
|
||||
fun getCurrentProviderKey(): String {
|
||||
return when (searchProvider) {
|
||||
SearchProvider.AMAP -> amapApiKey
|
||||
SearchProvider.BAIDU -> baiduApiKey
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCurrentProviderKey(key: String) {
|
||||
when (searchProvider) {
|
||||
SearchProvider.AMAP -> updateAmapApiKey(key)
|
||||
SearchProvider.BAIDU -> updateBaiduApiKey(key)
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
fun updateAppMockMode(mode: AppMockMode) {
|
||||
appMockMode = mode
|
||||
prefs.edit().putString(KEY_APP_MOCK_MODE, mode.name).apply()
|
||||
}
|
||||
|
||||
fun updateWhitelistApps(packages: Set<String>) {
|
||||
whitelistApps = packages
|
||||
savePackageSet(KEY_WHITELIST_APPS, packages)
|
||||
}
|
||||
|
||||
fun toggleWhitelistApp(packageName: String) {
|
||||
val updated = if (whitelistApps.contains(packageName)) {
|
||||
whitelistApps - packageName
|
||||
} else {
|
||||
whitelistApps + packageName
|
||||
}
|
||||
updateWhitelistApps(updated)
|
||||
}
|
||||
|
||||
fun updateBlacklistApps(packages: Set<String>) {
|
||||
blacklistApps = packages
|
||||
savePackageSet(KEY_BLACKLIST_APPS, packages)
|
||||
}
|
||||
|
||||
fun toggleBlacklistApp(packageName: String) {
|
||||
val updated = if (blacklistApps.contains(packageName)) {
|
||||
blacklistApps - packageName
|
||||
} else {
|
||||
blacklistApps + packageName
|
||||
}
|
||||
updateBlacklistApps(updated)
|
||||
}
|
||||
|
||||
private fun savePackageSet(key: String, packages: Set<String>) {
|
||||
val array = org.json.JSONArray()
|
||||
for (pkg in packages) {
|
||||
array.put(pkg)
|
||||
}
|
||||
prefs.edit().putString(key, array.toString()).apply()
|
||||
}
|
||||
|
||||
private fun parsePackageSet(jsonStr: String): Set<String> {
|
||||
return try {
|
||||
val array = org.json.JSONArray(jsonStr)
|
||||
val set = mutableSetOf<String>()
|
||||
for (i in 0 until array.length()) {
|
||||
set.add(array.getString(i))
|
||||
}
|
||||
set
|
||||
} catch (_: Exception) {
|
||||
emptySet()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateJitterEnabled(enabled: Boolean) {
|
||||
isJitterEnabled = enabled
|
||||
prefs.edit().putBoolean(KEY_ENABLE_JITTER, enabled).apply()
|
||||
}
|
||||
|
||||
fun updateGnssSimulationEnabled(enabled: Boolean) {
|
||||
isGnssSimulationEnabled = enabled
|
||||
prefs.edit().putBoolean(KEY_ENABLE_GNSS_SIMULATION, enabled).apply()
|
||||
}
|
||||
|
||||
fun updateNetworkCamouflageEnabled(enabled: Boolean) {
|
||||
isNetworkCamouflageEnabled = enabled
|
||||
prefs.edit().putBoolean(KEY_ENABLE_NETWORK_CAMOUFLAGE, enabled).apply()
|
||||
}
|
||||
|
||||
fun updateSensorSimulationEnabled(enabled: Boolean) {
|
||||
isSensorSimulationEnabled = enabled
|
||||
prefs.edit().putBoolean(KEY_ENABLE_SENSOR_SIMULATION, enabled).apply()
|
||||
}
|
||||
|
||||
fun updateStealthEnabled(enabled: Boolean) {
|
||||
isStealthEnabled = enabled
|
||||
prefs.edit().putBoolean(KEY_ENABLE_STEALTH, enabled).apply()
|
||||
}
|
||||
|
||||
fun updateDevCamouflageEnabled(enabled: Boolean) {
|
||||
isDevCamouflageEnabled = enabled
|
||||
prefs.edit().putBoolean(KEY_ENABLE_DEV_CAMOUFLAGE, enabled).apply()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.lzxnone.openloc.hook
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import com.lzxnone.openloc.hook.interceptor.AntiDetectionHook
|
||||
import com.lzxnone.openloc.hook.interceptor.GnssHook
|
||||
import com.lzxnone.openloc.hook.interceptor.LocationHook
|
||||
import com.lzxnone.openloc.hook.interceptor.NetworkLocationHook
|
||||
import com.lzxnone.openloc.hook.interceptor.SensorHook
|
||||
import com.lzxnone.openloc.hook.system.SystemServerHook
|
||||
import de.robv.android.xposed.IXposedHookLoadPackage
|
||||
import de.robv.android.xposed.XC_MethodHook
|
||||
import de.robv.android.xposed.XC_MethodReplacement
|
||||
import de.robv.android.xposed.XposedBridge
|
||||
import de.robv.android.xposed.XposedHelpers
|
||||
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
||||
|
||||
/**
|
||||
* Xposed / LSPosed 统一 Hook 分发主入口
|
||||
*/
|
||||
class HookEntry : IXposedHookLoadPackage {
|
||||
|
||||
@Volatile
|
||||
private var appContext: Context? = null
|
||||
|
||||
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
|
||||
// 1. 系统级全局拦截:如果是 Android 系统框架 (system_server)
|
||||
// 只要在 LSPosed 中勾选了【Android 系统 (android)】,整机所有应用全部享受全局定位拦截!
|
||||
if (lpparam.packageName == "android") {
|
||||
SystemServerHook.hook(lpparam.classLoader)
|
||||
return
|
||||
}
|
||||
|
||||
// 过滤系统 UI 进程
|
||||
if (lpparam.packageName == "com.android.systemui") {
|
||||
return
|
||||
}
|
||||
|
||||
// 2. 如果加载的是本应用自身,Hook 激活判定桩使其恒返回 true
|
||||
if (lpparam.packageName == MODULE_PACKAGE_NAME) {
|
||||
hookSelfActiveStatus(lpparam.classLoader)
|
||||
return
|
||||
}
|
||||
|
||||
// 3. 注入目标应用进程(客户端双重兜底):挂载 Context 并启动深度拦截链路(WiFi/基站/NMEA)
|
||||
initTargetHooks(lpparam)
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook 本身应用的 HookStatus.isModuleActive(),令其返回 true
|
||||
*/
|
||||
private fun hookSelfActiveStatus(classLoader: ClassLoader) {
|
||||
try {
|
||||
XposedHelpers.findAndHookMethod(
|
||||
"com.lzxnone.openloc.core.util.HookStatus",
|
||||
classLoader,
|
||||
"isModuleActive",
|
||||
object : XC_MethodReplacement() {
|
||||
override fun replaceHookedMethod(param: MethodHookParam?): Any {
|
||||
return true
|
||||
}
|
||||
}
|
||||
)
|
||||
XposedBridge.log("[OpenLoc] Hooked isModuleActive -> true successfully")
|
||||
} catch (t: Throwable) {
|
||||
XposedBridge.log("[OpenLoc] Failed to hook isModuleActive: ${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 目标应用进程初始化与全链路 Hook 挂载
|
||||
*/
|
||||
private fun initTargetHooks(lpparam: XC_LoadPackage.LoadPackageParam) {
|
||||
try {
|
||||
val contextProvider = { appContext }
|
||||
|
||||
// 监听 Application 启动以安全捕获应用级 Context
|
||||
XposedHelpers.findAndHookMethod(
|
||||
Application::class.java,
|
||||
"attach",
|
||||
Context::class.java,
|
||||
object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
if (appContext == null) {
|
||||
appContext = param.args[0] as? Context
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// 挂载定位与防检测核心拦截线
|
||||
LocationHook.hook(lpparam.classLoader, contextProvider)
|
||||
NetworkLocationHook.hook(lpparam.classLoader, contextProvider)
|
||||
GnssHook.hook(lpparam.classLoader, contextProvider)
|
||||
SensorHook.hook(lpparam.classLoader, contextProvider)
|
||||
AntiDetectionHook.hook(lpparam.classLoader, contextProvider)
|
||||
|
||||
XposedBridge.log("[OpenLoc] Injected target hooks for: ${lpparam.packageName}")
|
||||
} catch (t: Throwable) {
|
||||
XposedBridge.log("[OpenLoc] Error initializing target hooks for ${lpparam.packageName}: ${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val MODULE_PACKAGE_NAME = "com.lzxnone.openloc"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
package com.lzxnone.openloc.hook.interceptor
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
||||
import de.robv.android.xposed.XC_MethodHook
|
||||
import de.robv.android.xposed.XposedBridge
|
||||
import de.robv.android.xposed.XposedHelpers
|
||||
|
||||
/**
|
||||
* 防检测与隐匿拦截器
|
||||
* 1. 堆栈清洗:过滤 Xposed / LSPosed / OpenLoc 相关调用栈帧
|
||||
* 2. 模块包名自隐匿:隐藏 com.lzxnone.openloc,防止被目标应用通过 PackageManager 探测
|
||||
* 3. 开发者选项与模拟位置状态伪装:伪装开发者模式、USB调试、模拟位置为未开启
|
||||
*/
|
||||
object AntiDetectionHook {
|
||||
|
||||
private val isSanitizingStack = ThreadLocal.withInitial { false }
|
||||
|
||||
private val CAMOUFLAGE_SETTINGS_KEYS = setOf(
|
||||
"development_settings_enabled",
|
||||
"adb_enabled",
|
||||
"mock_location",
|
||||
"ALLOW_MOCK_LOCATION"
|
||||
)
|
||||
|
||||
private const val MODULE_PACKAGE_NAME = "com.lzxnone.openloc"
|
||||
|
||||
fun hook(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||
hookStackTrace(contextProvider)
|
||||
hookPackageManager(classLoader, contextProvider)
|
||||
hookSettingsCamouflage(classLoader, contextProvider)
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 调用栈隐匿:对 Throwable 与 Thread 的 getStackTrace 进行清洗
|
||||
*/
|
||||
private fun hookStackTrace(contextProvider: () -> Context?) {
|
||||
try {
|
||||
// Hook Throwable.getStackTrace()
|
||||
XposedHelpers.findAndHookMethod(
|
||||
Throwable::class.java,
|
||||
"getStackTrace",
|
||||
object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
if (isSanitizingStack.get() == true) return
|
||||
try {
|
||||
isSanitizingStack.set(true)
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName) || !config.isStealthEnabled) return
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val originalElements = param.result as? Array<StackTraceElement> ?: return
|
||||
var hasForbidden = false
|
||||
for (elem in originalElements) {
|
||||
if (isForbiddenClassName(elem.className)) {
|
||||
hasForbidden = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (hasForbidden) {
|
||||
param.result = originalElements.filter { !isForbiddenClassName(it.className) }.toTypedArray()
|
||||
}
|
||||
} finally {
|
||||
isSanitizingStack.set(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// Hook Thread.getStackTrace()
|
||||
XposedHelpers.findAndHookMethod(
|
||||
Thread::class.java,
|
||||
"getStackTrace",
|
||||
object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
if (isSanitizingStack.get() == true) return
|
||||
try {
|
||||
isSanitizingStack.set(true)
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName) || !config.isStealthEnabled) return
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val originalElements = param.result as? Array<StackTraceElement> ?: return
|
||||
var hasForbidden = false
|
||||
for (elem in originalElements) {
|
||||
if (isForbiddenClassName(elem.className)) {
|
||||
hasForbidden = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (hasForbidden) {
|
||||
param.result = originalElements.filter { !isForbiddenClassName(it.className) }.toTypedArray()
|
||||
}
|
||||
} finally {
|
||||
isSanitizingStack.set(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (t: Throwable) {
|
||||
XposedBridge.log("[OpenLoc] hookStackTrace error: ${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun isForbiddenClassName(className: String): Boolean {
|
||||
val lower = className.lowercase()
|
||||
return lower.contains("openloc") ||
|
||||
lower.contains("xposed") ||
|
||||
lower.contains("lsposed") ||
|
||||
lower.contains("sandhook") ||
|
||||
lower.contains("edxposed")
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. PackageManager 模块自隐匿
|
||||
*/
|
||||
private fun hookPackageManager(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||
val pmClasses = listOf(
|
||||
"android.app.ApplicationPackageManager",
|
||||
"android.content.pm.PackageManager"
|
||||
)
|
||||
|
||||
for (pmClassName in pmClasses) {
|
||||
val pmClass = try {
|
||||
XposedHelpers.findClass(pmClassName, classLoader)
|
||||
} catch (_: Throwable) {
|
||||
null
|
||||
} ?: continue
|
||||
|
||||
for (method in pmClass.declaredMethods) {
|
||||
when (method.name) {
|
||||
"getPackageInfo" -> {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val pkgName = param.args.firstOrNull { it is String } as? String ?: return
|
||||
if (pkgName == MODULE_PACKAGE_NAME) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isStealthEnabled) {
|
||||
param.throwable = PackageManager.NameNotFoundException(pkgName)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
"getApplicationInfo" -> {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val pkgName = param.args.firstOrNull { it is String } as? String ?: return
|
||||
if (pkgName == MODULE_PACKAGE_NAME) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isStealthEnabled) {
|
||||
param.throwable = PackageManager.NameNotFoundException(pkgName)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
"getInstalledPackages" -> {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName) || !config.isStealthEnabled) return
|
||||
|
||||
val list = param.result as? List<*> ?: return
|
||||
val filtered = list.filter {
|
||||
(it as? PackageInfo)?.packageName != MODULE_PACKAGE_NAME
|
||||
}
|
||||
param.result = filtered
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
"getInstalledApplications" -> {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName) || !config.isStealthEnabled) return
|
||||
|
||||
val list = param.result as? List<*> ?: return
|
||||
val filtered = list.filter {
|
||||
(it as? ApplicationInfo)?.packageName != MODULE_PACKAGE_NAME
|
||||
}
|
||||
param.result = filtered
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. 开发者选项与系统模拟位置状态伪装 (Settings.Secure & Settings.Global)
|
||||
*/
|
||||
private fun hookSettingsCamouflage(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||
val settingsClasses = listOf(
|
||||
"android.provider.Settings\$Secure",
|
||||
"android.provider.Settings\$Global"
|
||||
)
|
||||
|
||||
for (className in settingsClasses) {
|
||||
val settingsClass = try {
|
||||
XposedHelpers.findClass(className, classLoader)
|
||||
} catch (_: Throwable) {
|
||||
null
|
||||
} ?: continue
|
||||
|
||||
for (method in settingsClass.declaredMethods) {
|
||||
val methodName = method.name
|
||||
when (methodName) {
|
||||
"getString" -> {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val key = param.args.firstOrNull { it is String } as? String ?: return
|
||||
if (CAMOUFLAGE_SETTINGS_KEYS.contains(key)) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isDevCamouflageEnabled) {
|
||||
param.result = "0"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
"getInt" -> {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val key = param.args.firstOrNull { it is String } as? String ?: return
|
||||
if (CAMOUFLAGE_SETTINGS_KEYS.contains(key)) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isDevCamouflageEnabled) {
|
||||
param.result = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
"getLong" -> {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val key = param.args.firstOrNull { it is String } as? String ?: return
|
||||
if (CAMOUFLAGE_SETTINGS_KEYS.contains(key)) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isDevCamouflageEnabled) {
|
||||
param.result = 0L
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package com.lzxnone.openloc.hook.interceptor
|
||||
|
||||
import android.content.Context
|
||||
import android.location.GnssStatus
|
||||
import android.location.GpsStatus
|
||||
import android.location.LocationManager
|
||||
import android.location.OnNmeaMessageListener
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
||||
import com.lzxnone.openloc.hook.util.LocationSimulator
|
||||
import com.lzxnone.openloc.hook.util.VirtualGnssEngine
|
||||
import de.robv.android.xposed.XC_MethodHook
|
||||
import de.robv.android.xposed.XposedBridge
|
||||
import de.robv.android.xposed.XposedHelpers
|
||||
import java.util.Collections
|
||||
import java.util.WeakHashMap
|
||||
|
||||
/**
|
||||
* 全真多星座 GNSS 卫星与 NMEA 报文拦截器
|
||||
*
|
||||
* 1. 深度拦截 GnssStatus.Callback,构造注入 26 颗多星座卫星(GPS、北斗、GLONASS、Galileo)
|
||||
* 2. 维持 1Hz 卫星心跳分发,室内/无真实信号下仍持续稳定分发有效卫星解
|
||||
* 3. 拦截 NMEA 监听器,全量伪造 $GNGGA、$GNRMC、$GNGSA、$BDGSA、$GPGSV、$BDGSV、$GLGSV
|
||||
* 4. 兼容旧版 GpsStatus.Listener 探测
|
||||
*/
|
||||
object GnssHook {
|
||||
|
||||
private val isDeliveringNmea = ThreadLocal.withInitial { false }
|
||||
private val activeGnssCallbacks = Collections.newSetFromMap(WeakHashMap<GnssStatus.Callback, Boolean>())
|
||||
private val activeGpsListeners = Collections.newSetFromMap(WeakHashMap<GpsStatus.Listener, Boolean>())
|
||||
|
||||
@Volatile
|
||||
private var isTickerStarted = false
|
||||
private var mainHandler: Handler? = null
|
||||
|
||||
fun hook(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||
hookNmeaListener(contextProvider)
|
||||
hookGnssStatusCallbacks(classLoader, contextProvider)
|
||||
hookGpsStatusLegacy(contextProvider)
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 拦截并分发全真 NMEA-0183 多星座报文阵列
|
||||
*/
|
||||
private fun hookNmeaListener(contextProvider: () -> Context?) {
|
||||
try {
|
||||
val methods = LocationManager::class.java.declaredMethods
|
||||
for (method in methods) {
|
||||
if (method.name == "addNmeaListener") {
|
||||
val paramTypes = method.parameterTypes
|
||||
val listenerIndex = paramTypes.indexOfFirst {
|
||||
OnNmeaMessageListener::class.java.isAssignableFrom(it)
|
||||
}
|
||||
|
||||
if (listenerIndex != -1) {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val originalListener = param.args[listenerIndex] as? OnNmeaMessageListener ?: return
|
||||
hookNmeaCallback(originalListener, contextProvider)
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
XposedBridge.log("[OpenLoc] hookNmeaListener error: ${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
private val hookedNmeaClasses = mutableSetOf<String>()
|
||||
|
||||
private fun hookNmeaCallback(listener: OnNmeaMessageListener, contextProvider: () -> Context?) {
|
||||
val clazz = listener.javaClass
|
||||
val className = clazz.name
|
||||
if (hookedNmeaClasses.contains(className)) return
|
||||
hookedNmeaClasses.add(className)
|
||||
|
||||
try {
|
||||
XposedHelpers.findAndHookMethod(
|
||||
clazz,
|
||||
"onNmeaMessage",
|
||||
String::class.java,
|
||||
Long::class.javaPrimitiveType,
|
||||
object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
if (isDeliveringNmea.get() == true) return
|
||||
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName) || !config.isGnssSimulationEnabled) return
|
||||
|
||||
val rawMessage = param.args[0] as? String ?: return
|
||||
val timestamp = param.args[1] as? Long ?: System.currentTimeMillis()
|
||||
|
||||
// 当系统开始触发 NMEA 时,动态替换并批量补齐多星座全套报文
|
||||
if (rawMessage.startsWith("\$GP") || rawMessage.startsWith("\$GN") || rawMessage.startsWith("\$BD")) {
|
||||
val (curLat, curLng) = LocationSimulator.getSimulatedCoordinates(
|
||||
config.latitude,
|
||||
config.longitude,
|
||||
config.isJitterEnabled
|
||||
)
|
||||
|
||||
val fullNmeaList = VirtualGnssEngine.generateFullNmeaSequence(curLat, curLng, timestamp)
|
||||
if (fullNmeaList.isNotEmpty()) {
|
||||
// 替换当前句为第一句($GNGGA)
|
||||
param.args[0] = fullNmeaList[0]
|
||||
|
||||
// 补发剩余语句 ($GNRMC, $GNGSA, $BDGSA, $GPGSV...)
|
||||
try {
|
||||
isDeliveringNmea.set(true)
|
||||
val targetListener = param.thisObject as? OnNmeaMessageListener
|
||||
if (targetListener != null) {
|
||||
for (i in 1 until fullNmeaList.size) {
|
||||
targetListener.onNmeaMessage(fullNmeaList[i], timestamp)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
isDeliveringNmea.set(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. 深度拦截 GnssStatus 回调并维持 1Hz 卫星心跳
|
||||
*/
|
||||
private fun hookGnssStatusCallbacks(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||
try {
|
||||
// (1) 拦截 LocationManager.registerGnssStatusCallback 各重载
|
||||
val methods = LocationManager::class.java.declaredMethods
|
||||
for (method in methods) {
|
||||
if (method.name == "registerGnssStatusCallback") {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val callback = param.args.firstOrNull { it is GnssStatus.Callback } as? GnssStatus.Callback ?: return
|
||||
synchronized(activeGnssCallbacks) {
|
||||
activeGnssCallbacks.add(callback)
|
||||
}
|
||||
ensureTickerStarted(contextProvider)
|
||||
hookSingleGnssCallbackClass(callback.javaClass, contextProvider)
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
} else if (method.name == "unregisterGnssStatusCallback") {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val callback = param.args.firstOrNull { it is GnssStatus.Callback } as? GnssStatus.Callback ?: return
|
||||
synchronized(activeGnssCallbacks) {
|
||||
activeGnssCallbacks.remove(callback)
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
XposedBridge.log("[OpenLoc] hookGnssStatusCallbacks error: ${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
private val hookedGnssCallbackClasses = mutableSetOf<String>()
|
||||
|
||||
private fun hookSingleGnssCallbackClass(clazz: Class<*>, contextProvider: () -> Context?) {
|
||||
val className = clazz.name
|
||||
if (hookedGnssCallbackClasses.contains(className)) return
|
||||
hookedGnssCallbackClasses.add(className)
|
||||
|
||||
try {
|
||||
// Hook onSatelliteStatusChanged(GnssStatus)
|
||||
XposedHelpers.findAndHookMethod(
|
||||
clazz,
|
||||
"onSatelliteStatusChanged",
|
||||
GnssStatus::class.java,
|
||||
object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName) || !config.isGnssSimulationEnabled) return
|
||||
|
||||
val fakeStatus = VirtualGnssEngine.createGnssStatus()
|
||||
if (fakeStatus != null) {
|
||||
param.args[0] = fakeStatus
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. 启动 1Hz 定时卫星仿真分发调度(针对无真实卫星信号、室内等环境兜底)
|
||||
*/
|
||||
private fun ensureTickerStarted(contextProvider: () -> Context?) {
|
||||
if (isTickerStarted) return
|
||||
synchronized(this) {
|
||||
if (isTickerStarted) return
|
||||
isTickerStarted = true
|
||||
|
||||
if (mainHandler == null) {
|
||||
try {
|
||||
mainHandler = Handler(Looper.getMainLooper())
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
mainHandler?.post(object : Runnable {
|
||||
override fun run() {
|
||||
try {
|
||||
dispatchSimulatedGnssTick(contextProvider)
|
||||
} catch (_: Throwable) {}
|
||||
mainHandler?.postDelayed(this, 1000L) // 1 秒刷新一次
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private val notifiedFirstFixSet = Collections.newSetFromMap(WeakHashMap<GnssStatus.Callback, Boolean>())
|
||||
|
||||
private fun dispatchSimulatedGnssTick(contextProvider: () -> Context?) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName) || !config.isGnssSimulationEnabled) return
|
||||
|
||||
val fakeStatus = VirtualGnssEngine.createGnssStatus() ?: return
|
||||
|
||||
val callbacksSnapshot = synchronized(activeGnssCallbacks) {
|
||||
activeGnssCallbacks.toList()
|
||||
}
|
||||
|
||||
for (cb in callbacksSnapshot) {
|
||||
try {
|
||||
if (!notifiedFirstFixSet.contains(cb)) {
|
||||
notifiedFirstFixSet.add(cb)
|
||||
cb.onStarted()
|
||||
cb.onFirstFix(1200) // 1.2s 极速逼真定位时间
|
||||
}
|
||||
cb.onSatelliteStatusChanged(fakeStatus)
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
// 兼容旧版 GpsStatus
|
||||
val listenersSnapshot = synchronized(activeGpsListeners) {
|
||||
activeGpsListeners.toList()
|
||||
}
|
||||
for (listener in listenersSnapshot) {
|
||||
try {
|
||||
listener.onGpsStatusChanged(GpsStatus.GPS_EVENT_SATELLITE_STATUS)
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 4. 兼容老版本 SDK 的 GpsStatus.Listener
|
||||
*/
|
||||
private fun hookGpsStatusLegacy(contextProvider: () -> Context?) {
|
||||
try {
|
||||
// Hook addGpsStatusListener
|
||||
XposedHelpers.findAndHookMethod(
|
||||
LocationManager::class.java,
|
||||
"addGpsStatusListener",
|
||||
GpsStatus.Listener::class.java,
|
||||
object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val listener = param.args[0] as? GpsStatus.Listener ?: return
|
||||
synchronized(activeGpsListeners) {
|
||||
activeGpsListeners.add(listener)
|
||||
}
|
||||
ensureTickerStarted(contextProvider)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// Hook removeGpsStatusListener
|
||||
XposedHelpers.findAndHookMethod(
|
||||
LocationManager::class.java,
|
||||
"removeGpsStatusListener",
|
||||
GpsStatus.Listener::class.java,
|
||||
object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val listener = param.args[0] as? GpsStatus.Listener ?: return
|
||||
synchronized(activeGpsListeners) {
|
||||
activeGpsListeners.remove(listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// Hook getGpsStatus(GpsStatus status)
|
||||
XposedHelpers.findAndHookMethod(
|
||||
LocationManager::class.java,
|
||||
"getGpsStatus",
|
||||
GpsStatus::class.java,
|
||||
object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName) || !config.isGnssSimulationEnabled) return
|
||||
|
||||
val status = (param.result as? GpsStatus) ?: (param.args[0] as? GpsStatus) ?: return
|
||||
try {
|
||||
XposedHelpers.setIntField(status, "mTimeToFirstFix", 1200)
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
package com.lzxnone.openloc.hook.interceptor
|
||||
|
||||
import android.content.Context
|
||||
import android.location.Location
|
||||
import android.location.LocationListener
|
||||
import android.location.LocationManager
|
||||
import android.os.Build
|
||||
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
||||
import com.lzxnone.openloc.hook.util.LocationSimulator
|
||||
import de.robv.android.xposed.XC_MethodHook
|
||||
import de.robv.android.xposed.XC_MethodReplacement
|
||||
import de.robv.android.xposed.XposedBridge
|
||||
import de.robv.android.xposed.XposedHelpers
|
||||
import java.lang.reflect.Proxy
|
||||
|
||||
/**
|
||||
* 原生定位服务 LocationManager 与 Location 实体拦截器
|
||||
*/
|
||||
object LocationHook {
|
||||
|
||||
fun hook(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||
hookLocationEntity()
|
||||
hookLocationManager(classLoader, contextProvider)
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 拦截 Location 实体类中的 Mock 判定方法
|
||||
*/
|
||||
private fun hookLocationEntity() {
|
||||
try {
|
||||
// Hook isFromMockProvider 恒返回 false
|
||||
XposedHelpers.findAndHookMethod(
|
||||
Location::class.java,
|
||||
"isFromMockProvider",
|
||||
object : XC_MethodReplacement() {
|
||||
override fun replaceHookedMethod(param: MethodHookParam?): Any {
|
||||
return false
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// Android 12 (API 31)+ isMock() 恒返回 false
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
try {
|
||||
XposedHelpers.findAndHookMethod(
|
||||
Location::class.java,
|
||||
"isMock",
|
||||
object : XC_MethodReplacement() {
|
||||
override fun replaceHookedMethod(param: MethodHookParam?): Any {
|
||||
return false
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
XposedBridge.log("[OpenLoc] hookLocationEntity failed: ${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. 拦截 LocationManager 的核心定位获取方法
|
||||
*/
|
||||
private fun hookLocationManager(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||
try {
|
||||
// (1) 拦截 getLastKnownLocation
|
||||
XposedHelpers.findAndHookMethod(
|
||||
LocationManager::class.java,
|
||||
"getLastKnownLocation",
|
||||
String::class.java,
|
||||
object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName)) return
|
||||
|
||||
val provider = param.args[0] as? String ?: LocationManager.GPS_PROVIDER
|
||||
param.result = LocationSimulator.createMockLocation(
|
||||
latitude = config.latitude,
|
||||
longitude = config.longitude,
|
||||
provider = provider,
|
||||
isJitterEnabled = config.isJitterEnabled
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// (2) 拦截 requestLocationUpdates 各重载中传入的 LocationListener
|
||||
val methods = LocationManager::class.java.declaredMethods
|
||||
for (method in methods) {
|
||||
if (method.name == "requestLocationUpdates") {
|
||||
val paramTypes = method.parameterTypes
|
||||
val listenerIndex = paramTypes.indexOfFirst {
|
||||
LocationListener::class.java.isAssignableFrom(it)
|
||||
}
|
||||
|
||||
if (listenerIndex != -1) {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val originalListener = param.args[listenerIndex] as? LocationListener ?: return
|
||||
// 拦截回调类并 Hook 其 onLocationChanged
|
||||
hookListenerClass(originalListener.javaClass, contextProvider)
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// (3) Android 12+ 拦截 getCurrentLocation 异步单次定位
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
hookGetCurrentLocation(contextProvider)
|
||||
}
|
||||
|
||||
} catch (t: Throwable) {
|
||||
XposedBridge.log("[OpenLoc] hookLocationManager failed: ${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook 具体应用实现的 LocationListener.onLocationChanged
|
||||
*/
|
||||
private val hookedListenerClasses = mutableSetOf<String>()
|
||||
|
||||
private fun hookListenerClass(clazz: Class<*>, contextProvider: () -> Context?) {
|
||||
val className = clazz.name
|
||||
if (hookedListenerClasses.contains(className)) return
|
||||
hookedListenerClasses.add(className)
|
||||
|
||||
try {
|
||||
// Hook onLocationChanged(Location)
|
||||
XposedHelpers.findAndHookMethod(
|
||||
clazz,
|
||||
"onLocationChanged",
|
||||
Location::class.java,
|
||||
object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName)) return
|
||||
|
||||
val location = param.args[0] as? Location
|
||||
if (location != null) {
|
||||
LocationSimulator.applyMockData(location, config.latitude, config.longitude, config.isJitterEnabled)
|
||||
} else {
|
||||
param.args[0] = LocationSimulator.createMockLocation(
|
||||
config.latitude,
|
||||
config.longitude,
|
||||
isJitterEnabled = config.isJitterEnabled
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (_: Throwable) {}
|
||||
|
||||
// Android 14 (API 34)+ 新增 onLocationChanged(List<Location>)
|
||||
try {
|
||||
XposedHelpers.findAndHookMethod(
|
||||
clazz,
|
||||
"onLocationChanged",
|
||||
List::class.java,
|
||||
object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName)) return
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val list = param.args[0] as? List<Location> ?: return
|
||||
for (loc in list) {
|
||||
LocationSimulator.applyMockData(loc, config.latitude, config.longitude, config.isJitterEnabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Android 11+ / 12+ 单次定位 getCurrentLocation 拦截
|
||||
*/
|
||||
private fun hookGetCurrentLocation(contextProvider: () -> Context?) {
|
||||
val methods = LocationManager::class.java.declaredMethods
|
||||
for (method in methods) {
|
||||
if (method.name == "getCurrentLocation") {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName)) return
|
||||
|
||||
// Consumer<Location> 通常位于最后一位
|
||||
val lastIndex = param.args.size - 1
|
||||
if (lastIndex >= 0) {
|
||||
val originalConsumer = param.args[lastIndex] ?: return
|
||||
val consumerInterface = originalConsumer.javaClass.interfaces.firstOrNull {
|
||||
it.name == "java.util.function.Consumer"
|
||||
} ?: return
|
||||
|
||||
val proxy = Proxy.newProxyInstance(
|
||||
consumerInterface.classLoader,
|
||||
arrayOf(consumerInterface)
|
||||
) { _, m, args ->
|
||||
if (m.name == "accept" && args != null && args.isNotEmpty()) {
|
||||
val mockLoc = LocationSimulator.createMockLocation(
|
||||
config.latitude,
|
||||
config.longitude,
|
||||
isJitterEnabled = config.isJitterEnabled
|
||||
)
|
||||
m.invoke(originalConsumer, mockLoc)
|
||||
} else {
|
||||
m.invoke(originalConsumer, *(args ?: emptyArray()))
|
||||
}
|
||||
}
|
||||
param.args[lastIndex] = proxy
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package com.lzxnone.openloc.hook.interceptor
|
||||
|
||||
import android.content.Context
|
||||
import android.net.wifi.ScanResult
|
||||
import android.net.wifi.WifiInfo
|
||||
import android.net.wifi.WifiManager
|
||||
import android.os.Build
|
||||
import android.telephony.CellInfo
|
||||
import android.telephony.CellLocation
|
||||
import android.telephony.PhoneStateListener
|
||||
import android.telephony.TelephonyManager
|
||||
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
||||
import de.robv.android.xposed.XC_MethodHook
|
||||
import de.robv.android.xposed.XposedBridge
|
||||
import de.robv.android.xposed.XposedHelpers
|
||||
|
||||
/**
|
||||
* Wi-Fi 与基站深度防反查拦截器
|
||||
*
|
||||
* 核心目标:
|
||||
* 1. 拦截 WifiManager 扫描列表与连接 BSSID/MAC,阻断高德/腾讯/百度云端 Wi-Fi 指纹库反查真实物理位置
|
||||
* 2. 拦截 TelephonyManager 基站小区信息与位置监听,杜绝基站 LAC/CID 反查
|
||||
* 3. 拦截 PhoneStateListener 与 Android 12+ TelephonyCallback 实时小区回调
|
||||
*/
|
||||
object NetworkLocationHook {
|
||||
|
||||
private const val ANONYMOUS_MAC = "02:00:00:00:00:00"
|
||||
|
||||
fun hook(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||
hookWifiManager(contextProvider)
|
||||
hookTelephonyManager(classLoader, contextProvider)
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 深度拦截 Wi-Fi 扫描结果与连接 BSSID / MAC
|
||||
*/
|
||||
private fun hookWifiManager(contextProvider: () -> Context?) {
|
||||
try {
|
||||
// (1) 拦截 WifiManager.getScanResults()
|
||||
XposedHelpers.findAndHookMethod(
|
||||
WifiManager::class.java,
|
||||
"getScanResults",
|
||||
object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isNetworkCamouflageEnabled) {
|
||||
param.result = emptyList<ScanResult>()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// (2) 拦截 WifiInfo.getBSSID()
|
||||
XposedHelpers.findAndHookMethod(
|
||||
WifiInfo::class.java,
|
||||
"getBSSID",
|
||||
object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isNetworkCamouflageEnabled) {
|
||||
param.result = ANONYMOUS_MAC
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// (3) 拦截 WifiInfo.getMacAddress()
|
||||
XposedHelpers.findAndHookMethod(
|
||||
WifiInfo::class.java,
|
||||
"getMacAddress",
|
||||
object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isNetworkCamouflageEnabled) {
|
||||
param.result = ANONYMOUS_MAC
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (t: Throwable) {
|
||||
XposedBridge.log("[OpenLoc] hookWifiManager error: ${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. 深度拦截基站塔信息(MCC/MNC/LAC/CID)与实时监听器
|
||||
*/
|
||||
private fun hookTelephonyManager(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||
try {
|
||||
// (1) 拦截 getAllCellInfo
|
||||
XposedHelpers.findAndHookMethod(
|
||||
TelephonyManager::class.java,
|
||||
"getAllCellInfo",
|
||||
object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isNetworkCamouflageEnabled) {
|
||||
param.result = emptyList<CellInfo>()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// (2) 拦截 getCellLocation
|
||||
XposedHelpers.findAndHookMethod(
|
||||
TelephonyManager::class.java,
|
||||
"getCellLocation",
|
||||
object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isNetworkCamouflageEnabled) {
|
||||
param.result = null
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// (3) 拦截 TelephonyManager.listen(PhoneStateListener, int)
|
||||
XposedHelpers.findAndHookMethod(
|
||||
TelephonyManager::class.java,
|
||||
"listen",
|
||||
PhoneStateListener::class.java,
|
||||
Int::class.javaPrimitiveType,
|
||||
object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val listener = param.args[0] as? PhoneStateListener ?: return
|
||||
hookPhoneStateListenerClass(listener.javaClass, contextProvider)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// (4) Android 12+ TelephonyCallback 拦截
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
hookTelephonyCallback(classLoader, contextProvider)
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
XposedBridge.log("[OpenLoc] hookTelephonyManager error: ${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
private val hookedListenerClasses = mutableSetOf<String>()
|
||||
|
||||
private fun hookPhoneStateListenerClass(clazz: Class<*>, contextProvider: () -> Context?) {
|
||||
val className = clazz.name
|
||||
if (hookedListenerClasses.contains(className)) return
|
||||
hookedListenerClasses.add(className)
|
||||
|
||||
try {
|
||||
// onCellLocationChanged
|
||||
XposedHelpers.findAndHookMethod(
|
||||
clazz,
|
||||
"onCellLocationChanged",
|
||||
CellLocation::class.java,
|
||||
object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isNetworkCamouflageEnabled) {
|
||||
param.args[0] = null
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (_: Throwable) {}
|
||||
|
||||
try {
|
||||
// onCellInfoChanged
|
||||
XposedHelpers.findAndHookMethod(
|
||||
clazz,
|
||||
"onCellInfoChanged",
|
||||
List::class.java,
|
||||
object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isNetworkCamouflageEnabled) {
|
||||
param.args[0] = emptyList<CellInfo>()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
private fun hookTelephonyCallback(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||
try {
|
||||
val callbackClass = XposedHelpers.findClass("android.telephony.TelephonyCallback", classLoader)
|
||||
val methods = TelephonyManager::class.java.declaredMethods
|
||||
for (method in methods) {
|
||||
if (method.name == "registerTelephonyCallback") {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val cb = param.args.firstOrNull { it != null && callbackClass.isAssignableFrom(it.javaClass) } ?: return
|
||||
hookTelephonyCallbackClass(cb.javaClass, contextProvider)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
private fun hookTelephonyCallbackClass(clazz: Class<*>, contextProvider: () -> Context?) {
|
||||
val className = clazz.name
|
||||
if (hookedListenerClasses.contains(className)) return
|
||||
hookedListenerClasses.add(className)
|
||||
|
||||
for (method in clazz.declaredMethods) {
|
||||
if (method.name == "onCellInfoChanged") {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isNetworkCamouflageEnabled) {
|
||||
param.args[0] = emptyList<CellInfo>()
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
} else if (method.name == "onCellLocationChanged") {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (config.shouldMock(ctx.packageName) && config.isNetworkCamouflageEnabled) {
|
||||
param.args[0] = null
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.lzxnone.openloc.hook.interceptor
|
||||
|
||||
import android.content.Context
|
||||
import android.hardware.Sensor
|
||||
import android.hardware.SensorEvent
|
||||
import android.hardware.SensorEventListener
|
||||
import android.hardware.SensorManager
|
||||
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
||||
import de.robv.android.xposed.XC_MethodHook
|
||||
import de.robv.android.xposed.XposedBridge
|
||||
import de.robv.android.xposed.XposedHelpers
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* 物理动力学传感器协同与生理微颤拟真拦截器
|
||||
*
|
||||
* 核心目标:
|
||||
* 1. 拦截 SensorManager.registerListener,捕获应用注册的传感器监听器
|
||||
* 2. 针对加速度计 (TYPE_ACCELEROMETER) 与重力传感器 (TYPE_GRAVITY),动态注入人体手持特有的生物力学生理颤动(Physiological Tremor)
|
||||
* 3. 防止加速度方差几乎为 0 导致被高精风控判定为“放置在桌面的静止刚体设备”
|
||||
* 4. 针对陀螺仪 (TYPE_GYROSCOPE) 注入极细微的手持角速度扰动
|
||||
*/
|
||||
object SensorHook {
|
||||
|
||||
private val hookedListenerClasses = mutableSetOf<String>()
|
||||
|
||||
fun hook(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||
hookSensorManager(contextProvider)
|
||||
}
|
||||
|
||||
private fun hookSensorManager(contextProvider: () -> Context?) {
|
||||
try {
|
||||
val methods = SensorManager::class.java.declaredMethods
|
||||
for (method in methods) {
|
||||
if (method.name == "registerListener") {
|
||||
val paramTypes = method.parameterTypes
|
||||
val listenerIndex = paramTypes.indexOfFirst {
|
||||
SensorEventListener::class.java.isAssignableFrom(it)
|
||||
}
|
||||
|
||||
if (listenerIndex != -1) {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val listener = param.args[listenerIndex] as? SensorEventListener ?: return
|
||||
hookSensorEventListenerClass(listener.javaClass, contextProvider)
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
XposedBridge.log("[OpenLoc] hookSensorManager error: ${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun hookSensorEventListenerClass(clazz: Class<*>, contextProvider: () -> Context?) {
|
||||
val className = clazz.name
|
||||
if (hookedListenerClasses.contains(className)) return
|
||||
hookedListenerClasses.add(className)
|
||||
|
||||
try {
|
||||
XposedHelpers.findAndHookMethod(
|
||||
clazz,
|
||||
"onSensorChanged",
|
||||
SensorEvent::class.java,
|
||||
object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val ctx = contextProvider() ?: return
|
||||
val config = ConfigFetcher.getConfig(ctx)
|
||||
if (!config.shouldMock(ctx.packageName) || !config.isSensorSimulationEnabled) return
|
||||
|
||||
val event = param.args[0] as? SensorEvent ?: return
|
||||
val sensorType = event.sensor?.type ?: return
|
||||
|
||||
when (sensorType) {
|
||||
// 1. 三轴加速度计(最核心):注入人体手持 ~0.05 m/s² 生理微颤
|
||||
Sensor.TYPE_ACCELEROMETER -> {
|
||||
if (event.values.size >= 3) {
|
||||
event.values[0] += (Random.nextFloat() - 0.5f) * 0.08f
|
||||
event.values[1] += (Random.nextFloat() - 0.5f) * 0.08f
|
||||
event.values[2] += (Random.nextFloat() - 0.5f) * 0.08f
|
||||
}
|
||||
}
|
||||
// 2. 重力传感器:微量波动维持向量模长
|
||||
Sensor.TYPE_GRAVITY -> {
|
||||
if (event.values.size >= 3) {
|
||||
event.values[0] += (Random.nextFloat() - 0.5f) * 0.04f
|
||||
event.values[1] += (Random.nextFloat() - 0.5f) * 0.04f
|
||||
event.values[2] += (Random.nextFloat() - 0.5f) * 0.04f
|
||||
}
|
||||
}
|
||||
// 3. 陀螺仪:手持微弱角速度波动 (rad/s)
|
||||
Sensor.TYPE_GYROSCOPE -> {
|
||||
if (event.values.size >= 3) {
|
||||
event.values[0] += (Random.nextFloat() - 0.5f) * 0.015f
|
||||
event.values[1] += (Random.nextFloat() - 0.5f) * 0.015f
|
||||
event.values[2] += (Random.nextFloat() - 0.5f) * 0.015f
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.lzxnone.openloc.hook.ipc
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import com.lzxnone.openloc.core.provider.ConfigContract
|
||||
import com.lzxnone.openloc.hook.model.MockConfig
|
||||
import de.robv.android.xposed.XposedBridge
|
||||
|
||||
/**
|
||||
* 跨进程配置拉取与缓存器(运行在目标宿主进程)
|
||||
*/
|
||||
object ConfigFetcher {
|
||||
|
||||
private val PROVIDER_URI = Uri.parse(ConfigContract.CONTENT_URI)
|
||||
|
||||
@Volatile
|
||||
private var cachedConfig: MockConfig? = null
|
||||
|
||||
@Volatile
|
||||
private var lastFetchTime = 0L
|
||||
|
||||
private const val CACHE_DURATION_MS = 1500L // 缓存 1.5 秒,保证即时性同时兼顾性能
|
||||
|
||||
/**
|
||||
* 获取最新配置(带平滑缓存)
|
||||
*/
|
||||
fun getConfig(context: Context, force: Boolean = false): MockConfig {
|
||||
val now = System.currentTimeMillis()
|
||||
if (!force && cachedConfig != null && (now - lastFetchTime < CACHE_DURATION_MS)) {
|
||||
return cachedConfig!!
|
||||
}
|
||||
|
||||
return try {
|
||||
val bundle = context.contentResolver.call(
|
||||
PROVIDER_URI,
|
||||
ConfigContract.METHOD_GET_CONFIG,
|
||||
null,
|
||||
null
|
||||
)
|
||||
|
||||
if (bundle != null) {
|
||||
val mode = bundle.getString(ConfigContract.KEY_APP_MOCK_MODE, "GLOBAL") ?: "GLOBAL"
|
||||
val whitelistJson = bundle.getString(ConfigContract.KEY_WHITELIST_APPS, "[]") ?: "[]"
|
||||
val blacklistJson = bundle.getString(ConfigContract.KEY_BLACKLIST_APPS, "[]") ?: "[]"
|
||||
|
||||
val isJitter = bundle.getBoolean(ConfigContract.KEY_ENABLE_JITTER, true)
|
||||
val isGnss = bundle.getBoolean(ConfigContract.KEY_ENABLE_GNSS_SIMULATION, true)
|
||||
val isNetwork = bundle.getBoolean(ConfigContract.KEY_ENABLE_NETWORK_CAMOUFLAGE, true)
|
||||
val isSensor = bundle.getBoolean(ConfigContract.KEY_ENABLE_SENSOR_SIMULATION, true)
|
||||
val isStealth = bundle.getBoolean(ConfigContract.KEY_ENABLE_STEALTH, true)
|
||||
val isDevCamouflage = bundle.getBoolean(ConfigContract.KEY_ENABLE_DEV_CAMOUFLAGE, true)
|
||||
|
||||
val config = MockConfig(
|
||||
isEnabled = bundle.getBoolean(ConfigContract.KEY_ENABLED, false),
|
||||
latitude = bundle.getDouble(ConfigContract.KEY_LATITUDE, 39.908722),
|
||||
longitude = bundle.getDouble(ConfigContract.KEY_LONGITUDE, 116.397496),
|
||||
locationName = bundle.getString(ConfigContract.KEY_LOCATION_NAME, ""),
|
||||
mode = mode,
|
||||
whitelist = parseSet(whitelistJson),
|
||||
blacklist = parseSet(blacklistJson),
|
||||
isJitterEnabled = isJitter,
|
||||
isGnssSimulationEnabled = isGnss,
|
||||
isNetworkCamouflageEnabled = isNetwork,
|
||||
isSensorSimulationEnabled = isSensor,
|
||||
isStealthEnabled = isStealth,
|
||||
isDevCamouflageEnabled = isDevCamouflage
|
||||
)
|
||||
cachedConfig = config
|
||||
lastFetchTime = now
|
||||
config
|
||||
} else {
|
||||
cachedConfig ?: MockConfig()
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
// 在目标尚未完全就绪或权限受限时的静默容错
|
||||
cachedConfig ?: MockConfig()
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseSet(jsonStr: String): Set<String> {
|
||||
return try {
|
||||
val array = org.json.JSONArray(jsonStr)
|
||||
val set = mutableSetOf<String>()
|
||||
for (i in 0 until array.length()) {
|
||||
set.add(array.getString(i))
|
||||
}
|
||||
set
|
||||
} catch (_: Throwable) {
|
||||
emptySet()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.lzxnone.openloc.hook.model
|
||||
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* 虚拟定位配置实体
|
||||
*/
|
||||
data class MockConfig(
|
||||
val isEnabled: Boolean = false,
|
||||
val latitude: Double = 39.908722,
|
||||
val longitude: Double = 116.397496,
|
||||
val locationName: String = "",
|
||||
val mode: String = "GLOBAL",
|
||||
val whitelist: Set<String> = emptySet(),
|
||||
val blacklist: Set<String> = emptySet(),
|
||||
val isJitterEnabled: Boolean = true,
|
||||
val isGnssSimulationEnabled: Boolean = true,
|
||||
val isNetworkCamouflageEnabled: Boolean = true,
|
||||
val isSensorSimulationEnabled: Boolean = true,
|
||||
val isStealthEnabled: Boolean = true,
|
||||
val isDevCamouflageEnabled: Boolean = true
|
||||
) {
|
||||
/**
|
||||
* 判断指定应用包名是否应当生效虚拟定位
|
||||
*/
|
||||
fun shouldMock(packageName: String): Boolean {
|
||||
if (!isEnabled) return false
|
||||
return when (mode.uppercase(Locale.ROOT)) {
|
||||
"WHITELIST" -> whitelist.contains(packageName)
|
||||
"BLACKLIST" -> !blacklist.contains(packageName)
|
||||
else -> true // "GLOBAL"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
package com.lzxnone.openloc.hook.system
|
||||
|
||||
import android.location.Location
|
||||
import android.os.Build
|
||||
import com.lzxnone.openloc.hook.model.MockConfig
|
||||
import com.lzxnone.openloc.hook.util.LocationSimulator
|
||||
import de.robv.android.xposed.XC_MethodHook
|
||||
import de.robv.android.xposed.XposedBridge
|
||||
import de.robv.android.xposed.XposedHelpers
|
||||
import org.xmlpull.v1.XmlPullParser
|
||||
import org.xmlpull.v1.XmlPullParserFactory
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
|
||||
/**
|
||||
* 针对 Android 系统框架 (system_server / android) 的系统级全局 Hook
|
||||
*
|
||||
* 核心原理:
|
||||
* 在 Android 操作系统中,整机所有应用调用 LocationManager 获取位置,
|
||||
* 底层最终全部汇集到 system_server 进程里的 LocationManagerService 中进行统一调度和分发。
|
||||
*
|
||||
* 只要在 LSPosed 作用域中勾选了【Android 系统 (android)】,本拦截器就会在系统服务底层
|
||||
* 将发往所有应用的位置数据全部篡改并洗白。
|
||||
* 手机里无论是已有应用还是将来新下载的应用,统统无需单独指定,直接全局生效!
|
||||
*/
|
||||
object SystemServerHook {
|
||||
|
||||
private const val PREF_FILE_PATH_1 = "/data/data/com.lzxnone.openloc/shared_prefs/openloc_prefs.xml"
|
||||
private const val PREF_FILE_PATH_2 = "/data/user/0/com.lzxnone.openloc/shared_prefs/openloc_prefs.xml"
|
||||
|
||||
@Volatile
|
||||
private var lastReadTime = 0L
|
||||
@Volatile
|
||||
private var cachedConfig = MockConfig()
|
||||
|
||||
/**
|
||||
* 在 system_server 进程中直接读取 OpenLoc 的配置文件(system_server 具备最高读取权限)
|
||||
*/
|
||||
private fun readConfigDirectly(): MockConfig {
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - lastReadTime < 1500L) {
|
||||
return cachedConfig
|
||||
}
|
||||
|
||||
val file = listOf(File(PREF_FILE_PATH_1), File(PREF_FILE_PATH_2)).firstOrNull { it.exists() && it.canRead() }
|
||||
?: return cachedConfig
|
||||
|
||||
try {
|
||||
var isEnabled = false
|
||||
var lat = 39.908722
|
||||
var lng = 116.397496
|
||||
var mode = "GLOBAL"
|
||||
val whitelist = mutableSetOf<String>()
|
||||
val blacklist = mutableSetOf<String>()
|
||||
var isJitter = true
|
||||
var isGnss = true
|
||||
var isNetwork = true
|
||||
var isSensor = true
|
||||
var isStealth = true
|
||||
var isDevCamouflage = true
|
||||
|
||||
FileInputStream(file).use { fis ->
|
||||
val factory = XmlPullParserFactory.newInstance()
|
||||
val parser = factory.newPullParser()
|
||||
parser.setInput(fis, "UTF-8")
|
||||
|
||||
var eventType = parser.eventType
|
||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
val name = parser.getAttributeValue(null, "name")
|
||||
when (parser.name) {
|
||||
"boolean" -> {
|
||||
when (name) {
|
||||
"mock_service_enabled" -> {
|
||||
isEnabled = parser.getAttributeValue(null, "value") == "true"
|
||||
}
|
||||
"enable_jitter" -> {
|
||||
isJitter = parser.getAttributeValue(null, "value") == "true"
|
||||
}
|
||||
"enable_gnss_simulation" -> {
|
||||
isGnss = parser.getAttributeValue(null, "value") == "true"
|
||||
}
|
||||
"enable_network_camouflage" -> {
|
||||
isNetwork = parser.getAttributeValue(null, "value") == "true"
|
||||
}
|
||||
"enable_sensor_simulation" -> {
|
||||
isSensor = parser.getAttributeValue(null, "value") == "true"
|
||||
}
|
||||
"enable_stealth" -> {
|
||||
isStealth = parser.getAttributeValue(null, "value") == "true"
|
||||
}
|
||||
"enable_dev_camouflage" -> {
|
||||
isDevCamouflage = parser.getAttributeValue(null, "value") == "true"
|
||||
}
|
||||
}
|
||||
}
|
||||
"string" -> {
|
||||
when (name) {
|
||||
"mock_latitude" -> {
|
||||
lat = parser.nextText()?.toDoubleOrNull() ?: lat
|
||||
}
|
||||
"mock_longitude" -> {
|
||||
lng = parser.nextText()?.toDoubleOrNull() ?: lng
|
||||
}
|
||||
"app_mock_mode" -> {
|
||||
mode = parser.nextText() ?: mode
|
||||
}
|
||||
"whitelist_apps" -> {
|
||||
parseJsonArrayToSet(parser.nextText(), whitelist)
|
||||
}
|
||||
"blacklist_apps" -> {
|
||||
parseJsonArrayToSet(parser.nextText(), blacklist)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
eventType = parser.next()
|
||||
}
|
||||
}
|
||||
|
||||
cachedConfig = MockConfig(
|
||||
isEnabled = isEnabled,
|
||||
latitude = lat,
|
||||
longitude = lng,
|
||||
mode = mode,
|
||||
whitelist = whitelist,
|
||||
blacklist = blacklist,
|
||||
isJitterEnabled = isJitter,
|
||||
isGnssSimulationEnabled = isGnss,
|
||||
isNetworkCamouflageEnabled = isNetwork,
|
||||
isSensorSimulationEnabled = isSensor,
|
||||
isStealthEnabled = isStealth,
|
||||
isDevCamouflageEnabled = isDevCamouflage
|
||||
)
|
||||
lastReadTime = now
|
||||
} catch (_: Throwable) {}
|
||||
|
||||
return cachedConfig
|
||||
}
|
||||
|
||||
private fun parseJsonArrayToSet(jsonStr: String?, target: MutableSet<String>) {
|
||||
if (jsonStr.isNullOrBlank()) return
|
||||
try {
|
||||
val array = org.json.JSONArray(jsonStr)
|
||||
for (i in 0 until array.length()) {
|
||||
target.add(array.getString(i))
|
||||
}
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
fun hook(classLoader: ClassLoader) {
|
||||
XposedBridge.log("[OpenLoc] Initializing SystemServerHook for global mock location...")
|
||||
|
||||
hookSystemLocationService(classLoader)
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截系统底层 LocationManagerService 的分发与获取逻辑
|
||||
*/
|
||||
private fun hookSystemLocationService(classLoader: ClassLoader) {
|
||||
val lmsClassNames = listOf(
|
||||
"com.android.server.location.LocationManagerService",
|
||||
"com.android.server.LocationManagerService"
|
||||
)
|
||||
|
||||
for (className in lmsClassNames) {
|
||||
val lmsClass = try {
|
||||
XposedHelpers.findClass(className, classLoader)
|
||||
} catch (_: Throwable) {
|
||||
null
|
||||
} ?: continue
|
||||
|
||||
hookLmsMethods(lmsClass)
|
||||
break
|
||||
}
|
||||
|
||||
// Android 12+ (API 31)+ 核心底层服务 LocationProviderManager 拦截
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
hookLocationProviderManager(classLoader)
|
||||
}
|
||||
}
|
||||
|
||||
private fun hookLmsMethods(lmsClass: Class<*>) {
|
||||
for (method in lmsClass.declaredMethods) {
|
||||
// 1. 拦截系统返回给客户端的最后已知位置 getLastLocation
|
||||
if (method.name == "getLastLocation") {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun afterHookedMethod(param: MethodHookParam) {
|
||||
val config = readConfigDirectly()
|
||||
if (!config.isEnabled) return
|
||||
|
||||
val pkg = extractCallingPackage(param)
|
||||
if (pkg != null && !config.shouldMock(pkg)) return
|
||||
|
||||
val loc = param.result as? Location
|
||||
if (loc != null) {
|
||||
LocationSimulator.applyMockData(loc, config.latitude, config.longitude, config.isJitterEnabled)
|
||||
} else {
|
||||
param.result = LocationSimulator.createMockLocation(
|
||||
config.latitude,
|
||||
config.longitude,
|
||||
isJitterEnabled = config.isJitterEnabled
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
// 2. 拦截系统分发定位 reportLocation
|
||||
if (method.name == "reportLocation") {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val config = readConfigDirectly()
|
||||
if (!config.isEnabled) return
|
||||
|
||||
val loc = param.args.firstOrNull { it is Location } as? Location
|
||||
if (loc != null) {
|
||||
LocationSimulator.applyMockData(loc, config.latitude, config.longitude, config.isJitterEnabled)
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Android 12/13/14+ LocationProviderManager 深度拦截
|
||||
*/
|
||||
private fun hookLocationProviderManager(classLoader: ClassLoader) {
|
||||
val lpmClasses = listOf(
|
||||
"com.android.server.location.provider.LocationProviderManager",
|
||||
"com.android.server.location.LocationProviderManager"
|
||||
)
|
||||
|
||||
for (className in lpmClasses) {
|
||||
val lpmClass = try {
|
||||
XposedHelpers.findClass(className, classLoader)
|
||||
} catch (_: Throwable) {
|
||||
null
|
||||
} ?: continue
|
||||
|
||||
for (method in lpmClass.declaredMethods) {
|
||||
if (method.name == "setLastLocation" || method.name == "onReportLocation") {
|
||||
try {
|
||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||
val config = readConfigDirectly()
|
||||
if (!config.isEnabled) return
|
||||
|
||||
val loc = param.args.firstOrNull { it is Location } as? Location
|
||||
if (loc != null) {
|
||||
LocationSimulator.applyMockData(loc, config.latitude, config.longitude, config.isJitterEnabled)
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun extractCallingPackage(param: XC_MethodHook.MethodHookParam): String? {
|
||||
for (arg in param.args) {
|
||||
if (arg is String && arg.contains(".") && !arg.contains("/")) {
|
||||
return arg
|
||||
}
|
||||
if (arg != null && arg.javaClass.name.contains("AttributionSource")) {
|
||||
try {
|
||||
val pkg = XposedHelpers.callMethod(arg, "getPackageName") as? String
|
||||
if (!pkg.isNullOrBlank()) return pkg
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package com.lzxnone.openloc.hook.util
|
||||
|
||||
import android.location.Location
|
||||
import android.location.LocationManager
|
||||
import android.os.Build
|
||||
import android.os.SystemClock
|
||||
import de.robv.android.xposed.XposedHelpers
|
||||
import kotlin.math.atan2
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sqrt
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* 虚拟位置模拟生成与洗白工具
|
||||
*/
|
||||
object LocationSimulator {
|
||||
|
||||
@Volatile
|
||||
private var driftOffsetX = 0.0 // meters (East-West)
|
||||
@Volatile
|
||||
private var driftOffsetY = 0.0 // meters (North-South)
|
||||
@Volatile
|
||||
private var lastDriftTime = 0L
|
||||
@Volatile
|
||||
private var currentBearing = 0.0f
|
||||
@Volatile
|
||||
private var currentSpeed = 0.0f
|
||||
|
||||
/**
|
||||
* 计算并获取经过自然微漂移(平滑布朗运动)后的实时坐标
|
||||
*/
|
||||
@Synchronized
|
||||
fun getSimulatedCoordinates(
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
isJitterEnabled: Boolean
|
||||
): Pair<Double, Double> {
|
||||
if (!isJitterEnabled) {
|
||||
return Pair(latitude, longitude)
|
||||
}
|
||||
|
||||
val now = SystemClock.elapsedRealtime()
|
||||
val dt = if (lastDriftTime == 0L) 1.0 else ((now - lastDriftTime).coerceIn(100L, 5000L) / 1000.0)
|
||||
lastDriftTime = now
|
||||
|
||||
// 随机步长(随时间平滑积累,约每秒 0.15~0.3m)
|
||||
val stepStdDev = 0.20 * sqrt(dt)
|
||||
val dX = (Random.nextDouble() - 0.5) * 2.0 * stepStdDev
|
||||
val dY = (Random.nextDouble() - 0.5) * 2.0 * stepStdDev
|
||||
|
||||
// 类似弹簧向中心回拉,确保长期稳定在一个极小的真实扰动圆圈内(半径约 1.5 米以内)
|
||||
val springFactor = 0.08 * dt
|
||||
driftOffsetX = (driftOffsetX + dX) * (1.0 - springFactor)
|
||||
driftOffsetY = (driftOffsetY + dY) * (1.0 - springFactor)
|
||||
|
||||
val dist = sqrt(driftOffsetX * driftOffsetX + driftOffsetY * driftOffsetY)
|
||||
val maxRadius = 1.8 // 最大漂移半径 1.8 米
|
||||
if (dist > maxRadius) {
|
||||
driftOffsetX = (driftOffsetX / dist) * maxRadius
|
||||
driftOffsetY = (driftOffsetY / dist) * maxRadius
|
||||
}
|
||||
|
||||
// 米转换为纬度与经度增量
|
||||
val metersPerLatDegree = 111132.92
|
||||
val latRad = Math.toRadians(latitude)
|
||||
val metersPerLngDegree = (111412.84 * cos(latRad)).coerceAtLeast(1.0)
|
||||
|
||||
val finalLat = latitude + (driftOffsetY / metersPerLatDegree)
|
||||
val finalLng = longitude + (driftOffsetX / metersPerLngDegree)
|
||||
|
||||
// 计算微弱的自然速度和方向
|
||||
currentSpeed = (dist * 0.04 + Random.nextDouble(0.01, 0.06)).toFloat()
|
||||
if (dist > 0.15) {
|
||||
currentBearing = ((Math.toDegrees(atan2(driftOffsetX, driftOffsetY)) + 360) % 360).toFloat()
|
||||
}
|
||||
|
||||
return Pair(finalLat, finalLng)
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成一个全新且各项指标逼真的 Location 实例
|
||||
*/
|
||||
fun createMockLocation(
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
provider: String = LocationManager.GPS_PROVIDER,
|
||||
isJitterEnabled: Boolean = true
|
||||
): Location {
|
||||
return Location(provider).apply {
|
||||
applyMockData(this, latitude, longitude, isJitterEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将虚拟数据注入到现有的 Location 实例中,并彻底抹除 Mock 标志
|
||||
*/
|
||||
fun applyMockData(
|
||||
location: Location,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
isJitterEnabled: Boolean = true
|
||||
) {
|
||||
val (finalLat, finalLng) = getSimulatedCoordinates(latitude, longitude, isJitterEnabled)
|
||||
val dist = sqrt(driftOffsetX * driftOffsetX + driftOffsetY * driftOffsetY)
|
||||
|
||||
location.latitude = finalLat
|
||||
location.longitude = finalLng
|
||||
location.altitude = if (isJitterEnabled) {
|
||||
25.0 + (driftOffsetY * 0.1) + Random.nextDouble(-0.3, 0.3)
|
||||
} else {
|
||||
25.0
|
||||
}
|
||||
location.accuracy = if (isJitterEnabled) {
|
||||
3.5f + (dist * 0.6f).toFloat() + Random.nextFloat() * 0.5f // 3.5m ~ 5.5m 真实波动
|
||||
} else {
|
||||
3.5f
|
||||
}
|
||||
location.speed = if (isJitterEnabled) currentSpeed else 0.0f
|
||||
location.bearing = if (isJitterEnabled) currentBearing else 0.0f
|
||||
location.time = System.currentTimeMillis()
|
||||
location.elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
|
||||
|
||||
// 彻底洗白:抹除系统自带的 isFromMockProvider 标志
|
||||
stripMockFlags(location)
|
||||
}
|
||||
|
||||
/**
|
||||
* 抹除 Location 对象上的所有模拟位置痕迹
|
||||
*/
|
||||
fun stripMockFlags(location: Location) {
|
||||
try {
|
||||
// Android 12 (API 31)+ 官方新增属性
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
location.isMock = false
|
||||
}
|
||||
|
||||
// 针对各版本 Android 内部 mIsFromMockProvider 字段反射清洗
|
||||
try {
|
||||
XposedHelpers.setBooleanField(location, "mIsFromMockProvider", false)
|
||||
} catch (_: Throwable) {}
|
||||
|
||||
try {
|
||||
XposedHelpers.callMethod(location, "setIsFromMockProvider", false)
|
||||
} catch (_: Throwable) {}
|
||||
|
||||
// Android 9+ (API 28)+ 内部的 mFieldsMask 标志位清洗
|
||||
try {
|
||||
val fieldsMask = XposedHelpers.getIntField(location, "mFieldsMask")
|
||||
// 清除 HAS_MOCK_PROVIDER 标志位 (通常是 0x10 或类似)
|
||||
XposedHelpers.setIntField(location, "mFieldsMask", fieldsMask and 0x10.inv())
|
||||
} catch (_: Throwable) {}
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
package com.lzxnone.openloc.hook.util
|
||||
|
||||
import android.location.GnssStatus
|
||||
import android.os.Build
|
||||
import de.robv.android.xposed.XposedHelpers
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
import kotlin.math.sin
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* 全真多星座 GNSS 虚拟卫星仿真引擎
|
||||
*
|
||||
* 1. 提供覆盖全球及中国主流芯片的多星座卫星池(GPS、北斗、GLONASS、Galileo,共 26 颗)
|
||||
* 2. 依据仰角几何球坐标动态生成符合物理传输衰减的载噪比 (C/N0, 18~42 dB-Hz) 与时变微弱抖动
|
||||
* 3. 动态构建原生系统级 GnssStatus 实例(支持 Android 11+ Builder 与反射双重兜底)
|
||||
* 4. 动态生成工业标准的 NMEA-0183 报文阵列($GNGGA, $GNRMC, $GNGSA, $BDGSA, $GPGSV, $BDGSV, $GLGSV)
|
||||
*/
|
||||
object VirtualGnssEngine {
|
||||
|
||||
data class VirtualSatellite(
|
||||
val constellationType: Int,
|
||||
val svid: Int,
|
||||
val elevation: Float,
|
||||
val azimuth: Float,
|
||||
val carrierFrequencyHz: Float,
|
||||
val usedInFix: Boolean
|
||||
)
|
||||
|
||||
// 预设全真多星座卫星池(分布在 0~360° 方位角与 10~85° 仰角的完整半球星空)
|
||||
private val SATELLITE_POOL = listOf(
|
||||
// GPS (Constellation 1) - 8 颗,6 颗参与 Fix
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GPS, 3, 68f, 120f, 1575420000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GPS, 7, 42f, 280f, 1575420000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GPS, 14, 81f, 45f, 1575420000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GPS, 16, 25f, 190f, 1575420000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GPS, 22, 14f, 330f, 1575420000f, false),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GPS, 27, 53f, 85f, 1575420000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GPS, 30, 32f, 240f, 1575420000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GPS, 31, 11f, 15f, 1575420000f, false),
|
||||
|
||||
// BDS 北斗 (Constellation 5) - 10 颗,8 颗参与 Fix (国内核心主力)
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_BEIDOU, 1, 40f, 140f, 1561098000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_BEIDOU, 6, 75f, 210f, 1561098000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_BEIDOU, 9, 58f, 60f, 1561098000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_BEIDOU, 13, 84f, 175f, 1561098000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_BEIDOU, 19, 30f, 310f, 1561098000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_BEIDOU, 21, 49f, 15f, 1561098000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_BEIDOU, 26, 63f, 105f, 1561098000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_BEIDOU, 33, 22f, 265f, 1561098000f, false),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_BEIDOU, 35, 37f, 195f, 1561098000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_BEIDOU, 37, 12f, 80f, 1561098000f, false),
|
||||
|
||||
// GLONASS (Constellation 3) - 5 颗,4 颗参与 Fix
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GLONASS, 66, 55f, 350f, 1602000000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GLONASS, 71, 70f, 135f, 1602000000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GLONASS, 74, 38f, 225f, 1602000000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GLONASS, 82, 18f, 95f, 1602000000f, false),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GLONASS, 88, 28f, 170f, 1602000000f, true),
|
||||
|
||||
// GALILEO (Constellation 6) - 3 颗,2 颗参与 Fix
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GALILEO, 4, 64f, 290f, 1575420000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GALILEO, 12, 45f, 50f, 1575420000f, true),
|
||||
VirtualSatellite(GnssStatus.CONSTELLATION_GALILEO, 19, 15f, 160f, 1575420000f, false)
|
||||
)
|
||||
|
||||
private val timeFormat = SimpleDateFormat("HHmmss.SS", Locale.US).apply {
|
||||
timeZone = TimeZone.getTimeZone("UTC")
|
||||
}
|
||||
private val dateFormat = SimpleDateFormat("ddMMyy", Locale.US).apply {
|
||||
timeZone = TimeZone.getTimeZone("UTC")
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据仰角计算符合真实物理衰减的 C/N0 载噪比(单位 dB-Hz)
|
||||
*/
|
||||
fun computeCn0(sat: VirtualSatellite): Float {
|
||||
val elevRad = Math.toRadians(sat.elevation.toDouble())
|
||||
val baseCn0 = 18.0 + 23.0 * sin(elevRad)
|
||||
val noise = (Random.nextDouble() - 0.5) * 1.5
|
||||
return (baseCn0 + noise).coerceIn(16.0, 42.5).toFloat()
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建或获取原生系统的 GnssStatus 实例
|
||||
*/
|
||||
fun createGnssStatus(): GnssStatus? {
|
||||
// 优先使用 Android 11+ (API 30+) 官方提供的 GnssStatus.Builder
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
try {
|
||||
val builder = GnssStatus.Builder()
|
||||
val addSatelliteMethod = builder.javaClass.methods.firstOrNull { it.name == "addSatellite" }
|
||||
if (addSatelliteMethod != null) {
|
||||
val paramCount = addSatelliteMethod.parameterTypes.size
|
||||
for (sat in SATELLITE_POOL) {
|
||||
val cn0 = computeCn0(sat)
|
||||
if (paramCount >= 12) {
|
||||
addSatelliteMethod.invoke(
|
||||
builder,
|
||||
sat.constellationType,
|
||||
sat.svid,
|
||||
cn0,
|
||||
sat.elevation,
|
||||
sat.azimuth,
|
||||
true, // hasEphemeris
|
||||
true, // hasAlmanac
|
||||
sat.usedInFix,
|
||||
true, // hasCarrierFrequency
|
||||
sat.carrierFrequencyHz,
|
||||
true, // hasBasebandCn0
|
||||
(cn0 - 2.0f).coerceAtLeast(10.0f) // basebandCn0
|
||||
)
|
||||
} else {
|
||||
addSatelliteMethod.invoke(
|
||||
builder,
|
||||
sat.constellationType,
|
||||
sat.svid,
|
||||
cn0,
|
||||
sat.elevation,
|
||||
sat.azimuth,
|
||||
true, // hasEphemeris
|
||||
true, // hasAlmanac
|
||||
sat.usedInFix,
|
||||
true, // hasCarrierFrequency
|
||||
sat.carrierFrequencyHz
|
||||
)
|
||||
}
|
||||
}
|
||||
return builder.build()
|
||||
}
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
|
||||
// 低版本反射兜底(构造私有构造器)
|
||||
return try {
|
||||
val count = SATELLITE_POOL.size
|
||||
val svidWithFlags = IntArray(count)
|
||||
val cn0s = FloatArray(count)
|
||||
val elevations = FloatArray(count)
|
||||
val azimuths = FloatArray(count)
|
||||
val carrierFreqs = FloatArray(count)
|
||||
|
||||
for (i in 0 until count) {
|
||||
val sat = SATELLITE_POOL[i]
|
||||
// 编码 svidWithFlags (AOSP 规范)
|
||||
var flags = (sat.constellationType and 0x0F) shl 4
|
||||
flags = flags or (sat.svid shl 8)
|
||||
flags = flags or 1 // hasEphemeris
|
||||
flags = flags or 2 // hasAlmanac
|
||||
if (sat.usedInFix) flags = flags or 4
|
||||
flags = flags or 8 // hasCarrierFrequency
|
||||
|
||||
svidWithFlags[i] = flags
|
||||
cn0s[i] = computeCn0(sat)
|
||||
elevations[i] = sat.elevation
|
||||
azimuths[i] = sat.azimuth
|
||||
carrierFreqs[i] = sat.carrierFrequencyHz
|
||||
}
|
||||
|
||||
try {
|
||||
// Android 10+ 构造函数含 carrierFrequencies
|
||||
XposedHelpers.newInstance(
|
||||
GnssStatus::class.java,
|
||||
count,
|
||||
svidWithFlags,
|
||||
cn0s,
|
||||
elevations,
|
||||
azimuths,
|
||||
carrierFreqs
|
||||
) as? GnssStatus
|
||||
} catch (_: Throwable) {
|
||||
// Android 7~9 构造函数 5 参数
|
||||
XposedHelpers.newInstance(
|
||||
GnssStatus::class.java,
|
||||
count,
|
||||
svidWithFlags,
|
||||
cn0s,
|
||||
elevations,
|
||||
azimuths
|
||||
) as? GnssStatus
|
||||
}
|
||||
} catch (_: Throwable) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成全套完整的工业级 NMEA-0183 报文序列(包含 GGA, RMC, GSA, GSV 多星座信标)
|
||||
*/
|
||||
fun generateFullNmeaSequence(lat: Double, lng: Double, time: Long): List<String> {
|
||||
val result = mutableListOf<String>()
|
||||
val utcTime = timeFormat.format(Date(time))
|
||||
val dateStr = dateFormat.format(Date(time))
|
||||
val latStr = formatToNmeaCoord(lat, true)
|
||||
val lngStr = formatToNmeaCoord(lng, false)
|
||||
|
||||
val totalUsedSats = SATELLITE_POOL.count { it.usedInFix }
|
||||
|
||||
// 1. $GNGGA 定位解数据
|
||||
val ggaContent = "GNGGA,$utcTime,$latStr,$lngStr,1,$totalUsedSats,0.8,25.0,M,0.0,M,,"
|
||||
result.add("\$$ggaContent*${calculateChecksum(ggaContent)}\r\n")
|
||||
|
||||
// 2. $GNRMC 推荐最小导航数据
|
||||
val rmcContent = "GNRMC,$utcTime,A,$latStr,$lngStr,0.0,0.0,$dateStr,,,A"
|
||||
result.add("\$$rmcContent*${calculateChecksum(rmcContent)}\r\n")
|
||||
|
||||
// 3. $GNGSA (GPS 精度因子与解算卫星)
|
||||
val gpsUsedSats = SATELLITE_POOL.filter { it.constellationType == GnssStatus.CONSTELLATION_GPS && it.usedInFix }
|
||||
val gpsPrnSlots = (0 until 12).map { index ->
|
||||
if (index < gpsUsedSats.size) String.format(Locale.US, "%02d", gpsUsedSats[index].svid) else ""
|
||||
}.joinToString(",")
|
||||
val gsaGpsContent = "GNGSA,A,3,$gpsPrnSlots,1.2,0.8,0.9,1"
|
||||
result.add("\$$gsaGpsContent*${calculateChecksum(gsaGpsContent)}\r\n")
|
||||
|
||||
// 4. $BDGSA (北斗精度因子与解算卫星)
|
||||
val bdsUsedSats = SATELLITE_POOL.filter { it.constellationType == GnssStatus.CONSTELLATION_BEIDOU && it.usedInFix }
|
||||
val bdsPrnSlots = (0 until 12).map { index ->
|
||||
if (index < bdsUsedSats.size) String.format(Locale.US, "%02d", bdsUsedSats[index].svid) else ""
|
||||
}.joinToString(",")
|
||||
val gsaBdsContent = "BDGSA,A,3,$bdsPrnSlots,1.2,0.8,0.9,4"
|
||||
result.add("\$$gsaBdsContent*${calculateChecksum(gsaBdsContent)}\r\n")
|
||||
|
||||
// 5. $GPGSV (GPS 可见卫星星标,每页至多 4 颗)
|
||||
val gpsSats = SATELLITE_POOL.filter { it.constellationType == GnssStatus.CONSTELLATION_GPS }
|
||||
appendGsvSentences("GPGSV", gpsSats, result)
|
||||
|
||||
// 6. $BDGSV (北斗可见卫星星标,每页至多 4 颗)
|
||||
val bdsSats = SATELLITE_POOL.filter { it.constellationType == GnssStatus.CONSTELLATION_BEIDOU }
|
||||
appendGsvSentences("BDGSV", bdsSats, result)
|
||||
|
||||
// 7. $GLGSV (GLONASS 可见卫星星标,每页至多 4 颗)
|
||||
val gloSats = SATELLITE_POOL.filter { it.constellationType == GnssStatus.CONSTELLATION_GLONASS }
|
||||
appendGsvSentences("GLGSV", gloSats, result)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
private fun appendGsvSentences(talker: String, sats: List<VirtualSatellite>, target: MutableList<String>) {
|
||||
val totalSats = sats.size
|
||||
val totalPages = (totalSats + 3) / 4
|
||||
for (page in 1..totalPages) {
|
||||
val chunk = sats.drop((page - 1) * 4).take(4)
|
||||
val sb = java.lang.StringBuilder("$talker,$totalPages,$page,$totalSats")
|
||||
for (s in chunk) {
|
||||
val cn0 = computeCn0(s).toInt()
|
||||
sb.append(String.format(Locale.US, ",%02d,%02d,%03d,%02d", s.svid, s.elevation.toInt(), s.azimuth.toInt(), cn0))
|
||||
}
|
||||
sb.append(",1") // 信号 ID (L1/B1)
|
||||
val content = sb.toString()
|
||||
target.add("\$$content*${calculateChecksum(content)}\r\n")
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatToNmeaCoord(coord: Double, isLat: Boolean): String {
|
||||
val abs = Math.abs(coord)
|
||||
val degrees = abs.toInt()
|
||||
val minutes = (abs - degrees) * 60.0
|
||||
val direction = if (isLat) {
|
||||
if (coord >= 0) "N" else "S"
|
||||
} else {
|
||||
if (coord >= 0) "E" else "W"
|
||||
}
|
||||
val coordFormat = if (isLat) "%02d%07.4f" else "%03d%07.4f"
|
||||
return String.format(Locale.US, "$coordFormat,$direction", degrees, minutes)
|
||||
}
|
||||
|
||||
private fun calculateChecksum(sentence: String): String {
|
||||
var sum = 0
|
||||
for (ch in sentence) {
|
||||
sum = sum xor ch.code
|
||||
}
|
||||
return String.format(Locale.US, "%02X", sum)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.lzxnone.openloc.ui.components
|
||||
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.NavigationBar
|
||||
import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.NavigationBarItemDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import com.lzxnone.openloc.ui.navigation.NavTab
|
||||
|
||||
/**
|
||||
* 底部导航栏组件 (Material 3 NavigationBar)
|
||||
*/
|
||||
@Composable
|
||||
fun OpenLocBottomBar(
|
||||
currentTab: NavTab,
|
||||
onTabSelected: (NavTab) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
NavigationBar(
|
||||
modifier = modifier,
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
contentColor = MaterialTheme.colorScheme.onSurface
|
||||
) {
|
||||
NavTab.entries.forEach { tab ->
|
||||
val isSelected = currentTab == tab
|
||||
NavigationBarItem(
|
||||
selected = isSelected,
|
||||
onClick = { onTabSelected(tab) },
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = if (isSelected) tab.selectedIcon else tab.unselectedIcon,
|
||||
contentDescription = stringResource(id = tab.titleRes)
|
||||
)
|
||||
},
|
||||
label = {
|
||||
Text(
|
||||
text = stringResource(id = tab.titleRes),
|
||||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal
|
||||
)
|
||||
},
|
||||
colors = NavigationBarItemDefaults.colors(
|
||||
indicatorColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
selectedIconColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
selectedTextColor = MaterialTheme.colorScheme.primary,
|
||||
unselectedIconColor = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
unselectedTextColor = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.lzxnone.openloc.ui.components
|
||||
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import com.lzxnone.openloc.R
|
||||
|
||||
/**
|
||||
* 统一顶部标题栏 (Material 3)
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun OpenLocTopBar(
|
||||
title: String = stringResource(id = R.string.app_name),
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleLarge.copy(
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
)
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.background,
|
||||
titleContentColor = MaterialTheme.colorScheme.onBackground
|
||||
),
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.lzxnone.openloc.ui.navigation
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material.icons.filled.Place
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.outlined.Home
|
||||
import androidx.compose.material.icons.outlined.Place
|
||||
import androidx.compose.material.icons.outlined.Settings
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import com.lzxnone.openloc.R
|
||||
|
||||
/**
|
||||
* 底部导航栏选项定义
|
||||
*/
|
||||
enum class NavTab(
|
||||
@param:StringRes val titleRes: Int,
|
||||
val selectedIcon: ImageVector,
|
||||
val unselectedIcon: ImageVector
|
||||
) {
|
||||
HOME(
|
||||
titleRes = R.string.nav_home,
|
||||
selectedIcon = Icons.Filled.Home,
|
||||
unselectedIcon = Icons.Outlined.Home
|
||||
),
|
||||
LOCATION(
|
||||
titleRes = R.string.nav_location,
|
||||
selectedIcon = Icons.Filled.Place,
|
||||
unselectedIcon = Icons.Outlined.Place
|
||||
),
|
||||
SETTINGS(
|
||||
titleRes = R.string.nav_settings,
|
||||
selectedIcon = Icons.Filled.Settings,
|
||||
unselectedIcon = Icons.Outlined.Settings
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.lzxnone.openloc.ui.screens
|
||||
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.togetherWith
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.lzxnone.openloc.core.util.HookStatus
|
||||
import com.lzxnone.openloc.data.preference.AppPreferences
|
||||
import com.lzxnone.openloc.ui.components.OpenLocBottomBar
|
||||
import com.lzxnone.openloc.ui.components.OpenLocTopBar
|
||||
import com.lzxnone.openloc.ui.navigation.NavTab
|
||||
import com.lzxnone.openloc.ui.screens.home.HomeScreen
|
||||
import com.lzxnone.openloc.ui.screens.location.LocationScreen
|
||||
import com.lzxnone.openloc.ui.screens.settings.SettingsScreen
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.slideInHorizontally
|
||||
import androidx.compose.animation.slideOutHorizontally
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import com.lzxnone.openloc.data.preference.AppMockMode
|
||||
import com.lzxnone.openloc.ui.screens.apps.AppSelectionScreen
|
||||
|
||||
/**
|
||||
* 根容器页面:承载 TopAppBar、底部导航栏与各个 Tab 内容切换
|
||||
*/
|
||||
@Composable
|
||||
fun MainScreen(
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var currentTab by rememberSaveable { mutableStateOf(NavTab.HOME) }
|
||||
var activeAppSelectionMode by rememberSaveable { mutableStateOf<AppMockMode?>(null) }
|
||||
|
||||
// 响应式的总开关状态与激活状态
|
||||
val isServiceEnabled = AppPreferences.isServiceEnabled
|
||||
val isModuleActive = remember { HookStatus.isModuleActive() }
|
||||
|
||||
Box(modifier = modifier.fillMaxSize()) {
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||
topBar = {
|
||||
if (currentTab != NavTab.LOCATION) {
|
||||
OpenLocTopBar()
|
||||
}
|
||||
},
|
||||
bottomBar = {
|
||||
OpenLocBottomBar(
|
||||
currentTab = currentTab,
|
||||
onTabSelected = { currentTab = it }
|
||||
)
|
||||
}
|
||||
) { innerPadding ->
|
||||
AnimatedContent(
|
||||
targetState = currentTab,
|
||||
transitionSpec = {
|
||||
fadeIn() togetherWith fadeOut()
|
||||
},
|
||||
label = "TabContentAnimation",
|
||||
modifier = Modifier.padding(innerPadding)
|
||||
) { targetTab ->
|
||||
when (targetTab) {
|
||||
NavTab.HOME -> HomeScreen(
|
||||
isModuleActive = isModuleActive,
|
||||
isServiceEnabled = isServiceEnabled,
|
||||
onServiceEnabledChange = { enabled ->
|
||||
AppPreferences.updateServiceEnabled(enabled)
|
||||
},
|
||||
onOpenBlacklist = { activeAppSelectionMode = AppMockMode.BLACKLIST },
|
||||
onOpenWhitelist = { activeAppSelectionMode = AppMockMode.WHITELIST }
|
||||
)
|
||||
NavTab.LOCATION -> LocationScreen()
|
||||
NavTab.SETTINGS -> SettingsScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 应用选择全屏浮层(黑名单 / 白名单独立管理)
|
||||
AnimatedVisibility(
|
||||
visible = activeAppSelectionMode != null,
|
||||
enter = slideInHorizontally(initialOffsetX = { it }) + fadeIn(),
|
||||
exit = slideOutHorizontally(targetOffsetX = { it }) + fadeOut(),
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
activeAppSelectionMode?.let { mode ->
|
||||
AppSelectionScreen(
|
||||
mode = mode,
|
||||
onNavigateBack = { activeAppSelectionMode = null }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,504 @@
|
||||
package com.lzxnone.openloc.ui.screens.apps
|
||||
|
||||
import android.content.pm.ApplicationInfo
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material.icons.outlined.Android
|
||||
import androidx.compose.material.icons.outlined.Deselect
|
||||
import androidx.compose.material.icons.outlined.FilterList
|
||||
import androidx.compose.material.icons.outlined.SelectAll
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FilterChip
|
||||
import androidx.compose.material3.FilterChipDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.OutlinedTextFieldDefaults
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.lzxnone.openloc.R
|
||||
import com.lzxnone.openloc.data.preference.AppMockMode
|
||||
import com.lzxnone.openloc.data.preference.AppPreferences
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* 已安装应用数据模型
|
||||
*/
|
||||
data class InstalledAppItem(
|
||||
val packageName: String,
|
||||
val appName: String,
|
||||
val isSystemApp: Boolean,
|
||||
val iconBitmap: ImageBitmap? = null
|
||||
)
|
||||
|
||||
/**
|
||||
* 黑名单 / 白名单应用勾选管理页面
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AppSelectionScreen(
|
||||
mode: AppMockMode,
|
||||
onNavigateBack: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var searchQuery by remember { mutableStateOf("") }
|
||||
var showSystemApps by remember { mutableStateOf(false) }
|
||||
|
||||
var installedApps by remember { mutableStateOf<List<InstalledAppItem>>(emptyList()) }
|
||||
var isLoading by remember { mutableStateOf(true) }
|
||||
|
||||
// 拦截返回按键
|
||||
BackHandler(onBack = onNavigateBack)
|
||||
|
||||
// 异步加载所有已安装应用及其图标
|
||||
LaunchedEffect(Unit) {
|
||||
withContext(Dispatchers.IO) {
|
||||
val pm = context.packageManager
|
||||
val packages = pm.getInstalledPackages(0)
|
||||
val list = ArrayList<InstalledAppItem>(packages.size)
|
||||
|
||||
for (pkg in packages) {
|
||||
val appInfo = pkg.applicationInfo ?: continue
|
||||
// 排除本应用自身
|
||||
if (pkg.packageName == context.packageName) continue
|
||||
|
||||
val appName = appInfo.loadLabel(pm).toString()
|
||||
val isSystem = (appInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0
|
||||
|
||||
val iconBitmap = try {
|
||||
val iconDrawable = appInfo.loadIcon(pm)
|
||||
iconDrawable.toBitmap(96, 96).asImageBitmap()
|
||||
} catch (_: Throwable) {
|
||||
null
|
||||
}
|
||||
|
||||
list.add(
|
||||
InstalledAppItem(
|
||||
packageName = pkg.packageName,
|
||||
appName = appName,
|
||||
isSystemApp = isSystem,
|
||||
iconBitmap = iconBitmap
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// 用户应用排在前面,系统应用排在后面;组内按应用名称字母排序
|
||||
list.sortWith(
|
||||
compareBy<InstalledAppItem> { it.isSystemApp }
|
||||
.thenBy { it.appName.lowercase(Locale.ROOT) }
|
||||
)
|
||||
|
||||
installedApps = list
|
||||
isLoading = false
|
||||
}
|
||||
}
|
||||
|
||||
// 关联当前名单选中的包名集合
|
||||
val selectedPackages = if (mode == AppMockMode.BLACKLIST) {
|
||||
AppPreferences.blacklistApps
|
||||
} else {
|
||||
AppPreferences.whitelistApps
|
||||
}
|
||||
|
||||
// 根据搜索词和系统应用开关进行过滤
|
||||
val filteredApps = remember(installedApps, searchQuery, showSystemApps) {
|
||||
installedApps.filter { app ->
|
||||
(showSystemApps || !app.isSystemApp) &&
|
||||
(searchQuery.isBlank() ||
|
||||
app.appName.contains(searchQuery, ignoreCase = true) ||
|
||||
app.packageName.contains(searchQuery, ignoreCase = true))
|
||||
}
|
||||
}
|
||||
|
||||
// 标题与说明
|
||||
val titleText = if (mode == AppMockMode.BLACKLIST) {
|
||||
stringResource(id = R.string.apps_blacklist_title)
|
||||
} else {
|
||||
stringResource(id = R.string.apps_whitelist_title)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = modifier.fillMaxSize(),
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Column {
|
||||
Text(
|
||||
text = titleText,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
style = MaterialTheme.typography.titleLarge
|
||||
)
|
||||
Text(
|
||||
text = stringResource(
|
||||
id = R.string.apps_selected_count,
|
||||
selectedPackages.size,
|
||||
installedApps.size
|
||||
),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onNavigateBack) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.location_search_back)
|
||||
)
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
// 全选 / 全不选按钮
|
||||
val allVisibleSelected = filteredApps.isNotEmpty() &&
|
||||
filteredApps.all { selectedPackages.contains(it.packageName) }
|
||||
|
||||
IconButton(
|
||||
onClick = {
|
||||
if (allVisibleSelected) {
|
||||
// 取消当前可见的所有选中
|
||||
val visiblePackageSet = filteredApps.map { it.packageName }.toSet()
|
||||
val updated = selectedPackages - visiblePackageSet
|
||||
if (mode == AppMockMode.BLACKLIST) {
|
||||
AppPreferences.updateBlacklistApps(updated)
|
||||
} else {
|
||||
AppPreferences.updateWhitelistApps(updated)
|
||||
}
|
||||
} else {
|
||||
// 选中当前可见的所有应用
|
||||
val visiblePackageSet = filteredApps.map { it.packageName }.toSet()
|
||||
val updated = selectedPackages + visiblePackageSet
|
||||
if (mode == AppMockMode.BLACKLIST) {
|
||||
AppPreferences.updateBlacklistApps(updated)
|
||||
} else {
|
||||
AppPreferences.updateWhitelistApps(updated)
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = if (allVisibleSelected) Icons.Outlined.Deselect else Icons.Outlined.SelectAll,
|
||||
contentDescription = stringResource(
|
||||
id = if (allVisibleSelected) R.string.apps_deselect_all else R.string.apps_select_all
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
titleContentColor = MaterialTheme.colorScheme.onSurface,
|
||||
navigationIconContentColor = MaterialTheme.colorScheme.onSurface,
|
||||
actionIconContentColor = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
)
|
||||
}
|
||||
) { innerPadding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(innerPadding)
|
||||
) {
|
||||
// 搜索栏与系统应用开关
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 6.dp)
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = searchQuery,
|
||||
onValueChange = { searchQuery = it },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
placeholder = {
|
||||
Text(
|
||||
text = stringResource(id = R.string.apps_search_hint),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
},
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.Search,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
if (searchQuery.isNotEmpty()) {
|
||||
IconButton(onClick = { searchQuery = "" }) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.Close,
|
||||
contentDescription = stringResource(id = R.string.location_search_clear),
|
||||
modifier = Modifier.size(18.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
singleLine = true,
|
||||
colors = OutlinedTextFieldDefaults.colors(
|
||||
focusedContainerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.35f),
|
||||
unfocusedContainerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.2f),
|
||||
focusedBorderColor = MaterialTheme.colorScheme.primary,
|
||||
unfocusedBorderColor = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(6.dp))
|
||||
|
||||
// 筛选过滤 Chips
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.End,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
FilterChip(
|
||||
selected = showSystemApps,
|
||||
onClick = { showSystemApps = !showSystemApps },
|
||||
label = {
|
||||
Text(
|
||||
text = stringResource(
|
||||
id = if (showSystemApps) R.string.apps_hide_system_apps else R.string.apps_show_system_apps
|
||||
),
|
||||
style = MaterialTheme.typography.labelSmall
|
||||
)
|
||||
},
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.FilterList,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
},
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
colors = FilterChipDefaults.filterChipColors(
|
||||
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.6f)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 应用列表展示
|
||||
if (isLoading) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(32.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
CircularProgressIndicator(modifier = Modifier.size(36.dp))
|
||||
Text(
|
||||
text = stringResource(id = R.string.apps_loading),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
} else if (filteredApps.isEmpty()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(32.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = if (searchQuery.isNotEmpty()) {
|
||||
stringResource(id = R.string.apps_empty_search)
|
||||
} else {
|
||||
stringResource(id = R.string.apps_empty_installed)
|
||||
},
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
} else {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 6.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
items(filteredApps, key = { it.packageName }) { app ->
|
||||
val isChecked = selectedPackages.contains(app.packageName)
|
||||
AppItemCard(
|
||||
app = app,
|
||||
isChecked = isChecked,
|
||||
onToggle = {
|
||||
if (mode == AppMockMode.BLACKLIST) {
|
||||
AppPreferences.toggleBlacklistApp(app.packageName)
|
||||
} else {
|
||||
AppPreferences.toggleWhitelistApp(app.packageName)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个应用卡片条目
|
||||
*/
|
||||
@Composable
|
||||
private fun AppItemCard(
|
||||
app: InstalledAppItem,
|
||||
isChecked: Boolean,
|
||||
onToggle: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Card(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clickable(onClick = onToggle),
|
||||
shape = RoundedCornerShape(14.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = if (isChecked) {
|
||||
MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.45f)
|
||||
} else {
|
||||
MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.35f)
|
||||
}
|
||||
),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 0.dp)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 14.dp, vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// 应用图标
|
||||
if (app.iconBitmap != null) {
|
||||
Image(
|
||||
bitmap = app.iconBitmap,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(42.dp)
|
||||
)
|
||||
} else {
|
||||
Surface(
|
||||
shape = CircleShape,
|
||||
color = MaterialTheme.colorScheme.surfaceVariant,
|
||||
modifier = Modifier.size(42.dp)
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Android,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(14.dp))
|
||||
|
||||
// 名称与包名
|
||||
Column(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
Text(
|
||||
text = app.appName,
|
||||
style = MaterialTheme.typography.bodyLarge.copy(
|
||||
fontWeight = FontWeight.SemiBold
|
||||
),
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f, fill = false)
|
||||
)
|
||||
|
||||
if (app.isSystemApp) {
|
||||
Surface(
|
||||
shape = RoundedCornerShape(4.dp),
|
||||
color = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.7f)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.apps_system_app_tag),
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||
modifier = Modifier.padding(horizontal = 5.dp, vertical = 1.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
|
||||
Text(
|
||||
text = app.packageName,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
|
||||
// 复选框
|
||||
Checkbox(
|
||||
checked = isChecked,
|
||||
onCheckedChange = { onToggle() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,714 @@
|
||||
package com.lzxnone.openloc.ui.screens.favorites
|
||||
|
||||
import android.widget.Toast
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.detectDragGestures
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.BookmarkBorder
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.DeleteOutline
|
||||
import androidx.compose.material.icons.filled.DragHandle
|
||||
import androidx.compose.material.icons.filled.LocationOn
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.OutlinedTextFieldDefaults
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.zIndex
|
||||
import com.lzxnone.openloc.LocalizedDialogContent
|
||||
import com.lzxnone.openloc.R
|
||||
import com.lzxnone.openloc.core.util.LocationResolver
|
||||
import com.lzxnone.openloc.data.model.FavoriteItem
|
||||
import com.lzxnone.openloc.data.preference.AppPreferences
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* 收藏列表拖拽排序状态管理
|
||||
*/
|
||||
class FavoriteDragDropState(
|
||||
val lazyListState: LazyListState,
|
||||
val getItems: () -> List<FavoriteItem>,
|
||||
val onMove: (Int, Int) -> Unit
|
||||
) {
|
||||
var draggingItemId by mutableStateOf<String?>(null)
|
||||
var dragDeltaY by mutableStateOf(0f)
|
||||
|
||||
fun onDragStart(id: String) {
|
||||
draggingItemId = id
|
||||
dragDeltaY = 0f
|
||||
}
|
||||
|
||||
fun onDrag(delta: Float) {
|
||||
val currentId = draggingItemId ?: return
|
||||
dragDeltaY += delta
|
||||
|
||||
val items = getItems()
|
||||
val currentIndex = items.indexOfFirst { it.id == currentId }
|
||||
if (currentIndex == -1) return
|
||||
|
||||
val visibleItems = lazyListState.layoutInfo.visibleItemsInfo
|
||||
val currentItemInfo = visibleItems.firstOrNull { it.key == currentId } ?: return
|
||||
val currentItemMiddle = currentItemInfo.offset + currentItemInfo.size / 2 + dragDeltaY
|
||||
|
||||
val targetItem = visibleItems.firstOrNull { item ->
|
||||
item.key != currentId &&
|
||||
currentItemMiddle in item.offset.toFloat()..(item.offset + item.size).toFloat()
|
||||
}
|
||||
|
||||
if (targetItem != null) {
|
||||
val targetIndex = items.indexOfFirst { it.id == targetItem.key }
|
||||
if (targetIndex != -1 && targetIndex != currentIndex) {
|
||||
onMove(currentIndex, targetIndex)
|
||||
dragDeltaY += (currentItemInfo.offset - targetItem.offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onDragEnd() {
|
||||
draggingItemId = null
|
||||
dragDeltaY = 0f
|
||||
}
|
||||
|
||||
fun onDragCancel() {
|
||||
draggingItemId = null
|
||||
dragDeltaY = 0f
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 收藏夹页面
|
||||
* 包含搜索栏、条目列表(支持拖拽排序)以及添加新地址 Dialog
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun FavoritesScreen(
|
||||
currentWgsLat: Double,
|
||||
currentWgsLng: Double,
|
||||
currentAddress: String,
|
||||
onNavigateBack: () -> Unit,
|
||||
onSelectFavorite: (FavoriteItem) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var searchQuery by remember { mutableStateOf("") }
|
||||
var showAddDialog by remember { mutableStateOf(false) }
|
||||
var itemToDelete by remember { mutableStateOf<FavoriteItem?>(null) }
|
||||
|
||||
val lazyListState = rememberLazyListState()
|
||||
val dragDropState = remember(lazyListState) {
|
||||
FavoriteDragDropState(
|
||||
lazyListState = lazyListState,
|
||||
getItems = { AppPreferences.favorites },
|
||||
onMove = { from, to ->
|
||||
AppPreferences.moveFavorite(from, to)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// 系统返回拦截
|
||||
BackHandler(onBack = onNavigateBack)
|
||||
|
||||
Scaffold(
|
||||
modifier = modifier.fillMaxSize(),
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(id = R.string.favorites_title),
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onNavigateBack) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.action_cancel)
|
||||
)
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = { showAddDialog = true }) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.Add,
|
||||
contentDescription = stringResource(id = R.string.favorite_add_title)
|
||||
)
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
titleContentColor = MaterialTheme.colorScheme.onSurface,
|
||||
navigationIconContentColor = MaterialTheme.colorScheme.onSurface,
|
||||
actionIconContentColor = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
)
|
||||
}
|
||||
) { innerPadding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(innerPadding)
|
||||
) {
|
||||
// 搜索栏
|
||||
OutlinedTextField(
|
||||
value = searchQuery,
|
||||
onValueChange = { searchQuery = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
placeholder = {
|
||||
Text(
|
||||
text = stringResource(id = R.string.favorite_search_hint),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
},
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.Search,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
if (searchQuery.isNotEmpty()) {
|
||||
IconButton(onClick = { searchQuery = "" }) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.Close,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(18.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
singleLine = true,
|
||||
colors = OutlinedTextFieldDefaults.colors(
|
||||
focusedContainerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.35f),
|
||||
unfocusedContainerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.2f),
|
||||
focusedBorderColor = MaterialTheme.colorScheme.primary,
|
||||
unfocusedBorderColor = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
)
|
||||
|
||||
// 过滤收藏列表
|
||||
val allFavorites = AppPreferences.favorites
|
||||
val filteredFavorites = remember(searchQuery, allFavorites) {
|
||||
if (searchQuery.isBlank()) {
|
||||
allFavorites
|
||||
} else {
|
||||
allFavorites.filter { item ->
|
||||
item.name.contains(searchQuery, ignoreCase = true) ||
|
||||
item.address.contains(searchQuery, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allFavorites.isEmpty()) {
|
||||
// 无收藏数据时空状态提示
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(32.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Surface(
|
||||
shape = CircleShape,
|
||||
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.5f),
|
||||
modifier = Modifier.size(72.dp)
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.BookmarkBorder,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(36.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
Text(
|
||||
text = stringResource(id = R.string.favorite_empty_list),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
} else if (filteredFavorites.isEmpty()) {
|
||||
// 搜索无结果
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(32.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.favorite_search_empty),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// 列表区域(支持拖动排序)
|
||||
LazyColumn(
|
||||
state = lazyListState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp)
|
||||
) {
|
||||
items(filteredFavorites, key = { it.id }) { item ->
|
||||
val isDragging = dragDropState.draggingItemId == item.id
|
||||
FavoriteItemCard(
|
||||
item = item,
|
||||
isDragging = isDragging,
|
||||
dragDeltaY = if (isDragging) dragDropState.dragDeltaY else 0f,
|
||||
showDragHandle = searchQuery.isBlank(),
|
||||
onDragStart = { dragDropState.onDragStart(item.id) },
|
||||
onDrag = { dragDropState.onDrag(it) },
|
||||
onDragEnd = { dragDropState.onDragEnd() },
|
||||
onDragCancel = { dragDropState.onDragCancel() },
|
||||
onClick = { onSelectFavorite(item) },
|
||||
onDelete = { itemToDelete = item },
|
||||
modifier = if (isDragging) Modifier else Modifier.animateItem()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 新增收藏 Dialog
|
||||
if (showAddDialog) {
|
||||
AddFavoriteDialog(
|
||||
initialLat = currentWgsLat,
|
||||
initialLng = currentWgsLng,
|
||||
initialAddress = currentAddress,
|
||||
onDismiss = { showAddDialog = false },
|
||||
onConfirm = { newItem ->
|
||||
AppPreferences.addFavorite(newItem)
|
||||
Toast.makeText(context, context.getString(R.string.favorite_added_success), Toast.LENGTH_SHORT).show()
|
||||
showAddDialog = false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// 删除确认 Dialog
|
||||
itemToDelete?.let { item ->
|
||||
AlertDialog(
|
||||
onDismissRequest = { itemToDelete = null },
|
||||
title = {
|
||||
Text(text = stringResource(id = R.string.favorite_delete_confirm_title))
|
||||
},
|
||||
text = {
|
||||
Text(text = stringResource(id = R.string.favorite_delete_confirm_msg, item.name))
|
||||
},
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = {
|
||||
AppPreferences.removeFavorite(item.id)
|
||||
Toast.makeText(context, context.getString(R.string.favorite_deleted_success), Toast.LENGTH_SHORT).show()
|
||||
itemToDelete = null
|
||||
}
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.favorite_delete))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { itemToDelete = null }) {
|
||||
Text(text = stringResource(id = R.string.action_cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单条收藏条目卡片
|
||||
* 支持拖动排序手柄与点击选定
|
||||
*/
|
||||
@Composable
|
||||
private fun FavoriteItemCard(
|
||||
item: FavoriteItem,
|
||||
isDragging: Boolean,
|
||||
dragDeltaY: Float,
|
||||
showDragHandle: Boolean,
|
||||
onDragStart: () -> Unit,
|
||||
onDrag: (Float) -> Unit,
|
||||
onDragEnd: () -> Unit,
|
||||
onDragCancel: () -> Unit,
|
||||
onClick: () -> Unit,
|
||||
onDelete: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val currentOnDragStart by rememberUpdatedState(onDragStart)
|
||||
val currentOnDrag by rememberUpdatedState(onDrag)
|
||||
val currentOnDragEnd by rememberUpdatedState(onDragEnd)
|
||||
val currentOnDragCancel by rememberUpdatedState(onDragCancel)
|
||||
|
||||
Card(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.zIndex(if (isDragging) 2f else 0f)
|
||||
.graphicsLayer {
|
||||
translationY = if (isDragging) dragDeltaY else 0f
|
||||
shadowElevation = if (isDragging) 24f else 0f
|
||||
scaleX = if (isDragging) 1.02f else 1f
|
||||
scaleY = if (isDragging) 1.02f else 1f
|
||||
}
|
||||
.clickable(enabled = !isDragging, onClick = onClick),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = if (isDragging) {
|
||||
MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.55f)
|
||||
} else {
|
||||
MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.45f)
|
||||
}
|
||||
),
|
||||
elevation = CardDefaults.cardElevation(
|
||||
defaultElevation = if (isDragging) 8.dp else 0.dp
|
||||
)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(14.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Surface(
|
||||
shape = CircleShape,
|
||||
color = MaterialTheme.colorScheme.primaryContainer,
|
||||
modifier = Modifier.size(42.dp)
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.LocationOn,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
modifier = Modifier.size(22.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(14.dp))
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
// 名称
|
||||
Text(
|
||||
text = item.name,
|
||||
style = MaterialTheme.typography.titleMedium.copy(
|
||||
fontWeight = FontWeight.Bold
|
||||
),
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
|
||||
// 地区名称小字
|
||||
Text(
|
||||
text = item.address.ifEmpty { stringResource(id = R.string.location_unknown_address) },
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(3.dp))
|
||||
|
||||
// 经纬度小字
|
||||
Text(
|
||||
text = "${stringResource(id = R.string.location_latitude_format, item.latitude)} ${stringResource(id = R.string.location_longitude_format, item.longitude)}",
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
}
|
||||
|
||||
// 删除按钮
|
||||
IconButton(
|
||||
onClick = onDelete,
|
||||
modifier = Modifier.size(36.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.DeleteOutline,
|
||||
contentDescription = stringResource(id = R.string.favorite_delete),
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
|
||||
// 拖动手柄 (仅在未进行搜索过滤时显示)
|
||||
if (showDragHandle) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(40.dp)
|
||||
.pointerInput(Unit) {
|
||||
detectDragGestures(
|
||||
onDragStart = { currentOnDragStart() },
|
||||
onDrag = { change, dragAmount ->
|
||||
change.consume()
|
||||
currentOnDrag(dragAmount.y)
|
||||
},
|
||||
onDragEnd = { currentOnDragEnd() },
|
||||
onDragCancel = { currentOnDragCancel() }
|
||||
)
|
||||
},
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.DragHandle,
|
||||
contentDescription = stringResource(id = R.string.favorite_drag_handle),
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增地址 Dialog
|
||||
* 默认填入当前地图坐标与地区名称
|
||||
* 名称默认与地区名称相同
|
||||
* 地区名称彻底禁用,经纬度修改时自动推导地区名称与同步默认名称
|
||||
*/
|
||||
@Composable
|
||||
private fun AddFavoriteDialog(
|
||||
initialLat: Double,
|
||||
initialLng: Double,
|
||||
initialAddress: String,
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: (FavoriteItem) -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
// 默认名称与地区名称相同
|
||||
var name by remember { mutableStateOf(initialAddress) }
|
||||
var latText by remember { mutableStateOf(String.format(Locale.US, "%.6f", initialLat)) }
|
||||
var lngText by remember { mutableStateOf(String.format(Locale.US, "%.6f", initialLng)) }
|
||||
var address by remember { mutableStateOf(initialAddress) }
|
||||
var isResolvingAddress by remember { mutableStateOf(false) }
|
||||
var resolveJob by remember { mutableStateOf<Job?>(null) }
|
||||
var errorMessage by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
// 经纬度变化时,防抖 500ms 自动推导地区名称
|
||||
fun triggerAddressResolve() {
|
||||
val lat = latText.toDoubleOrNull()
|
||||
val lng = lngText.toDoubleOrNull()
|
||||
if (lat != null && lng != null && lat in -90.0..90.0 && lng in -180.0..180.0) {
|
||||
errorMessage = null
|
||||
resolveJob?.cancel()
|
||||
val oldAddress = address
|
||||
resolveJob = coroutineScope.launch {
|
||||
delay(500)
|
||||
isResolvingAddress = true
|
||||
val resolved = LocationResolver.resolveLocationName(context, lat, lng)
|
||||
val resolvedAddr = resolved.ifBlank { context.getString(R.string.location_unknown_address) }
|
||||
// 如果用户尚未手动修改名称,或名称仍为旧推导地名,则随之更新默认名称
|
||||
if (name.isBlank() || name == oldAddress) {
|
||||
name = resolvedAddr
|
||||
}
|
||||
address = resolvedAddr
|
||||
isResolvingAddress = false
|
||||
}
|
||||
} else {
|
||||
errorMessage = context.getString(R.string.favorite_invalid_coords)
|
||||
}
|
||||
}
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = {
|
||||
LocalizedDialogContent {
|
||||
Text(
|
||||
text = stringResource(id = R.string.favorite_add_title),
|
||||
style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Bold)
|
||||
)
|
||||
}
|
||||
},
|
||||
text = {
|
||||
LocalizedDialogContent {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
// 名称输入 (默认与地区名称相同)
|
||||
OutlinedTextField(
|
||||
value = name,
|
||||
onValueChange = {
|
||||
name = it
|
||||
if (errorMessage != null) errorMessage = null
|
||||
},
|
||||
label = { Text(text = stringResource(id = R.string.favorite_name_label)) },
|
||||
placeholder = { Text(text = stringResource(id = R.string.favorite_name_hint)) },
|
||||
singleLine = true,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
|
||||
// 地区名称 (禁用不可修改,由经纬度自动推导)
|
||||
OutlinedTextField(
|
||||
value = if (isResolvingAddress) stringResource(id = R.string.favorite_address_deriving) else address,
|
||||
onValueChange = {},
|
||||
label = { Text(text = stringResource(id = R.string.favorite_address_label)) },
|
||||
enabled = false,
|
||||
singleLine = false,
|
||||
maxLines = 3,
|
||||
trailingIcon = {
|
||||
if (isResolvingAddress) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(18.dp),
|
||||
strokeWidth = 2.dp
|
||||
)
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
colors = OutlinedTextFieldDefaults.colors(
|
||||
disabledTextColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.7f),
|
||||
disabledLabelColor = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f),
|
||||
disabledBorderColor = MaterialTheme.colorScheme.outline.copy(alpha = 0.3f),
|
||||
disabledContainerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.25f)
|
||||
)
|
||||
)
|
||||
|
||||
// 纬度与经度输入
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = latText,
|
||||
onValueChange = {
|
||||
latText = it
|
||||
triggerAddressResolve()
|
||||
},
|
||||
label = { Text(text = stringResource(id = R.string.favorite_latitude_label)) },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),
|
||||
singleLine = true,
|
||||
modifier = Modifier.weight(1f),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
|
||||
OutlinedTextField(
|
||||
value = lngText,
|
||||
onValueChange = {
|
||||
lngText = it
|
||||
triggerAddressResolve()
|
||||
},
|
||||
label = { Text(text = stringResource(id = R.string.favorite_longitude_label)) },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),
|
||||
singleLine = true,
|
||||
modifier = Modifier.weight(1f),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
}
|
||||
|
||||
// 错误提示
|
||||
if (errorMessage != null) {
|
||||
Text(
|
||||
text = errorMessage ?: "",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.error
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
LocalizedDialogContent {
|
||||
Button(
|
||||
onClick = {
|
||||
val trimmedName = name.trim()
|
||||
val lat = latText.toDoubleOrNull()
|
||||
val lng = lngText.toDoubleOrNull()
|
||||
|
||||
if (trimmedName.isEmpty()) {
|
||||
errorMessage = context.getString(R.string.favorite_invalid_name)
|
||||
return@Button
|
||||
}
|
||||
if (lat == null || lng == null || lat !in -90.0..90.0 || lng !in -180.0..180.0) {
|
||||
errorMessage = context.getString(R.string.favorite_invalid_coords)
|
||||
return@Button
|
||||
}
|
||||
|
||||
onConfirm(
|
||||
FavoriteItem(
|
||||
name = trimmedName,
|
||||
address = address.trim(),
|
||||
latitude = lat,
|
||||
longitude = lng
|
||||
)
|
||||
)
|
||||
}
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.settings_amap_key_save))
|
||||
}
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
LocalizedDialogContent {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(text = stringResource(id = R.string.action_cancel))
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
package com.lzxnone.openloc.ui.screens.home
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.outlined.Block
|
||||
import androidx.compose.material.icons.outlined.CheckCircleOutline
|
||||
import androidx.compose.material.icons.outlined.Tune
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.lzxnone.openloc.R
|
||||
import com.lzxnone.openloc.data.preference.AppMockMode
|
||||
import com.lzxnone.openloc.data.preference.AppPreferences
|
||||
|
||||
/**
|
||||
* 主页应用作用域管理卡片
|
||||
* 支持切换模式(全局 / 黑名单 / 白名单)及分别进入黑名单与白名单管理页面
|
||||
*/
|
||||
@Composable
|
||||
fun AppManagementCard(
|
||||
currentMode: AppMockMode,
|
||||
onModeChange: (AppMockMode) -> Unit,
|
||||
blacklistCount: Int,
|
||||
whitelistCount: Int,
|
||||
onOpenBlacklist: () -> Unit,
|
||||
onOpenWhitelist: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Card(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface
|
||||
),
|
||||
elevation = CardDefaults.cardElevation(
|
||||
defaultElevation = 1.dp
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(20.dp)
|
||||
) {
|
||||
// 头部标题与图标
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Surface(
|
||||
shape = CircleShape,
|
||||
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.6f),
|
||||
modifier = Modifier.size(36.dp)
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Tune,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(20.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(id = R.string.apps_management_title),
|
||||
style = MaterialTheme.typography.titleMedium.copy(
|
||||
fontWeight = FontWeight.Bold
|
||||
),
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
Text(
|
||||
text = stringResource(id = R.string.apps_management_desc),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
// 模式选择分段选择器
|
||||
SingleChoiceSegmentedButtonRow(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
SegmentedButton(
|
||||
selected = currentMode == AppMockMode.GLOBAL,
|
||||
onClick = { onModeChange(AppMockMode.GLOBAL) },
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 0, count = 3)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.apps_mode_global),
|
||||
style = MaterialTheme.typography.labelMedium
|
||||
)
|
||||
}
|
||||
|
||||
SegmentedButton(
|
||||
selected = currentMode == AppMockMode.BLACKLIST,
|
||||
onClick = { onModeChange(AppMockMode.BLACKLIST) },
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 1, count = 3)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.apps_mode_blacklist),
|
||||
style = MaterialTheme.typography.labelMedium
|
||||
)
|
||||
}
|
||||
|
||||
SegmentedButton(
|
||||
selected = currentMode == AppMockMode.WHITELIST,
|
||||
onClick = { onModeChange(AppMockMode.WHITELIST) },
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 2, count = 3)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.apps_mode_whitelist),
|
||||
style = MaterialTheme.typography.labelMedium
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
// 当前模式说明提示
|
||||
val modeDesc = when (currentMode) {
|
||||
AppMockMode.GLOBAL -> stringResource(id = R.string.apps_mode_global_desc)
|
||||
AppMockMode.BLACKLIST -> stringResource(id = R.string.apps_mode_blacklist_desc)
|
||||
AppMockMode.WHITELIST -> stringResource(id = R.string.apps_mode_whitelist_desc)
|
||||
}
|
||||
Text(
|
||||
text = modeDesc,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(horizontal = 4.dp, vertical = 2.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(14.dp))
|
||||
HorizontalDivider(
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
// 黑名单列表入口
|
||||
AppScopeListEntry(
|
||||
icon = Icons.Outlined.Block,
|
||||
title = stringResource(id = R.string.apps_blacklist_title),
|
||||
subtitle = stringResource(id = R.string.apps_blacklist_subtitle, blacklistCount),
|
||||
onClick = onOpenBlacklist,
|
||||
isHighlighted = currentMode == AppMockMode.BLACKLIST
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(6.dp))
|
||||
|
||||
// 白名单列表入口
|
||||
AppScopeListEntry(
|
||||
icon = Icons.Outlined.CheckCircleOutline,
|
||||
title = stringResource(id = R.string.apps_whitelist_title),
|
||||
subtitle = stringResource(id = R.string.apps_whitelist_subtitle, whitelistCount),
|
||||
onClick = onOpenWhitelist,
|
||||
isHighlighted = currentMode == AppMockMode.WHITELIST
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 黑/白名单列表条目入口
|
||||
*/
|
||||
@Composable
|
||||
private fun AppScopeListEntry(
|
||||
icon: ImageVector,
|
||||
title: String,
|
||||
subtitle: String,
|
||||
onClick: () -> Unit,
|
||||
isHighlighted: Boolean,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Surface(
|
||||
onClick = onClick,
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
color = if (isHighlighted) {
|
||||
MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.35f)
|
||||
} else {
|
||||
MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.25f)
|
||||
},
|
||||
modifier = modifier.fillMaxWidth()
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 14.dp, vertical = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = null,
|
||||
tint = if (isHighlighted) {
|
||||
MaterialTheme.colorScheme.primary
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
},
|
||||
modifier = Modifier.size(22.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
|
||||
Column {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.bodyMedium.copy(
|
||||
fontWeight = FontWeight.SemiBold
|
||||
),
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
Text(
|
||||
text = subtitle,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f),
|
||||
modifier = Modifier.size(20.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.lzxnone.openloc.ui.screens.home
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
import com.lzxnone.openloc.data.preference.AppPreferences
|
||||
|
||||
/**
|
||||
* 主页 Screen
|
||||
*/
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
isModuleActive: Boolean,
|
||||
isServiceEnabled: Boolean,
|
||||
onServiceEnabledChange: (Boolean) -> Unit,
|
||||
onOpenBlacklist: () -> Unit,
|
||||
onOpenWhitelist: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(scrollState)
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
// 1. 模块激活状态卡片(根据激活/未激活显示绿/红纯净状态)
|
||||
ModuleStatusCard(
|
||||
isModuleActive = isModuleActive
|
||||
)
|
||||
|
||||
// 2. 虚拟定位总开关卡片(未激活时禁用)
|
||||
ServiceSwitchCard(
|
||||
isModuleActive = isModuleActive,
|
||||
isServiceEnabled = isServiceEnabled,
|
||||
onServiceEnabledChange = onServiceEnabledChange
|
||||
)
|
||||
|
||||
// 3. 应用作用域管理卡片(全局 / 黑名单 / 白名单)
|
||||
AppManagementCard(
|
||||
currentMode = AppPreferences.appMockMode,
|
||||
onModeChange = { AppPreferences.updateAppMockMode(it) },
|
||||
blacklistCount = AppPreferences.blacklistApps.size,
|
||||
whitelistCount = AppPreferences.whitelistApps.size,
|
||||
onOpenBlacklist = onOpenBlacklist,
|
||||
onOpenWhitelist = onOpenWhitelist
|
||||
)
|
||||
|
||||
// 4. 版本与更新模块卡片
|
||||
VersionCard(
|
||||
versionName = "v1.0.0"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.lzxnone.openloc.ui.screens.home
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Cancel
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.lzxnone.openloc.R
|
||||
|
||||
/**
|
||||
* 模块状态卡片:仅展示“已激活”或“未激活”,根据状态展示鲜明颜色(绿/红)
|
||||
*/
|
||||
@Composable
|
||||
fun ModuleStatusCard(
|
||||
isModuleActive: Boolean,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val isDark = MaterialTheme.colorScheme.surface.red < 0.5f
|
||||
|
||||
// 激活对应绿色,未激活对应红色
|
||||
val statusColor = if (isModuleActive) {
|
||||
if (isDark) Color(0xFF81C784) else Color(0xFF2E7D32)
|
||||
} else {
|
||||
if (isDark) Color(0xFFEF5350) else Color(0xFFC62828)
|
||||
}
|
||||
|
||||
val cardBgColor = if (isModuleActive) {
|
||||
if (isDark) Color(0xFF142E18) else Color(0xFFE8F5E9)
|
||||
} else {
|
||||
if (isDark) Color(0xFF331616) else Color(0xFFFFEBEE)
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = cardBgColor
|
||||
),
|
||||
elevation = CardDefaults.cardElevation(
|
||||
defaultElevation = 0.dp
|
||||
)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 20.dp, vertical = 18.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Start
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(44.dp)
|
||||
.clip(CircleShape)
|
||||
.background(statusColor.copy(alpha = 0.18f)),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = if (isModuleActive) Icons.Filled.CheckCircle else Icons.Filled.Cancel,
|
||||
contentDescription = null,
|
||||
tint = statusColor,
|
||||
modifier = Modifier.size(28.dp)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
|
||||
Text(
|
||||
text = stringResource(
|
||||
id = if (isModuleActive) R.string.module_status_activated
|
||||
else R.string.module_status_inactive
|
||||
),
|
||||
style = MaterialTheme.typography.titleLarge.copy(
|
||||
fontWeight = FontWeight.Bold
|
||||
),
|
||||
color = statusColor
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.lzxnone.openloc.ui.screens.home
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.SwitchDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.lzxnone.openloc.R
|
||||
|
||||
/**
|
||||
* 虚拟定位总开关独立卡片
|
||||
* - 未激活时:禁用 Switch,并提示未激活
|
||||
* - 激活时:允许用户自由启停服务
|
||||
*/
|
||||
@Composable
|
||||
fun ServiceSwitchCard(
|
||||
isModuleActive: Boolean,
|
||||
isServiceEnabled: Boolean,
|
||||
onServiceEnabledChange: (Boolean) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Card(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface
|
||||
),
|
||||
elevation = CardDefaults.cardElevation(
|
||||
defaultElevation = 1.dp
|
||||
)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 20.dp, vertical = 18.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.service_switch_title),
|
||||
style = MaterialTheme.typography.titleMedium.copy(
|
||||
fontWeight = FontWeight.SemiBold
|
||||
),
|
||||
color = if (isModuleActive) {
|
||||
MaterialTheme.colorScheme.onSurface
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5f)
|
||||
}
|
||||
)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(
|
||||
text = stringResource(
|
||||
id = if (!isModuleActive) {
|
||||
R.string.service_switch_disabled_hint
|
||||
} else if (isServiceEnabled) {
|
||||
R.string.service_switch_desc_enabled
|
||||
} else {
|
||||
R.string.service_switch_desc_disabled
|
||||
}
|
||||
),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = if (!isModuleActive) {
|
||||
MaterialTheme.colorScheme.error.copy(alpha = 0.7f)
|
||||
} else if (isServiceEnabled) {
|
||||
MaterialTheme.colorScheme.primary
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
|
||||
Switch(
|
||||
checked = isServiceEnabled && isModuleActive,
|
||||
onCheckedChange = { if (isModuleActive) onServiceEnabledChange(it) },
|
||||
enabled = isModuleActive,
|
||||
colors = SwitchDefaults.colors(
|
||||
checkedThumbColor = MaterialTheme.colorScheme.onPrimary,
|
||||
checkedTrackColor = MaterialTheme.colorScheme.primary,
|
||||
uncheckedThumbColor = MaterialTheme.colorScheme.outline,
|
||||
uncheckedTrackColor = MaterialTheme.colorScheme.surfaceVariant
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.lzxnone.openloc.ui.screens.home
|
||||
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Info
|
||||
import androidx.compose.material.icons.outlined.Refresh
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.lzxnone.openloc.R
|
||||
|
||||
/**
|
||||
* 主页底部版本模块卡片
|
||||
* 显示应用当前版本(如 v1.0.0)与“检查更新”按钮
|
||||
*/
|
||||
@Composable
|
||||
fun VersionCard(
|
||||
versionName: String = stringResource(id = R.string.home_version_name),
|
||||
onCheckUpdate: (() -> Unit)? = null,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val placeholderToast = stringResource(id = R.string.home_check_updates_placeholder)
|
||||
|
||||
Card(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface
|
||||
),
|
||||
elevation = CardDefaults.cardElevation(
|
||||
defaultElevation = 1.dp
|
||||
)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 20.dp, vertical = 16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
Surface(
|
||||
shape = CircleShape,
|
||||
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.5f),
|
||||
modifier = Modifier.size(40.dp)
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Info,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(22.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(14.dp))
|
||||
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(id = R.string.home_version_card_title),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
Text(
|
||||
text = versionName,
|
||||
style = MaterialTheme.typography.titleMedium.copy(
|
||||
fontWeight = FontWeight.Bold
|
||||
),
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
|
||||
FilledTonalButton(
|
||||
onClick = {
|
||||
if (onCheckUpdate != null) {
|
||||
onCheckUpdate()
|
||||
} else {
|
||||
Toast.makeText(context, placeholderToast, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
},
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
colors = ButtonDefaults.filledTonalButtonColors(
|
||||
containerColor = MaterialTheme.colorScheme.secondaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onSecondaryContainer
|
||||
)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Refresh,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(6.dp))
|
||||
Text(
|
||||
text = stringResource(id = R.string.home_check_updates_btn),
|
||||
style = MaterialTheme.typography.labelLarge.copy(
|
||||
fontWeight = FontWeight.Medium
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.lzxnone.openloc.ui.screens.settings
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||
import androidx.compose.foundation.layout.FlowRow
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.lzxnone.openloc.R
|
||||
import com.lzxnone.openloc.data.preference.PresetThemeColors
|
||||
|
||||
/**
|
||||
* 主题颜色调色板选择对话框
|
||||
*/
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
fun ThemeColorPickerDialog(
|
||||
currentColor: Color,
|
||||
onDismissRequest: () -> Unit,
|
||||
onColorSelected: (Color) -> Unit
|
||||
) {
|
||||
var selectedColor by remember { mutableStateOf(currentColor) }
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
shape = RoundedCornerShape(24.dp),
|
||||
title = {
|
||||
com.lzxnone.openloc.LocalizedDialogContent {
|
||||
Text(
|
||||
text = stringResource(id = R.string.settings_theme_color_dialog_title),
|
||||
style = MaterialTheme.typography.titleLarge.copy(
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
text = {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp)
|
||||
) {
|
||||
// 预设主题色块矩阵
|
||||
FlowRow(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceAround,
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
maxItemsInEachRow = 4
|
||||
) {
|
||||
PresetThemeColors.forEach { color ->
|
||||
val isSelected = color.toArgb() == selectedColor.toArgb()
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(54.dp)
|
||||
.clip(CircleShape)
|
||||
.background(color)
|
||||
.border(
|
||||
width = if (isSelected) 3.dp else 1.dp,
|
||||
color = if (isSelected) MaterialTheme.colorScheme.onSurface
|
||||
else color.copy(alpha = 0.3f),
|
||||
shape = CircleShape
|
||||
)
|
||||
.clickable { selectedColor = color },
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
if (isSelected) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.Check,
|
||||
contentDescription = null,
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
com.lzxnone.openloc.LocalizedDialogContent {
|
||||
TextButton(
|
||||
onClick = {
|
||||
onColorSelected(selectedColor)
|
||||
onDismissRequest()
|
||||
}
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.action_confirm))
|
||||
}
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
com.lzxnone.openloc.LocalizedDialogContent {
|
||||
TextButton(onClick = onDismissRequest) {
|
||||
Text(text = stringResource(id = R.string.action_cancel))
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.lzxnone.openloc.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
// 浅色主题 - 现代科技蓝
|
||||
val PrimaryLight = Color(0xFF0061A4)
|
||||
val OnPrimaryLight = Color(0xFFFFFFFF)
|
||||
val PrimaryContainerLight = Color(0xFFD1E4FF)
|
||||
val OnPrimaryContainerLight = Color(0xFF001D36)
|
||||
|
||||
val SecondaryLight = Color(0xFF535F70)
|
||||
val OnSecondaryLight = Color(0xFFFFFFFF)
|
||||
val SecondaryContainerLight = Color(0xFFD7E3F7)
|
||||
val OnSecondaryContainerLight = Color(0xFF101C2B)
|
||||
|
||||
val TertiaryLight = Color(0xFF6B5778)
|
||||
val OnTertiaryLight = Color(0xFFFFFFFF)
|
||||
val TertiaryContainerLight = Color(0xFFF2DAFF)
|
||||
val OnTertiaryContainerLight = Color(0xFF251431)
|
||||
|
||||
val BackgroundLight = Color(0xFFF8F9FA)
|
||||
val OnBackgroundLight = Color(0xFF191C1E)
|
||||
val SurfaceLight = Color(0xFFFFFFFF)
|
||||
val OnSurfaceLight = Color(0xFF191C1E)
|
||||
val SurfaceVariantLight = Color(0xFFDFE2EB)
|
||||
val OnSurfaceVariantLight = Color(0xFF43474E)
|
||||
val OutlineLight = Color(0xFF73777F)
|
||||
|
||||
// 深色主题 - 现代科技蓝
|
||||
val PrimaryDark = Color(0xFF9ECAFF)
|
||||
val OnPrimaryDark = Color(0xFF003258)
|
||||
val PrimaryContainerDark = Color(0xFF00497D)
|
||||
val OnPrimaryContainerDark = Color(0xFFD1E4FF)
|
||||
|
||||
val SecondaryDark = Color(0xFFBBC7DB)
|
||||
val OnSecondaryDark = Color(0xFF253140)
|
||||
val SecondaryContainerDark = Color(0xFF3B4858)
|
||||
val OnSecondaryContainerDark = Color(0xFFD7E3F7)
|
||||
|
||||
val TertiaryDark = Color(0xFFD6BEE4)
|
||||
val OnTertiaryDark = Color(0xFF3B2948)
|
||||
val TertiaryContainerDark = Color(0xFF523F5F)
|
||||
val OnTertiaryContainerDark = Color(0xFFF2DAFF)
|
||||
|
||||
val BackgroundDark = Color(0xFF111416)
|
||||
val OnBackgroundDark = Color(0xFFE2E2E6)
|
||||
val SurfaceDark = Color(0xFF1A1C1E)
|
||||
val OnSurfaceDark = Color(0xFFE2E2E6)
|
||||
val SurfaceVariantDark = Color(0xFF43474E)
|
||||
val OnSurfaceVariantDark = Color(0xFFC3C7CF)
|
||||
val OutlineDark = Color(0xFF8D9199)
|
||||
|
||||
// 状态强调色(激活绿色 & 未激活警告橙色)
|
||||
val StatusActiveLight = Color(0xFF2E7D32)
|
||||
val StatusActiveContainerLight = Color(0xFFE8F5E9)
|
||||
val StatusActiveDark = Color(0xFF81C784)
|
||||
val StatusActiveContainerDark = Color(0xFF143017)
|
||||
|
||||
val StatusInactiveLight = Color(0xFFE65100)
|
||||
val StatusInactiveContainerLight = Color(0xFFFFF3E0)
|
||||
val StatusInactiveDark = Color(0xFFFFB74D)
|
||||
val StatusInactiveContainerDark = Color(0xFF3E2723)
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.lzxnone.openloc.ui.theme
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.lzxnone.openloc.data.preference.AppPreferences
|
||||
import com.lzxnone.openloc.data.preference.ThemeMode
|
||||
|
||||
private val DefaultDarkColorScheme = darkColorScheme(
|
||||
primary = PrimaryDark,
|
||||
onPrimary = OnPrimaryDark,
|
||||
primaryContainer = PrimaryContainerDark,
|
||||
onPrimaryContainer = OnPrimaryContainerDark,
|
||||
secondary = SecondaryDark,
|
||||
onSecondary = OnSecondaryDark,
|
||||
secondaryContainer = SecondaryContainerDark,
|
||||
onSecondaryContainer = OnSecondaryContainerDark,
|
||||
tertiary = TertiaryDark,
|
||||
onTertiary = OnTertiaryDark,
|
||||
tertiaryContainer = TertiaryContainerDark,
|
||||
onTertiaryContainer = OnTertiaryContainerDark,
|
||||
background = BackgroundDark,
|
||||
onBackground = OnBackgroundDark,
|
||||
surface = SurfaceDark,
|
||||
onSurface = OnSurfaceDark,
|
||||
surfaceVariant = SurfaceVariantDark,
|
||||
onSurfaceVariant = OnSurfaceVariantDark,
|
||||
outline = OutlineDark
|
||||
)
|
||||
|
||||
private val DefaultLightColorScheme = lightColorScheme(
|
||||
primary = PrimaryLight,
|
||||
onPrimary = OnPrimaryLight,
|
||||
primaryContainer = PrimaryContainerLight,
|
||||
onPrimaryContainer = OnPrimaryContainerLight,
|
||||
secondary = SecondaryLight,
|
||||
onSecondary = OnSecondaryLight,
|
||||
secondaryContainer = SecondaryContainerLight,
|
||||
onSecondaryContainer = OnSecondaryContainerLight,
|
||||
tertiary = TertiaryLight,
|
||||
onTertiary = OnTertiaryLight,
|
||||
tertiaryContainer = TertiaryContainerLight,
|
||||
onTertiaryContainer = OnTertiaryContainerLight,
|
||||
background = BackgroundLight,
|
||||
onBackground = OnBackgroundLight,
|
||||
surface = SurfaceLight,
|
||||
onSurface = OnSurfaceLight,
|
||||
surfaceVariant = SurfaceVariantLight,
|
||||
onSurfaceVariant = OnSurfaceVariantLight,
|
||||
outline = OutlineLight
|
||||
)
|
||||
|
||||
/**
|
||||
* 根据所选的主色调生成对应的深/浅色配色方案
|
||||
*/
|
||||
fun generateDynamicColorScheme(primary: Color, isDark: Boolean): ColorScheme {
|
||||
return if (isDark) {
|
||||
darkColorScheme(
|
||||
primary = primary,
|
||||
onPrimary = Color.White,
|
||||
primaryContainer = primary.copy(alpha = 0.35f),
|
||||
onPrimaryContainer = Color.White,
|
||||
secondary = primary.copy(alpha = 0.75f),
|
||||
onSecondary = Color.Black,
|
||||
secondaryContainer = primary.copy(alpha = 0.25f),
|
||||
onSecondaryContainer = Color.White,
|
||||
background = BackgroundDark,
|
||||
onBackground = OnBackgroundDark,
|
||||
surface = SurfaceDark,
|
||||
onSurface = OnSurfaceDark,
|
||||
surfaceVariant = SurfaceVariantDark,
|
||||
onSurfaceVariant = OnSurfaceVariantDark,
|
||||
outline = OutlineDark
|
||||
)
|
||||
} else {
|
||||
lightColorScheme(
|
||||
primary = primary,
|
||||
onPrimary = Color.White,
|
||||
primaryContainer = primary.copy(alpha = 0.15f),
|
||||
onPrimaryContainer = primary,
|
||||
secondary = primary.copy(alpha = 0.8f),
|
||||
onSecondary = Color.White,
|
||||
secondaryContainer = primary.copy(alpha = 0.12f),
|
||||
onSecondaryContainer = primary,
|
||||
background = BackgroundLight,
|
||||
onBackground = OnBackgroundLight,
|
||||
surface = SurfaceLight,
|
||||
onSurface = OnSurfaceLight,
|
||||
surfaceVariant = SurfaceVariantLight,
|
||||
onSurfaceVariant = OnSurfaceVariantLight,
|
||||
outline = OutlineLight
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun OpenLocTheme(
|
||||
themeMode: ThemeMode = AppPreferences.themeMode,
|
||||
themeColor: Color = Color(AppPreferences.themeColor),
|
||||
isDynamicColor: Boolean = AppPreferences.isDynamicColor,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val systemInDark = isSystemInDarkTheme()
|
||||
val isDark = when (themeMode) {
|
||||
ThemeMode.SYSTEM -> systemInDark
|
||||
ThemeMode.LIGHT -> false
|
||||
ThemeMode.DARK -> true
|
||||
}
|
||||
|
||||
val context = LocalContext.current
|
||||
val colorScheme = when {
|
||||
isDynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||
if (isDark) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
}
|
||||
PrimaryLight.toArgb() == themeColor.toArgb() -> {
|
||||
if (isDark) DefaultDarkColorScheme else DefaultLightColorScheme
|
||||
}
|
||||
else -> {
|
||||
generateDynamicColorScheme(themeColor, isDark)
|
||||
}
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = Typography,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.lzxnone.openloc.ui.theme
|
||||
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
// Set of Material typography styles to start with
|
||||
val Typography = Typography(
|
||||
bodyLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp,
|
||||
lineHeight = 24.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
/* Other default text styles to override
|
||||
titleLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 22.sp,
|
||||
lineHeight = 28.sp,
|
||||
letterSpacing = 0.sp
|
||||
),
|
||||
labelSmall = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 11.sp,
|
||||
lineHeight = 16.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
*/
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
</vector>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@mipmap/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@mipmap/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 8.2 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 7.1 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 11 KiB |
@@ -0,0 +1,176 @@
|
||||
<resources>
|
||||
<string name="app_name">OpenLoc</string>
|
||||
<string name="xposed_description">OpenLoc 虚拟定位 Hook 模块</string>
|
||||
|
||||
<!-- 底部导航栏 -->
|
||||
<string name="nav_home">主页</string>
|
||||
<string name="nav_location">定位</string>
|
||||
<string name="nav_settings">设置</string>
|
||||
|
||||
<!-- 主页 - 模块状态卡片 -->
|
||||
<string name="module_status_title">模块状态</string>
|
||||
<string name="module_status_activated">已激活</string>
|
||||
<string name="module_status_inactive">未激活</string>
|
||||
|
||||
<!-- 总开关卡片 -->
|
||||
<string name="service_switch_title">虚拟定位总开关</string>
|
||||
<string name="service_switch_desc_enabled">虚拟定位已开启,正在模拟位置</string>
|
||||
<string name="service_switch_desc_disabled">虚拟定位已关闭,使用真实位置</string>
|
||||
<string name="service_switch_disabled_hint">模块未激活,总开关已被禁用</string>
|
||||
|
||||
<!-- 设置 - 分组 -->
|
||||
<string name="settings_category_language">语言设置</string>
|
||||
<string name="settings_category_appearance">外观设置</string>
|
||||
|
||||
<!-- 设置 - 语言 -->
|
||||
<string name="settings_language_title">应用语言</string>
|
||||
<string name="settings_language_sheet_title">选择语言</string>
|
||||
<string name="settings_language_system">跟随系统</string>
|
||||
<string name="settings_language_zh">简体中文</string>
|
||||
<string name="settings_language_en">English</string>
|
||||
|
||||
<!-- 设置 - 外观 -->
|
||||
<string name="settings_theme_mode_title">主题模式</string>
|
||||
<string name="settings_theme_mode_sheet_title">选择主题模式</string>
|
||||
<string name="settings_theme_mode_system">跟随系统</string>
|
||||
<string name="settings_theme_mode_light">浅色模式</string>
|
||||
<string name="settings_theme_mode_dark">深色模式</string>
|
||||
|
||||
<string name="settings_dynamic_color_title">系统主题颜色</string>
|
||||
<string name="settings_dynamic_color_desc">跟随系统壁纸动态提取主题色 (Android 12+)</string>
|
||||
|
||||
<string name="settings_theme_color_title">主题颜色</string>
|
||||
<string name="settings_theme_color_dialog_title">选择主题颜色</string>
|
||||
|
||||
<string name="action_cancel">取消</string>
|
||||
<string name="action_confirm">确定</string>
|
||||
|
||||
<!-- 定位页面 -->
|
||||
<string name="location_search_hint">搜索地区 / 地名…</string>
|
||||
<string name="location_default_name">选定位置</string>
|
||||
<string name="location_latitude_format">纬度: %1$.6f</string>
|
||||
<string name="location_longitude_format">经度: %1$.6f</string>
|
||||
<string name="location_copy_coords">复制坐标</string>
|
||||
<string name="location_coords_copied">已复制坐标到剪贴板</string>
|
||||
<string name="location_reset_current">回到原位</string>
|
||||
<string name="location_located_to_real">已定位到当前真实位置</string>
|
||||
<string name="location_search_back">返回</string>
|
||||
<string name="location_search_clear">清空</string>
|
||||
<string name="location_search_history">搜索历史</string>
|
||||
<string name="location_search_clear_history">清空历史</string>
|
||||
<string name="location_search_no_results">未找到相关地点</string>
|
||||
<string name="location_search_empty_hint">输入地点名称或经纬度进行搜索</string>
|
||||
<string name="location_search_coord_jump">跳转至经纬度坐标</string>
|
||||
|
||||
<!-- 地图与搜索服务设置 -->
|
||||
<string name="settings_category_map_service">地图与搜索服务</string>
|
||||
<string name="settings_search_provider_title">搜索引擎提供商</string>
|
||||
<string name="settings_search_provider_sheet_title">选择搜索引擎提供商</string>
|
||||
<string name="search_provider_amap">高德地图</string>
|
||||
<string name="search_provider_baidu">百度地图</string>
|
||||
<string name="search_provider_photon">Photon</string>
|
||||
<string name="search_provider_nominatim">Nominatim</string>
|
||||
<string name="search_provider_badge_requires_key">需 Key</string>
|
||||
<string name="search_provider_badge_free">完全免费</string>
|
||||
|
||||
<string name="settings_api_key_title">API Key</string>
|
||||
<string name="settings_api_key_free_value">无需配置</string>
|
||||
<string name="settings_api_key_placeholder">请输入 Key / AK</string>
|
||||
<string name="settings_api_key_empty">Key 不能为空</string>
|
||||
<string name="error_unknown">未知错误</string>
|
||||
<string name="location_search_coord_format">经度: %1$.6f, 纬度: %2$.6f</string>
|
||||
<string name="settings_api_key_test">测试</string>
|
||||
<string name="settings_api_key_testing">正在测试...</string>
|
||||
<string name="settings_api_key_test_success">测试通过,Key 有效!</string>
|
||||
<string name="settings_api_key_test_failed">测试失败: %1$s</string>
|
||||
|
||||
<string name="settings_amap_key_dialog_title">配置高德 Key</string>
|
||||
<string name="settings_amap_key_hint">前往高德开放平台 (lbs.amap.com) 获取 Web服务 Key</string>
|
||||
<string name="settings_baidu_key_dialog_title">配置百度 AK</string>
|
||||
<string name="settings_baidu_key_hint">前往百度地图开放平台 (lbsyun.baidu.com) 获取服务端 AK</string>
|
||||
<string name="settings_amap_key_configured">已配置</string>
|
||||
<string name="settings_amap_key_not_configured">未配置</string>
|
||||
<string name="settings_amap_key_clear">清空</string>
|
||||
<string name="settings_amap_key_save">保存</string>
|
||||
|
||||
<string name="search_no_api_key_title_dynamic">未配置 %1$s Key</string>
|
||||
<string name="search_no_api_key_desc_dynamic">当前搜索引擎需要 API Key,可前往配置或切换为免费引擎。</string>
|
||||
<string name="search_configure_key_button">配置 Key</string>
|
||||
<string name="search_switch_provider_button">切换搜索引擎</string>
|
||||
<string name="search_key_invalid_title_dynamic">%1$s Key 无效</string>
|
||||
<string name="search_key_invalid_desc">Key 验证失败(%1$s)。请检查平台类型或重新输入。</string>
|
||||
<string name="search_edit_key_button">修改 Key</string>
|
||||
<string name="search_network_error">网络连接失败,请检查网络后重试</string>
|
||||
<string name="location_card_collapse">折叠</string>
|
||||
<string name="location_card_expand">展开</string>
|
||||
|
||||
<!-- 收藏夹 -->
|
||||
<string name="favorites_title">收藏夹</string>
|
||||
<string name="favorite_add_title">新增收藏地址</string>
|
||||
<string name="favorite_name_label">名称</string>
|
||||
<string name="favorite_name_hint">例如:家 / 公司</string>
|
||||
<string name="favorite_address_label">地区名称</string>
|
||||
<string name="favorite_address_deriving">正在根据经纬度推导地区…</string>
|
||||
<string name="favorite_latitude_label">纬度 (WGS-84)</string>
|
||||
<string name="favorite_longitude_label">经度 (WGS-84)</string>
|
||||
<string name="favorite_search_hint">搜索收藏条目的名称、地区名称…</string>
|
||||
<string name="favorite_empty_list">暂无收藏地址,点击右上角 + 新增</string>
|
||||
<string name="favorite_search_empty">未找到匹配的收藏条目</string>
|
||||
<string name="favorite_delete_confirm_title">删除收藏</string>
|
||||
<string name="favorite_delete_confirm_msg">确定要删除收藏“%1$s”吗?</string>
|
||||
<string name="favorite_added_success">已添加到收藏夹</string>
|
||||
<string name="favorite_deleted_success">已删除收藏</string>
|
||||
<string name="favorite_applied_success">已选定定位:%1$s</string>
|
||||
<string name="favorite_invalid_coords">请输入有效的纬度(-90~90)与经度(-180~180)</string>
|
||||
<string name="favorite_invalid_name">名称不能为空</string>
|
||||
<string name="favorite_delete">删除</string>
|
||||
<string name="favorite_drag_handle">拖动排序</string>
|
||||
<string name="location_unknown_address">未知地区</string>
|
||||
|
||||
<!-- 应用作用域管理 -->
|
||||
<string name="apps_management_title">应用作用域</string>
|
||||
<string name="apps_management_desc">配置虚拟定位的作用应用与过滤规则</string>
|
||||
<string name="apps_mode_title">生效模式</string>
|
||||
<string name="apps_mode_global">全局</string>
|
||||
<string name="apps_mode_blacklist">黑名单</string>
|
||||
<string name="apps_mode_whitelist">白名单</string>
|
||||
<string name="apps_mode_global_desc">整机所有应用均生效虚拟定位</string>
|
||||
<string name="apps_mode_blacklist_desc">黑名单中的应用保持真实定位,其余应用生效虚拟定位</string>
|
||||
<string name="apps_mode_whitelist_desc">仅白名单中的应用生效虚拟定位,其余应用保持真实定位</string>
|
||||
<string name="apps_blacklist_title">黑名单列表</string>
|
||||
<string name="apps_whitelist_title">白名单列表</string>
|
||||
<string name="apps_blacklist_subtitle">已排除 %1$d 个应用</string>
|
||||
<string name="apps_whitelist_subtitle">已生效 %1$d 个应用</string>
|
||||
<string name="apps_search_hint">搜索应用名称或包名…</string>
|
||||
<string name="apps_select_all">全选</string>
|
||||
<string name="apps_deselect_all">全不选</string>
|
||||
<string name="apps_show_system_apps">显示系统应用</string>
|
||||
<string name="apps_hide_system_apps">隐藏系统应用</string>
|
||||
<string name="apps_system_app_tag">系统</string>
|
||||
<string name="apps_loading">正在加载已安装应用…</string>
|
||||
<string name="apps_empty_search">未找到匹配的应用</string>
|
||||
<string name="apps_empty_installed">暂无可用应用</string>
|
||||
<string name="apps_selected_count">已选 %1$d / %2$d 项</string>
|
||||
|
||||
<!-- 防检测与真实度设置 -->
|
||||
<string name="settings_category_anti_detection">防检测与真实度增强</string>
|
||||
<string name="settings_anti_jitter_title">位置自然微漂移</string>
|
||||
<string name="settings_anti_jitter_desc">模拟真实卫星信号的高斯平滑游走,避免坐标绝对静止被风控拦截</string>
|
||||
<string name="settings_anti_gnss_title">全真多星座卫星仿真</string>
|
||||
<string name="settings_anti_gnss_desc">模拟 GPS、北斗、GLONASS、Galileo 多星座卫星群,注入物理载噪比与全量 NMEA 报文</string>
|
||||
<string name="settings_anti_network_title">基站与 Wi-Fi 防反查</string>
|
||||
<string name="settings_anti_network_desc">脱敏基站小区与 Wi-Fi BSSID,拦截运营商基站监听,杜绝云端指纹库反查真实物理地址</string>
|
||||
<string name="settings_anti_sensor_title">传感器手持生理拟真</string>
|
||||
<string name="settings_anti_sensor_desc">向加速度计注入生物力学生理微颤,打破桌面绝对静止特征,满足步态与姿态校验</string>
|
||||
<string name="settings_anti_stealth_title">堆栈与模块自隐匿</string>
|
||||
<string name="settings_anti_stealth_desc">过滤调用栈中的 Xposed 与 OpenLoc 栈帧,并对目标应用隐藏模块包名</string>
|
||||
<string name="settings_anti_dev_title">开发者选项伪装</string>
|
||||
<string name="settings_anti_dev_desc">对目标应用伪装为未开启开发者模式、未开启 USB 调试与未开启模拟位置</string>
|
||||
|
||||
<!-- 版本与更新 -->
|
||||
<string name="home_version_card_title">当前版本</string>
|
||||
<string name="home_version_name">v1.0.0</string>
|
||||
<string name="home_check_updates_btn">检查更新</string>
|
||||
<string name="home_check_updates_placeholder">当前已是最新版本</string>
|
||||
</resources>
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
<resources>
|
||||
<string name="app_name">OpenLoc</string>
|
||||
<string name="xposed_description">OpenLoc 虚拟定位 Hook 模块</string>
|
||||
|
||||
<!-- 底部导航栏 -->
|
||||
<string name="nav_home">主页</string>
|
||||
<string name="nav_location">定位</string>
|
||||
<string name="nav_settings">设置</string>
|
||||
|
||||
<!-- 主页 - 模块状态卡片 -->
|
||||
<string name="module_status_title">模块状态</string>
|
||||
<string name="module_status_activated">已激活</string>
|
||||
<string name="module_status_inactive">未激活</string>
|
||||
|
||||
<!-- 总开关卡片 -->
|
||||
<string name="service_switch_title">虚拟定位总开关</string>
|
||||
<string name="service_switch_desc_enabled">虚拟定位已开启,正在模拟位置</string>
|
||||
<string name="service_switch_desc_disabled">虚拟定位已关闭,使用真实位置</string>
|
||||
<string name="service_switch_disabled_hint">模块未激活,总开关已被禁用</string>
|
||||
|
||||
<!-- 设置 - 分组 -->
|
||||
<string name="settings_category_language">语言设置</string>
|
||||
<string name="settings_category_appearance">外观设置</string>
|
||||
|
||||
<!-- 设置 - 语言 -->
|
||||
<string name="settings_language_title">应用语言</string>
|
||||
<string name="settings_language_sheet_title">选择语言</string>
|
||||
<string name="settings_language_system">跟随系统</string>
|
||||
<string name="settings_language_zh">简体中文</string>
|
||||
<string name="settings_language_en">English</string>
|
||||
|
||||
<!-- 设置 - 外观 -->
|
||||
<string name="settings_theme_mode_title">主题模式</string>
|
||||
<string name="settings_theme_mode_sheet_title">选择主题模式</string>
|
||||
<string name="settings_theme_mode_system">跟随系统</string>
|
||||
<string name="settings_theme_mode_light">浅色模式</string>
|
||||
<string name="settings_theme_mode_dark">深色模式</string>
|
||||
|
||||
<string name="settings_dynamic_color_title">系统主题颜色</string>
|
||||
<string name="settings_dynamic_color_desc">跟随系统壁纸动态提取主题色 (Android 12+)</string>
|
||||
|
||||
<string name="settings_theme_color_title">主题颜色</string>
|
||||
<string name="settings_theme_color_dialog_title">选择主题颜色</string>
|
||||
|
||||
<string name="action_cancel">取消</string>
|
||||
<string name="action_confirm">确定</string>
|
||||
|
||||
<!-- 定位页面 -->
|
||||
<string name="location_search_hint">搜索地区 / 地名…</string>
|
||||
<string name="location_default_name">选定位置</string>
|
||||
<string name="location_latitude_format">纬度: %1$.6f</string>
|
||||
<string name="location_longitude_format">经度: %1$.6f</string>
|
||||
<string name="location_copy_coords">复制坐标</string>
|
||||
<string name="location_coords_copied">已复制坐标到剪贴板</string>
|
||||
<string name="location_reset_current">回到原位</string>
|
||||
<string name="location_located_to_real">已定位到当前真实位置</string>
|
||||
<string name="location_search_back">返回</string>
|
||||
<string name="location_search_clear">清空</string>
|
||||
<string name="location_search_history">搜索历史</string>
|
||||
<string name="location_search_clear_history">清空历史</string>
|
||||
<string name="location_search_no_results">未找到相关地点</string>
|
||||
<string name="location_search_empty_hint">输入地点名称或经纬度进行搜索</string>
|
||||
<string name="location_search_coord_jump">跳转至经纬度坐标</string>
|
||||
|
||||
<!-- 地图与搜索服务设置 -->
|
||||
<string name="settings_category_map_service">地图与搜索服务</string>
|
||||
<string name="settings_search_provider_title">搜索引擎提供商</string>
|
||||
<string name="settings_search_provider_sheet_title">选择搜索引擎提供商</string>
|
||||
<string name="search_provider_amap">高德地图</string>
|
||||
<string name="search_provider_baidu">百度地图</string>
|
||||
<string name="search_provider_photon">Photon</string>
|
||||
<string name="search_provider_nominatim">Nominatim</string>
|
||||
<string name="search_provider_badge_requires_key">需 Key</string>
|
||||
<string name="search_provider_badge_free">完全免费</string>
|
||||
|
||||
<string name="settings_api_key_title">API Key</string>
|
||||
<string name="settings_api_key_free_value">无需配置</string>
|
||||
<string name="settings_api_key_placeholder">请输入 Key / AK</string>
|
||||
<string name="settings_api_key_empty">Key 不能为空</string>
|
||||
<string name="error_unknown">未知错误</string>
|
||||
<string name="location_search_coord_format">经度: %1$.6f, 纬度: %2$.6f</string>
|
||||
<string name="settings_api_key_test">测试</string>
|
||||
<string name="settings_api_key_testing">正在测试...</string>
|
||||
<string name="settings_api_key_test_success">测试通过,Key 有效!</string>
|
||||
<string name="settings_api_key_test_failed">测试失败: %1$s</string>
|
||||
|
||||
<string name="settings_amap_key_dialog_title">配置高德 Key</string>
|
||||
<string name="settings_amap_key_hint">前往高德开放平台 (lbs.amap.com) 获取 Web服务 Key</string>
|
||||
<string name="settings_baidu_key_dialog_title">配置百度 AK</string>
|
||||
<string name="settings_baidu_key_hint">前往百度地图开放平台 (lbsyun.baidu.com) 获取服务端 AK</string>
|
||||
<string name="settings_amap_key_configured">已配置</string>
|
||||
<string name="settings_amap_key_not_configured">未配置</string>
|
||||
<string name="settings_amap_key_clear">清空</string>
|
||||
<string name="settings_amap_key_save">保存</string>
|
||||
|
||||
<string name="search_no_api_key_title_dynamic">未配置 %1$s Key</string>
|
||||
<string name="search_no_api_key_desc_dynamic">当前搜索引擎需要 API Key,可前往配置或切换为免费引擎。</string>
|
||||
<string name="search_configure_key_button">配置 Key</string>
|
||||
<string name="search_switch_provider_button">切换搜索引擎</string>
|
||||
<string name="search_key_invalid_title_dynamic">%1$s Key 无效</string>
|
||||
<string name="search_key_invalid_desc">Key 验证失败(%1$s)。请检查平台类型或重新输入。</string>
|
||||
<string name="search_edit_key_button">修改 Key</string>
|
||||
<string name="search_network_error">网络连接失败,请检查网络后重试</string>
|
||||
<string name="location_card_collapse">折叠</string>
|
||||
<string name="location_card_expand">展开</string>
|
||||
|
||||
<!-- 收藏夹 -->
|
||||
<string name="favorites_title">收藏夹</string>
|
||||
<string name="favorite_add_title">新增收藏地址</string>
|
||||
<string name="favorite_name_label">名称</string>
|
||||
<string name="favorite_name_hint">例如:家 / 公司</string>
|
||||
<string name="favorite_address_label">地区名称</string>
|
||||
<string name="favorite_address_deriving">正在根据经纬度推导地区…</string>
|
||||
<string name="favorite_latitude_label">纬度 (WGS-84)</string>
|
||||
<string name="favorite_longitude_label">经度 (WGS-84)</string>
|
||||
<string name="favorite_search_hint">搜索收藏条目的名称、地区名称…</string>
|
||||
<string name="favorite_empty_list">暂无收藏地址,点击右上角 + 新增</string>
|
||||
<string name="favorite_search_empty">未找到匹配的收藏条目</string>
|
||||
<string name="favorite_delete_confirm_title">删除收藏</string>
|
||||
<string name="favorite_delete_confirm_msg">确定要删除收藏“%1$s”吗?</string>
|
||||
<string name="favorite_added_success">已添加到收藏夹</string>
|
||||
<string name="favorite_deleted_success">已删除收藏</string>
|
||||
<string name="favorite_applied_success">已选定定位:%1$s</string>
|
||||
<string name="favorite_invalid_coords">请输入有效的纬度(-90~90)与经度(-180~180)</string>
|
||||
<string name="favorite_invalid_name">名称不能为空</string>
|
||||
<string name="favorite_delete">删除</string>
|
||||
<string name="favorite_drag_handle">拖动排序</string>
|
||||
<string name="location_unknown_address">未知地区</string>
|
||||
|
||||
<!-- 应用作用域管理 -->
|
||||
<string name="apps_management_title">应用作用域</string>
|
||||
<string name="apps_management_desc">配置虚拟定位的作用应用与过滤规则</string>
|
||||
<string name="apps_mode_title">生效模式</string>
|
||||
<string name="apps_mode_global">全局</string>
|
||||
<string name="apps_mode_blacklist">黑名单</string>
|
||||
<string name="apps_mode_whitelist">白名单</string>
|
||||
<string name="apps_mode_global_desc">整机所有应用均生效虚拟定位</string>
|
||||
<string name="apps_mode_blacklist_desc">黑名单中的应用保持真实定位,其余应用生效虚拟定位</string>
|
||||
<string name="apps_mode_whitelist_desc">仅白名单中的应用生效虚拟定位,其余应用保持真实定位</string>
|
||||
<string name="apps_blacklist_title">黑名单列表</string>
|
||||
<string name="apps_whitelist_title">白名单列表</string>
|
||||
<string name="apps_blacklist_subtitle">已排除 %1$d 个应用</string>
|
||||
<string name="apps_whitelist_subtitle">已生效 %1$d 个应用</string>
|
||||
<string name="apps_search_hint">搜索应用名称或包名…</string>
|
||||
<string name="apps_select_all">全选</string>
|
||||
<string name="apps_deselect_all">全不选</string>
|
||||
<string name="apps_show_system_apps">显示系统应用</string>
|
||||
<string name="apps_hide_system_apps">隐藏系统应用</string>
|
||||
<string name="apps_system_app_tag">系统</string>
|
||||
<string name="apps_loading">正在加载已安装应用…</string>
|
||||
<string name="apps_empty_search">未找到匹配的应用</string>
|
||||
<string name="apps_empty_installed">暂无可用应用</string>
|
||||
<string name="apps_selected_count">已选 %1$d / %2$d 项</string>
|
||||
|
||||
<!-- 防检测与真实度设置 -->
|
||||
<string name="settings_category_anti_detection">防检测与真实度增强</string>
|
||||
<string name="settings_anti_jitter_title">位置自然微漂移</string>
|
||||
<string name="settings_anti_jitter_desc">模拟真实卫星信号的高斯平滑游走,避免坐标绝对静止被风控拦截</string>
|
||||
<string name="settings_anti_gnss_title">全真多星座卫星仿真</string>
|
||||
<string name="settings_anti_gnss_desc">模拟 GPS、北斗、GLONASS、Galileo 多星座卫星群,注入物理载噪比与全量 NMEA 报文</string>
|
||||
<string name="settings_anti_network_title">基站与 Wi-Fi 防反查</string>
|
||||
<string name="settings_anti_network_desc">脱敏基站小区与 Wi-Fi BSSID,拦截运营商基站监听,杜绝云端指纹库反查真实物理地址</string>
|
||||
<string name="settings_anti_sensor_title">传感器手持生理拟真</string>
|
||||
<string name="settings_anti_sensor_desc">向加速度计注入生物力学生理微颤,打破桌面绝对静止特征,满足步态与姿态校验</string>
|
||||
<string name="settings_anti_stealth_title">堆栈与模块自隐匿</string>
|
||||
<string name="settings_anti_stealth_desc">过滤调用栈中的 Xposed 与 OpenLoc 栈帧,并对目标应用隐藏模块包名</string>
|
||||
<string name="settings_anti_dev_title">开发者选项伪装</string>
|
||||
<string name="settings_anti_dev_desc">对目标应用伪装为未开启开发者模式、未开启 USB 调试与未开启模拟位置</string>
|
||||
|
||||
<!-- 版本与更新 -->
|
||||
<string name="home_version_card_title">当前版本</string>
|
||||
<string name="home_version_name">v1.0.0</string>
|
||||
<string name="home_check_updates_btn">检查更新</string>
|
||||
<string name="home_check_updates_placeholder">当前已是最新版本</string>
|
||||
</resources>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="xposed_scope">
|
||||
<!-- 勾选 Android 系统实现整机全局免指定拦截 -->
|
||||
<item>android</item>
|
||||
<!-- 勾选模块自身实现激活状态自检 -->
|
||||
<item>com.lzxnone.openloc</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,175 @@
|
||||
<resources>
|
||||
<string name="app_name">OpenLoc</string>
|
||||
<string name="xposed_description">OpenLoc virtual location hook module</string>
|
||||
|
||||
<!-- Bottom Navigation -->
|
||||
<string name="nav_home">Home</string>
|
||||
<string name="nav_location">Location</string>
|
||||
<string name="nav_settings">Settings</string>
|
||||
|
||||
<!-- Home Screen - Module Status Card -->
|
||||
<string name="module_status_title">Module Status</string>
|
||||
<string name="module_status_activated">Activated</string>
|
||||
<string name="module_status_inactive">Inactive</string>
|
||||
|
||||
<!-- Master Switch Card -->
|
||||
<string name="service_switch_title">Master Switch</string>
|
||||
<string name="service_switch_desc_enabled">Virtual location is running</string>
|
||||
<string name="service_switch_desc_disabled">Virtual location is paused</string>
|
||||
<string name="service_switch_disabled_hint">Module inactive, switch is disabled</string>
|
||||
|
||||
<!-- Settings - Categories -->
|
||||
<string name="settings_category_language">Language</string>
|
||||
<string name="settings_category_appearance">Appearance</string>
|
||||
|
||||
<!-- Settings - Language -->
|
||||
<string name="settings_language_title">App Language</string>
|
||||
<string name="settings_language_sheet_title">Select Language</string>
|
||||
<string name="settings_language_system">Follow System</string>
|
||||
<string name="settings_language_zh">简体中文 (Chinese)</string>
|
||||
<string name="settings_language_en">English</string>
|
||||
|
||||
<!-- Settings - Appearance -->
|
||||
<string name="settings_theme_mode_title">Theme Mode</string>
|
||||
<string name="settings_theme_mode_sheet_title">Select Theme Mode</string>
|
||||
<string name="settings_theme_mode_system">Follow System</string>
|
||||
<string name="settings_theme_mode_light">Light Mode</string>
|
||||
<string name="settings_theme_mode_dark">Dark Mode</string>
|
||||
|
||||
<string name="settings_dynamic_color_title">System Theme Color</string>
|
||||
<string name="settings_dynamic_color_desc">Follow system wallpaper dynamic colors (Android 12+)</string>
|
||||
|
||||
<string name="settings_theme_color_title">Theme Color</string>
|
||||
<string name="settings_theme_color_dialog_title">Choose Palette</string>
|
||||
|
||||
<string name="action_cancel">Cancel</string>
|
||||
<string name="action_confirm">Confirm</string>
|
||||
|
||||
<!-- Location Screen -->
|
||||
<string name="location_search_hint">Search location / address…</string>
|
||||
<string name="location_default_name">Selected Location</string>
|
||||
<string name="location_latitude_format">Lat: %1$.6f</string>
|
||||
<string name="location_longitude_format">Lng: %1$.6f</string>
|
||||
<string name="location_copy_coords">Copy Coordinates</string>
|
||||
<string name="location_coords_copied">Coordinates copied to clipboard</string>
|
||||
<string name="location_reset_current">Reset to current location</string>
|
||||
<string name="location_located_to_real">Located to current position</string>
|
||||
<string name="location_search_back">Back</string>
|
||||
<string name="location_search_clear">Clear</string>
|
||||
<string name="location_search_history">Recent Searches</string>
|
||||
<string name="location_search_clear_history">Clear History</string>
|
||||
<string name="location_search_no_results">No matching places found</string>
|
||||
<string name="location_search_empty_hint">Enter place name or coordinates to search</string>
|
||||
<string name="location_search_coord_jump">Jump to coordinates</string>
|
||||
|
||||
<!-- Map & Search Service Settings -->
|
||||
<string name="settings_category_map_service">Map & Search Service</string>
|
||||
<string name="settings_search_provider_title">Search Engine Provider</string>
|
||||
<string name="settings_search_provider_sheet_title">Select Search Provider</string>
|
||||
<string name="search_provider_amap">AMap</string>
|
||||
<string name="search_provider_baidu">Baidu</string>
|
||||
<string name="search_provider_photon">Photon</string>
|
||||
<string name="search_provider_nominatim">Nominatim</string>
|
||||
<string name="search_provider_badge_requires_key">Key Required</string>
|
||||
<string name="search_provider_badge_free">Free / No Key</string>
|
||||
|
||||
<string name="settings_api_key_title">API Key</string>
|
||||
<string name="settings_api_key_free_value">Not Required</string>
|
||||
<string name="settings_api_key_placeholder">Enter Key / AK</string>
|
||||
<string name="settings_api_key_empty">Key cannot be empty</string>
|
||||
<string name="error_unknown">Unknown error</string>
|
||||
<string name="location_search_coord_format">Lng: %1$.6f, Lat: %2$.6f</string>
|
||||
<string name="settings_api_key_test">Test</string>
|
||||
<string name="settings_api_key_testing">Testing...</string>
|
||||
<string name="settings_api_key_test_success">Test passed! Key is valid.</string>
|
||||
<string name="settings_api_key_test_failed">Test failed: %1$s</string>
|
||||
|
||||
<string name="settings_amap_key_dialog_title">Configure AMap Key</string>
|
||||
<string name="settings_amap_key_hint">Get Web Service Key from lbs.amap.com</string>
|
||||
<string name="settings_baidu_key_dialog_title">Configure Baidu AK</string>
|
||||
<string name="settings_baidu_key_hint">Get Server AK from lbsyun.baidu.com</string>
|
||||
<string name="settings_amap_key_configured">Configured</string>
|
||||
<string name="settings_amap_key_not_configured">Not Configured</string>
|
||||
<string name="settings_amap_key_clear">Clear</string>
|
||||
<string name="settings_amap_key_save">Save</string>
|
||||
|
||||
<string name="search_no_api_key_title_dynamic">%1$s Key Not Configured</string>
|
||||
<string name="search_no_api_key_desc_dynamic">This engine requires an API Key. You can configure it or switch to a free engine.</string>
|
||||
<string name="search_configure_key_button">Configure Key</string>
|
||||
<string name="search_switch_provider_button">Switch Provider</string>
|
||||
<string name="search_key_invalid_title_dynamic">Invalid %1$s Key</string>
|
||||
<string name="search_key_invalid_desc">Key verification failed (%1$s). Please check platform type or re-enter.</string>
|
||||
<string name="search_edit_key_button">Edit Key</string>
|
||||
<string name="search_network_error">Network request failed, please check connection</string>
|
||||
<string name="location_card_collapse">Collapse</string>
|
||||
<string name="location_card_expand">Expand</string>
|
||||
|
||||
<!-- Favorites -->
|
||||
<string name="favorites_title">Favorites</string>
|
||||
<string name="favorite_add_title">Add Favorite Location</string>
|
||||
<string name="favorite_name_label">Name</string>
|
||||
<string name="favorite_name_hint">e.g. Home / Company</string>
|
||||
<string name="favorite_address_label">Area / Address</string>
|
||||
<string name="favorite_address_deriving">Deriving area name…</string>
|
||||
<string name="favorite_latitude_label">Latitude (WGS-84)</string>
|
||||
<string name="favorite_longitude_label">Longitude (WGS-84)</string>
|
||||
<string name="favorite_search_hint">Search name or area…</string>
|
||||
<string name="favorite_empty_list">No favorites yet. Tap + to add.</string>
|
||||
<string name="favorite_search_empty">No matching favorites found</string>
|
||||
<string name="favorite_delete_confirm_title">Delete Favorite</string>
|
||||
<string name="favorite_delete_confirm_msg">Are you sure you want to delete \"%1$s\"?</string>
|
||||
<string name="favorite_added_success">Added to favorites</string>
|
||||
<string name="favorite_deleted_success">Favorite deleted</string>
|
||||
<string name="favorite_applied_success">Moved to: %1$s</string>
|
||||
<string name="favorite_invalid_coords">Please enter valid latitude (-90~90) and longitude (-180~180)</string>
|
||||
<string name="favorite_invalid_name">Name cannot be empty</string>
|
||||
<string name="favorite_delete">Delete</string>
|
||||
<string name="favorite_drag_handle">Drag to reorder</string>
|
||||
<string name="location_unknown_address">Unknown address</string>
|
||||
|
||||
<!-- App Management / Scope -->
|
||||
<string name="apps_management_title">App Scope Management</string>
|
||||
<string name="apps_management_desc">Configure target apps and mock rules</string>
|
||||
<string name="apps_mode_title">Mock Mode</string>
|
||||
<string name="apps_mode_global">Global</string>
|
||||
<string name="apps_mode_blacklist">Blacklist</string>
|
||||
<string name="apps_mode_whitelist">Whitelist</string>
|
||||
<string name="apps_mode_global_desc">All applications on this device will receive mocked location.</string>
|
||||
<string name="apps_mode_blacklist_desc">Apps in the blacklist keep real location, while all other apps receive mocked location.</string>
|
||||
<string name="apps_mode_whitelist_desc">Only apps in the whitelist receive mocked location, while other apps keep real location.</string>
|
||||
<string name="apps_blacklist_title">Blacklist Apps</string>
|
||||
<string name="apps_whitelist_title">Whitelist Apps</string>
|
||||
<string name="apps_blacklist_subtitle">%1$d apps excluded</string>
|
||||
<string name="apps_whitelist_subtitle">%1$d apps enabled</string>
|
||||
<string name="apps_search_hint">Search app name or package…</string>
|
||||
<string name="apps_select_all">Select All</string>
|
||||
<string name="apps_deselect_all">Deselect All</string>
|
||||
<string name="apps_show_system_apps">Show system apps</string>
|
||||
<string name="apps_hide_system_apps">Hide system apps</string>
|
||||
<string name="apps_system_app_tag">System</string>
|
||||
<string name="apps_loading">Loading installed applications…</string>
|
||||
<string name="apps_empty_search">No matching applications found</string>
|
||||
<string name="apps_empty_installed">No applications found</string>
|
||||
<string name="apps_selected_count">%1$d / %2$d selected</string>
|
||||
|
||||
<!-- Anti-Detection & Realism Settings -->
|
||||
<string name="settings_category_anti_detection">Anti-Detection & Realism</string>
|
||||
<string name="settings_anti_jitter_title">Natural Location Drift</string>
|
||||
<string name="settings_anti_jitter_desc">Simulate smooth Brownian motion / Gaussian GNSS noise to prevent static location detection</string>
|
||||
<string name="settings_anti_gnss_title">Full Constellation GNSS Simulation</string>
|
||||
<string name="settings_anti_gnss_desc">Simulate realistic multi-constellation satellites (GPS, BeiDou, GLONASS, Galileo) with physical C/N0 noise and NMEA GSV/GSA sentences</string>
|
||||
<string name="settings_anti_network_title">Cell Tower & Wi-Fi Camouflage</string>
|
||||
<string name="settings_anti_network_desc">Camouflage cell tower and Wi-Fi BSSID to prevent cloud reverse geolocation lookup</string>
|
||||
<string name="settings_anti_sensor_title">Handheld Motion Sensor Simulation</string>
|
||||
<string name="settings_anti_sensor_desc">Inject subtle physiological micro-tremor into accelerometer readings to mimic active human hand-holding</string>
|
||||
<string name="settings_anti_stealth_title">Stack Trace & Module Stealth</string>
|
||||
<string name="settings_anti_stealth_desc">Sanitize call stack traces (filter Xposed/OpenLoc frames) and hide module package from target apps</string>
|
||||
<string name="settings_anti_dev_title">Developer Settings Camouflage</string>
|
||||
<string name="settings_anti_dev_desc">Disguise developer mode, USB debugging, and mock location as disabled for target apps</string>
|
||||
|
||||
<!-- Version & Updates -->
|
||||
<string name="home_version_card_title">Current Version</string>
|
||||
<string name="home_version_name">v1.0.0</string>
|
||||
<string name="home_check_updates_btn">Check for Updates</string>
|
||||
<string name="home_check_updates_placeholder">Already the latest version</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="Theme.OpenLoc" parent="android:Theme.Material.Light.NoActionBar" />
|
||||
</resources>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample backup rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/guide/topics/data/autobackup
|
||||
for details.
|
||||
Note: This file is ignored for devices older than API 31
|
||||
See https://developer.android.com/about/versions/12/backup-restore
|
||||
-->
|
||||
<full-backup-content>
|
||||
<!--
|
||||
<include domain="sharedpref" path="."/>
|
||||
<exclude domain="sharedpref" path="device.xml"/>
|
||||
-->
|
||||
</full-backup-content>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample data extraction rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
|
||||
for details.
|
||||
-->
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<!-- TODO: Use <include> and <exclude> to control what is backed up.
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
-->
|
||||
</cloud-backup>
|
||||
<!--
|
||||
<device-transfer>
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
</device-transfer>
|
||||
-->
|
||||
</data-extraction-rules>
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.lzxnone.openloc
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||