Skip to content

Commit

Permalink
fix #5
Browse files Browse the repository at this point in the history
  • Loading branch information
fuqiuluo committed Oct 31, 2024
1 parent bb7a8a6 commit 118a41a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/moe/fuqiuluo/portal/ext/Perfs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ var Context.needDowngradeToCdma: Boolean
putBoolean("needDowngradeToCdma", value)
}

var Context.hookSensor: Boolean
get() = sharedPrefs.getBoolean("hookSensor", false)

set(value) = sharedPrefs.edit {
putBoolean("hookSensor", value)
}

//var Context.updateInterval: Long
// get() = sharedPrefs.getLong("updateInterval", FakeLoc.updateInterval)
//
Expand Down
20 changes: 12 additions & 8 deletions app/src/main/java/moe/fuqiuluo/portal/ui/mock/MockFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import moe.fuqiuluo.portal.databinding.FragmentMockBinding
import moe.fuqiuluo.portal.ext.altitude
import moe.fuqiuluo.portal.ext.drawOverOtherAppsEnabled
import moe.fuqiuluo.portal.ext.historicalLocations
import moe.fuqiuluo.portal.ext.hookSensor
import moe.fuqiuluo.portal.ext.needOpenSELinux
import moe.fuqiuluo.portal.ext.rawHistoricalLocations
import moe.fuqiuluo.portal.ext.selectLocation
Expand Down Expand Up @@ -223,14 +224,17 @@ class MockFragment : Fragment() {
}

if (ShellUtils.hasRoot()) {
ShellUtils.setEnforceMode(false) // 关闭SELinux
if(MockServiceHelper.loadPortalLibrary(requireContext())) {
showToast("传感器劫持成功")
} else {
showToast("无法劫持传感器")
}
if (requireContext().needOpenSELinux) {
ShellUtils.setEnforceMode(true)
if (requireContext().hookSensor) {
ShellUtils.setEnforceMode(false) // 关闭SELinux
if(MockServiceHelper.loadPortalLibrary(requireContext())) {
showToast("传感器劫持成功")
} else {
showToast("无法劫持传感器")
}

if (requireContext().needOpenSELinux) {
ShellUtils.setEnforceMode(true)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import moe.fuqiuluo.portal.ext.debug
import moe.fuqiuluo.portal.ext.disableFusedProvider
import moe.fuqiuluo.portal.ext.disableGetCurrentLocation
import moe.fuqiuluo.portal.ext.disableRegitserLocationListener
import moe.fuqiuluo.portal.ext.hookSensor
import moe.fuqiuluo.portal.ext.needDowngradeToCdma
import moe.fuqiuluo.portal.ext.needOpenSELinux
import moe.fuqiuluo.portal.ext.rawHistoricalLocations
Expand Down Expand Up @@ -175,6 +176,18 @@ class SettingsFragment : Fragment() {
}
})

binding.sensorHookSwitch.isChecked = context.hookSensor
binding.sensorHookSwitch.setOnCheckedChangeListener(object: CompoundButton.OnCheckedChangeListener {
override fun onCheckedChanged(
buttonView: CompoundButton?,
isChecked: Boolean
) {
context.hookSensor = isChecked
showToast("重新启动生效")
updateRemoteConfig()
}
})


return root
}
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,44 @@
android:layout_gravity="center_vertical"
app:useMaterialThemeColors="true"/>
</LinearLayout>

<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/cdma_layout"
app:layout_constraintStart_toStartOf="parent" />

<LinearLayout
android:id="@+id/sensor_hook_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center_vertical">
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hook_sensor"
android:textColor="@color/portal_mini_title_color" />
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hook_sensor_desc"
android:textSize="11sp" />
</LinearLayout>
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/sensor_hook_switch"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
app:useMaterialThemeColors="true"/>
</LinearLayout>
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 118a41a

Please sign in to comment.