Skip to content

Commit 9ad72cb

Browse files
committed
- Add random position on select location
1 parent 58c9c31 commit 9ad72cb

7 files changed

Lines changed: 51 additions & 6 deletions

File tree

app/src/main/java/com/android1500/gpssetter/SettingsActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import androidx.appcompat.app.AppCompatActivity
55
import androidx.core.view.WindowCompat
66
import androidx.datastore.core.DataStore
77
import androidx.preference.CheckBoxPreference
8+
import androidx.preference.EditTextPreference
89
import androidx.preference.PreferenceDataStore
910
import androidx.preference.PreferenceFragmentCompat
11+
import androidx.preference.SwitchPreference
1012
import com.android1500.gpssetter.databinding.SettingsActivityBinding
1113
import com.android1500.gpssetter.repository.SettingsRepository
1214
import kotlinx.coroutines.Dispatchers
@@ -26,13 +28,15 @@ class SettingsActivity : AppCompatActivity() {
2628
override fun getBoolean(key: String?, defValue: Boolean): Boolean {
2729
return when(key) {
2830
"isHookedSystem" -> SettingsRepository.isHookSystem
31+
"random_position" -> SettingsRepository.isRandomPosition
2932
else -> throw IllegalArgumentException("Invalid key $key")
3033
}
3134
}
3235

3336
override fun putBoolean(key: String?, value: Boolean) {
3437
return when(key) {
3538
"isHookedSystem" -> SettingsRepository.isHookSystem = value
39+
"random_position" -> SettingsRepository.isRandomPosition = value
3640
else -> throw IllegalArgumentException("Invalid key $key")
3741
}
3842
}

app/src/main/java/com/android1500/gpssetter/repository/SettingsRepository.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ object SettingsRepository {
2222
private const val lat = 40.7128
2323
private const val lng = 74.0060
2424
private const val isHookedSystem = "isHookedSystem"
25+
private const val isRndPosition = "random_position"
2526

2627
private val pref: SharedPreferences by lazy {
2728
try {
@@ -54,6 +55,10 @@ object SettingsRepository {
5455
get() = pref.getBoolean( isHookedSystem, false)
5556
set(value) { pref.edit().putBoolean(isHookedSystem,value).apply() }
5657

58+
var isRandomPosition :Boolean
59+
get() = pref.getBoolean(isRndPosition, false)
60+
set(value) { pref.edit().putBoolean(isRndPosition, value).apply() }
61+
5762

5863

5964
fun update(start:Boolean, la: Double, ln: Double) {

app/src/main/java/com/android1500/gpssetter/xposed/XposedHook.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ package com.android1500.gpssetter.xposed
22

33
import android.app.AndroidAppHelper
44
import android.app.PendingIntent
5-
import android.content.BroadcastReceiver
65
import android.content.Context
7-
import android.content.Intent
8-
import android.content.IntentFilter
96
import android.location.Location
107
import android.location.LocationManager
118
import android.os.Build
@@ -18,13 +15,18 @@ import kotlinx.coroutines.GlobalScope
1815
import kotlinx.coroutines.launch
1916
import org.lsposed.hiddenapibypass.HiddenApiBypass
2017
import timber.log.Timber
18+
import java.util.*
19+
import kotlin.math.cos
2120

2221

2322
class XposedHook : IXposedHookLoadPackage {
2423

2524
companion object {
2625
var newlat: Double = 40.7128
2726
var newlng: Double = 74.0060
27+
private const val pi = 3.14159265359
28+
private val rand: Random = Random()
29+
private const val earth = 6378137.0
2830
private val settings = Xshare()
2931
var mLastUpdated: Long = 0
3032
private const val SHARED_PREFS_FILENAME = "${BuildConfig.APPLICATION_ID}_prefs"
@@ -194,8 +196,13 @@ class XposedHook : IXposedHookLoadPackage {
194196
private fun updateLocation() {
195197
try {
196198
mLastUpdated = System.currentTimeMillis()
197-
newlat = settings.getLat
198-
newlng = settings.getLng
199+
val x = (rand.nextInt(50) - 25).toDouble()
200+
val y = (rand.nextInt(50) - 25).toDouble()
201+
val dlat = x / earth
202+
val dlng = y / (earth * cos(pi * settings.getLat / 180.0))
203+
newlat = if (settings.isRandomPosition) settings.getLat + (dlat * 180.0 / pi) else settings.getLat
204+
newlng = if (settings.isRandomPosition) settings.getLng + (dlng * 180.0 / pi) else settings.getLng
205+
199206
}catch (e: Exception) {
200207
Timber.tag("GPS Setter").e(e, "Failed to get XposedSettings for %s", context.packageName)
201208
}

app/src/main/java/com/android1500/gpssetter/xposed/Xshare.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.android1500.gpssetter.xposed
22
import com.android1500.gpssetter.BuildConfig
3+
import com.android1500.gpssetter.repository.SettingsRepository
34
import de.robv.android.xposed.XSharedPreferences
45

56
class Xshare {
@@ -30,7 +31,13 @@ import de.robv.android.xposed.XSharedPreferences
3031

3132
val isHookedSystem : Boolean
3233
get() = pref().getBoolean(
33-
"isHookSystem",
34+
"isHookedSystem",
35+
false
36+
)
37+
38+
val isRandomPosition :Boolean
39+
get() = pref().getBoolean(
40+
"random_position",
3441
false
3542
)
3643

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M19.78,17.51c-2.47,0 -6.57,-1.33 -8.68,-5.43C8.77,7.57 10.6,3.6 11.63,2.01C6.27,2.2 1.98,6.59 1.98,12c0,0.14 0.02,0.28 0.02,0.42C2.61,12.16 3.28,12 3.98,12c0,0 0,0 0,0c0,-3.09 1.73,-5.77 4.3,-7.1C7.78,7.09 7.74,9.94 9.32,13c1.57,3.04 4.18,4.95 6.8,5.86c-1.23,0.74 -2.65,1.15 -4.13,1.15c-0.5,0 -1,-0.05 -1.48,-0.14c-0.37,0.7 -0.94,1.27 -1.64,1.64c0.98,0.32 2.03,0.5 3.11,0.5c3.5,0 6.58,-1.8 8.37,-4.52C20.18,17.5 19.98,17.51 19.78,17.51z"/>
5+
<path android:fillColor="@android:color/white" android:pathData="M7,16l-0.18,0C6.4,14.84 5.3,14 4,14c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.62,0 2.49,0 3,0c1.1,0 2,-0.9 2,-2C9,16.9 8.1,16 7,16z"/>
6+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M12,4L12,1L8,5l4,4L12,6c3.31,0 6,2.69 6,6 0,1.01 -0.25,1.97 -0.7,2.8l1.46,1.46C19.54,15.03 20,13.57 20,12c0,-4.42 -3.58,-8 -8,-8zM12,18c-3.31,0 -6,-2.69 -6,-6 0,-1.01 0.25,-1.97 0.7,-2.8L5.24,7.74C4.46,8.97 4,10.43 4,12c0,4.42 3.58,8 8,8v3l4,-4 -4,-4v3z"/>
5+
</vector>

app/src/main/res/xml/root_preferences.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111

1212
</PreferenceCategory>
1313

14+
<PreferenceCategory android:title="System">
15+
16+
<SwitchPreference
17+
android:title="Random position"
18+
android:summary="Location position will be random around set location."
19+
android:icon="@drawable/ic_random_position"
20+
android:key="random_position"/>
21+
22+
</PreferenceCategory>
23+
24+
1425

1526

1627
</PreferenceScreen>

0 commit comments

Comments
 (0)