Luigit
repositories / termux-janitor

termux-janitor

Interactive cleanup assistant for Termux: transparent, safe, confirmed disk reclamation.

owned by admin

src/android_allowlist.zig

Raw
//! Android allowlist verification (`TJ-ADAPT-09`).
//!
//! Validates that `spec_data.android_packages` contains exactly the
//! version-1 allowlisted identifiers with correct roles.
const std = @import("std");
const spec_data = @import("spec_data");

/// Expected Android Termux package identifiers in canonical order.
const expected: []const []const u8 = &.{
    "com.termux",
    "com.termux.api",
    "com.termux.boot",
    "com.termux.float",
    "com.termux.gui",
    "com.termux.styling",
    "com.termux.tasker",
    "com.termux.widget",
    "com.termux.x11",
};

/// Verify allowlist identities and roles (`TJ-ADAPT-09`).
/// Returns true if the allowlist is valid.
pub fn verify() bool {
    // Check count matches
    if (spec_data.android_packages.len != expected.len) return false;

    // Check each identity is present exactly once
    var i: usize = 0;
    while (i < expected.len) : (i += 1) {
        const exp = expected[i];
        const actual = spec_data.android_packages[i].identifier;
        if (!std.mem.eql(u8, exp, actual)) return false;

        // Check no duplicates
        var j: usize = 0;
        while (j < i) : (j += 1) {
            if (std.mem.eql(u8, spec_data.android_packages[j].identifier, exp)) {
                return false;
            }
        }

        // Check roles: com.termux is base, rest are add_on
        if (std.mem.eql(u8, exp, "com.termux")) {
            if (spec_data.android_packages[i].role != .base) return false;
        } else {
            if (spec_data.android_packages[i].role != .add_on) return false;
        }
    }

    return true;
}