storeready 0.2.0__py3-none-any.whl

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.
Files changed (61) hide show
  1. storeready/__init__.py +3 -0
  2. storeready/__main__.py +5 -0
  3. storeready/advice/__init__.py +87 -0
  4. storeready/android/__init__.py +14 -0
  5. storeready/android/checks/__init__.py +10 -0
  6. storeready/android/checks/edge_to_edge.py +148 -0
  7. storeready/android/checks/large_screen.py +137 -0
  8. storeready/android/checks/page_size.py +180 -0
  9. storeready/android/checks/target_api.py +119 -0
  10. storeready/android/formats/__init__.py +2 -0
  11. storeready/android/formats/_guard.py +41 -0
  12. storeready/android/formats/arsc.py +140 -0
  13. storeready/android/formats/axml.py +210 -0
  14. storeready/android/formats/bundle.py +191 -0
  15. storeready/android/formats/elf.py +84 -0
  16. storeready/android/formats/protobuf.py +92 -0
  17. storeready/android/load.py +195 -0
  18. storeready/android/manifest.py +159 -0
  19. storeready/android/model.py +124 -0
  20. storeready/cli.py +240 -0
  21. storeready/core/__init__.py +36 -0
  22. storeready/core/artifact.py +48 -0
  23. storeready/core/check.py +58 -0
  24. storeready/core/engine.py +115 -0
  25. storeready/core/finding.py +71 -0
  26. storeready/core/frozen.py +22 -0
  27. storeready/core/platform.py +38 -0
  28. storeready/core/rulebook.py +109 -0
  29. storeready/ios/__init__.py +14 -0
  30. storeready/ios/checks/__init__.py +33 -0
  31. storeready/ios/checks/ipad_multitasking.py +75 -0
  32. storeready/ios/checks/liquid_glass.py +75 -0
  33. storeready/ios/checks/privacy_manifest.py +126 -0
  34. storeready/ios/checks/privacy_reasons.py +213 -0
  35. storeready/ios/checks/sdk_manifests.py +85 -0
  36. storeready/ios/checks/upload_settings.py +152 -0
  37. storeready/ios/checks/usage_descriptions.py +233 -0
  38. storeready/ios/checks/xcode_sdk.py +121 -0
  39. storeready/ios/formats/__init__.py +1 -0
  40. storeready/ios/formats/macho.py +118 -0
  41. storeready/ios/load.py +216 -0
  42. storeready/ios/model.py +151 -0
  43. storeready/ios/privacy.py +113 -0
  44. storeready/knowledge/__init__.py +0 -0
  45. storeready/knowledge/fixes.toml +75 -0
  46. storeready/knowledge/frameworks.toml +25 -0
  47. storeready/knowledge/rules.toml +130 -0
  48. storeready/py.typed +0 -0
  49. storeready/report/__init__.py +2 -0
  50. storeready/report/baseline.py +67 -0
  51. storeready/report/data.py +57 -0
  52. storeready/report/policy.py +17 -0
  53. storeready/report/sarif.py +97 -0
  54. storeready/report/text.py +118 -0
  55. storeready-0.2.0.dist-info/METADATA +67 -0
  56. storeready-0.2.0.dist-info/RECORD +61 -0
  57. storeready-0.2.0.dist-info/WHEEL +5 -0
  58. storeready-0.2.0.dist-info/entry_points.txt +2 -0
  59. storeready-0.2.0.dist-info/licenses/LICENSE +202 -0
  60. storeready-0.2.0.dist-info/licenses/NOTICE +20 -0
  61. storeready-0.2.0.dist-info/top_level.txt +1 -0
storeready/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """Lists what in a mobile app breaks under the app stores' current platform rules."""
2
+
3
+ __version__ = "0.2.0"
storeready/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from storeready.cli import main
4
+
5
+ sys.exit(main())
@@ -0,0 +1,87 @@
1
+ """Advice: recognises the framework an app was built with and attaches known, sourced fixes.
2
+
3
+ Works on core.Facts and core.Finding only, so it serves every platform without importing any.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import tomllib
9
+ from collections.abc import Callable
10
+ from dataclasses import dataclass
11
+ from fnmatch import fnmatchcase
12
+ from importlib import resources
13
+ from typing import Any
14
+
15
+ from storeready.core import Facts, Finding, Platform
16
+
17
+
18
+ def _knowledge(name: str) -> dict[str, Any]:
19
+ text = resources.files("storeready.knowledge").joinpath(name).read_text(encoding="utf-8")
20
+ return tomllib.loads(text)
21
+
22
+
23
+ def frameworks(platform: Platform, facts: Facts, data: dict[str, Any] | None = None) -> list[str]:
24
+ """Frameworks the app is built with, most specific first."""
25
+ data = data or _knowledge("frameworks.toml")
26
+ found: set[str] = set()
27
+ if platform is Platform.ANDROID:
28
+ markers = data.get("android", {}).get("native_libraries", {})
29
+ found |= {markers[n] for n in facts.native_libraries if n in markers}
30
+ else:
31
+ markers = data.get("ios", {}).get("frameworks", {})
32
+ found |= {markers[n] for n in facts.frameworks if n in markers}
33
+ order: list[str] = data.get("order", [])
34
+ return sorted(found, key=lambda f: order.index(f) if f in order else len(order))
35
+
36
+
37
+ @dataclass(frozen=True)
38
+ class Fix:
39
+ check: str
40
+ owner: str
41
+ text: str
42
+ source: str
43
+ subject_glob: str = "*"
44
+ framework: str = ""
45
+ evidence: str = ""
46
+ inferred: bool = False
47
+
48
+ def matches(self, finding: Finding, built_with: frozenset[str]) -> bool:
49
+ return (
50
+ finding.check == self.check
51
+ and _glob(finding.subject, self.subject_glob)
52
+ and (not self.framework or self.framework in built_with)
53
+ and (not self.evidence or any(self.evidence in e.detail for e in finding.evidence))
54
+ )
55
+
56
+
57
+ def load_fixes(data: dict[str, Any] | None = None) -> tuple[Fix, ...]:
58
+ data = data or _knowledge("fixes.toml")
59
+ return tuple(Fix(**entry) for entry in data.get("fix", []))
60
+
61
+
62
+ def advisor(
63
+ built_with: list[str], fixes: tuple[Fix, ...] | None = None
64
+ ) -> Callable[[Finding], Finding]:
65
+ """An enricher that names the owner and the specific fix of findings it recognises."""
66
+ known = load_fixes() if fixes is None else fixes
67
+ frameworks_set = frozenset(built_with)
68
+
69
+ def enrich(finding: Finding) -> Finding:
70
+ if finding.level == 0:
71
+ return finding
72
+ for fix in known:
73
+ if fix.matches(finding, frameworks_set):
74
+ note = " (inferred from the source)" if fix.inferred else ""
75
+ return finding.with_(owner=fix.owner, fix=f"{fix.text}{note} See {fix.source}")
76
+ return finding if finding.owner else finding.with_(owner="app")
77
+
78
+ return enrich
79
+
80
+
81
+ def _glob(subject: str, pattern: str) -> bool:
82
+ """fnmatch with {a,b} alternatives."""
83
+ if "{" in pattern and "}" in pattern:
84
+ head, rest = pattern.split("{", 1)
85
+ options, tail = rest.split("}", 1)
86
+ return any(_glob(subject, head + option + tail) for option in options.split(","))
87
+ return fnmatchcase(subject, pattern)
@@ -0,0 +1,14 @@
1
+ """Android: reads APKs and App Bundles and checks them against Google Play and Android rules."""
2
+
3
+ from storeready.android.checks import CHECKS
4
+ from storeready.android.load import load
5
+ from storeready.core import Platform, PlatformSupport
6
+
7
+ SUPPORT = PlatformSupport(
8
+ platform=Platform.ANDROID,
9
+ suffixes=frozenset({".apk", ".aab"}),
10
+ load=load,
11
+ checks=CHECKS,
12
+ )
13
+
14
+ __all__ = ["SUPPORT"]
@@ -0,0 +1,10 @@
1
+ """Android checks: one module per store rule, each implementing core.Check[AndroidApp]."""
2
+
3
+ from storeready.android.checks.edge_to_edge import EdgeToEdge
4
+ from storeready.android.checks.large_screen import LargeScreen
5
+ from storeready.android.checks.page_size import PageSize
6
+ from storeready.android.checks.target_api import TargetApi
7
+
8
+ CHECKS = (TargetApi(), PageSize(), LargeScreen(), EdgeToEdge())
9
+
10
+ __all__ = ["CHECKS", "EdgeToEdge", "LargeScreen", "PageSize", "TargetApi"]
@@ -0,0 +1,148 @@
1
+ """Apps that target API 35+ are drawn edge to edge; the theme opt-out
2
+ (windowOptOutEdgeToEdgeEnforcement) stops working when they target API 36."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from collections.abc import Mapping
7
+
8
+ from storeready.android.model import AndroidApp
9
+ from storeready.core import CheckDoc, CheckInfo, Context, Evidence, Finding, Level, Platform
10
+
11
+ FIX = (
12
+ "Handle window insets (status bar, navigation bar, display cutout) on every screen, "
13
+ "then remove windowOptOutEdgeToEdgeEnforcement from the theme."
14
+ )
15
+
16
+
17
+ DOC = CheckDoc(
18
+ reads=("Manifest", "Resources"),
19
+ what="Reads the app's resource table and lists the themes, including those that inherit it "
20
+ "from a parent, that set `windowOptOutEdgeToEdgeEnforcement`, and which activities use them.",
21
+ why="Apps that target API {android.edge_to_edge.enforced_from_target} or higher are drawn "
22
+ "edge to edge, under the status and navigation bars. The theme opt-out is ignored once an "
23
+ "app targets API {android.edge_to_edge.opt_out_removed_at_target}, which Google Play "
24
+ "requires for new apps and updates from {android.target_api.phone.deadline}.",
25
+ fix="Handle window insets on every screen (status bar, navigation bar, display cutout), then "
26
+ "remove the opt-out from the theme.",
27
+ example="""[BREAKS] edge-to-edge: Screens handle being drawn edge to edge
28
+ - (breaks) Theme AppTheme opts out of edge-to-edge (used by MainActivity).
29
+ Works until the app targets API 36.""",
30
+ limitations=(
31
+ "Themes set in code are not seen. An opt-out theme that no activity uses directly is "
32
+ "reported as a note.",
33
+ ),
34
+ since="0.2.0",
35
+ )
36
+
37
+
38
+ class EdgeToEdge:
39
+ info = CheckInfo(
40
+ id="edge-to-edge",
41
+ platform=Platform.ANDROID,
42
+ title="Screens handle being drawn edge to edge",
43
+ rules=("android.edge_to_edge",),
44
+ doc=DOC,
45
+ )
46
+
47
+ def run(self, app: AndroidApp, ctx: Context) -> list[Finding]:
48
+ rule = ctx.rule("android.edge_to_edge")
49
+ enforced: int = rule["enforced_from_target"]
50
+ removed: int = rule["opt_out_removed_at_target"]
51
+ target = app.manifest.target_sdk or 0
52
+ opt_outs = app.edge_to_edge_opt_outs
53
+
54
+ if target < enforced:
55
+ return [
56
+ Finding(
57
+ self.info.id,
58
+ Level.BREAKS,
59
+ subject="app",
60
+ title=f"Targets API {target}; screens are drawn edge to edge once it targets "
61
+ f"API {enforced}.",
62
+ detail="Content will then draw under the status and navigation bars "
63
+ "unless the app handles window "
64
+ "insets.",
65
+ evidence=(
66
+ Evidence("manifest", f"targetSdkVersion={target}", "AndroidManifest.xml"),
67
+ ),
68
+ fix=FIX.split(", then")[0] + ".",
69
+ source=rule.source,
70
+ )
71
+ ]
72
+ if opt_outs is None:
73
+ return [
74
+ Finding(
75
+ self.info.id,
76
+ Level.NOTE,
77
+ subject="app",
78
+ title="Couldn't read the resource table to look for the edge-to-edge opt-out.",
79
+ source=rule.source,
80
+ )
81
+ ]
82
+ used = self._themes_in_use(app, opt_outs)
83
+ if not opt_outs:
84
+ return [
85
+ Finding(
86
+ self.info.id,
87
+ Level.OK,
88
+ subject="app",
89
+ title="No theme opts out of edge-to-edge.",
90
+ source=rule.source,
91
+ )
92
+ ]
93
+ findings = []
94
+ for style_id, name in sorted(opt_outs.items(), key=lambda kv: kv[1]):
95
+ where = used.get(style_id)
96
+ if target >= removed:
97
+ level, when = (
98
+ Level.BREAKS,
99
+ (
100
+ f"Ignored on Android 16 and later for apps that target API {removed} or higher."
101
+ ),
102
+ )
103
+ else:
104
+ level, when = (
105
+ Level.BREAKS,
106
+ (f"Works until the app targets API {removed}."),
107
+ )
108
+ if where is None:
109
+ level = Level.NOTE
110
+ when += " No activity in the manifest uses this theme directly."
111
+ findings.append(
112
+ Finding(
113
+ self.info.id,
114
+ level,
115
+ subject=_style_subject(style_id, name),
116
+ title=f"Theme {name} opts out of edge-to-edge"
117
+ + (f" (used by {where})." if where else "."),
118
+ detail=when,
119
+ evidence=(
120
+ Evidence(
121
+ "resources", "windowOptOutEdgeToEdgeEnforcement=true", f"style/{name}"
122
+ ),
123
+ ),
124
+ fix=FIX,
125
+ source=rule.source,
126
+ )
127
+ )
128
+ return findings
129
+
130
+ @staticmethod
131
+ def _themes_in_use(app: AndroidApp, opt_outs: Mapping[int, str]) -> dict[int, str]:
132
+ used: dict[int, str] = {}
133
+ m = app.manifest
134
+ for activity in m.activities:
135
+ theme = activity.theme or m.app_theme
136
+ if theme is not None and theme in opt_outs:
137
+ used.setdefault(theme, activity.name.rsplit(".", 1)[-1])
138
+ if m.app_theme is not None and m.app_theme in opt_outs:
139
+ used.setdefault(m.app_theme, "the application")
140
+ return used
141
+
142
+
143
+ def _style_subject(style_id: int, name: str) -> str:
144
+ """Style names are stable across builds, ids are not, so name the subject by the style's
145
+ name, unless a resource shrinker obfuscated it."""
146
+ if not name or name == "?" or "obfuscated" in name:
147
+ return f"style/0x{style_id:08x}"
148
+ return f"style/{name}"
@@ -0,0 +1,137 @@
1
+ """On screens of sw600dp or more, Android ignores orientation, resizability and aspect-ratio
2
+ limits for apps that target API 36+, with an opt-out that ends at API 37 (games exempt)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from storeready.android.model import REFERENCE, Activity, AndroidApp
7
+ from storeready.core import CheckDoc, CheckInfo, Context, Evidence, Finding, Level, Platform
8
+
9
+ OPT_OUT = "PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY"
10
+ FIX = (
11
+ "Make this screen work in landscape and in resized windows and keep its state across "
12
+ "configuration changes, then remove the limit. Test on a tablet or foldable emulator."
13
+ )
14
+
15
+
16
+ DOC = CheckDoc(
17
+ reads=("Manifest",),
18
+ what="Lists the activities that lock their orientation (`screenOrientation`), refuse to "
19
+ 'resize (`resizeableActivity="false"`) or limit their aspect ratio, and says whether '
20
+ "each limit still applies at the app's target API.",
21
+ why="On displays at least 600dp wide (tablets, unfolded foldables, desktop windows), Android "
22
+ "ignores these limits for apps that target API {android.large_screen.applies_from_target}. "
23
+ "The `PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY` property keeps them until the app "
24
+ "targets API {android.large_screen.opt_out_removed_at_target}. A screen built for one "
25
+ "orientation can then be stretched, cut off or lose its state. Games are exempt.",
26
+ fix="Make each listed screen work in landscape and in resized windows and keep its state "
27
+ "across configuration changes, then remove the limit. Test on a tablet or foldable "
28
+ "emulator.",
29
+ example="""[BREAKS] large-screens: Screens work when large screens ignore orientation and size limits
30
+ - (breaks) MainActivity (launcher) sets screenOrientation="portrait", resizeableActivity="false".
31
+ The PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY opt-out keeps this limit until the app targets API 37.""",
32
+ limitations=(
33
+ "Only limits declared in the manifest are seen. Calls to `setRequestedOrientation()` in "
34
+ "code are not.",
35
+ "The check reports limits. Whether a layout copes without them can only be seen on a "
36
+ "device.",
37
+ ),
38
+ )
39
+
40
+
41
+ class LargeScreen:
42
+ info = CheckInfo(
43
+ id="large-screens",
44
+ platform=Platform.ANDROID,
45
+ title="Screens work when large screens ignore orientation and size limits",
46
+ rules=("android.large_screen",),
47
+ doc=DOC,
48
+ )
49
+
50
+ def run(self, app: AndroidApp, ctx: Context) -> list[Finding]:
51
+ rule = ctx.rule("android.large_screen")
52
+ applies: int = rule["applies_from_target"]
53
+ no_opt_out: int = rule["opt_out_removed_at_target"]
54
+ play = (f"Google Play also requires apps to fill foldable displays without letterboxing "
55
+ f"from {rule['play_adaptive_from']}.") # fmt: skip
56
+ m = app.manifest
57
+ target = m.target_sdk or 0
58
+
59
+ if m.is_game:
60
+ return [
61
+ Finding(
62
+ self.info.id,
63
+ Level.NOTE,
64
+ subject="app",
65
+ title="Marked as a game, so Android keeps its large-screen limits.",
66
+ detail='Games (android:appCategory="game") are exempt from the Android change, '
67
+ "but Google Play requires games to meet its foldable quality standard from "
68
+ f"{rule['play_games_from']}.",
69
+ source=rule["play_source"],
70
+ )
71
+ ]
72
+ findings = [self._by_reference(a, rule.source) for a in m.activities
73
+ if a.orientation == REFERENCE] # fmt: skip
74
+ limited = [a for a in m.activities if a.restrictions]
75
+ if not limited:
76
+ return findings or [
77
+ Finding(
78
+ self.info.id,
79
+ Level.OK,
80
+ subject="app",
81
+ title="No activity locks orientation, size or aspect ratio.",
82
+ source=rule.source,
83
+ )
84
+ ]
85
+
86
+ for activity in limited:
87
+ opted = activity.opts_out_of_resize or m.app_opts_out_of_resize
88
+ if target < applies:
89
+ when = f"Tablets and foldables ignore this once the app targets API {applies}."
90
+ elif target < no_opt_out and opted:
91
+ when = (
92
+ "The app uses the PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY opt-out, which "
93
+ f"stops working when it targets API {no_opt_out}. Google's pages disagree on "
94
+ "whether it keeps orientation locks before then."
95
+ )
96
+ elif target < no_opt_out:
97
+ when = "Screens of sw600dp or more ignore this limit."
98
+ else:
99
+ when = (
100
+ f"Screens of sw600dp or more ignore this limit, and from API {no_opt_out} "
101
+ "there is no opt-out."
102
+ )
103
+ findings.append(
104
+ Finding(
105
+ self.info.id,
106
+ Level.BREAKS,
107
+ subject=activity.name,
108
+ title=f"{_short(activity.name)}{' (launcher)' if activity.is_launcher else ''} "
109
+ f"sets {', '.join(activity.restrictions)}.",
110
+ detail=f"{when} {play}",
111
+ evidence=(
112
+ *(Evidence("manifest", r, activity.name) for r in activity.restrictions),
113
+ *((Evidence("manifest", OPT_OUT, activity.name),) if opted else ()),
114
+ ),
115
+ fix=FIX,
116
+ source=rule.source,
117
+ tags=("launcher",) if activity.is_launcher else (),
118
+ )
119
+ )
120
+ return findings
121
+
122
+ def _by_reference(self, activity: Activity, source: str) -> Finding:
123
+ return Finding(
124
+ self.info.id,
125
+ Level.NOTE,
126
+ subject=f"{activity.name}:orientation-reference",
127
+ title=f"{_short(activity.name)} sets screenOrientation through a resource reference.",
128
+ detail="The value depends on the device configuration and isn't read from the "
129
+ "manifest. If it locks the orientation, large screens ignore it.",
130
+ evidence=(Evidence("manifest", "screenOrientation=@...", activity.name),),
131
+ fix="Check the value the reference resolves to on large screens.",
132
+ source=source,
133
+ )
134
+
135
+
136
+ def _short(name: str) -> str:
137
+ return name.rsplit(".", 1)[-1] if "." in name else name
@@ -0,0 +1,180 @@
1
+ """64-bit native code must support 16 KB memory pages (Google Play, apps targeting API 35+)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import date
6
+
7
+ from storeready.android.formats import elf
8
+ from storeready.android.model import AndroidApp, NativeLib, PageAlignment
9
+ from storeready.core import CheckDoc, CheckInfo, Context, Evidence, Finding, Level, Platform
10
+
11
+ FIX = (
12
+ "Rebuild with NDK r28+ (or link with -Wl,-z,max-page-size=16384), update prebuilt "
13
+ "libraries from SDKs, and package with AGP 8.5.1+."
14
+ )
15
+
16
+
17
+ DOC = CheckDoc(
18
+ reads=("Native libraries", "BundleConfig.pb"),
19
+ what="Reads the ELF program headers of every 64-bit native library (`arm64-v8a`, `x86_64`) "
20
+ "and checks that each LOAD segment is aligned to 16 KB. In an APK, a library stored "
21
+ "uncompressed must also start on a 16 KB boundary inside the zip. In an App Bundle, "
22
+ "`BundleConfig.pb` must ask bundletool for 16 KB alignment.",
23
+ why="On devices with 16 KB memory pages, libraries aligned to 4 KB may fail to load "
24
+ "(Android's compatibility mode covers only some apps). Google Play "
25
+ "requires 16 KB support from apps that target API {android.page_size.applies_from_target} "
26
+ "or higher, and refuses updates without it from {android.page_size.deadline}.",
27
+ fix="Build native code with NDK r28 or newer, or link with `-Wl,-z,max-page-size=16384`. "
28
+ "Update prebuilt libraries that come from SDKs, and package with AGP 8.5.1 or newer. When "
29
+ "storeready recognises the library, the finding names the SDK version that fixes it.",
30
+ example="""[DUE] 16kb-pages: Native code supports 16 KB memory pages
31
+ - (due) libreactnativejni.so (arm64-v8a) doesn't support 16 KB pages.
32
+ Google Play refuses updates without 16 KB support from 2027-02-01; on 16 KB devices the library may fail to load.
33
+ Fix [sdk:React Native]: Upgrade to React Native 0.77 or newer, which ships 16 KB page support.""",
34
+ limitations=(
35
+ "The RELRO alignment rule on Google's page is not checked yet.",
36
+ "Files named `lib*.so` that aren't ELF libraries, such as scripts and archives, are "
37
+ "ignored because Android never loads them.",
38
+ ),
39
+ )
40
+
41
+
42
+ class PageSize:
43
+ info = CheckInfo(
44
+ id="16kb-pages",
45
+ platform=Platform.ANDROID,
46
+ title="Native code supports 16 KB memory pages",
47
+ rules=("android.page_size",),
48
+ doc=DOC,
49
+ )
50
+
51
+ def run(self, app: AndroidApp, ctx: Context) -> list[Finding]:
52
+ rule = ctx.rule("android.page_size")
53
+ alignment: int = rule["alignment"]
54
+ deadline: date = rule["deadline"]
55
+ abis: list[str] = rule["abis"]
56
+ applies: int = rule["applies_from_target"]
57
+ if (app.manifest.target_sdk or 0) < applies:
58
+ # Google Play's rule covers apps targeting API 35+; this app can't be uploaded
59
+ # anyway (target-api says so), but the library still fails on 16 KB devices.
60
+ level = Level.BREAKS
61
+ else:
62
+ level = Level.BLOCKER if ctx.today >= deadline else Level.DUE
63
+ when = (
64
+ f"Google Play refuses updates without 16 KB support from {deadline}; on 16 KB "
65
+ "devices the library may fail to load."
66
+ )
67
+
68
+ # The same file can be in a base APK and a split; check each path once.
69
+ libs = list({lib.path: lib for lib in app.native_libs if lib.abi in abis}.values())
70
+ if not libs:
71
+ return [self._none(app, rule.source)]
72
+
73
+ findings = []
74
+ for lib in libs:
75
+ evidence = _problems(lib, alignment)
76
+ if evidence:
77
+ findings.append(
78
+ Finding(
79
+ self.info.id,
80
+ level,
81
+ subject=lib.path,
82
+ title=f"{lib.name} ({lib.abi}) doesn't support 16 KB pages.",
83
+ detail=when,
84
+ evidence=evidence,
85
+ fix=FIX,
86
+ source=rule.source,
87
+ tags=("native-library",),
88
+ )
89
+ )
90
+ if app.is_bundle and app.bundle_alignment in (PageAlignment.K4, PageAlignment.UNSPECIFIED):
91
+ findings.append(
92
+ Finding(
93
+ self.info.id,
94
+ level,
95
+ subject="BundleConfig.pb",
96
+ title="The bundle stores native libraries uncompressed with 4 KB alignment"
97
+ + (
98
+ " (bundletool's default)."
99
+ if app.bundle_alignment is PageAlignment.UNSPECIFIED
100
+ else "."
101
+ ),
102
+ detail="APKs built from this bundle get 4 KB aligned libraries unless the "
103
+ "bundle asks for PAGE_ALIGNMENT_16K.",
104
+ evidence=(
105
+ Evidence(
106
+ "bundle-config",
107
+ f"alignment={app.bundle_alignment.value}",
108
+ "BundleConfig.pb",
109
+ ),
110
+ ),
111
+ fix="Build the bundle with AGP 8.5.1 or newer.",
112
+ source=rule.source,
113
+ )
114
+ )
115
+ if findings:
116
+ return findings
117
+ count = len(libs)
118
+ return [
119
+ Finding(
120
+ self.info.id,
121
+ Level.OK,
122
+ subject="all",
123
+ title="The 64-bit native library supports 16 KB pages."
124
+ if count == 1
125
+ else f"All {count} 64-bit native libraries support 16 KB pages.",
126
+ source=rule.source,
127
+ )
128
+ ]
129
+
130
+ def _none(self, app: AndroidApp, source: str) -> Finding:
131
+ if app.native_libs:
132
+ return Finding(
133
+ self.info.id,
134
+ Level.NOTE,
135
+ subject="all",
136
+ title="Native libraries are 32-bit only.",
137
+ detail="The 16 KB rule covers 64-bit ABIs; Google Play also "
138
+ "requires 64-bit libraries.",
139
+ source=source,
140
+ )
141
+ hint = (
142
+ ""
143
+ if app.is_bundle or len(app.files) > 1
144
+ else (
145
+ " Apps installed from Google Play keep native code in split APKs "
146
+ "(split_config.arm64_v8a.apk); pass those too, or check a universal APK."
147
+ )
148
+ )
149
+ return Finding(
150
+ self.info.id,
151
+ Level.OK,
152
+ subject="all",
153
+ title="No native libraries found, so 16 KB pages don't apply.",
154
+ detail=hint.strip(),
155
+ source=source,
156
+ )
157
+
158
+
159
+ def _problems(lib: NativeLib, alignment: int) -> tuple[Evidence, ...]:
160
+ if not lib.data.startswith(b"\x7fELF"):
161
+ return () # a script or archive named .so so Android unpacks it; never loaded
162
+ try:
163
+ parsed = elf.parse(lib.data)
164
+ except elf.ElfError as e:
165
+ return (Evidence("elf", f"unreadable ELF headers ({e})", lib.path),)
166
+ found = []
167
+ low = [s.align for s in parsed.load_segments if s.align < alignment]
168
+ if low:
169
+ found.append(
170
+ Evidence("elf", f"LOAD segment aligned to {min(low)} bytes, need {alignment}", lib.path)
171
+ )
172
+ if not lib.compressed and lib.data_offset is not None and lib.data_offset % alignment:
173
+ found.append(
174
+ Evidence(
175
+ "zip",
176
+ f"stored uncompressed at offset {lib.data_offset}, not a multiple of {alignment}",
177
+ lib.path,
178
+ )
179
+ )
180
+ return tuple(found)