[simple_builder] actualizar a versión final

This commit is contained in:
Luis Guzmán 2026-03-12 03:04:37 -06:00
parent 177b025139
commit 77742cd2a2
4 changed files with 154 additions and 114 deletions

View File

@ -4,10 +4,10 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-03-07T07:26:40.093624067Z">
<DropdownSelection timestamp="2026-03-07T08:21:48.428800901Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=RF8Y80CE2DA" />
<DeviceId pluginId="PhysicalDevice" identifier="serial=69K7MB899PKJGQBI" />
</handle>
</Target>
</DropdownSelection>

View File

@ -3,7 +3,6 @@
package="org.iiab.controller"
xmlns:tools="http://schemas.android.com/tools">
<!-- Android 11+ Package Visibility -->
<queries>
<package android:name="com.termux" />
</queries>
@ -13,7 +12,6 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/Theme.IIABController">
<!-- VPN Service (Network Layer) -->
<service android:name=".TProxyService" android:process=":native"
android:permission="android.permission.BIND_VPN_SERVICE"
android:exported="true"
@ -21,34 +19,28 @@
<intent-filter>
<action android:name="android.net.VpnService"/>
</intent-filter>
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="VPN service"/>
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE" android:value="VPN service"/>
</service>
<!-- Watchdog Service (Keep-Alive Layer) -->
<service android:name=".WatchdogService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="specialUse">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="Watchdog and Heartbeat"/>
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE" android:value="Watchdog and Heartbeat"/>
</service>
<receiver android:enabled="true" android:name=".ServiceReceiver"
android:exported="true">
<receiver android:enabled="true" android:name=".ServiceReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<!-- VPN Recovery Receiver (The Boomerang) -->
<receiver android:name=".VpnRecoveryReceiver" android:exported="false">
<intent-filter>
<action android:name="org.iiab.controller.RECOVER_VPN" />
</intent-filter>
</receiver>
<!-- Termux Result Callback Receiver -->
<receiver android:name=".TermuxCallbackReceiver" android:exported="false">
<intent-filter>
<action android:name="org.iiab.controller.TERMUX_OUTPUT" />
@ -62,7 +54,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AppListActivity" android:label="@string/app_name"/>
@ -73,13 +64,14 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="com.termux.permission.RUN_COMMAND" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"
android:minSdkVersion="34" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" android:minSdkVersion="34" />
</manifest>

View File

@ -8,11 +8,16 @@ import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.SystemClock;
import android.util.Log;
import androidx.core.app.NotificationCompat;
import java.util.Locale;
public class WatchdogService extends Service {
private static final String CHANNEL_ID = "watchdog_channel";
@ -22,7 +27,9 @@ public class WatchdogService extends Service {
public static final String ACTION_STOP = "org.iiab.controller.WATCHDOG_STOP";
public static final String ACTION_HEARTBEAT = "org.iiab.controller.HEARTBEAT";
private static final int HEARTBEAT_INTERVAL_MS = 20 * 1000;
private PowerManager.WakeLock wakeLock;
private WifiManager.WifiLock wifiLock;
private long lastPulseTime = 0;
@Override
public void onCreate() {
@ -40,65 +47,85 @@ public class WatchdogService extends Service {
stopWatchdog();
return START_NOT_STICKY;
} else if (ACTION_HEARTBEAT.equals(action)) {
IIABWatchdog.performHeartbeat(this);
// CRITICAL: Reschedule for the next pulse to create an infinite loop
performPulse();
scheduleHeartbeat();
}
}
return START_STICKY;
}
private void startWatchdog() {
Notification notification = createNotification();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(NOTIFICATION_ID, notification);
} else {
startForeground(NOTIFICATION_ID, notification);
private void performPulse() {
long now = System.currentTimeMillis();
long delta = (lastPulseTime == 0) ? 0 : (now - lastPulseTime);
lastPulseTime = now;
boolean isNetworkConnected = isNetworkConnected();
String logMessage = String.format(Locale.getDefault(), "Pulse: Stimulating Termux... [Delta: %dms] [Network: %s]",
delta, isNetworkConnected ? "OK" : "FAIL");
IIABWatchdog.writeToBlackBox(this, logMessage);
IIABWatchdog.sendStimulus(this);
}
IIABWatchdog.logSessionStart(this);
private boolean isNetworkConnected() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null) return false;
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnected();
}
private void startWatchdog() {
acquireLocks();
startForeground(NOTIFICATION_ID, createNotification());
lastPulseTime = System.currentTimeMillis();
scheduleHeartbeat();
}
private void stopWatchdog() {
cancelHeartbeat();
IIABWatchdog.logSessionStop(this);
releaseLocks();
stopForeground(true);
stopSelf();
}
private PendingIntent getHeartbeatPendingIntent() {
Intent intent = new Intent(this, WatchdogService.class);
intent.setAction(ACTION_HEARTBEAT);
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags |= PendingIntent.FLAG_IMMUTABLE;
private void acquireLocks() {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "IIAB:WatchdogWakeLock");
wakeLock.acquire(10 * 60 * 1000L); // 10 minutes max lock
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "IIAB:WatchdogWifiLock");
wifiLock.acquire();
}
return PendingIntent.getService(this, 0, intent, flags);
private void releaseLocks() {
if (wakeLock != null && wakeLock.isHeld()) wakeLock.release();
if (wifiLock != null && wifiLock.isHeld()) wifiLock.release();
}
private void scheduleHeartbeat() {
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = getHeartbeatPendingIntent();
Intent intent = new Intent(this, WatchdogService.class);
intent.setAction(ACTION_HEARTBEAT);
int flags = PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, flags);
if (alarmManager != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// This wakes up the device even in Doze Mode
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + HEARTBEAT_INTERVAL_MS,
pendingIntent);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 30000, pendingIntent);
} else {
alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + HEARTBEAT_INTERVAL_MS,
pendingIntent);
alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 30000, pendingIntent);
}
}
}
private void cancelHeartbeat() {
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = getHeartbeatPendingIntent();
if (alarmManager != null) {
alarmManager.cancel(pendingIntent);
}
Intent intent = new Intent(this, WatchdogService.class);
intent.setAction(ACTION_HEARTBEAT);
int flags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0;
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, flags);
if (alarmManager != null) alarmManager.cancel(pendingIntent);
}
@Override
@ -108,35 +135,21 @@ public class WatchdogService extends Service {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
public IBinder onBind(Intent intent) { return null; }
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID, "IIAB Watchdog Service",
NotificationManager.IMPORTANCE_HIGH
);
channel.setDescription("Ensures services remain active when screen is off.");
NotificationManager manager = getSystemService(NotificationManager.class);
if (manager != null) {
manager.createNotificationChannel(channel);
}
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Watchdog Service", NotificationManager.IMPORTANCE_LOW);
NotificationManager nm = getSystemService(NotificationManager.class);
if (nm != null) nm.createNotificationChannel(channel);
}
}
private Notification createNotification() {
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_IMMUTABLE);
return new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("IIAB Watchdog Active")
.setContentText("Protecting Termux environment...")
.setContentText("Maintaining Termux environment...")
.setSmallIcon(android.R.drawable.ic_lock_idle_lock)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setOngoing(true)
.build();
}

View File

@ -2,14 +2,13 @@
set -euo pipefail
# gen_simple_inplace.sh
# Generate PEP 503 "simple" indexes in-place for existing directories:
# <SIMPLE_DIR>/<pkg>/index.html
# Optionally generates:
# <SIMPLE_DIR>/index.html
# Moves wheels from a pool to their corresponding PEP 503 directory and generates the index.html files.
# Standardizes web permissions (755 dir, 644 files)
die() { echo "ERROR: $*" >&2; exit 1; }
SIMPLE_DIR=""
FINAL_REPO=""
W_POOL=""
ONLY_PKG=""
NO_TOP=0
DO_VERIFY=0
@ -17,7 +16,8 @@ VERIFY_ONLY=0
while [ $# -gt 0 ]; do
case "$1" in
--simple-dir) SIMPLE_DIR="${2:-}"; shift 2 ;;
--final-repo|--simple-dir) FINAL_REPO="${2:-}"; shift 2 ;;
--w-pool) W_POOL="${2:-}"; shift 2 ;;
--pkg) ONLY_PKG="${2:-}"; shift 2 ;;
--no-top) NO_TOP=1; shift ;;
--verify) DO_VERIFY=1; shift ;;
@ -25,14 +25,17 @@ while [ $# -gt 0 ]; do
-h|--help)
cat <<'EOF'
Usage:
./gen_simple_inplace.sh --simple-dir /var/www/.../simple
./gen_simple_inplace.sh --simple-dir /var/www/.../simple --pkg cffi --no-top
./gen_simple_inplace.sh --simple-dir /var/www/.../simple --verify
./gen_simple_inplace.sh --simple-dir /var/www/.../simple --verify-only
./simple_builder.sh --final-repo ~/simple/ --w-pool ~/wheel_pool/
./simple_builder.sh --final-repo ~/simple/ --pkg cffi
./simple_builder.sh --final-repo ~/simple/ --verify
Options:
--no-top Don't rewrite /simple/index.html
--verify Verify that each <pkg>/index.html href exists and sha256 matches
--verify-only Verify only (do not regenerate any index.html)
--final-repo Path to the repository's root directory (e.g., ~/simple/)
--w-pool Path to the folder containing new wheels to accommodate (e.g., ~/wheel_pool/)
--pkg Update/Verify only a specific package
--no-top Do not regenerate the main /simple/index.html file
--verify Verify that the href attributes exist and the SHA256 attributes match
--verify-only Only verify (does not regenerate any index.html files or move wheels)
EOF
exit 0
;;
@ -40,16 +43,40 @@ EOF
esac
done
[ -n "$SIMPLE_DIR" ] || die "--simple-dir is required"
[ -d "$SIMPLE_DIR" ] || die "Not a directory: $SIMPLE_DIR"
[ -n "$FINAL_REPO" ] || die "--final-repo is required"
[ -d "$FINAL_REPO" ] || die "It is not a valid directory: $FINAL_REPO"
is_artifact() {
case "$1" in
*.whl|*.tar.gz|*.zip|*.tgz) return 0 ;;
*) return 1 ;;
esac
# Strict PEP 503 normalization
normalize_pkg_name() {
echo "$1" | tr '[:upper:]' '[:lower:]' | sed -E 's/[-_.]+/-/g'
}
# 1. Process the Pool of Wheels
if [ "$VERIFY_ONLY" -eq 0 ] && [ -n "$W_POOL" ]; then
[ -d "$W_POOL" ] || die "The pool is not a valid directory: $W_POOL"
echo "=> Scanning pool of wheels in: $W_POOL"
while IFS= read -r -d '' whl; do
filename="$(basename "$whl")"
# The distribution name is everything that comes before the first hyphen (-)
raw_dist="${filename%%-*}"
norm_pkg="$(normalize_pkg_name "$raw_dist")"
dest_dir="$FINAL_REPO/$norm_pkg"
# Create the folder and ensure its web permissions
mkdir -p "$dest_dir"
chmod 755 "$dest_dir"
echo " -> Moving: $filename to the directory /$norm_pkg/"
mv -f "$whl" "$dest_dir/"
# Ensure that the newly moved file has web permissions
chmod 644 "$dest_dir/$filename"
done < <(find "$W_POOL" -maxdepth 1 -type f -name '*.whl' -print0)
echo "=> Moving complete."
fi
verify_pkg_index() {
local pkgdir="$1"
local pkgname="$2"
@ -57,19 +84,17 @@ verify_pkg_index() {
local errs=0
if [ ! -f "$idx" ]; then
echo "VERIFY FAIL [$pkgname]: missing index.html" >&2
echo "VERIFY FAIL [$pkgname]: index.html is missing" >&2
return 1
fi
# Extract href targets like: filename#sha256=....
# We assume filenames don't contain quotes/spaces (true for wheels/sdists typically).
while IFS= read -r href; do
[ -n "$href" ] || continue
local file="${href%%#sha256=*}"
local want="${href##*#sha256=}"
if [ ! -f "$pkgdir/$file" ]; then
echo "VERIFY FAIL [$pkgname]: missing file: $file" >&2
echo "VERIFY FAIL [$pkgname]: file is missing: $file" >&2
errs=$((errs+1))
continue
fi
@ -78,12 +103,11 @@ verify_pkg_index() {
got="$(sha256sum "$pkgdir/$file" | awk '{print $1}')"
if [ "$got" != "$want" ]; then
echo "VERIFY FAIL [$pkgname]: sha256 mismatch for $file" >&2
echo " want: $want" >&2
echo " expected: $want" >&2
echo " got: $got" >&2
errs=$((errs+1))
fi
done < <(
# Pull href="..."; keep only those containing #sha256=
grep -oE 'href="[^"]+"' "$idx" \
| sed -E 's/^href="(.*)"$/\1/' \
| grep -E '#sha256=' || true
@ -103,61 +127,72 @@ write_pkg_index() {
local pkgname="$2"
local idx="$pkgdir/index.html"
# Collect artifacts in that pkg dir
mapfile -t files < <(find "$pkgdir" -maxdepth 1 -type f \( -name '*.whl' -o -name '*.tar.gz' -o -name '*.zip' -o -name '*.tgz' \) -printf '%f\n' | sort)
# Ensure directory and existing wheels permissions prior to this script
chmod 755 "$pkgdir"
find "$pkgdir" -maxdepth 1 -type f -name '*.whl' -exec chmod 644 {} +
# If no artifacts, skip (or you can still write an empty index if you want)
mapfile -t files < <(find "$pkgdir" -maxdepth 1 -type f -name '*.whl' -printf '%f\n' | sort)
[ "${#files[@]}" -gt 0 ] || return 0
{
echo "<!doctype html>"
echo "<html><head><meta charset=\"utf-8\"><title>${pkgname}</title></head><body>"
for bn in "${files[@]}"; do
# hash the file in place
sha="$(sha256sum "$pkgdir/$bn" | awk '{print $1}')"
printf '<a href="%s#sha256=%s">%s</a><br/>\n' "$bn" "$sha" "$bn"
done
echo "</body></html>"
} > "$idx"
# Ensure generated index permissions
chmod 644 "$idx"
}
# Determine package dirs
# Determine package directories
pkg_dirs=()
if [ -n "$ONLY_PKG" ]; then
[ -d "$SIMPLE_DIR/$ONLY_PKG" ] || die "Package dir not found: $SIMPLE_DIR/$ONLY_PKG"
pkg_dirs+=("$SIMPLE_DIR/$ONLY_PKG")
ONLY_PKG="$(normalize_pkg_name "$ONLY_PKG")"
[ -d "$FINAL_REPO/$ONLY_PKG" ] || die "Package directory not found: $FINAL_REPO/$ONLY_PKG"
pkg_dirs+=("$FINAL_REPO/$ONLY_PKG")
else
# All subdirs except hidden ones
while IFS= read -r d; do
pkg_dirs+=("$d")
done < <(find "$SIMPLE_DIR" -mindepth 1 -maxdepth 1 -type d ! -name '.*' | sort)
done < <(find "$FINAL_REPO" -mindepth 1 -maxdepth 1 -type d ! -name '.*' | sort)
fi
if [ "$VERIFY_ONLY" -eq 0 ]; then
# Generate per-package indexes
echo "=> Generating indexes (index.html) and standardizing permissions..."
# Ensure root directory permissions
chmod 755 "$FINAL_REPO"
for d in "${pkg_dirs[@]}"; do
pkg="$(basename "$d")"
write_pkg_index "$d" "$pkg"
done
# Top index (optional)
# Main Index
if [ "$NO_TOP" -eq 0 ] && [ -z "$ONLY_PKG" ]; then
top="$SIMPLE_DIR/index.html"
top="$FINAL_REPO/index.html"
{
echo "<!doctype html>"
echo "<html><head><meta charset=\"utf-8\"><title>Simple Index</title></head><body>"
for d in "${pkg_dirs[@]}"; do
pkg="$(basename "$d")"
if find "$d" -maxdepth 1 -type f \( -name '*.whl' -o -name '*.tar.gz' -o -name '*.zip' -o -name '*.tgz' \) | grep -q .; then
if find "$d" -maxdepth 1 -type f -name '*.whl' | grep -q .; then
printf '<a href="./%s/">%s</a><br/>\n' "$pkg" "$pkg"
fi
done
echo "</body></html>"
} > "$top"
# Main index permissions
chmod 644 "$top"
fi
fi
if [ "$DO_VERIFY" -eq 1 ]; then
echo "=> Verifying integrity..."
vfail=0
for d in "${pkg_dirs[@]}"; do
pkg="$(basename "$d")"
@ -166,12 +201,12 @@ if [ "$DO_VERIFY" -eq 1 ]; then
fi
done
if [ "$vfail" -ne 0 ]; then
die "Verification failed"
die "Verification failed for one or more packages."
fi
fi
if [ "$VERIFY_ONLY" -eq 1 ]; then
echo "OK: verified indexes under: $SIMPLE_DIR"
echo "=> OK: indexes verified in: $FINAL_REPO"
else
echo "OK: indexes generated under: $SIMPLE_DIR"
echo "=> OK: process finished successfully in: $FINAL_REPO"
fi