-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathvalidate-cloudmessaging-trimming.sh
More file actions
executable file
·81 lines (67 loc) · 2.66 KB
/
Copy pathvalidate-cloudmessaging-trimming.sh
File metadata and controls
executable file
·81 lines (67 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
project="$repo_root/tests/Plugin.Firebase.IntegrationTests/Plugin.Firebase.IntegrationTests.csproj"
obj_dir="$repo_root/tests/Plugin.Firebase.IntegrationTests/obj/Release/net9.0-android"
acw_map="$obj_dir/acw-map.txt"
manifest="$obj_dir/AndroidManifest.xml"
managed_type="Plugin.Firebase.CloudMessaging.Platforms.Android.MyFirebaseMessagingService"
messaging_action="com.google.firebase.MESSAGING_EVENT"
# This probe validates the generated Android service metadata after full trimming.
# The integration app includes broad test fixtures and runner packages that are not
# linker-warning-clean, so do not let unrelated trim warnings skip the manifest check.
dotnet build "$project" \
-c Release \
-f net9.0-android \
/p:TrimMode=full \
/p:AndroidPackageFormat=apk \
/p:TreatWarningsAsErrors=false \
/p:WarningsAsErrors= \
/p:ILLinkTreatWarningsAsErrors=false
python3 - "$acw_map" "$manifest" "$managed_type" "$messaging_action" <<'PY'
from pathlib import Path
import sys
import xml.etree.ElementTree as ET
acw_map = Path(sys.argv[1])
manifest = Path(sys.argv[2])
managed_type = sys.argv[3]
messaging_action = sys.argv[4]
android_ns = "{http://schemas.android.com/apk/res/android}"
if not acw_map.exists():
raise SystemExit(f"Android callable-wrapper map was not generated: {acw_map}")
if not manifest.exists():
raise SystemExit(f"Android manifest was not generated: {manifest}")
java_type = None
for line in acw_map.read_text(encoding="utf-8").splitlines():
managed, separator, java = line.partition(";")
if not separator:
continue
if managed.split(",", 1)[0].strip() == managed_type:
java_type = java.strip()
break
if not java_type:
raise SystemExit(f"{managed_type} was not preserved in {acw_map}")
root = ET.parse(manifest).getroot()
services = [
service
for service in root.findall(".//service")
if service.attrib.get(f"{android_ns}name") == java_type
]
if not services:
raise SystemExit(f"{java_type} was not registered as a service in {manifest}")
service = services[0]
exported = service.attrib.get(f"{android_ns}exported")
if exported != "false":
raise SystemExit(
f"{java_type} should be registered with android:exported=\"false\", found {exported!r}"
)
actions = [
action.attrib.get(f"{android_ns}name")
for action in service.findall("./intent-filter/action")
]
if messaging_action not in actions:
raise SystemExit(
f"{java_type} is missing the {messaging_action} intent action in {manifest}"
)
print(f"Validated {managed_type} as {java_type} with android:exported=\"false\".")
PY