Skip to content

Commit

Permalink
Merge pull request #32 from KieronQuinn/release/1.4
Browse files Browse the repository at this point in the history
Release/1.4
  • Loading branch information
KieronQuinn authored Mar 19, 2022
2 parents 89a1808 + 53f3f2e commit e3cd7ef
Show file tree
Hide file tree
Showing 27 changed files with 263 additions and 30 deletions.
10 changes: 5 additions & 5 deletions Controls/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ android {
}

dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation "androidx.lifecycle:lifecycle-common-java8:2.4.0-alpha03"
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.lifecycle:lifecycle-common-java8:2.5.0-alpha04"
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.fragment:fragment:1.3.6'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.fragment:fragment-ktx:1.4.1'
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation "io.insert-koin:koin-android:$koin_version"
compileOnly project(path: ':systemstubs')
Expand Down
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id 'com.google.android.gms.oss-licenses-plugin'
}

def version = '1.3.1'
def version = '1.4'

android {
compileSdk 31
Expand All @@ -16,7 +16,7 @@ android {
applicationId "com.kieronquinn.app.classicpowermenu"
minSdk 30
targetSdk 31
versionCode 131
versionCode 140
versionName version

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -71,15 +71,15 @@ sourceSets{
dependencies {

//AndroidX
def lifecycle_version = "2.4.0"
def lifecycle_version = "2.4.1"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.lifecycle:lifecycle-service:2.4.0'
implementation 'androidx.work:work-runtime-ktx:2.7.1'
implementation "androidx.core:core-splashscreen:1.0.0-beta01"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
Expand Down Expand Up @@ -137,7 +137,7 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

//Other third party
implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:4.2'
implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:4.3'
implementation 'com.airbnb.android:lottie:4.2.2'
implementation 'com.jakewharton:process-phoenix:2.1.2'
implementation 'me.saket:better-link-movement-method:2.2.0'
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 @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 131,
"versionName": "1.3.1",
"versionCode": 140,
"versionName": "1.4",
"outputFile": "app-release.apk"
}
],
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>

<activity android:name=".ui.activities.PowerMenuActivity"
android:theme="@style/Theme.ClassicPowerMenu.Fullscreen"
android:noHistory="true"
android:exported="true"
android:launchMode="singleInstance"
android:excludeFromRecents="true"/>
android:excludeFromRecents="true">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="classicpowermenu"/>
</intent-filter>

</activity>

<service android:name=".service.accessibility.CPMAccessibilityService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface IClassicPowerMenu {
void shutdown();
void reboot(boolean safeMode);
void rebootWithReason(String reason);
void restartSystemUi();

//Screenshot button
void takeScreenshot();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kieronquinn.app.classicpowermenu.components.quickaccesswallet

import android.Manifest
import android.annotation.SuppressLint
import android.content.ComponentName
import android.content.Context
import android.content.Intent
Expand All @@ -11,6 +12,7 @@ import android.util.Log

object CPMQuickAccessWalletServiceInfoBuilder {

@SuppressLint("BlockedPrivateApi")
fun create(context: Context): Any? {
val quickAccessWalletServiceInfoClass = Class.forName("android.service.quickaccesswallet.QuickAccessWalletServiceInfo")
val quickAccessWalletServiceMetadataClass = Class.forName("android.service.quickaccesswallet.QuickAccessWalletServiceInfo\$ServiceMetadata")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ abstract class Settings {
abstract val enabledFlow: Flow<Boolean>
abstract var useMonet: Boolean
abstract var monetColor: Int?
abstract var useSolidBackground: Boolean
abstract var powerOptionsHideWhenLocked: Boolean
abstract var powerOptionsOpenCollapsed: Boolean
abstract var allowRotation: Boolean
Expand Down Expand Up @@ -57,6 +58,9 @@ class SettingsImpl(context: Context): Settings() {

private const val KEY_MONET_COLOR = "monet_color"

private const val KEY_USE_SOLID_BACKGROUND = "use_solid_background"
private const val DEFAULT_USE_SOLID_BACKGROUND = false

//Power Options
private const val KEY_POWER_OPTIONS_HIDE_WHEN_LOCKED = "power_options_hide_when_locked"
private const val DEFAULT_POWER_OPTIONS_HIDE_WHEN_LOCKED = false
Expand Down Expand Up @@ -119,6 +123,7 @@ class SettingsImpl(context: Context): Settings() {

override var useMonet by shared(KEY_USE_MONET, DEFAULT_USE_MONET)
override var monetColor by sharedColor(KEY_MONET_COLOR)
override var useSolidBackground by shared(KEY_USE_SOLID_BACKGROUND, DEFAULT_USE_SOLID_BACKGROUND)

override var powerOptionsHideWhenLocked by shared(KEY_POWER_OPTIONS_HIDE_WHEN_LOCKED, DEFAULT_POWER_OPTIONS_HIDE_WHEN_LOCKED)
override var powerOptionsOpenCollapsed by shared(KEY_POWER_OPTIONS_OPEN_COLLAPSED, DEFAULT_POWER_OPTIONS_OPEN_COLLAPSED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import android.content.pm.ApplicationInfo
import android.os.Build
import android.os.IBinder
import android.util.Log
import android.view.View
import androidx.core.os.BuildCompat
import com.kieronquinn.app.classicpowermenu.BuildConfig
import com.kieronquinn.app.classicpowermenu.IGlobalActions
import com.kieronquinn.app.classicpowermenu.service.globalactions.GlobalActionsService
import com.kieronquinn.app.classicpowermenu.utils.extensions.SystemProperties_getString
import de.robv.android.xposed.*
import de.robv.android.xposed.callbacks.XC_LoadPackage
import java.lang.reflect.Method

class Xposed: IXposedHookLoadPackage, ServiceConnection {

Expand Down Expand Up @@ -59,7 +62,6 @@ class Xposed: IXposedHookLoadPackage, ServiceConnection {
}

private fun hookAospSystemUI(lpparam: XC_LoadPackage.LoadPackageParam) {

val globalActionsDialogClassName = if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){
"com.android.systemui.globalactions.GlobalActionsDialogLite"
}else{
Expand All @@ -75,18 +77,38 @@ class Xposed: IXposedHookLoadPackage, ServiceConnection {
}
})

//Calls the service if connected, and prevents the normal dialog showing if that returns true
XposedHelpers.findAndHookMethod(globalActionsDialogClass, "handleShow", object: XC_MethodHook(){
//Find the showOrHideDialog method, which has multiple variants but always the same first 2 args
val showMethod = globalActionsDialogClass.declaredMethods
.firstOrNull { it.name == "showOrHideDialog" } ?: return

val hideMethod = globalActionsDialogClass
.getDeclaredMethod("dismissGlobalActionsMenu")

val mKeyguardShowing = globalActionsDialogClass
.getDeclaredField("mKeyguardShowing").apply {
isAccessible = true
}

val mDeviceProvisioned = globalActionsDialogClass
.getField("mDeviceProvisioned").apply {
isAccessible = true
}

XposedBridge.hookMethod(showMethod, object: XC_MethodHook() {
override fun beforeHookedMethod(param: MethodHookParam) {
val keyguardShowing = param.args[0]
val deviceProvisioned = param.args[1]
mKeyguardShowing.set(param.thisObject, keyguardShowing)
mDeviceProvisioned.set(param.thisObject, deviceProvisioned)
if(handleShow(param)){
param.result = true
}
}
})

//Optionally calls to the service, if it exists
XposedHelpers.findAndHookMethod(globalActionsDialogClass, "dismissDialog", object: XC_MethodHook(){
XposedBridge.hookMethod(hideMethod, object: XC_MethodHook() {
override fun beforeHookedMethod(param: MethodHookParam?) {
super.beforeHookedMethod(param)
handleDismiss()
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum class PowerMenuButtonType {
}

enum class PowerMenuButtonId {
EMERGENCY, POWER_OFF, REBOOT, LOCKDOWN, SCREENSHOT, REBOOT_RECOVERY, REBOOT_BOOTLOADER;
EMERGENCY, POWER_OFF, REBOOT, LOCKDOWN, SCREENSHOT, REBOOT_RECOVERY, REBOOT_BOOTLOADER, RESTART_SYSTEMUI;

companion object {
val DEFAULT = listOf(EMERGENCY, POWER_OFF, REBOOT, LOCKDOWN, SCREENSHOT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CPMRootServiceImpl: IClassicPowerMenu.Stub() {
UserHandle::class.java.getMethod("getIdentifier").invoke(userHandle) as Int
Intent::class.java.getMethod("prepareToLeaveProcess", Context::class.java)
.invoke(intent, context)
return activityManager.bindIsolatedService(
return activityManager.bindServiceInstance(
bindContainer.thread,
bindContainer.activityToken,
intent,
Expand Down Expand Up @@ -138,6 +138,10 @@ class CPMRootServiceImpl: IClassicPowerMenu.Stub() {
powerManager.reboot(false, reason, false)
}

override fun restartSystemUi() {
Runtime.getRuntime().exec("pkill systemui")
}

override fun takeScreenshot() {
//Wait for app to close
Handler(Looper.getMainLooper()).postDelayed({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class PowerMenuActivity : MonetCompatActivity(), PowerMenuStarter.PowerMenuStart
starter.setEventListener(this)
lifecycleScope.launchWhenResumed {
window.decorView.awaitPost()
blurProvider.applyBlurToWindow(window, 1.5f)
if(!viewModel.useSolidBackground){
blurProvider.applyBlurToWindow(window, 1.5f)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ abstract class PowerMenuActivityViewModel: ViewModel() {
abstract val closeBroadcast: Flow<Unit>
abstract fun sendCloseBroadcast(context: Context, ignoreSelf: Boolean)

abstract val useSolidBackground: Boolean

}

class PowerMenuActivityViewModelImpl(context: Context, private val service: CPMServiceContainer, private val settings: Settings): PowerMenuActivityViewModel() {
Expand Down Expand Up @@ -49,4 +51,6 @@ class PowerMenuActivityViewModelImpl(context: Context, private val service: CPMS
}
}

override val useSolidBackground by settings::useSolidBackground

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,19 @@ class PowerMenuFragment :
}

private fun View.setupBackground() {
background = ColorDrawable(
ColorUtils.setAlphaComponent(
monet.getBackgroundColor(context, true),
128
background = if(viewModel.useSolidBackground){
ColorDrawable(
monet.getBackgroundColorSecondary(context, true)
?: monet.getBackgroundColor(context, true)
)
)
}else{
ColorDrawable(
ColorUtils.setAlphaComponent(
monet.getBackgroundColor(context, true),
128
)
)
}
}

private fun setupButtonsRecyclerView() = with(binding.powerMenuButtonsRecyclerview) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ abstract class PowerMenuViewModel: ViewModel() {
abstract fun onRebootLongClicked()
abstract fun onRebootRecoveryClicked()
abstract fun onRebootBootloaderClicked()
abstract fun onRestartSystemUIClicked()

abstract fun onEmergencyClicked(context: Context)
abstract fun onLockdownClicked()
Expand All @@ -46,6 +47,7 @@ abstract class PowerMenuViewModel: ViewModel() {
abstract val showQuickAccessWallet: Boolean
abstract val showControls: Boolean
abstract val monetEnabled: Boolean
abstract val useSolidBackground: Boolean

}

Expand All @@ -64,6 +66,7 @@ class PowerMenuViewModelImpl(context: Context, private val service: CPMServiceCo
override val showControls by settings::deviceControlsShow
override val showQuickAccessWallet by settings::quickAccessWalletShow
override val monetEnabled by settings::useMonet
override val useSolidBackground by settings::useSolidBackground

override suspend fun shouldShowLockdown(): Boolean {
//No point showing lockdown without a lock
Expand Down Expand Up @@ -116,6 +119,15 @@ class PowerMenuViewModelImpl(context: Context, private val service: CPMServiceCo
}
}

override fun onRestartSystemUIClicked() {
viewModelScope.launch {
service.runWithService {
it.restartSystemUi()
}
navigation.closePowerMenu()
}
}

override fun onRebootLongClicked() {
viewModelScope.launch {
navigation.navigate(PowerMenuFragmentDirections.actionPowerMenuFragmentToSafeModeTopSheetFragment())
Expand Down Expand Up @@ -247,6 +259,13 @@ class PowerMenuViewModelImpl(context: Context, private val service: CPMServiceCo
::onRebootBootloaderClicked,
shouldShow = ::shouldShowPowerOption
)
PowerMenuButtonId.RESTART_SYSTEMUI -> PowerMenuButton.Button(
PowerMenuButtonId.RESTART_SYSTEMUI,
R.drawable.ic_restart_systemui,
context.getString(R.string.power_menu_button_restart_systemui),
::onRestartSystemUIClicked,
shouldShow = ::shouldShowPowerOption
)
}

private fun shouldShowPowerOption(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SettingsFaqFragment: BoundFragment<FragmentSettingsFaqBinding>(FragmentSet

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.root.isNestedScrollingEnabled = false
val typeface = ResourcesCompat.getFont(requireContext(), R.font.google_sans_text_medium)
val markwon = Markwon.builder(requireContext()).usePlugin(object: AbstractMarkwonPlugin() {
override fun configureTheme(builder: MarkwonTheme.Builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class SettingsMainFragment : SettingsSwitchedFragment(), AutoExpandOnRotate, Pro
getText(R.string.settings_monet_desc),
viewModel::useMonet
),
SettingsItem.SwitchSetting(
R.drawable.ic_settings_solid_color,
getString(R.string.settings_solid_color),
getText(R.string.settings_solid_color_desc),
viewModel::useSolidColor
),
SettingsItem.Setting(
R.drawable.ic_settings_monet_color_picker,
getString(R.string.settings_monet_color_picker),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ abstract class SettingsMainViewModel: ViewModel() {
abstract val developerOptionsEnabled: Flow<Boolean>
abstract var accessibilityServiceDisabled: Boolean
abstract val accessibilityServiceDisabledFlow: Flow<Boolean>
abstract var useSolidColor: Boolean

abstract fun isDeveloperOptionsEnabled(): Boolean
abstract fun isWallpaperColorPickerAvailable(): Boolean
Expand All @@ -53,6 +54,7 @@ class SettingsMainViewModelImpl(context: Context, private val settings: Settings
override val enabled = settings.enabledFlow
override val enabledInitialState = settings.enabled
override var useMonet by settings::useMonet
override var useSolidColor by settings::useSolidBackground
override val developerOptionsEnabled = settings.developerOptionsEnabledFlow
private val resumeBus = MutableSharedFlow<Unit>()

Expand Down
Loading

0 comments on commit e3cd7ef

Please sign in to comment.