build: remove TWA
@@ -46,13 +46,13 @@ grep versionCode android/app/build.gradle
|
|||||||
- 打完核对:`aapt2 dump badging` 的 versionCode、`apksigner verify --print-certs` 的证书,
|
- 打完核对:`aapt2 dump badging` 的 versionCode、`apksigner verify --print-certs` 的证书,
|
||||||
以及解包 grep 接口地址(内网地址必须为 0 次)
|
以及解包 grep 接口地址(内网地址必须为 0 次)
|
||||||
- **一条命令出正式包**:`pnpm run android:apk`
|
- **一条命令出正式包**:`pnpm run android:apk`
|
||||||
= `android:sync:prod` + `assembleRelease` + 用 `twa/android.keystore` 签名 + 复制到
|
= `android:sync:prod` + `assembleRelease` + 用根目录 `android.keystore` 签名 + 复制到
|
||||||
`android/app/release/app-release.apk`(已 gitignore),末尾会打印 versionCode、大小、
|
`android/app/release/app-release.apk`(已 gitignore),末尾会打印 versionCode、大小、
|
||||||
sha256 和证书指纹
|
sha256 和证书指纹
|
||||||
- 签名凭证放在 `android/keystore.properties`(已 gitignore),格式见同目录
|
- 签名凭证放在 `android/keystore.properties`(已 gitignore),格式见同目录
|
||||||
`keystore.properties.example`;缺密码时脚本会直接拦住,不会产出 debug 包
|
`keystore.properties.example`;缺密码时脚本会直接拦住,不会产出 debug 包
|
||||||
- 只重新打包、不重建 web:`pnpm run android:apk -- -SkipSync`
|
- 只重新打包、不重建 web:`pnpm run android:apk -- -SkipSync`
|
||||||
- 仍然可以用 Android Studio 打包,但**签名必须是 `twa/android.keystore`**
|
- 仍然可以用 Android Studio 打包,但**签名必须是根目录 `android.keystore`**
|
||||||
(alias `gao-customer`,`CN=yeyu` / SHA-256 `3E:9C:CC:8A:…`),否则系统拒绝覆盖安装
|
(alias `gao-customer`,`CN=yeyu` / SHA-256 `3E:9C:CC:8A:…`),否则系统拒绝覆盖安装
|
||||||
|
|
||||||
### 3. 提高 CI 的兼容基线
|
### 3. 提高 CI 的兼容基线
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# 发版签名凭证(复制为 android/keystore.properties 后填写,该文件已 gitignore)
|
# 发版签名凭证(复制为 android/keystore.properties 后填写,该文件已 gitignore)
|
||||||
# storeFile 相对于 android/ 目录
|
# storeFile 相对于 android/ 目录
|
||||||
storeFile=../twa/android.keystore
|
storeFile=../android.keystore
|
||||||
keyAlias=gao-customer
|
keyAlias=gao-customer
|
||||||
storePassword=
|
storePassword=
|
||||||
keyPassword=
|
keyPassword=
|
||||||
|
|||||||
@@ -7,9 +7,6 @@
|
|||||||
"dev": "vite --host",
|
"dev": "vite --host",
|
||||||
"build": "pnpm run type-check:publish && vite build",
|
"build": "pnpm run type-check:publish && vite build",
|
||||||
"build:zip": "pnpm run build && powershell -NoProfile -ExecutionPolicy Bypass -File scripts/build-zip.ps1",
|
"build:zip": "pnpm run build && powershell -NoProfile -ExecutionPolicy Bypass -File scripts/build-zip.ps1",
|
||||||
"twa:build": "cd twa && pnpm --config.registry=https://registry.npmjs.org dlx @bubblewrap/cli@1.25.0 build --manifest=./twa-manifest.json",
|
|
||||||
"twa:update": "cd twa && pnpm --config.registry=https://registry.npmjs.org dlx @bubblewrap/cli@1.25.0 update --skipVersionUpgrade --manifest=./twa-manifest.json",
|
|
||||||
"twa:validate": "pnpm --config.registry=https://registry.npmjs.org dlx @bubblewrap/cli@1.25.0 validate --url=https://gao.imyeyu.com/",
|
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"lint": "eslint . --ext .ts,.vue",
|
"lint": "eslint . --ext .ts,.vue",
|
||||||
"type-check": "vue-tsc -p tsconfig.app.json --noEmit",
|
"type-check": "vue-tsc -p tsconfig.app.json --noEmit",
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"relation": [
|
|
||||||
"delegate_permission/common.handle_all_urls",
|
|
||||||
"delegate_permission/common.use_as_origin"
|
|
||||||
],
|
|
||||||
"target": {
|
|
||||||
"namespace": "android_app",
|
|
||||||
"package_name": "com.imyeyu.gao.customer",
|
|
||||||
"sha256_cert_fingerprints": [
|
|
||||||
"3E:9C:CC:8A:29:71:18:74:BB:56:AA:88:AD:62:E1:F3:AC:F2:70:07:C4:67:D9:32:B8:A2:4B:B7:E7:8E:06:34"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -8,7 +8,7 @@ $root = Split-Path -Parent $PSScriptRoot
|
|||||||
$propertiesPath = Join-Path $root "android\keystore.properties"
|
$propertiesPath = Join-Path $root "android\keystore.properties"
|
||||||
|
|
||||||
if (-not (Test-Path $propertiesPath)) {
|
if (-not (Test-Path $propertiesPath)) {
|
||||||
Write-Host "缺少 android\keystore.properties:发版包必须用 twa\android.keystore 签名" -ForegroundColor Red
|
Write-Host "缺少 android\keystore.properties:发版包必须用根目录 android.keystore 签名" -ForegroundColor Red
|
||||||
Write-Host "照着同目录的 keystore.properties.example 补全后重试"
|
Write-Host "照着同目录的 keystore.properties.example 补全后重试"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ import type {
|
|||||||
import type { PhotoItem } from "@/types/Photo.ts";
|
import type { PhotoItem } from "@/types/Photo.ts";
|
||||||
import { getAttachmentReadURL } from "@/utils/attachment.ts";
|
import { getAttachmentReadURL } from "@/utils/attachment.ts";
|
||||||
import { Message } from "@/utils/message.ts";
|
import { Message } from "@/utils/message.ts";
|
||||||
import { saveCapturedFilesFromInput } from "@/utils/twaBridge";
|
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
inheritAttrs: false
|
inheritAttrs: false
|
||||||
@@ -89,7 +88,6 @@ const isBusy = computed(() => props.busy || isUploading.value);
|
|||||||
const attachmentItems = computed(() => props.items.map(toAttachmentSelectorItem));
|
const attachmentItems = computed(() => props.items.map(toAttachmentSelectorItem));
|
||||||
|
|
||||||
async function handleSelect(selection: AttachmentSelectorSelection): Promise<void> {
|
async function handleSelect(selection: AttachmentSelectorSelection): Promise<void> {
|
||||||
saveCapturedFilesFromInput(selection.input, selection.files);
|
|
||||||
if (!props.upload) {
|
if (!props.upload) {
|
||||||
emit("select", selection);
|
emit("select", selection);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import { VCan, VRole } from "timi-web-api/utils/directives/Access";
|
|||||||
import type { ApiResponse } from "timi-web-api";
|
import type { ApiResponse } from "timi-web-api";
|
||||||
import { Message } from "@/utils/message";
|
import { Message } from "@/utils/message";
|
||||||
import { runAutoUpdate } from "@/composables/useAppUpdate";
|
import { runAutoUpdate } from "@/composables/useAppUpdate";
|
||||||
import { initializeTwaBridge } from "@/utils/twaBridge";
|
|
||||||
import { VEntranceTransition } from "timi-tdesign-mobile";
|
import { VEntranceTransition } from "timi-tdesign-mobile";
|
||||||
import timiWebStyle from "timi-web/src/assets/style/timi-web.less?inline";
|
import timiWebStyle from "timi-web/src/assets/style/timi-web.less?inline";
|
||||||
import tdesignCustomStyle from "timi-tdesign-mobile/src/assets/style/tdesign-custom.less?inline";
|
import tdesignCustomStyle from "timi-tdesign-mobile/src/assets/style/tdesign-custom.less?inline";
|
||||||
@@ -29,8 +28,6 @@ export const pinia = createPinia();
|
|||||||
const apiBaseURL = import.meta.env.VITE_API_BASE_URL as string | undefined;
|
const apiBaseURL = import.meta.env.VITE_API_BASE_URL as string | undefined;
|
||||||
const libraryOverrideStyleId = "library-override-style";
|
const libraryOverrideStyleId = "library-override-style";
|
||||||
|
|
||||||
initializeTwaBridge();
|
|
||||||
|
|
||||||
function mountLibraryOverrideStyle(): void {
|
function mountLibraryOverrideStyle(): void {
|
||||||
const oldStyle = document.getElementById(libraryOverrideStyleId);
|
const oldStyle = document.getElementById(libraryOverrideStyleId);
|
||||||
oldStyle?.remove();
|
oldStyle?.remove();
|
||||||
|
|||||||
@@ -1,330 +0,0 @@
|
|||||||
const TWA_ORIGIN = "https://gao.imyeyu.com";
|
|
||||||
const TWA_BRIDGE_TIMEOUT = 10_000;
|
|
||||||
const MEDIA_CHUNK_SIZE = 64 * 1024;
|
|
||||||
const LOG_PREFIX = "[TWA 相册]";
|
|
||||||
|
|
||||||
type CapturedMediaType = "image" | "video";
|
|
||||||
|
|
||||||
interface TwaMessage {
|
|
||||||
type: string;
|
|
||||||
id?: string;
|
|
||||||
index?: number;
|
|
||||||
data?: string;
|
|
||||||
error?: string;
|
|
||||||
version?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
type TwaResponseHandler = (message: TwaMessage) => void;
|
|
||||||
|
|
||||||
let bridgeInitialized = false;
|
|
||||||
let bridgePort: MessagePort | undefined;
|
|
||||||
let bridgeWaiterList: Array<(port: MessagePort | undefined) => void> = [];
|
|
||||||
let transferQueue = Promise.resolve();
|
|
||||||
const responseHandlerMap = new Map<string, TwaResponseHandler>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化 TWA 通信监听。
|
|
||||||
*
|
|
||||||
* 普通浏览器不会收到带 MessagePort 的消息,因此初始化失败时不会影响网页功能。
|
|
||||||
*/
|
|
||||||
export function initializeTwaBridge(): void {
|
|
||||||
if (bridgeInitialized || typeof window === "undefined") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bridgeInitialized = true;
|
|
||||||
window.addEventListener("message", handleWindowMessage);
|
|
||||||
logInfo("已初始化网页侧通信监听");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将直接拍摄得到的媒体保存到 Android 系统相册。
|
|
||||||
*
|
|
||||||
* 非 TWA 环境会直接返回,不会阻塞原有上传流程。
|
|
||||||
*/
|
|
||||||
export function saveCapturedMediaToAlbum(file: File, mediaType: CapturedMediaType): void {
|
|
||||||
if (!file.size) {
|
|
||||||
logWarn("跳过相册保存:文件大小为 0", {
|
|
||||||
fileName: file.name,
|
|
||||||
mediaType
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeTwaBridge();
|
|
||||||
logInfo("收到相册保存请求", {
|
|
||||||
fileName: file.name,
|
|
||||||
fileType: file.type,
|
|
||||||
fileSize: file.size,
|
|
||||||
mediaType
|
|
||||||
});
|
|
||||||
transferQueue = transferQueue
|
|
||||||
.then(async () => {
|
|
||||||
await transferMedia(file, mediaType);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
// 相册保存是增强能力,失败时不能影响媒体上传。
|
|
||||||
logError("相册保存失败,已忽略并继续原上传流程", error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据文件输入框判断是否为直接拍摄,并启动相册保存。
|
|
||||||
*/
|
|
||||||
export function saveCapturedFilesFromInput(input: HTMLInputElement, fileList: readonly File[]): void {
|
|
||||||
if (!input.capture || !fileList.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mediaType: CapturedMediaType = input.accept.toLowerCase().includes("video") ? "video" : "image";
|
|
||||||
logInfo("识别为直接拍摄媒体", {
|
|
||||||
accept: input.accept,
|
|
||||||
capture: input.capture,
|
|
||||||
fileCount: fileList.length,
|
|
||||||
mediaType
|
|
||||||
});
|
|
||||||
for (const file of fileList) {
|
|
||||||
saveCapturedMediaToAlbum(file, mediaType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleWindowMessage(event: MessageEvent): void {
|
|
||||||
const message = parseMessage(event.data);
|
|
||||||
if (message?.type !== "twa-bridge-ready") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.origin !== TWA_ORIGIN || !event.ports.length) {
|
|
||||||
logWarn("忽略无效的 TWA 桥接就绪消息", {
|
|
||||||
origin: event.origin,
|
|
||||||
hasMessagePort: event.ports.length > 0
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
logInfo("收到 Android 侧桥接就绪消息", {
|
|
||||||
origin: event.origin,
|
|
||||||
version: message.version
|
|
||||||
});
|
|
||||||
bridgePort = event.ports[0];
|
|
||||||
bridgePort.onmessage = handlePortMessage;
|
|
||||||
bridgePort.start();
|
|
||||||
bridgePort.postMessage(JSON.stringify({
|
|
||||||
type: "twa-bridge-ready-ack",
|
|
||||||
version: 1
|
|
||||||
}));
|
|
||||||
|
|
||||||
const waiterList = bridgeWaiterList;
|
|
||||||
bridgeWaiterList = [];
|
|
||||||
for (const waiter of waiterList) {
|
|
||||||
waiter(bridgePort);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handlePortMessage(event: MessageEvent): void {
|
|
||||||
const message = parseMessage(event.data);
|
|
||||||
if (!message?.id) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
responseHandlerMap.get(message.id)?.(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function transferMedia(file: File, mediaType: CapturedMediaType): Promise<void> {
|
|
||||||
const port = await waitForBridgePort();
|
|
||||||
if (!port) {
|
|
||||||
logWarn("未连接到 TWA,跳过相册保存", {
|
|
||||||
fileName: file.name,
|
|
||||||
mediaType
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const id = createTransferId();
|
|
||||||
let transferFinished = false;
|
|
||||||
logInfo("开始传输媒体", {
|
|
||||||
id,
|
|
||||||
fileName: file.name,
|
|
||||||
mediaType,
|
|
||||||
fileSize: file.size,
|
|
||||||
chunkSize: MEDIA_CHUNK_SIZE
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
await sendTransferMessage(port, id, {
|
|
||||||
type: "media-start",
|
|
||||||
id,
|
|
||||||
mediaType,
|
|
||||||
mimeType: file.type || `${mediaType}/*`,
|
|
||||||
fileName: file.name,
|
|
||||||
size: file.size
|
|
||||||
}, "media-started");
|
|
||||||
|
|
||||||
let offset = 0;
|
|
||||||
let index = 0;
|
|
||||||
while (offset < file.size) {
|
|
||||||
const chunk = await file.slice(offset, offset + MEDIA_CHUNK_SIZE).arrayBuffer();
|
|
||||||
if (index === 0 || index % 16 === 0 || offset + chunk.byteLength >= file.size) {
|
|
||||||
logDebug("发送媒体分块", {
|
|
||||||
id,
|
|
||||||
index,
|
|
||||||
chunkSize: chunk.byteLength,
|
|
||||||
offset
|
|
||||||
});
|
|
||||||
}
|
|
||||||
await sendTransferMessage(port, id, {
|
|
||||||
type: "media-chunk",
|
|
||||||
id,
|
|
||||||
index,
|
|
||||||
data: encodeBase64(chunk)
|
|
||||||
}, "media-chunk-ack", index);
|
|
||||||
offset += chunk.byteLength;
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
await sendTransferMessage(port, id, {
|
|
||||||
type: "media-finish",
|
|
||||||
id
|
|
||||||
}, "media-saved");
|
|
||||||
transferFinished = true;
|
|
||||||
logInfo("媒体已保存到系统相册", {
|
|
||||||
id,
|
|
||||||
fileName: file.name,
|
|
||||||
fileSize: file.size
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
if (!transferFinished) {
|
|
||||||
logWarn("媒体传输未完成,发送中止请求", { id });
|
|
||||||
port.postMessage(JSON.stringify({
|
|
||||||
type: "media-abort",
|
|
||||||
id
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function sendTransferMessage(
|
|
||||||
port: MessagePort,
|
|
||||||
id: string,
|
|
||||||
message: Record<string, unknown>,
|
|
||||||
expectedType: string,
|
|
||||||
expectedIndex?: number
|
|
||||||
): Promise<void> {
|
|
||||||
const responsePromise = waitForTransferResponse(id, expectedType, expectedIndex);
|
|
||||||
logDebug("发送桥接消息", {
|
|
||||||
id,
|
|
||||||
type: message.type,
|
|
||||||
expectedType,
|
|
||||||
expectedIndex
|
|
||||||
});
|
|
||||||
port.postMessage(JSON.stringify(message));
|
|
||||||
await responsePromise;
|
|
||||||
}
|
|
||||||
|
|
||||||
function waitForBridgePort(): Promise<MessagePort | undefined> {
|
|
||||||
if (bridgePort) {
|
|
||||||
return Promise.resolve(bridgePort);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise(resolve => {
|
|
||||||
let settled = false;
|
|
||||||
const settle = (port?: MessagePort): void => {
|
|
||||||
if (settled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
settled = true;
|
|
||||||
resolve(port);
|
|
||||||
};
|
|
||||||
bridgeWaiterList.push(settle);
|
|
||||||
logDebug("等待 Android 侧桥接就绪");
|
|
||||||
window.setTimeout(() => {
|
|
||||||
bridgeWaiterList = bridgeWaiterList.filter(waiter => waiter !== settle);
|
|
||||||
logWarn("等待 TWA 桥接超时,当前页面不是已建立通道的 TWA,或 Android 来源校验未通过", {
|
|
||||||
origin: window.location.origin,
|
|
||||||
displayMode: getDisplayMode(),
|
|
||||||
userAgent: navigator.userAgent
|
|
||||||
});
|
|
||||||
settle();
|
|
||||||
}, TWA_BRIDGE_TIMEOUT);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function waitForTransferResponse(id: string, expectedType: string, expectedIndex?: number): Promise<void> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const timeout = window.setTimeout(() => {
|
|
||||||
responseHandlerMap.delete(id);
|
|
||||||
logError("等待桥接响应超时", new Error(`${expectedType}, id=${id}`));
|
|
||||||
reject(new Error("TWA 媒体保存响应超时"));
|
|
||||||
}, 15_000);
|
|
||||||
|
|
||||||
responseHandlerMap.set(id, message => {
|
|
||||||
if (message.type === "media-error") {
|
|
||||||
window.clearTimeout(timeout);
|
|
||||||
responseHandlerMap.delete(id);
|
|
||||||
logError("Android 侧返回媒体错误", new Error(message.error || "TWA 媒体保存失败"));
|
|
||||||
reject(new Error(message.error || "TWA 媒体保存失败"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (message.type !== expectedType || (expectedIndex !== undefined && message.index !== expectedIndex)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.clearTimeout(timeout);
|
|
||||||
responseHandlerMap.delete(id);
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function logInfo(message: string, detail?: unknown): void {
|
|
||||||
console.warn(LOG_PREFIX, message, detail ?? "");
|
|
||||||
}
|
|
||||||
|
|
||||||
function logDebug(message: string, detail?: unknown): void {
|
|
||||||
console.warn(LOG_PREFIX, message, detail ?? "");
|
|
||||||
}
|
|
||||||
|
|
||||||
function logWarn(message: string, detail?: unknown): void {
|
|
||||||
console.warn(LOG_PREFIX, message, detail ?? "");
|
|
||||||
}
|
|
||||||
|
|
||||||
function logError(message: string, error: unknown): void {
|
|
||||||
console.error(LOG_PREFIX, message, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseMessage(value: unknown): TwaMessage | undefined {
|
|
||||||
if (typeof value !== "string") {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const message = JSON.parse(value) as TwaMessage;
|
|
||||||
return typeof message.type === "string" ? message : undefined;
|
|
||||||
} catch {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function encodeBase64(buffer: ArrayBuffer): string {
|
|
||||||
const bytes = new Uint8Array(buffer);
|
|
||||||
let binary = "";
|
|
||||||
for (let index = 0; index < bytes.length; index += 0x8000) {
|
|
||||||
binary += String.fromCharCode(...bytes.subarray(index, index + 0x8000));
|
|
||||||
}
|
|
||||||
return window.btoa(binary);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createTransferId(): string {
|
|
||||||
if (typeof crypto !== "undefined" && "randomUUID" in crypto) {
|
|
||||||
return crypto.randomUUID();
|
|
||||||
}
|
|
||||||
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDisplayMode(): string {
|
|
||||||
if (window.matchMedia("(display-mode: standalone)").matches) {
|
|
||||||
return "standalone";
|
|
||||||
}
|
|
||||||
if (window.matchMedia("(display-mode: fullscreen)").matches) {
|
|
||||||
return "fullscreen";
|
|
||||||
}
|
|
||||||
return "browser";
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
.gradle/
|
|
||||||
local.properties
|
|
||||||
**/build/
|
|
||||||
*.apk
|
|
||||||
*.aab
|
|
||||||
*.idsig
|
|
||||||
*.jks
|
|
||||||
*.keystore
|
|
||||||
|
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
# TWA 构建说明
|
|
||||||
|
|
||||||
本目录是 `gao.imyeyu.com` 的 Trusted Web Activity 工程。APK 只包含 Android 启动壳,业务页面始终从 `https://gao.imyeyu.com/` 加载,不把前端 `dist` 打进 APK。
|
|
||||||
|
|
||||||
## 构建环境
|
|
||||||
|
|
||||||
- JDK 17
|
|
||||||
- Android SDK
|
|
||||||
- Bubblewrap CLI 1.25.0
|
|
||||||
|
|
||||||
在本机首次使用 Bubblewrap 时执行:
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
pnpm --config.registry=https://registry.npmjs.org dlx @bubblewrap/cli@1.25.0 doctor
|
|
||||||
```
|
|
||||||
|
|
||||||
## 构建 APK
|
|
||||||
|
|
||||||
首次构建正式版本时,先在本目录生成并妥善备份 release keystore:
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
keytool -genkeypair -v -keystore .\android.keystore -alias gao-customer -keyalg RSA -keysize 2048 -validity 10000
|
|
||||||
```
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
pnpm --config.registry=https://registry.npmjs.org dlx @bubblewrap/cli@1.25.0 build
|
|
||||||
```
|
|
||||||
|
|
||||||
构建前请准备长期保存的 release keystore,并确认 `twa-manifest.json` 中的 `signingKey` 指向它。当前目录的 `signingKey` 是可提交的相对路径模板;本次验证 APK 使用的是本机调试签名,不能作为正式发布签名。
|
|
||||||
|
|
||||||
构建完成后,用 release keystore 的 SHA-256 证书指纹更新 `../public/.well-known/assetlinks.json`,再发布前端 `dist`。TWA 只有在网站的 `/.well-known/assetlinks.json` 与 APK 包名、签名一致时,才会进入无地址栏的全屏模式。
|
|
||||||
|
|
||||||
当前 `assetlinks.json` 中登记的是本机调试证书指纹,只能配合本次验证 APK 使用。正式发布前必须替换为 release 证书指纹;如果使用 Google Play,还要把 Play App Signing 证书指纹一并登记。
|
|
||||||
|
|
||||||
## TWA 媒体桥接
|
|
||||||
|
|
||||||
TWA 通过 `postMessage` 接收网页直接拍摄的照片和视频,Android 10 及以上使用 `MediaStore` 分块写入系统相册,照片保存到“图片/糕店管理”,视频保存到“视频/糕店管理”。普通浏览器和从相册选择的文件不会触发该桥接。
|
|
||||||
|
|
||||||
桥接依赖 `assetlinks.json` 中的 `delegate_permission/common.use_as_origin` 关系。发布 APK 前必须使用实际 release 签名证书的 SHA-256 指纹更新该文件,否则来源验证失败,桥接不会启用。
|
|
||||||
|
|
||||||
## 前端发布顺序
|
|
||||||
|
|
||||||
1. 先上传新版本 `dist/assets`。
|
|
||||||
2. 再上传新的 `index.html`、Manifest 和其他静态文件。
|
|
||||||
3. 最后检查 `https://gao.imyeyu.com/`、`/manifest.webmanifest` 和 `/.well-known/assetlinks.json`。
|
|
||||||
|
|
||||||
`index.html` 不缓存,带哈希的 `/assets/` 长缓存。不要给前端资源增加 Service Worker 缓存,除非同时实现版本更新和回滚,否则会阻止 TWA 获取最新页面。
|
|
||||||
@@ -1,213 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2019 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import groovy.xml.MarkupBuilder
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id 'com.android.application'
|
|
||||||
}
|
|
||||||
|
|
||||||
def twaManifest = [
|
|
||||||
applicationId: 'com.imyeyu.gao.customer',
|
|
||||||
hostName: 'gao.imyeyu.com', // The domain being opened in the TWA.
|
|
||||||
launchUrl: '/', // The start path for the TWA. Must be relative to the domain.
|
|
||||||
name: '糕店客户管理', // The application name.
|
|
||||||
launcherName: '糕店管理', // The name shown on the Android Launcher.
|
|
||||||
themeColor: '#FFFFFF', // The color used for the status bar.
|
|
||||||
themeColorDark: '#000000', // The color used for the dark status bar.
|
|
||||||
navigationColor: '#000000', // The color used for the navigation bar.
|
|
||||||
navigationColorDark: '#000000', // The color used for the dark navbar.
|
|
||||||
navigationDividerColor: '#000000', // The navbar divider color.
|
|
||||||
navigationDividerColorDark: '#000000', // The dark navbar divider color.
|
|
||||||
backgroundColor: '#FFFFFF', // The color used for the splash screen background.
|
|
||||||
enableNotifications: false, // Set to true to enable notification delegation.
|
|
||||||
// Every shortcut must include the following fields:
|
|
||||||
// - name: String that will show up in the shortcut.
|
|
||||||
// - short_name: Shorter string used if |name| is too long.
|
|
||||||
// - url: Absolute path of the URL to launch the app with (e.g '/create').
|
|
||||||
// - icon: Name of the resource in the drawable folder to use as an icon.
|
|
||||||
shortcuts: [],
|
|
||||||
// The duration of fade out animation in milliseconds to be played when removing splash screen.
|
|
||||||
splashScreenFadeOutDuration: 300,
|
|
||||||
generatorApp: 'bubblewrap-cli', // Application that generated the Android Project
|
|
||||||
// The fallback strategy for when Trusted Web Activity is not available. Possible values are
|
|
||||||
// 'customtabs' and 'webview'.
|
|
||||||
fallbackType: 'customtabs',
|
|
||||||
enableSiteSettingsShortcut: 'true',
|
|
||||||
orientation: 'portrait',
|
|
||||||
]
|
|
||||||
|
|
||||||
android {
|
|
||||||
compileSdkVersion 36
|
|
||||||
namespace "com.imyeyu.gao.customer"
|
|
||||||
defaultConfig {
|
|
||||||
applicationId "com.imyeyu.gao.customer"
|
|
||||||
minSdkVersion 21
|
|
||||||
targetSdkVersion 36
|
|
||||||
versionCode 1
|
|
||||||
versionName "1"
|
|
||||||
|
|
||||||
// The name for the application
|
|
||||||
resValue "string", "appName", twaManifest.name
|
|
||||||
|
|
||||||
// The name for the application on the Android Launcher
|
|
||||||
resValue "string", "launcherName", twaManifest.launcherName
|
|
||||||
|
|
||||||
// The URL that will be used when launching the TWA from the Android Launcher
|
|
||||||
def launchUrl = "https://" + twaManifest.hostName + twaManifest.launchUrl
|
|
||||||
resValue "string", "launchUrl", launchUrl
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// The URL the Web Manifest for the Progressive Web App that the TWA points to. This
|
|
||||||
// is used by Chrome OS and Meta Quest to open the Web version of the PWA instead of
|
|
||||||
// the TWA, as it will probably give a better user experience for non-mobile devices.
|
|
||||||
resValue "string", "webManifestUrl", 'https://gao.imyeyu.com/manifest.webmanifest'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This is used by Meta Quest.
|
|
||||||
resValue "string", "fullScopeUrl", 'https://gao.imyeyu.com/'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// The hostname is used when building the intent-filter, so the TWA is able to
|
|
||||||
// handle Intents to open host url of the application.
|
|
||||||
resValue "string", "hostName", twaManifest.hostName
|
|
||||||
|
|
||||||
// This attribute sets the status bar color for the TWA. It can be either set here or in
|
|
||||||
// `res/values/colors.xml`. Setting in both places is an error and the app will not
|
|
||||||
// compile. If not set, the status bar color defaults to #FFFFFF - white.
|
|
||||||
resValue "color", "colorPrimary", twaManifest.themeColor
|
|
||||||
|
|
||||||
// This attribute sets the dark status bar color for the TWA. It can be either set here or in
|
|
||||||
// `res/values/colors.xml`. Setting in both places is an error and the app will not
|
|
||||||
// compile. If not set, the status bar color defaults to #000000 - white.
|
|
||||||
resValue "color", "colorPrimaryDark", twaManifest.themeColorDark
|
|
||||||
|
|
||||||
// This attribute sets the navigation bar color for the TWA. It can be either set here or
|
|
||||||
// in `res/values/colors.xml`. Setting in both places is an error and the app will not
|
|
||||||
// compile. If not set, the navigation bar color defaults to #FFFFFF - white.
|
|
||||||
resValue "color", "navigationColor", twaManifest.navigationColor
|
|
||||||
|
|
||||||
// This attribute sets the dark navigation bar color for the TWA. It can be either set here
|
|
||||||
// or in `res/values/colors.xml`. Setting in both places is an error and the app will not
|
|
||||||
// compile. If not set, the navigation bar color defaults to #000000 - black.
|
|
||||||
resValue "color", "navigationColorDark", twaManifest.navigationColorDark
|
|
||||||
|
|
||||||
// This attribute sets the navbar divider color for the TWA. It can be either
|
|
||||||
// set here or in `res/values/colors.xml`. Setting in both places is an error and the app
|
|
||||||
// will not compile. If not set, the divider color defaults to #00000000 - transparent.
|
|
||||||
resValue "color", "navigationDividerColor", twaManifest.navigationDividerColor
|
|
||||||
|
|
||||||
// This attribute sets the dark navbar divider color for the TWA. It can be either
|
|
||||||
// set here or in `res/values/colors.xml`. Setting in both places is an error and the
|
|
||||||
//app will not compile. If not set, the divider color defaults to #000000 - black.
|
|
||||||
resValue "color", "navigationDividerColorDark", twaManifest.navigationDividerColorDark
|
|
||||||
|
|
||||||
// Sets the color for the background used for the splash screen when launching the
|
|
||||||
// Trusted Web Activity.
|
|
||||||
resValue "color", "backgroundColor", twaManifest.backgroundColor
|
|
||||||
|
|
||||||
// Defines a provider authority for the Splash Screen
|
|
||||||
resValue "string", "providerAuthority", twaManifest.applicationId + '.fileprovider'
|
|
||||||
|
|
||||||
// The enableNotification resource is used to enable or disable the
|
|
||||||
// TrustedWebActivityService, by changing the android:enabled and android:exported
|
|
||||||
// attributes
|
|
||||||
resValue "bool", "enableNotification", twaManifest.enableNotifications.toString()
|
|
||||||
|
|
||||||
twaManifest.shortcuts.eachWithIndex { shortcut, index ->
|
|
||||||
resValue "string", "shortcut_name_$index", "$shortcut.name"
|
|
||||||
resValue "string", "shortcut_short_name_$index", "$shortcut.short_name"
|
|
||||||
}
|
|
||||||
|
|
||||||
// The splashScreenFadeOutDuration resource is used to set the duration of fade out animation in milliseconds
|
|
||||||
// to be played when removing splash screen. The default is 0 (no animation).
|
|
||||||
resValue "integer", "splashScreenFadeOutDuration", twaManifest.splashScreenFadeOutDuration.toString()
|
|
||||||
|
|
||||||
resValue "string", "generatorApp", twaManifest.generatorApp
|
|
||||||
|
|
||||||
resValue "string", "fallbackType", twaManifest.fallbackType
|
|
||||||
|
|
||||||
resValue "bool", "enableSiteSettingsShortcut", twaManifest.enableSiteSettingsShortcut
|
|
||||||
resValue "string", "orientation", twaManifest.orientation
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
buildTypes {
|
|
||||||
release {
|
|
||||||
minifyEnabled true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
|
||||||
}
|
|
||||||
lintOptions {
|
|
||||||
checkReleaseBuilds false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
task generateShorcutsFile {
|
|
||||||
assert twaManifest.shortcuts.size() < 5, "You can have at most 4 shortcuts."
|
|
||||||
twaManifest.shortcuts.eachWithIndex { s, i ->
|
|
||||||
assert s.name != null, 'Missing `name` in shortcut #' + i
|
|
||||||
assert s.short_name != null, 'Missing `short_name` in shortcut #' + i
|
|
||||||
assert s.url != null, 'Missing `icon` in shortcut #' + i
|
|
||||||
assert s.icon != null, 'Missing `url` in shortcut #' + i
|
|
||||||
}
|
|
||||||
|
|
||||||
def shortcutsFile = new File("$projectDir/src/main/res/xml", "shortcuts.xml")
|
|
||||||
|
|
||||||
def xmlWriter = new StringWriter()
|
|
||||||
def xmlMarkup = new MarkupBuilder(new IndentPrinter(xmlWriter, " ", true))
|
|
||||||
|
|
||||||
xmlMarkup
|
|
||||||
.'shortcuts'('xmlns:android': 'http://schemas.android.com/apk/res/android') {
|
|
||||||
twaManifest.shortcuts.eachWithIndex { s, i ->
|
|
||||||
'shortcut'(
|
|
||||||
'android:shortcutId': 'shortcut' + i,
|
|
||||||
'android:enabled': 'true',
|
|
||||||
'android:icon': '@drawable/' + s.icon,
|
|
||||||
'android:shortcutShortLabel': '@string/shortcut_short_name_' + i,
|
|
||||||
'android:shortcutLongLabel': '@string/shortcut_name_' + i) {
|
|
||||||
'intent'(
|
|
||||||
'android:action': 'android.intent.action.MAIN',
|
|
||||||
'android:targetPackage': twaManifest.applicationId,
|
|
||||||
'android:targetClass': twaManifest.applicationId + '.LauncherActivity',
|
|
||||||
'android:data': s.url)
|
|
||||||
'categories'('android:name': 'android.intent.category.LAUNCHER')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
shortcutsFile.text = xmlWriter.toString() + '\n'
|
|
||||||
}
|
|
||||||
|
|
||||||
preBuild.dependsOn(generateShorcutsFile)
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
|
||||||
|
|
||||||
implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.6.2'
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
<!--
|
|
||||||
Copyright 2019 Google Inc. All Rights Reserved.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- The "package" attribute is rewritten by the Gradle build with the value of applicationId.
|
|
||||||
It is still required here, as it is used to derive paths, for instance when referring
|
|
||||||
to an Activity by ".MyActivity" instead of the full name. If more Activities are added to the
|
|
||||||
application, the package attribute will need to reflect the correct path in order to use
|
|
||||||
the abbreviated format. -->
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="com.imyeyu.gao.customer">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<application
|
|
||||||
android:name="Application"
|
|
||||||
android:allowBackup="true"
|
|
||||||
android:icon="@mipmap/ic_launcher"
|
|
||||||
android:label="@string/appName"
|
|
||||||
|
|
||||||
android:manageSpaceActivity="com.google.androidbrowserhelper.trusted.ManageDataLauncherActivity"
|
|
||||||
|
|
||||||
android:supportsRtl="true"
|
|
||||||
android:theme="@android:style/Theme.Translucent.NoTitleBar">
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="asset_statements"
|
|
||||||
android:resource="@string/assetStatements" />
|
|
||||||
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="web_manifest_url"
|
|
||||||
android:value="@string/webManifestUrl" />
|
|
||||||
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="twa_generator"
|
|
||||||
android:value="@string/generatorApp" />
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<activity android:name="com.google.androidbrowserhelper.trusted.ManageDataLauncherActivity"
|
|
||||||
android:exported="false"
|
|
||||||
android:enabled="true"
|
|
||||||
android:excludeFromRecents="true">
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.customtabs.trusted.MANAGE_SPACE_URL"
|
|
||||||
android:value="@string/launchUrl" />
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
|
|
||||||
<activity android:name="LauncherActivity"
|
|
||||||
android:alwaysRetainTaskState="true"
|
|
||||||
android:label="@string/launcherName"
|
|
||||||
android:exported="true">
|
|
||||||
<meta-data android:name="android.support.customtabs.trusted.DEFAULT_URL"
|
|
||||||
android:value="@string/launchUrl" />
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR"
|
|
||||||
android:resource="@color/colorPrimary" />
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR_DARK"
|
|
||||||
android:resource="@color/colorPrimaryDark" />
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.customtabs.trusted.NAVIGATION_BAR_COLOR"
|
|
||||||
android:resource="@color/navigationColor" />
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.customtabs.trusted.NAVIGATION_BAR_COLOR_DARK"
|
|
||||||
android:resource="@color/navigationColorDark" />
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="androix.browser.trusted.NAVIGATION_BAR_DIVIDER_COLOR"
|
|
||||||
android:resource="@color/navigationDividerColor" />
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="androix.browser.trusted.NAVIGATION_BAR_DIVIDER_COLOR_DARK"
|
|
||||||
android:resource="@color/navigationDividerColorDark" />
|
|
||||||
|
|
||||||
<meta-data android:name="android.support.customtabs.trusted.SPLASH_IMAGE_DRAWABLE"
|
|
||||||
android:resource="@drawable/splash"/>
|
|
||||||
|
|
||||||
<meta-data android:name="android.support.customtabs.trusted.SPLASH_SCREEN_BACKGROUND_COLOR"
|
|
||||||
android:resource="@color/backgroundColor"/>
|
|
||||||
|
|
||||||
<meta-data android:name="android.support.customtabs.trusted.SPLASH_SCREEN_FADE_OUT_DURATION"
|
|
||||||
android:value="@integer/splashScreenFadeOutDuration"/>
|
|
||||||
|
|
||||||
<meta-data android:name="android.support.customtabs.trusted.FILE_PROVIDER_AUTHORITY"
|
|
||||||
android:value="@string/providerAuthority"/>
|
|
||||||
|
|
||||||
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
|
|
||||||
|
|
||||||
<meta-data android:name="android.support.customtabs.trusted.FALLBACK_STRATEGY"
|
|
||||||
android:value="@string/fallbackType" />
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<meta-data android:name="android.support.customtabs.trusted.SCREEN_ORIENTATION"
|
|
||||||
android:value="@string/orientation"/>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<intent-filter android:autoVerify="true">
|
|
||||||
<action android:name="android.intent.action.VIEW"/>
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<category android:name="android.intent.category.BROWSABLE"/>
|
|
||||||
<data android:scheme="https"
|
|
||||||
android:host="@string/hostName"
|
|
||||||
|
|
||||||
/>
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity android:name="com.google.androidbrowserhelper.trusted.FocusActivity" />
|
|
||||||
|
|
||||||
<activity android:name="com.google.androidbrowserhelper.trusted.WebViewFallbackActivity"
|
|
||||||
android:configChanges="orientation|screenSize" />
|
|
||||||
|
|
||||||
<provider
|
|
||||||
android:name="androidx.core.content.FileProvider"
|
|
||||||
android:authorities="@string/providerAuthority"
|
|
||||||
android:grantUriPermissions="true"
|
|
||||||
android:exported="false">
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
|
||||||
android:resource="@xml/filepaths" />
|
|
||||||
</provider>
|
|
||||||
|
|
||||||
<service
|
|
||||||
android:name="androidx.browser.customtabs.PostMessageService"
|
|
||||||
android:exported="true" />
|
|
||||||
|
|
||||||
<service
|
|
||||||
android:name=".DelegationService"
|
|
||||||
android:enabled="@bool/enableNotification"
|
|
||||||
android:exported="@bool/enableNotification">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE"/>
|
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
|
||||||
</intent-filter>
|
|
||||||
</service>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</application>
|
|
||||||
</manifest>
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2020 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.imyeyu.gao.customer;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class Application extends android.app.Application {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
super.onCreate();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.imyeyu.gao.customer;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class DelegationService extends
|
|
||||||
com.google.androidbrowserhelper.trusted.DelegationService {
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
super.onCreate();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,322 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2020 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.imyeyu.gao.customer;
|
|
||||||
|
|
||||||
import android.content.pm.ActivityInfo;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.util.Base64;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.browser.customtabs.CustomTabsCallback;
|
|
||||||
import androidx.browser.customtabs.CustomTabsService;
|
|
||||||
import androidx.browser.customtabs.CustomTabsSession;
|
|
||||||
import com.google.androidbrowserhelper.trusted.QualityEnforcer;
|
|
||||||
import com.google.androidbrowserhelper.trusted.TwaLauncher;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class LauncherActivity
|
|
||||||
extends com.google.androidbrowserhelper.trusted.LauncherActivity {
|
|
||||||
private static final String TAG = "GaoTwaBridge";
|
|
||||||
private static final Uri WEB_ORIGIN = Uri.parse("https://gao.imyeyu.com");
|
|
||||||
private static final long CHANNEL_RETRY_DELAY_MILLIS = 500L;
|
|
||||||
private static final int MAX_CHANNEL_ATTEMPTS = 20;
|
|
||||||
|
|
||||||
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
||||||
private final CustomTabsCallback bridgeCallback = new BridgeCallback();
|
|
||||||
private TwaMediaStoreBridge mediaStoreBridge;
|
|
||||||
private CustomTabsSession postMessageSession;
|
|
||||||
private boolean originValidationRequested;
|
|
||||||
private boolean originValidated;
|
|
||||||
private boolean postMessageChannelRequested;
|
|
||||||
private boolean postMessageChannelReady;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
mediaStoreBridge = new TwaMediaStoreBridge(this);
|
|
||||||
Log.i(TAG, "TWA Activity 已创建,开始初始化媒体相册桥接");
|
|
||||||
// Setting an orientation crashes the app due to the transparent background on Android 8.0
|
|
||||||
// Oreo and below. We only set the orientation on Oreo and above. This only affects the
|
|
||||||
// splash screen and Chrome will still respect the orientation.
|
|
||||||
// See https://github.com/GoogleChromeLabs/bubblewrap/issues/496 for details.
|
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);
|
|
||||||
} else {
|
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Uri getLaunchingUrl() {
|
|
||||||
// Get the original launch Url.
|
|
||||||
Uri uri = super.getLaunchingUrl();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected CustomTabsCallback getCustomTabsCallback() {
|
|
||||||
return bridgeCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
Log.i(TAG, "TWA Activity 销毁,清理未完成的媒体传输");
|
|
||||||
if (mediaStoreBridge != null) {
|
|
||||||
mediaStoreBridge.abortAll();
|
|
||||||
}
|
|
||||||
mainHandler.removeCallbacksAndMessages(null);
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scheduleChannelRequest(int attempt) {
|
|
||||||
if (attempt >= MAX_CHANNEL_ATTEMPTS || postMessageChannelReady) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mainHandler.postDelayed(() -> requestPostMessageChannel(attempt), CHANNEL_RETRY_DELAY_MILLIS);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void requestPostMessageChannel(int attempt) {
|
|
||||||
if (isFinishing() || postMessageChannelReady) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomTabsSession session = getCustomTabsSession();
|
|
||||||
if (session == null) {
|
|
||||||
Log.w(TAG, "请求 PostMessage 通道失败:当前没有可用的 CustomTabsSession,attempt=" + attempt);
|
|
||||||
scheduleChannelRequest(attempt + 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
postMessageSession = session;
|
|
||||||
|
|
||||||
if (!originValidationRequested) {
|
|
||||||
originValidationRequested = true;
|
|
||||||
Log.i(TAG, "开始验证 TWA 来源关系:" + WEB_ORIGIN);
|
|
||||||
session.validateRelationship(CustomTabsService.RELATION_USE_AS_ORIGIN, WEB_ORIGIN, null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!originValidated || postMessageChannelRequested) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
postMessageChannelRequested = true;
|
|
||||||
boolean requested = session.requestPostMessageChannel(WEB_ORIGIN, WEB_ORIGIN, new Bundle());
|
|
||||||
Log.i(TAG, "请求 PostMessage 通道,结果=" + requested);
|
|
||||||
if (!requested) {
|
|
||||||
postMessageChannelRequested = false;
|
|
||||||
scheduleChannelRequest(attempt + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当前 Bubblewrap 生成的 Android Browser Helper 版本没有公开 TWA 会话访问器,
|
|
||||||
* 这里按字段类型读取会话,不依赖混淆后的私有字段名称。
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
private CustomTabsSession getCustomTabsSession() {
|
|
||||||
try {
|
|
||||||
Object twaLauncher = findFieldValue(this, TwaLauncher.class);
|
|
||||||
if (twaLauncher == null) {
|
|
||||||
Log.w(TAG, "未找到 TwaLauncher 实例");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
CustomTabsSession session = (CustomTabsSession) findFieldValue(twaLauncher, CustomTabsSession.class);
|
|
||||||
if (session == null) {
|
|
||||||
Log.w(TAG, "未找到 CustomTabsSession 实例");
|
|
||||||
}
|
|
||||||
return session;
|
|
||||||
} catch (ReflectiveOperationException | RuntimeException exception) {
|
|
||||||
Log.w(TAG, "读取 TWA 会话失败", exception);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static Object findFieldValue(Object target, Class<?> fieldType) throws IllegalAccessException {
|
|
||||||
Class<?> currentClass = target.getClass();
|
|
||||||
while (currentClass != null) {
|
|
||||||
for (Field field : currentClass.getDeclaredFields()) {
|
|
||||||
if (!fieldType.isAssignableFrom(field.getType())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
field.setAccessible(true);
|
|
||||||
return field.get(target);
|
|
||||||
}
|
|
||||||
currentClass = currentClass.getSuperclass();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleBridgeMessage(String message) {
|
|
||||||
if (mediaStoreBridge == null || !postMessageChannelReady) {
|
|
||||||
Log.w(TAG, "忽略媒体消息:桥接尚未就绪");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
JSONObject payload = new JSONObject(message);
|
|
||||||
String type = payload.optString("type");
|
|
||||||
String id = payload.optString("id");
|
|
||||||
Log.d(TAG, "收到网页桥接消息,type=" + type + ", id=" + id);
|
|
||||||
if ("twa-bridge-ready-ack".equals(type)) {
|
|
||||||
Log.i(TAG, "网页已确认 TWA 桥接就绪");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (id.length() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("media-start".equals(type)) {
|
|
||||||
String error = mediaStoreBridge.start(
|
|
||||||
id,
|
|
||||||
payload.optString("mimeType"),
|
|
||||||
payload.optString("fileName"),
|
|
||||||
payload.optLong("size", -1L)
|
|
||||||
);
|
|
||||||
Log.i(TAG, "开始保存媒体,id=" + id + ", mimeType=" + payload.optString("mimeType")
|
|
||||||
+ ", fileName=" + payload.optString("fileName") + ", size=" + payload.optLong("size", -1L)
|
|
||||||
+ ", result=" + (error == null ? "success" : error));
|
|
||||||
postBridgeResponse(error == null ? "media-started" : "media-error", id, null, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ("media-chunk".equals(type)) {
|
|
||||||
int index = payload.optInt("index", -1);
|
|
||||||
if (index < 0) {
|
|
||||||
mediaStoreBridge.abort(id);
|
|
||||||
postBridgeResponse("media-error", id, null, "媒体分块编号无效");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
byte[] chunk = Base64.decode(payload.optString("data"), Base64.NO_WRAP);
|
|
||||||
String error = mediaStoreBridge.append(id, index, chunk);
|
|
||||||
if (error != null || index == 0 || index % 16 == 0) {
|
|
||||||
Log.d(TAG, "写入媒体分块,id=" + id + ", index=" + index + ", bytes=" + chunk.length
|
|
||||||
+ ", result=" + (error == null ? "success" : error));
|
|
||||||
}
|
|
||||||
postBridgeResponse(error == null ? "media-chunk-ack" : "media-error", id, index, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ("media-finish".equals(type)) {
|
|
||||||
String error = mediaStoreBridge.finish(id);
|
|
||||||
Log.i(TAG, "完成保存媒体,id=" + id + ", result=" + (error == null ? "success" : error));
|
|
||||||
postBridgeResponse(error == null ? "media-saved" : "media-error", id, null, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ("media-abort".equals(type)) {
|
|
||||||
Log.w(TAG, "网页主动中止媒体保存,id=" + id);
|
|
||||||
mediaStoreBridge.abort(id);
|
|
||||||
}
|
|
||||||
} catch (Exception exception) {
|
|
||||||
Log.e(TAG, "解析 TWA 媒体消息失败,原始消息长度=" + message.length(), exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void postBridgeResponse(String type, String id, @Nullable Integer index, @Nullable String error) {
|
|
||||||
JSONObject response = new JSONObject();
|
|
||||||
try {
|
|
||||||
response.put("type", type);
|
|
||||||
response.put("id", id);
|
|
||||||
if (index != null) {
|
|
||||||
response.put("index", index);
|
|
||||||
}
|
|
||||||
if (error != null) {
|
|
||||||
response.put("error", error);
|
|
||||||
}
|
|
||||||
} catch (Exception exception) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mainHandler.post(() -> {
|
|
||||||
if (!postMessageChannelReady || postMessageSession == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int result = postMessageSession.postMessage(response.toString(), null);
|
|
||||||
Log.d(TAG, "发送桥接响应,type=" + type + ", id=" + id + ", result=" + result);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class BridgeCallback extends QualityEnforcer {
|
|
||||||
@Override
|
|
||||||
public void onNavigationEvent(int navigationEvent, @Nullable Bundle extras) {
|
|
||||||
super.onNavigationEvent(navigationEvent, extras);
|
|
||||||
Log.d(TAG, "TWA 导航事件=" + navigationEvent);
|
|
||||||
if (navigationEvent == NAVIGATION_FINISHED) {
|
|
||||||
scheduleChannelRequest(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRelationshipValidationResult(
|
|
||||||
int relation,
|
|
||||||
@Nullable Uri requestedOrigin,
|
|
||||||
boolean result,
|
|
||||||
@Nullable Bundle extras
|
|
||||||
) {
|
|
||||||
super.onRelationshipValidationResult(relation, requestedOrigin, result, extras);
|
|
||||||
if (relation != CustomTabsService.RELATION_USE_AS_ORIGIN || !WEB_ORIGIN.equals(requestedOrigin)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
originValidated = result;
|
|
||||||
Log.i(TAG, "TWA 来源验证结果=" + result + ", origin=" + requestedOrigin);
|
|
||||||
if (result) {
|
|
||||||
scheduleChannelRequest(0);
|
|
||||||
} else {
|
|
||||||
Log.w(TAG, "TWA 来源验证失败,请检查 assetlinks.json");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessageChannelReady(@Nullable Bundle extras) {
|
|
||||||
super.onMessageChannelReady(extras);
|
|
||||||
postMessageChannelReady = true;
|
|
||||||
Log.i(TAG, "PostMessage 通道已就绪");
|
|
||||||
postMessageSession = getCustomTabsSession();
|
|
||||||
if (postMessageSession == null) {
|
|
||||||
Log.e(TAG, "PostMessage 通道已就绪,但无法获取 CustomTabsSession");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JSONObject readyMessage = new JSONObject();
|
|
||||||
try {
|
|
||||||
readyMessage.put("type", "twa-bridge-ready");
|
|
||||||
readyMessage.put("version", 1);
|
|
||||||
} catch (Exception exception) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int result = postMessageSession.postMessage(readyMessage.toString(), null);
|
|
||||||
Log.i(TAG, "发送 TWA 桥接就绪消息,result=" + result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPostMessage(String message, @Nullable Bundle extras) {
|
|
||||||
super.onPostMessage(message, extras);
|
|
||||||
handleBridgeMessage(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,249 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2026 imyeyu.com
|
|
||||||
*
|
|
||||||
* MIT License
|
|
||||||
*/
|
|
||||||
package com.imyeyu.gao.customer;
|
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.provider.MediaStore;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 TWA 传来的媒体分块写入 Android 系统相册。
|
|
||||||
*/
|
|
||||||
final class TwaMediaStoreBridge {
|
|
||||||
private static final String TAG = "GaoTwaMediaStore";
|
|
||||||
private static final long MAX_MEDIA_SIZE = 512L * 1024L * 1024L;
|
|
||||||
private static final int BUFFER_SIZE = 64 * 1024;
|
|
||||||
|
|
||||||
private final ContentResolver contentResolver;
|
|
||||||
private final Map<String, PendingMedia> pendingMediaMap = new HashMap<>();
|
|
||||||
|
|
||||||
TwaMediaStoreBridge(Context context) {
|
|
||||||
contentResolver = context.getContentResolver();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized String start(
|
|
||||||
String id,
|
|
||||||
String mimeType,
|
|
||||||
String fileName,
|
|
||||||
long expectedSize
|
|
||||||
) {
|
|
||||||
Log.i(TAG, "准备创建相册媒体,id=" + id + ", mimeType=" + mimeType + ", fileName=" + fileName
|
|
||||||
+ ", expectedSize=" + expectedSize + ", sdk=" + Build.VERSION.SDK_INT);
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
|
||||||
Log.w(TAG, "Android 版本低于 10,无法无权限写入相册");
|
|
||||||
return "Android 10 以下系统不支持无权限写入系统相册";
|
|
||||||
}
|
|
||||||
if (id.length() == 0 || id.length() > 128) {
|
|
||||||
return "媒体标识无效";
|
|
||||||
}
|
|
||||||
if (pendingMediaMap.containsKey(id)) {
|
|
||||||
return "媒体传输已存在";
|
|
||||||
}
|
|
||||||
if (expectedSize <= 0 || expectedSize > MAX_MEDIA_SIZE) {
|
|
||||||
return "媒体文件大小超出限制";
|
|
||||||
}
|
|
||||||
|
|
||||||
String normalizedMimeType = normalizeMimeType(mimeType);
|
|
||||||
if (normalizedMimeType == null) {
|
|
||||||
return "只支持照片和视频";
|
|
||||||
}
|
|
||||||
|
|
||||||
Uri mediaUri = null;
|
|
||||||
try {
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put(MediaStore.MediaColumns.DISPLAY_NAME, buildDisplayName(fileName, normalizedMimeType));
|
|
||||||
values.put(MediaStore.MediaColumns.MIME_TYPE, normalizedMimeType);
|
|
||||||
values.put(MediaStore.MediaColumns.RELATIVE_PATH, buildRelativePath(normalizedMimeType));
|
|
||||||
values.put(MediaStore.MediaColumns.IS_PENDING, 1);
|
|
||||||
|
|
||||||
mediaUri = contentResolver.insert(getCollectionUri(normalizedMimeType), values);
|
|
||||||
if (mediaUri == null) {
|
|
||||||
Log.e(TAG, "MediaStore insert 返回空 Uri,id=" + id);
|
|
||||||
return "创建相册媒体失败";
|
|
||||||
}
|
|
||||||
|
|
||||||
OutputStream outputStream = contentResolver.openOutputStream(mediaUri);
|
|
||||||
if (outputStream == null) {
|
|
||||||
deleteQuietly(mediaUri);
|
|
||||||
Log.e(TAG, "无法打开 MediaStore 输出流,id=" + id + ", uri=" + mediaUri);
|
|
||||||
return "打开相册媒体失败";
|
|
||||||
}
|
|
||||||
pendingMediaMap.put(id, new PendingMedia(mediaUri, outputStream, expectedSize));
|
|
||||||
Log.i(TAG, "相册媒体创建成功,id=" + id + ", uri=" + mediaUri + ", path="
|
|
||||||
+ buildRelativePath(normalizedMimeType));
|
|
||||||
return null;
|
|
||||||
} catch (Exception exception) {
|
|
||||||
if (mediaUri != null) {
|
|
||||||
deleteQuietly(mediaUri);
|
|
||||||
}
|
|
||||||
Log.e(TAG, "创建相册媒体异常,id=" + id, exception);
|
|
||||||
return "创建相册媒体失败";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized String append(String id, int index, byte[] chunk) {
|
|
||||||
PendingMedia pendingMedia = pendingMediaMap.get(id);
|
|
||||||
if (pendingMedia == null) {
|
|
||||||
return "媒体传输不存在";
|
|
||||||
}
|
|
||||||
if (index != pendingMedia.nextChunkIndex) {
|
|
||||||
abort(id);
|
|
||||||
return "媒体分块顺序错误";
|
|
||||||
}
|
|
||||||
if (chunk.length == 0 || pendingMedia.receivedSize + chunk.length > pendingMedia.expectedSize) {
|
|
||||||
abort(id);
|
|
||||||
return "媒体分块大小错误";
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
pendingMedia.outputStream.write(chunk);
|
|
||||||
pendingMedia.outputStream.flush();
|
|
||||||
pendingMedia.receivedSize += chunk.length;
|
|
||||||
pendingMedia.nextChunkIndex++;
|
|
||||||
return null;
|
|
||||||
} catch (IOException exception) {
|
|
||||||
abort(id);
|
|
||||||
Log.e(TAG, "写入相册媒体异常,id=" + id + ", index=" + index, exception);
|
|
||||||
return "写入相册媒体失败";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized String finish(String id) {
|
|
||||||
PendingMedia pendingMedia = pendingMediaMap.remove(id);
|
|
||||||
if (pendingMedia == null) {
|
|
||||||
return "媒体传输不存在";
|
|
||||||
}
|
|
||||||
if (pendingMedia.receivedSize != pendingMedia.expectedSize) {
|
|
||||||
closeQuietly(pendingMedia.outputStream);
|
|
||||||
deleteQuietly(pendingMedia.mediaUri);
|
|
||||||
Log.e(TAG, "媒体内容不完整,id=" + id + ", received=" + pendingMedia.receivedSize
|
|
||||||
+ ", expected=" + pendingMedia.expectedSize);
|
|
||||||
return "媒体内容不完整";
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
pendingMedia.outputStream.flush();
|
|
||||||
pendingMedia.outputStream.close();
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put(MediaStore.MediaColumns.IS_PENDING, 0);
|
|
||||||
if (contentResolver.update(pendingMedia.mediaUri, values, null, null) != 1) {
|
|
||||||
deleteQuietly(pendingMedia.mediaUri);
|
|
||||||
Log.e(TAG, "发布相册媒体失败,MediaStore update 返回 0,id=" + id);
|
|
||||||
return "发布相册媒体失败";
|
|
||||||
}
|
|
||||||
Log.i(TAG, "相册媒体发布成功,id=" + id + ", uri=" + pendingMedia.mediaUri
|
|
||||||
+ ", bytes=" + pendingMedia.receivedSize);
|
|
||||||
return null;
|
|
||||||
} catch (Exception exception) {
|
|
||||||
closeQuietly(pendingMedia.outputStream);
|
|
||||||
deleteQuietly(pendingMedia.mediaUri);
|
|
||||||
Log.e(TAG, "保存相册媒体异常,id=" + id, exception);
|
|
||||||
return "保存相册媒体失败";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized void abort(String id) {
|
|
||||||
PendingMedia pendingMedia = pendingMediaMap.remove(id);
|
|
||||||
if (pendingMedia == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
closeQuietly(pendingMedia.outputStream);
|
|
||||||
deleteQuietly(pendingMedia.mediaUri);
|
|
||||||
Log.w(TAG, "已清理中止的相册媒体,id=" + id + ", uri=" + pendingMedia.mediaUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized void abortAll() {
|
|
||||||
for (PendingMedia pendingMedia : pendingMediaMap.values()) {
|
|
||||||
closeQuietly(pendingMedia.outputStream);
|
|
||||||
deleteQuietly(pendingMedia.mediaUri);
|
|
||||||
}
|
|
||||||
pendingMediaMap.clear();
|
|
||||||
Log.i(TAG, "已清理全部未完成的相册媒体");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static String normalizeMimeType(String mimeType) {
|
|
||||||
String normalizedMimeType = mimeType == null ? "" : mimeType.trim().toLowerCase(Locale.ROOT);
|
|
||||||
if (normalizedMimeType.startsWith("image/")) {
|
|
||||||
return normalizedMimeType.equals("image/*") ? "image/jpeg" : normalizedMimeType;
|
|
||||||
}
|
|
||||||
if (normalizedMimeType.startsWith("video/")) {
|
|
||||||
return normalizedMimeType.equals("video/*") ? "video/mp4" : normalizedMimeType;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Uri getCollectionUri(String mimeType) {
|
|
||||||
if (mimeType.startsWith("video/")) {
|
|
||||||
return MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
|
||||||
}
|
|
||||||
return MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String buildRelativePath(String mimeType) {
|
|
||||||
if (mimeType.startsWith("video/")) {
|
|
||||||
return Environment.DIRECTORY_MOVIES + "/糕店管理";
|
|
||||||
}
|
|
||||||
return Environment.DIRECTORY_PICTURES + "/糕店管理";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String buildDisplayName(String fileName, String mimeType) {
|
|
||||||
String safeFileName = fileName == null ? "" : fileName
|
|
||||||
.replaceAll("[^A-Za-z0-9._-]", "_")
|
|
||||||
.replaceAll("^\\.+$", "");
|
|
||||||
if (safeFileName.length() == 0) {
|
|
||||||
safeFileName = "capture-" + System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
if (safeFileName.lastIndexOf('.') < 0) {
|
|
||||||
safeFileName += mimeType.startsWith("video/") ? ".mp4" : ".jpg";
|
|
||||||
}
|
|
||||||
return safeFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteQuietly(Uri uri) {
|
|
||||||
try {
|
|
||||||
contentResolver.delete(uri, null, null);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
// 相册清理失败时不能覆盖原始错误。
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void closeQuietly(OutputStream outputStream) {
|
|
||||||
try {
|
|
||||||
outputStream.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
// 关闭失败时继续清理媒体记录。
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class PendingMedia {
|
|
||||||
private final Uri mediaUri;
|
|
||||||
private final OutputStream outputStream;
|
|
||||||
private final long expectedSize;
|
|
||||||
private long receivedSize;
|
|
||||||
private int nextChunkIndex;
|
|
||||||
|
|
||||||
private PendingMedia(Uri mediaUri, OutputStream outputStream, long expectedSize) {
|
|
||||||
this.mediaUri = mediaUri;
|
|
||||||
this.outputStream = new BufferedOutputStream(outputStream, BUFFER_SIZE);
|
|
||||||
this.expectedSize = expectedSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<!--
|
|
||||||
Copyright 2020 Google Inc. All Rights Reserved.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
<inset xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:aapt="http://schemas.android.com/aapt"
|
|
||||||
android:inset="2dp">
|
|
||||||
<aapt:attr name="android:drawable">
|
|
||||||
<shape android:shape="oval">
|
|
||||||
<solid android:color="@color/shortcut_background" />
|
|
||||||
<size android:width="44dp" android:height="44dp" />
|
|
||||||
</shape>
|
|
||||||
</aapt:attr>
|
|
||||||
</inset>
|
|
||||||
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 47 KiB |
|
Before Width: | Height: | Size: 74 KiB |
@@ -1,33 +0,0 @@
|
|||||||
<!--
|
|
||||||
Copyright 2019 Google Inc. All Rights Reserved.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:aapt="http://schemas.android.com/aapt">
|
|
||||||
<background>
|
|
||||||
<layer-list>
|
|
||||||
<item android:drawable="@android:color/white" />
|
|
||||||
<!--
|
|
||||||
The paddings below give the icons a similar proportion as the
|
|
||||||
icon generated by WebAPKs.
|
|
||||||
-->
|
|
||||||
<item android:drawable="@mipmap/ic_maskable"
|
|
||||||
android:top="8.5dp"
|
|
||||||
android:right="8.5dp"
|
|
||||||
android:left="8.5dp"
|
|
||||||
android:bottom="8.5dp" />
|
|
||||||
</layer-list>
|
|
||||||
</background>
|
|
||||||
<foreground android:drawable="@android:color/transparent" />
|
|
||||||
</adaptive-icon>
|
|
||||||
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 10 KiB |
@@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "Gao Customer H5",
|
|
||||||
"short_name": "Gao H5",
|
|
||||||
"display": "standalone",
|
|
||||||
"background_color": "#ffffff",
|
|
||||||
"theme_color": "#ffffff",
|
|
||||||
"start_url": "/",
|
|
||||||
"scope": "/",
|
|
||||||
"icons": [
|
|
||||||
{
|
|
||||||
"src": "/icons/icon-192.png",
|
|
||||||
"sizes": "192x192",
|
|
||||||
"type": "image/png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "/icons/icon-512.png",
|
|
||||||
"sizes": "512x512",
|
|
||||||
"type": "image/png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "/icons/icon-maskable-512.png",
|
|
||||||
"sizes": "512x512",
|
|
||||||
"type": "image/png",
|
|
||||||
"purpose": "maskable"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<!--
|
|
||||||
Copyright 2020 Google Inc. All Rights Reserved.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<color name="shortcut_background">#F5F5F5</color>
|
|
||||||
</resources>
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright 2021 Google Inc. All Rights Reserved.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
The "fullscreen" and "fullscreen-sticky" TWA manifest values correspond to "immersive" and "sticky-immersive"
|
|
||||||
AndroidManifest values.
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
This variable below expresses the relationship between the app and the site,
|
|
||||||
as documented in the TWA documentation at
|
|
||||||
https://developers.google.com/web/updates/2017/10/using-twa#set_up_digital_asset_links_in_an_android_app
|
|
||||||
and is injected into the AndroidManifest.xml
|
|
||||||
-->
|
|
||||||
<string name="assetStatements">
|
|
||||||
[{
|
|
||||||
\"relation\": [\"delegate_permission/common.handle_all_urls\"],
|
|
||||||
\"target\": {
|
|
||||||
\"namespace\": \"web\",
|
|
||||||
\"site\": \"https://gao.imyeyu.com\"
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
|
|
||||||
</string>
|
|
||||||
</resources>
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<!--
|
|
||||||
Copyright 2019 Google Inc. All Rights Reserved.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
<paths>
|
|
||||||
<files-path path="twa_splash/" name="twa_splash" />
|
|
||||||
</paths>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<shortcuts xmlns:android='http://schemas.android.com/apk/res/android' />
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2019 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
|
||||||
|
|
||||||
buildscript {
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
google()
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath 'com.android.tools.build:gradle:8.9.1'
|
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
|
||||||
// in the individual module build.gradle files
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
allprojects {
|
|
||||||
repositories {
|
|
||||||
google()
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
task clean(type: Delete) {
|
|
||||||
delete rootProject.buildDir
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
# Project-wide Gradle settings.
|
|
||||||
# IDE (e.g. Android Studio) users:
|
|
||||||
# Gradle settings configured through the IDE *will override*
|
|
||||||
# any settings specified in this file.
|
|
||||||
# For more details on how to configure your build environment visit
|
|
||||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
|
||||||
# Specifies the JVM arguments used for the daemon process.
|
|
||||||
# The setting is particularly useful for tweaking memory settings.
|
|
||||||
org.gradle.jvmargs=-Xmx1536m
|
|
||||||
# When configured, Gradle will run in incubating parallel mode.
|
|
||||||
# This option should only be used with decoupled projects. More details, visit
|
|
||||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
|
||||||
# org.gradle.parallel=true
|
|
||||||
android.useAndroidX=true
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
|
||||||
distributionPath=wrapper/dists
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
|
||||||
networkTimeout=10000
|
|
||||||
validateDistributionUrl=true
|
|
||||||
@@ -1,249 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
#
|
|
||||||
# Copyright © 2015-2021 the original authors.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
#
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Gradle start up script for POSIX generated by Gradle.
|
|
||||||
#
|
|
||||||
# Important for running:
|
|
||||||
#
|
|
||||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
|
||||||
# noncompliant, but you have some other compliant shell such as ksh or
|
|
||||||
# bash, then to run this script, type that shell name before the whole
|
|
||||||
# command line, like:
|
|
||||||
#
|
|
||||||
# ksh Gradle
|
|
||||||
#
|
|
||||||
# Busybox and similar reduced shells will NOT work, because this script
|
|
||||||
# requires all of these POSIX shell features:
|
|
||||||
# * functions;
|
|
||||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
|
||||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
|
||||||
# * compound commands having a testable exit status, especially «case»;
|
|
||||||
# * various built-in commands including «command», «set», and «ulimit».
|
|
||||||
#
|
|
||||||
# Important for patching:
|
|
||||||
#
|
|
||||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
|
||||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
|
||||||
#
|
|
||||||
# The "traditional" practice of packing multiple parameters into a
|
|
||||||
# space-separated string is a well documented source of bugs and security
|
|
||||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
|
||||||
# options in "$@", and eventually passing that to Java.
|
|
||||||
#
|
|
||||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
|
||||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
|
||||||
# see the in-line comments for details.
|
|
||||||
#
|
|
||||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
|
||||||
# Darwin, MinGW, and NonStop.
|
|
||||||
#
|
|
||||||
# (3) This script is generated from the Groovy template
|
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
|
||||||
# within the Gradle project.
|
|
||||||
#
|
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
|
||||||
app_path=$0
|
|
||||||
|
|
||||||
# Need this for daisy-chained symlinks.
|
|
||||||
while
|
|
||||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
|
||||||
[ -h "$app_path" ]
|
|
||||||
do
|
|
||||||
ls=$( ls -ld "$app_path" )
|
|
||||||
link=${ls#*' -> '}
|
|
||||||
case $link in #(
|
|
||||||
/*) app_path=$link ;; #(
|
|
||||||
*) app_path=$APP_HOME$link ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# This is normally unused
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
APP_BASE_NAME=${0##*/}
|
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
||||||
MAX_FD=maximum
|
|
||||||
|
|
||||||
warn () {
|
|
||||||
echo "$*"
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
die () {
|
|
||||||
echo
|
|
||||||
echo "$*"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
|
||||||
cygwin=false
|
|
||||||
msys=false
|
|
||||||
darwin=false
|
|
||||||
nonstop=false
|
|
||||||
case "$( uname )" in #(
|
|
||||||
CYGWIN* ) cygwin=true ;; #(
|
|
||||||
Darwin* ) darwin=true ;; #(
|
|
||||||
MSYS* | MINGW* ) msys=true ;; #(
|
|
||||||
NONSTOP* ) nonstop=true ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
|
||||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
|
||||||
else
|
|
||||||
JAVACMD=$JAVA_HOME/bin/java
|
|
||||||
fi
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
JAVACMD=java
|
|
||||||
if ! command -v java >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|
||||||
case $MAX_FD in #(
|
|
||||||
max*)
|
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
|
||||||
# shellcheck disable=SC2039,SC3045
|
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
|
||||||
warn "Could not query maximum file descriptor limit"
|
|
||||||
esac
|
|
||||||
case $MAX_FD in #(
|
|
||||||
'' | soft) :;; #(
|
|
||||||
*)
|
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
|
||||||
# shellcheck disable=SC2039,SC3045
|
|
||||||
ulimit -n "$MAX_FD" ||
|
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Collect all arguments for the java command, stacking in reverse order:
|
|
||||||
# * args from the command line
|
|
||||||
# * the main class name
|
|
||||||
# * -classpath
|
|
||||||
# * -D...appname settings
|
|
||||||
# * --module-path (only if needed)
|
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if "$cygwin" || "$msys" ; then
|
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
|
||||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
|
||||||
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
for arg do
|
|
||||||
if
|
|
||||||
case $arg in #(
|
|
||||||
-*) false ;; # don't mess with options #(
|
|
||||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
|
||||||
[ -e "$t" ] ;; #(
|
|
||||||
*) false ;;
|
|
||||||
esac
|
|
||||||
then
|
|
||||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
|
||||||
fi
|
|
||||||
# Roll the args list around exactly as many times as the number of
|
|
||||||
# args, so each arg winds up back in the position where it started, but
|
|
||||||
# possibly modified.
|
|
||||||
#
|
|
||||||
# NB: a `for` loop captures its iteration list before it begins, so
|
|
||||||
# changing the positional parameters here affects neither the number of
|
|
||||||
# iterations, nor the values presented in `arg`.
|
|
||||||
shift # remove old arg
|
|
||||||
set -- "$@" "$arg" # push replacement arg
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Collect all arguments for the java command:
|
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
|
||||||
# and any embedded shellness will be escaped.
|
|
||||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
|
||||||
# treated as '${Hostname}' itself on the command line.
|
|
||||||
|
|
||||||
set -- \
|
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
|
||||||
-classpath "$CLASSPATH" \
|
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
|
||||||
"$@"
|
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
|
||||||
if ! command -v xargs >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
die "xargs is not available"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Use "xargs" to parse quoted args.
|
|
||||||
#
|
|
||||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
|
||||||
#
|
|
||||||
# In Bash we could simply go:
|
|
||||||
#
|
|
||||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
|
||||||
# set -- "${ARGS[@]}" "$@"
|
|
||||||
#
|
|
||||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
|
||||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
|
||||||
# character that might be a shell metacharacter, then use eval to reverse
|
|
||||||
# that process (while maintaining the separation between arguments), and wrap
|
|
||||||
# the whole thing up as a single "set" statement.
|
|
||||||
#
|
|
||||||
# This will of course break if any of these variables contains a newline or
|
|
||||||
# an unmatched quote.
|
|
||||||
#
|
|
||||||
|
|
||||||
eval "set -- $(
|
|
||||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
|
||||||
xargs -n1 |
|
|
||||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
|
||||||
tr '\n' ' '
|
|
||||||
)" '"$@"'
|
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
@rem
|
|
||||||
@rem Copyright 2015 the original author or authors.
|
|
||||||
@rem
|
|
||||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
@rem you may not use this file except in compliance with the License.
|
|
||||||
@rem You may obtain a copy of the License at
|
|
||||||
@rem
|
|
||||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
@rem
|
|
||||||
@rem Unless required by applicable law or agreed to in writing, software
|
|
||||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
@rem See the License for the specific language governing permissions and
|
|
||||||
@rem limitations under the License.
|
|
||||||
@rem
|
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
|
||||||
@rem ##########################################################################
|
|
||||||
@rem
|
|
||||||
@rem Gradle startup script for Windows
|
|
||||||
@rem
|
|
||||||
@rem ##########################################################################
|
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
|
||||||
@rem This is normally unused
|
|
||||||
set APP_BASE_NAME=%~n0
|
|
||||||
set APP_HOME=%DIRNAME%
|
|
||||||
|
|
||||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
||||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
|
||||||
|
|
||||||
@rem Find java.exe
|
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
|
||||||
|
|
||||||
echo. 1>&2
|
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
|
||||||
echo. 1>&2
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
|
||||||
echo location of your Java installation. 1>&2
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
|
||||||
|
|
||||||
echo. 1>&2
|
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
|
||||||
echo. 1>&2
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
|
||||||
echo location of your Java installation. 1>&2
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:execute
|
|
||||||
@rem Setup the command line
|
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
|
||||||
|
|
||||||
:end
|
|
||||||
@rem End local scope for the variables with windows NT shell
|
|
||||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
|
||||||
|
|
||||||
:fail
|
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
||||||
rem the _cmd.exe /c_ return code!
|
|
||||||
set EXIT_CODE=%ERRORLEVEL%
|
|
||||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
|
||||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
|
||||||
exit /b %EXIT_CODE%
|
|
||||||
|
|
||||||
:mainEnd
|
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
|
||||||
|
|
||||||
:omega
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
dff2536399b4ac0116642fb1c752408b59929697
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
include ':app'
|
|
||||||
|
Before Width: | Height: | Size: 13 KiB |
@@ -1,47 +0,0 @@
|
|||||||
{
|
|
||||||
"packageId": "com.imyeyu.gao.customer",
|
|
||||||
"host": "gao.imyeyu.com",
|
|
||||||
"name": "糕店客户管理",
|
|
||||||
"launcherName": "糕店管理",
|
|
||||||
"display": "standalone",
|
|
||||||
"themeColor": "#FFFFFF",
|
|
||||||
"themeColorDark": "#000000",
|
|
||||||
"navigationColor": "#000000",
|
|
||||||
"navigationColorDark": "#000000",
|
|
||||||
"navigationDividerColor": "#000000",
|
|
||||||
"navigationDividerColorDark": "#000000",
|
|
||||||
"backgroundColor": "#FFFFFF",
|
|
||||||
"enableNotifications": false,
|
|
||||||
"startUrl": "/",
|
|
||||||
"iconUrl": "https://gao.imyeyu.com/icons/icon-512.png",
|
|
||||||
"maskableIconUrl": "https://gao.imyeyu.com/icons/icon-maskable-512.png",
|
|
||||||
"splashScreenFadeOutDuration": 300,
|
|
||||||
"signingKey": {
|
|
||||||
"path": "./android.keystore",
|
|
||||||
"alias": "gao-customer"
|
|
||||||
},
|
|
||||||
"appVersionName": "1",
|
|
||||||
"appVersionCode": 1,
|
|
||||||
"shortcuts": [],
|
|
||||||
"generatorApp": "bubblewrap-cli",
|
|
||||||
"webManifestUrl": "https://gao.imyeyu.com/manifest.webmanifest",
|
|
||||||
"fallbackType": "customtabs",
|
|
||||||
"features": {},
|
|
||||||
"alphaDependencies": {
|
|
||||||
"enabled": false
|
|
||||||
},
|
|
||||||
"enableSiteSettingsShortcut": true,
|
|
||||||
"isChromeOSOnly": false,
|
|
||||||
"isMetaQuest": false,
|
|
||||||
"fullScopeUrl": "https://gao.imyeyu.com/",
|
|
||||||
"minSdkVersion": 21,
|
|
||||||
"orientation": "portrait",
|
|
||||||
"fingerprints": [],
|
|
||||||
"additionalTrustedOrigins": [],
|
|
||||||
"retainedBundles": [],
|
|
||||||
"protocolHandlers": [],
|
|
||||||
"fileHandlers": [],
|
|
||||||
"launchHandlerClientMode": "",
|
|
||||||
"displayOverride": [],
|
|
||||||
"appVersion": "1"
|
|
||||||
}
|
|
||||||