场景:设备还没接进平台、或人站在机架前不想插线时,原来得在手机上手动输平台地址和
令牌(还可能漏指纹)。现在平台「设备池」里点某台设备的「二维码」,手机上点
「扫码配置」扫一下即完成。
- ScanActivity:Camera1 + **ZXing core**(刻意不用 ML Kit —— 那要 Google Play 服务,
国内机型普遍没有);QR 的定位图案让 ZXing 自带旋转不变性,不用手动转 YUV 帧
- 二维码内容(平台侧生成):{"v":1,"server":…,"token":…,"fingerprint":…,"name":…}
—— 指纹只能由平台给(应用读不到 ro.serialno,见 Prefs 说明),扫码正好是最省事的传递方式
- MainActivity 加「扫码配置」按钮(原「配置」改名「手动配置」)
实机踩到的坑(已修):
- **相机必须在拿到权限后再打开**:surfaceCreated 早于权限回调触发,先开相机会报
"Fail to connect to camera service" 并把流程直接断掉(第一次实测就是这么挂的)
→ 改成 surfaceCreated 只记下 holder,授权回调里再开
- `params.previewSize = size` 编译不过:setPreviewSize 收的是两个 int 不是 Size 对象
实测(A07 / USB 连接):扫码 → 相机启动 → 解码 → 保存 → 立刻拉清单,
平台认出「A07」,全程无需打字、无需 adb。
102 lines
4.7 KiB
XML
102 lines
4.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||
xmlns:tools="http://schemas.android.com/tools">
|
||
|
||
<!--
|
||
usesCleartextTraffic=true 的原因:平台跑在局域网里、只有 HTTP(没有 TLS),
|
||
Android 9+ 默认会拦掉明文请求(实测报 "Cleartext HTTP traffic ... not permitted")。
|
||
本 App 只连你在「配置」里填的那个平台地址,不传输用户隐私数据。
|
||
将来平台上了 HTTPS,把 application 上那一行删掉即可。
|
||
-->
|
||
|
||
<!-- 从平台拉应用清单 / 下载 APK -->
|
||
<uses-permission android:name="android.permission.INTERNET" />
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||
<!-- 自己调系统安装器安装 APK(这正是绕开 MIUI「USB 安装」拦截的关键) -->
|
||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||
<!-- 扫配置二维码 -->
|
||
<uses-permission android:name="android.permission.CAMERA" />
|
||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||
<!--
|
||
查询任意已安装应用的版本号 —— 用来在商店列表里显示「已安装 / 可更新 / 安装」。
|
||
Android 11+ 默认限制了软件包可见性(不给的话 getPackageInfo 一律抛 NameNotFound,
|
||
实测表现为"明明装了却全显示未安装");本 App 不是上架 Google Play 的应用,
|
||
用这个权限没有商店审核问题。
|
||
-->
|
||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
|
||
tools:ignore="QueryAllPackagesPermission" />
|
||
|
||
<application
|
||
android:allowBackup="false"
|
||
android:usesCleartextTraffic="true"
|
||
android:icon="@drawable/ic_launcher"
|
||
android:label="@string/app_name"
|
||
android:supportsRtl="true"
|
||
android:theme="@style/Theme.DeviceAgent">
|
||
|
||
<!-- 主界面:应用商店(看清单、选应用、下载安装) -->
|
||
<activity
|
||
android:name=".MainActivity"
|
||
android:exported="true"
|
||
android:label="@string/app_name">
|
||
<intent-filter>
|
||
<action android:name="android.intent.action.MAIN" />
|
||
<category android:name="android.intent.category.LAUNCHER" />
|
||
</intent-filter>
|
||
</activity>
|
||
|
||
<!-- 剪贴板注入:透明 Activity,由平台用 adb am start 拉起
|
||
(完整命令见 README「快速开始」,参数 text_b64 传 base64 文本) -->
|
||
<activity
|
||
android:name=".ClipActivity"
|
||
android:exported="true"
|
||
android:excludeFromRecents="true"
|
||
android:noHistory="true"
|
||
android:theme="@style/Theme.DeviceAgent.Transparent" />
|
||
|
||
<!-- 身份显示:全屏大字,人在机架前一眼看出这台是平台的哪一台
|
||
(参数 name / ip / serial / server,close=1 关闭;命令见 README) -->
|
||
<activity
|
||
android:name=".InfoActivity"
|
||
android:exported="true"
|
||
android:launchMode="singleTop"
|
||
android:excludeFromRecents="true" />
|
||
|
||
<!-- 扫码配置:扫平台设备池里生成的配置二维码,一次写入地址/令牌/指纹
|
||
(设备还没连上平台、或人在机器旁不想插线时用;已连上平台的也可以用
|
||
ConfigActivity 走 adb 下发,两条路等价) -->
|
||
<activity
|
||
android:name=".ScanActivity"
|
||
android:exported="false"
|
||
android:label="扫码配置"
|
||
android:screenOrientation="portrait" />
|
||
|
||
<!-- 一次性配置下发(平台用 adb 推地址与令牌,省得每台手输) -->
|
||
<activity
|
||
android:name=".ConfigActivity"
|
||
android:exported="true"
|
||
android:excludeFromRecents="true"
|
||
android:noHistory="true"
|
||
android:theme="@style/Theme.DeviceAgent.Transparent" />
|
||
|
||
<!-- 自检:平台用来判断"装没装、哪一版" -->
|
||
<activity
|
||
android:name=".PingActivity"
|
||
android:exported="true"
|
||
android:excludeFromRecents="true"
|
||
android:noHistory="true"
|
||
android:theme="@style/Theme.DeviceAgent.Transparent" />
|
||
|
||
<!-- 把下载到私有目录的 APK 授权给系统安装器读 -->
|
||
<provider
|
||
android:name="androidx.core.content.FileProvider"
|
||
android:authorities="${applicationId}.fileprovider"
|
||
android:exported="false"
|
||
android:grantUriPermissions="true">
|
||
<meta-data
|
||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||
android:resource="@xml/file_paths" />
|
||
</provider>
|
||
</application>
|
||
</manifest>
|