mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
fix: droiddeckctl refuses a DROIDDECK_PACKAGE that is not a package name (#896)
The value goes to the device shell inside `am start -n` and `content call --uri`. Anything but a dotted Android package name is refused before adb runs.
This commit is contained in:
1 parent
99381a8f3e
commit
0b8d55d434
2 files changed
+13
No files matched your search
@@ -26,6 +26,7 @@ from adb_device import DeviceResolutionError, resolve_serial
|
||||
# tools/release/variants.txt: the same app also ships as other packages (e.g. com.antutu.benchmark.full).
|
||||
PACKAGE = os.environ.get("DROIDDECK_PACKAGE", "com.droiddeck.launcher")
|
||||
AUTHORITY = f"content://{PACKAGE}.agent"
|
||||
PACKAGE_NAME = re.compile(r"[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)+")
|
||||
STEAM_CLIENT_APP = 769
|
||||
REQUEST_CAP = 256 * 1024
|
||||
|
||||
@@ -886,6 +887,8 @@ def main(argv: list[str] | None = None) -> int:
|
||||
args = build_parser().parse_args(argv)
|
||||
serial = None
|
||||
try:
|
||||
if not PACKAGE_NAME.fullmatch(PACKAGE): # it reaches the device shell through `am start` and `content call`
|
||||
raise ControlError(f"DROIDDECK_PACKAGE is not an Android package name: {PACKAGE!r}", "INVALID_REQUEST")
|
||||
adb = adb_path(args.adb)
|
||||
serial = resolve_serial(adb, args.serial, log=True)
|
||||
result = execute(args, adb, serial)
|
||||
|
||||
@@ -160,6 +160,16 @@ class DroiddeckctlTest(FakeAdbTest):
|
||||
started = [e["args"] for e in self.calls() if e["args"][:3] == ["shell", "am", "start"]]
|
||||
self.assertIn("com.antutu.benchmark.full/com.droiddeck.launcher.agent.AgentStartActivity", started[0])
|
||||
|
||||
def test_a_malformed_package_is_refused_before_adb(self):
|
||||
with unittest.mock.patch.dict(os.environ, {"DROIDDECK_PACKAGE": "com.example;reboot"}):
|
||||
variant = load("droiddeckctl")
|
||||
out = io.StringIO()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(io.StringIO()):
|
||||
code = variant.main(["--adb", str(self.adb), "--serial", "fake-1", "state"])
|
||||
self.assertEqual(2, code)
|
||||
self.assertEqual("INVALID_REQUEST", json.loads(out.getvalue())["error"]["code"])
|
||||
self.assertFalse(self.calls())
|
||||
|
||||
def test_state_passes_through_with_the_serial(self):
|
||||
self.configure({"state": state()})
|
||||
code, out = self.run_ctl("state")
|
||||
|
||||
Reference in new issue
Block a user