codeplay-common 4.11.38 → 4.11.40
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 +1 -1
- package/RELEASE_NOTES.md +13 -13
- package/files/buildCodeplay/add-splash-screen.js +1 -1
- package/files/buildCodeplay/codeplayBeforeBuild.js +2 -2
- package/files/buildCodeplay/ensure-current-build.cjs +32 -4
- package/files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs +31 -31
- package/files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs +28 -28
- package/files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle +9 -9
- package/files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs +30 -30
- package/files/buildCodeplay/huawei-privacy-entry.js +135 -135
- package/files/buildCodeplay/huawei-privacy.css +22 -22
- package/files/buildCodeplay/ios-ad-consent.cjs +56 -56
- package/files/buildCodeplay/ios-emi-admob-modification.js +25 -25
- package/files/buildCodeplay/newly added.txt +89 -89
- package/files/buildCodeplay/non-google-billing.pro +3 -3
- package/files/buildCodeplay/release-sync.config.json +4 -4
- package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
- package/files/buildCodeplay/ruads.cjs +220 -220
- package/files/buildCodeplay/saf-mediastore-dependency.cjs +21 -21
- package/files/buildCodeplay/setSplashAnimation.js +2 -2
- package/files/buildCodeplay/setup-ruads.cjs +62 -62
- package/files/buildCodeplay/splash-setup.cjs +88 -88
- package/files/buildCodeplay/store-billing.cjs +43 -43
- package/files/buildCodeplay/tests/huawei-live-reload.test.cjs +60 -60
- package/files/buildCodeplay/tests/huawei-privacy.test.cjs +49 -49
- package/files/scripts-common/collect-startup-profile.js +134 -134
- package/files/scripts-common/generate-baseline-profile.js +218 -218
- package/files/take-screen-image.js +4552 -4414
- package/package.json +1 -1
- package/runtime/splash-ready.mjs +52 -52
- package/runtime/vk-ads/vk-ad-configuration.json +39 -39
- package/scripts/baseline-profile.test.cjs +189 -189
- package/scripts/ensure-current-build.test.cjs +128 -28
- package/scripts/ios-ad-consent.test.cjs +99 -99
- package/scripts/ruads-install.test.cjs +197 -197
- package/scripts/ruads-policy.test.cjs +174 -174
- package/scripts/saf-mediastore-dependency.test.cjs +44 -44
- package/scripts/splash-setup.test.cjs +142 -142
- package/scripts/sync-files.js +1 -1
- package/scripts/vite-build-settings.test.cjs +93 -93
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-
const { execFile } = require('child_process');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { promisify } = require('util');
|
|
5
|
-
const { setTimeout: delay } = require('timers/promises');
|
|
6
|
-
const AdmZip = require('adm-zip');
|
|
7
|
-
|
|
8
|
-
const execFileAsync = promisify(execFile);
|
|
9
|
-
|
|
10
|
-
function normalizeProfile(rawProfile) {
|
|
11
|
-
// Match Macrobenchmark's portable HRF filtering: exclude arrays and inline caches.
|
|
12
|
-
return [...new Set(rawProfile.split(/\r?\n/).map(line => line.trim()).filter(line =>
|
|
13
|
-
!line.includes('+') && /^[HSP]*L[^;]+;(?:->.+)?$/.test(line)
|
|
14
|
-
))].sort().join('\n');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function collectStartupProfile({ serial, appId, apkPath, rootDir, timeoutMinutes, deadline }) {
|
|
18
|
-
if (!/^[a-zA-Z_][\w]*(\.[a-zA-Z_][\w]*)+$/.test(appId)) {
|
|
19
|
-
throw new Error('Invalid application ID for host-driven profile collection.');
|
|
20
|
-
}
|
|
21
|
-
const apk = new AdmZip(apkPath);
|
|
22
|
-
const config = JSON.parse(apk.readAsText('assets/capacitor.config.json'));
|
|
23
|
-
if (config.appId !== appId || config.server?.url || !apk.getEntry('assets/public/index.html')) {
|
|
24
|
-
throw new Error('The profiling APK must contain the correct app and bundled web assets with no server.url.');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const controller = new AbortController();
|
|
28
|
-
const cancel = () => controller.abort(new Error('Host-driven profile collection cancelled.'));
|
|
29
|
-
const timeout = setTimeout(() => {
|
|
30
|
-
controller.abort(new Error(`Host-driven profile collection exceeded ${timeoutMinutes} minutes.`));
|
|
31
|
-
}, Math.max(0, (deadline ?? Date.now() + timeoutMinutes * 60000) - Date.now()));
|
|
32
|
-
process.on('SIGINT', cancel);
|
|
33
|
-
process.on('SIGTERM', cancel);
|
|
34
|
-
const adb = async (args, commandTimeout = 30000) => {
|
|
35
|
-
const result = await execFileAsync('adb', ['-s', serial, ...args], {
|
|
36
|
-
encoding: 'utf8',
|
|
37
|
-
maxBuffer: 32 * 1024 * 1024,
|
|
38
|
-
timeout: commandTimeout,
|
|
39
|
-
signal: controller.signal,
|
|
40
|
-
});
|
|
41
|
-
return result.stdout.trim();
|
|
42
|
-
};
|
|
43
|
-
const receiver = `${appId}/androidx.profileinstaller.ProfileInstallReceiver`;
|
|
44
|
-
const broadcast = async (action, resultCode, extras = []) => {
|
|
45
|
-
const result = await adb(['shell', 'am', 'broadcast', '-a', `androidx.profileinstaller.action.${action}`, ...extras, receiver]);
|
|
46
|
-
if (!new RegExp(`result=${resultCode}\\b`).test(result)) {
|
|
47
|
-
throw new Error(`ProfileInstaller ${action} did not return ${resultCode}: ${result}`);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
let skipFileWritten = false;
|
|
51
|
-
try {
|
|
52
|
-
const sdk = Number(await adb(['shell', 'getprop', 'ro.build.version.sdk']));
|
|
53
|
-
if (sdk < 34) throw new Error('Host-driven profile collection requires Android 14 or later.');
|
|
54
|
-
console.log('Using Android\'s ADB profile collection workflow without the instrumentation runner.');
|
|
55
|
-
const installResult = await adb(['install', '-r', apkPath], 120000);
|
|
56
|
-
if (!/\bSuccess\b/.test(installResult)) throw new Error(`Profiling APK installation failed: ${installResult}`);
|
|
57
|
-
const resolution = await adb(['shell', 'cmd', 'package', 'resolve-activity', '--brief',
|
|
58
|
-
'-a', 'android.intent.action.MAIN', '-c', 'android.intent.category.LAUNCHER', appId]);
|
|
59
|
-
const component = resolution.split(/\r?\n/).find(line => line.startsWith(`${appId}/`));
|
|
60
|
-
if (!component || !/^[\w.$]+\/[\w.$]+$/.test(component)) {
|
|
61
|
-
throw new Error(`Could not resolve the app's launch activity: ${resolution}`);
|
|
62
|
-
}
|
|
63
|
-
const activity = component.split('/')[1];
|
|
64
|
-
const activityDescriptor = `L${(activity.startsWith('.') ? appId + activity : activity).replace(/\./g, '/')};`;
|
|
65
|
-
await broadcast('SKIP_FILE', 10, ['-e', 'EXTRA_SKIP_FILE_OPERATION', 'WRITE_SKIP_FILE']);
|
|
66
|
-
skipFileWritten = true;
|
|
67
|
-
await adb(['shell', 'am', 'force-stop', appId]);
|
|
68
|
-
const reset = await adb(['shell', 'cmd', 'package', 'compile', '-f', '-m', 'verify', appId], 120000);
|
|
69
|
-
if (!/\bSuccess\b/.test(reset)) throw new Error(`Could not reset app compilation: ${reset}`);
|
|
70
|
-
const clear = await adb(['shell', 'pm', 'art', 'clear-app-profiles', appId]);
|
|
71
|
-
if (!/Profiles cleared/.test(clear)) throw new Error(`Could not clear previous runtime profiles: ${clear}`);
|
|
72
|
-
|
|
73
|
-
const tempDir = path.join(rootDir, 'agent-temp', 'baseline-profile', 'host-collection');
|
|
74
|
-
fs.mkdirSync(tempDir, { recursive: true });
|
|
75
|
-
let lastProfile = '';
|
|
76
|
-
let stableCount = 0;
|
|
77
|
-
for (let iteration = 1; iteration <= 15; iteration += 1) {
|
|
78
|
-
console.log(`Startup profile iteration ${iteration}/15: launching bundled app.`);
|
|
79
|
-
const launch = await adb(['shell', 'am', 'start', '-W', '-n', component]);
|
|
80
|
-
if (!/Status: ok/.test(launch) || /Error:/.test(launch)) throw new Error(`App launch failed: ${launch}`);
|
|
81
|
-
// Android's documented workflow requires at least five seconds before saving.
|
|
82
|
-
await delay(6000, undefined, { signal: controller.signal });
|
|
83
|
-
if (iteration === 1) {
|
|
84
|
-
const screenshot = await execFileAsync('adb', ['-s', serial, 'exec-out', 'screencap', '-p'], {
|
|
85
|
-
encoding: 'buffer', maxBuffer: 32 * 1024 * 1024, timeout: 10000, signal: controller.signal,
|
|
86
|
-
});
|
|
87
|
-
fs.writeFileSync(path.join(tempDir, 'startup.png'), screenshot.stdout);
|
|
88
|
-
}
|
|
89
|
-
await broadcast('SAVE_PROFILE', 12);
|
|
90
|
-
await delay(1100, undefined, { signal: controller.signal });
|
|
91
|
-
await adb(['shell', 'am', 'force-stop', appId]);
|
|
92
|
-
const compile = await adb(['shell', 'cmd', 'package', 'compile', '-f', '-m', 'speed-profile', appId], 120000);
|
|
93
|
-
if (!/\bSuccess\b/.test(compile)) throw new Error(`Profile compilation failed: ${compile}`);
|
|
94
|
-
await adb(['shell', 'pm', 'dump-profiles', '--dump-classes-and-methods', appId]);
|
|
95
|
-
const rawProfile = await adb(['exec-out', 'cat', `/data/misc/profman/${appId}-primary.prof.txt`]);
|
|
96
|
-
fs.writeFileSync(path.join(tempDir, `iteration-${iteration}.txt`), rawProfile);
|
|
97
|
-
const profile = normalizeProfile(rawProfile);
|
|
98
|
-
if (!profile.includes(activityDescriptor) || !profile.includes('Lcom/getcapacitor/Bridge;')) {
|
|
99
|
-
throw new Error('The collected profile is missing the app launch activity or Capacitor bridge.');
|
|
100
|
-
}
|
|
101
|
-
stableCount = profile === lastProfile ? stableCount + 1 : 1;
|
|
102
|
-
lastProfile = profile;
|
|
103
|
-
console.log(`Startup profile iteration ${iteration}: ${profile.split('\n').length} rules; ${stableCount}/3 matching captures.`);
|
|
104
|
-
if (stableCount === 3) break;
|
|
105
|
-
}
|
|
106
|
-
if (stableCount < 3) throw new Error('Startup profile did not stabilize within 15 iterations. Existing profile files were preserved.');
|
|
107
|
-
controller.signal.throwIfAborted();
|
|
108
|
-
const outputDir = path.join(rootDir, 'baselineProfiles');
|
|
109
|
-
fs.mkdirSync(outputDir, { recursive: true });
|
|
110
|
-
// This journey only exercises startup, so both profile inputs cover that same journey.
|
|
111
|
-
for (const fileName of ['baseline-prof.txt', 'startup-prof.txt']) {
|
|
112
|
-
fs.writeFileSync(path.join(outputDir, fileName), `${lastProfile}\n`);
|
|
113
|
-
}
|
|
114
|
-
console.log(`Generated stable startup and baseline profiles in ${outputDir}`);
|
|
115
|
-
} catch (error) {
|
|
116
|
-
throw controller.signal.aborted ? controller.signal.reason : error;
|
|
117
|
-
} finally {
|
|
118
|
-
clearTimeout(timeout);
|
|
119
|
-
process.removeListener('SIGINT', cancel);
|
|
120
|
-
process.removeListener('SIGTERM', cancel);
|
|
121
|
-
if (skipFileWritten) {
|
|
122
|
-
try {
|
|
123
|
-
// Cleanup must still run when the collection signal was cancelled.
|
|
124
|
-
await execFileAsync('adb', ['-s', serial, 'shell', 'am', 'broadcast', '-a',
|
|
125
|
-
'androidx.profileinstaller.action.SKIP_FILE', '-e', 'EXTRA_SKIP_FILE_OPERATION',
|
|
126
|
-
'DELETE_SKIP_FILE', receiver], { timeout: 10000 });
|
|
127
|
-
} catch (error) {
|
|
128
|
-
console.error(`Could not restore automatic profile installation: ${error.message}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
module.exports = { collectStartupProfile, normalizeProfile };
|
|
1
|
+
const { execFile } = require('child_process');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { promisify } = require('util');
|
|
5
|
+
const { setTimeout: delay } = require('timers/promises');
|
|
6
|
+
const AdmZip = require('adm-zip');
|
|
7
|
+
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
|
|
10
|
+
function normalizeProfile(rawProfile) {
|
|
11
|
+
// Match Macrobenchmark's portable HRF filtering: exclude arrays and inline caches.
|
|
12
|
+
return [...new Set(rawProfile.split(/\r?\n/).map(line => line.trim()).filter(line =>
|
|
13
|
+
!line.includes('+') && /^[HSP]*L[^;]+;(?:->.+)?$/.test(line)
|
|
14
|
+
))].sort().join('\n');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function collectStartupProfile({ serial, appId, apkPath, rootDir, timeoutMinutes, deadline }) {
|
|
18
|
+
if (!/^[a-zA-Z_][\w]*(\.[a-zA-Z_][\w]*)+$/.test(appId)) {
|
|
19
|
+
throw new Error('Invalid application ID for host-driven profile collection.');
|
|
20
|
+
}
|
|
21
|
+
const apk = new AdmZip(apkPath);
|
|
22
|
+
const config = JSON.parse(apk.readAsText('assets/capacitor.config.json'));
|
|
23
|
+
if (config.appId !== appId || config.server?.url || !apk.getEntry('assets/public/index.html')) {
|
|
24
|
+
throw new Error('The profiling APK must contain the correct app and bundled web assets with no server.url.');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
const cancel = () => controller.abort(new Error('Host-driven profile collection cancelled.'));
|
|
29
|
+
const timeout = setTimeout(() => {
|
|
30
|
+
controller.abort(new Error(`Host-driven profile collection exceeded ${timeoutMinutes} minutes.`));
|
|
31
|
+
}, Math.max(0, (deadline ?? Date.now() + timeoutMinutes * 60000) - Date.now()));
|
|
32
|
+
process.on('SIGINT', cancel);
|
|
33
|
+
process.on('SIGTERM', cancel);
|
|
34
|
+
const adb = async (args, commandTimeout = 30000) => {
|
|
35
|
+
const result = await execFileAsync('adb', ['-s', serial, ...args], {
|
|
36
|
+
encoding: 'utf8',
|
|
37
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
38
|
+
timeout: commandTimeout,
|
|
39
|
+
signal: controller.signal,
|
|
40
|
+
});
|
|
41
|
+
return result.stdout.trim();
|
|
42
|
+
};
|
|
43
|
+
const receiver = `${appId}/androidx.profileinstaller.ProfileInstallReceiver`;
|
|
44
|
+
const broadcast = async (action, resultCode, extras = []) => {
|
|
45
|
+
const result = await adb(['shell', 'am', 'broadcast', '-a', `androidx.profileinstaller.action.${action}`, ...extras, receiver]);
|
|
46
|
+
if (!new RegExp(`result=${resultCode}\\b`).test(result)) {
|
|
47
|
+
throw new Error(`ProfileInstaller ${action} did not return ${resultCode}: ${result}`);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
let skipFileWritten = false;
|
|
51
|
+
try {
|
|
52
|
+
const sdk = Number(await adb(['shell', 'getprop', 'ro.build.version.sdk']));
|
|
53
|
+
if (sdk < 34) throw new Error('Host-driven profile collection requires Android 14 or later.');
|
|
54
|
+
console.log('Using Android\'s ADB profile collection workflow without the instrumentation runner.');
|
|
55
|
+
const installResult = await adb(['install', '-r', apkPath], 120000);
|
|
56
|
+
if (!/\bSuccess\b/.test(installResult)) throw new Error(`Profiling APK installation failed: ${installResult}`);
|
|
57
|
+
const resolution = await adb(['shell', 'cmd', 'package', 'resolve-activity', '--brief',
|
|
58
|
+
'-a', 'android.intent.action.MAIN', '-c', 'android.intent.category.LAUNCHER', appId]);
|
|
59
|
+
const component = resolution.split(/\r?\n/).find(line => line.startsWith(`${appId}/`));
|
|
60
|
+
if (!component || !/^[\w.$]+\/[\w.$]+$/.test(component)) {
|
|
61
|
+
throw new Error(`Could not resolve the app's launch activity: ${resolution}`);
|
|
62
|
+
}
|
|
63
|
+
const activity = component.split('/')[1];
|
|
64
|
+
const activityDescriptor = `L${(activity.startsWith('.') ? appId + activity : activity).replace(/\./g, '/')};`;
|
|
65
|
+
await broadcast('SKIP_FILE', 10, ['-e', 'EXTRA_SKIP_FILE_OPERATION', 'WRITE_SKIP_FILE']);
|
|
66
|
+
skipFileWritten = true;
|
|
67
|
+
await adb(['shell', 'am', 'force-stop', appId]);
|
|
68
|
+
const reset = await adb(['shell', 'cmd', 'package', 'compile', '-f', '-m', 'verify', appId], 120000);
|
|
69
|
+
if (!/\bSuccess\b/.test(reset)) throw new Error(`Could not reset app compilation: ${reset}`);
|
|
70
|
+
const clear = await adb(['shell', 'pm', 'art', 'clear-app-profiles', appId]);
|
|
71
|
+
if (!/Profiles cleared/.test(clear)) throw new Error(`Could not clear previous runtime profiles: ${clear}`);
|
|
72
|
+
|
|
73
|
+
const tempDir = path.join(rootDir, 'agent-temp', 'baseline-profile', 'host-collection');
|
|
74
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
75
|
+
let lastProfile = '';
|
|
76
|
+
let stableCount = 0;
|
|
77
|
+
for (let iteration = 1; iteration <= 15; iteration += 1) {
|
|
78
|
+
console.log(`Startup profile iteration ${iteration}/15: launching bundled app.`);
|
|
79
|
+
const launch = await adb(['shell', 'am', 'start', '-W', '-n', component]);
|
|
80
|
+
if (!/Status: ok/.test(launch) || /Error:/.test(launch)) throw new Error(`App launch failed: ${launch}`);
|
|
81
|
+
// Android's documented workflow requires at least five seconds before saving.
|
|
82
|
+
await delay(6000, undefined, { signal: controller.signal });
|
|
83
|
+
if (iteration === 1) {
|
|
84
|
+
const screenshot = await execFileAsync('adb', ['-s', serial, 'exec-out', 'screencap', '-p'], {
|
|
85
|
+
encoding: 'buffer', maxBuffer: 32 * 1024 * 1024, timeout: 10000, signal: controller.signal,
|
|
86
|
+
});
|
|
87
|
+
fs.writeFileSync(path.join(tempDir, 'startup.png'), screenshot.stdout);
|
|
88
|
+
}
|
|
89
|
+
await broadcast('SAVE_PROFILE', 12);
|
|
90
|
+
await delay(1100, undefined, { signal: controller.signal });
|
|
91
|
+
await adb(['shell', 'am', 'force-stop', appId]);
|
|
92
|
+
const compile = await adb(['shell', 'cmd', 'package', 'compile', '-f', '-m', 'speed-profile', appId], 120000);
|
|
93
|
+
if (!/\bSuccess\b/.test(compile)) throw new Error(`Profile compilation failed: ${compile}`);
|
|
94
|
+
await adb(['shell', 'pm', 'dump-profiles', '--dump-classes-and-methods', appId]);
|
|
95
|
+
const rawProfile = await adb(['exec-out', 'cat', `/data/misc/profman/${appId}-primary.prof.txt`]);
|
|
96
|
+
fs.writeFileSync(path.join(tempDir, `iteration-${iteration}.txt`), rawProfile);
|
|
97
|
+
const profile = normalizeProfile(rawProfile);
|
|
98
|
+
if (!profile.includes(activityDescriptor) || !profile.includes('Lcom/getcapacitor/Bridge;')) {
|
|
99
|
+
throw new Error('The collected profile is missing the app launch activity or Capacitor bridge.');
|
|
100
|
+
}
|
|
101
|
+
stableCount = profile === lastProfile ? stableCount + 1 : 1;
|
|
102
|
+
lastProfile = profile;
|
|
103
|
+
console.log(`Startup profile iteration ${iteration}: ${profile.split('\n').length} rules; ${stableCount}/3 matching captures.`);
|
|
104
|
+
if (stableCount === 3) break;
|
|
105
|
+
}
|
|
106
|
+
if (stableCount < 3) throw new Error('Startup profile did not stabilize within 15 iterations. Existing profile files were preserved.');
|
|
107
|
+
controller.signal.throwIfAborted();
|
|
108
|
+
const outputDir = path.join(rootDir, 'baselineProfiles');
|
|
109
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
110
|
+
// This journey only exercises startup, so both profile inputs cover that same journey.
|
|
111
|
+
for (const fileName of ['baseline-prof.txt', 'startup-prof.txt']) {
|
|
112
|
+
fs.writeFileSync(path.join(outputDir, fileName), `${lastProfile}\n`);
|
|
113
|
+
}
|
|
114
|
+
console.log(`Generated stable startup and baseline profiles in ${outputDir}`);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
throw controller.signal.aborted ? controller.signal.reason : error;
|
|
117
|
+
} finally {
|
|
118
|
+
clearTimeout(timeout);
|
|
119
|
+
process.removeListener('SIGINT', cancel);
|
|
120
|
+
process.removeListener('SIGTERM', cancel);
|
|
121
|
+
if (skipFileWritten) {
|
|
122
|
+
try {
|
|
123
|
+
// Cleanup must still run when the collection signal was cancelled.
|
|
124
|
+
await execFileAsync('adb', ['-s', serial, 'shell', 'am', 'broadcast', '-a',
|
|
125
|
+
'androidx.profileinstaller.action.SKIP_FILE', '-e', 'EXTRA_SKIP_FILE_OPERATION',
|
|
126
|
+
'DELETE_SKIP_FILE', receiver], { timeout: 10000 });
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error(`Could not restore automatic profile installation: ${error.message}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = { collectStartupProfile, normalizeProfile };
|