phoneview 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. phoneview-1.0.0/LICENSE +201 -0
  2. phoneview-1.0.0/PKG-INFO +317 -0
  3. phoneview-1.0.0/README.md +280 -0
  4. phoneview-1.0.0/pyproject.toml +56 -0
  5. phoneview-1.0.0/setup.cfg +4 -0
  6. phoneview-1.0.0/src/phoneview/__init__.py +2 -0
  7. phoneview-1.0.0/src/phoneview/__main__.py +3 -0
  8. phoneview-1.0.0/src/phoneview/android/__init__.py +0 -0
  9. phoneview-1.0.0/src/phoneview/android/adb.py +198 -0
  10. phoneview-1.0.0/src/phoneview/android/backend.py +432 -0
  11. phoneview-1.0.0/src/phoneview/android/scrcpy.py +233 -0
  12. phoneview-1.0.0/src/phoneview/backends/__init__.py +0 -0
  13. phoneview-1.0.0/src/phoneview/backends/auto.py +152 -0
  14. phoneview-1.0.0/src/phoneview/backends/base.py +104 -0
  15. phoneview-1.0.0/src/phoneview/events.py +103 -0
  16. phoneview-1.0.0/src/phoneview/httpmini.py +86 -0
  17. phoneview-1.0.0/src/phoneview/ios/__init__.py +0 -0
  18. phoneview-1.0.0/src/phoneview/ios/backend.py +616 -0
  19. phoneview-1.0.0/src/phoneview/ios/connection.py +106 -0
  20. phoneview-1.0.0/src/phoneview/ios/developer_mode.py +86 -0
  21. phoneview-1.0.0/src/phoneview/ios/hid.py +185 -0
  22. phoneview-1.0.0/src/phoneview/ios/stream.py +225 -0
  23. phoneview-1.0.0/src/phoneview/ios/wda.py +208 -0
  24. phoneview-1.0.0/src/phoneview/media.py +150 -0
  25. phoneview-1.0.0/src/phoneview/security.py +134 -0
  26. phoneview-1.0.0/src/phoneview/server.py +231 -0
  27. phoneview-1.0.0/src/phoneview/session.py +201 -0
  28. phoneview-1.0.0/src/phoneview/static/index.html +66 -0
  29. phoneview-1.0.0/src/phoneview/static/viewer.css +35 -0
  30. phoneview-1.0.0/src/phoneview/static/viewer.js +473 -0
  31. phoneview-1.0.0/src/phoneview/streaming.py +50 -0
  32. phoneview-1.0.0/src/phoneview.egg-info/PKG-INFO +317 -0
  33. phoneview-1.0.0/src/phoneview.egg-info/SOURCES.txt +41 -0
  34. phoneview-1.0.0/src/phoneview.egg-info/dependency_links.txt +1 -0
  35. phoneview-1.0.0/src/phoneview.egg-info/entry_points.txt +2 -0
  36. phoneview-1.0.0/src/phoneview.egg-info/requires.txt +10 -0
  37. phoneview-1.0.0/src/phoneview.egg-info/top_level.txt +1 -0
  38. phoneview-1.0.0/tests/test_android.py +213 -0
  39. phoneview-1.0.0/tests/test_connection.py +79 -0
  40. phoneview-1.0.0/tests/test_developer_mode.py +95 -0
  41. phoneview-1.0.0/tests/test_ios.py +288 -0
  42. phoneview-1.0.0/tests/test_protocol.py +163 -0
  43. phoneview-1.0.0/tests/test_server.py +288 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,317 @@
1
+ Metadata-Version: 2.4
2
+ Name: phoneview
3
+ Version: 1.0.0
4
+ Summary: View and control a USB-connected Android phone or iPhone from a browser
5
+ Author: Rahul Chatterjee
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/rchatterjee/phone-controller
8
+ Project-URL: Source, https://github.com/rchatterjee/phone-controller
9
+ Project-URL: Issues, https://github.com/rchatterjee/phone-controller/issues
10
+ Keywords: android,iphone,screen-mirroring,scrcpy,remote-control,webcodecs
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Web Environment
13
+ Classifier: Intended Audience :: Information Technology
14
+ Classifier: Operating System :: Microsoft :: Windows
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Security
23
+ Classifier: Topic :: System :: Hardware :: Universal Serial Bus (USB)
24
+ Requires-Python: >=3.11
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: fastapi<1,>=0.115
28
+ Requires-Dist: uvicorn<1,>=0.34
29
+ Requires-Dist: Pillow>=11
30
+ Requires-Dist: pymobiledevice3<11.50,>=11.49
31
+ Provides-Extra: dev
32
+ Requires-Dist: httpx<1,>=0.28; extra == "dev"
33
+ Requires-Dist: websockets>=12; extra == "dev"
34
+ Requires-Dist: build; extra == "dev"
35
+ Requires-Dist: twine; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # PhoneView (phone-controller)
39
+
40
+ A tool to view and control phones from a laptop, and potentially remotely, for
41
+ security clinics. The phone's owner has to unlock the phone and follow the steps
42
+ to establish the connection, every time.
43
+
44
+ View and control a USB-connected phone from a browser. One small Python process
45
+ on the host (Windows, Linux, Raspberry Pi, thin client) relays the phone's screen to
46
+ a local web page and sends your clicks, drags and typing back to the phone.
47
+
48
+ | Phone | Video | Control | What you need |
49
+ |---|---|---|---|
50
+ | Android 5.0+ | Live H.264, up to 60 fps (scrcpy 5.0.1 server) | Multi-touch, keys, typing, scroll, rotate | USB debugging on; `adb` on the host |
51
+ | iPhone, iOS 27+ | Live HEVC (CoreDevice stream, pymobiledevice3 serve-web); falls back to screenshots | Touch, buttons | Developer Mode |
52
+ | iPhone, iOS 17–26 | Screenshots, ~1–5 fps (DVT) | Live touch, buttons, typing (CoreDevice HID) | Developer Mode |
53
+ | iPhone, iOS 15–16 | Screenshots (screenshotr; Developer Disk Image auto-mounted) | Only if WebDriverAgent is installed ([docs/ios-wda.md](https://github.com/rchatterjee/phone-controller/blob/main/docs/ios-wda.md)); then also faster MJPEG video | Developer Mode (iOS 16) |
54
+
55
+ The host never decodes or re-encodes Android video; it only copies packets, so a
56
+ Raspberry Pi or Wyse 3040 is enough. The browser decodes with WebCodecs.
57
+
58
+ ## Install
59
+
60
+ Python 3.11+. Install it as a standalone tool, in its own environment:
61
+
62
+ ```bash
63
+ pipx install phoneview # or: uv tool install phoneview
64
+ ```
65
+
66
+ `pip install phoneview` into a virtual environment works too. PhoneView pins
67
+ pymobiledevice3 to 11.49.x. ISDi uses the same range, so ISDi users install both
68
+ together with `pip install "isdi-scanner[phoneview]"` (see ISDi's README).
69
+
70
+ From a checkout, for development:
71
+
72
+ ```bash
73
+ python -m venv .venv
74
+ .venv/bin/pip install -e .[dev] # Windows: .venv\Scripts\pip install -e .[dev]
75
+ ```
76
+
77
+ Platform pieces:
78
+
79
+ - **Android:** Android platform-tools (`adb`). Debian/Ubuntu/Raspberry Pi OS:
80
+ `sudo apt install adb` (also installs the udev rules). Windows: install
81
+ platform-tools and put `adb.exe` on `PATH`, or pass `--adb C:\path\adb.exe`.
82
+ The scrcpy server (~90 KB) is downloaded once from the scrcpy GitHub release
83
+ and checked against a pinned SHA-256; on an offline host pass
84
+ `--scrcpy-server /path/to/scrcpy-server-v5.0.1`.
85
+ - **iPhone:** Linux needs `usbmuxd` (`sudo apt install usbmuxd`). Windows needs
86
+ Apple's USB driver (the Apple Devices app or iTunes).
87
+
88
+ On the phone:
89
+
90
+ - Android: enable **Developer options → USB debugging**, plug in, accept the
91
+ *Allow USB debugging?* prompt. On Xiaomi/HyperOS also enable **USB debugging
92
+ (Security settings)**, otherwise touches are ignored.
93
+ - iPhone: unlock, tap **Trust**, and turn on **Developer Mode** (the page walks you through it).
94
+
95
+ ## Run
96
+
97
+ ```bash
98
+ phoneview # or: python -m phoneview
99
+ ```
100
+
101
+ PhoneView prints a link like `http://127.0.0.1:8000/?token=…` and opens it in your
102
+ browser. The token is new on every start; without it the page shows "Access denied".
103
+ PhoneView detects whether an Android phone or an iPhone is plugged in and switches
104
+ automatically. It can also be started from ISDi's **PhoneView** button (see below).
105
+
106
+ Using the page:
107
+
108
+ - Click = tap. Drag = swipe; the finger follows the pointer live.
109
+ Ctrl+drag = two-finger pinch around the screen centre (Android).
110
+ - Mouse wheel scrolls (Android natively; iPhone via a short swipe).
111
+ - Click the screen, then type. Enter, Backspace, arrows and Escape (= Back on
112
+ Android) work, and Ctrl+V pastes. The text box under the buttons does the same.
113
+ - Phone buttons (Back, Home, Recent apps, Power, Volume, Siri/Assistant) and
114
+ Android actions (Notifications, Quick settings, Rotate, Screen off/on) appear
115
+ only when the connected phone supports them.
116
+ - **Stream settings** adjusts resolution, fps and bit rate (Android), or
117
+ screenshot size, quality, fps and bandwidth budget (iPhone) without reconnecting.
118
+
119
+ Useful options (`phoneview --help` lists all):
120
+
121
+ ```
122
+ --platform auto|android|ios restrict detection
123
+ --serial ID choose a device when several are plugged in
124
+ --max-size 1280 --max-fps 30 --bit-rate 4 Android video
125
+ --ios-video auto|stream|screenshot iPhone video route
126
+ --width 480 --quality 65 --active-fps 3 --idle-fps 0.5 --bandwidth-mbps 1.5 iPhone screenshots
127
+ --tunnel | --rsd HOST PORT iOS 17+ tunnel options (see docs/ios-mvp-notes.md)
128
+ --public-origin URL allow a local reverse proxy's origin (tailscale serve)
129
+ --audit-log FILE append who viewed which phone, and when (JSON lines)
130
+ --no-browser print the link only
131
+ ```
132
+
133
+ ### Viewing from another computer: `tailscale serve`
134
+
135
+ PhoneView always listens on 127.0.0.1. For remote viewing, let Tailscale publish it
136
+ inside your tailnet over HTTPS, on the machine the phone is plugged into:
137
+
138
+ ```bash
139
+ tailscale serve --bg --https=8443 http://127.0.0.1:8000
140
+ phoneview --public-origin https://laptop.tailnet.ts.net:8443
141
+ ```
142
+
143
+ Then open `https://laptop.tailnet.ts.net:8443/?token=…` with the token from the
144
+ startup link. HTTPS also enables the browser's video decoder remotely.
145
+
146
+ - Use `tailscale serve`, **never `tailscale funnel`**: funnel publishes to the internet.
147
+ - Restrict who can reach port 8443 with a tailnet access rule (for example,
148
+ only `group:consultants` to `tag:clinic-laptop`).
149
+ - Do not change the bind address; the token is not meant to stand alone on a network.
150
+
151
+ Without Tailscale, an SSH tunnel works the same way:
152
+ `ssh -N -L 8000:127.0.0.1:8000 user@host`, then open the link locally.
153
+
154
+ ### Starting from ISDi
155
+
156
+ ISDi shows a **PhoneView** button when PhoneView is installed with it
157
+ (`pip install "isdi-scanner[phoneview]"`), is on its `PATH`, or `ISDI_PHONEVIEW_CMD`
158
+ points to it. Pressing it starts PhoneView on port 6201 if it
159
+ is not already running, then opens it in a new tab, already signed in. When the
160
+ consultant arrived through `tailscale serve`, the link points at
161
+ `https://<same host>:8443` (override with `ISDI_PHONEVIEW_PUBLIC_URL`). PhoneView
162
+ stops when ISDi stops, including when ISDi is killed. For remote use, also serve
163
+ that port: `tailscale serve --bg --https=8443 http://127.0.0.1:6201`.
164
+
165
+ ### Running as a service (Linux)
166
+
167
+ ```ini
168
+ # /etc/systemd/system/phoneview.service
169
+ [Unit]
170
+ Description=PhoneView
171
+ After=network.target
172
+
173
+ [Service]
174
+ User=phoneview
175
+ ExecStart=/opt/phoneview/.venv/bin/phoneview --port 8000
176
+ Restart=on-failure
177
+
178
+ [Install]
179
+ WantedBy=multi-user.target
180
+ ```
181
+
182
+ The service user needs USB access: membership of `plugdev` (Android udev rules) and
183
+ access to the usbmuxd socket for iPhones.
184
+
185
+ ## How it works
186
+
187
+ ```
188
+ browser (WebCodecs / JPEG, pointer + keys)
189
+ │ one WebSocket: binary video/JPEG frames, JSON status + input
190
+ host: session layer (token sign-in, host/origin checks, one controller, backpressure, input validation)
191
+ │ Backend interface: capabilities, video, input, setup actions
192
+ ├─ Android: adb server protocol → scrcpy server on the phone → H.264 passthrough
193
+ ├─ iOS 27+: pymobiledevice3 ScreenStreamServer (in-process, loopback) → HEVC passthrough
194
+ ├─ iOS 17+: DVT screenshots → JPEG + CoreDevice HID
195
+ └─ iOS 15–16: screenshotr / WDA MJPEG → JPEG + WebDriverAgent
196
+ ```
197
+
198
+ - `src/phoneview/server.py`: app, security middleware, CLI
199
+ - `src/phoneview/security.py`: token sign-in, session cookies, host/origin allow-lists, audit log
200
+ - `src/phoneview/session.py`: WebSocket protocol (documented at the top of the file)
201
+ - `src/phoneview/media.py`: fan-out; video queues resync on key frames, JPEG is latest-wins with acknowledgements
202
+ - `src/phoneview/events.py`: the one input model every backend accepts
203
+ - `src/phoneview/backends/`: interface and USB auto-detection
204
+ - `src/phoneview/android/`: adb client, scrcpy protocol, backend
205
+ - `src/phoneview/ios/`: connection/tunnel, Developer Mode, HID, stream, WDA, backend
206
+ - `src/phoneview/static/`: `index.html`, `viewer.js`, `viewer.css` (no build step)
207
+
208
+ Robustness rules the code follows:
209
+
210
+ - **Version pinning.** scrcpy server 5.0.1 by SHA-256 (its protocol is internal);
211
+ pymobiledevice3 `>=11.49,<11.50` (CoreDevice APIs move between releases).
212
+ - **Capabilities, not special cases.** Each backend reports what works right now,
213
+ and the page shows only those controls.
214
+ - **Fallbacks.** Android drops to a smaller size if the encoder refuses one. iPhone
215
+ tries the live stream, then screenshots. A browser that cannot decode HEVC
216
+ switches the iPhone to screenshots by itself.
217
+ - **Recovery.** Unplug/replug, viewer reload and settings changes reconnect on their own.
218
+ Stale input never crosses a reconnect (generation numbers). Held fingers are
219
+ released when the viewer leaves.
220
+ - **Lightweight.** Android runs the scrcpy server only while someone is watching,
221
+ plus 10 s of grace. iPhone screenshots drop to the idle rate when nothing changes.
222
+
223
+ ## Security
224
+
225
+ | Layer | What it does |
226
+ |---|---|
227
+ | Network | Listens on 127.0.0.1 only; nothing is reachable from the LAN. Remote access goes through `tailscale serve` (TLS, tailnet membership, access rules). |
228
+ | Sign-in | Per-run token (`PHONEVIEW_TOKEN`, or generated) → random session id in an HttpOnly, SameSite=Strict cookie (Secure over HTTPS). Every page and the WebSocket require it. The token is never a command-line argument, so other users can't read it from the process list. |
229
+ | Requests | Host allow-list (blocks DNS rebinding), Origin allow-list on the WebSocket (blocks cross-site hijacking), strict CSP, no caching, one controller at a time. |
230
+ | Accountability | Each view's start and end, with the tailnet login that `tailscale serve` adds (`Tailscale-User-Login`, which it strips from incoming requests), go to the log and to `--audit-log`. |
231
+ | Data | No frames, keystrokes or clipboard contents are stored. |
232
+
233
+ Not covered: anyone with an account or malware on the host machine can use the phone
234
+ through adb or usbmuxd directly, so use a dedicated, up-to-date host.
235
+
236
+ **After each clinic session, remove the trust the phone keeps:**
237
+
238
+ - Android: don't tick "Always allow from this computer". Afterwards,
239
+ **Developer options → Revoke USB debugging authorizations**, then turn USB debugging off.
240
+ - iPhone: **Settings → General → Transfer or Reset iPhone → Reset → Reset Location &
241
+ Privacy** (forgets trusted computers), then turn Developer Mode off.
242
+
243
+ ## Releasing to PyPI
244
+
245
+ The version lives in `src/phoneview/__init__.py`. To release, bump it, tag
246
+ `vX.Y.Z`, and publish a GitHub release; `.github/workflows/publish.yml` builds, checks
247
+ and uploads with PyPI trusted publishing. One-time setup: on PyPI, add a trusted
248
+ publisher for this repository, workflow `publish.yml`, environment `pypi`.
249
+
250
+ To build and check by hand:
251
+
252
+ ```bash
253
+ python -m build && python -m twine check dist/*
254
+ ```
255
+
256
+ ## Tests
257
+
258
+ ```bash
259
+ pip install -e .[dev]
260
+ python -m unittest discover -s tests
261
+ node tests/test_viewer_js.cjs
262
+ # Real browser against a fake phone (needs ffmpeg and `pip install playwright`):
263
+ python tools/browser_e2e.py
264
+ # Against a real phone, while phoneview runs (token from its startup link):
265
+ PHONEVIEW_TOKEN=... python tools/smoke_test.py --port 8000
266
+ ```
267
+
268
+ What has and has not been verified:
269
+
270
+ | Check | Status |
271
+ |---|---|
272
+ | scrcpy 5.0.1 message layouts, checked against the 5.0.1 Java sources | unit tests |
273
+ | Android pipeline: adb protocol, jar push, server launch, H.264 relay, touch/key injection, viewer-leave release | end to end against a fake adb + scrcpy server |
274
+ | iOS HID dispatch, serve-web stream framing, WDA gesture replay, screenshot loop | unit tests with fakes |
275
+ | Viewer: H.264 decode via WebCodecs (~27 fps of a 30 fps clip), JPEG path, click/drag/typing → events | headless Chrome 149, `tools/browser_e2e.py` |
276
+ | Google Pixel 10, from a Windows 11 host | **works on hardware** (2026-10-31) |
277
+ | Samsung Galaxy Tab S6 (SM-T860, Android 12), from Windows 11 | **works on hardware** (2026-10-31), after shortening the scrcpy launch command (see Troubleshooting) |
278
+ | iPhone 8, iOS 16 (screenshotr + DDI auto-mount, view-only without WDA) | **works as expected on hardware** (2026-10-31) |
279
+ | WebDriverAgent control, CoreDevice HEVC stream (iOS 27+) | **not yet tested** (no hardware) |
280
+ | Raspberry Pi / Wyse 3040 CPU and memory | **not yet measured** |
281
+
282
+ Known limitations, to confirm on hardware:
283
+
284
+ - **iOS 17+ touch without a media stream.** pymobiledevice3 notes that some
285
+ configurations ignore HID touch and keyboard reports unless a media stream is
286
+ active. Home and the App switcher were confirmed on hardware earlier. Individual
287
+ taps and drags in screenshot mode were not.
288
+ - **Android rotation.** For a fraction of a second after the phone rotates, taps
289
+ can land at transposed positions, and scrcpy ignores a release sent with the old
290
+ frame size.
291
+ - **iOS 27+ live stream with no viewer.** The stream keeps the phone awake and
292
+ encoding until PhoneView stops. Android stops 10 s after the last viewer leaves.
293
+
294
+ Earlier iOS 17 hardware findings (HID behaviour, App switcher, timing) are kept in
295
+ [docs/ios-mvp-notes.md](https://github.com/rchatterjee/phone-controller/blob/main/docs/ios-mvp-notes.md).
296
+
297
+ ## Troubleshooting
298
+
299
+ - **"No Android device found" or "no permissions" (Linux):** install `adb` from apt
300
+ (it adds the udev rules), make sure your user is in `plugdev`, and replug the phone.
301
+ - **Samsung: "stack corruption detected (-fstack-protector)" in the log:** Samsung's
302
+ encoder aborts when the scrcpy launch command reaches 255 characters
303
+ ([scrcpy #2841](https://github.com/Genymobile/scrcpy/issues/2841)). PhoneView omits
304
+ options already at their defaults to stay under the limit, and a test enforces it.
305
+ If this appears again, run `adb logcat -d -b crash` and report the output.
306
+ - **Android touches do nothing (Xiaomi):** enable *USB debugging (Security settings)*.
307
+ - **Black screen on some Android apps:** banking and DRM apps block screen capture. This is expected.
308
+ - **"This browser cannot decode …":** use a current Chrome, Edge or Safari, opened at
309
+ `http://127.0.0.1` or `localhost`, not a LAN IP.
310
+ - **iPhone 16.x "Could not mount the Developer Disk Image":** keep the phone
311
+ unlocked with Developer Mode on. The first mount downloads the image from GitHub.
312
+ - **WSL:** USB devices are not visible inside WSL without `usbipd` passthrough. Run
313
+ PhoneView on Windows directly, or attach the phone with `usbipd attach`.
314
+
315
+ ## License
316
+
317
+ Apache License 2.0. See [LICENSE](https://github.com/rchatterjee/phone-controller/blob/main/LICENSE).