Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto
gradlew text eol=lf
*.bat text eol=crlf
*.jar binary
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
pull_request:
push:
branches: [master]

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: 21

- uses: gradle/actions/setup-gradle@v5

- name: Unit tests, lint and debug build
run: ./gradlew testDebugUnitTest lintDebug assembleDebug

- name: Upload test and lint reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: reports
path: app/build/reports/
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Release

# Push a version tag to publish a signed APK, for example:
# git tag v1.2.0 && git push origin v1.2.0
on:
push:
tags: ["v*.*.*"]

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: 21

- uses: gradle/actions/setup-gradle@v5

- name: Decode release keystore
env:
KEYSTORE_BASE64: ${{ secrets.RELEASE_KEYSTORE_BASE64 }}
run: |
if [ -z "$KEYSTORE_BASE64" ]; then
echo "::error::Secret RELEASE_KEYSTORE_BASE64 is not set. See README, section Releases."
exit 1
fi
echo "$KEYSTORE_BASE64" | base64 --decode > "$RUNNER_TEMP/release.jks"

- name: Test and build signed APK
env:
SIGNING_STORE_FILE: ${{ runner.temp }}/release.jks
SIGNING_STORE_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ vars.RELEASE_KEY_ALIAS || 'rrgmc' }}
SIGNING_KEY_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
run: ./gradlew testDebugUnitTest lintDebug assembleRelease -PappVersion="${GITHUB_REF_NAME#v}"

- name: Publish GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
apk="android-dev-settings-${GITHUB_REF_NAME}.apk"
cp app/build/outputs/apk/release/app-release.apk "$apk"
gh release create "$GITHUB_REF_NAME" "$apk" --title "$GITHUB_REF_NAME" --generate-notes

- name: Remove keystore
if: always()
run: rm -f "$RUNNER_TEMP/release.jks"
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.gradle/
build/
local.properties
.idea/
*.iml
.kotlin/
captures/
.cxx/
112 changes: 110 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,110 @@
# android-dev-settings
android-dev-settings
# Android Dev Settings

An Android app that toggles the developer settings I use most, without opening Developer options:

- USB debugging
- Wireless debugging
- Stay awake while charging (AC, USB and wireless)
- Keep screen on for a chosen time, charging or not

The app is for my own phones. It is not published on the Play Store. It needs Android 11 (API 30) or later.

## Build

Requirements: JDK 17 or later, and the Android SDK with platform 36. Put the SDK path in
`local.properties` (`sdk.dir=...`) or in the `ANDROID_HOME` environment variable.

```bash
./gradlew assembleDebug
```

The APK is `app/build/outputs/apk/debug/app-debug.apk`. Install it with:

```bash
adb install -r app/build/outputs/apk/debug/app-debug.apk
```

Run the unit tests and lint with:

```bash
./gradlew testDebugUnitTest lintDebug
```

## Grant the permission

Changing these settings needs `android.permission.WRITE_SECURE_SETTINGS`. Only a computer can grant it, and
only once per installation:

1. Turn on USB debugging in Developer options and connect the phone to the computer.
2. Run:

```bash
adb shell pm grant com.rangelreale.devsettings android.permission.WRITE_SECURE_SETTINGS
```

Until the permission is granted, the main screen shows a setup card with this command and a copy button, and every
switch stays disabled. The app notices the grant within a few seconds. It needs neither root nor Shizuku.

Developer options must be on for the settings to have effect. When they are off, the main screen explains how to
turn them on: open About phone and tap Build number seven times.

## Main screen

Each row shows the setting, its current value and a switch. Values come from the system on every resume and
through a content observer, so changes made in system Settings appear at once.

- Turning off USB or wireless debugging asks for confirmation, because a connected computer loses its connection.
- When wireless debugging is on, the screen shows the phone's address and port for `adb connect`, with a copy
button. The port is found through the `service.adb.tls.port` property or, failing that, mDNS.
- The first time wireless debugging is turned on for a Wi-Fi network, Android asks whether to allow that network.
- "Open wireless debugging (pairing)" opens Developer options with the wireless debugging row highlighted. Tap the
row title to reach pairing. Android has no public intent for the pairing screen itself.
- "Open Developer options" opens the system Developer options screen.

## Quick Settings tiles

Add the tiles from the Quick Settings edit screen. Every tile shows the real system state, and a long press opens
the app. Without the permission, a tile shows "Setup needed" and a tap opens the app on the setup card. (Android
does not deliver taps to tiles in the unavailable state, so these tiles stay inactive instead.)

| Tile | Tap |
| --- | --- |
| USB debugging | Turns USB debugging on or off. On a locked phone, it asks to unlock first. |
| Wireless debugging | Turns wireless debugging on or off. On a locked phone, it asks to unlock first. |
| Stay awake | Turns stay awake while charging on (AC, USB and wireless) or off. |
| Keep screen on | Moves to the next step: 5 min, 15 min, 30 min, 1 hour, until stopped, off. Each step restarts the countdown. The subtitle shows the time left. |

Tiles do not ask for confirmation.

## Keep screen on

A foreground service holds a screen wake lock. Its ongoing notification counts down the time left and has a Stop
action. On Android 13 and later, the app asks for notification permission the first time; without it, the screen
still stays on but the notification is hidden. The power button still turns the screen off.

## Releases

CI runs on every pull request and every push to `master`: unit tests, lint and a debug build
(`.github/workflows/ci.yml`).

Pushing a tag such as `v1.2.0` runs `.github/workflows/release.yml`. It tests, builds an APK signed with the
release key, and publishes it as a GitHub release. The version name comes from the tag (`1.2.0`) and the version
code is `major * 10000 + minor * 100 + patch`.

```bash
git tag v1.2.0
git push origin v1.2.0
```

The release workflow needs two repository secrets:

| Secret | Value |
| --- | --- |
| `RELEASE_KEYSTORE_BASE64` | The keystore file, base64-encoded. |
| `RELEASE_KEYSTORE_PASSWORD` | The keystore password. It is also used as the key password. |

The key alias defaults to `rrgmc`. Set the repository variable `RELEASE_KEY_ALIAS` to use another one.

To build a signed release locally, set `SIGNING_STORE_FILE`, `SIGNING_STORE_PASSWORD`, `SIGNING_KEY_ALIAS` and
`SIGNING_KEY_PASSWORD`, then run `./gradlew assembleRelease -PappVersion=1.2.0`. Without these variables, release
builds are signed with the debug key.
83 changes: 83 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
}

// Release CI passes the tag without its "v" prefix: -PappVersion=1.2.3
val appVersion = providers.gradleProperty("appVersion").orNull ?: "0.1.0"
val appVersionCode = appVersion.substringBefore('-').split('.').map { it.toInt() }
.let { (major, minor, patch) -> major * 10_000 + minor * 100 + patch }

// Release signing comes from environment variables. Without them, release builds use the debug key.
val releaseStoreFile: String? = System.getenv("SIGNING_STORE_FILE")

android {
namespace = "com.rangelreale.devsettings"
compileSdk = 36

defaultConfig {
applicationId = "com.rangelreale.devsettings"
minSdk = 30
targetSdk = 36
versionCode = appVersionCode
versionName = appVersion
}

signingConfigs {
if (releaseStoreFile != null) {
create("release") {
storeFile = file(releaseStoreFile)
storePassword = System.getenv("SIGNING_STORE_PASSWORD")
keyAlias = System.getenv("SIGNING_KEY_ALIAS")
keyPassword = System.getenv("SIGNING_KEY_PASSWORD")
}
}
}

buildTypes {
release {
isMinifyEnabled = false
signingConfig = signingConfigs.findByName("release") ?: signingConfigs.getByName("debug")
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

buildFeatures {
compose = true
}

lint {
// targetSdk 36 and the tool and library versions are pinned on purpose; newer ones need compileSdk 37.
// These checks also look up versions online, so their result would change as new releases appear.
disable += setOf("OldTargetApi", "GradleDependency", "AndroidGradlePluginVersion", "NewerVersionAvailable")
warningsAsErrors = true
}
}

kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.activity.compose)
implementation(libs.kotlinx.coroutines.android)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.compose.material3)
debugImplementation(libs.androidx.compose.ui.tooling)

testImplementation(libs.junit)
}
Loading
Loading