Skip to content
Open
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
12 changes: 12 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Jira ticket
<!-- e.g. FLW-1234 -->

## What changed and why

## How it was tested
<!-- Flavors and build type tested, tests added or run -->

## Checklist
- [ ] Room schema changed → DB version bumped, new migration added and tested (no edits to old migrations)
- [ ] `proguard-rules.pro` changed → every new `-keep` is narrow and has a comment saying why (see `docs/PLAY_VITALS_MONITORING.md` §5)
- [ ] New image/bitmap code decodes with downsampling and does not keep bitmaps after the screen closes
98 changes: 98 additions & 0 deletions .github/scripts/check_proguard_keeps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python3
"""Fail a PR that adds an unjustified or over-broad ProGuard/R8 -keep rule (FLW-1216).

Only lines ADDED by the PR are checked; the existing broad rules are FLW-1211's job.

Rules for every added `-keep*` line in a *.pro file:
1. It needs a `#` comment directly above it (one comment may cover a group of
keep lines added together).
2. It must not keep a wildcard package/class wholesale, e.g.
`-keep class org.piramalswasthya.sakhi.** { *; }` or `-keepnames class **`.
If one is truly needed, put `keep-broad-ok: <reason>` in the comment above.

Usage: check_proguard_keeps.py <base-ref> (e.g. origin/main)
"""
import re
import subprocess
import sys

WILDCARD_CLASS = re.compile(r"(\*\*|(^|[\s.])\*)(\s|\{|$)")
ALL_MEMBERS = re.compile(r"\{\s*\*\s*;\s*\}")
HUNK = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@")
BROAD_OK = "keep-broad-ok:"


def added_lines(base):
"""Return {path: set(line numbers added in the new file)} for *.pro files."""
diff = subprocess.run(
["git", "diff", "-U0", "--no-color", f"{base}...HEAD", "--", "*.pro"],
check=True, capture_output=True, text=True,
).stdout
result, path = {}, None
for line in diff.splitlines():
if line.startswith("+++ "):
path = None if line == "+++ /dev/null" else line[6:] # strip "+++ b/"
elif path and (m := HUNK.match(line)):
start, count = int(m.group(1)), int(m.group(2) or 1)
result.setdefault(path, set()).update(range(start, start + count))
return result


def class_spec(rule):
"""`-keep class a.b.** { *; }` -> `a.b.**` (text between the class keyword and `{`)."""
head = rule.split("{", 1)[0]
m = re.search(r"\b(class|interface|enum)\s+(.+)$", head.strip())
return m.group(2).split()[0] if m else ""


def is_broad(rule):
if not WILDCARD_CLASS.search(class_spec(rule)):
return False
# A wildcard class is fine when only specific members are kept.
return "{" not in rule or bool(ALL_MEMBERS.search(rule))


def comment_above(lines, added, idx):
"""Comment directly above lines[idx], skipping other lines added in the same group."""
i = idx - 1
while i >= 0:
text = lines[i].strip()
if text.startswith("#"):
return text
if not text or (i + 1) not in added:
return None
i -= 1
return None


def main():
if len(sys.argv) != 2:
print(__doc__)
return 2
errors = 0
for path, added in added_lines(sys.argv[1]).items():
with open(path, encoding="utf-8") as f:
lines = f.read().splitlines()
for n in sorted(added):
rule = lines[n - 1].strip()
if not rule.startswith("-keep"):
continue
comment = comment_above(lines, added, n - 1)
if comment is None:
print(f"::error file={path},line={n}::New keep rule has no comment above it "
f"explaining why it is needed: {rule}")
errors += 1
elif is_broad(rule) and BROAD_OK not in comment:
print(f"::error file={path},line={n}::Keep rule is too broad (wildcard class with all "
f"members kept), it blocks R8 shrinking and the Play DEX metric. Narrow it, or "
f"add '{BROAD_OK} <reason>' to the comment above: {rule}")
errors += 1
if errors:
print(f"{errors} ProGuard keep rule problem(s). See docs/PLAY_VITALS_MONITORING.md section 5.")
return 1
print("ProGuard keep rules OK.")
return 0


if __name__ == "__main__":
sys.exit(main())
18 changes: 18 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ concurrency:
cancel-in-progress: true

jobs:
# Separate from the build so a bad keep rule fails in seconds (FLW-1216). Only lines
# the PR adds are checked; the existing broad rules are being removed under FLW-1211.
proguard-keep-rules:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check new ProGuard keep rules
run: python3 .github/scripts/check_proguard_keeps.py "origin/${{ github.base_ref }}"

test-and-coverage:
runs-on: ubuntu-latest

Expand Down
103 changes: 103 additions & 0 deletions docs/PLAY_VITALS_MONITORING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Play Memory & DEX Monitoring Checklist (FLW-1216)

Google Play starts penalising apps that break the memory, bitmap or DEX optimisation
thresholds in **February 2027** (lower visibility, restricted publishing). This checklist
keeps the fixes from FLW-1211…1215 from regressing.

## Thresholds (P90, rolling 28 days, Play installs only)

| Metric | Threshold |
|---|---|
| Dynamic memory (anon RSS + swap, foreground) | 4 GB device: **2 GB** · 6–8 GB: 2.25 GB · 12 GB: 3.25 GB · 16 GB: 4.25 GB |
| Bitmap memory outside foreground | Perceptible/background: **200 MB** · cached: **400 MB** |
| DEX optimisation | **≥ 25 %** of DEX shrunk/obfuscated/optimised (only when DEX > 10 MB) |

Sideloaded installs are not counted in vitals, but the penalty still applies to the Play listing.

## Play apps

| App | Package |
|---|---|
| Saksham | `org.piramalswasthya.sakhi.saksham` |
| Niramay | `org.piramalswasthya.sakhi.niramay` |
| Xushrukha | `org.piramalswasthya.sakhi.xushrukha` |
| Mitanin | `org.piramalswasthya.sakhi.mitanin` |

## When

- **After every Play release** (about 7 days after rollout, once vitals have data): sections 1–3.
- **Every release build:** section 4.
- **January 2027 checkpoint** (before enforcement): all sections, all apps, and record the result on FLW-1216.

## 1. Play Console vitals (per app)

Play Console → app → **Android vitals** → **Memory** and **App size / DEX optimisation**.

- [ ] Dynamic memory P90 is below the threshold for every device RAM bucket.
- [ ] Background and cached bitmap memory P90 is below 200 MB / 400 MB.
- [ ] DEX optimisation is ≥ 25 % (or DEX is below 10 MB).
- [ ] No metric shows a warning, and none moved more than 20 % toward its threshold since the last check.
If one did, raise a ticket with the version where it started.

## 2. Crashlytics (per app)

Each flavor is a separate Firebase app, so pick the app first; this is the flavor filter.
Firebase console → **Crashlytics** → filter by latest version.

- [ ] Search issues for `OutOfMemoryError`. Note the count and affected users vs the previous version.
- [ ] No **new** OOM issue in the latest version. A new one → ticket with the top stack frame.
- [ ] Crash stack traces are de-obfuscated (readable class names). If not, the R8 mapping file
upload failed for that build.

## 3. Firebase Performance (per app)

Firebase console → **Performance** → **Custom traces**. Compare the latest version's P90 with the
previous version's.

| Trace | What it times | Flag if P90 grows more than |
|---|---|---|
| `login` | `UserRepo.authenticateUser` | 30 % |
| `full_pull` | First / incremental full pull (attr `type`) | 30 % |
| `ben_download` | Beneficiary download in `PullFromAmritWorker` | 30 % |
| `sync_push` | Each push worker (attr `worker`, `result`) | 30 % |
| `db_open` | Room DB open (attr `kind`) | 30 % |
| `db_encrypt_check` | SQLCipher encryption check (release only) | 30 % |

- [ ] No trace grew past its limit. If one did, raise a ticket with trace name, attribute and versions.
- [ ] Network request success rate shows no new drop on the main API host.

## 4. Release build DEX (each release, any one flavor)

After `bundle<Flavor>Release`:

```bash
# Total DEX size in the bundle
unzip -l app/build/outputs/bundle/<flavor>Release/app-<flavor>-release.aab \
| awk '/\.dex$/ {s+=$1; n++} END {printf "dex files: %d\ntotal dex: %.2f MB\n", n, s/1048576}'

# Share of app classes R8 renamed (proxy for obfuscation coverage; trend only)
grep -E '^org\.piramalswasthya\.sakhi\.\S+ -> \S+:$' app/build/outputs/mapping/<flavor>Release/mapping.txt \
| awk '{t++; if ($1 != substr($3,1,length($3)-1)) r++} END {printf "app classes renamed: %d/%d (%.1f%%)\n", r, t, 100*r/t}'
```

- [ ] DEX size did not grow more than 10 % since the last release without a known reason (new library, etc.).
- [ ] Renamed share did not drop since the last release.

## 5. Keep-rule review (every PR)

CI job **PR Checks → proguard-keep-rules** (`.github/scripts/check_proguard_keeps.py`) checks
every `-keep` line a PR adds to a `.pro` file:

- It needs a `#` comment directly above it saying why (one comment can cover a group added together).
- It must not keep a wildcard class or package wholesale, e.g. `-keep class org.piramalswasthya.sakhi.** { *; }`
or `-keepnames class com.foo.**`. Keep the specific classes or members instead.
- If a broad rule is truly unavoidable (a library that reflects over all its classes), write
`# keep-broad-ok: <reason>` above it. The reviewer must agree with the reason.

Rules that existed before this check are not flagged; they are being narrowed under FLW-1211.

## Log

| Date | Version | App | Memory P90 | Bitmap BG/cached | DEX opt % | New OOMs | Trace regressions | By |
|---|---|---|---|---|---|---|---|---|
| | | | | | | | | |
Loading