Commit e95aa90
committed
fix(privilege): stop the app-ops fallback reporting a restriction it never applied
The review of this branch found that one rung still did the thing the branch
exists to delete. `Shizuku.setAppRestricted`'s reflection fallback ended in
`reflectionRan && opReadsBackAsExpected() != false`, defended by a comment
claiming `setMode` throws when it is denied. It does not, anywhere in Thor's
range: before API 30 a package/uid mismatch met `Slog.w("Bad call: ...")` and a
null out of `getOpsRawLocked`, so `setMode` changed nothing and returned
normally; from API 30 the check throws, but from inside `verifyAndGetBypass`,
where `setMode` catches it (`Slog.e(TAG, "Cannot setMode", e); return;`). The
only refusal that ever reaches the caller is `enforceManageAppOpsModes`. So on a
denied write `reflectionRan` is true, an unreadable read-back is null, and
`true && (null != false)` reported success with nothing restricted. Flipped to
`== true`.
`reflectionRan` stays in the expression as a guard rather than as evidence: for
`restricted = false` the expected mode is MODE_ALLOWED, which is also
RUN_ANY_IN_BACKGROUND's platform default, so an op nobody ever wrote reads back
as expected and the conjunct is what keeps a throwing `setMode` from being
reported as success by the default mode alone.
The rule the two polarities follow is now stated once, at the read-back: a rung
may fail OPEN on an unreadable read-back only if it has a self-report that is
evidence independent of the read-back; with no such evidence it fails CLOSED.
Rung 1 has that evidence (`appops set` exits non-zero for an unknown package or
op) and keeps `!= false`. Rung 2 has none, because a void return is not a mode.
The clear-data sites fall out of the same rule.
Also corrected three claims this branch's own comments got wrong:
- `verifyIncomingUid` covers API 28-29 only; `checkOperation` dropped it in 30
and current AOSP passes `shouldVerifyUid = false` there explicitly. Routing
the read through the privileged binder is still right, for reasons that do
span 28..37 — `verifyIncomingPackage` from 31, and `checkOperationUnchecked`
answering `opToDefaultMode(code)` rather than throwing when its own
`verifyAndGetBypass` fails, which is worse than answering null.
- `DhizukuHelper.forceStopApp` rung 1 is not "alive". `execute` runs `am` inside
the Dhizuku app via an AIDL call to `IDhizuku.remoteProcess`, at Dhizuku's own
app uid, and `ActivityManagerService.forceStopPackage` opens on
`FORCE_STOP_PACKAGES`, which device owner does not confer — the same shape
already measured one subcommand over in this file (`am get-current-user`
denied to uid 10231). The read-back stays: it costs nothing on a rung that
short-circuits and guards the ROM that does hold the permission.
- `buildSuspendDialogInfo`'s KDoc had Shizuku's answer pasted into Dhizuku. The
suspender named there is `BuildConfig.APPLICATION_ID`, not `com.android.shell`.
Both `readBackgroundMode` KDocs now record the uid-level blind spot:
`checkOperationUnchecked` returns a uid-level mode before it reaches the package
entry, both of Thor's writes are package-level, and `checkOperationRaw` is not
the fix. Mechanism read out of AppOpsService; no uid-level writer of
RUN_ANY_IN_BACKGROUND identified, so it is recorded as a blind spot rather than
a bug.
`RootSystemGateway.forceStopApp` now keeps the `ApplicationInfo` from its last
read so the failure message can say which of `isStoppedNow`'s two falses
occurred — "could not read the package" and "it is still running" need
different fixes and were being reported as the same sentence.
Both surface tests gained a source-text sweep, because reflection is blind to an
extension function, a companion member and a `@JvmName` rename while every call
site keeps reading the same. Each sweep runs its guards first: corpus size, the
anchor file non-empty, the declaration pattern proven against a declaration
known to be present, and the extension pattern proven against its own shape.
`surfaceNames()` now unions `declaredMethods` with `methods` so moving a member
to a super-interface does not take it out of view.1 parent 3cbb43e commit e95aa90
5 files changed
Lines changed: 598 additions & 81 deletions
File tree
- app/src
- main/java/com/valhalla/thor/data
- gateway
- source/local
- dhizuku
- shizuku
- test/java/com/valhalla/thor
- data/source/local/shizuku
- domain/repository
Lines changed: 25 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
209 | 213 | | |
210 | 214 | | |
211 | 215 | | |
| |||
241 | 245 | | |
242 | 246 | | |
243 | 247 | | |
244 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
245 | 257 | | |
246 | 258 | | |
247 | 259 | | |
248 | 260 | | |
249 | 261 | | |
250 | | - | |
| 262 | + | |
251 | 263 | | |
252 | 264 | | |
253 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
254 | 276 | | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
| 277 | + | |
259 | 278 | | |
260 | 279 | | |
261 | 280 | | |
| |||
Lines changed: 63 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
184 | 184 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
192 | 211 | | |
193 | 212 | | |
194 | 213 | | |
| |||
1001 | 1020 | | |
1002 | 1021 | | |
1003 | 1022 | | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
1007 | 1033 | | |
1008 | 1034 | | |
1009 | 1035 | | |
| |||
1138 | 1164 | | |
1139 | 1165 | | |
1140 | 1166 | | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
1144 | 1189 | | |
1145 | 1190 | | |
1146 | 1191 | | |
| |||
0 commit comments