Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"backgroundColor": "#FAF3EC",
"ios": {
"icon": "./assets/ios-icon-1024.png",
"bundleIdentifier": "com.birthmark.app",
"bundleIdentifier": "com.htpdevs.birthmark",
"supportsTablet": true,
"requireFullScreen": true,
"infoPlist": {
Expand All @@ -22,6 +22,12 @@
"android": {
"package": "com.htpdevs.birthmark",
"allowBackup": false,
"blockedPermissions": [
"android.permission.INTERNET",
"android.permission.SYSTEM_ALERT_WINDOW",
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE"
],
"softwareKeyboardLayoutMode": "resize",
"adaptiveIcon": {
"backgroundColor": "#E8775A",
Expand Down Expand Up @@ -61,7 +67,8 @@
"imageWidth": 76
}
],
"./plugins/withNoUserScriptSandboxing"
"./plugins/withNoUserScriptSandboxing",
"./plugins/withDebugOnlyInternet"
],
"experiments": {
"typedRoutes": true,
Expand Down
5 changes: 5 additions & 0 deletions assets/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ LOGO

iOS
ios-icon-1024.png Upload to Xcode / App Store Connect. Square on purpose — iOS rounds the corners.
No alpha channel: App Store Connect rejects icons with one.
Re-export: magick in.png -background '#E8775A' -alpha remove -alpha off -strip PNG24:ios-icon-1024.png

ANDROID (adaptive icon = two layers that Android stacks and masks)
android-background.svg / -432.png Background layer: solid coral by design
android-foreground.svg / -432.png Foreground layer: transparent, cream "b" + espresso hands.
Looks like "just hands" on white; correct when stacked on coral.
android-monochrome.svg Themed-icon layer (Android 13+)
play-store-512.png Google Play listing icon
play-feature-graphic-1024x500.png Google Play feature graphic: lockup.png at 720px wide, centered on cream.
24-bit PNG, no alpha. Rebuild:
magick -size 1024x500 xc:'#FAF3EC' \( lockup.png -resize 720x \) -gravity center -composite -alpha off -strip PNG24:play-feature-graphic-1024x500.png

WEB
favicon.svg, favicon-16/32/48.png, apple-touch-icon-180.png
Expand Down
Binary file modified assets/ios-icon-1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/play-feature-graphic-1024x500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions plugins/withDebugOnlyInternet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Release builds must not hold INTERNET: the app is offline and the privacy
// policy says nothing leaves the device. app.json blocks it through
// android.blockedPermissions, which writes a tools:node="remove" entry into the
// main manifest and strips it from every library manifest too. Debug builds
// still need it to load the JS bundle from Metro, so this plugin declares it in
// the debug manifests (debug, and debugOptimized when the template has it),
// which outrank main in the merge and keep it there.
const fs = require('fs');
const path = require('path');
const { withDangerousMod } = require('expo/config-plugins');

const INTERNET = '<uses-permission android:name="android.permission.INTERNET"/>';
const DEV_VARIANTS = ['debug', 'debugOptimized'];

/** Returns the debug manifest with INTERNET declared once, before <application>. */
function addDebugInternetPermission(xml) {
if (/android:name="android\.permission\.INTERNET"/.test(xml)) return xml;
const at = xml.indexOf('<application');
if (at < 0) throw new Error('withDebugOnlyInternet: debug manifest has no <application> element');
return `${xml.slice(0, at)}${INTERNET}\n\n ${xml.slice(at)}`;
}

/** Patches the dev-variant manifests under an android/ project root. Returns the variants patched. */
function patchDevManifests(androidRoot) {
const patched = [];
for (const variant of DEV_VARIANTS) {
const file = path.join(androidRoot, 'app', 'src', variant, 'AndroidManifest.xml');
// debug always exists; a missing one means the template changed, so fail loudly.
if (variant !== 'debug' && !fs.existsSync(file)) continue;
fs.writeFileSync(file, addDebugInternetPermission(fs.readFileSync(file, 'utf8')));
patched.push(variant);
}
return patched;
}

const withDebugOnlyInternet = (config) =>
withDangerousMod(config, [
'android',
async (cfg) => {
patchDevManifests(cfg.modRequest.platformProjectRoot);
return cfg;
},
]);

module.exports = withDebugOnlyInternet;
module.exports.addDebugInternetPermission = addDebugInternetPermission;
module.exports.patchDevManifests = patchDevManifests;
6 changes: 5 additions & 1 deletion tests/appConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { join } from 'path';

const appJson = JSON.parse(readFileSync(join(__dirname, '..', 'app.json'), 'utf8')).expo;

// The Play Store listing is keyed to this id and it can never change after the
// Store listings are keyed to these ids and they can never change after the
// first upload, so a rename here would publish a different app.
describe('app config', () => {
it('Android application id is com.htpdevs.birthmark', () => {
expect(appJson.android.package).toBe('com.htpdevs.birthmark');
});

it('iOS bundle identifier is com.htpdevs.birthmark', () => {
expect(appJson.ios.bundleIdentifier).toBe('com.htpdevs.birthmark');
});
});
95 changes: 95 additions & 0 deletions tests/debugOnlyInternet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';

// Release builds block INTERNET (app.json android.blockedPermissions), so the
// offline claim in the privacy policy holds for what ships. Debug builds load
// the bundle from Metro and need it back; this plugin adds it to the debug
// manifests, which outrank main in the Gradle merge. Verified on prebuild:
// release merged manifest has no INTERNET, debug and debugOptimized have it.

// eslint-disable-next-line @typescript-eslint/no-require-imports
const { addDebugInternetPermission, patchDevManifests } = require('../plugins/withDebugOnlyInternet');

const appJson = JSON.parse(readFileSync(join(__dirname, '..', 'app.json'), 'utf8')).expo;

// The Expo SDK 57 template's android/app/src/debug/AndroidManifest.xml.
const TEMPLATE = `<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" tools:replace="android:usesCleartextTraffic" />
</manifest>
`;

const count = (xml: string) => (xml.match(/android\.permission\.INTERNET/g) ?? []).length;

describe('debug-only INTERNET plugin', () => {
it('adds INTERNET before <application>', () => {
const out = addDebugInternetPermission(TEMPLATE);
expect(count(out)).toBe(1);
expect(out.indexOf('android.permission.INTERNET')).toBeLessThan(out.indexOf('<application'));
expect(out).toContain('android.permission.SYSTEM_ALERT_WINDOW');
});

it('is idempotent', () => {
const once = addDebugInternetPermission(TEMPLATE);
expect(addDebugInternetPermission(once)).toBe(once);
});

it('fails loudly if the template has no <application>', () => {
expect(() => addDebugInternetPermission('<manifest></manifest>')).toThrow(/no <application>/);
});

describe('on a prebuilt android/ tree', () => {
let root: string;
const manifest = (variant: string) => join(root, 'app', 'src', variant, 'AndroidManifest.xml');
const write = (variant: string) => {
mkdirSync(join(root, 'app', 'src', variant), { recursive: true });
writeFileSync(manifest(variant), TEMPLATE);
};

beforeEach(() => {
root = mkdtempSync(join(tmpdir(), 'birthmark-android-'));
});
afterEach(() => rmSync(root, { recursive: true, force: true }));

it('patches debug and debugOptimized, and stays single across repeated prebuilds', () => {
write('debug');
write('debugOptimized');
write('main');
expect(patchDevManifests(root)).toEqual(['debug', 'debugOptimized']);
patchDevManifests(root);
expect(count(readFileSync(manifest('debug'), 'utf8'))).toBe(1);
expect(count(readFileSync(manifest('debugOptimized'), 'utf8'))).toBe(1);
expect(readFileSync(manifest('main'), 'utf8')).toBe(TEMPLATE);
});

it('skips a missing debugOptimized', () => {
write('debug');
expect(patchDevManifests(root)).toEqual(['debug']);
});

it('fails when the debug manifest is missing', () => {
expect(() => patchDevManifests(root)).toThrow(/ENOENT/);
});
});

it('is registered in app.json', () => {
expect(appJson.plugins).toContain('./plugins/withDebugOnlyInternet');
});
});

describe('release Android permissions', () => {
it('blocks INTERNET, overlay, and legacy storage', () => {
// Exact list: blocking a permission a library calls at runtime throws
// SecurityException, so additions here need the same release check.
expect(appJson.android.blockedPermissions).toEqual([
'android.permission.INTERNET',
'android.permission.SYSTEM_ALERT_WINDOW',
'android.permission.READ_EXTERNAL_STORAGE',
'android.permission.WRITE_EXTERNAL_STORAGE',
]);
});
});
47 changes: 47 additions & 0 deletions tests/storeAssets.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { readFileSync } from 'fs';
import { join } from 'path';

// Store upload rules checked against the PNG header (IHDR):
// - App Store Connect rejects an app icon with an alpha channel.
// - Google Play's feature graphic must be 1024x500, JPEG or 24-bit PNG, no alpha.
const ROOT = join(__dirname, '..');

const PNG_SIGNATURE = '89504e470d0a1a0a';
// IHDR color types: 0 gray, 2 RGB, 3 palette, 4 gray+alpha, 6 RGB+alpha.
const ALPHA_COLOR_TYPES = [4, 6];

function pngInfo(rel: string) {
const buf = readFileSync(join(ROOT, rel));
expect(buf.subarray(0, 8).toString('hex')).toBe(PNG_SIGNATURE);
expect(buf.subarray(12, 16).toString('ascii')).toBe('IHDR');
return {
width: buf.readUInt32BE(16),
height: buf.readUInt32BE(20),
colorType: buf[25],
// A palette or gray PNG can still carry transparency in a tRNS chunk.
hasTrns: buf.includes(Buffer.from('tRNS', 'ascii')),
};
}

const appJson = JSON.parse(readFileSync(join(ROOT, 'app.json'), 'utf8')).expo;

describe('store assets', () => {
it.each([appJson.icon, appJson.ios.icon])('iOS app icon %s is 1024x1024 with no alpha', (rel: string) => {
const info = pngInfo(rel);
expect([info.width, info.height]).toEqual([1024, 1024]);
expect(ALPHA_COLOR_TYPES).not.toContain(info.colorType);
expect(info.hasTrns).toBe(false);
});

it('Play feature graphic is a 1024x500 24-bit PNG with no alpha', () => {
const info = pngInfo('assets/play-feature-graphic-1024x500.png');
expect([info.width, info.height]).toEqual([1024, 500]);
expect(info.colorType).toBe(2);
expect(info.hasTrns).toBe(false);
});

it('Play listing icon is 512x512', () => {
const info = pngInfo('assets/play-store-512.png');
expect([info.width, info.height]).toEqual([512, 512]);
});
});
Loading