Skip to content

Commit

Permalink
Added boot completed receiver to send settings to module. This avoids…
Browse files Browse the repository at this point in the history
… problems with SELinux blocking access to the shared preferences. Bumped version to 1.41.
  • Loading branch information
Francois Campbell authored and Francois Campbell committed Jul 9, 2016
1 parent 038bcce commit 5862d66
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 56 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "io.github.francoiscampbell.xposeddatausage"
minSdkVersion 16
targetSdkVersion 23
versionCode 15
versionName "1.40"
versionCode 16
versionName "1.41"
}
buildTypes {
release {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.github.francoiscampbell.xposeddatausage">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:name=".DataUsageApplication"
android:allowBackup="true"
Expand Down Expand Up @@ -39,6 +41,13 @@
</intent-filter>
</activity-alias>

<receiver android:name=".nonmodule.BootCompletedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>


</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import de.robv.android.xposed.callbacks.XC_InitPackageResources
import de.robv.android.xposed.callbacks.XC_LoadPackage
import io.github.francoiscampbell.xposeddatausage.di.AppModule
import io.github.francoiscampbell.xposeddatausage.di.DaggerAppComponent
import io.github.francoiscampbell.xposeddatausage.di.RootModule
import io.github.francoiscampbell.xposeddatausage.log.XposedLog
import io.github.francoiscampbell.xposeddatausage.util.hookLayout
import io.github.francoiscampbell.xposeddatausage.util.registerReceiver
Expand All @@ -18,26 +17,24 @@ import io.github.francoiscampbell.xposeddatausage.util.registerReceiver
*/
class Module() : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPackageResources {
companion object {
private lateinit var rootModule: RootModule
private lateinit var modulePath: String

const val PACKAGE_MODULE = "io.github.francoiscampbell.xposeddatausage"
private const val PACKAGE_SYSTEM_UI = "com.android.systemui"
private const val PACKAGE_ANDROID_SYSTEM = "android"
private const val CLASS_NAME_CONTEXT = "android.app.ContextImpl"
private const val PERMISSION_READ_NETWORK_USAGE_HISTORY = "android.permission.READ_NETWORK_USAGE_HISTORY"
}

override fun initZygote(startupParam: IXposedHookZygoteInit.StartupParam) {
rootModule = RootModule(startupParam.modulePath)
modulePath = startupParam.modulePath
}

override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
if (lpparam.packageName != PACKAGE_ANDROID_SYSTEM) {
return
}

XposedLog.i("Nuking permission check")

XposedLog.i("Nuking PERMISSION_READ_NETWORK_USAGE_HISTORY check")
XposedHelpers.findAndHookMethod(
CLASS_NAME_CONTEXT,
lpparam.classLoader,
Expand Down Expand Up @@ -67,8 +64,7 @@ class Module() : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitP
val hookedContext = liparam.view.context

val dataUsageView = DaggerAppComponent.builder()
.rootModule(rootModule)
.appModule(AppModule(hookedContext, liparam))
.appModule(AppModule(modulePath, hookedContext, liparam))
.build()
.dataUsageView()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.github.francoiscampbell.xposeddatausage.widget.DataUsageView
/**
* Created by francois on 16-03-30.
*/
@Component(modules = arrayOf(RootModule::class, AppModule::class))
@Component(modules = arrayOf(AppModule::class))
interface AppComponent {
fun dataUsageView(): DataUsageView
fun dataUsageView(): DataUsageView
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.francoiscampbell.xposeddatausage.di

import android.content.Context
import android.content.res.XModuleResources
import android.net.ConnectivityManager
import android.net.INetworkStatsService
import android.net.TrafficStats
Expand All @@ -23,8 +24,14 @@ import javax.inject.Named
* Created by francois on 16-03-30.
*/
@Module
open class AppModule(private val hookedContext: Context,
open class AppModule(private val xposedModulePath: String,
private val hookedContext: Context,
private val liparam: XC_LayoutInflated.LayoutInflatedParam) {
@Provides
fun provideXModuleResources(): XModuleResources {
return XModuleResources.createInstance(xposedModulePath, null)
}

@Provides
@Named("ui")
fun provideUiContext() = hookedContext
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ object XposedLog {
var debugLogging = false

fun i(message: String) {
Log.i(xposedTag, "$tag/$message")
}

fun d(message: String) {
if (BuildConfig.DEBUG || debugLogging) {
Log.i(xposedTag, "$tag/$message")
}
}

fun e(message: String, throwable: Throwable? = null) {
when (BuildConfig.DEBUG || debugLogging) {
true -> Log.e(xposedTag, "$tag/$message/${Log.getStackTraceString(throwable)}")
false -> Log.e(xposedTag, "$tag/$message")
if (BuildConfig.DEBUG || debugLogging) {
Log.e(xposedTag, "$tag/$message/${Log.getStackTraceString(throwable)}")
} else {
Log.e(xposedTag, "$tag/$message")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.content.IntentFilter
import android.content.res.XModuleResources
import android.graphics.Color
import de.robv.android.xposed.XSharedPreferences
import io.github.francoiscampbell.xposeddatausage.R
import io.github.francoiscampbell.xposeddatausage.log.XposedLog
import io.github.francoiscampbell.xposeddatausage.model.net.NetworkManager
Expand All @@ -20,22 +19,16 @@ import javax.inject.Named
*/
class SettingsImpl @Inject constructor(
@Named("app") private val context: Context,
private val res: XModuleResources,
private val prefs: XSharedPreferences
private val res: XModuleResources
) : Settings {
private val settingsUpdatedAction = res.getString(R.string.action_settings_updated)
private lateinit var settingsChangedListener: OnSettingsChangedListener

override fun attach(listener: OnSettingsChangedListener) {
settingsChangedListener = listener
sendAllSettingsToListener()
registerSettingsReceiver()
}

private fun sendAllSettingsToListener() {
prefs.apply { reload() }.all.forEach { handleSettingUpdate(it.key, it.value) }
}

private fun registerSettingsReceiver() {
context.registerReceiver(IntentFilter(settingsUpdatedAction)) { context, intent ->
intent.extras?.keySet()?.forEach {
Expand All @@ -46,7 +39,7 @@ class SettingsImpl @Inject constructor(
}

private fun handleSettingUpdate(key: String, newValue: Any?): Unit {
XposedLog.i("$key is $newValue in ${javaClass.simpleName}")
XposedLog.d("$key is $newValue in ${javaClass.simpleName}")
if (newValue == null) return
settingsChangedListener.run {
@Suppress("UNCHECKED_CAST")
Expand Down Expand Up @@ -80,8 +73,6 @@ class SettingsImpl @Inject constructor(
res.getString(R.string.pref_debug_logging_key) -> onDebugLoggingChanged(newValue as Boolean)
}
}

XposedLog.i("Debug logging is ${XposedLog.debugLogging} in SettingsImpl")
}

private fun networkTypeNamesToEnum(networkTypeNames: Set<String>): Set<NetworkManager.NetworkType> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.francoiscampbell.xposeddatausage.nonmodule

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent

/**
* Created by francois on 2016-07-08.
*/
class BootCompletedReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
SettingsChangeActions(context).apply {
startListeningForChanges()
stopListeningForChanges()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SettingsChangeActions(

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
val newPrefValue = sharedPreferences.all[key]
XposedLog.i("$key changed to $newPrefValue in ${javaClass.simpleName}")
XposedLog.d("$key changed to $newPrefValue in ${javaClass.simpleName}")

if (isPrefForApp(key)) {
handleAppPrefChange(key, newPrefValue)
Expand All @@ -38,13 +38,13 @@ class SettingsChangeActions(
}

fun startListeningForChanges() {
XposedLog.i("startBroadcastingChanges")
XposedLog.d("startBroadcastingChanges")
prefs.all.forEach { onSharedPreferenceChanged(prefs, it.key) } //push settings to module when opening the settings app
prefs.registerOnSharedPreferenceChangeListener(this)
}

fun stopListeningForChanges() {
XposedLog.i("stopBroadcastingChanges")
XposedLog.d("stopBroadcastingChanges")
prefs.unregisterOnSharedPreferenceChangeListener(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SettingsFragment : PreferenceFragment() {

settingsChangeActions.startListeningForChanges()

XposedLog.i("Debug logging is ${XposedLog.debugLogging} in SettingsFragment")
XposedLog.d("Debug logging is ${XposedLog.debugLogging} in SettingsFragment")
}

override fun onPause() {
Expand Down

0 comments on commit 5862d66

Please sign in to comment.