Skip to content

Commit

Permalink
Merge pull request #35 from KieronQuinn/release/2.1
Browse files Browse the repository at this point in the history
2.1
  • Loading branch information
KieronQuinn authored Jul 8, 2021
2 parents 685e084 + 3376e4e commit 328165c
Show file tree
Hide file tree
Showing 60 changed files with 1,494 additions and 50 deletions.
76 changes: 76 additions & 0 deletions .idea/navEditor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ plugins {
id 'com.google.android.gms.oss-licenses-plugin'
}

def tagName = '2.0'
def tagName = '2.1'

android {
compileSdkVersion 'android-S'
defaultConfig {
applicationId "com.kieronquinn.app.darq"
minSdkVersion 29
targetSdkVersion 'S'
versionCode 13
versionName "2.0"
versionCode 21
versionName "2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String", "TAG_NAME", "\"${tagName}\"")
}
Expand Down Expand Up @@ -77,7 +77,8 @@ dependencies {

//AndroidX
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.core:core-ktx:1.5.0'
implementation "androidx.fragment:fragment-ktx:1.3.5"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.work:work-runtime-ktx:2.5.0"

Expand All @@ -93,7 +94,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"

//Material
implementation 'com.google.android.material:material:1.4.0-rc01'
implementation 'com.google.android.material:material:1.4.0'

//Network
implementation 'com.squareup.picasso:picasso:2.71828'
Expand Down
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 13,
"versionName": "2.0",
"versionCode": 21,
"versionName": "2.1",
"outputFile": "app-release.apk"
}
]
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@
android:value="@string/xposed_desc" />
<meta-data
android:name="xposedminversion"
android:value="53" />
android:value="93" />
<meta-data
android:name="xposedsharedprefs"
android:value="true" />

</application>

Expand Down
2 changes: 0 additions & 2 deletions app/src/main/assets/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ Sometimes an app launches too quickly for force dark to be applied. You may have
## Which apps look good when force dark is enabled?
During testing; LinkedIn, Facebook and Google Opinion Rewards were found to be usable with force dark enabled. Plenty more will work too, it's up to you to experiment and see what works.

Please note that some of the above require the Xposed module to be enabled for them to work.

## Can Force Dark be made to work on all apps without Xposed?
No. Apps are able to disable force dark in code, so Xposed is the only way to prevent that.

Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/kieronquinn/app/darq/DarqApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ package com.kieronquinn.app.darq
import android.app.Application
import android.app.DownloadManager
import android.content.Context
import android.util.Log
import com.kieronquinn.app.darq.components.github.UpdateChecker
import com.kieronquinn.app.darq.components.navigation.Navigation
import com.kieronquinn.app.darq.components.navigation.NavigationImpl
import com.kieronquinn.app.darq.components.settings.AppSharedPreferences
import com.kieronquinn.app.darq.components.settings.DarqSharedPreferences
import com.kieronquinn.app.darq.providers.DarqServiceConnectionProvider
import com.kieronquinn.app.darq.providers.blur.BlurProvider
import com.kieronquinn.app.darq.ui.screens.bottomsheets.backuprestore.BackupRestoreBottomSheetViewModel
import com.kieronquinn.app.darq.ui.screens.bottomsheets.backuprestore.BackupRestoreBottomSheetViewModelImpl
import com.kieronquinn.app.darq.ui.screens.bottomsheets.backuprestore.backup.BackupRestoreBackupBottomSheetViewModel
import com.kieronquinn.app.darq.ui.screens.bottomsheets.backuprestore.backup.BackupRestoreBackupBottomSheetViewModelImpl
import com.kieronquinn.app.darq.ui.screens.bottomsheets.backuprestore.restore.BackupRestoreRestoreBottomSheetViewModelImpl
import com.kieronquinn.app.darq.ui.screens.bottomsheets.backuprestore.restore.BackupRestoreRestoreViewModel
import com.kieronquinn.app.darq.ui.screens.bottomsheets.update.UpdateDownloadBottomSheetViewModel
import com.kieronquinn.app.darq.ui.screens.bottomsheets.update.UpdateDownloadBottomSheetViewModelImpl
import com.kieronquinn.app.darq.ui.screens.container.ContainerSharedViewModel
Expand Down Expand Up @@ -52,6 +59,9 @@ class DarqApplication : Application() {
viewModel<SettingsDeveloperOptionsViewModel>{ SettingsDeveloperOptionsViewModelImpl(get()) }
viewModel<UpdateDownloadBottomSheetViewModel>{ UpdateDownloadBottomSheetViewModelImpl(getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager) }
viewModel<LocationPermissionDialogViewModel> { LocationPermissionDialogViewModelImpl(get(), get()) }
viewModel<BackupRestoreBottomSheetViewModel> { BackupRestoreBottomSheetViewModelImpl(get()) }
viewModel<BackupRestoreBackupBottomSheetViewModel> { BackupRestoreBackupBottomSheetViewModelImpl(get(), get(), get()) }
viewModel<BackupRestoreRestoreViewModel> { BackupRestoreRestoreBottomSheetViewModelImpl(get(), get(), get()) }
}

private val providersModule = module {
Expand All @@ -73,6 +83,8 @@ class DarqApplication : Application() {
androidContext(this@DarqApplication)
modules(serviceModule, appComponentsModule, viewModelsModule, providersModule)
}
val applicationThread = Context::class.java.getMethod("getIApplicationThread").invoke(this as Context)
Log.d("DarQA", "ApplicationThread $applicationThread")
Sui.init(packageName)
setupMonet()
}
Expand Down
112 changes: 105 additions & 7 deletions app/src/main/java/com/kieronquinn/app/darq/Xposed.kt
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
}
}

}
Loading

0 comments on commit 328165c

Please sign in to comment.