-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Backup and Restore your config to device or the cloud - A rewritten Xposed module with the ability to make even more apps work with force dark, including Snapchat and an option (enabled by default) to fix the inverted (black on dark) status bar icon colors. - Fixed crashes related to navigation in the app - Fixed a crash where requesting root could cause a crash - Improved some Material You theming throughout the app
- Loading branch information
1 parent
685e084
commit 3376e4e
Showing
60 changed files
with
1,494 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,118 @@ | ||
package com.kieronquinn.app.darq | ||
|
||
import android.app.Activity | ||
import android.app.AndroidAppHelper | ||
import android.content.Context | ||
import android.content.res.Resources | ||
import android.util.Log | ||
import android.view.View | ||
import de.robv.android.xposed.IXposedHookLoadPackage | ||
import de.robv.android.xposed.XC_MethodReplacement | ||
import de.robv.android.xposed.XposedHelpers | ||
import com.kieronquinn.app.darq.components.settings.XposedSharedPreferences | ||
import com.kieronquinn.app.darq.model.xposed.XposedSettings | ||
import com.kieronquinn.app.darq.utils.extensions.isDarkTheme | ||
import de.robv.android.xposed.* | ||
import de.robv.android.xposed.callbacks.XC_LoadPackage | ||
|
||
|
||
class Xposed : IXposedHookLoadPackage { | ||
|
||
companion object { | ||
private const val TAG = "DarQXposed" | ||
private const val SHARED_PREFS_FILENAME = "${BuildConfig.APPLICATION_ID}_prefs" | ||
} | ||
|
||
private var xposedSettings: XposedSettings? = null | ||
|
||
private val context by lazy { | ||
AndroidAppHelper.currentApplication() as Context | ||
} | ||
|
||
private val isDarkMode: Boolean | ||
get() = Resources.getSystem().configuration.isDarkTheme | ||
|
||
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { | ||
XposedHelpers.findAndHookMethod(View::class.java, "setForceDarkAllowed", Boolean::class.java, object : XC_MethodReplacement() { | ||
override fun replaceHookedMethod(param: MethodHookParam?): Any? { | ||
Log.d("DarQXposed", "Preventing the use of setForceDarkAllowed for ${lpparam.packageName}") | ||
return null | ||
if(lpparam.packageName == BuildConfig.APPLICATION_ID){ | ||
setupSelfHooks(lpparam.classLoader) | ||
} | ||
XposedHelpers.findAndHookMethod(View::class.java, "setForceDarkAllowed", Boolean::class.java, object : XC_MethodHook() { | ||
override fun beforeHookedMethod(param: MethodHookParam) { | ||
super.beforeHookedMethod(param) | ||
if(xposedSettings == null) { | ||
xposedSettings = getXposedSettings(context) | ||
} | ||
if(xposedSettings?.enabled == true){ | ||
param.args[0] = true | ||
} | ||
} | ||
}) | ||
XposedHelpers.findAndHookMethod(Activity::class.java, "onResume", object: XC_MethodHook(){ | ||
override fun afterHookedMethod(param: MethodHookParam) { | ||
super.afterHookedMethod(param) | ||
if(xposedSettings == null) { | ||
xposedSettings = getXposedSettings(context) | ||
} | ||
if(xposedSettings?.enabled == true && xposedSettings?.invertStatus == true){ | ||
val activity = param.thisObject as? Activity ?: return | ||
if(isDarkMode) { | ||
activity.window.decorView.run { | ||
post { | ||
systemUiVisibility = | ||
systemUiVisibility.and(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
XposedHelpers.findAndHookMethod("android.graphics.HardwareRenderer", lpparam.classLoader, "setForceDark", Boolean::class.java, object: XC_MethodHook(){ | ||
override fun beforeHookedMethod(param: MethodHookParam) { | ||
super.beforeHookedMethod(param) | ||
if(xposedSettings?.enabled == true && xposedSettings?.aggressiveDark == true) { | ||
Log.i(TAG, "Overriding setForceDark to $isDarkMode for ${lpparam.packageName}") | ||
param.args[0] = isDarkMode | ||
} | ||
} | ||
}) | ||
} | ||
|
||
private fun setupSelfHooks(classLoader: ClassLoader){ | ||
XposedHelpers.findAndHookMethod("com.kieronquinn.app.darq.model.xposed.XposedSelfHooks", classLoader, "isXposedModuleEnabled", object: XC_MethodReplacement(){ | ||
override fun replaceHookedMethod(param: MethodHookParam): Any { | ||
param.result = true | ||
return true | ||
} | ||
}) | ||
XposedHelpers.findAndHookMethod("com.kieronquinn.app.darq.model.xposed.XposedSelfHooks", classLoader, "getXSharedPrefsPath", object: XC_MethodReplacement(){ | ||
override fun replaceHookedMethod(param: MethodHookParam): Any { | ||
val path = XSharedPreferences(BuildConfig.APPLICATION_ID, SHARED_PREFS_FILENAME).file.absolutePath | ||
param.result = path | ||
return path | ||
} | ||
}) | ||
} | ||
|
||
private fun getXposedSettings(context: Context): XposedSettings? { | ||
return try { | ||
val xposedPreferences = XposedSharedPreferences(SHARED_PREFS_FILENAME) | ||
val darqEnabled = xposedPreferences.enabled | ||
val appSelected = xposedPreferences.enabledApps.contains(context.packageName) | ||
val alwaysUseForceDark = xposedPreferences.alwaysForceDark | ||
Log.d(TAG, "Enabled apps ${xposedPreferences.enabledApps.joinToString(", ")}") | ||
return if(!darqEnabled || (!appSelected && !alwaysUseForceDark)){ | ||
XposedSettings(enabled = false).apply { | ||
Log.d(TAG, "Got XposedSettings disabled for ${context.packageName}") | ||
} | ||
}else{ | ||
XposedSettings(enabled = true, aggressiveDark = xposedPreferences.xposedAggressiveDark, invertStatus = xposedPreferences.xposedInvertStatus).apply { | ||
Log.d(TAG, "Got XposedSettings enabled for ${context.packageName}") | ||
} | ||
} | ||
}catch (e: Exception){ | ||
//Don't crash the app | ||
if(BuildConfig.DEBUG) { | ||
Log.e(TAG, "Failed to get XposedSettings for ${context.packageName}", e) | ||
} | ||
null | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.