@androperator/emulator-macos-tweaks 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -19
- package/assets/launcher/launcher +0 -0
- package/assets/launcher/manifest.json +2 -2
- package/package.json +1 -1
- package/src/core.js +18 -18
- package/src/names.js +10 -7
- package/src/launch.mjs +0 -72
package/README.md
CHANGED
|
@@ -16,12 +16,13 @@ This is an independent CLI. It does not depend on ADBuddy or change emulator lau
|
|
|
16
16
|
|
|
17
17
|
## Requirements and supported builds
|
|
18
18
|
|
|
19
|
-
- macOS 14 or newer
|
|
19
|
+
- macOS 14 or newer. The CLI requires Node.js 22 or newer.
|
|
20
20
|
- Write access to your Android SDK and backup location; do not run with sudo.
|
|
21
|
-
-
|
|
22
|
-
- Executable SHA-256: `eaa97a970b81f81640db73ed79e19ee173323653a0a1203217e1199d078011f3`.
|
|
21
|
+
- An Apple Silicon Android Emulator GUI binary with a compatible Mach-O layout and embedded icons.
|
|
23
22
|
|
|
24
|
-
The reference build is 37.1.11, build 15917651.
|
|
23
|
+
The reference build is 37.1.11, build 15917651. Compatibility checks use the
|
|
24
|
+
executable structure and embedded icon contents across SDK revisions, including
|
|
25
|
+
different major versions. Intel binaries are unsupported.
|
|
25
26
|
|
|
26
27
|
Patching replaces Google's signature with a **local ad-hoc signature**, preserving the original entitlements and hardened runtime. The modified emulator is no longer Google-signed or notarized. No developer certificate or private key is used. Gatekeeper may treat the patched emulator differently. The CLI does not disable Gatekeeper or change system security settings.
|
|
27
28
|
|
|
@@ -92,12 +93,11 @@ reports `names` and `namingHealthy`; `restore` restores the exact original
|
|
|
92
93
|
backend and removes an unchanged managed naming configuration. Unrecognized
|
|
93
94
|
configuration files are never overwritten or deleted.
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
backup directory in place: it contains the backend, dispatcher, launch script,
|
|
96
|
+
The native dispatcher prepares launches without Node.js. If you installed an
|
|
97
|
+
earlier Node-backed naming patch, reapply with this CLI to migrate it. Keep the
|
|
98
|
+
printed backup directory in place. It contains the backend, dispatcher,
|
|
99
99
|
configuration and per-AVD SDK copies. Missing or corrupt naming resources stop
|
|
100
|
-
launching with an error
|
|
100
|
+
launching with an error. The CLI can still restore the original.
|
|
101
101
|
The first launch copies the backend for that AVD. Later launches reuse the
|
|
102
102
|
hash-verified copy. These copies link SDK libraries and system images and must
|
|
103
103
|
not be used for SDK maintenance. No AVD data is copied or renamed.
|
|
@@ -120,7 +120,7 @@ node scripts/verify-names.mjs
|
|
|
120
120
|
|
|
121
121
|
Tests use synthetic executables and fake process integrations. They require neither an Android SDK nor a device. macOS CI runs on Node.js 22 and 24. Real signing and boot checks supplement these tests for the supported build.
|
|
122
122
|
|
|
123
|
-
To add support for a build, use an untouched, signature-verified vendor executable. Record its revision, build ID, architecture, full SHA-256, and each original PNG hash and allocation length in `src/profiles.json`. The patcher discovers images by content rather than fixed offsets. Provide replacement PNGs that fit those allocations exactly, with valid chunks and checksums. Verify signing, boot, Dock appearance, and exact restore on that build before adding it to the support table. New layouts require a new verified profile; compatible
|
|
123
|
+
To add support for a build, use an untouched, signature-verified vendor executable. Record its revision, build ID, architecture, full SHA-256, and each original PNG hash and allocation length in `src/profiles.json`. The patcher discovers images by content rather than fixed offsets. Provide replacement PNGs that fit those allocations exactly, with valid chunks and checksums. Verify signing, boot, Dock appearance, and exact restore on that build before adding it to the support table. New layouts require a new verified profile; a compatible new build does not require a separate profile.
|
|
124
124
|
|
|
125
125
|
The editable `assets/Emulator.icon` source uses a vector phone/Android symbol, white background, and Apple's native icon renderer. The bundled 32, 128 and 256 pixel PNGs were compiled with Xcode's asset compiler and palette-compressed to fit the emulator's allocations. Xcode is not required by CLI users. Native helper source is in `native/`; `node scripts/build-runtime.mjs` rebuilds the packaged arm64 helper and all five icons and writes their content manifest. `npm run build:launcher` rebuilds the AVD dispatcher and its manifest. Rebuild and run native verification after changing those sources; review the regenerated manifest and runtime files together.
|
|
126
126
|
|
|
@@ -138,12 +138,11 @@ Copyright (C) 2026 Action Launcher Pty Ltd
|
|
|
138
138
|
|
|
139
139
|
### Compatibility across SDK updates
|
|
140
140
|
|
|
141
|
-
Apple Silicon
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
SDK-update protection remain in effect.
|
|
141
|
+
Apple Silicon builds can be patched when their arm64 Mach-O structure and
|
|
142
|
+
embedded icons match a bundled profile. The patcher checks icon contents,
|
|
143
|
+
dimensions, checksums, unique allocations and load-command padding. Status JSON
|
|
144
|
+
includes `supportedVersions` and `compatibilityReason` for diagnosis.
|
|
145
|
+
|
|
146
|
+
Apply and restore still verify exact hashes for the installed executable and
|
|
147
|
+
its backups. The dispatcher also checks that the SDK revision matches the
|
|
148
|
+
patch generation before launching a cached backend against that SDK's libraries.
|
package/assets/launcher/launcher
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/src/core.js
CHANGED
|
@@ -7,7 +7,7 @@ import { sha256, patchImages, locateIcons } from './png.js';
|
|
|
7
7
|
import { macOS } from './platform.js';
|
|
8
8
|
import { addIconHelper } from './macho.js';
|
|
9
9
|
import { readRuntime, copyRuntime, verifyRuntime, runtimeHash } from './runtime.js';
|
|
10
|
-
import { readNamingBundle, configurationHash, verifyNaming, installConfiguration, removeConfiguration } from './names.js';
|
|
10
|
+
import { readNamingBundle, configurationHash, isNamingReceipt, verifyNaming, installConfiguration, removeConfiguration } from './names.js';
|
|
11
11
|
const packageRoot = fileURLToPath(new URL('../', import.meta.url));
|
|
12
12
|
const bundledProfiles = JSON.parse(await readFile(new URL('./profiles.json', import.meta.url)));
|
|
13
13
|
const hashFile = async file => sha256(await readFile(file));
|
|
@@ -16,8 +16,8 @@ async function resolveProfile(bytes, revision, profiles, binary) {
|
|
|
16
16
|
const hash = sha256(bytes);
|
|
17
17
|
const exact = profiles.find(item => item.revision === revision && item.sha256 === hash && item.binary === binary);
|
|
18
18
|
if (exact) return { profile: exact, compatibilityReason: null };
|
|
19
|
-
const candidates = profiles.filter(item => item.
|
|
20
|
-
if (!candidates.length) return { profile: null, compatibilityReason:
|
|
19
|
+
const candidates = profiles.filter(item => item.binary === binary);
|
|
20
|
+
if (!candidates.length) return { profile: null, compatibilityReason: 'Requires an Apple Silicon emulator at a supported GUI executable path.' };
|
|
21
21
|
let compatibilityReason;
|
|
22
22
|
for (const template of candidates) {
|
|
23
23
|
try {
|
|
@@ -80,11 +80,11 @@ export async function inspect({ sdk: explicit, backupDir, profiles = bundledProf
|
|
|
80
80
|
try {
|
|
81
81
|
if (!(await lstat(receiptPath)).isFile()) throw new Error('Invalid backup receipt');
|
|
82
82
|
const receipt = JSON.parse(await readFile(receiptPath, 'utf8'));
|
|
83
|
-
if (![1, 2, 3].includes(receipt.schema) || receipt.target !== target || receipt.originalHash !== name.slice(0, 64) || !/^[a-f0-9]{64}$/.test(receipt.patchedHash ?? '') || !['prepared','applied','restored'].includes(receipt.state)) throw new Error('Invalid backup receipt');
|
|
83
|
+
if (![1, 2, 3, 4].includes(receipt.schema) || receipt.target !== target || receipt.originalHash !== name.slice(0, 64) || !/^[a-f0-9]{64}$/.test(receipt.patchedHash ?? '') || !['prepared','applied','restored'].includes(receipt.state)) throw new Error('Invalid backup receipt');
|
|
84
84
|
if (receipt.schema === 1 && name !== receipt.originalHash) throw new Error('Invalid legacy backup directory');
|
|
85
85
|
if (receipt.schema === 2 && (receipt.icons !== 'auto' || name !== `${receipt.originalHash}-automatic-${runtimeHash(receipt.runtime)}`)) throw new Error('Invalid automatic backup directory');
|
|
86
|
-
if (receipt
|
|
87
|
-
if (receipt
|
|
86
|
+
if (isNamingReceipt(receipt) && (name !== `${receipt.originalHash}-names-${receipt.namesHash}` || !['auto', 'phone'].includes(receipt.icons) || ![receipt.namesHash, receipt.backendHash, receipt.configHash, ...(receipt.schema === 3 ? [receipt.scriptHash] : [])].every(hash => /^[a-f0-9]{64}$/.test(hash ?? '')))) throw new Error('Invalid naming backup directory');
|
|
87
|
+
if (isNamingReceipt(receipt) && receipt.icons === 'auto') runtimeHash(receipt.runtime);
|
|
88
88
|
receipts.push({ ...receipt, directory: join(folder, name) });
|
|
89
89
|
} catch (error) {
|
|
90
90
|
throw new Error(`Cannot read backup receipt ${receiptPath}: ${error.message}`);
|
|
@@ -92,7 +92,7 @@ export async function inspect({ sdk: explicit, backupDir, profiles = bundledProf
|
|
|
92
92
|
}
|
|
93
93
|
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
94
94
|
const configHash = await configurationHash(target);
|
|
95
|
-
const receipt = receipts.find(record => record
|
|
95
|
+
const receipt = receipts.find(record => isNamingReceipt(record) && record.configHash === configHash && [record.patchedHash, record.originalHash].includes(targetHash)) ?? receipts.find(record => record.patchedHash === targetHash) ?? receipts.find(record => record.originalHash === targetHash);
|
|
96
96
|
const originalSource = receipt?.patchedHash === targetHash ? join(receipt.directory, 'original') : target;
|
|
97
97
|
const originalBytes = await readFile(originalSource);
|
|
98
98
|
if (receipt?.patchedHash === targetHash && sha256(originalBytes) !== receipt.originalHash) throw new Error('Original backup is corrupt');
|
|
@@ -104,13 +104,13 @@ export async function inspect({ sdk: explicit, backupDir, profiles = bundledProf
|
|
|
104
104
|
catch { runtimeHealthy = false; }
|
|
105
105
|
}
|
|
106
106
|
const icons = state === 'patched' ? (receipt.icons ?? 'phone') : null;
|
|
107
|
-
const names = state === 'patched' && receipt
|
|
107
|
+
const names = state === 'patched' && isNamingReceipt(receipt) ? 'avd' : 'off';
|
|
108
108
|
let namingHealthy = null;
|
|
109
109
|
if (names === 'avd') {
|
|
110
110
|
try { await verifyNaming(receipt); namingHealthy = configHash === receipt.configHash; }
|
|
111
111
|
catch { namingHealthy = false; }
|
|
112
112
|
}
|
|
113
|
-
return { compatibilityReason, supportedVersions: [
|
|
113
|
+
return { compatibilityReason, supportedVersions: ['Apple Silicon builds with compatible binary and icons'], configHash, names, namingHealthy, icons, runtimeHealthy, sdk, revision, target, targetHash, storage, folder, targetId, state, receipt, profile, adapter, mode: info.mode & 0o777, receipts };
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
async function withLock(context, operation) {
|
|
@@ -153,13 +153,14 @@ export async function apply(options = {}) {
|
|
|
153
153
|
const profile = context.profile;
|
|
154
154
|
if (!profile) throw new Error(`Unsupported emulator ${context.revision ?? 'version'} (${context.targetHash}). No files changed. ${context.compatibilityReason}`);
|
|
155
155
|
const bundle = icons === 'auto' ? await readRuntime(runtimeDirectory, context.adapter) : null;
|
|
156
|
-
const naming = names === 'avd' ? await readNamingBundle(options.packageRoot ?? packageRoot, context.adapter
|
|
156
|
+
const naming = names === 'avd' ? await readNamingBundle(options.packageRoot ?? packageRoot, context.adapter) : null;
|
|
157
|
+
if (naming && !context.revision) throw new Error('Cannot verify the installed SDK revision for AVD naming');
|
|
157
158
|
const namesHash = naming ? sha256(Buffer.from(JSON.stringify([naming.hash, icons, bundle?.hash ?? null]))) : null;
|
|
158
159
|
const directory = join(context.folder, naming ? `${originalHash}-names-${namesHash}` : icons === 'auto' ? `${originalHash}-automatic-${bundle.hash}` : originalHash);
|
|
159
160
|
return withLock(context, async () => {
|
|
160
161
|
await context.adapter.verify(context.target);
|
|
161
162
|
const activeConfig = await configurationHash(context.target);
|
|
162
|
-
if (activeConfig && !context.receipts.some(record => record
|
|
163
|
+
if (activeConfig && !context.receipts.some(record => isNamingReceipt(record) && record.configHash === activeConfig)) throw new Error('Unrecognized naming configuration; nothing overwritten');
|
|
163
164
|
const existing = context.receipts.find(record => record.directory === directory);
|
|
164
165
|
if (existing) {
|
|
165
166
|
if (await hashFile(join(directory, 'original')) !== originalHash) throw new Error('Original backup is corrupt; refusing to replace it');
|
|
@@ -168,12 +169,12 @@ export async function apply(options = {}) {
|
|
|
168
169
|
await verifyRuntime(join(directory, 'runtime'), existing.runtime);
|
|
169
170
|
await context.adapter.verify(join(directory, 'runtime/helper.dylib'));
|
|
170
171
|
}
|
|
171
|
-
if (existing
|
|
172
|
+
if (isNamingReceipt(existing)) {
|
|
172
173
|
await verifyNaming(existing);
|
|
173
174
|
await context.adapter.verify(join(directory, 'backend'));
|
|
174
175
|
await installConfiguration(context, existing);
|
|
175
176
|
}
|
|
176
|
-
if (context.targetHash === existing.patchedHash && (existing
|
|
177
|
+
if (context.targetHash === existing.patchedHash && (!isNamingReceipt(existing) || activeConfig === existing.configHash)) return { ...context, changed: false };
|
|
177
178
|
await replace(context, join(directory, 'patched'), existing.patchedHash);
|
|
178
179
|
if (!naming) await removeConfiguration(context);
|
|
179
180
|
await atomicJSON(join(directory, 'receipt.json'), { ...existing, directory: undefined, state: 'applied' });
|
|
@@ -202,16 +203,15 @@ export async function apply(options = {}) {
|
|
|
202
203
|
if (naming) {
|
|
203
204
|
const backend = join(preparation, 'backend');
|
|
204
205
|
await rename(candidate, backend);
|
|
205
|
-
const backendHash = await hashFile(backend)
|
|
206
|
-
|
|
207
|
-
const configuration = { schema: 1, sdk: context.sdk, target: context.target, directory, revision: context.revision, node: naming.node, script: join(directory, 'launch.mjs'), backend: join(directory, 'backend'), backendHash, scriptHash };
|
|
206
|
+
const backendHash = await hashFile(backend);
|
|
207
|
+
const configuration = { schema: 2, sdk: context.sdk, target: context.target, directory, revision: context.revision, backendHash };
|
|
208
208
|
await atomicJSON(join(preparation, 'launch.json'), configuration);
|
|
209
|
-
namingFields = { namesHash, backendHash,
|
|
209
|
+
namingFields = { namesHash, backendHash, configHash: await hashFile(join(preparation, 'launch.json')) };
|
|
210
210
|
await context.adapter.copy(naming.launcher, candidate);
|
|
211
211
|
await context.adapter.sign(backup, candidate, preparation);
|
|
212
212
|
}
|
|
213
213
|
const patchedHash = await hashFile(candidate);
|
|
214
|
-
const receipt = { schema: naming ?
|
|
214
|
+
const receipt = { schema: naming ? 4 : bundle ? 2 : 1, target: context.target, revision: context.revision, build: profile.build, originalHash, patchedHash, state: 'prepared', created: new Date().toISOString(), slots, ...(bundle ? { icons, runtime: bundle.manifest } : {}), ...(naming ? { icons, ...namingFields } : {}) };
|
|
215
215
|
for (const file of [backup, candidate]) {
|
|
216
216
|
const handle = await open(file, 'r');
|
|
217
217
|
try { await handle.sync(); } finally { await handle.close(); }
|
package/src/names.js
CHANGED
|
@@ -2,6 +2,7 @@ import { readFile, lstat, writeFile, rename, rm } from 'node:fs/promises';
|
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import { sha256 } from './png.js';
|
|
5
|
+
export const isNamingReceipt = receipt => receipt.schema === 3 || receipt.schema === 4;
|
|
5
6
|
export const configurationPath = target => join(dirname(target), '.emulator-tweaks-launch.json');
|
|
6
7
|
export async function configurationHash(target) {
|
|
7
8
|
try {
|
|
@@ -10,24 +11,26 @@ export async function configurationHash(target) {
|
|
|
10
11
|
return sha256(await readFile(path));
|
|
11
12
|
} catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
12
13
|
}
|
|
13
|
-
export async function readNamingBundle(root, adapter
|
|
14
|
+
export async function readNamingBundle(root, adapter) {
|
|
14
15
|
const directory = join(root, 'assets/launcher');
|
|
15
16
|
const manifest = JSON.parse(await readFile(join(directory, 'manifest.json'), 'utf8'));
|
|
16
17
|
const launcher = join(directory, 'launcher');
|
|
17
|
-
const bytes = await readFile(launcher)
|
|
18
|
-
if (bytes.length < 16 || manifest.schema !==
|
|
18
|
+
const bytes = await readFile(launcher);
|
|
19
|
+
if (bytes.length < 16 || manifest.schema !== 2 || manifest.architecture !== 'arm64' || sha256(bytes) !== manifest.sha256 || bytes.readUInt32LE(0) !== 0xfeedfacf || bytes.readUInt32LE(4) !== 0x100000c || bytes.readUInt32LE(12) !== 2) throw new Error('Invalid bundled AVD launcher');
|
|
19
20
|
await adapter.verify(launcher);
|
|
20
|
-
return { launcher,
|
|
21
|
+
return { launcher, hash: manifest.sha256 };
|
|
21
22
|
}
|
|
22
23
|
export async function verifyNaming(receipt) {
|
|
23
|
-
|
|
24
|
+
const files = [['backend', receipt.backendHash], ['launch.json', receipt.configHash]];
|
|
25
|
+
if (receipt.schema === 3) files.push(['launch.mjs', receipt.scriptHash]);
|
|
26
|
+
for (const [name, expected] of files) {
|
|
24
27
|
const path = join(receipt.directory, name), info = await lstat(path);
|
|
25
28
|
if (!info.isFile() || info.isSymbolicLink() || sha256(await readFile(path)) !== expected) throw new Error('Naming runtime is missing or corrupt');
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
export async function installConfiguration(context, receipt) {
|
|
29
32
|
const current = await configurationHash(context.target);
|
|
30
|
-
if (current && !context.receipts.some(record => record
|
|
33
|
+
if (current && !context.receipts.some(record => isNamingReceipt(record) && record.configHash === current)) throw new Error('Unrecognized naming configuration; nothing overwritten');
|
|
31
34
|
const temporary = `${configurationPath(context.target)}.${randomUUID()}.tmp`;
|
|
32
35
|
try {
|
|
33
36
|
await writeFile(temporary, await readFile(join(receipt.directory, 'launch.json')), { flag: 'wx', mode: 0o600 });
|
|
@@ -36,5 +39,5 @@ export async function installConfiguration(context, receipt) {
|
|
|
36
39
|
}
|
|
37
40
|
export async function removeConfiguration(context) {
|
|
38
41
|
const current = await configurationHash(context.target);
|
|
39
|
-
if (current && context.receipts.some(record => record
|
|
42
|
+
if (current && context.receipts.some(record => isNamingReceipt(record) && record.configHash === current)) await rm(configurationPath(context.target));
|
|
40
43
|
}
|
package/src/launch.mjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { readFile, mkdir, lstat, realpath, readdir, symlink, copyFile, chmod, mkdtemp, rename, rm } from 'node:fs/promises';
|
|
2
|
-
import { constants } from 'node:fs';
|
|
3
|
-
import { createHash } from 'node:crypto';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
7
|
-
export function avdName(arguments_) {
|
|
8
|
-
const names = [];
|
|
9
|
-
for (let i = 0; i < arguments_.length; i++) {
|
|
10
|
-
if (arguments_[i] === '-avd' && arguments_[i + 1]) names.push(arguments_[++i]);
|
|
11
|
-
else if (arguments_[i].startsWith('@')) names.push(arguments_[i].slice(1));
|
|
12
|
-
}
|
|
13
|
-
if (new Set(names).size > 1) throw new Error('Conflicting AVD names');
|
|
14
|
-
const name = names[0];
|
|
15
|
-
if (name && (!/^[A-Za-z0-9_.-]{1,255}$/.test(name) || ['.', '..', 'qemu-system-aarch64'].includes(name.toLowerCase()))) throw new Error('Invalid or reserved AVD name');
|
|
16
|
-
return arguments_.includes('-no-window') ? undefined : name;
|
|
17
|
-
}
|
|
18
|
-
async function regularFile(path) {
|
|
19
|
-
const info = await lstat(path);
|
|
20
|
-
if (!info.isFile() || info.isSymbolicLink()) throw new Error(`Not a regular file: ${path}`);
|
|
21
|
-
return info;
|
|
22
|
-
}
|
|
23
|
-
export async function prepareLaunch(config, arguments_) {
|
|
24
|
-
if (config.schema !== 1 || await realpath(config.sdk) !== config.sdk || !config.directory.startsWith('/') ||
|
|
25
|
-
config.target !== join(config.sdk, 'emulator/qemu/darwin-aarch64/qemu-system-aarch64') ||
|
|
26
|
-
config.backend !== join(config.directory, 'backend') || config.script !== join(config.directory, 'launch.mjs')) throw new Error('Invalid naming configuration');
|
|
27
|
-
const revision = (await readFile(join(config.sdk, 'emulator/source.properties'), 'utf8')).match(/^Pkg\.Revision\s*=\s*(\S+)\s*$/m)?.[1];
|
|
28
|
-
if (revision !== config.revision) throw new Error('SDK version changed; restore or reapply emulator tweaks');
|
|
29
|
-
await regularFile(config.backend);
|
|
30
|
-
if (hash(await readFile(config.backend)) !== config.backendHash) throw new Error('Named emulator backend is corrupt');
|
|
31
|
-
const name = avdName(arguments_) ?? 'qemu-system-aarch64';
|
|
32
|
-
const launches = join(config.directory, 'launches');
|
|
33
|
-
await mkdir(launches, { recursive: true, mode: 0o700 });
|
|
34
|
-
const info = await lstat(launches);
|
|
35
|
-
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error('Invalid naming cache directory');
|
|
36
|
-
const destination = join(launches, hash(Buffer.from(name)));
|
|
37
|
-
const executable = join(destination, 'sdk/emulator/qemu/darwin-aarch64', name);
|
|
38
|
-
try {
|
|
39
|
-
await regularFile(executable);
|
|
40
|
-
if (hash(await readFile(executable)) !== config.backendHash) throw new Error('Cached named emulator is corrupt');
|
|
41
|
-
return executable;
|
|
42
|
-
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
43
|
-
const temporary = await mkdtemp(join(launches, '.prepare-'));
|
|
44
|
-
try {
|
|
45
|
-
async function clone(from, to, relative = '') {
|
|
46
|
-
await mkdir(to, { mode: 0o700 });
|
|
47
|
-
for (const entry of await readdir(from, { withFileTypes: true })) {
|
|
48
|
-
const key = relative ? `${relative}/${entry.name}` : entry.name;
|
|
49
|
-
const source = join(from, entry.name), output = join(to, entry.name);
|
|
50
|
-
if (['emulator', 'emulator/qemu', 'emulator/qemu/darwin-aarch64'].includes(key)) await clone(source, output, key);
|
|
51
|
-
else if (key !== 'emulator/qemu/darwin-aarch64/qemu-system-aarch64' && entry.name !== '.emulator-tweaks-launch.json' && entry.name !== '.emulator-icon-macos.lock') await symlink(source, output);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
await clone(config.sdk, join(temporary, 'sdk'));
|
|
55
|
-
const candidate = join(temporary, 'sdk/emulator/qemu/darwin-aarch64', name);
|
|
56
|
-
// Never overwrite a library or other SDK entry that happens to share the AVD name.
|
|
57
|
-
await copyFile(config.backend, candidate, constants.COPYFILE_EXCL);
|
|
58
|
-
await chmod(candidate, (await regularFile(config.backend)).mode & 0o777);
|
|
59
|
-
if (hash(await readFile(candidate)) !== config.backendHash) throw new Error('Named emulator copy changed');
|
|
60
|
-
try { await rename(temporary, destination); }
|
|
61
|
-
catch (error) { if (!['EEXIST', 'ENOTEMPTY'].includes(error.code)) throw error; }
|
|
62
|
-
await regularFile(executable);
|
|
63
|
-
if (hash(await readFile(executable)) !== config.backendHash) throw new Error('Concurrent named emulator cache is corrupt');
|
|
64
|
-
return executable;
|
|
65
|
-
} finally { await rm(temporary, { recursive: true, force: true }); }
|
|
66
|
-
}
|
|
67
|
-
if (process.argv[1] && await realpath(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
68
|
-
try {
|
|
69
|
-
const config = JSON.parse(await readFile(process.argv[2], 'utf8'));
|
|
70
|
-
console.log(await prepareLaunch(config, process.argv.slice(3)));
|
|
71
|
-
} catch (error) { console.error(`androperator-emulator-tweaks: ${error.message}`); process.exitCode = 1; }
|
|
72
|
-
}
|