Skip to content

Commit 6a44965

Browse files
authored
feat(android): add option to specify services in AndroidManifest (#2684)
1 parent 1565f90 commit 6a44965

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

docs/android.services.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
A name-value pair for an item of additional, arbitrary data that can be supplied to the application.
2+
3+
Equivalent to
4+
[`<service>`](https://developer.android.com/guide/topics/manifest/service-element).
5+
6+
Example:
7+
8+
```xml
9+
<application>
10+
<service
11+
android:name="com.example.locationService"
12+
android:exported="true"
13+
android:foregroundServiceType="location" />
14+
</application>
15+
```
16+
17+
becomes
18+
19+
```json
20+
{
21+
"android": {
22+
"services": [
23+
{
24+
"android:name": "com.example.locationService",
25+
"android:exported": true,
26+
"android:foregroundServiceType": "location"
27+
}
28+
],
29+
}
30+
}
31+
```
32+
33+
<details>

packages/app/android/android-manifest.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,31 @@ function generateAndroidManifest(appManifestPath, manifestOutput, fs = nodefs) {
109109
}
110110
}
111111

112+
// https://developer.android.com/guide/topics/manifest/service-element
113+
const services = android.services;
114+
if (Array.isArray(services)) {
115+
const names = ["android:name"];
116+
const attributes = [
117+
"android:description",
118+
"android:directBootAware",
119+
"android:enabled",
120+
"android:exported",
121+
"android:foregroundServiceType",
122+
"android:icon",
123+
"android:isolatedProcess",
124+
"android:label",
125+
"android:name",
126+
"android:permission",
127+
"android:process",
128+
"android:stopWithTask",
129+
];
130+
const entries = toXML(services, names, attributes, attributeNamePrefix);
131+
132+
if (entries.length > 0) {
133+
manifest.application["service"] = entries;
134+
}
135+
}
136+
112137
const builder = new XMLBuilder(xmlOptions);
113138
fs.mkdirSync(path.dirname(manifestOutput), { recursive: true, mode: 0o755 });
114139
fs.writeFileSync(manifestOutput, builder.build(xml));

packages/app/scripts/types.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,33 @@ export type AndroidConfig = {
3030
"android:value": string;
3131
"android:resource": string;
3232
}[];
33+
services?: {
34+
"android:name": string;
35+
"android:description": string;
36+
"android:directBootAware": "true" | "false";
37+
"android:enabled": "true" | "false";
38+
"android:exported": "true" | "false";
39+
"android:foregroundServiceType":
40+
| "camera"
41+
| "connectedDevice"
42+
| "dataSync"
43+
| "health"
44+
| "location"
45+
| "mediaPlayback"
46+
| "mediaProjection"
47+
| "microphone"
48+
| "phoneCall"
49+
| "remoteMessaging"
50+
| "shortService"
51+
| "specialUse"
52+
| "systemExempted";
53+
"android:icon": string;
54+
"android:isolatedProcess": "true" | "false";
55+
"android:label": string;
56+
"android:permission": string;
57+
"android:process": string;
58+
"android:stopWithTask": "true" | "false";
59+
}[];
3360
};
3461
};
3562

@@ -38,6 +65,7 @@ export type AndroidManifest = {
3865
"uses-permission": Record<string, string>[];
3966
application: {
4067
"meta-data": Record<string, string>[];
68+
service: Record<string, string>[];
4169
};
4270
};
4371

0 commit comments

Comments
 (0)