Compare commits
13
Commits
2f5b852e00
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc60b0de15 | ||
|
|
b039f610b3 | ||
|
|
c8c63046bc | ||
|
|
ac59cf842c | ||
|
|
df9eb548cb | ||
|
|
253f3c72b1 | ||
|
|
7b0d5b802d | ||
|
|
32fa4a611a | ||
|
|
6ffa7d8108 | ||
|
|
07abd416b6 | ||
|
|
ee7b7d3666 | ||
|
|
02a206d384 | ||
|
|
8b49607efe |
No files matched your search
@@ -1,76 +0,0 @@
|
|||||||
name: Release OpenLoc APKs
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build & Publish Release
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout Code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up JDK 21
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
distribution: 'temurin'
|
|
||||||
java-version: '21'
|
|
||||||
cache: 'gradle'
|
|
||||||
|
|
||||||
- name: Grant Execute Permission for Gradlew
|
|
||||||
run: chmod +x gradlew
|
|
||||||
|
|
||||||
- name: Restore Keystore from Secrets (If Configured)
|
|
||||||
env:
|
|
||||||
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
|
||||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
|
||||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
|
||||||
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
|
|
||||||
run: |
|
|
||||||
if [ -n "$KEYSTORE_BASE64" ]; then
|
|
||||||
echo "Restoring official keystore..."
|
|
||||||
echo "$KEYSTORE_BASE64" | base64 -d > app/openloc.jks
|
|
||||||
cat <<EOF > keystore.properties
|
|
||||||
storeFile=openloc.jks
|
|
||||||
storePassword=${KEYSTORE_PASSWORD}
|
|
||||||
keyAlias=${KEY_ALIAS}
|
|
||||||
keyPassword=${KEY_PASSWORD}
|
|
||||||
EOF
|
|
||||||
else
|
|
||||||
echo "No custom keystore secret provided, fallback signing will be used."
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Run Tests & Build Release APKs
|
|
||||||
run: ./gradlew testDebugUnitTest assembleRelease --stacktrace
|
|
||||||
|
|
||||||
- name: Prepare Architecture Assets
|
|
||||||
run: |
|
|
||||||
TAG_NAME="${GITHUB_REF_NAME:-latest}"
|
|
||||||
cd app/build/outputs/apk/release/
|
|
||||||
cp app-universal-release.apk "OpenLoc-${TAG_NAME}-universal.apk"
|
|
||||||
cp app-arm64-v8a-release.apk "OpenLoc-${TAG_NAME}-arm64-v8a.apk"
|
|
||||||
cp app-armeabi-v7a-release.apk "OpenLoc-${TAG_NAME}-armeabi-v7a.apk"
|
|
||||||
cp app-x86_64-release.apk "OpenLoc-${TAG_NAME}-x86_64.apk"
|
|
||||||
cp app-x86-release.apk "OpenLoc-${TAG_NAME}-x86.apk"
|
|
||||||
ls -la OpenLoc-*.apk
|
|
||||||
|
|
||||||
- name: Publish GitHub Release & Upload Assets
|
|
||||||
uses: softprops/action-gh-release@v2
|
|
||||||
with:
|
|
||||||
files: |
|
|
||||||
app/build/outputs/apk/release/OpenLoc-*-universal.apk
|
|
||||||
app/build/outputs/apk/release/OpenLoc-*-arm64-v8a.apk
|
|
||||||
app/build/outputs/apk/release/OpenLoc-*-armeabi-v7a.apk
|
|
||||||
app/build/outputs/apk/release/OpenLoc-*-x86_64.apk
|
|
||||||
app/build/outputs/apk/release/OpenLoc-*-x86.apk
|
|
||||||
generate_release_notes: true
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
@@ -1,44 +1,70 @@
|
|||||||
<div align="center">
|
<p align="center">
|
||||||
|
<img src="assets/logo.png" width="128" height="128" alt="OpenLoc Logo" />
|
||||||
|
</p>
|
||||||
|
|
||||||
<img src="assets/logo.png" width="128" height="128" alt="OpenLoc Logo" />
|
<h1 align="center">OpenLoc</h1>
|
||||||
|
|
||||||
# OpenLoc
|
<p align="center">
|
||||||
|
专为 Android 平台设计的现代地理位置模拟与隐私辅助工具
|
||||||
专为 Android 平台设计的现代地理位置模拟与隐私辅助工具
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://img.shields.io/badge/Platform-Android-3DDC84?style=flat-square&logo=android&logoColor=white" alt="Platform" />
|
<img src="https://img.shields.io/badge/Platform-Android-3DDC84?style=flat-square&logo=android&logoColor=white" alt="Platform" />
|
||||||
<img src="https://img.shields.io/badge/Language-Kotlin-7F52FF?style=flat-square&logo=kotlin&logoColor=white" alt="Language" />
|
<img src="https://img.shields.io/badge/Language-Kotlin-7F52FF?style=flat-square&logo=kotlin&logoColor=white" alt="Language" />
|
||||||
<img src="https://img.shields.io/badge/UI-Jetpack_Compose_/_Material_3-4285F4?style=flat-square&logo=jetpackcompose&logoColor=white" alt="UI" />
|
<img src="https://img.shields.io/badge/UI-Jetpack%20Compose%20%2F%20Material%203-4285F4?style=flat-square&logo=jetpackcompose&logoColor=white" alt="UI" />
|
||||||
<img src="https://img.shields.io/badge/Privacy-Local_Only-00C853?style=flat-square" alt="Privacy" />
|
<br>
|
||||||
|
<img src="https://img.shields.io/badge/Privacy-Local%20Only-00C853?style=flat-square" alt="Privacy" />
|
||||||
<img src="https://img.shields.io/badge/License-GPL--3.0-007AFF?style=flat-square" alt="License" />
|
<img src="https://img.shields.io/badge/License-GPL--3.0-007AFF?style=flat-square" alt="License" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
<p align="center">
|
||||||
|
<b>简体中文</b> | <a href="README_EN.md">English</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 软件用途
|
OpenLoc 旨在为开发者、测试人员以及关注个人数字隐私的用户提供安全、可控且纯净的位置环境模拟服务。基于 Xposed / LSPosed 运行时注入与现代 Android 架构设计,提供高拟真、无残留的多维环境模拟能力。
|
||||||
|
|
||||||
OpenLoc 旨在为开发者、测试人员以及关注个人数字隐私的用户提供安全、可控且纯净的位置环境模拟服务,主要用于以下场景:
|
---
|
||||||
|
|
||||||
- **位置环境模拟**
|
## 核心实现架构
|
||||||
支持在地图上自由选定目标位置或精确检索地理坐标,为应用提供自定义的虚拟定位环境,便于进行基于位置的应用功能开发与场景联调。
|
|
||||||
|
|
||||||
- **应用作用域管控**
|
### 1. 底层 Hook 与多维定位拦截
|
||||||
支持全局模式、黑名单模式与白名单模式,用户可灵活指定哪些应用接收模拟位置、哪些应用使用真实网络环境,避免影响日常无关应用的正常使用。
|
- **系统层级深度劫持**:通过 Xposed 框架深度挂钩 Android 系统底层 `LocationManagerService`、网络定位提供者及第三方 NLP 接口,接管全球卫星导航、网络基站与 Wi-Fi 扫描结果。
|
||||||
|
- **内存级模拟脱敏**:在内存对象层实时抹除 `isMock` 与 `mIsFromMockProvider` 标志,从源头消除底层定位模拟特征。
|
||||||
|
- **模块包名自隐匿**:针对受控目标应用动态隐藏 OpenLoc 自身的安装包信息,有效防御应用通过 `PackageManager` 扫描安装列表以识别模块存在的行为。
|
||||||
|
|
||||||
- **常用地点快捷收藏**
|
### 2. 多维拟真与防检测矩阵
|
||||||
提供便捷的地点收藏与管理功能,支持常用测试点位或兴趣位置的自定义命名、快速切换与拖拽排序。
|
- **自然位置微漂移**:采用高斯平滑滤波与布朗运动随机游走模型,动态生成拟真经纬度微小漂移,防止因坐标绝对静止触发服务端风控策略。
|
||||||
|
- **全星座卫星信号仿真**:支持 GPS、北斗(BeiDou)、GLONASS、Galileo 等主流卫星星座的物理载噪比与伪距仿真,动态生成合规的全量 NMEA GSV/GSA 报文流。
|
||||||
|
- **生物手持生理拟真**:向设备传感器层注入微弱的生理微颤信号,模拟手持设备日常轻微晃动,规避步态与姿态静止监测。
|
||||||
|
- **基站小区与 Wi-Fi 防反查**:针对周围蜂窝基站(Cell Tower)与 Wi-Fi 接入点(BSSID)进行脱敏混淆,杜绝目标应用上传网络指纹至云端数据库反查真实物理位置。
|
||||||
|
|
||||||
- **多维环境拟真与隐私防护**
|
### 3. 应用作用域精细化管控
|
||||||
在提供虚拟坐标的同时,协同拟真设备在日常手持、运动状态下的环境表现,避免单一静态坐标导致的数据异常,有效防止个人真实物理行踪的过度获取与隐私泄露。
|
- **多维度生效策略**:
|
||||||
|
- **全局模式**:整机所有应用统一接收模拟位置。
|
||||||
|
- **黑名单模式**:黑名单内的特定应用保持真实物理定位,其余应用接收模拟位置。
|
||||||
|
- **白名单模式**:仅白名单指定的应用接收模拟位置,其余应用保持真实定位。
|
||||||
|
- **高效应用检索**:内置快速搜索、分类筛选(系统应用/用户应用)以及全选/全不选批处理能力。
|
||||||
|
|
||||||
- **纯粹无干扰的交互体验**
|
### 4. 交互式地图与地点管理
|
||||||
基于 Material 3 现代设计语言构建,界面简洁直观,无后台冗余常驻,注重工具属性的克制与易用性。
|
- **现代化地图选点**:集成 OpenStreetMap 地图引擎,提供流畅的手势选点、缩放与精准坐标拾取体验。
|
||||||
|
- **多引擎智能检索**:支持高德地图、百度地图、Photon、Nominatim 等多元化位置搜索引擎与经纬度坐标直达。
|
||||||
|
- **常用地点收藏夹**:支持收藏自定义命名地点,提供即时选定、拖拽排序与离线存储管理。
|
||||||
|
|
||||||
|
### 5. 纯净体验与全站国际化
|
||||||
|
- **Jetpack Compose & Material 3**:采用现代声明式 UI 体系构建,深度支持 Material You 壁纸动态取色与多套质感主题色切换。
|
||||||
|
- **全站国际化(i18n)**:UI 界面文字完全解耦,支持简体中文与英文多语言环境,严格禁止硬编码。
|
||||||
|
- **本地纯净运行**:无任何非必要的后台常驻常驻驻留进程,隐私数据完全保留于设备本地。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 免责声明
|
## 免责声明
|
||||||
|
|
||||||
本软件仅供合法的软件开发调试、学术研究、定位功能测试及个人隐私保护使用,请勿用于任何违反法律法规或破坏第三方服务协议的用途。
|
本软件仅供合法的软件开发调试、学术研究、定位功能测试及个人隐私保护使用,请勿用于任何违反法律法规或破坏第三方服务协议的用途。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 开源协议
|
||||||
|
|
||||||
|
本项目基于 **GNU General Public License v3.0 (GPL-3.0)** 协议开源。详细条款请参阅 [LICENSE](LICENSE) 文件。
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<p align="center">
|
||||||
|
<img src="assets/logo.png" width="128" height="128" alt="OpenLoc Logo" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h1 align="center">OpenLoc</h1>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
A modern location simulation and privacy assistant tailored for the Android platform
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://img.shields.io/badge/Platform-Android-3DDC84?style=flat-square&logo=android&logoColor=white" alt="Platform" />
|
||||||
|
<img src="https://img.shields.io/badge/Language-Kotlin-7F52FF?style=flat-square&logo=kotlin&logoColor=white" alt="Language" />
|
||||||
|
<img src="https://img.shields.io/badge/UI-Jetpack%20Compose%20%2F%20Material%203-4285F4?style=flat-square&logo=jetpackcompose&logoColor=white" alt="UI" />
|
||||||
|
<br>
|
||||||
|
<img src="https://img.shields.io/badge/Privacy-Local%20Only-00C853?style=flat-square" alt="Privacy" />
|
||||||
|
<img src="https://img.shields.io/badge/License-GPL--3.0-007AFF?style=flat-square" alt="License" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="README.md">简体中文</a> | <b>English</b>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
OpenLoc is designed for developers, QA engineers, and privacy-conscious users who require a secure, controllable, and clean mock location environment. Built on top of runtime hooking via Xposed / LSPosed alongside modern Android architectural components, OpenLoc delivers high-fidelity, residue-free multi-dimensional environmental simulation.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Core Architecture & Implementation
|
||||||
|
|
||||||
|
### 1. Low-Level Hooking & Multi-Dimensional Geolocation Interception
|
||||||
|
- **System-Level Deep Hooking**: Deeply hooks into Android's core `LocationManagerService`, network location providers, and third-party NLP frameworks via Xposed to intercept GNSS data, cellular base station scans, and Wi-Fi networks.
|
||||||
|
- **In-Memory Mock Flag Sanitization**: Clears the `isMock` and `mIsFromMockProvider` fields in memory objects in real time, eliminating fundamental mock location signatures at the source.
|
||||||
|
- **Module Package Self-Stealth**: Transparently conceals OpenLoc's own package information from monitored applications, defeating detection mechanisms that scan installed packages via `PackageManager`.
|
||||||
|
|
||||||
|
### 2. Multi-Dimensional Realism & Anti-Detection Matrix
|
||||||
|
- **Natural Location Drift**: Employs Gaussian smoothing and Brownian motion random walk models to dynamically generate lifelike subtle coordinate drifts, preventing risk control alarms triggered by absolute static coordinates.
|
||||||
|
- **Full Constellation GNSS Simulation**: Simulates physical Carrier-to-Noise ratio (C/N0) and pseudoranges across GPS, BeiDou, GLONASS, and Galileo constellations, generating compliant full-stream NMEA GSV/GSA sentences.
|
||||||
|
- **Physiological Micro-Tremor Simulation**: Injects subtle physiological tremors into the device's accelerometer sensors, replicating natural handheld micro-movements to bypass gait and stationary posture detections.
|
||||||
|
- **Cell Tower & Wi-Fi Camouflage**: Sanitizes and obfuscates nearby cellular cell identifiers and Wi-Fi BSSIDs, preventing apps from querying cloud fingerprint databases to trace real physical locations.
|
||||||
|
|
||||||
|
### 3. Granular Application Scope Management
|
||||||
|
- **Versatile Scope Policies**:
|
||||||
|
- **Global Mode**: All applications across the system receive simulated coordinates.
|
||||||
|
- **Blacklist Mode**: Designated blacklisted applications retain real physical positioning, while all other applications receive simulated locations.
|
||||||
|
- **Whitelist Mode**: Only explicitly whitelisted applications receive simulated locations, leaving all other applications untouched.
|
||||||
|
- **Intuitive App Selector**: Equipped with fast search indexing, category filtering (System vs. User apps), and bulk selection capabilities.
|
||||||
|
|
||||||
|
### 4. Interactive Map & Favorites Management
|
||||||
|
- **Modern Map Interaction**: Integrated with OpenStreetMap engine for fluid gestures, smooth zooming, and accurate coordinate selection.
|
||||||
|
- **Multi-Engine Geosearch**: Supports diverse search providers including AMap, Baidu Maps, Photon, and Nominatim, with direct coordinate jump functionality.
|
||||||
|
- **Favorites & Waypoints**: Save and name custom locations with instant switching, drag-to-reorder, and persistent local storage.
|
||||||
|
|
||||||
|
### 5. Clean Experience & Internationalization
|
||||||
|
- **Jetpack Compose & Material 3**: Built with a modern declarative UI framework, supporting Material You dynamic color extraction and customizable palette themes with light/dark modes.
|
||||||
|
- **Strict Internationalization (i18n)**: All UI strings are completely decoupled with zero hardcoded text, providing comprehensive native support for Simplified Chinese and English.
|
||||||
|
- **Pure Local Execution**: Zero background daemon overhead and zero external analytics; all privacy configurations remain strictly on the local device.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Disclaimer
|
||||||
|
|
||||||
|
This software is intended solely for legitimate software development, academic research, geolocation testing, and personal privacy protection. Please do not use it for any activity that violates laws, regulations, or third-party service agreements.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This project is licensed under the **GNU General Public License v3.0 (GPL-3.0)**. See the [LICENSE](LICENSE) file for details.
|
||||||
+7
-10
@@ -18,19 +18,14 @@ android {
|
|||||||
applicationId = "com.lzxnone.openloc"
|
applicationId = "com.lzxnone.openloc"
|
||||||
minSdk = 28
|
minSdk = 28
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 2
|
versionCode = 10
|
||||||
versionName = "1.1.0"
|
versionName = "1.3.2"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|
||||||
splits {
|
base {
|
||||||
abi {
|
archivesName.set("OpenLoc-v${defaultConfig.versionName}")
|
||||||
isEnable = true
|
|
||||||
reset()
|
|
||||||
include("armeabi-v7a", "arm64-v8a", "x86", "x86_64")
|
|
||||||
isUniversalApk = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,7 +55,8 @@ android {
|
|||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
isMinifyEnabled = false
|
isMinifyEnabled = true
|
||||||
|
isShrinkResources = true
|
||||||
signingConfig = signingConfigs.getByName("release")
|
signingConfig = signingConfigs.getByName("release")
|
||||||
proguardFiles(
|
proguardFiles(
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
@@ -75,6 +71,7 @@ android {
|
|||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
compose = true
|
compose = true
|
||||||
|
buildConfig = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+22
-18
@@ -1,21 +1,25 @@
|
|||||||
# Add project specific ProGuard rules here.
|
# 仅代码裁剪(Tree Shaking),完全禁用重命名混淆
|
||||||
# You can control the set of applied configuration files using the
|
-dontobfuscate
|
||||||
# proguardFiles setting in build.gradle.
|
-dontoptimize
|
||||||
#
|
|
||||||
# For more details, see
|
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
||||||
|
|
||||||
# If your project uses WebView with JS, uncomment the following
|
# 保留调试堆栈信息与注解签名
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
-keepattributes SourceFile,LineNumberTable,InnerClasses,EnclosingMethod,Exceptions,Signature
|
||||||
# class:
|
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
||||||
# public *;
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Uncomment this to preserve the line number information for
|
# 保持 Android 基础组件(Activity, Provider 等)
|
||||||
# debugging stack traces.
|
-keep public class * extends android.app.Activity
|
||||||
#-keepattributes SourceFile,LineNumberTable
|
-keep public class * extends android.app.Application
|
||||||
|
-keep public class * extends android.app.Service
|
||||||
|
-keep public class * extends android.content.BroadcastReceiver
|
||||||
|
-keep public class * extends android.content.ContentProvider
|
||||||
|
|
||||||
# If you keep the line number information, uncomment this to
|
# 保持 Xposed / LSPosed 钩子入口及所有 Hook 类(在目标进程反射加载)
|
||||||
# hide the original source file name.
|
-keep class com.lzxnone.openloc.hook.** { *; }
|
||||||
#-renamesourcefileattribute SourceFile
|
|
||||||
|
# 保持数据模型与配置实体
|
||||||
|
-keep class com.lzxnone.openloc.data.model.** { *; }
|
||||||
|
-keep class com.lzxnone.openloc.hook.model.** { *; }
|
||||||
|
-keep class com.lzxnone.openloc.core.provider.** { *; }
|
||||||
|
|
||||||
|
# 保持 osmdroid 地图库必须的反射类与组件
|
||||||
|
-keep class org.osmdroid.** { *; }
|
||||||
|
-dontwarn org.osmdroid.**
|
||||||
@@ -6,6 +6,9 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<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_FINE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.QUERY_ALL_PACKAGES"
|
android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||||
tools:ignore="QueryAllPackagesPermission" />
|
tools:ignore="QueryAllPackagesPermission" />
|
||||||
@@ -51,6 +54,12 @@
|
|||||||
android:authorities="com.lzxnone.openloc.provider"
|
android:authorities="com.lzxnone.openloc.provider"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
tools:ignore="ExportedContentProvider" />
|
tools:ignore="ExportedContentProvider" />
|
||||||
|
|
||||||
|
<!-- 后台常驻前台定位服务 -->
|
||||||
|
<service
|
||||||
|
android:name=".core.service.MockLocationForegroundService"
|
||||||
|
android:exported="false"
|
||||||
|
android:foregroundServiceType="location" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -30,8 +30,11 @@ class LocationConfigProvider : ContentProvider() {
|
|||||||
val prefs = ctx.getSharedPreferences("openloc_prefs", Context.MODE_PRIVATE)
|
val prefs = ctx.getSharedPreferences("openloc_prefs", Context.MODE_PRIVATE)
|
||||||
|
|
||||||
val isEnabled = prefs.getBoolean("mock_service_enabled", false)
|
val isEnabled = prefs.getBoolean("mock_service_enabled", false)
|
||||||
val lat = prefs.getString("mock_latitude", "39.908722")?.toDoubleOrNull() ?: 39.908722
|
val runtime = AppPreferences.getRuntimeMockState()
|
||||||
val lng = prefs.getString("mock_longitude", "116.397496")?.toDoubleOrNull() ?: 116.397496
|
val lat = if (isEnabled) runtime.latitude else (prefs.getString("mock_latitude", "39.908722")?.toDoubleOrNull() ?: 39.908722)
|
||||||
|
val lng = if (isEnabled) runtime.longitude else (prefs.getString("mock_longitude", "116.397496")?.toDoubleOrNull() ?: 116.397496)
|
||||||
|
val speed = if (isEnabled) runtime.speed else 0.0f
|
||||||
|
val bearing = if (isEnabled) runtime.bearing else 0.0f
|
||||||
val name = prefs.getString("mock_location_name", "") ?: ""
|
val name = prefs.getString("mock_location_name", "") ?: ""
|
||||||
val mode = prefs.getString("app_mock_mode", "GLOBAL") ?: "GLOBAL"
|
val mode = prefs.getString("app_mock_mode", "GLOBAL") ?: "GLOBAL"
|
||||||
val whitelistJson = prefs.getString("whitelist_apps", "[]") ?: "[]"
|
val whitelistJson = prefs.getString("whitelist_apps", "[]") ?: "[]"
|
||||||
@@ -47,6 +50,10 @@ class LocationConfigProvider : ContentProvider() {
|
|||||||
putBoolean(ConfigContract.KEY_ENABLED, isEnabled)
|
putBoolean(ConfigContract.KEY_ENABLED, isEnabled)
|
||||||
putDouble(ConfigContract.KEY_LATITUDE, lat)
|
putDouble(ConfigContract.KEY_LATITUDE, lat)
|
||||||
putDouble(ConfigContract.KEY_LONGITUDE, lng)
|
putDouble(ConfigContract.KEY_LONGITUDE, lng)
|
||||||
|
putDouble("altitude", 50.0)
|
||||||
|
putFloat("accuracy", 5.0f)
|
||||||
|
putFloat("bearing", bearing)
|
||||||
|
putFloat("speed", speed)
|
||||||
putString(ConfigContract.KEY_LOCATION_NAME, name)
|
putString(ConfigContract.KEY_LOCATION_NAME, name)
|
||||||
putString(ConfigContract.KEY_APP_MOCK_MODE, mode)
|
putString(ConfigContract.KEY_APP_MOCK_MODE, mode)
|
||||||
putString(ConfigContract.KEY_WHITELIST_APPS, whitelistJson)
|
putString(ConfigContract.KEY_WHITELIST_APPS, whitelistJson)
|
||||||
|
|||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package com.lzxnone.openloc.core.service
|
||||||
|
|
||||||
|
import android.app.AlarmManager
|
||||||
|
import android.app.Notification
|
||||||
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.app.Service
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.ServiceInfo
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.IBinder
|
||||||
|
import android.os.SystemClock
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
import com.lzxnone.openloc.MainActivity
|
||||||
|
import com.lzxnone.openloc.R
|
||||||
|
import com.lzxnone.openloc.data.preference.AppPreferences
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后台常驻前台服务:防止 OpenLoc 切到后台后被系统冻结,保障 1Hz 连续定位与跑步平滑推进不中断
|
||||||
|
*/
|
||||||
|
class MockLocationForegroundService : Service() {
|
||||||
|
|
||||||
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
AppPreferences.init(applicationContext)
|
||||||
|
createNotificationChannel()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
if (!AppPreferences.isServiceEnabled || !AppPreferences.isNotificationEnabled) {
|
||||||
|
stopSelf()
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
|
|
||||||
|
val notification = buildNotification(this)
|
||||||
|
try {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
startForeground(
|
||||||
|
NOTIFICATION_ID,
|
||||||
|
notification,
|
||||||
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
startForeground(NOTIFICATION_ID, notification)
|
||||||
|
}
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
try {
|
||||||
|
startForeground(NOTIFICATION_ID, notification)
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
AppPreferences.ensureTickerRunning()
|
||||||
|
return START_STICKY
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||||
|
if (AppPreferences.isServiceEnabled && AppPreferences.isNotificationEnabled) {
|
||||||
|
try {
|
||||||
|
val restartIntent = Intent(applicationContext, MockLocationForegroundService::class.java)
|
||||||
|
val pendingIntentFlags = PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||||
|
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
PendingIntent.getForegroundService(applicationContext, RESTART_REQUEST_CODE, restartIntent, pendingIntentFlags)
|
||||||
|
} else {
|
||||||
|
PendingIntent.getService(applicationContext, RESTART_REQUEST_CODE, restartIntent, pendingIntentFlags)
|
||||||
|
}
|
||||||
|
val alarmManager = getSystemService(Context.ALARM_SERVICE) as? AlarmManager
|
||||||
|
alarmManager?.set(
|
||||||
|
AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
||||||
|
SystemClock.elapsedRealtime() + 1000L,
|
||||||
|
pendingIntent
|
||||||
|
)
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
super.onTaskRemoved(rootIntent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createNotificationChannel() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager ?: return
|
||||||
|
val channel = NotificationChannel(
|
||||||
|
CHANNEL_ID,
|
||||||
|
getString(R.string.service_keepalive_channel_name),
|
||||||
|
NotificationManager.IMPORTANCE_LOW
|
||||||
|
).apply {
|
||||||
|
setShowBadge(false)
|
||||||
|
}
|
||||||
|
manager.createNotificationChannel(channel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val CHANNEL_ID = "openloc_keepalive"
|
||||||
|
private const val NOTIFICATION_ID = 10086
|
||||||
|
private const val RESTART_REQUEST_CODE = 10087
|
||||||
|
|
||||||
|
fun buildNotification(context: Context): Notification {
|
||||||
|
val launchIntent = Intent(context, MainActivity::class.java).apply {
|
||||||
|
flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
}
|
||||||
|
val pendingIntent = PendingIntent.getActivity(
|
||||||
|
context,
|
||||||
|
0,
|
||||||
|
launchIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
|
|
||||||
|
val title = context.getString(R.string.service_keepalive_title)
|
||||||
|
val desc = context.getString(R.string.service_keepalive_desc)
|
||||||
|
val largeIcon = try {
|
||||||
|
BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher_round)
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
return NotificationCompat.Builder(context, CHANNEL_ID)
|
||||||
|
.setSmallIcon(R.mipmap.ic_launcher)
|
||||||
|
.apply {
|
||||||
|
if (largeIcon != null) {
|
||||||
|
setLargeIcon(largeIcon)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.setContentTitle(title)
|
||||||
|
.setContentText(desc)
|
||||||
|
.setOngoing(true)
|
||||||
|
.setOnlyAlertOnce(true)
|
||||||
|
.setSilent(true)
|
||||||
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
|
.setContentIntent(pendingIntent)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateNotification(context: Context) {
|
||||||
|
if (!AppPreferences.isServiceEnabled || !AppPreferences.isNotificationEnabled) return
|
||||||
|
try {
|
||||||
|
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager ?: return
|
||||||
|
manager.notify(NOTIFICATION_ID, buildNotification(context))
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun start(context: Context) {
|
||||||
|
try {
|
||||||
|
val intent = Intent(context, MockLocationForegroundService::class.java)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
context.startForegroundService(intent)
|
||||||
|
} else {
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stop(context: Context) {
|
||||||
|
try {
|
||||||
|
context.stopService(Intent(context, MockLocationForegroundService::class.java))
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,103 +1,162 @@
|
|||||||
package com.lzxnone.openloc.core.util
|
package com.lzxnone.openloc.core.util
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import com.lzxnone.openloc.BuildConfig
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import java.io.BufferedReader
|
||||||
|
import java.io.InputStreamReader
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 版本更新信息
|
* 版本更新信息
|
||||||
*/
|
*/
|
||||||
data class UpdateInfo(
|
data class UpdateInfo(
|
||||||
val hasUpdate: Boolean,
|
val versionCode: Long,
|
||||||
val latestVersion: String,
|
val versionName: String,
|
||||||
val currentVersion: String,
|
|
||||||
val releaseTitle: String,
|
|
||||||
val changelog: String,
|
val changelog: String,
|
||||||
val releaseUrl: String
|
val downloadUrl: String,
|
||||||
)
|
val apkSize: String = ""
|
||||||
|
) {
|
||||||
|
val hasUpdate: Boolean
|
||||||
|
get() = UpdateChecker.isNewerVersion(versionName, BuildConfig.VERSION_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GitHub Releases 版本更新检查器
|
* Gitea Releases 版本更新检查器
|
||||||
*/
|
*/
|
||||||
object UpdateChecker {
|
object UpdateChecker {
|
||||||
private const val GITHUB_API_URL = "https://api.github.com/repos/lzxnone/openloc/releases/latest"
|
private const val UPDATE_URL = "https://gitea.lzxnone.cloud/api/v1/repos/lzxnone/OpenLoc/releases/latest"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查 GitHub 是否有新版本
|
* 检查是否有新版本
|
||||||
*/
|
*/
|
||||||
suspend fun checkUpdate(currentVersion: String = "v1.1.0"): Result<UpdateInfo> = withContext(Dispatchers.IO) {
|
suspend fun checkUpdate(): Result<UpdateInfo> = withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val url = URL(GITHUB_API_URL)
|
val url = URL(UPDATE_URL)
|
||||||
val conn = (url.openConnection() as HttpURLConnection).apply {
|
val connection = (url.openConnection() as HttpURLConnection).apply {
|
||||||
requestMethod = "GET"
|
|
||||||
connectTimeout = 8000
|
connectTimeout = 8000
|
||||||
readTimeout = 8000
|
readTimeout = 8000
|
||||||
setRequestProperty("Accept", "application/vnd.github.v3+json")
|
requestMethod = "GET"
|
||||||
setRequestProperty("User-Agent", "OpenLoc-App")
|
setRequestProperty("Accept", "application/json")
|
||||||
|
setRequestProperty("User-Agent", "OpenLoc-Android")
|
||||||
}
|
}
|
||||||
|
|
||||||
val code = conn.responseCode
|
val responseCode = connection.responseCode
|
||||||
if (code == 200) {
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
val responseText = conn.inputStream.bufferedReader().use { it.readText() }
|
val reader = BufferedReader(InputStreamReader(connection.inputStream, Charsets.UTF_8))
|
||||||
val json = JSONObject(responseText)
|
val response = reader.use { it.readText() }
|
||||||
val tagName = json.optString("tag_name", "").trim()
|
connection.disconnect()
|
||||||
val title = json.optString("name", tagName).trim()
|
|
||||||
val body = json.optString("body", "").trim()
|
|
||||||
val htmlUrl = json.optString("html_url", "https://github.com/lzxnone/openloc/releases").trim()
|
|
||||||
|
|
||||||
val hasUpdate = isNewerVersion(tagName, currentVersion)
|
Result.success(parseReleaseJson(response))
|
||||||
Result.success(
|
|
||||||
UpdateInfo(
|
|
||||||
hasUpdate = hasUpdate,
|
|
||||||
latestVersion = tagName.ifEmpty { currentVersion },
|
|
||||||
currentVersion = currentVersion,
|
|
||||||
releaseTitle = title.ifEmpty { tagName },
|
|
||||||
changelog = body,
|
|
||||||
releaseUrl = htmlUrl
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else if (code == 404) {
|
|
||||||
// 仓库尚未发布任何 Release 时 GitHub 会返回 404
|
|
||||||
Result.success(
|
|
||||||
UpdateInfo(
|
|
||||||
hasUpdate = false,
|
|
||||||
latestVersion = currentVersion,
|
|
||||||
currentVersion = currentVersion,
|
|
||||||
releaseTitle = "",
|
|
||||||
changelog = "",
|
|
||||||
releaseUrl = "https://github.com/lzxnone/openloc/releases"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
Result.failure(Exception("HTTP $code"))
|
connection.disconnect()
|
||||||
|
Result.failure(Exception("HTTP error $responseCode"))
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Result.failure(e)
|
Result.failure(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
internal fun parseReleaseJson(
|
||||||
* 比较版本号:remote > current 则返回 true
|
response: String,
|
||||||
*/
|
supportedAbis: Array<String> = Build.SUPPORTED_ABIS ?: emptyArray()
|
||||||
fun isNewerVersion(remoteTag: String, currentVer: String): Boolean {
|
): UpdateInfo {
|
||||||
if (remoteTag.isBlank()) return false
|
val json = JSONObject(response)
|
||||||
val cleanRemote = remoteTag.trim().removePrefix("v").removePrefix("V")
|
val rawTag = json.optString("tag_name", "").trim()
|
||||||
val cleanCurrent = currentVer.trim().removePrefix("v").removePrefix("V")
|
val versionName = rawTag.removePrefix("v").removePrefix("V")
|
||||||
|
val versionCode = parseVersionCode(versionName)
|
||||||
|
val changelog = json.optString("body", "").ifBlank {
|
||||||
|
json.optString("name", "")
|
||||||
|
}
|
||||||
|
|
||||||
val remoteParts = cleanRemote.split(".").mapNotNull { it.toIntOrNull() }
|
val (downloadUrl, apkSize) = selectApkAsset(
|
||||||
val currentParts = cleanCurrent.split(".").mapNotNull { it.toIntOrNull() }
|
assets = json.optJSONArray("assets"),
|
||||||
|
supportedAbis = supportedAbis,
|
||||||
|
fallbackUrl = json.optString("html_url", "")
|
||||||
|
)
|
||||||
|
|
||||||
|
return UpdateInfo(
|
||||||
|
versionCode = versionCode,
|
||||||
|
versionName = versionName,
|
||||||
|
changelog = changelog,
|
||||||
|
downloadUrl = downloadUrl,
|
||||||
|
apkSize = apkSize
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun selectApkAsset(
|
||||||
|
assets: JSONArray?,
|
||||||
|
supportedAbis: Array<String>,
|
||||||
|
fallbackUrl: String
|
||||||
|
): Pair<String, String> {
|
||||||
|
if (assets == null || assets.length() == 0) {
|
||||||
|
return fallbackUrl to ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val apkAssets = buildList {
|
||||||
|
for (i in 0 until assets.length()) {
|
||||||
|
val asset = assets.optJSONObject(i) ?: continue
|
||||||
|
val name = asset.optString("name", "")
|
||||||
|
val downloadUrl = asset.optString("browser_download_url", "")
|
||||||
|
val size = asset.optLong("size", 0L)
|
||||||
|
if (name.endsWith(".apk", ignoreCase = true) && downloadUrl.isNotBlank()) {
|
||||||
|
add(Triple(name, downloadUrl, size))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apkAssets.isEmpty()) {
|
||||||
|
return fallbackUrl to ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val matched = supportedAbis.firstNotNullOfOrNull { abi ->
|
||||||
|
apkAssets.firstOrNull { (name, _, _) ->
|
||||||
|
name.contains(abi, ignoreCase = true)
|
||||||
|
}
|
||||||
|
} ?: apkAssets.firstOrNull { (name, _, _) ->
|
||||||
|
name.contains("universal", ignoreCase = true)
|
||||||
|
} ?: apkAssets.first()
|
||||||
|
|
||||||
|
val sizeText = if (matched.third > 0L) {
|
||||||
|
String.format(Locale.US, "%.2f MB", matched.third / (1024.0 * 1024.0))
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
return matched.second to sizeText
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun isNewerVersion(remoteVersion: String, currentVersion: String): Boolean {
|
||||||
|
val remoteParts = parseVersionParts(remoteVersion)
|
||||||
|
val currentParts = parseVersionParts(currentVersion)
|
||||||
if (remoteParts.isEmpty()) return false
|
if (remoteParts.isEmpty()) return false
|
||||||
|
|
||||||
val maxLen = maxOf(remoteParts.size, currentParts.size)
|
val maxLen = maxOf(remoteParts.size, currentParts.size)
|
||||||
for (i in 0 until maxLen) {
|
for (i in 0 until maxLen) {
|
||||||
val r = remoteParts.getOrElse(i) { 0 }
|
val r = remoteParts.getOrElse(i) { 0 }
|
||||||
val c = currentParts.getOrElse(i) { 0 }
|
val c = currentParts.getOrElse(i) { 0 }
|
||||||
if (r > c) return true
|
if (r != c) return r > c
|
||||||
if (r < c) return false
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun parseVersionCode(versionName: String): Long {
|
||||||
|
val parts = parseVersionParts(versionName)
|
||||||
|
if (parts.isEmpty()) return 0L
|
||||||
|
val major = parts.getOrElse(0) { 0 }
|
||||||
|
val minor = parts.getOrElse(1) { 0 }
|
||||||
|
val patch = parts.getOrElse(2) { 0 }
|
||||||
|
return major * 10000L + minor * 100L + patch
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseVersionParts(version: String): List<Int> {
|
||||||
|
val cleaned = version.trim().removePrefix("v").removePrefix("V")
|
||||||
|
if (cleaned.isBlank()) return emptyList()
|
||||||
|
return cleaned.split(".")
|
||||||
|
.map { segment -> segment.takeWhile { it.isDigit() }.toIntOrNull() ?: 0 }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,11 @@ package com.lzxnone.openloc.data.preference
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.location.Location
|
||||||
import android.location.LocationManager
|
import android.location.LocationManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.HandlerThread
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableLongStateOf
|
import androidx.compose.runtime.mutableLongStateOf
|
||||||
@@ -17,6 +20,9 @@ import com.lzxnone.openloc.core.util.SearchResult
|
|||||||
import com.lzxnone.openloc.core.util.TraceLogger
|
import com.lzxnone.openloc.core.util.TraceLogger
|
||||||
import com.lzxnone.openloc.data.model.FavoriteItem
|
import com.lzxnone.openloc.data.model.FavoriteItem
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
||||||
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.sin
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
enum class ThemeMode(@param:StringRes val titleRes: Int) {
|
enum class ThemeMode(@param:StringRes val titleRes: Int) {
|
||||||
SYSTEM(R.string.settings_theme_mode_system),
|
SYSTEM(R.string.settings_theme_mode_system),
|
||||||
@@ -89,6 +95,7 @@ object AppPreferences {
|
|||||||
private const val KEY_DYNAMIC_COLOR = "dynamic_color"
|
private const val KEY_DYNAMIC_COLOR = "dynamic_color"
|
||||||
private const val KEY_LANGUAGE = "language"
|
private const val KEY_LANGUAGE = "language"
|
||||||
private const val KEY_SERVICE_ENABLED = "mock_service_enabled"
|
private const val KEY_SERVICE_ENABLED = "mock_service_enabled"
|
||||||
|
private const val KEY_NOTIFICATION_ENABLED = "enable_notification"
|
||||||
|
|
||||||
private lateinit var prefs: SharedPreferences
|
private lateinit var prefs: SharedPreferences
|
||||||
@Volatile
|
@Volatile
|
||||||
@@ -119,9 +126,12 @@ object AppPreferences {
|
|||||||
private const val KEY_ENABLE_GNSS_SIMULATION = "enable_gnss_simulation"
|
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_NETWORK_CAMOUFLAGE = "enable_network_camouflage"
|
||||||
private const val KEY_ENABLE_SENSOR_SIMULATION = "enable_sensor_simulation"
|
private const val KEY_ENABLE_SENSOR_SIMULATION = "enable_sensor_simulation"
|
||||||
|
private const val KEY_RUNNING_MODE_ENABLED = "running_mode_enabled"
|
||||||
|
private const val KEY_RUNNING_SPEED = "running_speed"
|
||||||
private const val KEY_ENABLE_STEALTH = "enable_stealth"
|
private const val KEY_ENABLE_STEALTH = "enable_stealth"
|
||||||
private const val KEY_ENABLE_DEV_CAMOUFLAGE = "enable_dev_camouflage"
|
private const val KEY_ENABLE_DEV_CAMOUFLAGE = "enable_dev_camouflage"
|
||||||
private const val KEY_AUTO_CHECK_UPDATE = "auto_check_update"
|
private const val KEY_AUTO_CHECK_UPDATE = "auto_check_update"
|
||||||
|
private const val KEY_SUPPRESSED_UPDATE_VERSION = "suppressed_update_version"
|
||||||
|
|
||||||
var appLanguage by mutableStateOf(AppLanguage.SYSTEM)
|
var appLanguage by mutableStateOf(AppLanguage.SYSTEM)
|
||||||
private set
|
private set
|
||||||
@@ -129,6 +139,9 @@ object AppPreferences {
|
|||||||
var isAutoCheckUpdateEnabled by mutableStateOf(true)
|
var isAutoCheckUpdateEnabled by mutableStateOf(true)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
var suppressedUpdateVersionCode by mutableLongStateOf(0L)
|
||||||
|
private set
|
||||||
|
|
||||||
|
|
||||||
var searchProvider by mutableStateOf(SearchProvider.AMAP)
|
var searchProvider by mutableStateOf(SearchProvider.AMAP)
|
||||||
private set
|
private set
|
||||||
@@ -154,6 +167,17 @@ object AppPreferences {
|
|||||||
var isSensorSimulationEnabled by mutableStateOf(true)
|
var isSensorSimulationEnabled by mutableStateOf(true)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
var isRunningModeEnabled by mutableStateOf(false)
|
||||||
|
private set
|
||||||
|
|
||||||
|
private val processToken = android.os.Binder()
|
||||||
|
|
||||||
|
var runningSpeedMps by androidx.compose.runtime.mutableFloatStateOf(3.0f)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var isNotificationEnabled by mutableStateOf(false)
|
||||||
|
private set
|
||||||
|
|
||||||
var isStealthEnabled by mutableStateOf(true)
|
var isStealthEnabled by mutableStateOf(true)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@@ -175,6 +199,96 @@ object AppPreferences {
|
|||||||
var isServiceEnabled by mutableStateOf(false)
|
var isServiceEnabled by mutableStateOf(false)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
// 1Hz 连续推进与三端联动实时状态(不依赖路线绘制 UI,自动平滑过渡近距离切点)
|
||||||
|
@Volatile private var activeLat: Double = 39.908722
|
||||||
|
@Volatile private var activeLng: Double = 116.397496
|
||||||
|
@Volatile private var activeSpeed: Float = 0.0f
|
||||||
|
@Volatile private var activeBearing: Float = 0.0f
|
||||||
|
@Volatile private var hasActivePoint: Boolean = false
|
||||||
|
|
||||||
|
internal data class RuntimeMockState(
|
||||||
|
val latitude: Double,
|
||||||
|
val longitude: Double,
|
||||||
|
val speed: Float,
|
||||||
|
val bearing: Float
|
||||||
|
)
|
||||||
|
|
||||||
|
internal fun getRuntimeMockState(): RuntimeMockState {
|
||||||
|
val pushLat = if (hasActivePoint) activeLat else mockLatitude
|
||||||
|
val pushLng = if (hasActivePoint) activeLng else mockLongitude
|
||||||
|
return RuntimeMockState(pushLat, pushLng, activeSpeed, activeBearing)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val tickerThread by lazy {
|
||||||
|
HandlerThread("OpenLoc-1Hz-Ticker").apply { start() }
|
||||||
|
}
|
||||||
|
private val tickerHandler by lazy { Handler(tickerThread.looper) }
|
||||||
|
@Volatile private var isTickerRunning = false
|
||||||
|
|
||||||
|
private val tickerRunnable = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
if (!isServiceEnabled) {
|
||||||
|
isTickerRunning = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
stepAndPush1Hz()
|
||||||
|
tickerHandler.postDelayed(this, 1000L)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ensureTickerRunning() {
|
||||||
|
startTickerIfNeeded()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startTickerIfNeeded() {
|
||||||
|
if (!isServiceEnabled || isTickerRunning) return
|
||||||
|
isTickerRunning = true
|
||||||
|
tickerHandler.removeCallbacks(tickerRunnable)
|
||||||
|
tickerHandler.postDelayed(tickerRunnable, 1000L)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopTicker() {
|
||||||
|
isTickerRunning = false
|
||||||
|
tickerHandler.removeCallbacks(tickerRunnable)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stepAndPush1Hz() {
|
||||||
|
if (!hasActivePoint) {
|
||||||
|
activeLat = mockLatitude
|
||||||
|
activeLng = mockLongitude
|
||||||
|
hasActivePoint = true
|
||||||
|
}
|
||||||
|
|
||||||
|
val results = FloatArray(2)
|
||||||
|
Location.distanceBetween(activeLat, activeLng, mockLatitude, mockLongitude, results)
|
||||||
|
val distMeters = results[0]
|
||||||
|
val initialBearing = results[1]
|
||||||
|
|
||||||
|
if (isRunningModeEnabled && distMeters in 2.5f..2500.0f) {
|
||||||
|
// 平滑推进:按用户设定的跑步速度(默认 3.0 m/s),带 ±8% 自然配速波动与微小横向摆动
|
||||||
|
val baseSpeed = runningSpeedMps.coerceIn(1.0f, 8.0f)
|
||||||
|
val paceFactor = 0.92f + Random.nextFloat() * 0.16f
|
||||||
|
val stepSpeed = (baseSpeed * paceFactor).coerceAtMost(distMeters)
|
||||||
|
val fraction = (stepSpeed / distMeters).toDouble().coerceIn(0.0, 1.0)
|
||||||
|
|
||||||
|
val swayDeg = if (isJitterEnabled) (Random.nextDouble() - 0.5) * 0.000004 else 0.0
|
||||||
|
activeLat += (mockLatitude - activeLat) * fraction + swayDeg
|
||||||
|
activeLng += (mockLongitude - activeLng) * fraction + swayDeg
|
||||||
|
activeSpeed = stepSpeed
|
||||||
|
activeBearing = ((initialBearing % 360f) + 360f) % 360f
|
||||||
|
} else {
|
||||||
|
// 已到达目标点或跨区远距离直达:保持 1Hz 心跳推送与微幅生理漂移
|
||||||
|
val jitterLat = if (isJitterEnabled) (Random.nextDouble() - 0.5) * 0.000008 else 0.0
|
||||||
|
val jitterLng = if (isJitterEnabled) (Random.nextDouble() - 0.5) * 0.000008 else 0.0
|
||||||
|
activeLat = mockLatitude + jitterLat
|
||||||
|
activeLng = mockLongitude + jitterLng
|
||||||
|
activeSpeed = 0.0f
|
||||||
|
activeBearing = 0.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
syncConfigToSystem(quiet = true)
|
||||||
|
}
|
||||||
|
|
||||||
var searchHistory by mutableStateOf<List<SearchResult>>(emptyList())
|
var searchHistory by mutableStateOf<List<SearchResult>>(emptyList())
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@@ -232,35 +346,58 @@ object AppPreferences {
|
|||||||
isGnssSimulationEnabled = prefs.getBoolean(KEY_ENABLE_GNSS_SIMULATION, true)
|
isGnssSimulationEnabled = prefs.getBoolean(KEY_ENABLE_GNSS_SIMULATION, true)
|
||||||
isNetworkCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_NETWORK_CAMOUFLAGE, true)
|
isNetworkCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_NETWORK_CAMOUFLAGE, true)
|
||||||
isSensorSimulationEnabled = prefs.getBoolean(KEY_ENABLE_SENSOR_SIMULATION, true)
|
isSensorSimulationEnabled = prefs.getBoolean(KEY_ENABLE_SENSOR_SIMULATION, true)
|
||||||
|
isRunningModeEnabled = prefs.getBoolean(KEY_RUNNING_MODE_ENABLED, false)
|
||||||
|
runningSpeedMps = prefs.getFloat(KEY_RUNNING_SPEED, 3.0f).coerceIn(1.0f, 8.0f)
|
||||||
|
isNotificationEnabled = prefs.getBoolean(KEY_NOTIFICATION_ENABLED, false)
|
||||||
isStealthEnabled = prefs.getBoolean(KEY_ENABLE_STEALTH, true)
|
isStealthEnabled = prefs.getBoolean(KEY_ENABLE_STEALTH, true)
|
||||||
isDevCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_DEV_CAMOUFLAGE, true)
|
isDevCamouflageEnabled = prefs.getBoolean(KEY_ENABLE_DEV_CAMOUFLAGE, true)
|
||||||
isAutoCheckUpdateEnabled = prefs.getBoolean(KEY_AUTO_CHECK_UPDATE, true)
|
isAutoCheckUpdateEnabled = prefs.getBoolean(KEY_AUTO_CHECK_UPDATE, true)
|
||||||
|
suppressedUpdateVersionCode = prefs.getLong(KEY_SUPPRESSED_UPDATE_VERSION, 0L)
|
||||||
|
|
||||||
|
activeLat = mockLatitude
|
||||||
|
activeLng = mockLongitude
|
||||||
|
hasActivePoint = hasUserSetLocation
|
||||||
|
|
||||||
syncConfigToSystem()
|
syncConfigToSystem()
|
||||||
|
if (isServiceEnabled) {
|
||||||
|
startTickerIfNeeded()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun syncConfigToSystem() {
|
fun syncConfigToSystem(quiet: Boolean = false) {
|
||||||
try {
|
try {
|
||||||
val ctx = appContext ?: return
|
val ctx = appContext ?: return
|
||||||
val lm = ctx.getSystemService(Context.LOCATION_SERVICE) as? LocationManager ?: return
|
val lm = ctx.getSystemService(Context.LOCATION_SERVICE) as? LocationManager ?: return
|
||||||
TraceLogger.i("AppPreferences", "syncConfigToSystem -> Enabled=$isServiceEnabled, Mock=($mockLatitude, $mockLongitude), Mode=${appMockMode.name}, Whitelist=${whitelistApps.size}, Blacklist=${blacklistApps.size}")
|
val pushLat = if (hasActivePoint) activeLat else mockLatitude
|
||||||
|
val pushLng = if (hasActivePoint) activeLng else mockLongitude
|
||||||
|
if (!quiet) {
|
||||||
|
TraceLogger.i("AppPreferences", "syncConfigToSystem -> Enabled=$isServiceEnabled, Mock=($pushLat, $pushLng), Speed=$activeSpeed, Bearing=$activeBearing, Mode=${appMockMode.name}, Whitelist=${whitelistApps.size}, Blacklist=${blacklistApps.size}")
|
||||||
|
}
|
||||||
val bundle = Bundle().apply {
|
val bundle = Bundle().apply {
|
||||||
putBoolean(GlobalMockMemory.EXTRA_ENABLED, isServiceEnabled)
|
putBoolean(GlobalMockMemory.EXTRA_ENABLED, isServiceEnabled)
|
||||||
putDouble(GlobalMockMemory.EXTRA_LATITUDE, mockLatitude)
|
putDouble(GlobalMockMemory.EXTRA_LATITUDE, pushLat)
|
||||||
putDouble(GlobalMockMemory.EXTRA_LONGITUDE, mockLongitude)
|
putDouble(GlobalMockMemory.EXTRA_LONGITUDE, pushLng)
|
||||||
putDouble(GlobalMockMemory.EXTRA_ALTITUDE, 50.0)
|
putDouble(GlobalMockMemory.EXTRA_ALTITUDE, 50.0)
|
||||||
putFloat(GlobalMockMemory.EXTRA_ACCURACY, 5.0f)
|
putFloat(GlobalMockMemory.EXTRA_ACCURACY, 5.0f)
|
||||||
|
putFloat(GlobalMockMemory.EXTRA_BEARING, activeBearing)
|
||||||
|
putFloat(GlobalMockMemory.EXTRA_SPEED, activeSpeed)
|
||||||
putString(GlobalMockMemory.EXTRA_LOCATION_NAME, mockLocationName)
|
putString(GlobalMockMemory.EXTRA_LOCATION_NAME, mockLocationName)
|
||||||
putString(GlobalMockMemory.EXTRA_MODE, appMockMode.name)
|
putString(GlobalMockMemory.EXTRA_MODE, appMockMode.name)
|
||||||
|
putBoolean(GlobalMockMemory.EXTRA_SENSOR_SIMULATION, isSensorSimulationEnabled)
|
||||||
|
putBoolean(GlobalMockMemory.EXTRA_NOTIFICATION_ENABLED, isNotificationEnabled)
|
||||||
|
putBoolean(GlobalMockMemory.EXTRA_RUNNING_MODE_ENABLED, isRunningModeEnabled)
|
||||||
|
putBoolean(GlobalMockMemory.EXTRA_JITTER_ENABLED, isJitterEnabled)
|
||||||
|
putBinder("process_token", processToken)
|
||||||
putStringArrayList(GlobalMockMemory.EXTRA_WHITELIST, ArrayList(whitelistApps))
|
putStringArrayList(GlobalMockMemory.EXTRA_WHITELIST, ArrayList(whitelistApps))
|
||||||
putStringArrayList(GlobalMockMemory.EXTRA_BLACKLIST, ArrayList(blacklistApps))
|
putStringArrayList(GlobalMockMemory.EXTRA_BLACKLIST, ArrayList(blacklistApps))
|
||||||
}
|
}
|
||||||
// 1. 原生底层 IPC 隧道(直达 system_server 与全局内存)
|
// 1. 原生底层 IPC 隧道(直达 system_server 与全局内存)
|
||||||
lm.sendExtraCommand(GlobalMockMemory.COMMAND_PROVIDER, GlobalMockMemory.COMMAND_SYNC, bundle)
|
lm.sendExtraCommand(GlobalMockMemory.COMMAND_PROVIDER, GlobalMockMemory.COMMAND_SYNC, bundle)
|
||||||
|
|
||||||
// 2. 隐式广播双重保险
|
// 2. 隐式广播双重保险(前台高优先级投递,减少后台延迟)
|
||||||
val intent = Intent("com.lzxnone.openloc.ACTION_SYNC_CONFIG").apply {
|
val intent = Intent("com.lzxnone.openloc.ACTION_SYNC_CONFIG").apply {
|
||||||
|
addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
|
||||||
putExtras(bundle)
|
putExtras(bundle)
|
||||||
}
|
}
|
||||||
ctx.sendBroadcast(intent)
|
ctx.sendBroadcast(intent)
|
||||||
@@ -284,7 +421,29 @@ object AppPreferences {
|
|||||||
.putString(KEY_MOCK_LOCATION_NAME, mockLocationName)
|
.putString(KEY_MOCK_LOCATION_NAME, mockLocationName)
|
||||||
.apply()
|
.apply()
|
||||||
|
|
||||||
syncConfigToSystem()
|
var shouldImmediatePush = true
|
||||||
|
if (isServiceEnabled && isRunningModeEnabled && isUserManual && hasActivePoint) {
|
||||||
|
val results = FloatArray(2)
|
||||||
|
Location.distanceBetween(activeLat, activeLng, latitude, longitude, results)
|
||||||
|
val distMeters = results[0]
|
||||||
|
if (distMeters in 2.5f..2500.0f) {
|
||||||
|
// 开启跑步模式时,近距离切点交给 1Hz 引擎按配速平滑推进
|
||||||
|
shouldImmediatePush = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldImmediatePush) {
|
||||||
|
activeLat = latitude
|
||||||
|
activeLng = longitude
|
||||||
|
activeSpeed = 0.0f
|
||||||
|
activeBearing = 0.0f
|
||||||
|
hasActivePoint = true
|
||||||
|
syncConfigToSystem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isServiceEnabled) {
|
||||||
|
startTickerIfNeeded()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateThemeMode(mode: ThemeMode) {
|
fun updateThemeMode(mode: ThemeMode) {
|
||||||
@@ -311,6 +470,43 @@ object AppPreferences {
|
|||||||
fun updateServiceEnabled(enabled: Boolean) {
|
fun updateServiceEnabled(enabled: Boolean) {
|
||||||
isServiceEnabled = enabled
|
isServiceEnabled = enabled
|
||||||
prefs.edit().putBoolean(KEY_SERVICE_ENABLED, enabled).apply()
|
prefs.edit().putBoolean(KEY_SERVICE_ENABLED, enabled).apply()
|
||||||
|
if (enabled) {
|
||||||
|
if (!hasActivePoint) {
|
||||||
|
activeLat = mockLatitude
|
||||||
|
activeLng = mockLongitude
|
||||||
|
hasActivePoint = true
|
||||||
|
}
|
||||||
|
syncConfigToSystem()
|
||||||
|
startTickerIfNeeded()
|
||||||
|
} else {
|
||||||
|
stopTicker()
|
||||||
|
activeSpeed = 0.0f
|
||||||
|
activeBearing = 0.0f
|
||||||
|
syncConfigToSystem()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateRunningModeEnabled(enabled: Boolean) {
|
||||||
|
isRunningModeEnabled = enabled
|
||||||
|
prefs.edit().putBoolean(KEY_RUNNING_MODE_ENABLED, enabled).apply()
|
||||||
|
if (!enabled) {
|
||||||
|
activeLat = mockLatitude
|
||||||
|
activeLng = mockLongitude
|
||||||
|
activeSpeed = 0.0f
|
||||||
|
activeBearing = 0.0f
|
||||||
|
}
|
||||||
|
syncConfigToSystem()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateRunningSpeed(speedMps: Float) {
|
||||||
|
val clamped = speedMps.coerceIn(1.0f, 8.0f)
|
||||||
|
runningSpeedMps = clamped
|
||||||
|
prefs.edit().putFloat(KEY_RUNNING_SPEED, clamped).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateNotificationEnabled(enabled: Boolean) {
|
||||||
|
isNotificationEnabled = enabled
|
||||||
|
prefs.edit().putBoolean(KEY_NOTIFICATION_ENABLED, enabled).apply()
|
||||||
syncConfigToSystem()
|
syncConfigToSystem()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -560,5 +756,10 @@ object AppPreferences {
|
|||||||
isAutoCheckUpdateEnabled = enabled
|
isAutoCheckUpdateEnabled = enabled
|
||||||
prefs.edit().putBoolean(KEY_AUTO_CHECK_UPDATE, enabled).apply()
|
prefs.edit().putBoolean(KEY_AUTO_CHECK_UPDATE, enabled).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateSuppressedVersionCode(code: Long) {
|
||||||
|
suppressedUpdateVersionCode = code
|
||||||
|
prefs.edit().putLong(KEY_SUPPRESSED_UPDATE_VERSION, code).apply()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8,6 +8,8 @@ import com.lzxnone.openloc.hook.interceptor.BleHook
|
|||||||
import com.lzxnone.openloc.hook.interceptor.GnssHook
|
import com.lzxnone.openloc.hook.interceptor.GnssHook
|
||||||
import com.lzxnone.openloc.hook.interceptor.LocationHook
|
import com.lzxnone.openloc.hook.interceptor.LocationHook
|
||||||
import com.lzxnone.openloc.hook.interceptor.NetworkLocationHook
|
import com.lzxnone.openloc.hook.interceptor.NetworkLocationHook
|
||||||
|
import com.lzxnone.openloc.hook.interceptor.SensorHook
|
||||||
|
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
||||||
import com.lzxnone.openloc.hook.system.SystemServerHook
|
import com.lzxnone.openloc.hook.system.SystemServerHook
|
||||||
import com.lzxnone.openloc.hook.system.TelephonyRegistryHook
|
import com.lzxnone.openloc.hook.system.TelephonyRegistryHook
|
||||||
import de.robv.android.xposed.IXposedHookLoadPackage
|
import de.robv.android.xposed.IXposedHookLoadPackage
|
||||||
@@ -95,6 +97,9 @@ class HookEntry : IXposedHookLoadPackage {
|
|||||||
if (appContext == null && ctx != null) {
|
if (appContext == null && ctx != null) {
|
||||||
appContext = ctx
|
appContext = ctx
|
||||||
}
|
}
|
||||||
|
if (ctx != null) {
|
||||||
|
ConfigFetcher.init(ctx)
|
||||||
|
}
|
||||||
// 在 Application.attach 完成后,针对动态加载 Multidex/插件环境二次加固第三方定位 SDK
|
// 在 Application.attach 完成后,针对动态加载 Multidex/插件环境二次加固第三方定位 SDK
|
||||||
val appClassLoader = ctx?.classLoader ?: lpparam.classLoader
|
val appClassLoader = ctx?.classLoader ?: lpparam.classLoader
|
||||||
ThirdPartyNlpHook.hook(appClassLoader, pkg, contextProvider)
|
ThirdPartyNlpHook.hook(appClassLoader, pkg, contextProvider)
|
||||||
@@ -107,6 +112,7 @@ class HookEntry : IXposedHookLoadPackage {
|
|||||||
ThirdPartyNlpHook.hook(lpparam.classLoader, pkg, contextProvider)
|
ThirdPartyNlpHook.hook(lpparam.classLoader, pkg, contextProvider)
|
||||||
NetworkLocationHook.hook(lpparam.classLoader, pkg, contextProvider)
|
NetworkLocationHook.hook(lpparam.classLoader, pkg, contextProvider)
|
||||||
GnssHook.hook(lpparam.classLoader, pkg, contextProvider)
|
GnssHook.hook(lpparam.classLoader, pkg, contextProvider)
|
||||||
|
SensorHook.hook(lpparam.classLoader, pkg, contextProvider)
|
||||||
BleHook.hookClient(lpparam.classLoader, pkg)
|
BleHook.hookClient(lpparam.classLoader, pkg)
|
||||||
AntiDetectionHook.hook(lpparam.classLoader, contextProvider)
|
AntiDetectionHook.hook(lpparam.classLoader, contextProvider)
|
||||||
|
|
||||||
|
|||||||
@@ -1,125 +0,0 @@
|
|||||||
package com.lzxnone.openloc.hook.client
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.location.Location
|
|
||||||
import android.location.LocationManager
|
|
||||||
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
|
||||||
import de.robv.android.xposed.XC_MethodHook
|
|
||||||
import de.robv.android.xposed.XposedBridge
|
|
||||||
import de.robv.android.xposed.XposedHelpers
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端系统私有 Transport 内部类与 Fused 融合引流拦截器
|
|
||||||
* (基于 GhostMapX 核心架构设计)
|
|
||||||
*/
|
|
||||||
object ClientTransportHook {
|
|
||||||
|
|
||||||
fun hook(classLoader: ClassLoader, packageName: String, contextProvider: () -> Context?) {
|
|
||||||
hookSystemTransports(classLoader, packageName, contextProvider)
|
|
||||||
hookFusedProviderRedirect(classLoader, packageName, contextProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1. 深度拦截客户端必经的系统 Transport 内部类
|
|
||||||
*/
|
|
||||||
private fun hookSystemTransports(classLoader: ClassLoader, packageName: String, contextProvider: () -> Context?) {
|
|
||||||
val transportClassNames = listOf(
|
|
||||||
"android.location.LocationManager\$LocationListenerTransport",
|
|
||||||
"android.location.LocationManager\$GetCurrentLocationTransport",
|
|
||||||
"android.location.LocationManager\$BatchedLocationCallbackWrapper"
|
|
||||||
)
|
|
||||||
|
|
||||||
for (className in transportClassNames) {
|
|
||||||
val clazz = try {
|
|
||||||
XposedHelpers.findClass(className, classLoader)
|
|
||||||
} catch (_: Throwable) {
|
|
||||||
null
|
|
||||||
} ?: continue
|
|
||||||
|
|
||||||
for (method in clazz.declaredMethods) {
|
|
||||||
if (method.name == "onLocationChanged" || method.name == "onLocation") {
|
|
||||||
try {
|
|
||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
|
||||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
|
||||||
if (!getEffectiveParams(packageName, contextProvider)) return
|
|
||||||
|
|
||||||
for (arg in param.args) {
|
|
||||||
modifyLocationArgument(arg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (_: Throwable) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 2. 强行阻断并重定向 Fused (融合定位) 提供商
|
|
||||||
*/
|
|
||||||
private fun hookFusedProviderRedirect(classLoader: ClassLoader, packageName: String, contextProvider: () -> Context?) {
|
|
||||||
try {
|
|
||||||
val lmClass = LocationManager::class.java
|
|
||||||
for (method in lmClass.declaredMethods) {
|
|
||||||
if (method.name == "requestLocationUpdates" || method.name == "requestSingleUpdate") {
|
|
||||||
try {
|
|
||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
|
||||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
|
||||||
if (!getEffectiveParams(packageName, contextProvider)) return
|
|
||||||
|
|
||||||
// 如果入参 provider 是 fused,强行引流至 gps
|
|
||||||
val providerIndex = param.args.indexOfFirst { it is String && it.equals("fused", ignoreCase = true) }
|
|
||||||
if (providerIndex != -1) {
|
|
||||||
param.args[providerIndex] = LocationManager.GPS_PROVIDER
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (_: Throwable) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (_: Throwable) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getEffectiveParams(packageName: String, contextProvider: () -> Context?): Boolean {
|
|
||||||
if (packageName == "com.lzxnone.openloc") return false
|
|
||||||
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
val ctx = contextProvider()
|
|
||||||
if (ctx != null) {
|
|
||||||
val config = ConfigFetcher.getConfig(ctx)
|
|
||||||
return config.shouldMock(packageName.ifBlank { ctx.packageName })
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun modifyLocationArgument(arg: Any?) {
|
|
||||||
if (arg == null) return
|
|
||||||
if (arg is Location) {
|
|
||||||
GlobalMockMemory.applyToLocation(arg)
|
|
||||||
} else if (arg is List<*>) {
|
|
||||||
for (item in arg) {
|
|
||||||
if (item is Location) {
|
|
||||||
GlobalMockMemory.applyToLocation(item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (arg.javaClass.name.contains("LocationResult")) {
|
|
||||||
try {
|
|
||||||
val list = (XposedHelpers.callMethod(arg, "asList") as? List<*>)
|
|
||||||
?: (XposedHelpers.getObjectField(arg, "mLocations") as? List<*>)
|
|
||||||
if (list != null) {
|
|
||||||
for (loc in list) {
|
|
||||||
if (loc is Location) {
|
|
||||||
GlobalMockMemory.applyToLocation(loc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val lastLoc = XposedHelpers.callMethod(arg, "getLastLocation") as? Location
|
|
||||||
if (lastLoc != null) {
|
|
||||||
GlobalMockMemory.applyToLocation(lastLoc)
|
|
||||||
}
|
|
||||||
} catch (_: Throwable) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,9 @@ import android.content.Context
|
|||||||
import android.location.Location
|
import android.location.Location
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
|
import com.lzxnone.openloc.core.util.CoordinateConverter
|
||||||
import com.lzxnone.openloc.core.util.TraceLogger
|
import com.lzxnone.openloc.core.util.TraceLogger
|
||||||
|
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
||||||
import de.robv.android.xposed.XC_MethodHook
|
import de.robv.android.xposed.XC_MethodHook
|
||||||
import de.robv.android.xposed.XposedBridge
|
import de.robv.android.xposed.XposedBridge
|
||||||
@@ -14,6 +16,7 @@ import java.lang.reflect.Method
|
|||||||
import java.lang.reflect.Proxy
|
import java.lang.reflect.Proxy
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.WeakHashMap
|
import java.util.WeakHashMap
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 国内三大巨头自研底层 NLP 与商用定位 SDK 深度防御拦截器
|
* 国内三大巨头自研底层 NLP 与商用定位 SDK 深度防御拦截器
|
||||||
@@ -27,13 +30,52 @@ import java.util.WeakHashMap
|
|||||||
object ThirdPartyNlpHook {
|
object ThirdPartyNlpHook {
|
||||||
|
|
||||||
private val tencentListenerProxyMap = Collections.synchronizedMap(WeakHashMap<Any, Any>())
|
private val tencentListenerProxyMap = Collections.synchronizedMap(WeakHashMap<Any, Any>())
|
||||||
|
private val activeTencentListeners = Collections.synchronizedMap(WeakHashMap<Any, Pair<ClassLoader, String>>())
|
||||||
|
private val hookedTencentManagerClasses = Collections.synchronizedSet(mutableSetOf<String>())
|
||||||
|
private val hookedTencentLocationImplClasses = Collections.synchronizedSet(mutableSetOf<String>())
|
||||||
|
private val tencentPushRegistered = AtomicBoolean(false)
|
||||||
|
@Volatile private var primaryPackageName: String = ""
|
||||||
|
|
||||||
fun hook(classLoader: ClassLoader, packageName: String, contextProvider: () -> Context?) {
|
fun hook(classLoader: ClassLoader, packageName: String, contextProvider: () -> Context?) {
|
||||||
if (packageName == "com.lzxnone.openloc") return
|
if (packageName == "com.lzxnone.openloc") return
|
||||||
|
if (primaryPackageName.isEmpty()) {
|
||||||
|
primaryPackageName = packageName
|
||||||
|
}
|
||||||
|
|
||||||
hookTencentLocationSDK(classLoader, packageName)
|
if (tencentPushRegistered.compareAndSet(false, true)) {
|
||||||
hookBaiduLocationSDK(classLoader, packageName)
|
ConfigFetcher.addOnConfigChangedListener {
|
||||||
hookAmapLocationSDK(classLoader, packageName)
|
pushToActiveTencentListeners()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hookTencentLocationSDK(classLoader, primaryPackageName)
|
||||||
|
hookBaiduLocationSDK(classLoader, primaryPackageName)
|
||||||
|
hookAmapLocationSDK(classLoader, primaryPackageName)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun pushToActiveTencentListeners() {
|
||||||
|
val pkg = primaryPackageName
|
||||||
|
if (!GlobalMockMemory.isEnabled || !GlobalMockMemory.shouldMock(pkg)) return
|
||||||
|
val snapshot = synchronized(activeTencentListeners) {
|
||||||
|
activeTencentListeners.entries.map { it.key to it.value }
|
||||||
|
}
|
||||||
|
if (snapshot.isEmpty()) return
|
||||||
|
|
||||||
|
for ((listener, meta) in snapshot) {
|
||||||
|
val (cl, prefix) = meta
|
||||||
|
try {
|
||||||
|
val mockLoc = createMockTencentLocation(cl, prefix) ?: continue
|
||||||
|
val method = listener.javaClass.methods.firstOrNull {
|
||||||
|
it.name == "onLocationChanged" && it.parameterCount >= 1
|
||||||
|
} ?: continue
|
||||||
|
when (method.parameterCount) {
|
||||||
|
1 -> method.invoke(listener, mockLoc)
|
||||||
|
2 -> method.invoke(listener, mockLoc, 0)
|
||||||
|
else -> method.invoke(listener, mockLoc, 0, "OK")
|
||||||
|
}
|
||||||
|
TraceLogger.w("ThirdPartyNLP", "[$pkg] Active push to Tencent listener ($prefix) -> (${GlobalMockMemory.latitude}, ${GlobalMockMemory.longitude})")
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================================================================
|
// ====================================================================================
|
||||||
@@ -41,24 +83,33 @@ object ThirdPartyNlpHook {
|
|||||||
// ====================================================================================
|
// ====================================================================================
|
||||||
|
|
||||||
private fun hookTencentLocationSDK(classLoader: ClassLoader, packageName: String) {
|
private fun hookTencentLocationSDK(classLoader: ClassLoader, packageName: String) {
|
||||||
// (1) 现代腾讯定位 SDK:com.tencent.map.geolocation.TencentLocationManager
|
// (1) 现代腾讯定位 SDK 与微信内置混淆版 sapp SDK
|
||||||
val tencentManagerClass = try {
|
val tencentPrefixes = listOf(
|
||||||
XposedHelpers.findClass("com.tencent.map.geolocation.TencentLocationManager", classLoader)
|
"com.tencent.map.geolocation",
|
||||||
} catch (_: Throwable) {
|
"com.tencent.map.geolocation.sapp"
|
||||||
null
|
)
|
||||||
}
|
|
||||||
|
|
||||||
if (tencentManagerClass != null) {
|
for (prefix in tencentPrefixes) {
|
||||||
TraceLogger.i("ThirdPartyNLP", "[$packageName] Detected modern TencentLocationManager, arming Tencent hooks...")
|
val managerName = "$prefix.TencentLocationManager"
|
||||||
|
val tencentManagerClass = try {
|
||||||
|
XposedHelpers.findClass(managerName, classLoader)
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
} ?: continue
|
||||||
|
|
||||||
|
val key = "$managerName@${System.identityHashCode(tencentManagerClass)}"
|
||||||
|
if (!hookedTencentManagerClasses.add(key)) continue
|
||||||
|
|
||||||
|
TraceLogger.i("ThirdPartyNLP", "[$packageName] Detected $managerName, arming Tencent hooks...")
|
||||||
|
|
||||||
for (method in tencentManagerClass.declaredMethods) {
|
for (method in tencentManagerClass.declaredMethods) {
|
||||||
when (method.name) {
|
when (method.name) {
|
||||||
"requestLocationUpdates", "requestSingleFreshLocation" -> {
|
"requestLocationUpdates", "requestSingleFreshLocation", "requestLocationWithScene" -> {
|
||||||
try {
|
try {
|
||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||||
if (!GlobalMockMemory.isEnabled || !GlobalMockMemory.shouldMock(packageName)) return
|
if (!GlobalMockMemory.isEnabled || !GlobalMockMemory.shouldMock(packageName)) return
|
||||||
wrapTencentListenerArgs(param.args, classLoader, packageName)
|
wrapTencentListenerArgs(param.args, classLoader, packageName, prefix)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (_: Throwable) {}
|
} catch (_: Throwable) {}
|
||||||
@@ -68,6 +119,7 @@ object ThirdPartyNlpHook {
|
|||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||||
val originalListener = param.args.getOrNull(0) ?: return
|
val originalListener = param.args.getOrNull(0) ?: return
|
||||||
|
activeTencentListeners.remove(originalListener)
|
||||||
val proxy = tencentListenerProxyMap[originalListener]
|
val proxy = tencentListenerProxyMap[originalListener]
|
||||||
if (proxy != null) {
|
if (proxy != null) {
|
||||||
param.args[0] = proxy
|
param.args[0] = proxy
|
||||||
@@ -81,9 +133,13 @@ object ThirdPartyNlpHook {
|
|||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||||
override fun afterHookedMethod(param: MethodHookParam) {
|
override fun afterHookedMethod(param: MethodHookParam) {
|
||||||
if (!GlobalMockMemory.isEnabled || !GlobalMockMemory.shouldMock(packageName)) return
|
if (!GlobalMockMemory.isEnabled || !GlobalMockMemory.shouldMock(packageName)) return
|
||||||
val mockLoc = createMockTencentLocation(classLoader)
|
val result = param.result
|
||||||
|
if (result != null) {
|
||||||
|
hookTencentLocationImplClass(result.javaClass, packageName)
|
||||||
|
}
|
||||||
|
val mockLoc = createMockTencentLocation(classLoader, prefix)
|
||||||
if (mockLoc != null) {
|
if (mockLoc != null) {
|
||||||
TraceLogger.w("ThirdPartyNLP", "[$packageName] TencentLocationManager.getLastKnownLocation -> SPOOFED")
|
TraceLogger.w("ThirdPartyNLP", "[$packageName] $managerName.getLastKnownLocation -> SPOOFED")
|
||||||
param.result = mockLoc
|
param.result = mockLoc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,9 +265,14 @@ object ThirdPartyNlpHook {
|
|||||||
/**
|
/**
|
||||||
* 包装 TencentLocationListener,注入动态代理
|
* 包装 TencentLocationListener,注入动态代理
|
||||||
*/
|
*/
|
||||||
private fun wrapTencentListenerArgs(args: Array<Any?>, classLoader: ClassLoader, packageName: String) {
|
private fun wrapTencentListenerArgs(
|
||||||
|
args: Array<Any?>,
|
||||||
|
classLoader: ClassLoader,
|
||||||
|
packageName: String,
|
||||||
|
prefix: String
|
||||||
|
) {
|
||||||
val listenerInterface = try {
|
val listenerInterface = try {
|
||||||
XposedHelpers.findClass("com.tencent.map.geolocation.TencentLocationListener", classLoader)
|
XposedHelpers.findClass("$prefix.TencentLocationListener", classLoader)
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -222,28 +283,70 @@ object ThirdPartyNlpHook {
|
|||||||
if (Proxy.isProxyClass(arg.javaClass) && Proxy.getInvocationHandler(arg) is TencentListenerInvocationHandler) {
|
if (Proxy.isProxyClass(arg.javaClass) && Proxy.getInvocationHandler(arg) is TencentListenerInvocationHandler) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
activeTencentListeners[arg] = classLoader to prefix
|
||||||
val proxy = tencentListenerProxyMap.getOrPut(arg) {
|
val proxy = tencentListenerProxyMap.getOrPut(arg) {
|
||||||
Proxy.newProxyInstance(
|
Proxy.newProxyInstance(
|
||||||
classLoader,
|
classLoader,
|
||||||
arrayOf(listenerInterface),
|
arrayOf(listenerInterface),
|
||||||
TencentListenerInvocationHandler(arg, classLoader, packageName)
|
TencentListenerInvocationHandler(arg, classLoader, packageName, prefix)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
args[i] = proxy
|
args[i] = proxy
|
||||||
TraceLogger.d("ThirdPartyNLP", "[$packageName] Wrapped TencentLocationListener at index $i with dynamic proxy")
|
TraceLogger.d("ThirdPartyNLP", "[$packageName] Wrapped $prefix.TencentLocationListener at index $i with dynamic proxy")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun hookTencentLocationImplClass(clazz: Class<*>, packageName: String) {
|
||||||
|
if (Proxy.isProxyClass(clazz)) return
|
||||||
|
val name = clazz.name
|
||||||
|
if (!hookedTencentLocationImplClasses.add(name)) return
|
||||||
|
|
||||||
|
TraceLogger.i("ThirdPartyNLP", "[$packageName] Hooked concrete TencentLocation impl: $name")
|
||||||
|
for (method in clazz.declaredMethods) {
|
||||||
|
when (method.name) {
|
||||||
|
"getLatitude" -> hookGetter(method, packageName) { GlobalMockMemory.latitude }
|
||||||
|
"getLongitude" -> hookGetter(method, packageName) { GlobalMockMemory.longitude }
|
||||||
|
"getAltitude" -> hookGetter(method, packageName) { GlobalMockMemory.altitude }
|
||||||
|
"getAccuracy" -> hookGetter(method, packageName) { GlobalMockMemory.accuracy }
|
||||||
|
"getSpeed" -> hookGetter(method, packageName) { GlobalMockMemory.speed }
|
||||||
|
"getBearing" -> hookGetter(method, packageName) { GlobalMockMemory.bearing }
|
||||||
|
"getDirection" -> hookGetter(method, packageName) { GlobalMockMemory.bearing.toDouble() }
|
||||||
|
"getProvider" -> hookGetter(method, packageName) { "gps" }
|
||||||
|
"isMockGps" -> hookGetter(method, packageName) { 0 }
|
||||||
|
"getName", "getAddress" -> hookGetter(method, packageName) {
|
||||||
|
GlobalMockMemory.locationName.ifEmpty { "我的位置" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun hookGetter(method: Method, packageName: String, crossinline valueProvider: () -> Any) {
|
||||||
|
try {
|
||||||
|
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||||
|
override fun afterHookedMethod(param: MethodHookParam) {
|
||||||
|
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
||||||
|
param.result = valueProvider()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
|
||||||
private class TencentListenerInvocationHandler(
|
private class TencentListenerInvocationHandler(
|
||||||
private val originalListener: Any,
|
private val originalListener: Any,
|
||||||
private val classLoader: ClassLoader,
|
private val classLoader: ClassLoader,
|
||||||
private val packageName: String
|
private val packageName: String,
|
||||||
|
private val prefix: String
|
||||||
) : InvocationHandler {
|
) : InvocationHandler {
|
||||||
override fun invoke(proxy: Any?, method: Method, args: Array<Any?>?): Any? {
|
override fun invoke(proxy: Any?, method: Method, args: Array<Any?>?): Any? {
|
||||||
if (method.name == "onLocationChanged") {
|
if (method.name == "onLocationChanged") {
|
||||||
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
||||||
val mockLoc = createMockTencentLocation(classLoader)
|
val incomingLoc = args?.getOrNull(0)
|
||||||
|
if (incomingLoc != null) {
|
||||||
|
hookTencentLocationImplClass(incomingLoc.javaClass, packageName)
|
||||||
|
}
|
||||||
|
val mockLoc = createMockTencentLocation(classLoader, prefix)
|
||||||
if (mockLoc != null && args != null && args.isNotEmpty()) {
|
if (mockLoc != null && args != null && args.isNotEmpty()) {
|
||||||
args[0] = mockLoc
|
args[0] = mockLoc
|
||||||
if (args.size > 1) {
|
if (args.size > 1) {
|
||||||
@@ -252,7 +355,7 @@ object ThirdPartyNlpHook {
|
|||||||
if (args.size > 2) {
|
if (args.size > 2) {
|
||||||
args[2] = "OK"
|
args[2] = "OK"
|
||||||
}
|
}
|
||||||
TraceLogger.w("ThirdPartyNLP", "[$packageName] TencentLocationListener.onLocationChanged -> REPLACED with Mock Location (${GlobalMockMemory.latitude}, ${GlobalMockMemory.longitude})")
|
TraceLogger.w("ThirdPartyNLP", "[$packageName] $prefix.TencentLocationListener.onLocationChanged -> REPLACED with Mock Location (${GlobalMockMemory.latitude}, ${GlobalMockMemory.longitude})")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,9 +366,12 @@ object ThirdPartyNlpHook {
|
|||||||
/**
|
/**
|
||||||
* 动态反射构建标准 TencentLocation 接口代理实例
|
* 动态反射构建标准 TencentLocation 接口代理实例
|
||||||
*/
|
*/
|
||||||
private fun createMockTencentLocation(classLoader: ClassLoader): Any? {
|
private fun createMockTencentLocation(
|
||||||
|
classLoader: ClassLoader,
|
||||||
|
prefix: String = "com.tencent.map.geolocation"
|
||||||
|
): Any? {
|
||||||
val locationInterface = try {
|
val locationInterface = try {
|
||||||
XposedHelpers.findClass("com.tencent.map.geolocation.TencentLocation", classLoader)
|
XposedHelpers.findClass("$prefix.TencentLocation", classLoader)
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -348,7 +454,27 @@ object ThirdPartyNlpHook {
|
|||||||
|
|
||||||
if (bdLocationClass != null) {
|
if (bdLocationClass != null) {
|
||||||
TraceLogger.i("ThirdPartyNLP", "[$packageName] Detected BDLocation, arming Baidu hooks...")
|
TraceLogger.i("ThirdPartyNLP", "[$packageName] Detected BDLocation, arming Baidu hooks...")
|
||||||
|
val getCoorTypeMethod = try {
|
||||||
|
bdLocationClass.getMethod("getCoorType")
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resolveBaiduCoords(instance: Any?): DoubleArray? {
|
||||||
|
val coorType = try {
|
||||||
|
(getCoorTypeMethod?.invoke(instance) as? String)?.lowercase()
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
return when {
|
||||||
|
coorType == "bd09mc" || (coorType != null && coorType.contains("mc")) -> null
|
||||||
|
coorType == "wgs84" -> doubleArrayOf(GlobalMockMemory.latitude, GlobalMockMemory.longitude)
|
||||||
|
coorType == "gcj02" -> CoordinateConverter.wgs84ToGcj02(GlobalMockMemory.latitude, GlobalMockMemory.longitude)
|
||||||
|
else -> CoordinateConverter.wgs84ToBd09(GlobalMockMemory.latitude, GlobalMockMemory.longitude)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastBdLogTime = 0L
|
||||||
for (method in bdLocationClass.declaredMethods) {
|
for (method in bdLocationClass.declaredMethods) {
|
||||||
when (method.name) {
|
when (method.name) {
|
||||||
"getLatitude" -> {
|
"getLatitude" -> {
|
||||||
@@ -356,7 +482,16 @@ object ThirdPartyNlpHook {
|
|||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||||
override fun afterHookedMethod(param: MethodHookParam) {
|
override fun afterHookedMethod(param: MethodHookParam) {
|
||||||
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
||||||
param.result = GlobalMockMemory.latitude
|
val orig = param.result as? Double ?: return
|
||||||
|
if (orig == Double.MIN_VALUE || orig == 0.0 || kotlin.math.abs(orig) > 90.0) return
|
||||||
|
val coords = resolveBaiduCoords(param.thisObject) ?: return
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
if (now - lastBdLogTime > 2000L) {
|
||||||
|
lastBdLogTime = now
|
||||||
|
val coorType = try { getCoorTypeMethod?.invoke(param.thisObject) as? String } catch (_: Throwable) { null }
|
||||||
|
TraceLogger.d("ThirdPartyNLP", "[$packageName] BDLocation.getLatitude orig=$orig, coorType=$coorType -> ${coords[0]}")
|
||||||
|
}
|
||||||
|
param.result = coords[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -367,7 +502,10 @@ object ThirdPartyNlpHook {
|
|||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||||
override fun afterHookedMethod(param: MethodHookParam) {
|
override fun afterHookedMethod(param: MethodHookParam) {
|
||||||
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
||||||
param.result = GlobalMockMemory.longitude
|
val orig = param.result as? Double ?: return
|
||||||
|
if (orig == Double.MIN_VALUE || orig == 0.0 || kotlin.math.abs(orig) > 180.0) return
|
||||||
|
val coords = resolveBaiduCoords(param.thisObject) ?: return
|
||||||
|
param.result = coords[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -422,7 +560,10 @@ object ThirdPartyNlpHook {
|
|||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||||
override fun afterHookedMethod(param: MethodHookParam) {
|
override fun afterHookedMethod(param: MethodHookParam) {
|
||||||
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
||||||
param.result = 61 // 61: GPS 定位成功
|
val orig = param.result as? Int
|
||||||
|
if (orig == 161 || orig == 66 || orig == 65 || orig == 68) {
|
||||||
|
param.result = 61 // 将网络/离线成功态统一伪装为 GPS 定位成功
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.lzxnone.openloc.hook.interceptor
|
package com.lzxnone.openloc.hook.interceptor
|
||||||
|
|
||||||
import android.bluetooth.le.ScanCallback
|
import android.bluetooth.le.ScanCallback
|
||||||
import android.bluetooth.le.ScanResult
|
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
||||||
import de.robv.android.xposed.XC_MethodHook
|
import de.robv.android.xposed.XC_MethodHook
|
||||||
import de.robv.android.xposed.XposedBridge
|
import de.robv.android.xposed.XposedBridge
|
||||||
|
|||||||
@@ -3,10 +3,8 @@
|
|||||||
package com.lzxnone.openloc.hook.interceptor
|
package com.lzxnone.openloc.hook.interceptor
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.location.GnssStatus
|
|
||||||
import android.location.GpsStatus
|
import android.location.GpsStatus
|
||||||
import android.location.LocationManager
|
import android.location.LocationManager
|
||||||
import android.location.OnNmeaMessageListener
|
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
||||||
import de.robv.android.xposed.XC_MethodHook
|
import de.robv.android.xposed.XC_MethodHook
|
||||||
import de.robv.android.xposed.XposedBridge
|
import de.robv.android.xposed.XposedBridge
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ import android.os.Handler
|
|||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import com.lzxnone.openloc.core.util.TraceLogger
|
import com.lzxnone.openloc.core.util.TraceLogger
|
||||||
|
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
||||||
import de.robv.android.xposed.XC_MethodHook
|
import de.robv.android.xposed.XC_MethodHook
|
||||||
import de.robv.android.xposed.XposedBridge
|
import de.robv.android.xposed.XposedBridge
|
||||||
import de.robv.android.xposed.XposedHelpers
|
import de.robv.android.xposed.XposedHelpers
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.WeakHashMap
|
import java.util.WeakHashMap
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户端 LocationManager 拦截器(严格对齐 GhostMapX LYe/LXe 实现)
|
* 客户端 LocationManager 拦截器(严格对齐 GhostMapX LYe/LXe 实现)
|
||||||
@@ -33,15 +35,51 @@ object LocationHook {
|
|||||||
|
|
||||||
private val mainHandler = Handler(Looper.getMainLooper())
|
private val mainHandler = Handler(Looper.getMainLooper())
|
||||||
private val hookedListenerClasses = Collections.synchronizedSet(mutableSetOf<String>())
|
private val hookedListenerClasses = Collections.synchronizedSet(mutableSetOf<String>())
|
||||||
|
private val activeListeners = Collections.synchronizedMap(WeakHashMap<LocationListener, String>())
|
||||||
|
private val isInitialized = AtomicBoolean(false)
|
||||||
|
@Volatile private var currentContextProvider: (() -> Context?)? = null
|
||||||
|
@Volatile private var currentPackageName: String = ""
|
||||||
|
|
||||||
fun hook(classLoader: ClassLoader, packageName: String, contextProvider: () -> Context?) {
|
fun hook(classLoader: ClassLoader, packageName: String, contextProvider: () -> Context?) {
|
||||||
// 关键安全防线:针对 OpenLoc 自身绝对放行,确保可无阻获取硬件真实 GPS 回到真实定位点
|
// 关键安全防线:针对 OpenLoc 自身绝对放行,确保可无阻获取硬件真实 GPS 回到真实定位点
|
||||||
if (packageName == "com.lzxnone.openloc") return
|
if (packageName == "com.lzxnone.openloc") return
|
||||||
|
// 防止同进程内附属包(如系统插件)重复初始化并覆盖主包名与监听回调
|
||||||
|
if (!isInitialized.compareAndSet(false, true)) return
|
||||||
|
|
||||||
|
currentContextProvider = contextProvider
|
||||||
|
currentPackageName = packageName
|
||||||
|
|
||||||
|
ConfigFetcher.addOnConfigChangedListener {
|
||||||
|
pushLocationToActiveListeners()
|
||||||
|
}
|
||||||
|
|
||||||
hookClientLocationManager(classLoader, packageName)
|
hookClientLocationManager(classLoader, packageName)
|
||||||
hookLocationTransports(classLoader, packageName)
|
hookLocationTransports(classLoader, packageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun refreshConfigIfPossible() {
|
||||||
|
val ctx = currentContextProvider?.invoke() ?: return
|
||||||
|
ConfigFetcher.getConfig(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun pushLocationToActiveListeners() {
|
||||||
|
val pkg = currentPackageName
|
||||||
|
if (!GlobalMockMemory.isEnabled || !GlobalMockMemory.shouldMock(pkg)) return
|
||||||
|
|
||||||
|
val snapshot = synchronized(activeListeners) { activeListeners.entries.map { it.key to it.value } }
|
||||||
|
if (snapshot.isEmpty()) return
|
||||||
|
|
||||||
|
mainHandler.post {
|
||||||
|
for ((listener, provider) in snapshot) {
|
||||||
|
try {
|
||||||
|
val mockLoc = GlobalMockMemory.createLocation(provider)
|
||||||
|
listener.onLocationChanged(mockLoc)
|
||||||
|
TraceLogger.w("ClientHook", "[$pkg] Active push on config change -> ${TraceLogger.formatLocation(mockLoc)}")
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun hookClientLocationManager(classLoader: ClassLoader, packageName: String) {
|
private fun hookClientLocationManager(classLoader: ClassLoader, packageName: String) {
|
||||||
val lmClass = LocationManager::class.java
|
val lmClass = LocationManager::class.java
|
||||||
|
|
||||||
@@ -51,6 +89,7 @@ object LocationHook {
|
|||||||
try {
|
try {
|
||||||
XposedBridge.hookAllMethods(lmClass, methodName, object : XC_MethodHook() {
|
XposedBridge.hookAllMethods(lmClass, methodName, object : XC_MethodHook() {
|
||||||
override fun afterHookedMethod(param: MethodHookParam) {
|
override fun afterHookedMethod(param: MethodHookParam) {
|
||||||
|
refreshConfigIfPossible()
|
||||||
val shouldMock = GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)
|
val shouldMock = GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)
|
||||||
val originalLoc = param.result as? Location
|
val originalLoc = param.result as? Location
|
||||||
TraceLogger.d("ClientHook", "[$packageName] $methodName called -> originalResult=${TraceLogger.formatLocation(originalLoc)}, shouldMock=$shouldMock")
|
TraceLogger.d("ClientHook", "[$packageName] $methodName called -> originalResult=${TraceLogger.formatLocation(originalLoc)}, shouldMock=$shouldMock")
|
||||||
@@ -88,11 +127,14 @@ object LocationHook {
|
|||||||
try {
|
try {
|
||||||
XposedBridge.hookAllMethods(lmClass, methodName, object : XC_MethodHook() {
|
XposedBridge.hookAllMethods(lmClass, methodName, object : XC_MethodHook() {
|
||||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||||
|
refreshConfigIfPossible()
|
||||||
if (!GlobalMockMemory.isEnabled || !GlobalMockMemory.shouldMock(packageName)) return
|
if (!GlobalMockMemory.isEnabled || !GlobalMockMemory.shouldMock(packageName)) return
|
||||||
|
|
||||||
// 查找 LocationListener 参数并挂钩其 onLocationChanged
|
val provider = param.args.firstOrNull { it is String } as? String ?: "gps"
|
||||||
|
// 查找 LocationListener 参数并挂钩其 onLocationChanged,同时记录活跃监听器
|
||||||
for (arg in param.args) {
|
for (arg in param.args) {
|
||||||
if (arg is LocationListener) {
|
if (arg is LocationListener) {
|
||||||
|
activeListeners[arg] = provider
|
||||||
hookLocationListenerClass(arg.javaClass, packageName)
|
hookLocationListenerClass(arg.javaClass, packageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,6 +157,16 @@ object LocationHook {
|
|||||||
})
|
})
|
||||||
} catch (_: Throwable) {}
|
} catch (_: Throwable) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4. removeUpdates 移除时清理活跃监听器引用
|
||||||
|
try {
|
||||||
|
XposedBridge.hookAllMethods(lmClass, "removeUpdates", object : XC_MethodHook() {
|
||||||
|
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||||
|
val listener = param.args.firstOrNull { it is LocationListener } as? LocationListener ?: return
|
||||||
|
activeListeners.remove(listener)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (_: Throwable) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,6 +187,7 @@ object LocationHook {
|
|||||||
try {
|
try {
|
||||||
XposedBridge.hookAllMethods(clazz, "onLocation", object : XC_MethodHook() {
|
XposedBridge.hookAllMethods(clazz, "onLocation", object : XC_MethodHook() {
|
||||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||||
|
refreshConfigIfPossible()
|
||||||
val loc = param.args.getOrNull(0) as? Location
|
val loc = param.args.getOrNull(0) as? Location
|
||||||
val shouldMock = GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)
|
val shouldMock = GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)
|
||||||
TraceLogger.d("ClientTransport", "[$packageName] Transport.onLocation: incoming=${TraceLogger.formatLocation(loc)}, shouldMock=$shouldMock")
|
TraceLogger.d("ClientTransport", "[$packageName] Transport.onLocation: incoming=${TraceLogger.formatLocation(loc)}, shouldMock=$shouldMock")
|
||||||
@@ -151,6 +204,7 @@ object LocationHook {
|
|||||||
try {
|
try {
|
||||||
XposedBridge.hookAllMethods(clazz, "onLocationChanged", object : XC_MethodHook() {
|
XposedBridge.hookAllMethods(clazz, "onLocationChanged", object : XC_MethodHook() {
|
||||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||||
|
refreshConfigIfPossible()
|
||||||
val arg = param.args.getOrNull(0)
|
val arg = param.args.getOrNull(0)
|
||||||
val shouldMock = GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)
|
val shouldMock = GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)
|
||||||
TraceLogger.d("ClientTransport", "[$packageName] Transport.onLocationChanged: incoming=${if (arg is Location) TraceLogger.formatLocation(arg) else arg?.toString()}, shouldMock=$shouldMock")
|
TraceLogger.d("ClientTransport", "[$packageName] Transport.onLocationChanged: incoming=${if (arg is Location) TraceLogger.formatLocation(arg) else arg?.toString()}, shouldMock=$shouldMock")
|
||||||
@@ -180,6 +234,7 @@ object LocationHook {
|
|||||||
val name = clazz.name
|
val name = clazz.name
|
||||||
if (hookedListenerClasses.contains(name)) return
|
if (hookedListenerClasses.contains(name)) return
|
||||||
hookedListenerClasses.add(name)
|
hookedListenerClasses.add(name)
|
||||||
|
TraceLogger.i("ClientListener", "[$packageName] Hooked LocationListener class: $name")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
XposedBridge.hookAllMethods(clazz, "onLocationChanged", object : XC_MethodHook() {
|
XposedBridge.hookAllMethods(clazz, "onLocationChanged", object : XC_MethodHook() {
|
||||||
|
|||||||
@@ -0,0 +1,264 @@
|
|||||||
|
package com.lzxnone.openloc.hook.interceptor
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.hardware.Sensor
|
||||||
|
import android.hardware.SensorManager
|
||||||
|
import android.os.SystemClock
|
||||||
|
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
||||||
|
import de.robv.android.xposed.XC_MethodHook
|
||||||
|
import de.robv.android.xposed.XposedBridge
|
||||||
|
import de.robv.android.xposed.XposedHelpers
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
import kotlin.math.PI
|
||||||
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.sin
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运动与姿态传感器拟真拦截器(零分配热路径设计)
|
||||||
|
*
|
||||||
|
* 1. 拦截 SystemSensorManager$SensorEventQueue.dispatchSensorEvent(handle, values, accuracy, timestamp)
|
||||||
|
* 直接原地修改传感器数值数组,无需代理每个 SensorEventListener。
|
||||||
|
* 2. 拦截 SensorManager.registerListenerImpl 建立 handle -> Sensor.type 映射,并在首次缺失时
|
||||||
|
* 通过 getSensorList(Sensor.TYPE_ALL) 兜底补全映射。
|
||||||
|
* 3. 双模式物理拟真(受 GlobalMockMemory.enableSensorSimulation 控制):
|
||||||
|
* - 静止/手持模式(speed <= 0.3 m/s):注入微幅低频生理微颤,避免绝对静止导致融合定位锁死;
|
||||||
|
* - 步行/跑步模式(speed > 0.3 m/s):按速度动态计算步频并叠加自然节律波动,沿当前重力方向
|
||||||
|
* 注入周期性步态冲击波、左右摆臂角速度与严格单调递增的计步增量。
|
||||||
|
*/
|
||||||
|
object SensorHook {
|
||||||
|
|
||||||
|
private val handleToType = ConcurrentHashMap<Int, Int>()
|
||||||
|
private val isInitialized = AtomicBoolean(false)
|
||||||
|
@Volatile private var catalogInitialized = false
|
||||||
|
|
||||||
|
// 低通滤波估算的重力方向向量(用于沿实际手持姿态方向叠加步态垂直冲击)
|
||||||
|
@Volatile private var gravityX = 0f
|
||||||
|
@Volatile private var gravityY = 0f
|
||||||
|
@Volatile private var gravityZ = 9.81f
|
||||||
|
|
||||||
|
// 步态相位与计步器单调递增状态
|
||||||
|
@Volatile private var gaitPhase = 0.0
|
||||||
|
@Volatile private var lastGaitUpdateNs = 0L
|
||||||
|
@Volatile private var baseHardwareSteps = -1f
|
||||||
|
@Volatile private var simulatedStepDelta = 0.0
|
||||||
|
|
||||||
|
fun hook(classLoader: ClassLoader, packageName: String, contextProvider: () -> Context?) {
|
||||||
|
if (packageName == "com.lzxnone.openloc") return
|
||||||
|
if (!isInitialized.compareAndSet(false, true)) return
|
||||||
|
|
||||||
|
hookSensorRegistration(classLoader, contextProvider)
|
||||||
|
hookSensorEventDispatch(classLoader, packageName)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hookSensorRegistration(classLoader: ClassLoader, contextProvider: () -> Context?) {
|
||||||
|
val systemSensorManagerClass = try {
|
||||||
|
XposedHelpers.findClassIfExists("android.hardware.SystemSensorManager", classLoader)
|
||||||
|
?: SensorManager::class.java
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
SensorManager::class.java
|
||||||
|
}
|
||||||
|
|
||||||
|
val hookCallback = object : XC_MethodHook() {
|
||||||
|
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||||
|
for (arg in param.args) {
|
||||||
|
if (arg is Sensor) {
|
||||||
|
recordSensorHandle(arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!catalogInitialized) {
|
||||||
|
val manager = param.thisObject as? SensorManager
|
||||||
|
?: contextProvider()?.getSystemService(Context.SENSOR_SERVICE) as? SensorManager
|
||||||
|
if (manager != null) {
|
||||||
|
populateSensorCatalog(manager)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
XposedBridge.hookAllMethods(systemSensorManagerClass, "registerListenerImpl", hookCallback)
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
try {
|
||||||
|
XposedBridge.hookAllMethods(SensorManager::class.java, "registerListener", hookCallback)
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hookSensorEventDispatch(classLoader: ClassLoader, packageName: String) {
|
||||||
|
val queueClass = try {
|
||||||
|
XposedHelpers.findClassIfExists("android.hardware.SystemSensorManager\$SensorEventQueue", classLoader)
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
} ?: return
|
||||||
|
|
||||||
|
try {
|
||||||
|
XposedBridge.hookAllMethods(queueClass, "dispatchSensorEvent", object : XC_MethodHook() {
|
||||||
|
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||||
|
if (!GlobalMockMemory.isEnabled ||
|
||||||
|
!GlobalMockMemory.enableSensorSimulation ||
|
||||||
|
!GlobalMockMemory.shouldMock(packageName)
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val handle = param.args.getOrNull(0) as? Int ?: return
|
||||||
|
val values = param.args.getOrNull(1) as? FloatArray ?: return
|
||||||
|
val sensorType = handleToType[handle] ?: return
|
||||||
|
|
||||||
|
val nowNs = SystemClock.elapsedRealtimeNanos()
|
||||||
|
val speed = GlobalMockMemory.speed
|
||||||
|
applySensorSimulation(sensorType, values, speed, nowNs)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun populateSensorCatalog(manager: SensorManager) {
|
||||||
|
catalogInitialized = true
|
||||||
|
try {
|
||||||
|
val allSensors = manager.getSensorList(Sensor.TYPE_ALL) ?: return
|
||||||
|
for (sensor in allSensors) {
|
||||||
|
recordSensorHandle(sensor)
|
||||||
|
}
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun recordSensorHandle(sensor: Sensor) {
|
||||||
|
try {
|
||||||
|
val handle = XposedHelpers.callMethod(sensor, "getHandle") as? Int ?: return
|
||||||
|
handleToType[handle] = sensor.type
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
try {
|
||||||
|
val handle = XposedHelpers.getIntField(sensor, "mHandle")
|
||||||
|
handleToType[handle] = sensor.type
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun applySensorSimulation(sensorType: Int, values: FloatArray, speedMps: Float, nowNs: Long) {
|
||||||
|
val timeSec = nowNs * 1e-9
|
||||||
|
|
||||||
|
if (speedMps <= 0.3f) {
|
||||||
|
// 静止/手持模式:注入微幅生理微颤,打破绝对静止判定
|
||||||
|
when (sensorType) {
|
||||||
|
Sensor.TYPE_ACCELEROMETER -> {
|
||||||
|
if (values.size < 3) return
|
||||||
|
updateGravityEstimate(values[0], values[1], values[2])
|
||||||
|
values[0] += (0.035 * sin(timeSec * 7.3) + 0.015 * cos(timeSec * 17.1)).toFloat()
|
||||||
|
values[1] += (0.035 * cos(timeSec * 6.9) + 0.015 * sin(timeSec * 15.7)).toFloat()
|
||||||
|
values[2] += (0.045 * sin(timeSec * 8.1) + 0.018 * cos(timeSec * 19.3)).toFloat()
|
||||||
|
}
|
||||||
|
Sensor.TYPE_LINEAR_ACCELERATION -> {
|
||||||
|
if (values.size < 3) return
|
||||||
|
values[0] += (0.025 * sin(timeSec * 7.3)).toFloat()
|
||||||
|
values[1] += (0.025 * cos(timeSec * 6.9)).toFloat()
|
||||||
|
values[2] += (0.030 * sin(timeSec * 8.1)).toFloat()
|
||||||
|
}
|
||||||
|
Sensor.TYPE_GYROSCOPE -> {
|
||||||
|
if (values.size < 3) return
|
||||||
|
values[0] += (0.008 * sin(timeSec * 3.7)).toFloat()
|
||||||
|
values[1] += (0.008 * cos(timeSec * 4.3)).toFloat()
|
||||||
|
values[2] += (0.006 * sin(timeSec * 2.9)).toFloat()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastGaitUpdateNs = nowNs
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 步行/跑步模式:按速度计算动态步频并推进步态相位
|
||||||
|
val stepFreq = computeStepFrequency(speedMps, timeSec)
|
||||||
|
val dtSec = if (lastGaitUpdateNs > 0L && nowNs > lastGaitUpdateNs) {
|
||||||
|
((nowNs - lastGaitUpdateNs) * 1e-9).coerceIn(0.0, 0.25)
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
}
|
||||||
|
lastGaitUpdateNs = nowNs
|
||||||
|
|
||||||
|
if (dtSec > 0.0) {
|
||||||
|
gaitPhase = (gaitPhase + 2.0 * PI * stepFreq * dtSec) % (4.0 * PI)
|
||||||
|
simulatedStepDelta += stepFreq * dtSec
|
||||||
|
}
|
||||||
|
|
||||||
|
val clampedSpeed = speedMps.coerceIn(0.3f, 6.0f)
|
||||||
|
val impactAmp = 1.2f + (clampedSpeed - 0.3f) * 0.65f
|
||||||
|
val swayAmp = 0.25f + (clampedSpeed - 0.3f) * 0.12f
|
||||||
|
|
||||||
|
when (sensorType) {
|
||||||
|
Sensor.TYPE_ACCELEROMETER -> {
|
||||||
|
if (values.size < 3) return
|
||||||
|
updateGravityEstimate(values[0], values[1], values[2])
|
||||||
|
|
||||||
|
val gNorm = sqrt(gravityX * gravityX + gravityY * gravityY + gravityZ * gravityZ)
|
||||||
|
val ux: Float
|
||||||
|
val uy: Float
|
||||||
|
val uz: Float
|
||||||
|
if (gNorm > 1.0f) {
|
||||||
|
ux = gravityX / gNorm
|
||||||
|
uy = gravityY / gNorm
|
||||||
|
uz = gravityZ / gNorm
|
||||||
|
} else {
|
||||||
|
ux = 0f
|
||||||
|
uy = 0f
|
||||||
|
uz = 1f
|
||||||
|
}
|
||||||
|
|
||||||
|
// 沿实际重力方向叠加主频 + 二次谐波步态冲击
|
||||||
|
val verticalWave = impactAmp * (0.72 * sin(gaitPhase) + 0.28 * sin(2.0 * gaitPhase)).toFloat()
|
||||||
|
val lateralWave = swayAmp * sin(gaitPhase * 0.5).toFloat()
|
||||||
|
|
||||||
|
values[0] += ux * verticalWave + lateralWave * 0.7f
|
||||||
|
values[1] += uy * verticalWave + lateralWave * 0.7f
|
||||||
|
values[2] += uz * verticalWave
|
||||||
|
}
|
||||||
|
Sensor.TYPE_LINEAR_ACCELERATION -> {
|
||||||
|
if (values.size < 3) return
|
||||||
|
val verticalWave = impactAmp * (0.72 * sin(gaitPhase) + 0.28 * sin(2.0 * gaitPhase)).toFloat()
|
||||||
|
val lateralWave = swayAmp * sin(gaitPhase * 0.5).toFloat()
|
||||||
|
values[0] += lateralWave
|
||||||
|
values[1] += lateralWave * 0.5f
|
||||||
|
values[2] += verticalWave
|
||||||
|
}
|
||||||
|
Sensor.TYPE_GYROSCOPE -> {
|
||||||
|
if (values.size < 3) return
|
||||||
|
val gyroAmp = 0.18f + (clampedSpeed - 0.3f) * 0.08f
|
||||||
|
values[0] += (gyroAmp * sin(gaitPhase * 0.5)).toFloat()
|
||||||
|
values[1] += (gyroAmp * 0.8f * cos(gaitPhase * 0.5)).toFloat()
|
||||||
|
values[2] += (gyroAmp * 0.5f * sin(gaitPhase)).toFloat()
|
||||||
|
}
|
||||||
|
Sensor.TYPE_STEP_COUNTER -> {
|
||||||
|
if (values.isEmpty()) return
|
||||||
|
if (baseHardwareSteps < 0f) {
|
||||||
|
baseHardwareSteps = values[0]
|
||||||
|
}
|
||||||
|
val targetSteps = baseHardwareSteps + simulatedStepDelta.toFloat()
|
||||||
|
if (targetSteps > values[0]) {
|
||||||
|
values[0] = targetSteps
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Sensor.TYPE_STEP_DETECTOR -> {
|
||||||
|
if (values.isEmpty()) return
|
||||||
|
values[0] = 1.0f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateGravityEstimate(ax: Float, ay: Float, az: Float) {
|
||||||
|
val alpha = 0.92f
|
||||||
|
gravityX = alpha * gravityX + (1f - alpha) * ax
|
||||||
|
gravityY = alpha * gravityY + (1f - alpha) * ay
|
||||||
|
gravityZ = alpha * gravityZ + (1f - alpha) * az
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据移动速度(m/s)计算拟真步频(Hz),并附加 ±4% 自然节律波动
|
||||||
|
*/
|
||||||
|
internal fun computeStepFrequency(speedMps: Float, timeSec: Double): Float {
|
||||||
|
if (speedMps <= 0.3f) return 0f
|
||||||
|
val clamped = speedMps.coerceIn(0.3f, 6.0f)
|
||||||
|
// 0.3 m/s -> ~1.4 Hz (84 spm), 3.0 m/s -> ~2.6 Hz (156 spm), 6.0 m/s -> ~3.2 Hz (192 spm)
|
||||||
|
val baseFreq = 1.35 + (clamped - 0.3) * 0.32
|
||||||
|
val naturalWobble = 1.0 + 0.04 * sin(timeSec * 0.43)
|
||||||
|
return (baseFreq * naturalWobble).toFloat()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,10 @@ import android.content.BroadcastReceiver
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
|
import android.location.LocationManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
import com.lzxnone.openloc.core.provider.ConfigContract
|
import com.lzxnone.openloc.core.provider.ConfigContract
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
||||||
import com.lzxnone.openloc.hook.model.MockConfig
|
import com.lzxnone.openloc.hook.model.MockConfig
|
||||||
@@ -31,28 +33,34 @@ object ConfigFetcher {
|
|||||||
|
|
||||||
private val isFetching = ThreadLocal.withInitial { false }
|
private val isFetching = ThreadLocal.withInitial { false }
|
||||||
|
|
||||||
|
private val configChangedListeners = java.util.concurrent.CopyOnWriteArrayList<() -> Unit>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取最新配置(优先读取零延迟全局内存)
|
* 在宿主应用启动早期初始化:注册动态广播接收器并拉取初始配置
|
||||||
|
*/
|
||||||
|
fun init(context: Context) {
|
||||||
|
ensureReceiverRegistered(context)
|
||||||
|
getConfig(context, force = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addOnConfigChangedListener(listener: () -> Unit) {
|
||||||
|
configChangedListeners.addIfAbsent(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun notifyConfigChanged() {
|
||||||
|
for (listener in configChangedListeners) {
|
||||||
|
try {
|
||||||
|
listener()
|
||||||
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最新配置(结合广播秒级同步 + ContentProvider 定时兜底拉取)
|
||||||
*/
|
*/
|
||||||
fun getConfig(context: Context, force: Boolean = false): MockConfig {
|
fun getConfig(context: Context, force: Boolean = false): MockConfig {
|
||||||
ensureReceiverRegistered(context)
|
ensureReceiverRegistered(context)
|
||||||
|
|
||||||
// 1. 优先使用系统原生管道注入的全局静态内存
|
|
||||||
if (GlobalMockMemory.isEnabled) {
|
|
||||||
return MockConfig(
|
|
||||||
isEnabled = GlobalMockMemory.isEnabled,
|
|
||||||
latitude = GlobalMockMemory.latitude,
|
|
||||||
longitude = GlobalMockMemory.longitude,
|
|
||||||
altitude = GlobalMockMemory.altitude,
|
|
||||||
accuracy = GlobalMockMemory.accuracy,
|
|
||||||
bearing = GlobalMockMemory.bearing,
|
|
||||||
speed = GlobalMockMemory.speed,
|
|
||||||
mode = GlobalMockMemory.mode,
|
|
||||||
whitelist = GlobalMockMemory.whitelist,
|
|
||||||
blacklist = GlobalMockMemory.blacklist
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
if (!force && cachedConfig != null && (now - lastFetchTime < CACHE_DURATION_MS)) {
|
if (!force && cachedConfig != null && (now - lastFetchTime < CACHE_DURATION_MS)) {
|
||||||
return cachedConfig!!
|
return cachedConfig!!
|
||||||
@@ -64,6 +72,9 @@ object ConfigFetcher {
|
|||||||
|
|
||||||
isFetching.set(true)
|
isFetching.set(true)
|
||||||
return try {
|
return try {
|
||||||
|
// 优先走 system_server 内存隧道(携带实时推进坐标、speed 与 bearing),失败再回退 ContentProvider
|
||||||
|
fetchFromSystemServer(context, now)?.let { return it }
|
||||||
|
|
||||||
val bundle = context.contentResolver.call(
|
val bundle = context.contentResolver.call(
|
||||||
PROVIDER_URI,
|
PROVIDER_URI,
|
||||||
ConfigContract.METHOD_GET_CONFIG,
|
ConfigContract.METHOD_GET_CONFIG,
|
||||||
@@ -80,42 +91,105 @@ object ConfigFetcher {
|
|||||||
isEnabled = bundle.getBoolean(ConfigContract.KEY_ENABLED, false),
|
isEnabled = bundle.getBoolean(ConfigContract.KEY_ENABLED, false),
|
||||||
latitude = bundle.getDouble(ConfigContract.KEY_LATITUDE, 39.908722),
|
latitude = bundle.getDouble(ConfigContract.KEY_LATITUDE, 39.908722),
|
||||||
longitude = bundle.getDouble(ConfigContract.KEY_LONGITUDE, 116.397496),
|
longitude = bundle.getDouble(ConfigContract.KEY_LONGITUDE, 116.397496),
|
||||||
altitude = bundle.getDouble("altitude", 50.0),
|
altitude = bundle.getDouble("altitude", GlobalMockMemory.altitude),
|
||||||
accuracy = bundle.getFloat("accuracy", 5.0f),
|
accuracy = bundle.getFloat("accuracy", GlobalMockMemory.accuracy),
|
||||||
bearing = bundle.getFloat("bearing", 0.0f),
|
bearing = bundle.getFloat("bearing", GlobalMockMemory.bearing),
|
||||||
speed = bundle.getFloat("speed", 0.0f),
|
speed = bundle.getFloat("speed", GlobalMockMemory.speed),
|
||||||
mode = mode,
|
mode = mode,
|
||||||
whitelist = parseSet(whitelistJson),
|
whitelist = parseSet(whitelistJson),
|
||||||
blacklist = parseSet(blacklistJson)
|
blacklist = parseSet(blacklistJson),
|
||||||
|
enableSensorSimulation = bundle.getBoolean(ConfigContract.KEY_ENABLE_SENSOR_SIMULATION, true)
|
||||||
)
|
)
|
||||||
cachedConfig = config
|
cachedConfig = config
|
||||||
lastFetchTime = now
|
lastFetchTime = now
|
||||||
|
|
||||||
// 如果通过 Provider 拉取成功且已开启,同步更新全局静态内存
|
val changed = GlobalMockMemory.isEnabled != config.isEnabled ||
|
||||||
if (config.isEnabled) {
|
GlobalMockMemory.latitude != config.latitude ||
|
||||||
GlobalMockMemory.isEnabled = config.isEnabled
|
GlobalMockMemory.longitude != config.longitude ||
|
||||||
GlobalMockMemory.latitude = config.latitude
|
GlobalMockMemory.mode != config.mode ||
|
||||||
GlobalMockMemory.longitude = config.longitude
|
GlobalMockMemory.enableSensorSimulation != config.enableSensorSimulation
|
||||||
GlobalMockMemory.altitude = config.altitude
|
|
||||||
GlobalMockMemory.accuracy = config.accuracy
|
// 同步更新全局静态内存(包含关闭与坐标变更)
|
||||||
GlobalMockMemory.bearing = config.bearing
|
GlobalMockMemory.isEnabled = config.isEnabled
|
||||||
GlobalMockMemory.speed = config.speed
|
GlobalMockMemory.latitude = config.latitude
|
||||||
GlobalMockMemory.mode = config.mode
|
GlobalMockMemory.longitude = config.longitude
|
||||||
GlobalMockMemory.whitelist = config.whitelist
|
GlobalMockMemory.altitude = config.altitude
|
||||||
GlobalMockMemory.blacklist = config.blacklist
|
GlobalMockMemory.accuracy = config.accuracy
|
||||||
|
GlobalMockMemory.bearing = config.bearing
|
||||||
|
GlobalMockMemory.speed = config.speed
|
||||||
|
GlobalMockMemory.mode = config.mode
|
||||||
|
GlobalMockMemory.whitelist = config.whitelist
|
||||||
|
GlobalMockMemory.blacklist = config.blacklist
|
||||||
|
GlobalMockMemory.enableSensorSimulation = config.enableSensorSimulation
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
notifyConfigChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
config
|
config
|
||||||
} else {
|
} else {
|
||||||
cachedConfig ?: MockConfig()
|
fetchFromSystemServer(context, now) ?: cachedConfig ?: MockConfig()
|
||||||
}
|
}
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
cachedConfig ?: MockConfig()
|
fetchFromSystemServer(context, now) ?: cachedConfig ?: MockConfig()
|
||||||
} finally {
|
} finally {
|
||||||
isFetching.set(false)
|
isFetching.set(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绕过 Android 11+ 包可见性限制,直接通过 system_server 内存隧道读取最新配置
|
||||||
|
*/
|
||||||
|
private fun fetchFromSystemServer(context: Context, now: Long): MockConfig? {
|
||||||
|
return try {
|
||||||
|
val lm = context.getSystemService(Context.LOCATION_SERVICE) as? LocationManager ?: return null
|
||||||
|
val outBundle = Bundle()
|
||||||
|
val ok = lm.sendExtraCommand(
|
||||||
|
GlobalMockMemory.COMMAND_PROVIDER,
|
||||||
|
GlobalMockMemory.COMMAND_GET_CONFIG,
|
||||||
|
outBundle
|
||||||
|
)
|
||||||
|
if (!ok || !outBundle.containsKey(GlobalMockMemory.EXTRA_ENABLED)) return null
|
||||||
|
|
||||||
|
val prevEnabled = GlobalMockMemory.isEnabled
|
||||||
|
val prevLat = GlobalMockMemory.latitude
|
||||||
|
val prevLng = GlobalMockMemory.longitude
|
||||||
|
val prevMode = GlobalMockMemory.mode
|
||||||
|
val prevSensor = GlobalMockMemory.enableSensorSimulation
|
||||||
|
|
||||||
|
GlobalMockMemory.updateFromBundle(outBundle)
|
||||||
|
|
||||||
|
val config = MockConfig(
|
||||||
|
isEnabled = GlobalMockMemory.isEnabled,
|
||||||
|
latitude = GlobalMockMemory.latitude,
|
||||||
|
longitude = GlobalMockMemory.longitude,
|
||||||
|
altitude = GlobalMockMemory.altitude,
|
||||||
|
accuracy = GlobalMockMemory.accuracy,
|
||||||
|
bearing = GlobalMockMemory.bearing,
|
||||||
|
speed = GlobalMockMemory.speed,
|
||||||
|
mode = GlobalMockMemory.mode,
|
||||||
|
whitelist = GlobalMockMemory.whitelist,
|
||||||
|
blacklist = GlobalMockMemory.blacklist,
|
||||||
|
enableSensorSimulation = GlobalMockMemory.enableSensorSimulation
|
||||||
|
)
|
||||||
|
cachedConfig = config
|
||||||
|
lastFetchTime = now
|
||||||
|
|
||||||
|
val changed = prevEnabled != config.isEnabled ||
|
||||||
|
prevLat != config.latitude ||
|
||||||
|
prevLng != config.longitude ||
|
||||||
|
prevMode != config.mode ||
|
||||||
|
prevSensor != config.enableSensorSimulation
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
notifyConfigChanged()
|
||||||
|
}
|
||||||
|
config
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun ensureReceiverRegistered(context: Context) {
|
private fun ensureReceiverRegistered(context: Context) {
|
||||||
if (isReceiverRegistered) return
|
if (isReceiverRegistered) return
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
@@ -126,13 +200,28 @@ object ConfigFetcher {
|
|||||||
override fun onReceive(ctx: Context?, intent: Intent?) {
|
override fun onReceive(ctx: Context?, intent: Intent?) {
|
||||||
val extras = intent?.extras ?: return
|
val extras = intent?.extras ?: return
|
||||||
GlobalMockMemory.updateFromBundle(extras)
|
GlobalMockMemory.updateFromBundle(extras)
|
||||||
|
cachedConfig = MockConfig(
|
||||||
|
isEnabled = GlobalMockMemory.isEnabled,
|
||||||
|
latitude = GlobalMockMemory.latitude,
|
||||||
|
longitude = GlobalMockMemory.longitude,
|
||||||
|
altitude = GlobalMockMemory.altitude,
|
||||||
|
accuracy = GlobalMockMemory.accuracy,
|
||||||
|
bearing = GlobalMockMemory.bearing,
|
||||||
|
speed = GlobalMockMemory.speed,
|
||||||
|
mode = GlobalMockMemory.mode,
|
||||||
|
whitelist = GlobalMockMemory.whitelist,
|
||||||
|
blacklist = GlobalMockMemory.blacklist,
|
||||||
|
enableSensorSimulation = GlobalMockMemory.enableSensorSimulation
|
||||||
|
)
|
||||||
lastFetchTime = System.currentTimeMillis()
|
lastFetchTime = System.currentTimeMillis()
|
||||||
|
notifyConfigChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val regCtx = context.applicationContext ?: context
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
context.applicationContext.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED)
|
regCtx.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED)
|
||||||
} else {
|
} else {
|
||||||
context.applicationContext.registerReceiver(receiver, filter)
|
regCtx.registerReceiver(receiver, filter)
|
||||||
}
|
}
|
||||||
isReceiverRegistered = true
|
isReceiverRegistered = true
|
||||||
} catch (_: Throwable) {}
|
} catch (_: Throwable) {}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ object GlobalMockMemory {
|
|||||||
|
|
||||||
const val COMMAND_PROVIDER = "openloc"
|
const val COMMAND_PROVIDER = "openloc"
|
||||||
const val COMMAND_SYNC = "sync_config"
|
const val COMMAND_SYNC = "sync_config"
|
||||||
|
const val COMMAND_GET_CONFIG = "get_config"
|
||||||
|
|
||||||
const val EXTRA_ENABLED = "is_enabled"
|
const val EXTRA_ENABLED = "is_enabled"
|
||||||
const val EXTRA_LATITUDE = "latitude"
|
const val EXTRA_LATITUDE = "latitude"
|
||||||
@@ -25,6 +26,10 @@ object GlobalMockMemory {
|
|||||||
const val EXTRA_MODE = "mode"
|
const val EXTRA_MODE = "mode"
|
||||||
const val EXTRA_WHITELIST = "whitelist"
|
const val EXTRA_WHITELIST = "whitelist"
|
||||||
const val EXTRA_BLACKLIST = "blacklist"
|
const val EXTRA_BLACKLIST = "blacklist"
|
||||||
|
const val EXTRA_SENSOR_SIMULATION = "enable_sensor_simulation"
|
||||||
|
const val EXTRA_NOTIFICATION_ENABLED = "enable_notification"
|
||||||
|
const val EXTRA_RUNNING_MODE_ENABLED = "running_mode_enabled"
|
||||||
|
const val EXTRA_JITTER_ENABLED = "enable_jitter"
|
||||||
|
|
||||||
@Volatile var isEnabled: Boolean = false
|
@Volatile var isEnabled: Boolean = false
|
||||||
@Volatile var latitude: Double = 39.908722
|
@Volatile var latitude: Double = 39.908722
|
||||||
@@ -37,6 +42,10 @@ object GlobalMockMemory {
|
|||||||
@Volatile var locationName: String = ""
|
@Volatile var locationName: String = ""
|
||||||
@Volatile var whitelist: Set<String> = emptySet()
|
@Volatile var whitelist: Set<String> = emptySet()
|
||||||
@Volatile var blacklist: Set<String> = emptySet()
|
@Volatile var blacklist: Set<String> = emptySet()
|
||||||
|
@Volatile var enableSensorSimulation: Boolean = true
|
||||||
|
@Volatile var enableNotification: Boolean = false
|
||||||
|
@Volatile var runningModeEnabled: Boolean = false
|
||||||
|
@Volatile var enableJitter: Boolean = true
|
||||||
|
|
||||||
fun updateFromBundle(bundle: Bundle) {
|
fun updateFromBundle(bundle: Bundle) {
|
||||||
isEnabled = bundle.getBoolean(EXTRA_ENABLED, isEnabled)
|
isEnabled = bundle.getBoolean(EXTRA_ENABLED, isEnabled)
|
||||||
@@ -48,6 +57,10 @@ object GlobalMockMemory {
|
|||||||
speed = bundle.getFloat(EXTRA_SPEED, speed)
|
speed = bundle.getFloat(EXTRA_SPEED, speed)
|
||||||
mode = bundle.getString(EXTRA_MODE, mode) ?: mode
|
mode = bundle.getString(EXTRA_MODE, mode) ?: mode
|
||||||
locationName = bundle.getString(EXTRA_LOCATION_NAME, locationName) ?: locationName
|
locationName = bundle.getString(EXTRA_LOCATION_NAME, locationName) ?: locationName
|
||||||
|
enableSensorSimulation = bundle.getBoolean(EXTRA_SENSOR_SIMULATION, enableSensorSimulation)
|
||||||
|
enableNotification = bundle.getBoolean(EXTRA_NOTIFICATION_ENABLED, enableNotification)
|
||||||
|
runningModeEnabled = bundle.getBoolean(EXTRA_RUNNING_MODE_ENABLED, runningModeEnabled)
|
||||||
|
enableJitter = bundle.getBoolean(EXTRA_JITTER_ENABLED, enableJitter)
|
||||||
|
|
||||||
val whiteListArray = bundle.getStringArrayList(EXTRA_WHITELIST)
|
val whiteListArray = bundle.getStringArrayList(EXTRA_WHITELIST)
|
||||||
if (whiteListArray != null) {
|
if (whiteListArray != null) {
|
||||||
@@ -71,6 +84,10 @@ object GlobalMockMemory {
|
|||||||
putFloat(EXTRA_SPEED, speed)
|
putFloat(EXTRA_SPEED, speed)
|
||||||
putString(EXTRA_MODE, mode)
|
putString(EXTRA_MODE, mode)
|
||||||
putString(EXTRA_LOCATION_NAME, locationName)
|
putString(EXTRA_LOCATION_NAME, locationName)
|
||||||
|
putBoolean(EXTRA_SENSOR_SIMULATION, enableSensorSimulation)
|
||||||
|
putBoolean(EXTRA_NOTIFICATION_ENABLED, enableNotification)
|
||||||
|
putBoolean(EXTRA_RUNNING_MODE_ENABLED, runningModeEnabled)
|
||||||
|
putBoolean(EXTRA_JITTER_ENABLED, enableJitter)
|
||||||
putStringArrayList(EXTRA_WHITELIST, ArrayList(whitelist))
|
putStringArrayList(EXTRA_WHITELIST, ArrayList(whitelist))
|
||||||
putStringArrayList(EXTRA_BLACKLIST, ArrayList(blacklist))
|
putStringArrayList(EXTRA_BLACKLIST, ArrayList(blacklist))
|
||||||
}
|
}
|
||||||
@@ -108,13 +125,17 @@ object GlobalMockMemory {
|
|||||||
* 生成标准可用的 Mock Location 对象
|
* 生成标准可用的 Mock Location 对象
|
||||||
*/
|
*/
|
||||||
fun createLocation(provider: String = "gps"): Location {
|
fun createLocation(provider: String = "gps"): Location {
|
||||||
|
val currentSpeed = this@GlobalMockMemory.speed
|
||||||
|
val hasValidBearing = currentSpeed > 0.1f
|
||||||
return Location(provider).apply {
|
return Location(provider).apply {
|
||||||
latitude = this@GlobalMockMemory.latitude
|
latitude = this@GlobalMockMemory.latitude
|
||||||
longitude = this@GlobalMockMemory.longitude
|
longitude = this@GlobalMockMemory.longitude
|
||||||
altitude = this@GlobalMockMemory.altitude
|
altitude = this@GlobalMockMemory.altitude
|
||||||
accuracy = this@GlobalMockMemory.accuracy
|
accuracy = this@GlobalMockMemory.accuracy
|
||||||
bearing = this@GlobalMockMemory.bearing
|
speed = currentSpeed
|
||||||
speed = this@GlobalMockMemory.speed
|
if (hasValidBearing) {
|
||||||
|
bearing = this@GlobalMockMemory.bearing
|
||||||
|
}
|
||||||
time = System.currentTimeMillis()
|
time = System.currentTimeMillis()
|
||||||
elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
|
elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
|
||||||
|
|
||||||
@@ -122,28 +143,10 @@ object GlobalMockMemory {
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
verticalAccuracyMeters = 1.5f
|
verticalAccuracyMeters = 1.5f
|
||||||
speedAccuracyMetersPerSecond = 0.1f
|
speedAccuracyMetersPerSecond = 0.1f
|
||||||
bearingAccuracyDegrees = 1.0f
|
if (hasValidBearing) {
|
||||||
|
bearingAccuracyDegrees = 1.0f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 就地覆写现有 Location 对象
|
|
||||||
*/
|
|
||||||
fun applyToLocation(location: Location) {
|
|
||||||
location.latitude = latitude
|
|
||||||
location.longitude = longitude
|
|
||||||
location.altitude = altitude
|
|
||||||
location.accuracy = accuracy
|
|
||||||
location.bearing = bearing
|
|
||||||
location.speed = speed
|
|
||||||
location.time = System.currentTimeMillis()
|
|
||||||
location.elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
location.verticalAccuracyMeters = 1.5f
|
|
||||||
location.speedAccuracyMetersPerSecond = 0.1f
|
|
||||||
location.bearingAccuracyDegrees = 1.0f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,23 @@ data class MockConfig(
|
|||||||
val speed: Float = 0.0f,
|
val speed: Float = 0.0f,
|
||||||
val mode: String = "GLOBAL",
|
val mode: String = "GLOBAL",
|
||||||
val whitelist: Set<String> = emptySet(),
|
val whitelist: Set<String> = emptySet(),
|
||||||
val blacklist: Set<String> = emptySet()
|
val blacklist: Set<String> = emptySet(),
|
||||||
|
val enableSensorSimulation: Boolean = true
|
||||||
) {
|
) {
|
||||||
fun shouldMock(packageName: String?): Boolean {
|
fun shouldMock(packageName: String?): Boolean {
|
||||||
if (!isEnabled) return false
|
if (!isEnabled) return false
|
||||||
if (packageName.isNullOrBlank()) return true
|
if (packageName.isNullOrBlank()) return true
|
||||||
if (packageName == "com.lzxnone.openloc" || packageName == "android") return false
|
if (packageName == "com.lzxnone.openloc" || packageName == "android") return false
|
||||||
|
if (packageName.startsWith("com.android.server.") ||
|
||||||
|
packageName.startsWith("android.") ||
|
||||||
|
packageName.startsWith("com.qualcomm.") ||
|
||||||
|
packageName.startsWith("com.qti.") ||
|
||||||
|
packageName == "com.xiaomi.metoknlp" ||
|
||||||
|
packageName == "com.xiaomi.location.fused" ||
|
||||||
|
packageName.contains(".hal.") ||
|
||||||
|
packageName.contains("Gpo4Client")) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return when (mode.uppercase()) {
|
return when (mode.uppercase()) {
|
||||||
"WHITELIST" -> whitelist.contains(packageName)
|
"WHITELIST" -> whitelist.contains(packageName)
|
||||||
"BLACKLIST" -> !blacklist.contains(packageName)
|
"BLACKLIST" -> !blacklist.contains(packageName)
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
package com.lzxnone.openloc.hook.system
|
package com.lzxnone.openloc.hook.system
|
||||||
|
|
||||||
|
import android.app.Notification
|
||||||
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
|
import android.graphics.drawable.Icon
|
||||||
import android.location.Location
|
import android.location.Location
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.IInterface
|
import android.os.IInterface
|
||||||
|
import com.lzxnone.openloc.R
|
||||||
import com.lzxnone.openloc.core.util.TraceLogger
|
import com.lzxnone.openloc.core.util.TraceLogger
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
||||||
import de.robv.android.xposed.XC_MethodHook
|
import de.robv.android.xposed.XC_MethodHook
|
||||||
@@ -36,7 +46,9 @@ object SystemServerHook {
|
|||||||
|
|
||||||
// 活跃监听器与其所属目标包名的映射表(以 IBinder 为 key,彻底消除 Class 静态闭包污染)
|
// 活跃监听器与其所属目标包名的映射表(以 IBinder 为 key,彻底消除 Class 静态闭包污染)
|
||||||
private val activeListeners = ConcurrentHashMap<IBinder, String>()
|
private val activeListeners = ConcurrentHashMap<IBinder, String>()
|
||||||
|
private val activeListenerInstances = ConcurrentHashMap<IBinder, Pair<Any, String>>()
|
||||||
private val activeCallbacks = ConcurrentHashMap<IBinder, String>()
|
private val activeCallbacks = ConcurrentHashMap<IBinder, String>()
|
||||||
|
private val pushExecutor = java.util.concurrent.Executors.newSingleThreadExecutor()
|
||||||
|
|
||||||
// 已挂钩 onLocationChanged 的类名集合,防止重复 Hook
|
// 已挂钩 onLocationChanged 的类名集合,防止重复 Hook
|
||||||
private val hookedListenerClasses = Collections.synchronizedSet(mutableSetOf<String>())
|
private val hookedListenerClasses = Collections.synchronizedSet(mutableSetOf<String>())
|
||||||
@@ -44,6 +56,11 @@ object SystemServerHook {
|
|||||||
// 已挂钩 Wi-Fi 服务的类名集合,防止重复 Hook
|
// 已挂钩 Wi-Fi 服务的类名集合,防止重复 Hook
|
||||||
private val hookedWifiClasses = Collections.synchronizedSet(mutableSetOf<String>())
|
private val hookedWifiClasses = Collections.synchronizedSet(mutableSetOf<String>())
|
||||||
|
|
||||||
|
private const val SYSTEM_NOTIFICATION_CHANNEL_ID = "openloc_system_keepalive"
|
||||||
|
private const val SYSTEM_NOTIFICATION_ID = 10086
|
||||||
|
@Volatile private var systemContext: Context? = null
|
||||||
|
@Volatile private var linkedProcessToken: IBinder? = null
|
||||||
|
|
||||||
fun hook(classLoader: ClassLoader) {
|
fun hook(classLoader: ClassLoader) {
|
||||||
XposedBridge.log("[OpenLoc] [SystemServer] Initializing GhostMapX architecture in system_server...")
|
XposedBridge.log("[OpenLoc] [SystemServer] Initializing GhostMapX architecture in system_server...")
|
||||||
|
|
||||||
@@ -81,11 +98,48 @@ object SystemServerHook {
|
|||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
||||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
override fun beforeHookedMethod(param: MethodHookParam) {
|
||||||
val provider = param.args.getOrNull(0) as? String
|
val provider = param.args.getOrNull(0) as? String
|
||||||
|
val command = param.args.getOrNull(1) as? String
|
||||||
val extras = param.args.getOrNull(2) as? Bundle
|
val extras = param.args.getOrNull(2) as? Bundle
|
||||||
if (provider == GlobalMockMemory.COMMAND_PROVIDER || provider == "ghostmapx") {
|
if (provider == GlobalMockMemory.COMMAND_PROVIDER || provider == "ghostmapx") {
|
||||||
if (extras != null) {
|
if (command == GlobalMockMemory.COMMAND_GET_CONFIG && extras != null) {
|
||||||
|
extras.putAll(GlobalMockMemory.toBundle())
|
||||||
|
param.result = true
|
||||||
|
} else if (extras != null) {
|
||||||
|
if (systemContext == null) {
|
||||||
|
systemContext = try {
|
||||||
|
XposedHelpers.getObjectField(param.thisObject, "mContext") as? Context
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
} ?: resolveSystemContext(classLoader)
|
||||||
|
}
|
||||||
GlobalMockMemory.updateFromBundle(extras)
|
GlobalMockMemory.updateFromBundle(extras)
|
||||||
|
val token = extras.getBinder("process_token")
|
||||||
|
if (token != null && token !== linkedProcessToken) {
|
||||||
|
linkedProcessToken = token
|
||||||
|
try {
|
||||||
|
token.linkToDeath({
|
||||||
|
if (linkedProcessToken === token) {
|
||||||
|
linkedProcessToken = null
|
||||||
|
}
|
||||||
|
if (GlobalMockMemory.isEnabled && GlobalMockMemory.enableNotification) {
|
||||||
|
postSystemNotification(isProcessAlive = false)
|
||||||
|
}
|
||||||
|
}, 0)
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
if (GlobalMockMemory.isEnabled && GlobalMockMemory.enableNotification) {
|
||||||
|
postSystemNotification(isProcessAlive = false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (GlobalMockMemory.isEnabled && GlobalMockMemory.enableNotification) {
|
||||||
|
postSystemNotification(isProcessAlive = true)
|
||||||
|
} else {
|
||||||
|
cancelSystemNotification()
|
||||||
|
}
|
||||||
TraceLogger.i("SystemServer", "Config Synced -> Enabled=${GlobalMockMemory.isEnabled}, Target=(${GlobalMockMemory.latitude}, ${GlobalMockMemory.longitude}), Mode=${GlobalMockMemory.mode}, Whitelist=${GlobalMockMemory.whitelist.size}, Blacklist=${GlobalMockMemory.blacklist.size}")
|
TraceLogger.i("SystemServer", "Config Synced -> Enabled=${GlobalMockMemory.isEnabled}, Target=(${GlobalMockMemory.latitude}, ${GlobalMockMemory.longitude}), Mode=${GlobalMockMemory.mode}, Whitelist=${GlobalMockMemory.whitelist.size}, Blacklist=${GlobalMockMemory.blacklist.size}")
|
||||||
|
if (GlobalMockMemory.isEnabled) {
|
||||||
|
pushLocationToActiveListeners()
|
||||||
|
}
|
||||||
param.result = true
|
param.result = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,7 +197,7 @@ object SystemServerHook {
|
|||||||
arg.javaClass.name.contains("Consumer") ||
|
arg.javaClass.name.contains("Consumer") ||
|
||||||
arg.javaClass.name.contains("Transport"))) {
|
arg.javaClass.name.contains("Transport"))) {
|
||||||
val binder = (arg as? IInterface)?.asBinder() ?: (arg as? IBinder)
|
val binder = (arg as? IInterface)?.asBinder() ?: (arg as? IBinder)
|
||||||
if (binder != null && pkg != null) {
|
if (binder != null) {
|
||||||
activeCallbacks[binder] = pkg
|
activeCallbacks[binder] = pkg
|
||||||
TraceLogger.i("SystemServer", "Bound callback binder=$binder to pkg=$pkg")
|
TraceLogger.i("SystemServer", "Bound callback binder=$binder to pkg=$pkg")
|
||||||
try {
|
try {
|
||||||
@@ -188,12 +242,14 @@ object SystemServerHook {
|
|||||||
arg.javaClass.name.contains("Transport") ||
|
arg.javaClass.name.contains("Transport") ||
|
||||||
arg.javaClass.name.contains("Callback"))) {
|
arg.javaClass.name.contains("Callback"))) {
|
||||||
val binder = (arg as? IInterface)?.asBinder() ?: (arg as? IBinder)
|
val binder = (arg as? IInterface)?.asBinder() ?: (arg as? IBinder)
|
||||||
if (binder != null && pkg != null) {
|
if (binder != null) {
|
||||||
activeListeners[binder] = pkg
|
activeListeners[binder] = pkg
|
||||||
|
activeListenerInstances[binder] = arg to provider
|
||||||
TraceLogger.i("SystemServer", "Bound listener binder=$binder to pkg=$pkg")
|
TraceLogger.i("SystemServer", "Bound listener binder=$binder to pkg=$pkg")
|
||||||
try {
|
try {
|
||||||
binder.linkToDeath({
|
binder.linkToDeath({
|
||||||
activeListeners.remove(binder)
|
activeListeners.remove(binder)
|
||||||
|
activeListenerInstances.remove(binder)
|
||||||
TraceLogger.d("SystemServer", "Listener binder dead for pkg=$pkg")
|
TraceLogger.d("SystemServer", "Listener binder dead for pkg=$pkg")
|
||||||
}, 0)
|
}, 0)
|
||||||
} catch (_: Throwable) {}
|
} catch (_: Throwable) {}
|
||||||
@@ -323,6 +379,25 @@ object SystemServerHook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1Hz 配置同步时主动向已登记的目标应用监听器推送最新坐标(解决未勾选目标软件时跑步模式不动的问题)
|
||||||
|
*/
|
||||||
|
private fun pushLocationToActiveListeners() {
|
||||||
|
if (!GlobalMockMemory.isEnabled || activeListenerInstances.isEmpty()) return
|
||||||
|
pushExecutor.execute {
|
||||||
|
for ((binder, entry) in activeListenerInstances) {
|
||||||
|
val pkg = activeListeners[binder] ?: continue
|
||||||
|
if (!GlobalMockMemory.shouldMock(pkg)) continue
|
||||||
|
if (!binder.isBinderAlive) {
|
||||||
|
activeListeners.remove(binder)
|
||||||
|
activeListenerInstances.remove(binder)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sendInitialMockLocation(entry.first, entry.second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 首帧秒推辅助方法(对齐 GhostMapX Lcf.a 144-200行)
|
* 首帧秒推辅助方法(对齐 GhostMapX Lcf.a 144-200行)
|
||||||
*/
|
*/
|
||||||
@@ -574,4 +649,141 @@ object SystemServerHook {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun resolveSystemContext(classLoader: ClassLoader): Context? {
|
||||||
|
return try {
|
||||||
|
val atClass = XposedHelpers.findClass("android.app.ActivityThread", classLoader)
|
||||||
|
val at = XposedHelpers.callStaticMethod(atClass, "currentActivityThread")
|
||||||
|
XposedHelpers.callMethod(at, "getSystemContext") as? Context
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun postSystemNotification(isProcessAlive: Boolean = true) {
|
||||||
|
val sysCtx = systemContext ?: return
|
||||||
|
val identity = Binder.clearCallingIdentity()
|
||||||
|
try {
|
||||||
|
val manager = sysCtx.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager ?: return
|
||||||
|
val openLocCtx = try {
|
||||||
|
sysCtx.createPackageContext("com.lzxnone.openloc", Context.CONTEXT_IGNORE_SECURITY)
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
sysCtx
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
val channel = NotificationChannel(
|
||||||
|
SYSTEM_NOTIFICATION_CHANNEL_ID,
|
||||||
|
openLocCtx.getString(R.string.service_keepalive_channel_name),
|
||||||
|
NotificationManager.IMPORTANCE_LOW
|
||||||
|
).apply {
|
||||||
|
setShowBadge(false)
|
||||||
|
}
|
||||||
|
manager.createNotificationChannel(channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
val launchIntent = Intent().apply {
|
||||||
|
setClassName("com.lzxnone.openloc", "com.lzxnone.openloc.MainActivity")
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
}
|
||||||
|
val pendingIntent = PendingIntent.getActivity(
|
||||||
|
sysCtx,
|
||||||
|
0,
|
||||||
|
launchIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
|
|
||||||
|
val modeText = if (GlobalMockMemory.runningModeEnabled) {
|
||||||
|
openLocCtx.getString(R.string.notification_mode_running)
|
||||||
|
} else {
|
||||||
|
openLocCtx.getString(R.string.notification_mode_static)
|
||||||
|
}
|
||||||
|
val title = openLocCtx.getString(R.string.notification_title_format, modeText)
|
||||||
|
|
||||||
|
val locationName = GlobalMockMemory.locationName.takeIf { it.isNotBlank() }
|
||||||
|
?: openLocCtx.getString(R.string.notification_location_unnamed)
|
||||||
|
val coordLine = openLocCtx.getString(
|
||||||
|
R.string.notification_coord_line,
|
||||||
|
GlobalMockMemory.latitude,
|
||||||
|
GlobalMockMemory.longitude
|
||||||
|
)
|
||||||
|
|
||||||
|
val displaySpeed = if (isProcessAlive) GlobalMockMemory.speed else 0.0f
|
||||||
|
val displayBearing = if (isProcessAlive && GlobalMockMemory.speed > 0.05f) GlobalMockMemory.bearing else 0.0f
|
||||||
|
val speedBearingLine = openLocCtx.getString(
|
||||||
|
R.string.notification_speed_bearing_line,
|
||||||
|
displaySpeed,
|
||||||
|
displayBearing
|
||||||
|
)
|
||||||
|
|
||||||
|
val (accelX, accelY, accelZ) = if (GlobalMockMemory.enableSensorSimulation && displaySpeed > 0.05f) {
|
||||||
|
val clampedSpeed = displaySpeed.coerceIn(0.3f, 6.0f)
|
||||||
|
val stepFreq = (1.65f + (clampedSpeed - 1.0f) * 0.22f).coerceIn(1.3f, 3.2f)
|
||||||
|
val nowSec = System.currentTimeMillis() / 1000.0
|
||||||
|
val phase = (nowSec * 2.0 * Math.PI * stepFreq) % (2.0 * Math.PI)
|
||||||
|
val impactAmp = 1.2f + (clampedSpeed - 0.3f) * 0.65f
|
||||||
|
val swayAmp = 0.25f + (clampedSpeed - 0.3f) * 0.12f
|
||||||
|
val ax = swayAmp * kotlin.math.sin(phase * 0.5).toFloat()
|
||||||
|
val ay = swayAmp * 0.5f * kotlin.math.sin(phase * 0.5).toFloat()
|
||||||
|
val az = 9.81f + impactAmp * (0.72 * kotlin.math.sin(phase) + 0.28 * kotlin.math.sin(2.0 * phase)).toFloat()
|
||||||
|
Triple(ax, ay, az)
|
||||||
|
} else {
|
||||||
|
Triple(0.0f, 0.0f, 9.81f)
|
||||||
|
}
|
||||||
|
val accelLine = openLocCtx.getString(
|
||||||
|
R.string.notification_accel_line,
|
||||||
|
accelX,
|
||||||
|
accelY,
|
||||||
|
accelZ
|
||||||
|
)
|
||||||
|
|
||||||
|
val fullText = "$locationName\n$coordLine\n$speedBearingLine\n$accelLine"
|
||||||
|
|
||||||
|
val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
Notification.Builder(sysCtx, SYSTEM_NOTIFICATION_CHANNEL_ID)
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
Notification.Builder(sysCtx)
|
||||||
|
}
|
||||||
|
|
||||||
|
val smallIcon = Icon.createWithResource("com.lzxnone.openloc", R.mipmap.ic_launcher)
|
||||||
|
val largeIcon = try {
|
||||||
|
BitmapFactory.decodeResource(openLocCtx.resources, R.mipmap.ic_launcher_round)
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.setSmallIcon(smallIcon)
|
||||||
|
.apply {
|
||||||
|
if (largeIcon != null) {
|
||||||
|
setLargeIcon(largeIcon)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.setContentTitle(title)
|
||||||
|
.setContentText(locationName)
|
||||||
|
.setStyle(Notification.BigTextStyle().bigText(fullText))
|
||||||
|
.setOngoing(true)
|
||||||
|
.setOnlyAlertOnce(true)
|
||||||
|
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||||
|
.setContentIntent(pendingIntent)
|
||||||
|
|
||||||
|
manager.notify(SYSTEM_NOTIFICATION_ID, builder.build())
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
TraceLogger.e("SystemServer", "postSystemNotification failed: ${t.message}")
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(identity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun cancelSystemNotification() {
|
||||||
|
val sysCtx = systemContext ?: return
|
||||||
|
val identity = Binder.clearCallingIdentity()
|
||||||
|
try {
|
||||||
|
val manager = sysCtx.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager ?: return
|
||||||
|
manager.cancel(SYSTEM_NOTIFICATION_ID)
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(identity)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
package com.lzxnone.openloc.ui.components
|
package com.lzxnone.openloc.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.Info
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
@@ -18,6 +22,8 @@ import com.lzxnone.openloc.R
|
|||||||
@Composable
|
@Composable
|
||||||
fun OpenLocTopBar(
|
fun OpenLocTopBar(
|
||||||
title: String = stringResource(id = R.string.app_name),
|
title: String = stringResource(id = R.string.app_name),
|
||||||
|
onAboutClick: () -> Unit = {},
|
||||||
|
showAboutAction: Boolean = true,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
@@ -29,6 +35,17 @@ fun OpenLocTopBar(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
actions = {
|
||||||
|
if (showAboutAction) {
|
||||||
|
IconButton(onClick = onAboutClick) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.Info,
|
||||||
|
contentDescription = stringResource(id = R.string.section_about),
|
||||||
|
tint = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
colors = TopAppBarDefaults.topAppBarColors(
|
colors = TopAppBarDefaults.topAppBarColors(
|
||||||
containerColor = MaterialTheme.colorScheme.background,
|
containerColor = MaterialTheme.colorScheme.background,
|
||||||
titleContentColor = MaterialTheme.colorScheme.onBackground
|
titleContentColor = MaterialTheme.colorScheme.onBackground
|
||||||
|
|||||||
@@ -4,18 +4,13 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.heightIn
|
import androidx.compose.foundation.layout.heightIn
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.outlined.NewReleases
|
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
@@ -34,27 +29,25 @@ import com.lzxnone.openloc.core.util.UpdateInfo
|
|||||||
@Composable
|
@Composable
|
||||||
fun UpdateDialog(
|
fun UpdateDialog(
|
||||||
updateInfo: UpdateInfo,
|
updateInfo: UpdateInfo,
|
||||||
onDismiss: () -> Unit
|
onDismiss: () -> Unit,
|
||||||
|
onDontShowAgain: (Long) -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scrollState = rememberScrollState()
|
val scrollState = rememberScrollState()
|
||||||
|
|
||||||
|
val displayVersion = if (updateInfo.versionName.startsWith("v", ignoreCase = true)) {
|
||||||
|
"V" + updateInfo.versionName.substring(1)
|
||||||
|
} else {
|
||||||
|
"V${updateInfo.versionName}"
|
||||||
|
}
|
||||||
|
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
icon = {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Outlined.NewReleases,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colorScheme.primary,
|
|
||||||
modifier = Modifier.size(32.dp)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(id = R.string.home_update_available_title, updateInfo.latestVersion),
|
text = stringResource(id = R.string.update_dialog_title_format, displayVersion),
|
||||||
style = MaterialTheme.typography.titleLarge.copy(
|
style = MaterialTheme.typography.titleLarge,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
text = {
|
text = {
|
||||||
@@ -64,57 +57,47 @@ fun UpdateDialog(
|
|||||||
.heightIn(max = 280.dp)
|
.heightIn(max = 280.dp)
|
||||||
.verticalScroll(scrollState)
|
.verticalScroll(scrollState)
|
||||||
) {
|
) {
|
||||||
if (updateInfo.releaseTitle.isNotBlank() && updateInfo.releaseTitle != updateInfo.latestVersion) {
|
Text(
|
||||||
Text(
|
text = updateInfo.changelog,
|
||||||
text = updateInfo.releaseTitle,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
style = MaterialTheme.typography.titleMedium.copy(
|
color = MaterialTheme.colorScheme.onSurface
|
||||||
fontWeight = FontWeight.SemiBold
|
)
|
||||||
),
|
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateInfo.changelog.isNotBlank()) {
|
|
||||||
Text(
|
|
||||||
text = updateInfo.changelog,
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Text(
|
|
||||||
text = stringResource(id = R.string.home_update_dialog_msg),
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
openBrowser(context, updateInfo.releaseUrl)
|
openBrowser(context, updateInfo.downloadUrl)
|
||||||
onDismiss()
|
onDismiss()
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Text(text = stringResource(id = R.string.home_update_btn_go))
|
Text(text = stringResource(id = R.string.btn_download_update))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(onClick = onDismiss) {
|
Row {
|
||||||
Text(text = stringResource(id = R.string.home_update_btn_later))
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
onDontShowAgain(updateInfo.versionCode)
|
||||||
|
onDismiss()
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text(text = stringResource(id = R.string.btn_dont_show_again))
|
||||||
|
}
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text(text = stringResource(id = R.string.action_cancel))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openBrowser(context: Context, url: String) {
|
private fun openBrowser(context: Context, url: String) {
|
||||||
try {
|
if (url.isBlank()) return
|
||||||
val targetUri = Uri.parse(url.ifBlank { "https://github.com/lzxnone/openloc/releases" })
|
runCatching {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, targetUri).apply {
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)).apply {
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
}
|
}
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
} catch (_: Exception) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,54 +1,66 @@
|
|||||||
package com.lzxnone.openloc.ui.screens
|
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 android.Manifest
|
import android.Manifest
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.fadeIn
|
||||||
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.animation.slideInHorizontally
|
import androidx.compose.animation.slideInHorizontally
|
||||||
import androidx.compose.animation.slideOutHorizontally
|
import androidx.compose.animation.slideOutHorizontally
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
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.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.lzxnone.openloc.BuildConfig
|
||||||
import com.lzxnone.openloc.R
|
import com.lzxnone.openloc.R
|
||||||
|
import com.lzxnone.openloc.core.util.HookStatus
|
||||||
import com.lzxnone.openloc.core.util.UpdateChecker
|
import com.lzxnone.openloc.core.util.UpdateChecker
|
||||||
import com.lzxnone.openloc.core.util.UpdateInfo
|
import com.lzxnone.openloc.core.util.UpdateInfo
|
||||||
import com.lzxnone.openloc.data.preference.AppMockMode
|
import com.lzxnone.openloc.data.preference.AppMockMode
|
||||||
|
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.components.UpdateDialog
|
import com.lzxnone.openloc.ui.components.UpdateDialog
|
||||||
|
import com.lzxnone.openloc.ui.navigation.NavTab
|
||||||
|
import com.lzxnone.openloc.ui.screens.about.AboutScreen
|
||||||
import com.lzxnone.openloc.ui.screens.apps.AppSelectionScreen
|
import com.lzxnone.openloc.ui.screens.apps.AppSelectionScreen
|
||||||
|
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 kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根容器页面:承载 TopAppBar、底部导航栏与各个 Tab 内容切换
|
* 根容器页面:承载 TopAppBar、底部导航栏与各个 Tab 内容切换
|
||||||
*/
|
*/
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(
|
fun MainScreen(
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
@@ -57,8 +69,10 @@ fun MainScreen(
|
|||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
var currentTab by rememberSaveable { mutableStateOf(NavTab.HOME) }
|
var currentTab by rememberSaveable { mutableStateOf(NavTab.HOME) }
|
||||||
|
var isAboutViewOpen by rememberSaveable { mutableStateOf(false) }
|
||||||
var activeAppSelectionMode by rememberSaveable { mutableStateOf<AppMockMode?>(null) }
|
var activeAppSelectionMode by rememberSaveable { mutableStateOf<AppMockMode?>(null) }
|
||||||
var updateInfoToDisplay by remember { mutableStateOf<UpdateInfo?>(null) }
|
var updateInfoToDisplay by remember { mutableStateOf<UpdateInfo?>(null) }
|
||||||
|
var isCheckingAppUpdate by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
// 响应式的总开关状态与激活状态
|
// 响应式的总开关状态与激活状态
|
||||||
val isServiceEnabled = AppPreferences.isServiceEnabled
|
val isServiceEnabled = AppPreferences.isServiceEnabled
|
||||||
@@ -91,26 +105,26 @@ fun MainScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 每次进入软件,若开启了自动检查更新,则在后台静默检测,发现新版才弹窗
|
// 每次进入软件,若开启了自动检查更新,则在后台静默检测,发现新版且未被抑制才弹窗
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
if (AppPreferences.isAutoCheckUpdateEnabled) {
|
if (AppPreferences.isAutoCheckUpdateEnabled) {
|
||||||
val result = UpdateChecker.checkUpdate(currentVersion = "v1.1.0")
|
val result = UpdateChecker.checkUpdate()
|
||||||
result.getOrNull()?.let { info ->
|
result.getOrNull()?.let { info ->
|
||||||
if (info.hasUpdate) {
|
if (info.hasUpdate && info.versionCode > AppPreferences.suppressedUpdateVersionCode) {
|
||||||
updateInfoToDisplay = info
|
updateInfoToDisplay = info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val checkingUpdateText = stringResource(id = R.string.home_checking_update)
|
|
||||||
val checkFailedText = stringResource(id = R.string.home_check_update_failed)
|
val checkFailedText = stringResource(id = R.string.home_check_update_failed)
|
||||||
val alreadyLatestText = stringResource(id = R.string.home_already_latest, "v1.1.0")
|
val alreadyLatestText = stringResource(id = R.string.about_latest_version)
|
||||||
|
|
||||||
val performManualCheck: () -> Unit = {
|
val performManualCheck: () -> Unit = {
|
||||||
Toast.makeText(context, checkingUpdateText, Toast.LENGTH_SHORT).show()
|
isCheckingAppUpdate = true
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
val result = UpdateChecker.checkUpdate(currentVersion = "v1.1.0")
|
val result = UpdateChecker.checkUpdate()
|
||||||
|
isCheckingAppUpdate = false
|
||||||
result.onSuccess { info ->
|
result.onSuccess { info ->
|
||||||
if (info.hasUpdate) {
|
if (info.hasUpdate) {
|
||||||
updateInfoToDisplay = info
|
updateInfoToDisplay = info
|
||||||
@@ -123,69 +137,149 @@ fun MainScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Box(modifier = modifier.fillMaxSize()) {
|
if (isAboutViewOpen) {
|
||||||
|
BackHandler {
|
||||||
|
isAboutViewOpen = false
|
||||||
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
|
||||||
topBar = {
|
topBar = {
|
||||||
if (currentTab != NavTab.LOCATION) {
|
TopAppBar(
|
||||||
OpenLocTopBar()
|
navigationIcon = {
|
||||||
}
|
IconButton(onClick = { isAboutViewOpen = false }) {
|
||||||
},
|
Icon(
|
||||||
bottomBar = {
|
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
OpenLocBottomBar(
|
contentDescription = stringResource(R.string.btn_back)
|
||||||
currentTab = currentTab,
|
)
|
||||||
onTabSelected = { currentTab = it }
|
}
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.section_about),
|
||||||
|
style = MaterialTheme.typography.titleLarge,
|
||||||
|
fontWeight = FontWeight.Bold
|
||||||
|
)
|
||||||
|
},
|
||||||
|
colors = TopAppBarDefaults.topAppBarColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surface,
|
||||||
|
titleContentColor = MaterialTheme.colorScheme.onSurface
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
) { innerPadding ->
|
) { innerPadding ->
|
||||||
AnimatedContent(
|
AboutScreen(
|
||||||
targetState = currentTab,
|
onCheckAppUpdate = performManualCheck,
|
||||||
transitionSpec = {
|
isCheckingUpdate = isCheckingAppUpdate,
|
||||||
fadeIn() togetherWith fadeOut()
|
|
||||||
},
|
|
||||||
label = "TabContentAnimation",
|
|
||||||
modifier = Modifier.padding(innerPadding)
|
modifier = Modifier.padding(innerPadding)
|
||||||
) { targetTab ->
|
)
|
||||||
when (targetTab) {
|
}
|
||||||
NavTab.HOME -> HomeScreen(
|
} else {
|
||||||
isModuleActive = isModuleActive,
|
Box(modifier = modifier.fillMaxSize()) {
|
||||||
isServiceEnabled = isServiceEnabled,
|
Scaffold(
|
||||||
onServiceEnabledChange = { enabled ->
|
modifier = Modifier.fillMaxSize(),
|
||||||
AppPreferences.updateServiceEnabled(enabled)
|
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||||
},
|
topBar = {
|
||||||
onOpenBlacklist = { activeAppSelectionMode = AppMockMode.BLACKLIST },
|
if (currentTab != NavTab.LOCATION) {
|
||||||
onOpenWhitelist = { activeAppSelectionMode = AppMockMode.WHITELIST },
|
OpenLocTopBar(
|
||||||
onCheckUpdate = performManualCheck
|
onAboutClick = { isAboutViewOpen = true }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bottomBar = {
|
||||||
|
OpenLocBottomBar(
|
||||||
|
currentTab = currentTab,
|
||||||
|
onTabSelected = { currentTab = it }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) { innerPadding ->
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(bottom = innerPadding.calculateBottomPadding())
|
||||||
|
) {
|
||||||
|
// 1. 地图页面:一旦进入后始终常驻保活,切换 Tab 绝不销毁 MapView,零延迟、不重新加载
|
||||||
|
var hasLoadedLocation by rememberSaveable { mutableStateOf(false) }
|
||||||
|
if (currentTab == NavTab.LOCATION) {
|
||||||
|
hasLoadedLocation = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasLoadedLocation) {
|
||||||
|
LocationScreen(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
isVisible = (currentTab == NavTab.LOCATION)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 首页 (当前 Tab 为 HOME 时展示)
|
||||||
|
AnimatedVisibility(
|
||||||
|
visible = currentTab == NavTab.HOME,
|
||||||
|
enter = fadeIn(),
|
||||||
|
exit = fadeOut(),
|
||||||
|
modifier = Modifier.fillMaxSize()
|
||||||
|
) {
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(top = innerPadding.calculateTopPadding()),
|
||||||
|
color = MaterialTheme.colorScheme.background
|
||||||
|
) {
|
||||||
|
HomeScreen(
|
||||||
|
isModuleActive = isModuleActive,
|
||||||
|
isServiceEnabled = isServiceEnabled,
|
||||||
|
onServiceEnabledChange = { enabled ->
|
||||||
|
AppPreferences.updateServiceEnabled(enabled)
|
||||||
|
},
|
||||||
|
onOpenBlacklist = { activeAppSelectionMode = AppMockMode.BLACKLIST },
|
||||||
|
onOpenWhitelist = { activeAppSelectionMode = AppMockMode.WHITELIST }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 设置页 (当前 Tab 为 SETTINGS 时展示)
|
||||||
|
AnimatedVisibility(
|
||||||
|
visible = currentTab == NavTab.SETTINGS,
|
||||||
|
enter = fadeIn(),
|
||||||
|
exit = fadeOut(),
|
||||||
|
modifier = Modifier.fillMaxSize()
|
||||||
|
) {
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(top = innerPadding.calculateTopPadding()),
|
||||||
|
color = MaterialTheme.colorScheme.background
|
||||||
|
) {
|
||||||
|
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 }
|
||||||
)
|
)
|
||||||
NavTab.LOCATION -> LocationScreen()
|
|
||||||
NavTab.SETTINGS -> SettingsScreen()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 应用选择全屏浮层(黑名单 / 白名单独立管理)
|
// 新版本更新弹窗(全局层级)
|
||||||
AnimatedVisibility(
|
updateInfoToDisplay?.let { info ->
|
||||||
visible = activeAppSelectionMode != null,
|
UpdateDialog(
|
||||||
enter = slideInHorizontally(initialOffsetX = { it }) + fadeIn(),
|
updateInfo = info,
|
||||||
exit = slideOutHorizontally(targetOffsetX = { it }) + fadeOut(),
|
onDismiss = { updateInfoToDisplay = null },
|
||||||
modifier = Modifier.fillMaxSize()
|
onDontShowAgain = { suppressedCode ->
|
||||||
) {
|
AppPreferences.updateSuppressedVersionCode(suppressedCode)
|
||||||
activeAppSelectionMode?.let { mode ->
|
|
||||||
AppSelectionScreen(
|
|
||||||
mode = mode,
|
|
||||||
onNavigateBack = { activeAppSelectionMode = null }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
|
|
||||||
// 新版本更新弹窗
|
|
||||||
updateInfoToDisplay?.let { info ->
|
|
||||||
UpdateDialog(
|
|
||||||
updateInfo = info,
|
|
||||||
onDismiss = { updateInfoToDisplay = null }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
package com.lzxnone.openloc.ui.screens.about
|
||||||
|
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
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.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.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Info
|
||||||
|
import androidx.compose.material.icons.filled.Sync
|
||||||
|
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.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.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.lzxnone.openloc.BuildConfig
|
||||||
|
import com.lzxnone.openloc.R
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun AboutScreen(
|
||||||
|
onCheckAppUpdate: () -> Unit = {},
|
||||||
|
isCheckingUpdate: Boolean = false,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(horizontal = 24.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
Spacer(modifier = Modifier.height(48.dp))
|
||||||
|
|
||||||
|
// 软件图标
|
||||||
|
Image(
|
||||||
|
painter = painterResource(id = R.drawable.app_logo),
|
||||||
|
contentDescription = stringResource(R.string.app_name),
|
||||||
|
modifier = Modifier
|
||||||
|
.size(100.dp)
|
||||||
|
.clip(RoundedCornerShape(22.dp))
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(18.dp))
|
||||||
|
|
||||||
|
// 软件名称
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.app_name),
|
||||||
|
style = MaterialTheme.typography.headlineSmall,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(6.dp))
|
||||||
|
|
||||||
|
// 作者
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.about_author, "lzxnone"),
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(36.dp))
|
||||||
|
|
||||||
|
// 版本与检查更新卡片
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
shape = RoundedCornerShape(16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surface
|
||||||
|
),
|
||||||
|
elevation = CardDefaults.cardElevation(
|
||||||
|
defaultElevation = 1.dp
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.padding(vertical = 4.dp)) {
|
||||||
|
// 版本
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp, vertical = 14.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Info,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(24.dp)
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.about_app_version),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
fontWeight = FontWeight.Medium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "v${BuildConfig.VERSION_NAME}",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalDivider(
|
||||||
|
modifier = Modifier.padding(horizontal = 16.dp),
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||||
|
)
|
||||||
|
|
||||||
|
// 检查更新
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable(enabled = !isCheckingUpdate) {
|
||||||
|
onCheckAppUpdate()
|
||||||
|
}
|
||||||
|
.padding(horizontal = 16.dp, vertical = 14.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Sync,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(24.dp)
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.about_check_updates),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
fontWeight = FontWeight.Medium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
)
|
||||||
|
if (isCheckingUpdate) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.checking_updates),
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -146,15 +146,24 @@ fun AppSelectionScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关联当前名单选中的包名集合
|
// 关联当前名单选中的包名集合(用于实时响应勾选状态与计数展示)
|
||||||
val selectedPackages = if (mode == AppMockMode.BLACKLIST) {
|
val selectedPackages = if (mode == AppMockMode.BLACKLIST) {
|
||||||
AppPreferences.blacklistApps
|
AppPreferences.blacklistApps
|
||||||
} else {
|
} else {
|
||||||
AppPreferences.whitelistApps
|
AppPreferences.whitelistApps
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据搜索词、系统应用开关以及是否已选中进行过滤和排序(已选中的应用排在最上方)
|
// 记录进入页面时的初始选中集合:排序仅基于此快照,选中/取消不立即触发重排,只有用户下一次进入页面时才重新排序
|
||||||
val filteredApps = remember(installedApps, searchQuery, showSystemApps, selectedPackages) {
|
val initialSelectedPackages = remember {
|
||||||
|
if (mode == AppMockMode.BLACKLIST) {
|
||||||
|
AppPreferences.blacklistApps
|
||||||
|
} else {
|
||||||
|
AppPreferences.whitelistApps
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据搜索词、系统应用开关过滤,基于进入页面时的 initialSelectedPackages 稳定排序
|
||||||
|
val filteredApps = remember(installedApps, searchQuery, showSystemApps, initialSelectedPackages) {
|
||||||
installedApps
|
installedApps
|
||||||
.filter { app ->
|
.filter { app ->
|
||||||
(showSystemApps || !app.isSystemApp) &&
|
(showSystemApps || !app.isSystemApp) &&
|
||||||
@@ -163,7 +172,7 @@ fun AppSelectionScreen(
|
|||||||
app.packageName.contains(searchQuery, ignoreCase = true))
|
app.packageName.contains(searchQuery, ignoreCase = true))
|
||||||
}
|
}
|
||||||
.sortedWith(
|
.sortedWith(
|
||||||
compareByDescending<InstalledAppItem> { selectedPackages.contains(it.packageName) }
|
compareByDescending<InstalledAppItem> { initialSelectedPackages.contains(it.packageName) }
|
||||||
.thenBy { it.isSystemApp }
|
.thenBy { it.isSystemApp }
|
||||||
.thenBy { it.appName.lowercase(Locale.ROOT) }
|
.thenBy { it.appName.lowercase(Locale.ROOT) }
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ fun HomeScreen(
|
|||||||
onServiceEnabledChange: (Boolean) -> Unit,
|
onServiceEnabledChange: (Boolean) -> Unit,
|
||||||
onOpenBlacklist: () -> Unit,
|
onOpenBlacklist: () -> Unit,
|
||||||
onOpenWhitelist: () -> Unit,
|
onOpenWhitelist: () -> Unit,
|
||||||
onCheckUpdate: () -> Unit,
|
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
val scrollState = rememberScrollState()
|
val scrollState = rememberScrollState()
|
||||||
@@ -55,15 +54,5 @@ fun HomeScreen(
|
|||||||
onOpenBlacklist = onOpenBlacklist,
|
onOpenBlacklist = onOpenBlacklist,
|
||||||
onOpenWhitelist = onOpenWhitelist
|
onOpenWhitelist = onOpenWhitelist
|
||||||
)
|
)
|
||||||
|
|
||||||
// 4. 版本与更新模块卡片
|
|
||||||
VersionCard(
|
|
||||||
versionName = "v1.1.0",
|
|
||||||
isAutoCheckEnabled = AppPreferences.isAutoCheckUpdateEnabled,
|
|
||||||
onAutoCheckChange = { AppPreferences.updateAutoCheckUpdateEnabled(it) },
|
|
||||||
onCheckUpdate = onCheckUpdate
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,169 +0,0 @@
|
|||||||
package com.lzxnone.openloc.ui.screens.home
|
|
||||||
|
|
||||||
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.HorizontalDivider
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Surface
|
|
||||||
import androidx.compose.material3.Switch
|
|
||||||
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
|
|
||||||
import com.lzxnone.openloc.data.preference.AppPreferences
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主页底部版本模块卡片
|
|
||||||
* 显示应用当前版本(如 v1.0.0)、“检查更新”按钮,以及“启动时自动检查更新”开关
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun VersionCard(
|
|
||||||
versionName: String = stringResource(id = R.string.home_version_name),
|
|
||||||
isAutoCheckEnabled: Boolean = AppPreferences.isAutoCheckUpdateEnabled,
|
|
||||||
onAutoCheckChange: (Boolean) -> Unit = { AppPreferences.updateAutoCheckUpdateEnabled(it) },
|
|
||||||
onCheckUpdate: () -> 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()) {
|
|
||||||
// 上半部分:版本信息与手动检查更新按钮
|
|
||||||
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 = onCheckUpdate,
|
|
||||||
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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HorizontalDivider(
|
|
||||||
modifier = Modifier.padding(horizontal = 20.dp),
|
|
||||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.4f)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 下半部分:自动检查更新选项(默认开启)
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 20.dp, vertical = 14.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
|
||||||
Text(
|
|
||||||
text = stringResource(id = R.string.home_auto_check_update_title),
|
|
||||||
style = MaterialTheme.typography.titleSmall.copy(
|
|
||||||
fontWeight = FontWeight.SemiBold
|
|
||||||
),
|
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(2.dp))
|
|
||||||
Text(
|
|
||||||
text = stringResource(id = R.string.home_auto_check_update_desc),
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
|
||||||
|
|
||||||
Switch(
|
|
||||||
checked = isAutoCheckEnabled,
|
|
||||||
onCheckedChange = onAutoCheckChange
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,6 +11,7 @@ import android.location.LocationManager
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import com.lzxnone.openloc.createLocalizedContext
|
||||||
import com.lzxnone.openloc.core.util.TraceLogger
|
import com.lzxnone.openloc.core.util.TraceLogger
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
@@ -80,8 +81,6 @@ import androidx.compose.material3.ModalBottomSheet
|
|||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.OutlinedTextFieldDefaults
|
import androidx.compose.material3.OutlinedTextFieldDefaults
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Switch
|
|
||||||
import androidx.compose.material3.SwitchDefaults
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
@@ -159,7 +158,8 @@ val AMapVectorTileSource = object : OnlineTileSourceBase(
|
|||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun LocationScreen(
|
fun LocationScreen(
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier,
|
||||||
|
isVisible: Boolean = true
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
@@ -340,20 +340,22 @@ fun LocationScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 核心二元状态机:根据虚拟定位总开关 (isServiceEnabled) 切换定位模式
|
// 核心二元状态机:根据虚拟定位总开关 (isServiceEnabled) 与页面可见性 (isVisible) 切换定位模式
|
||||||
LaunchedEffect(isServiceEnabled) {
|
LaunchedEffect(isServiceEnabled, isVisible) {
|
||||||
val lm = context.getSystemService(Context.LOCATION_SERVICE) as? LocationManager ?: return@LaunchedEffect
|
val lm = context.getSystemService(Context.LOCATION_SERVICE) as? LocationManager ?: return@LaunchedEffect
|
||||||
val hasFine = ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
val hasFine = ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||||
val hasCoarse = ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
val hasCoarse = ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||||
|
|
||||||
if (isServiceEnabled) {
|
if (isServiceEnabled || !isVisible) {
|
||||||
// ================= 【总开关开启】 =================
|
// 当总开关开启或页面处于不可见状态时,彻底注销物理真实定位监听,节省电量与硬件开销
|
||||||
// 1. 立刻彻底注销并移除所有的物理真实定位监听,不再接收任何真机硬件坐标
|
|
||||||
try {
|
try {
|
||||||
lm.removeUpdates(realLocationListener)
|
lm.removeUpdates(realLocationListener)
|
||||||
} catch (_: Throwable) {}
|
} catch (_: Throwable) {}
|
||||||
|
}
|
||||||
|
|
||||||
// 2. 检查是否为首次开启且从未手动选过点:若无历史选点,主动取一次真实定位作为初始点
|
if (isServiceEnabled) {
|
||||||
|
// ================= 【总开关开启】 =================
|
||||||
|
// 检查是否为首次开启且从未手动选过点:若无历史选点,主动取一次真实定位作为初始点
|
||||||
if (!AppPreferences.hasUserSetLocation && (hasFine || hasCoarse)) {
|
if (!AppPreferences.hasUserSetLocation && (hasFine || hasCoarse)) {
|
||||||
fetchRealLocationOnce(lm) { realWgsLat, realWgsLng ->
|
fetchRealLocationOnce(lm) { realWgsLat, realWgsLng ->
|
||||||
val gcj = CoordinateConverter.wgs84ToGcj02(realWgsLat, realWgsLng)
|
val gcj = CoordinateConverter.wgs84ToGcj02(realWgsLat, realWgsLng)
|
||||||
@@ -379,11 +381,11 @@ fun LocationScreen(
|
|||||||
String.format(Locale.getDefault(), "%.5f, %.5f", AppPreferences.mockLatitude, AppPreferences.mockLongitude)
|
String.format(Locale.getDefault(), "%.5f, %.5f", AppPreferences.mockLatitude, AppPreferences.mockLongitude)
|
||||||
}
|
}
|
||||||
currentMarker?.title = locationName
|
currentMarker?.title = locationName
|
||||||
mapViewRef?.controller?.animateTo(p)
|
mapViewRef?.controller?.setCenter(p)
|
||||||
mapViewRef?.invalidate()
|
mapViewRef?.invalidate()
|
||||||
}
|
}
|
||||||
} else {
|
} else if (isVisible) {
|
||||||
// ================= 【总开关关闭】 =================
|
// ================= 【总开关关闭 & 页面可见】 =================
|
||||||
// 1. 关闭的一瞬间,立马主动获取一次真机真实坐标,拉回当前设备物理原位
|
// 1. 关闭的一瞬间,立马主动获取一次真机真实坐标,拉回当前设备物理原位
|
||||||
if (hasFine || hasCoarse) {
|
if (hasFine || hasCoarse) {
|
||||||
fetchRealLocationOnce(lm) { realWgsLat, realWgsLng ->
|
fetchRealLocationOnce(lm) { realWgsLat, realWgsLng ->
|
||||||
@@ -391,7 +393,7 @@ fun LocationScreen(
|
|||||||
val p = GeoPoint(gcj[0], gcj[1])
|
val p = GeoPoint(gcj[0], gcj[1])
|
||||||
currentGeoPoint = p
|
currentGeoPoint = p
|
||||||
currentMarker?.position = p
|
currentMarker?.position = p
|
||||||
mapViewRef?.controller?.animateTo(p)
|
mapViewRef?.controller?.setCenter(p)
|
||||||
mapViewRef?.invalidate()
|
mapViewRef?.invalidate()
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
val resolved = LocationResolver.resolveLocationName(context, realWgsLat, realWgsLng)
|
val resolved = LocationResolver.resolveLocationName(context, realWgsLat, realWgsLng)
|
||||||
@@ -500,7 +502,7 @@ fun LocationScreen(
|
|||||||
|
|
||||||
currentGeoPoint = mapPoint
|
currentGeoPoint = mapPoint
|
||||||
currentMarker?.position = mapPoint
|
currentMarker?.position = mapPoint
|
||||||
mapViewRef?.controller?.animateTo(mapPoint)
|
mapViewRef?.controller?.setCenter(mapPoint)
|
||||||
mapViewRef?.invalidate()
|
mapViewRef?.invalidate()
|
||||||
|
|
||||||
locationName = result.name
|
locationName = result.name
|
||||||
@@ -576,9 +578,10 @@ fun LocationScreen(
|
|||||||
val tapOverlay = MapEventsOverlay(object : MapEventsReceiver {
|
val tapOverlay = MapEventsOverlay(object : MapEventsReceiver {
|
||||||
override fun singleTapConfirmedHelper(p: GeoPoint): Boolean {
|
override fun singleTapConfirmedHelper(p: GeoPoint): Boolean {
|
||||||
if (!AppPreferences.isServiceEnabled) {
|
if (!AppPreferences.isServiceEnabled) {
|
||||||
|
val localizedContext = createLocalizedContext(context, AppPreferences.appLanguage)
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
context,
|
localizedContext,
|
||||||
context.getString(R.string.location_mock_disabled_prompt),
|
localizedContext.getString(R.string.location_mock_disabled_prompt),
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
return true
|
return true
|
||||||
@@ -602,12 +605,24 @@ fun LocationScreen(
|
|||||||
},
|
},
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
update = { mapView ->
|
update = { mapView ->
|
||||||
currentMarker?.position = currentGeoPoint
|
if (isVisible) {
|
||||||
mapView.invalidate()
|
if (mapView.visibility != android.view.View.VISIBLE) {
|
||||||
|
mapView.visibility = android.view.View.VISIBLE
|
||||||
|
mapView.onResume()
|
||||||
|
}
|
||||||
|
currentMarker?.position = currentGeoPoint
|
||||||
|
mapView.invalidate()
|
||||||
|
} else {
|
||||||
|
if (mapView.visibility != android.view.View.GONE) {
|
||||||
|
mapView.onPause()
|
||||||
|
mapView.visibility = android.view.View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// ------------------ 2. 顶部未激活时的浮动搜索胶囊 ------------------
|
if (isVisible) {
|
||||||
|
// ------------------ 2. 顶部未激活时的浮动搜索胶囊 ------------------
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@@ -1289,7 +1304,7 @@ fun LocationScreen(
|
|||||||
pointOnMap = targetPoint,
|
pointOnMap = targetPoint,
|
||||||
isUserManual = true,
|
isUserManual = true,
|
||||||
centerMap = true,
|
centerMap = true,
|
||||||
animate = true
|
animate = false
|
||||||
)
|
)
|
||||||
locationName = favorite.name
|
locationName = favorite.name
|
||||||
showFavoritesScreen = false
|
showFavoritesScreen = false
|
||||||
@@ -1561,6 +1576,7 @@ fun LocationScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
package com.lzxnone.openloc.ui.screens.settings
|
package com.lzxnone.openloc.ui.screens.settings
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
@@ -33,6 +38,7 @@ import androidx.compose.material.icons.filled.DarkMode
|
|||||||
import androidx.compose.material.icons.filled.DeveloperMode
|
import androidx.compose.material.icons.filled.DeveloperMode
|
||||||
import androidx.compose.material.icons.filled.Explore
|
import androidx.compose.material.icons.filled.Explore
|
||||||
import androidx.compose.material.icons.filled.Key
|
import androidx.compose.material.icons.filled.Key
|
||||||
|
import androidx.compose.material.icons.filled.Notifications
|
||||||
import androidx.compose.material.icons.filled.SatelliteAlt
|
import androidx.compose.material.icons.filled.SatelliteAlt
|
||||||
import androidx.compose.material.icons.filled.Security
|
import androidx.compose.material.icons.filled.Security
|
||||||
import androidx.compose.material.icons.filled.Translate
|
import androidx.compose.material.icons.filled.Translate
|
||||||
@@ -81,7 +87,9 @@ import kotlinx.coroutines.launch
|
|||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.material.icons.filled.KeyOff
|
import androidx.compose.material.icons.filled.KeyOff
|
||||||
import androidx.compose.material.icons.filled.Public
|
import androidx.compose.material.icons.filled.Public
|
||||||
|
import androidx.compose.material.icons.filled.Speed
|
||||||
import androidx.compose.material3.FilledTonalButton
|
import androidx.compose.material3.FilledTonalButton
|
||||||
|
import androidx.compose.material3.Slider
|
||||||
import com.lzxnone.openloc.core.util.LocationResolver
|
import com.lzxnone.openloc.core.util.LocationResolver
|
||||||
import com.lzxnone.openloc.data.preference.SearchProvider
|
import com.lzxnone.openloc.data.preference.SearchProvider
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -94,6 +102,11 @@ fun SettingsScreen(
|
|||||||
val scrollState = rememberScrollState()
|
val scrollState = rememberScrollState()
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val notificationPermissionLauncher = rememberLauncherForActivityResult(
|
||||||
|
contract = ActivityResultContracts.RequestPermission()
|
||||||
|
) { granted ->
|
||||||
|
AppPreferences.updateNotificationEnabled(granted)
|
||||||
|
}
|
||||||
|
|
||||||
// 控制各个面板显示状态
|
// 控制各个面板显示状态
|
||||||
var showLanguageSheet by remember { mutableStateOf(false) }
|
var showLanguageSheet by remember { mutableStateOf(false) }
|
||||||
@@ -298,6 +311,150 @@ fun SettingsScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------ 2.5 增强设置板块 ------------------
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.settings_category_enhanced),
|
||||||
|
style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold),
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(start = 4.dp, top = 8.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
shape = RoundedCornerShape(16.dp),
|
||||||
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||||
|
elevation = CardDefaults.cardElevation(defaultElevation = 1.dp)
|
||||||
|
) {
|
||||||
|
SettingSwitchItem(
|
||||||
|
title = stringResource(id = R.string.settings_sensor_simulation_title),
|
||||||
|
icon = Icons.Filled.Vibration,
|
||||||
|
checked = AppPreferences.isSensorSimulationEnabled,
|
||||||
|
onCheckedChange = { AppPreferences.updateSensorSimulationEnabled(it) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------ 2.6 跑步设置板块 ------------------
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.settings_category_running),
|
||||||
|
style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold),
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(start = 4.dp, top = 8.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
val runningEnabled = AppPreferences.isRunningModeEnabled
|
||||||
|
val currentSpeed = AppPreferences.runningSpeedMps
|
||||||
|
val paceTotalSec = (1000.0 / currentSpeed.coerceAtLeast(0.5f)).toInt()
|
||||||
|
val paceMin = paceTotalSec / 60
|
||||||
|
val paceSec = paceTotalSec % 60
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
shape = RoundedCornerShape(16.dp),
|
||||||
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||||
|
elevation = CardDefaults.cardElevation(defaultElevation = 1.dp)
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
SettingSwitchItem(
|
||||||
|
title = stringResource(id = R.string.settings_running_mode_title),
|
||||||
|
icon = Icons.Filled.Explore,
|
||||||
|
checked = runningEnabled,
|
||||||
|
onCheckedChange = { AppPreferences.updateRunningModeEnabled(it) }
|
||||||
|
)
|
||||||
|
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.4f),
|
||||||
|
modifier = Modifier.padding(horizontal = 16.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp, vertical = 14.dp)
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
|
) {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(36.dp)
|
||||||
|
.clip(CircleShape)
|
||||||
|
.background(
|
||||||
|
if (runningEnabled) MaterialTheme.colorScheme.primary.copy(alpha = 0.12f)
|
||||||
|
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.06f)
|
||||||
|
),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Filled.Speed,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = if (runningEnabled) MaterialTheme.colorScheme.primary
|
||||||
|
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f),
|
||||||
|
modifier = Modifier.size(20.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.width(14.dp))
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.settings_running_speed_title),
|
||||||
|
style = MaterialTheme.typography.bodyLarge.copy(fontWeight = FontWeight.Medium),
|
||||||
|
color = if (runningEnabled) MaterialTheme.colorScheme.onSurface
|
||||||
|
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = stringResource(
|
||||||
|
id = R.string.settings_running_speed_format,
|
||||||
|
currentSpeed,
|
||||||
|
paceMin,
|
||||||
|
paceSec
|
||||||
|
),
|
||||||
|
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
||||||
|
color = if (runningEnabled) MaterialTheme.colorScheme.primary
|
||||||
|
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(6.dp))
|
||||||
|
|
||||||
|
Slider(
|
||||||
|
value = currentSpeed,
|
||||||
|
onValueChange = { AppPreferences.updateRunningSpeed(it) },
|
||||||
|
valueRange = 1.0f..8.0f,
|
||||||
|
steps = 13,
|
||||||
|
enabled = runningEnabled,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------ 2.6 通知设置板块 ------------------
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.settings_category_notification),
|
||||||
|
style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold),
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(start = 4.dp, top = 4.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
shape = RoundedCornerShape(16.dp),
|
||||||
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||||
|
elevation = CardDefaults.cardElevation(defaultElevation = 1.dp)
|
||||||
|
) {
|
||||||
|
SettingSwitchItem(
|
||||||
|
title = stringResource(id = R.string.settings_notification_enabled_title),
|
||||||
|
icon = Icons.Default.Notifications,
|
||||||
|
checked = AppPreferences.isNotificationEnabled,
|
||||||
|
onCheckedChange = { enabled ->
|
||||||
|
AppPreferences.updateNotificationEnabled(enabled)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------ 3. 地图与搜索服务板块 ------------------
|
// ------------------ 3. 地图与搜索服务板块 ------------------
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(id = R.string.settings_category_map_service),
|
text = stringResource(id = R.string.settings_category_map_service),
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 9.6 KiB |
@@ -0,0 +1,224 @@
|
|||||||
|
<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_mock_disabled_prompt">Virtual location is not enabled, please enable it first</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">Module Package Stealth</string>
|
||||||
|
<string name="settings_anti_stealth_desc">Hide OpenLoc package from target apps to prevent package scanning detection</string>
|
||||||
|
<string name="settings_anti_dev_title">Mock Flag Sanitization</string>
|
||||||
|
<string name="settings_anti_dev_desc">Sanitize isMock and mIsFromMockProvider flags in Location objects</string>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Version & Updates -->
|
||||||
|
<string name="home_version_card_title">Current Version</string>
|
||||||
|
<string name="home_version_name">v1.2.2</string>
|
||||||
|
<string name="home_check_updates_btn">Check for Updates</string>
|
||||||
|
<string name="home_auto_check_update_title">Auto Check on Launch</string>
|
||||||
|
<string name="home_auto_check_update_desc">Automatically check for new releases when opening the app</string>
|
||||||
|
<string name="home_checking_update">Checking for updates…</string>
|
||||||
|
<string name="home_update_available_title">New Version Available: %1$s</string>
|
||||||
|
<string name="home_update_dialog_msg">A new version of OpenLoc has been released.</string>
|
||||||
|
<string name="home_update_btn_go">Go to Update</string>
|
||||||
|
<string name="home_update_btn_later">Later</string>
|
||||||
|
<string name="home_check_update_failed">Failed to check for updates, please check network</string>
|
||||||
|
<string name="home_already_latest">Already the latest version (%1$s)</string>
|
||||||
|
|
||||||
|
<!-- About & Updates -->
|
||||||
|
<string name="section_about">About</string>
|
||||||
|
<string name="btn_back">Back</string>
|
||||||
|
<string name="about_author">Author: %1$s</string>
|
||||||
|
<string name="about_app_version">Version</string>
|
||||||
|
<string name="about_check_updates">Check for Updates</string>
|
||||||
|
<string name="about_latest_version">Already up to date</string>
|
||||||
|
<string name="checking_updates">Checking for updates…</string>
|
||||||
|
<string name="update_dialog_title_format">New Version %1$s</string>
|
||||||
|
<string name="btn_dont_show_again">Don\'t show again</string>
|
||||||
|
<string name="btn_download_update">Download Update</string>
|
||||||
|
|
||||||
|
<!-- Enhanced Settings -->
|
||||||
|
<string name="settings_category_enhanced">Enhanced Settings</string>
|
||||||
|
<string name="settings_sensor_simulation_title">Motion & Attitude Sensor Simulation</string>
|
||||||
|
<string name="settings_sensor_simulation_desc">Simulate handheld micro-tremors, gait, and step cadence to avoid static lock or anti-cheat checks</string>
|
||||||
|
|
||||||
|
<!-- Running Settings -->
|
||||||
|
<string name="settings_category_running">Running Settings</string>
|
||||||
|
<string name="settings_running_mode_title">Running Mode</string>
|
||||||
|
<string name="settings_running_mode_desc">Move smoothly at running speed for nearby points; jump instantly when off</string>
|
||||||
|
<string name="settings_running_speed_title">Running Speed</string>
|
||||||
|
<string name="settings_running_speed_format">%1$.1f m/s (%2$d\'%3$02d\"/km)</string>
|
||||||
|
<string name="service_keepalive_channel_name">Location Keep-Alive Service</string>
|
||||||
|
<string name="service_keepalive_title">OpenLoc Location Service Running</string>
|
||||||
|
<string name="service_keepalive_desc">Keeping 1Hz location & sensor simulation active in background</string>
|
||||||
|
|
||||||
|
<!-- Notification Settings -->
|
||||||
|
<string name="settings_category_notification">Notification Settings</string>
|
||||||
|
<string name="settings_notification_enabled_title">Status Bar Notification</string>
|
||||||
|
<string name="settings_notification_enabled_desc">Show app icon, mock location, and motion parameters in a persistent notification while mock location is active</string>
|
||||||
|
<string name="notification_title_format">OpenLoc · %1$s</string>
|
||||||
|
<string name="notification_mode_running">Running Mode</string>
|
||||||
|
<string name="notification_mode_static">Static Mock</string>
|
||||||
|
<string name="notification_location_unnamed">Custom Point</string>
|
||||||
|
<string name="notification_coord_line">Lat: %1$.5f Lng: %2$.5f</string>
|
||||||
|
<string name="notification_speed_bearing_line">Speed: %1$.2f m/s Bearing: %2$.0f°</string>
|
||||||
|
<string name="notification_accel_line">X Accel: %1$.2f Y Accel: %2$.2f Z Accel: %3$.2f</string>
|
||||||
|
</resources>
|
||||||
@@ -171,17 +171,56 @@
|
|||||||
|
|
||||||
<!-- 版本与更新 -->
|
<!-- 版本与更新 -->
|
||||||
<string name="home_version_card_title">当前版本</string>
|
<string name="home_version_card_title">当前版本</string>
|
||||||
<string name="home_version_name">v1.1.0</string>
|
<string name="home_version_name">v1.2.2</string>
|
||||||
<string name="home_check_updates_btn">检查更新</string>
|
<string name="home_check_updates_btn">检查更新</string>
|
||||||
<string name="home_auto_check_update_title">启动时自动检查更新</string>
|
<string name="home_auto_check_update_title">启动时自动检查更新</string>
|
||||||
<string name="home_auto_check_update_desc">每次进入软件自动联网检测 GitHub 最新版本</string>
|
<string name="home_auto_check_update_desc">每次进入软件自动联网检测最新版本</string>
|
||||||
<string name="home_checking_update">正在检查更新…</string>
|
<string name="home_checking_update">正在检查更新…</string>
|
||||||
<string name="home_update_available_title">发现新版本: %1$s</string>
|
<string name="home_update_available_title">发现新版本: %1$s</string>
|
||||||
<string name="home_update_dialog_msg">OpenLoc 已在 GitHub 发布最新版本,欢迎前往下载更新。</string>
|
<string name="home_update_dialog_msg">OpenLoc 已发布最新版本,欢迎前往下载更新。</string>
|
||||||
<string name="home_update_btn_go">前往更新</string>
|
<string name="home_update_btn_go">前往更新</string>
|
||||||
<string name="home_update_btn_later">稍后</string>
|
<string name="home_update_btn_later">稍后</string>
|
||||||
<string name="home_check_update_failed">检查更新失败,请检查网络</string>
|
<string name="home_check_update_failed">检查更新失败,请检查网络</string>
|
||||||
<string name="home_already_latest">当前已是最新版本 (%1$s)</string>
|
<string name="home_already_latest">当前已是最新版本 (%1$s)</string>
|
||||||
|
|
||||||
|
<!-- 关于与更新 -->
|
||||||
|
<string name="section_about">关于</string>
|
||||||
|
<string name="btn_back">返回</string>
|
||||||
|
<string name="about_author">作者:%1$s</string>
|
||||||
|
<string name="about_app_version">版本</string>
|
||||||
|
<string name="about_check_updates">检查更新</string>
|
||||||
|
<string name="about_latest_version">当前已是最新版本</string>
|
||||||
|
<string name="checking_updates">正在检查更新…</string>
|
||||||
|
<string name="update_dialog_title_format">新版本 %1$s</string>
|
||||||
|
<string name="btn_dont_show_again">不再显示</string>
|
||||||
|
<string name="btn_download_update">下载更新</string>
|
||||||
|
|
||||||
|
<!-- 增强设置 -->
|
||||||
|
<string name="settings_category_enhanced">增强设置</string>
|
||||||
|
<string name="settings_sensor_simulation_title">运动与姿态传感器拟真</string>
|
||||||
|
<string name="settings_sensor_simulation_desc">模拟手持微颤、步态波形与计步增量,防止静止锁死与运动风控检测</string>
|
||||||
|
|
||||||
|
<!-- 跑步设置 -->
|
||||||
|
<string name="settings_category_running">跑步设置</string>
|
||||||
|
<string name="settings_running_mode_title">开启跑步模式</string>
|
||||||
|
<string name="settings_running_mode_desc">开启后近距离切点按配速慢慢移动,关闭时瞬间移动</string>
|
||||||
|
<string name="settings_running_speed_title">跑步速度</string>
|
||||||
|
<string name="settings_running_speed_format">%1$.1f m/s(%2$d\'%3$02d\"/km)</string>
|
||||||
|
<string name="service_keepalive_channel_name">定位后台常驻服务</string>
|
||||||
|
<string name="service_keepalive_title">OpenLoc 定位服务运行中</string>
|
||||||
|
<string name="service_keepalive_desc">正在后台保持 1Hz 连续定位与传感器拟真推送</string>
|
||||||
|
|
||||||
|
<!-- 通知设置 -->
|
||||||
|
<string name="settings_category_notification">通知设置</string>
|
||||||
|
<string name="settings_notification_enabled_title">状态栏常驻通知</string>
|
||||||
|
<string name="settings_notification_enabled_desc">开启后,虚拟定位运行时将在任务栏常驻显示软件图标、名称、当前位置及运动参数</string>
|
||||||
|
<string name="notification_title_format">OpenLoc · %1$s</string>
|
||||||
|
<string name="notification_mode_running">跑步模式</string>
|
||||||
|
<string name="notification_mode_static">定点模拟</string>
|
||||||
|
<string name="notification_location_unnamed">自定义坐标</string>
|
||||||
|
<string name="notification_coord_line">纬度: %1$.5f 经度: %2$.5f</string>
|
||||||
|
<string name="notification_speed_bearing_line">速度: %1$.2f m/s 航向: %2$.0f°</string>
|
||||||
|
<string name="notification_accel_line">X加速度: %1$.2f Y加速度: %2$.2f Z加速度: %3$.2f</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
|
||||||
@@ -171,17 +171,56 @@
|
|||||||
|
|
||||||
<!-- 版本与更新 -->
|
<!-- 版本与更新 -->
|
||||||
<string name="home_version_card_title">当前版本</string>
|
<string name="home_version_card_title">当前版本</string>
|
||||||
<string name="home_version_name">v1.1.0</string>
|
<string name="home_version_name">v1.2.2</string>
|
||||||
<string name="home_check_updates_btn">检查更新</string>
|
<string name="home_check_updates_btn">检查更新</string>
|
||||||
<string name="home_auto_check_update_title">启动时自动检查更新</string>
|
<string name="home_auto_check_update_title">启动时自动检查更新</string>
|
||||||
<string name="home_auto_check_update_desc">每次进入软件自动联网检测 GitHub 最新版本</string>
|
<string name="home_auto_check_update_desc">每次进入软件自动联网检测最新版本</string>
|
||||||
<string name="home_checking_update">正在检查更新…</string>
|
<string name="home_checking_update">正在检查更新…</string>
|
||||||
<string name="home_update_available_title">发现新版本: %1$s</string>
|
<string name="home_update_available_title">发现新版本: %1$s</string>
|
||||||
<string name="home_update_dialog_msg">OpenLoc 已在 GitHub 发布最新版本,欢迎前往下载更新。</string>
|
<string name="home_update_dialog_msg">OpenLoc 已发布最新版本,欢迎前往下载更新。</string>
|
||||||
<string name="home_update_btn_go">前往更新</string>
|
<string name="home_update_btn_go">前往更新</string>
|
||||||
<string name="home_update_btn_later">稍后</string>
|
<string name="home_update_btn_later">稍后</string>
|
||||||
<string name="home_check_update_failed">检查更新失败,请检查网络</string>
|
<string name="home_check_update_failed">检查更新失败,请检查网络</string>
|
||||||
<string name="home_already_latest">当前已是最新版本 (%1$s)</string>
|
<string name="home_already_latest">当前已是最新版本 (%1$s)</string>
|
||||||
|
|
||||||
|
<!-- 关于与更新 -->
|
||||||
|
<string name="section_about">关于</string>
|
||||||
|
<string name="btn_back">返回</string>
|
||||||
|
<string name="about_author">作者:%1$s</string>
|
||||||
|
<string name="about_app_version">版本</string>
|
||||||
|
<string name="about_check_updates">检查更新</string>
|
||||||
|
<string name="about_latest_version">当前已是最新版本</string>
|
||||||
|
<string name="checking_updates">正在检查更新…</string>
|
||||||
|
<string name="update_dialog_title_format">新版本 %1$s</string>
|
||||||
|
<string name="btn_dont_show_again">不再显示</string>
|
||||||
|
<string name="btn_download_update">下载更新</string>
|
||||||
|
|
||||||
|
<!-- 增强设置 -->
|
||||||
|
<string name="settings_category_enhanced">增强设置</string>
|
||||||
|
<string name="settings_sensor_simulation_title">运动与姿态传感器拟真</string>
|
||||||
|
<string name="settings_sensor_simulation_desc">模拟手持微颤、步态波形与计步增量,防止静止锁死与运动风控检测</string>
|
||||||
|
|
||||||
|
<!-- 跑步设置 -->
|
||||||
|
<string name="settings_category_running">跑步设置</string>
|
||||||
|
<string name="settings_running_mode_title">开启跑步模式</string>
|
||||||
|
<string name="settings_running_mode_desc">开启后近距离切点按配速慢慢移动,关闭时瞬间移动</string>
|
||||||
|
<string name="settings_running_speed_title">跑步速度</string>
|
||||||
|
<string name="settings_running_speed_format">%1$.1f m/s(%2$d\'%3$02d\"/km)</string>
|
||||||
|
<string name="service_keepalive_channel_name">定位后台常驻服务</string>
|
||||||
|
<string name="service_keepalive_title">OpenLoc 定位服务运行中</string>
|
||||||
|
<string name="service_keepalive_desc">正在后台保持 1Hz 连续定位与传感器拟真推送</string>
|
||||||
|
|
||||||
|
<!-- 通知设置 -->
|
||||||
|
<string name="settings_category_notification">通知设置</string>
|
||||||
|
<string name="settings_notification_enabled_title">状态栏常驻通知</string>
|
||||||
|
<string name="settings_notification_enabled_desc">开启后,虚拟定位运行时将在任务栏常驻显示软件图标、名称、当前位置及运动参数</string>
|
||||||
|
<string name="notification_title_format">OpenLoc · %1$s</string>
|
||||||
|
<string name="notification_mode_running">跑步模式</string>
|
||||||
|
<string name="notification_mode_static">定点模拟</string>
|
||||||
|
<string name="notification_location_unnamed">自定义坐标</string>
|
||||||
|
<string name="notification_coord_line">纬度: %1$.5f 经度: %2$.5f</string>
|
||||||
|
<string name="notification_speed_bearing_line">速度: %1$.2f m/s 航向: %2$.0f°</string>
|
||||||
|
<string name="notification_accel_line">X加速度: %1$.2f Y加速度: %2$.2f Z加速度: %3$.2f</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
|
||||||
@@ -171,15 +171,54 @@
|
|||||||
|
|
||||||
<!-- Version & Updates -->
|
<!-- Version & Updates -->
|
||||||
<string name="home_version_card_title">Current Version</string>
|
<string name="home_version_card_title">Current Version</string>
|
||||||
<string name="home_version_name">v1.1.0</string>
|
<string name="home_version_name">v1.2.2</string>
|
||||||
<string name="home_check_updates_btn">Check for Updates</string>
|
<string name="home_check_updates_btn">Check for Updates</string>
|
||||||
<string name="home_auto_check_update_title">Auto Check on Launch</string>
|
<string name="home_auto_check_update_title">Auto Check on Launch</string>
|
||||||
<string name="home_auto_check_update_desc">Automatically check for new releases when opening the app</string>
|
<string name="home_auto_check_update_desc">Automatically check for new releases when opening the app</string>
|
||||||
<string name="home_checking_update">Checking for updates…</string>
|
<string name="home_checking_update">Checking for updates…</string>
|
||||||
<string name="home_update_available_title">New Version Available: %1$s</string>
|
<string name="home_update_available_title">New Version Available: %1$s</string>
|
||||||
<string name="home_update_dialog_msg">A new version of OpenLoc has been released on GitHub.</string>
|
<string name="home_update_dialog_msg">A new version of OpenLoc has been released.</string>
|
||||||
<string name="home_update_btn_go">Go to Update</string>
|
<string name="home_update_btn_go">Go to Update</string>
|
||||||
<string name="home_update_btn_later">Later</string>
|
<string name="home_update_btn_later">Later</string>
|
||||||
<string name="home_check_update_failed">Failed to check for updates, please check network</string>
|
<string name="home_check_update_failed">Failed to check for updates, please check network</string>
|
||||||
<string name="home_already_latest">Already the latest version (%1$s)</string>
|
<string name="home_already_latest">Already the latest version (%1$s)</string>
|
||||||
|
|
||||||
|
<!-- About & Updates -->
|
||||||
|
<string name="section_about">About</string>
|
||||||
|
<string name="btn_back">Back</string>
|
||||||
|
<string name="about_author">Author: %1$s</string>
|
||||||
|
<string name="about_app_version">Version</string>
|
||||||
|
<string name="about_check_updates">Check for Updates</string>
|
||||||
|
<string name="about_latest_version">Already up to date</string>
|
||||||
|
<string name="checking_updates">Checking for updates…</string>
|
||||||
|
<string name="update_dialog_title_format">New Version %1$s</string>
|
||||||
|
<string name="btn_dont_show_again">Don\'t show again</string>
|
||||||
|
<string name="btn_download_update">Download Update</string>
|
||||||
|
|
||||||
|
<!-- Enhanced Settings -->
|
||||||
|
<string name="settings_category_enhanced">Enhanced Settings</string>
|
||||||
|
<string name="settings_sensor_simulation_title">Motion & Attitude Sensor Simulation</string>
|
||||||
|
<string name="settings_sensor_simulation_desc">Simulate handheld micro-tremors, gait, and step cadence to avoid static lock or anti-cheat checks</string>
|
||||||
|
|
||||||
|
<!-- Running Settings -->
|
||||||
|
<string name="settings_category_running">Running Settings</string>
|
||||||
|
<string name="settings_running_mode_title">Running Mode</string>
|
||||||
|
<string name="settings_running_mode_desc">Move smoothly at running speed for nearby points; jump instantly when off</string>
|
||||||
|
<string name="settings_running_speed_title">Running Speed</string>
|
||||||
|
<string name="settings_running_speed_format">%1$.1f m/s (%2$d\'%3$02d\"/km)</string>
|
||||||
|
<string name="service_keepalive_channel_name">Location Keep-Alive Service</string>
|
||||||
|
<string name="service_keepalive_title">OpenLoc Location Service Running</string>
|
||||||
|
<string name="service_keepalive_desc">Keeping 1Hz location & sensor simulation active in background</string>
|
||||||
|
|
||||||
|
<!-- Notification Settings -->
|
||||||
|
<string name="settings_category_notification">Notification Settings</string>
|
||||||
|
<string name="settings_notification_enabled_title">Status Bar Notification</string>
|
||||||
|
<string name="settings_notification_enabled_desc">Show app icon, mock location, and motion parameters in a persistent notification while mock location is active</string>
|
||||||
|
<string name="notification_title_format">OpenLoc · %1$s</string>
|
||||||
|
<string name="notification_mode_running">Running Mode</string>
|
||||||
|
<string name="notification_mode_static">Static Mock</string>
|
||||||
|
<string name="notification_location_unnamed">Custom Point</string>
|
||||||
|
<string name="notification_coord_line">Lat: %1$.5f Lng: %2$.5f</string>
|
||||||
|
<string name="notification_speed_bearing_line">Speed: %1$.2f m/s Bearing: %2$.0f°</string>
|
||||||
|
<string name="notification_accel_line">X Accel: %1$.2f Y Accel: %2$.2f Z Accel: %3$.2f</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.lzxnone.openloc
|
package com.lzxnone.openloc
|
||||||
|
|
||||||
|
import android.hardware.Sensor
|
||||||
import com.lzxnone.openloc.hook.interceptor.AntiDetectionHook
|
import com.lzxnone.openloc.hook.interceptor.AntiDetectionHook
|
||||||
|
import com.lzxnone.openloc.hook.interceptor.SensorHook
|
||||||
import com.lzxnone.openloc.hook.model.MockConfig
|
import com.lzxnone.openloc.hook.model.MockConfig
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertFalse
|
import org.junit.Assert.assertFalse
|
||||||
@@ -62,4 +64,41 @@ class HookSafetyTest {
|
|||||||
assertFalse("hookStackTrace must be completely removed", methodNames.contains("hookStackTrace"))
|
assertFalse("hookStackTrace must be completely removed", methodNames.contains("hookStackTrace"))
|
||||||
assertFalse("hookSettingsCamouflage must be completely removed", methodNames.contains("hookSettingsCamouflage"))
|
assertFalse("hookSettingsCamouflage must be completely removed", methodNames.contains("hookSettingsCamouflage"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testHardwareAndSystemProvidersAreExemptFromMock() {
|
||||||
|
val config = MockConfig(
|
||||||
|
isEnabled = true,
|
||||||
|
mode = "GLOBAL"
|
||||||
|
)
|
||||||
|
assertFalse(config.shouldMock("com.lzxnone.openloc"))
|
||||||
|
assertFalse(config.shouldMock("android"))
|
||||||
|
assertFalse(config.shouldMock("com.android.server.location"))
|
||||||
|
assertFalse(config.shouldMock("com.android.server.location.gnss.hal.Gpo4Client"))
|
||||||
|
assertFalse(config.shouldMock("com.qualcomm.location"))
|
||||||
|
assertFalse(config.shouldMock("com.qti.location"))
|
||||||
|
assertFalse(config.shouldMock("com.xiaomi.metoknlp"))
|
||||||
|
assertFalse(config.shouldMock("com.xiaomi.location.fused"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSensorHookStepFrequencyAndSimulation() {
|
||||||
|
assertEquals(0f, SensorHook.computeStepFrequency(0f, 1.0), 0.001f)
|
||||||
|
val walkFreq = SensorHook.computeStepFrequency(1.4f, 1.0)
|
||||||
|
val runFreq = SensorHook.computeStepFrequency(3.5f, 1.0)
|
||||||
|
assertTrue("Walk frequency should be realistic (1.3~2.0 Hz)", walkFreq in 1.3f..2.0f)
|
||||||
|
assertTrue("Run frequency should exceed walk frequency", runFreq > walkFreq)
|
||||||
|
|
||||||
|
// Stationary micro-tremor should perturb flat zero gyroscope values
|
||||||
|
val gyro = floatArrayOf(0f, 0f, 0f)
|
||||||
|
SensorHook.applySensorSimulation(Sensor.TYPE_GYROSCOPE, gyro, 0f, 1_000_000_000L)
|
||||||
|
assertTrue("Stationary gyroscope should have non-zero micro-tremor", gyro.any { it != 0f })
|
||||||
|
|
||||||
|
// Step counter must remain monotonic when running
|
||||||
|
val step1 = floatArrayOf(100f)
|
||||||
|
SensorHook.applySensorSimulation(Sensor.TYPE_STEP_COUNTER, step1, 3.0f, 2_000_000_000L)
|
||||||
|
val step2 = floatArrayOf(100f)
|
||||||
|
SensorHook.applySensorSimulation(Sensor.TYPE_STEP_COUNTER, step2, 3.0f, 3_000_000_000L)
|
||||||
|
assertTrue("Step counter must increase monotonically while moving", step2[0] > step1[0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user