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
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Gives Android's lock screen robotOS's cover (ui/LockScreenLook). -->
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<!-- The idle Wi-Fi cut fires on time even in Doze. -->
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/dev/r1ptt/PttService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class PttService : Service() {
app.radio.applyBaseline()
DeviceSettings.apply(app.store.value)
app.battery.record(this, "service_start")
kotlin.concurrent.thread(name = "lock-look") { runCatching { dev.r1ptt.ui.LockScreenLook.applyOnce(app) } }
TurnMetrics.event("service_started")
}

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/dev/r1ptt/ui/DeviceActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ open class DeviceActivity : Activity() {
// A restricted R1 can be rung by its owner at any time; otherwise offer this only while
// ringing. The side button also stops ringing.
val ringing = hub.quarantined || hub.management.ringing
// With an Android PIN the owner can open robotOS while the host can't be reached; never when restricted.
// With an Android screen lock the owner can open robotOS while the host can't be reached; never when restricted.
val ownerPin = !hub.quarantined && getSystemService(android.app.KeyguardManager::class.java).isDeviceSecure
val key = listOf(label, detail, identity.optString("return_message"), identity.optBoolean("secure_lock_applied"),
hub.canReenroll, ringing, ownerPin).joinToString("\u0000")
Expand Down Expand Up @@ -175,7 +175,7 @@ open class DeviceActivity : Activity() {
else "robotOS is restricted. A secure Android screen lock is not active through robotOS; this does not lock other Android apps or protect against physical system access."))
}
page.body.addView(ui.button("Check recovery status", primary = true) { hub.recoverNow() })
if (ownerPin) page.body.addView(ui.button("Open with this R1's PIN") { launchOwnerPin() })
if (ownerPin) page.body.addView(ui.button("Open with your screen lock") { launchOwnerPin() })
page.body.addView(ui.button("Connect to a network") {
startActivity(android.content.Intent(android.provider.Settings.Panel.ACTION_INTERNET_CONNECTIVITY))
})
Expand All @@ -193,11 +193,11 @@ open class DeviceActivity : Activity() {
gatePage?.fade(!covering, smooth)
}

/** Android's own PIN screen, with its guess limits; robotOS never sees or stores the PIN. */
/** Android's own screen-lock confirmation, with its guess limits; robotOS never sees or stores it. */
@Suppress("DEPRECATION")
private fun launchOwnerPin() {
val intent = getSystemService(android.app.KeyguardManager::class.java).createConfirmDeviceCredentialIntent(
"Open robotOS", "Enter this R1's PIN. robotOS checks with your host as soon as it can.") ?: return
"Open robotOS", "Confirm your screen lock. robotOS checks with your host as soon as it can.") ?: return
startActivityForResult(intent, OWNER_PIN)
}

Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/dev/r1ptt/ui/LockScreenLook.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dev.r1ptt.ui

import android.app.WallpaperManager
import android.content.Context
import android.graphics.Bitmap
import android.view.WindowManager
import dev.r1ptt.data.EventLog

/**
* Android's lock screen wears robotOS's recovery cover: the robot mark glowing on black, so swiping
* up to unlock looks like swiping the cover away. Applied once per design version, so a wallpaper
* the owner picks later is never replaced.
*/
object LockScreenLook {
private const val VERSION = 1

fun applyOnce(
context: Context,
// Home too, so any glimpse of the wallpaper while unlocking matches.
wear: (Bitmap) -> Unit = { WallpaperManager.getInstance(context).setBitmap(it, null, true, WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM) },
) {
val prefs = context.getSharedPreferences("look", Context.MODE_PRIVATE)
if (prefs.getInt("lock_wallpaper", 0) >= VERSION) return
val screen = context.getSystemService(WindowManager::class.java).maximumWindowMetrics.bounds
val picture = LogoGlow.still(context, screen.width(), screen.height())
wear(picture)
prefs.edit().putInt("lock_wallpaper", VERSION).apply()
EventLog.record("lock screen: robotOS cover applied")
}
}
19 changes: 18 additions & 1 deletion app/src/main/java/dev/r1ptt/ui/Widgets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ class LogoGlow(context: Context) : View(context) {
override fun onDraw(canvas: Canvas) {
val t = if (animator.isRunning) animator.animatedValue as Float else 0f
// Starts dim and swells, so the glow rises as the cover appears.
val glow = (sin(2 * PI * (t - .25f)) * .5 + .5).toFloat()
drawLogo(canvas, (sin(2 * PI * (t - .25f)) * .5 + .5).toFloat())
}

private fun drawLogo(canvas: Canvas, glow: Float) {
val cx = width / 2f
val cy = height / 2f
halo.alpha = (70 + 185 * glow).toInt()
Expand Down Expand Up @@ -219,6 +222,20 @@ class LogoGlow(context: Context) : View(context) {
animate().translationX(dx * far).translationY(dy * far).alpha(0f).setDuration(200)
.withEndAction { onSwiped?.invoke() }.start()
}

companion object {
/** The cover at full glow as a picture, for Android's lock screen ([LockScreenLook]). */
fun still(context: Context, width: Int, height: Int): Bitmap {
val logo = LogoGlow(context)
logo.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY))
logo.layout(0, 0, width, height)
return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888).also { picture ->
val canvas = Canvas(picture)
canvas.drawColor(context.getColor(R.color.bg))
logo.drawLogo(canvas, 1f)
}
}
}
}

/** Three dots for "working" or four bars for "speaking". Moves only while it is actually shown. */
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/dev/r1ptt/workspace/HubSettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ class HubSettingsActivity : DeviceActivity() {
})
}
body.addView(ui.button("Android location settings") { startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) })
permission("secure_lock", "Allow secure remote lock", "With your permission, lost or revoked status automatically requests Android secure lock whenever a PIN/password and active device admin are available. Enabling Android security later automatically strengthens recovery protection. Without them robotOS restricts its own screens and actions; other Android apps remain accessible.")
permission("secure_lock", "Allow secure remote lock", "With your permission, lost or revoked status automatically requests Android secure lock whenever an Android screen lock and active device admin are available. Enabling Android security later automatically strengthens recovery protection. Without them robotOS restricts its own screens and actions; other Android apps remain accessible.")
val security = hub.management.security()
body.addView(ui.note(if (security.optBoolean("secure_lock_available")) "Protection: robotOS restriction and Android secure lock."
else "Protection: robotOS restriction. Android secure lock requires the permission above, remote management, an Android PIN/password and device admin."))
else "Protection: robotOS restriction. Android secure lock requires the permission above, remote management, an Android screen lock (PIN, pattern or password) and device admin."))
body.addView(ui.button("Enable Android device admin") {
startActivity(Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN).putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
android.content.ComponentName(this, dev.r1ptt.sys.AdminReceiver::class.java)))
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/dev/r1ptt/workspace/WorkspaceClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ class WorkspaceClient(private val app: App) {
recoverNow()
}
/**
* The owner confirmed this R1's Android PIN on the recovery screen. It opens like a passing check,
* The owner confirmed Android's screen lock on the recovery screen. It opens like a passing check,
* grace included. A restricted R1 stays restricted, and the host's next answer still applies:
* a lost reply takes the screen back at once.
*/
fun confirmedByOwner() {
if (!identity.paired || quarantined || !recoveryPending) return
recoveryConfirmed(recoveryTicket())
mutable.value = "Opened with this R1's PIN · checking with your host when it can"
EventLog.record("recovery: opened with the owner's Android PIN")
mutable.value = "Opened with your screen lock · checking with your host when it can"
EventLog.record("recovery: opened with the owner's screen lock")
dev.r1ptt.ui.DeviceActivity.refreshRecovery(app)
}
/** Screen off or network lost: a fresh R1 stays open for its next wake; otherwise fence now. */
Expand Down
27 changes: 27 additions & 0 deletions app/src/test/java/dev/r1ptt/ui/LockScreenLookTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.r1ptt.ui

import android.graphics.Bitmap
import dev.r1ptt.App
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], application = App::class)
class LockScreenLookTest {
private val app get() = RuntimeEnvironment.getApplication() as App

/** Applied once, so a wallpaper the owner picks afterwards is never replaced. */
@Test fun theLockScreenGetsTheCoverOnce() {
val worn = mutableListOf<Bitmap>()
LockScreenLook.applyOnce(app) { worn += it }
LockScreenLook.applyOnce(app) { worn += it }
assertEquals(1, worn.size)
val screen = app.getSystemService(android.view.WindowManager::class.java).maximumWindowMetrics.bounds
assertEquals(screen.width(), worn.single().width)
assertEquals(screen.height(), worn.single().height)
}
}
10 changes: 10 additions & 0 deletions app/src/test/java/dev/r1ptt/ui/ScreensSnapshotTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ class ScreensSnapshotTest {
File(out, "app-icon.png").outputStream().use { assertTrue(bitmap.compress(Bitmap.CompressFormat.PNG, 100, it)) }
}

/** Android's lock screen wears the recovery cover at full glow, black at the edges like the cover. */
@Test fun lockScreenWearsTheCover() {
val still = LogoGlow.still(app, 480, 640)
File(out, "lock-screen.png").outputStream().use { assertTrue(still.compress(Bitmap.CompressFormat.PNG, 100, it)) }
assertEquals(app.getColor(R.color.bg), still.getPixel(5, 5))
val markTop = (640 - (480 * .42f).toInt()) / 2
val glow = still.getPixel(240, markTop - 6)
assertTrue("orange glow just above the mark", Color.red(glow) > Color.blue(glow) + 40)
}

@Test fun recoveryOpensOnTheGlowingLogo() {
// Robolectric runs an endless animation's frames back to back, which would race the clock
// past the logo; a paused choreographer draws frames only as the test advances time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ class RecoveryProtectionTest {
}

private fun pinButton(activity: DeviceActivity) =
activity.window.decorView.find(TextView::class.java).firstOrNull { it.text == "Open with this R1's PIN" }
activity.window.decorView.find(TextView::class.java).firstOrNull { it.text == "Open with your screen lock" }

/** With an Android PIN, the owner can open an R1 whose host can't be reached (#45), using Android's own PIN screen. */
@Test fun theOwnersAndroidPinOpensAnUnverifiedR1() {
Expand All @@ -629,7 +629,7 @@ class RecoveryProtectionTest {
assertFalse(app.workspace.blocked)
assertTrue(app.workspace.networkAllowed)
assertEquals(View.VISIBLE, activity.findViewById<View>(android.R.id.content).visibility)
assertTrue(dev.r1ptt.data.EventLog.lines().any { it.endsWith("recovery: opened with the owner's Android PIN") })
assertTrue(dev.r1ptt.data.EventLog.lines().any { it.endsWith("recovery: opened with the owner's screen lock") })
controller.pause().stop().destroy()
}

Expand Down
13 changes: 7 additions & 6 deletions docs/HUB.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,13 @@ Protection adapts to the security features actually enabled on the R1. Without a
credential, robotOS restricts its own screens and action entry points; this does not lock Android
or prevent access through other apps, debugging or a modified operating system. With a secure
credential, active device admin and locally enabled management, lost mode can also request an
Android lock. A secure credential is the recommended setup ([INSTALL.md](INSTALL.md#lock-it-with-a-pin)):
Android's PIN encrypts the R1's data and limits guessing, which robotOS's own screens cannot do.
While Android is locked the button only wakes the lock screen. When the host can't confirm a wake,
the recovery screen can open robotOS with Android's own PIN confirmation; robotOS never stores the
PIN, and a lost, revoked or cleared R1 stays restricted. robotOS turns the screen off with the
sleep key, not device admin's immediate lock, so Android's "lock after screen timeout" applies. Capability checks refresh when robotOS resumes and reports its state, so enabling
Android lock. A secure credential is the recommended setup ([INSTALL.md](INSTALL.md#lock-it-with-a-screen-lock)):
an Android PIN, pattern or password encrypts the R1's data and limits guessing, which robotOS's own
screens cannot do. While Android is locked the button only wakes the lock screen. When the host
can't confirm a wake, the recovery screen can open robotOS with Android's own confirmation of the
screen lock; robotOS never stores it, and a lost, revoked or cleared R1 stays restricted. robotOS
turns the screen off with the sleep key, not device admin's immediate lock, so Android's "lock after
screen timeout" applies. Capability checks refresh when robotOS resumes and reports its state, so enabling
those protections locally does not require re-enrollment. No local permission is silently granted.
The console reports app restrictions, secure credential availability, remote-lock support and
device-reported lock application separately, together with the last connection time. A lock
Expand Down
53 changes: 37 additions & 16 deletions docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ The script makes these changes:
- Grants the app root.
- Makes the app the home screen.
- Preserves the existing lock screen and device-admin state; provisioning grants neither. See
[Lock it with a PIN](#lock-it-with-a-pin) below.
[Lock it with a screen lock](#lock-it-with-a-screen-lock) below.
- Sets a 15 s screen timeout and low brightness.
- Turns on Android's dark theme, colored from the R1's orange, so Android's own screens and the
keyboard match robotOS.
Expand Down Expand Up @@ -186,25 +186,46 @@ Work through these with the R1 on USB:
8. **Battery.** Unplug the R1 overnight, then plug it in and run `tools/battery-report.sh`. See
[BATTERY.md](BATTERY.md).

## Lock it with a PIN
## Lock it with a screen lock

Recommended. Only Android's own lock protects the R1's data: with a PIN, its storage is encrypted
with a key tied to the PIN, and Android limits how fast anyone can guess. robotOS's recovery cover
is not a lock; it can be bypassed through debugging, safe mode or other Android screens.
Recommended. Only Android's own screen lock protects the R1's data: with a PIN, pattern or
password, the R1's storage is encrypted with a key tied to it, and Android limits how fast anyone
can guess. robotOS's recovery cover is not a lock; it can be bypassed through USB debugging, safe
mode or other Android screens.

1. In robotOS, open **Settings → Host & devices**, tap **Configure Android screen lock**, and choose
**PIN**.
2. On the same Android screen, open the screen lock's settings (the gear). Set **Lock after screen
timeout** to **15 minutes**, which matches robotOS's recovery grace, and turn **Power button
instantly locks** off. A wake within 15 minutes then opens at once; a longer one asks for the PIN.
**PIN**, **Pattern** or **Password**. A PIN of six or more digits is the strongest choice that's
comfortable on the R1's small screen. A pattern is quicker but easier to guess from smudges or
over your shoulder.
2. On the same Android screen, open the screen lock's settings (the gear):
- **Lock after screen timeout:** **5 minutes**. A wake within 5 minutes opens at once; a later
one asks for your screen lock. A longer delay is more convenient but gives someone who picks
up the R1 longer to get in. There's no point going past 15 minutes, robotOS's recovery grace.
- **Power button instantly locks:** off. The R1's button is its power button, and robotOS's
tap-to-sleep counts as a press, so leaving this on locks the R1 on every tap.
3. Back in **Host & devices**, turn on **Allow remote management** and **Allow secure remote
lock**, then tap **Enable Android device admin** and activate it. Marking the R1 lost on your host
now locks Android too.

While Android is locked, the button does nothing but wake the lock screen (it still silences a
ringing R1), so nobody can talk to Hermes without the PIN. If your host can't be reached, the
recovery screen offers **Open with this R1's PIN**, which uses Android's own PIN screen; robotOS
never sees or stores the PIN. It never opens an R1 the host has marked lost or revoked.
lock**, then tap **Enable Android device admin** and choose **Activate**. Marking the R1 lost on
your host then locks Android too. robotOS uses device admin only to lock the screen; you can turn
it off in Android's **Settings → Security → Device admin apps**.

**Check it worked:** **Host & devices** shows "Protection: robotOS restriction and Android secure
lock". If it shows only "robotOS restriction", one of the three steps is missing.

What changes:
- Android's lock screen shows robotOS's glowing mark on black, like the recovery cover, so swiping
up to unlock looks like swiping the cover away. robotOS sets this wallpaper once. If you pick
another in Android's settings, robotOS leaves it alone.
- A wake within the lock delay opens at once. A later one asks for your screen lock first.
- While Android is locked, the button only wakes the lock screen; it still silences a ringing R1.
Nobody can talk to Hermes, which can send texts, without your screen lock.
- If your host can't be reached, the recovery screen offers **Open with your screen lock**. It uses
Android's own confirmation, so robotOS never sees or stores your PIN, pattern or password. It
never opens an R1 your host has marked lost, revoked or cleared.

**Limits:** robotOS runs on an R1 with an unlocked bootloader and root. A screen lock keeps the data
encrypted from someone who finds or reboots the R1. A determined attacker with the device and time
could still modify the system to capture your screen lock the next time you use it. If an R1 goes
missing, mark it lost or revoke it on your host.

## Troubleshooting

Expand Down
Loading
Loading