Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

fix(self-check): let the card hand a row's trip to the page, so the list survives it

booboosui8f34d1586dd2
diff --git a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt b/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt
index 38e667f..e6855c9 100644
--- a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt
+++ b/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt
@@ -1869,6 +1869,11 @@ class BodyCoreService : Service() {
* * **No `closeTyping()`.** Unlike [openSettings] there is no text field
* here, so there is no keyboard to hand back and nothing to compete for
* focus.
+ * * **It hands the trip over, it does not make it.** A row that leaves the
+ * device hands the Intent to `SelfCheckActivity.showForErrand` instead of
+ * launching it — a window cannot be left up over the destination and has
+ * no way to be told the user came back. See [onErrand] below, which is
+ * where the whole argument is.
*/
private fun openSelfCheck() {
if (selfCheck?.isShowing() == true) return
@@ -1891,25 +1896,50 @@ class BodyCoreService : Service() {
// Our own sheet, reached through the service because that is where
// it lives. Never null from here: if this method is running, we are.
onOpenSettings = { openSettings() },
- // Give the screen back to the page we are about to open. Both windows
- // here — the folded-back assistant card and this very card — are
- // TYPE_APPLICATION_OVERLAY, and an overlay outranks every Activity on
- // the device. Without this, 去下载 opened a browser underneath the
- // card that had just asked the user to look at it, and 去开启 did the
- // same to the system Settings page. The fold is the one every
- // screen.* tool call and ⤡ already perform; this is one more place
- // that needs it. See SelfCheckUi.apply for the full argument.
+ // A row is sending the user to another screen, and **this card hands
+ // the trip over rather than making it**.
//
- // The card is closed rather than hidden, because there is no honest
- // way back: the browser is not ours and reports nothing when the user
- // returns, so a card left up would sit over whatever they actually
- // came back to. Folding the assistant is what makes the way back
- // sane instead — the ball is there, and the check reopens from ✓
- // with a fresh reading, which is what the user wants after they have
- // been off changing something anyway. Closing has to come last:
- // SelfCheckUi.hide runs onDismiss from Glass.exit's completion, and
- // that is what clears [selfCheck].
- onYieldScreen = {
+ // Two facts about this card make it the wrong vehicle and the page
+ // the right one, and both were measured rather than reasoned about:
+ //
+ // * **It cannot be left up.** This card and the assistant's card
+ // behind it are both TYPE_APPLICATION_OVERLAY, and an overlay
+ // outranks every Activity on the device — a card left up sits on
+ // the Settings screen the user was just sent to use. Reported
+ // from the field as "点击去下载ADB的时候,应该退出全屏,不然挡住浏览器了".
+ // * **It cannot come back.** A window gets no `onResume`, and the
+ // destination goes out with FLAG_ACTIVITY_NEW_TASK into a task of
+ // its own, so back from Settings has nowhere of ours to return to.
+ // The user's own A/B, in one message: 「首次…逐项点击处理,回来后还是
+ // 检查项的页面。但是…点击处理,处理完退回来,就回到桌面了」 — the good
+ // half of that was the *page*, which sits in the same task as the
+ // screen it opened and is simply resumed when the user gets back.
+ //
+ // So the check changes hands: [SelfCheckActivity.showForErrand] puts
+ // the same card on a stage that can survive the trip, and the errand
+ // is launched from *there* — owned by a task that outlives the app
+ // the user is looking at. Whatever they fix, they come back to the
+ // list, and ✕ on that page is the established hand-back (see
+ // `SelfCheckActivity.onStageLeaving`: overlays back up and the
+ // assistant unfolds full size).
+ //
+ // The assistant is still folded first, and it is not optional: this
+ // window is the one covering the screen, and it has to be out of the
+ // way before a page can be seen under it. The ball also goes onto the
+ // ledge (`setPagePerched`), the same shape `openPageFrom` gives a
+ // page, so it hangs off the edge of the card instead of on top of a
+ // row — the page is a fullscreen surface and a ball parked in the
+ // middle of it is the bug that flag exists to prevent.
+ //
+ // Order matters twice. `showForErrand` first, because the page is
+ // what has to be *under* the destination and its window should be up
+ // before the card finishes sinking (the two cards are the same size
+ // in the same place, so the swap is invisible). `hide` last, because
+ // `SelfCheckUi.hide` runs `onDismiss` from `Glass.exit`'s completion
+ // and that is what clears [selfCheck].
+ onErrand = { there ->
+ window.setPagePerched(true)
+ net.kuafuai.andee.ui.SelfCheckActivity.showForErrand(this, there)
dispatcher.compactForUser()
selfCheck?.hide(yielding = true)
},
diff --git a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt
index 94dee14..1cfcf44 100644
--- a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt
+++ b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt
@@ -1,11 +1,14 @@
package net.kuafuai.andee.ui
+import android.content.Intent
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.provider.Settings
import android.widget.ImageView
+import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import net.kuafuai.andee.BodyCoreService
+import net.kuafuai.andee.R
import net.kuafuai.andee.ScreenBodyService
import net.kuafuai.andee.config.FactoryReset
import net.kuafuai.andee.config.Notebook
@@ -27,7 +30,9 @@ import net.kuafuai.andee.i18n.AppLocale
* So on a working device this Activity is never *seen*: the icon starts it, it
* hands the request to the service and finishes — see the next section. All the
* drawing it used to do lives in [SelfCheckUi] now, and what is left here is the
- * case the card cannot cover.
+ * case the card cannot cover. There is exactly one exception, and it is not a
+ * door the user opened: the card hands this page the trips it cannot carry,
+ * below.
*
* ### Why it still has to exist, and why it still has to be in the launcher
*
@@ -85,6 +90,23 @@ import net.kuafuai.andee.i18n.AppLocale
* hosts differ in exactly two things — where the card goes, and whether we may
* ask the compositor to blur — and both of those are [SelfCheckUi]'s to decide.
*
+ * ### And the carrier for the card's errands (2026-10-13)
+ *
+ * The one thing the *card* cannot do is survive a trip, so this page now comes
+ * up in the middle of a working device after all: when a row on the card sends
+ * the user to a system screen, the card hands the Intent over rather than
+ * closing the list. See [showForErrand], which is where that argument lives —
+ * including why the destination must be launched from here (it lands in *this*
+ * page's task, so back has somewhere to return to) and why a rebuilt page must
+ * not re-run it.
+ *
+ * So "on a working device this Activity is never seen" needs one amendment: it
+ * is never seen *as the assistant's app* — every open of it that the user did
+ * not ask for by hand still ends in `expand()` and `finish()` — but it is now
+ * what carries a row's trip, and the user lands on it when they come back from
+ * Settings. That is deliberate: the list is what they left, and coming back to
+ * it is the whole point.
+ *
* ### The backdrop is what makes the card's fill honest
*
* [SelfCheckUi] hands the card the *frosted* fill unconditionally when it is
@@ -124,6 +146,17 @@ class SelfCheckActivity : StageActivity() {
*/
const val EXTRA_SCREEN_CAPTURE = "screen_capture"
+ /**
+ * Start-intent extra: the screen the check card was asked to open, and
+ * could not carry itself.
+ *
+ * An `Intent` extra rather than a set of fields, because it *is* one:
+ * the card built it with `SelfCheckUi.intentFor` (the same call that
+ * decided there was anything to open) and this page must launch
+ * *that*, not a reconstruction of it. See [showForErrand].
+ */
+ private const val EXTRA_ERRAND = "errand"
+
/**
* When to look again after a resume with red rows still on the page.
*
@@ -132,6 +165,52 @@ class SelfCheckActivity : StageActivity() {
* [settleRecheck].
*/
private val SETTLE_AT_MS = longArrayOf(1_500L, 5_000L)
+
+ /**
+ * Bring this page up to carry an errand the check card cannot make
+ * itself, and open [errand] from here.
+ *
+ * ### Why the errand needs a page at all
+ *
+ * The card is a `TYPE_APPLICATION_OVERLAY`, which outranks every
+ * Activity on the device, so a card left up would sit on the Settings
+ * screen it had just sent the user to. Closing it works and **loses the
+ * list**: a window gets no `onResume`, and the destination leaves with
+ * `FLAG_ACTIVITY_NEW_TASK` into a task of its own, so pressing back has
+ * nowhere of ours to return to. The report is exact about the shape of
+ * it: from the page, 处理 → away → back lands on the list; from the
+ * card, the same three taps land on the desktop with a ball in the
+ * corner.
+ *
+ * An Activity has both properties the card lacks. It is *in the task*
+ * the destination is started into (this page passes the Intent on
+ * without `NEW_TASK`), and it gets [onResume] when the user comes back —
+ * which is also where the row they just fixed is re-read and turns
+ * green. So the trip is handed over rather than thrown away, and the
+ * user comes back to the same card, on a stage, with the same rows.
+ *
+ * ### Two traps, both paid for once already
+ *
+ * * **`NEW_TASK` is set here and nowhere else.** The caller is the
+ * service, and `startActivity` without the flag throws from a Service
+ * Context. It belongs on *this* Intent only — the errand inside must
+ * not have it, or the destination lands in a task of its own and the
+ * way back is gone again, which is the bug this whole path exists to
+ * fix.
+ * * **A re-creation must not re-open the errand.** The user is off in
+ * Settings for as long as they like and a ROM is free to rebuild this
+ * page meanwhile; re-running the errand there would throw them back
+ * into the screen they are trying to leave. [onCreate] launches it
+ * only on a fresh creation — see the `savedInstanceState` test — and
+ * drops the extra as it does, so nothing downstream can either.
+ */
+ fun showForErrand(context: android.content.Context, errand: Intent) {
+ context.startActivity(
+ Intent(context, SelfCheckActivity::class.java)
+ .putExtra(EXTRA_ERRAND, errand)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ )
+ }
}
/**
* The card. Built here on the service-off path only, placed on [stage], and
@@ -270,8 +349,17 @@ class SelfCheckActivity : StageActivity() {
// can still know that. See [SelfCheck.isPageOpen].
val checkOpen = SelfCheck.isPageOpen(this)
+ // And an errand outranks everything, because it is the one case where
+ // this page has been *asked* for: the card handed it a screen to open
+ // and the user is waiting to be sent there. Completing the icon's
+ // branches instead would expand the assistant and throw the errand away
+ // — a tap that does nothing, on the path the user just took because the
+ // list told them to. See [showForErrand].
+ val errand = intent?.getParcelableExtra<Intent>(EXTRA_ERRAND)
+ val carrying = errand != null
+
val svc = BodyCoreService.get()
- if (!restored && !checkOpen && svc != null && svc.ensureOverlays()) {
+ if (!restored && !checkOpen && !carrying && svc != null && svc.ensureOverlays()) {
svc.dispatcherForNotification()?.expand()
finish()
return
@@ -283,7 +371,7 @@ class SelfCheckActivity : StageActivity() {
// (first launch after a fresh grant). Falling through here would draw a
// checklist for a device that is working, which is the exact report
// this branch was rewritten to stop producing.
- if (!restored && !checkOpen && svc == null && ScreenBodyService.get() != null && Settings.canDrawOverlays(this)) {
+ if (!restored && !checkOpen && !carrying && svc == null && ScreenBodyService.get() != null && Settings.canDrawOverlays(this)) {
finish()
return
}
@@ -337,6 +425,40 @@ class SelfCheckActivity : StageActivity() {
ui.show()
ui.start()
revealStage()
+
+ // The trip this page was brought up to carry — see [showForErrand].
+ //
+ // After the card is up, so the page the user comes back to has already
+ // drawn itself once, and **only on a fresh creation**: a rebuild with the
+ // user in Settings carries the same Intent, and re-opening the errand
+ // there would drag them back into the screen they are leaving. The extra
+ // is dropped as it is launched rather than merely skipped, so no later
+ // reader of `intent` — this class's own [onNewIntent] included — can
+ // find an errand that has already been run.
+ if (savedInstanceState == null && errand != null) {
+ intent?.removeExtra(EXTRA_ERRAND)
+ openErrand(errand)
+ }
+ }
+
+ /**
+ * Send the user where the row asked, from *this* page's task.
+ *
+ * Deliberately no `FLAG_ACTIVITY_NEW_TASK` — see [showForErrand] for the
+ * whole argument. A failure is a toast rather than a silence, the same rule
+ * every button on this card follows, and the page stays up behind it: the
+ * list is exactly what the user wants in that case, and it is where the row
+ * is that told them to go.
+ */
+ private fun openErrand(errand: Intent) {
+ val ok = runCatching { startActivity(errand) }
+ .onFailure { android.util.Log.w("Body", "self-check errand would not launch", it) }
+ .isSuccess
+ if (!ok) {
+ runCatching {
+ Toast.makeText(this, getString(R.string.check_fix_no_screen), Toast.LENGTH_LONG).show()
+ }
+ }
}
/**
@@ -520,6 +642,16 @@ class SelfCheckActivity : StageActivity() {
super.onNewIntent(intent)
setIntent(intent)
if (intent.getBooleanExtra(EXTRA_SCREEN_CAPTURE, false)) requestScreenCapture()
+ // An errand can only arrive here if this page was already up, which is
+ // not a path the card can currently reach — it is the *other* door, and
+ // the page covers the assistant it is opened from. Handled anyway, and
+ // for the same reason the capture extra is: this class is `singleTop`,
+ // so the day something else hands it one, the alternative to this branch
+ // is a launch that silently does nothing. See [showForErrand].
+ intent.getParcelableExtra<Intent>(EXTRA_ERRAND)?.let {
+ intent.removeExtra(EXTRA_ERRAND)
+ openErrand(it)
+ }
}
override fun onResume() {
diff --git a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt
index 85d06e4..02c4f23 100644
--- a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt
+++ b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt
@@ -99,7 +99,7 @@ class SelfCheckUi(
* The card is gone — put your house in order.
*
* @param yielding true when this close is the host stepping out of the way
- * of another screen (see [onYieldScreen]), false when the user asked for
+ * of another screen (see [onErrand]), false when the user asked for
* it with ✕ or 完成. A host needs the difference, and only a host can act
* on it: a user closing the check is asking for the assistant back, while
* a yield is one step of handing the screen to somebody else and must not
@@ -110,16 +110,27 @@ class SelfCheckUi(
/** Fired when this card's own picker moved the language — see the class doc. */
private val onLocaleChanged: () -> Unit = {},
/**
- * Fired just before the user is sent to another screen, so the host can get
- * out of the way. See [apply] for the whole argument.
- *
- * Default no-op, and that is the Activity host's correct answer rather than
- * a shrug: there the card *is* an Activity, so the system draws whatever it
- * starts on top of it and there is nothing to yield. Only the window host —
- * where this card and the assistant's card behind it are both overlays —
- * has anything to do, and it is the only host that passes this.
+ * A row has picked somewhere to send the user, and this host has to say
+ * whether it can carry the trip itself.
+ *
+ * `null` — the Activity host — means "launch it from here": whatever this
+ * card starts lands on top of this page, the page is still in the task when
+ * the user comes back, and the list is simply still there for them. See
+ * [apply].
+ *
+ * Non-null means the host is an overlay and **cannot** carry it, so it takes
+ * the Intent and owes the user the list back. That is the window host, and
+ * the whole argument is in `BodyCoreService.openSelfCheck`: an overlay
+ * outranks every Activity on the device, so this card would sit on the
+ * Settings screen it just asked the user to go and use, and a window gets no
+ * `onResume` to notice them coming back. It hands the trip to
+ * [SelfCheckActivity] instead of throwing the list away.
+ *
+ * Renamed from `onYieldScreen` with the fix: "yield" described the card
+ * getting out of the way, which was never the part that needed deciding —
+ * what the caller does *next* is. See `SelfCheckActivity.showForErrand`.
*/
- private val onYieldScreen: () -> Unit = {},
+ private val onErrand: ((Intent) -> Unit)? = null,
/** Non-null ⇒ that host places the card and this class owns no window. */
private val host: FrameLayout? = null,
) {
@@ -292,15 +303,15 @@ class SelfCheckUi(
* then believes no card is up while one is on screen.
*
* Narrow either way, but this change widened it: `hide()` no longer comes
- * only from a user pressing ✕ — [onYieldScreen] has the host close the card
- * on the way out to the browser. Fold, reopen the check, and the stale exit
+ * only from a user pressing ✕ — [onErrand] has the host close the card on
+ * the way out to the browser. Fold, reopen the check, and the stale exit
* would land after the second card was up.
*
* ### [yielding], and why the caller has to say
*
* The two closes look identical from in here and mean opposite things out
* there, so the one caller that knows which it is passes it: ✕ and 完成
- * close with the default, and [onYieldScreen]'s host closes with `true`.
+ * close with the default, and [onErrand]'s host closes with `true`.
* The distinction exists because of what the *host* does with it — see
* [onDismiss] — and it cannot be inferred here, because the fold that
* accompanies a yield is the host's own doing and is already in flight by
@@ -809,7 +820,7 @@ class SelfCheckUi(
/**
* Every fix is a `startActivity` — nothing here closes a gap by itself.
*
- * ### The card gets out of the way first, and why it has to
+ * ### The card cannot make this trip, and that has to be decided here
*
* In the window host this card is a `TYPE_APPLICATION_OVERLAY` sized to 98%
* × 96% of the display, and **an overlay outranks every Activity on the
@@ -820,69 +831,75 @@ class SelfCheckUi(
* wrong — they are ordinary Activities and they do come up. They just come up
* behind us.
*
- * So every door but one tells the host to yield first — see
- * [onYieldScreen]. It is deliberately *every* door and not just the browser:
- * 去开启 and 允许 are the same mistake against the same kind of window, and
- * fixing only the one that got reported would leave two dead buttons behind
- * a live one.
- *
- * [SelfCheck.Fix.OurSettings] is the exception, and it is the reason the
- * yield is here and not in [launch]: that sheet is an overlay of ours too,
- * and the design is that it comes up **over** this card so the list is still
- * behind it to return to. Yielding for it would close the card the user is
- * meant to come back to.
- *
- * The card itself is not closed here — delivering the yield is the host's
- * job, because only the host knows whether there is anything to close. On
- * the Activity host there is not: that card *is* an Activity, so whatever it
- * starts is drawn on top of it by the system already. See [onYieldScreen].
+ * ### Yielding was half the fix, and the missing half was reported as this
+ *
+ * The card was then closed and the assistant folded to the ball before the
+ * destination was launched, which cleared the screen correctly and **lost the
+ * list**: a window gets no `onResume`, and the destination went out with
+ * `FLAG_ACTIVITY_NEW_TASK` into a task of its own, so back from the Settings
+ * screen had nowhere to return to and dropped the user on the launcher with
+ * a ball in the corner. The user's own comparison, and it is the one to
+ * satisfy: on the device where the check is the *page* (no assistant yet,
+ * first install) a row's 处理 sends them to Settings and coming back lands
+ * on the list — so that has to be true from the card too:
+ * 「点处理,处理完退回来,就回到桌面了」.
+ *
+ * The fix is [onErrand]: the host that cannot survive the trip is asked to
+ * take the Intent, and the one that can leave the per-row decision alone.
+ * `launch` below is therefore the *Activity* host's path — the card's starts
+ * nothing itself any more.
+ *
+ * [SelfCheck.Fix.OurSettings] is the exception and the reason this is not one
+ * loop over every fix: that sheet is an overlay of ours, drawn **over** this
+ * card so that the list is still behind it to return to. Handing that trip
+ * away would close the card the user is meant to come back to — see
+ * `BodyCoreService.openSelfCheck`.
*/
private fun apply(f: SelfCheck.Finding) {
- val fix = f.fix
- if (fix !is SelfCheck.Fix.OurSettings) {
- // Only if there is somewhere to go. Yielding and failing is the one
- // outcome with nothing on screen: the card is gone and so is the
- // page it promised. Cheap to rule out — see [openable] — and this is
- // not hypothetical, a HONOR really has Settings screens with no
- // Activity behind the action.
- if (!openable(fix)) {
- toastNoScreen()
- return
- }
- onYieldScreen()
- }
- when (fix) {
- // Both of these leave the device, and both are already spelled out by
- // [intentFor] — the same call [openable] asked, so what was checked
- // and what gets launched can never be two different Intents. 去下载
- // is the link: a browser, not Settings, and the user comes back
- // through wherever they were with 重新检查 to tell them whether it
- // took.
- is SelfCheck.Fix.Screen, is SelfCheck.Fix.Link -> launch(intentFor(fix))
-
- is SelfCheck.Fix.Grant -> launch(
- Intent(context, PermissionRequestActivity::class.java)
- .putExtra("permissions", fix.permissions.toTypedArray())
- )
-
+ when (val fix = f.fix) {
is SelfCheck.Fix.OurSettings -> onOpenSettings?.invoke()
+ // The three that leave us, under one roof because they are one
+ // decision: the destination is spelled out by [intentFor] (the same
+ // call [openable] asked, so what was checked and what gets launched
+ // can never be two different Intents), and who launches it depends
+ // only on whether the host can come back from it.
+ is SelfCheck.Fix.Screen, is SelfCheck.Fix.Link, is SelfCheck.Fix.Grant -> {
+ // Only if there is somewhere to go. Leaving and failing is the
+ // one outcome with nothing on screen: the card is gone and so
+ // is the page it promised. Cheap to rule out — see [openable] —
+ // and this is not hypothetical, a HONOR really has Settings
+ // screens with no Activity behind the action.
+ if (!openable(fix)) {
+ toastNoScreen()
+ return
+ }
+ val there = intentFor(fix)
+ onErrand?.let { hand -> hand(there); return }
+ launch(there)
+ }
+
is SelfCheck.Fix.Adb, SelfCheck.Fix.Nothing -> Unit
}
}
/**
* Whether [fix] has an Activity on this device at all — asked **before**
- * [onYieldScreen] closes the card, so the two can never disagree.
+ * anything is closed or handed over, so the two can never disagree.
*
* Everything this card cannot open is either its own ([Fix.OurSettings],
* [Fix.Grant]) or has nothing to open ([Fix.Adb], [Fix.Nothing]), so only
- * the two that leave the device are worth asking about.
+ * the two that leave the device are worth asking about. `Grant` counts as
+ * ours and not as a query: `PermissionRequestActivity` is in *this* APK, so
+ * a `queryIntentActivities` for it would answer about a component that is
+ * guaranteed to be there — the honest question for that row is whether the
+ * user grants it, which is the dialog's job.
*
* `queryIntentActivities` rather than `resolveActivity`: the stricter call
* wants a default-browsing handler, and a device with several browsers and
* no default set would read as "nowhere to go" for 去下载 — refusing to
- * yield on the very button this exists to serve. When the query itself
+ * send the user out on the very button this exists to serve. When the query
+ * itself
* fails the answer is `true`: that defers to [launch]'s own failure toast,
* which is the honest fallback rather than a second guess.
*/
@@ -898,14 +915,16 @@ class SelfCheckUi(
}
/**
- * The Intent [apply] will hand to [launch]; one definition, asked twice.
- *
- * Only the two that leave the device are spelled out. The `else` is an empty
- * Intent rather than a throw because no caller reaches it — [apply] routes
- * the other three fixes to their own branches and [openable] short-circuits
- * before asking — but an empty Intent resolving to nothing reads as "no
- * Activity for a fix that never wanted one", while a throw here would take
- * the card down for a case that cannot happen.
+ * The Intent [apply] will hand over or launch; one definition, asked twice.
+ *
+ * The three that leave us are spelled out, [Fix.Grant] included: its
+ * destination is `PermissionRequestActivity` — ours, and an Activity, which
+ * is exactly why it belongs here rather than in a branch of its own. The
+ * `else` is an empty Intent rather than a throw because no caller reaches
+ * it — [apply] routes the other two fixes to their own branches and
+ * [openable] short-circuits before asking — but an empty Intent resolving to
+ * nothing reads as "no Activity for a fix that never wanted one", while a
+ * throw here would take the card down for a case that cannot happen.
*/
private fun intentFor(fix: SelfCheck.Fix): Intent = when (fix) {
is SelfCheck.Fix.Screen -> Intent(fix.action).apply {
@@ -915,6 +934,9 @@ class SelfCheckUi(
is SelfCheck.Fix.Link -> Intent(Intent.ACTION_VIEW, Uri.parse(fix.url))
+ is SelfCheck.Fix.Grant -> Intent(context, PermissionRequestActivity::class.java)
+ .putExtra("permissions", fix.permissions.toTypedArray())
+
else -> Intent()
}
@@ -937,16 +959,20 @@ class SelfCheckUi(
* rule this whole card is built on. So the failure gets a voice.
*
* This is the second line of defence, not the first: [openable] already
- * refuses to yield when there is nowhere to go. It still has to exist,
+ * refuses to leave when there is nowhere to go. It still has to exist,
* because the check and the launch are separated by the card's exit
* animation — long enough for the answer to change. And unlike
* [openable]'s refusal, this one arrives after the card is gone, so the
* toast is the only thing left to say.
+ *
+ * **Only the Activity host reaches this now.** The window host hands the
+ * Intent to [onErrand] and never launches anything itself, so the `host ==
+ * null` test below is not a branch any more — a Service Context still needs
+ * the flag, and an Activity must not have it (it would put somebody else's
+ * settings screen in a task of its own, which is also what used to make the
+ * way back impossible).
*/
private fun launch(intent: Intent) {
- // Only when there is no Activity of ours in play: from a Service Context
- // the flag is mandatory, and from an Activity it would put somebody
- // else's settings screen in a task of its own.
if (host == null) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val ok = runCatching { context.startActivity(intent) }.onFailure {
Log.w(TAG, "self-check: no activity for ${intent.action}", it)