├── app ├── .gitignore ├── src │ └── main │ │ ├── ic_launcher-playstore.png │ │ ├── java │ │ └── org │ │ │ └── alberto97 │ │ │ └── aodtoggle │ │ │ ├── config │ │ │ ├── Settings.kt │ │ │ └── AmbientDisplayConfiguration.kt │ │ │ ├── permissions │ │ │ ├── PlatformExtensions.kt │ │ │ ├── ShizukuUtils.kt │ │ │ ├── GrantWriteSecureSettingsUseCase.kt │ │ │ └── PlatformPermissionManager.kt │ │ │ ├── TileServiceExtensions.kt │ │ │ └── AodTileService.kt │ │ ├── res │ │ ├── mipmap │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── values-zh-rTW │ │ │ └── strings.xml │ │ ├── values │ │ │ └── strings.xml │ │ └── drawable │ │ │ ├── ic_round_aod_24.xml │ │ │ └── ic_launcher_foreground.xml │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── fastlane └── metadata │ └── android │ ├── zh-TW │ ├── title.txt │ ├── short_description.txt │ └── full_description.txt │ └── en-US │ ├── title.txt │ ├── changelogs │ ├── 2.txt │ ├── 3.txt │ └── 4.txt │ ├── short_description.txt │ ├── images │ ├── icon.png │ └── featureGraphic.png │ └── full_description.txt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle ├── LICENSE ├── gradle.properties ├── README.md ├── .gitignore ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /fastlane/metadata/android/zh-TW/title.txt: -------------------------------------------------------------------------------- 1 | 微光螢幕控制 -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/title.txt: -------------------------------------------------------------------------------- 1 | Always On Display Toggle -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/2.txt: -------------------------------------------------------------------------------- 1 | * Update for F-Droid release 2 | -------------------------------------------------------------------------------- /fastlane/metadata/android/zh-TW/short_description.txt: -------------------------------------------------------------------------------- 1 | 透過快速設定面板切換 Always On Display -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/short_description.txt: -------------------------------------------------------------------------------- 1 | Toggle Always on Display from the quick settings panel -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/3.txt: -------------------------------------------------------------------------------- 1 | * Added support for Android 13 2 | * Remove no more used dependency 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alberto97/AlwaysOnDisplayToggle/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alberto97/AlwaysOnDisplayToggle/HEAD/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/4.txt: -------------------------------------------------------------------------------- 1 | * Added support for Android 14 2 | * The WRITE_SECURE_SETTINGS permission now can be granted via Shizuku 3 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alberto97/AlwaysOnDisplayToggle/HEAD/fastlane/metadata/android/en-US/images/icon.png -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/images/featureGraphic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alberto97/AlwaysOnDisplayToggle/HEAD/fastlane/metadata/android/en-US/images/featureGraphic.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | google() 5 | mavenCentral() 6 | } 7 | } 8 | rootProject.name='AOD Toggle' 9 | include ':app' 10 | -------------------------------------------------------------------------------- /app/src/main/java/org/alberto97/aodtoggle/config/Settings.kt: -------------------------------------------------------------------------------- 1 | package org.alberto97.aodtoggle.config 2 | 3 | // Keep in sync with 4 | // https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/provider/Settings.java 5 | object Settings { 6 | const val DOZE_ALWAYS_ON = "doze_always_on" 7 | } -------------------------------------------------------------------------------- /app/src/main/res/mipmap/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /fastlane/metadata/android/zh-TW/full_description.txt: -------------------------------------------------------------------------------- 1 | 這個應用程式能在快速設定面板建立一個啟用 / 停用 Always On Display (微光螢幕) 方塊。 2 | 這項功能需要寫入系統設定,請透過 Shizuku 或您電腦中的 ADB 命令取得權限,使其能夠正常運作: 3 | adb shell pm grant org.alberto97.aodtoggle android.permission.WRITE_SECURE_SETTINGS 4 | 5 | 請注意,本應用程式僅有使用 Google Pixel 進行測試。 6 | 不同的裝置製造商可能會以其他方式設計 Always On Display,使本應用程式無法運作。 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionSha256Sum=61ad310d3c7d3e5da131b76bbf22b5a4c0786e9d892dae8c1658d4b484de3caa 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip 5 | networkTimeout=10000 6 | validateDistributionUrl=true 7 | zipStoreBase=GRADLE_USER_HOME 8 | zipStorePath=wrapper/dists 9 | -------------------------------------------------------------------------------- /app/src/main/java/org/alberto97/aodtoggle/permissions/PlatformExtensions.kt: -------------------------------------------------------------------------------- 1 | package org.alberto97.aodtoggle.permissions 2 | 3 | import android.os.UserHandle 4 | 5 | object PlatformExtensions { 6 | 7 | fun UserHandle.getIdentifier(): Int { 8 | val getIdentifierMethod = UserHandle::class.java.getMethod("getIdentifier") 9 | return getIdentifierMethod.invoke(this) as Int 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/res/values-zh-rTW/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 切換微光螢幕 3 | 微光螢幕 4 | 請安裝 Shizuku 或連接您的電腦並執行下列指令: 5 | \nadb shell pm grant %1$s %2$s 6 | 請開啟 Shizuku 並授權應用程式「%1$s」 7 | 不支援的裝置 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Always on display toggle 3 | Always on display 4 | Please install Shizuku or run the following command from your pc:\nadb shell pm grant %1$s %2$s 5 | Please open Shizuku and authorize the app \"%1$s\" 6 | Unsupported device 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/java/org/alberto97/aodtoggle/TileServiceExtensions.kt: -------------------------------------------------------------------------------- 1 | package org.alberto97.aodtoggle 2 | 3 | import android.app.AlertDialog 4 | import android.service.quicksettings.TileService 5 | 6 | object TileServiceExtensions { 7 | 8 | fun TileService.collapseQSPanel() { 9 | // Show dialog and dismiss it immediately as workaround to close the QS panel 10 | val dialog = AlertDialog.Builder(this) 11 | .create() 12 | 13 | showDialog(dialog) 14 | dialog.dismiss() 15 | } 16 | } -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/full_description.txt: -------------------------------------------------------------------------------- 1 | This app adds a tile to the quick settings panel that turns Always on Display on or off. 2 | The app needs to write to the system settings. Therefore the related permission has to be granted via Shizuku or from your computer with adb in order for the app to work properly: 3 | 4 | adb shell pm grant org.alberto97.aodtoggle android.permission.WRITE_SECURE_SETTINGS 5 | 6 | Please note that this app has only been tested on Google Pixel. 7 | Different manufacturers may have implemented AoD their own way and therefore the app might not work. -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_round_aod_24.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/org/alberto97/aodtoggle/permissions/ShizukuUtils.kt: -------------------------------------------------------------------------------- 1 | package org.alberto97.aodtoggle.permissions 2 | 3 | import android.content.pm.PackageManager 4 | import rikka.shizuku.Shizuku 5 | 6 | enum class ShizukuStatus { 7 | PERM_GRANTED, PERM_NOT_GRANTED, SERVICE_STOPPED 8 | } 9 | 10 | object ShizukuUtils { 11 | 12 | fun hasPermission(): ShizukuStatus { 13 | return if (Shizuku.getBinder() != null) { 14 | if (Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED) { 15 | ShizukuStatus.PERM_GRANTED 16 | } else { 17 | ShizukuStatus.PERM_NOT_GRANTED 18 | } 19 | } else { 20 | ShizukuStatus.SERVICE_STOPPED 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 11 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/java/org/alberto97/aodtoggle/permissions/GrantWriteSecureSettingsUseCase.kt: -------------------------------------------------------------------------------- 1 | package org.alberto97.aodtoggle.permissions 2 | 3 | import android.Manifest 4 | import android.content.Context 5 | import android.os.Process 6 | import android.util.Log 7 | import org.alberto97.aodtoggle.permissions.PlatformExtensions.getIdentifier 8 | 9 | class GrantWriteSecureSettingsUseCase( 10 | private val permissionManager: PlatformPermissionManager = PlatformPermissionManager() 11 | ) { 12 | companion object { 13 | const val TAG = "GrantWriteSecureSettingsUseCase" 14 | } 15 | 16 | fun execute(context: Context): Boolean { 17 | try { 18 | val userId = Process.myUserHandle().getIdentifier() 19 | permissionManager.grantRuntimePermission( 20 | context.packageName, 21 | Manifest.permission.WRITE_SECURE_SETTINGS, 22 | userId 23 | ) 24 | return true 25 | } catch (e: Exception) { 26 | Log.e(TAG, "Could not grant WRITE_SECURE_SETTINGS: ${e.stackTraceToString()}") 27 | return false 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Alberto Pedron 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official 20 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | namespace 'org.alberto97.aodtoggle' 8 | compileSdk 35 9 | 10 | defaultConfig { 11 | applicationId "org.alberto97.aodtoggle" 12 | minSdkVersion 26 13 | targetSdkVersion 35 14 | versionCode 4 15 | versionName "1.1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled true 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | 27 | compileOptions { 28 | sourceCompatibility = JavaVersion.VERSION_21 29 | targetCompatibility = JavaVersion.VERSION_21 30 | } 31 | } 32 | 33 | dependencies { 34 | implementation fileTree(dir: 'libs', include: ['*.jar']) 35 | 36 | implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:6.1' 37 | 38 | def shizuku_version = "13.1.5" 39 | implementation "dev.rikka.shizuku:api:$shizuku_version" 40 | implementation "dev.rikka.shizuku:provider:$shizuku_version" 41 | 42 | compileOnly "dev.rikka.hidden:stub:4.3.3" 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 6 | 7 | 13 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Always on Display Toggle 2 | 3 | [Get it on F-Droid](https://f-droid.org/packages/org.alberto97.aodtoggle/) 7 | 8 | [![GitHub release](https://img.shields.io/github/release/Alberto97/AlwaysOnDisplayToggle.svg?logo=github)](https://github.com/Alberto97/AlwaysOnDisplayToggle/releases/latest) 9 | [![F-Droid](https://img.shields.io/f-droid/v/org.alberto97.aodtoggle.svg?logo=F-Droid)](https://f-droid.org/en/packages/org.alberto97.aodtoggle/) 10 | [![GitHub license](https://img.shields.io/github/license/Alberto97/AlwaysOnDisplayToggle)](https://github.com/Alberto97/AlwaysOnDisplayToggle/blob/master/LICENSE) 11 | 12 | An Android quick setting that turns Always on Display on or off. 13 | 14 | ## Permissions 15 | 16 | The app requires the ```WRITE_SECURE_SETTINGS``` permission to be able to toggle AoD on and off.\ 17 | You can grant it with [Shizuku](https://shizuku.rikka.app/) or adb: 18 | 19 | ```bash 20 | adb shell pm grant org.alberto97.aodtoggle android.permission.WRITE_SECURE_SETTINGS 21 | ``` 22 | or in case of multiple users (`` is listed as first number in output of `adb shell pm list users`): 23 | ```bash 24 | adb shell pm grant --user org.alberto97.aodtoggle android.permission.WRITE_SECURE_SETTINGS 25 | ``` 26 | 27 | Please note that this app has only been tested on Google Pixels.\ 28 | Different manufacturers may have implemented AoD their own way and therefore the app might not work. 29 | -------------------------------------------------------------------------------- /app/src/main/java/org/alberto97/aodtoggle/config/AmbientDisplayConfiguration.kt: -------------------------------------------------------------------------------- 1 | package org.alberto97.aodtoggle.config 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.res.Resources 5 | import android.text.TextUtils 6 | import android.util.Log 7 | 8 | // In a real world where every manufacturer modify the Android framework its own way 9 | // this is probably not enough to make sure AOD is available. 10 | // I have a Pixel though. 11 | class AmbientDisplayConfiguration { 12 | 13 | fun isAvailable(): Boolean { 14 | return isAodAvailable() && isDozeAvailable() 15 | } 16 | 17 | private fun isAodAvailable(): Boolean { 18 | val available = try { 19 | val res = getAndroidIdentifier("config_dozeAlwaysOnDisplayAvailable", "bool") 20 | Resources.getSystem().getBoolean(res) 21 | } catch (e: Exception) { 22 | false 23 | } 24 | Log.d("package", "AOD available: $available") 25 | return available 26 | } 27 | 28 | private fun isDozeAvailable(): Boolean { 29 | val component = try { 30 | val res = getAndroidIdentifier("config_dozeComponent", "string") 31 | Resources.getSystem().getString(res) 32 | } catch (e: Exception) { 33 | null 34 | } 35 | val available = !TextUtils.isEmpty(component) 36 | Log.d("package", "Ambient Display component: $component - available: $available") 37 | return available 38 | } 39 | 40 | @SuppressLint("DiscouragedApi") 41 | private fun getAndroidIdentifier(name: String, defType: String): Int { 42 | return Resources.getSystem().getIdentifier(name, defType, "android") 43 | } 44 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.aar 4 | *.ap_ 5 | *.aab 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | # Uncomment the following line in case you need and you don't have the release build type files in your app 18 | # release/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # IDEA/Android Studio project files, because 40 | # the project can be imported from settings.gradle 41 | *.iml 42 | .idea/* 43 | !.idea/copyright 44 | !.idea/codeStyles/codeStyleConfig.xml 45 | 46 | # Keystore files 47 | # Uncomment the following lines if you do not want to check your keystore files in. 48 | #*.jks 49 | #*.keystore 50 | 51 | # External native build folder generated in Android Studio 2.2 and later 52 | .externalNativeBuild 53 | .cxx/ 54 | 55 | # Google Services (e.g. APIs or Firebase) 56 | # google-services.json 57 | 58 | # Freeline 59 | freeline.py 60 | freeline/ 61 | freeline_project_description.json 62 | 63 | # fastlane 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | fastlane/readme.md 69 | 70 | # Version control 71 | vcs.xml 72 | 73 | # lint 74 | lint/intermediates/ 75 | lint/generated/ 76 | lint/outputs/ 77 | lint/tmp/ 78 | # lint/reports/ 79 | 80 | # Android Profiling 81 | *.hprof 82 | 83 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 1>&2 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 48 | echo. 1>&2 49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 50 | echo location of your Java installation. 1>&2 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 1>&2 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 62 | echo. 1>&2 63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 64 | echo location of your Java installation. 1>&2 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /app/src/main/java/org/alberto97/aodtoggle/permissions/PlatformPermissionManager.kt: -------------------------------------------------------------------------------- 1 | package org.alberto97.aodtoggle.permissions 2 | 3 | import android.annotation.TargetApi 4 | import android.content.Context 5 | import android.content.pm.IPackageManager 6 | import android.os.Build 7 | import android.permission.IPermissionManager 8 | import org.lsposed.hiddenapibypass.HiddenApiBypass 9 | import rikka.shizuku.ShizukuBinderWrapper 10 | import rikka.shizuku.SystemServiceHelper 11 | 12 | class PlatformPermissionManager { 13 | 14 | companion object { 15 | const val PACKAGE_MANAGER_SERVICE = "package" 16 | const val PERMISSION_MANAGER_SERVICE = "permissionmgr" 17 | } 18 | 19 | fun grantRuntimePermission(packageName: String, permissionName: String, userId: Int) { 20 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) 21 | return Api34Impl.grantRuntimePermission(packageName, permissionName, userId) 22 | 23 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) 24 | return Api30Impl.grantRuntimePermission(packageName, permissionName, userId) 25 | 26 | return LegacyImpl.grantRuntimePermission(packageName, permissionName, userId) 27 | } 28 | 29 | @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) 30 | object Api34Impl { 31 | private const val PERSISTENT_DEVICE_ID_DEFAULT = "default:" + Context.DEVICE_ID_DEFAULT 32 | 33 | private val permissionManager: IPermissionManager by lazy { 34 | HiddenApiBypass.addHiddenApiExemptions("Landroid/permission") 35 | IPermissionManager.Stub.asInterface( 36 | ShizukuBinderWrapper(SystemServiceHelper.getSystemService(PERMISSION_MANAGER_SERVICE)) 37 | ) 38 | } 39 | 40 | fun grantRuntimePermission(packageName: String, permissionName: String, userId: Int) { 41 | try { 42 | // Android 14 QPR3+ 43 | permissionManager.grantRuntimePermission( 44 | packageName, 45 | permissionName, 46 | PERSISTENT_DEVICE_ID_DEFAULT, 47 | userId 48 | ) 49 | return 50 | } catch (e: NoSuchMethodError) { 51 | // No-op 52 | } 53 | 54 | try { 55 | // Android 14 QPR2 56 | permissionManager.grantRuntimePermission( 57 | packageName, 58 | permissionName, 59 | Context.DEVICE_ID_DEFAULT, 60 | userId 61 | ) 62 | return 63 | } catch (e2: NoSuchMethodError) { 64 | // No-op 65 | } 66 | 67 | // Android 14 initial release 68 | permissionManager.grantRuntimePermission(packageName, permissionName, userId) 69 | } 70 | } 71 | 72 | @TargetApi(Build.VERSION_CODES.R) 73 | object Api30Impl { 74 | private val permissionManager: IPermissionManager by lazy { 75 | HiddenApiBypass.addHiddenApiExemptions("Landroid/permission") 76 | IPermissionManager.Stub.asInterface( 77 | ShizukuBinderWrapper(SystemServiceHelper.getSystemService(PERMISSION_MANAGER_SERVICE)) 78 | ) 79 | } 80 | 81 | fun grantRuntimePermission(packageName: String, permissionName: String, userId: Int) { 82 | permissionManager.grantRuntimePermission(packageName, permissionName, userId) 83 | } 84 | } 85 | 86 | object LegacyImpl { 87 | private val packageManager = IPackageManager.Stub.asInterface( 88 | ShizukuBinderWrapper(SystemServiceHelper.getSystemService(PACKAGE_MANAGER_SERVICE)) 89 | ) 90 | 91 | fun grantRuntimePermission(packageName: String, permissionName: String, userId: Int) { 92 | packageManager.grantRuntimePermission(packageName, permissionName, userId) 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /app/src/main/java/org/alberto97/aodtoggle/AodTileService.kt: -------------------------------------------------------------------------------- 1 | package org.alberto97.aodtoggle 2 | 3 | import android.Manifest 4 | import android.app.AlertDialog 5 | import android.content.pm.PackageManager 6 | import android.os.Build 7 | import android.service.quicksettings.Tile 8 | import android.service.quicksettings.TileService 9 | import android.util.Log 10 | import org.alberto97.aodtoggle.TileServiceExtensions.collapseQSPanel 11 | import org.alberto97.aodtoggle.config.AmbientDisplayConfiguration 12 | import org.alberto97.aodtoggle.config.Settings 13 | import org.alberto97.aodtoggle.permissions.GrantWriteSecureSettingsUseCase 14 | import org.alberto97.aodtoggle.permissions.ShizukuStatus 15 | import org.alberto97.aodtoggle.permissions.ShizukuUtils 16 | import rikka.shizuku.Shizuku 17 | 18 | class AodTileService : TileService() { 19 | 20 | override fun onStartListening() { 21 | super.onStartListening() 22 | 23 | val config = AmbientDisplayConfiguration() 24 | if (config.isAvailable()) { 25 | val enabled = isAodEnabled() 26 | setTileActive(enabled) 27 | } else { 28 | setTileUnavailable() 29 | } 30 | } 31 | 32 | override fun onClick() { 33 | super.onClick() 34 | 35 | if (hasPermission()) { 36 | toggleAod() 37 | } else { 38 | handleMissingPermission() 39 | } 40 | } 41 | 42 | private fun handleMissingPermission() { 43 | when (ShizukuUtils.hasPermission()) { 44 | ShizukuStatus.PERM_GRANTED -> handleShizukuPermissionGranted() 45 | ShizukuStatus.PERM_NOT_GRANTED -> requestShizukuPermission() 46 | ShizukuStatus.SERVICE_STOPPED -> showWriteSecureSettingsPermissionDialog() 47 | } 48 | } 49 | 50 | private fun requestShizukuPermission() { 51 | collapseQSPanel() 52 | Shizuku.requestPermission(0) 53 | Shizuku.addRequestPermissionResultListener { _, grantResult -> 54 | val hasPermission = grantResult == PackageManager.PERMISSION_GRANTED 55 | if (hasPermission) { 56 | handleShizukuPermissionGranted() 57 | } else { 58 | showMissingShizukuPermissionDialog() 59 | } 60 | } 61 | } 62 | 63 | private fun handleShizukuPermissionGranted() { 64 | val grantWriteSecureSettingsUseCase = GrantWriteSecureSettingsUseCase() 65 | val granted = grantWriteSecureSettingsUseCase.execute(baseContext) 66 | if (granted) { 67 | toggleAod() 68 | } else { 69 | showWriteSecureSettingsPermissionDialog() 70 | } 71 | } 72 | 73 | private fun showWriteSecureSettingsPermissionDialog() { 74 | val msg = getString( 75 | R.string.grant_write_secure_settings, 76 | this.packageName, 77 | Manifest.permission.WRITE_SECURE_SETTINGS 78 | ) 79 | val dialog = AlertDialog.Builder(this) 80 | .setMessage(msg) 81 | .setNeutralButton(android.R.string.ok, null) 82 | .create() 83 | 84 | showDialog(dialog) 85 | } 86 | 87 | private fun showMissingShizukuPermissionDialog() { 88 | val appName = getString(R.string.app_name) 89 | val msg = getString(R.string.grant_shizuku_permission, appName) 90 | val dialog = AlertDialog.Builder(this) 91 | .setMessage(msg) 92 | .setNeutralButton(android.R.string.ok, null) 93 | .create() 94 | 95 | showDialog(dialog) 96 | } 97 | 98 | private fun hasPermission(): Boolean { 99 | val writeSecureSettings = checkSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS) 100 | val granted = writeSecureSettings == PackageManager.PERMISSION_GRANTED 101 | Log.d("package", "${Manifest.permission.WRITE_SECURE_SETTINGS} granted: $granted") 102 | 103 | return granted 104 | } 105 | 106 | private fun toggleAod() { 107 | val enabled = !isAodEnabled() 108 | setAodEnabled(enabled) 109 | setTileActive(enabled) 110 | } 111 | 112 | private fun setTileUnavailable() { 113 | val tile = qsTile 114 | 115 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) 116 | tile.subtitle = getString(R.string.unsupported_device) 117 | 118 | tile.state = Tile.STATE_UNAVAILABLE 119 | tile.updateTile() 120 | } 121 | 122 | private fun setTileActive(active: Boolean) { 123 | val tile = qsTile 124 | tile.state = if (active) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE 125 | tile.updateTile() 126 | } 127 | 128 | private fun isAodEnabled(): Boolean { 129 | val enabled = try { 130 | android.provider.Settings.Secure.getInt(contentResolver, Settings.DOZE_ALWAYS_ON) == 1 131 | } catch (e: Exception) { 132 | false 133 | } 134 | Log.d("package", "AOD enabled: $enabled") 135 | return enabled 136 | } 137 | 138 | private fun setAodEnabled(state: Boolean): Boolean { 139 | val intState = if (state) 1 else 0 140 | android.provider.Settings.Secure.putInt(contentResolver, Settings.DOZE_ALWAYS_ON, intState) 141 | return isAodEnabled() 142 | } 143 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | --------------------------------------------------------------------------------