package com.aethex.os; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.view.KeyEvent; import android.view.View; import android.view.WindowInsets; import android.view.WindowInsetsController; import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.ScrollView; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; /** * AeThexOS Terminal - Real root shell with full system access. * Execute actual Linux commands on the device. */ public class TerminalActivity extends AppCompatActivity { private ThemeManager themeManager; private TextView outputView; private EditText inputView; private ScrollView scrollView; private Handler mainHandler; // Current working directory (simulated) private String currentDir = "/sdcard"; // Command history private List commandHistory = new ArrayList<>(); private int historyIndex = -1; // Root status private boolean hasRoot = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_terminal); hideSystemUI(); themeManager = new ThemeManager(this); mainHandler = new Handler(Looper.getMainLooper()); outputView = findViewById(R.id.terminal_output); inputView = findViewById(R.id.terminal_input); scrollView = findViewById(R.id.terminal_scroll); // Apply Source Code Pro font outputView.setTypeface(themeManager.getMonoFont(this)); inputView.setTypeface(themeManager.getMonoFont(this)); findViewById(R.id.terminal_back).setOnClickListener(v -> { finish(); overridePendingTransition(R.anim.scale_in, R.anim.slide_down_out); }); // Check root status new Thread(() -> { hasRoot = RootShell.isRootAvailable(); mainHandler.post(this::showWelcome); }).start(); // Handle enter key inputView.setOnEditorActionListener((v, actionId, event) -> { if (actionId == EditorInfo.IME_ACTION_SEND || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) { String cmd = inputView.getText().toString().trim(); if (!cmd.isEmpty()) { commandHistory.add(cmd); historyIndex = commandHistory.size(); processCommand(cmd); inputView.setText(""); } return true; } return false; }); inputView.requestFocus(); AeThexKeyboard.attach(this); } private void showWelcome() { appendColored("╔══════════════════════════════════════════╗", "#06B6D4"); appendColored("║ AeThexOS Terminal v2.1.0 [ROOT] ║", "#06B6D4"); appendColored("╚══════════════════════════════════════════╝", "#06B6D4"); appendOutput(""); if (hasRoot) { appendColored(" ✓ ROOT ACCESS GRANTED", "#22C55E"); appendColored(" ✓ Full system privileges enabled", "#22C55E"); } else { appendColored(" ⚠ Root access unavailable", "#FBBF24"); appendColored(" ⚠ Running in restricted mode", "#FBBF24"); } // Check Terminal Pro ModuleManager modules = ModuleManager.getInstance(this); if (modules.hasTerminalPro()) { appendColored(" ★ Terminal Pro features enabled", "#A855F7"); } appendOutput(""); appendColored("Type 'help' for commands, or run any Linux command.", "#66FFFFFF"); appendColored("Prefix with 'su' for root execution.\n", "#66FFFFFF"); } private void processCommand(String cmd) { String prompt = hasRoot ? "root@aethex:~# " : "user@aethex:~$ "; appendColored(prompt + cmd, "#06B6D4"); String[] parts = cmd.split("\\s+"); String command = parts[0].toLowerCase(); // Terminal Pro aliases ModuleManager modules = ModuleManager.getInstance(this); if (modules.hasTerminalPro()) { // Expand aliases switch (command) { case "ll": cmd = "ls -la"; parts = cmd.split("\\s+"); command = "ls"; break; case "la": cmd = "ls -a"; parts = cmd.split("\\s+"); command = "ls"; break; case "l": cmd = "ls -l"; parts = cmd.split("\\s+"); command = "ls"; break; case "cls": outputView.setText(""); return; case "..": cmd = "cd .."; parts = cmd.split("\\s+"); command = "cd"; break; case "c": cmd = "clear"; command = "clear"; break; case "h": cmd = "history"; command = "history"; break; } } // Built-in commands switch (command) { case "help": showHelp(); return; case "clear": case "cls": outputView.setText(""); return; case "exit": case "quit": finish(); overridePendingTransition(R.anim.scale_in, R.anim.slide_down_out); return; case "neofetch": showNeofetch(); return; case "rootcheck": checkRoot(); return; case "sysinfo": showSysInfo(); return; case "processes": case "ps": showProcesses(); return; case "netinfo": showNetInfo(); return; case "cpuinfo": showCpuInfo(); return; case "meminfo": showMemInfo(); return; case "diskinfo": case "df": showDiskInfo(); return; case "mounts": showMounts(); return; case "selinux": showSelinux(); return; case "getprop": if (parts.length > 1) { executeAsync(cmd, false); } else { appendColored("Usage: getprop ", "#FBBF24"); } return; case "setprop": if (parts.length > 2) { executeAsync(cmd, true); } else { appendColored("Usage: setprop ", "#FBBF24"); } return; case "remount": remountSystem(); return; case "reboot": rebootDevice(parts); return; case "dmesg": executeAsync("dmesg | tail -50", true); return; case "logcat": executeAsync("logcat -d -t 30", false); return; case "su": if (parts.length > 1) { // Execute rest of command as root String rootCmd = cmd.substring(3).trim(); executeAsync(rootCmd, true); } else { if (hasRoot) { appendColored("Root shell active. All commands run as root.", "#22C55E"); } else { appendColored("Root access denied.", "#EF4444"); } } return; case "shell": case "sh": if (parts.length > 1) { String shellCmd = cmd.substring(command.length()).trim(); executeAsync(shellCmd, false); } else { appendColored("Usage: sh ", "#FBBF24"); } return; case "history": showHistory(); return; case "modules": showModules(); return; } // Execute as real shell command executeAsync(cmd, hasRoot); } private void showHistory() { ModuleManager modules = ModuleManager.getInstance(this); if (!modules.hasTerminalPro()) { appendColored("⚠ Terminal Pro required for command history", "#FBBF24"); appendColored(" Install from Marketplace to unlock", "#66FFFFFF"); return; } appendColored("\n═══ Command History ═══", "#A855F7"); if (commandHistory.isEmpty()) { appendOutput(" (no commands yet)"); } else { int start = Math.max(0, commandHistory.size() - 20); for (int i = start; i < commandHistory.size(); i++) { appendOutput(" " + (i + 1) + " " + commandHistory.get(i)); } } appendOutput(""); } private void showModules() { ModuleManager mm = ModuleManager.getInstance(this); appendColored("\n═══ Installed Modules ═══", "#A855F7"); appendOutput(" " + mm.getInstalledCount() + " modules installed"); appendOutput(" " + mm.getTotalCreditsSpent() + " Cr spent"); appendOutput(""); if (mm.hasTerminalPro()) appendColored(" ✓ Terminal Pro", "#22C55E"); if (mm.hasDataAnalyzer()) appendColored(" ✓ Data Analyzer", "#22C55E"); if (mm.hasNetScanner()) appendColored(" ✓ Net Scanner", "#22C55E"); if (mm.hasHexEditor()) appendColored(" ✓ Hex Editor", "#22C55E"); if (mm.hasEncryption()) appendColored(" ✓ Cipher Module", "#22C55E"); if (mm.hasAppLock()) appendColored(" ✓ Shield Guard", "#22C55E"); if (mm.hasStealthMode()) appendColored(" ✓ Ghost Protocol", "#22C55E"); if (mm.hasBiometricLock()) appendColored(" ✓ Vault Lock", "#22C55E"); if (mm.hasNeonThemes()) appendColored(" ✓ Neon Theme Pack", "#22C55E"); if (mm.hasCRTOverlay()) appendColored(" ✓ Retro CRT Skin", "#22C55E"); if (mm.hasHoloGlass()) appendColored(" ✓ Holo Glass UI", "#22C55E"); if (mm.hasSoundPackPro()) appendColored(" ✓ Sound Pack Pro", "#22C55E"); if (mm.hasPixelArcade()) appendColored(" ✓ Pixel Arcade", "#22C55E"); if (mm.hasSynthStudio()) appendColored(" ✓ Synth Studio", "#22C55E"); appendOutput(""); } private void showHelp() { ModuleManager modules = ModuleManager.getInstance(this); boolean hasPro = modules.hasTerminalPro(); appendColored("\n═══ AeThexOS Terminal Commands ═══", "#06B6D4"); appendOutput(""); appendColored("BUILT-IN:", "#FBBF24"); appendOutput(" help Show this help"); appendOutput(" clear Clear terminal"); appendOutput(" exit Close terminal"); appendOutput(" neofetch System overview"); appendOutput(" modules Show installed modules"); appendOutput(""); appendColored("SYSTEM INFO:", "#FBBF24"); appendOutput(" sysinfo Full system information"); appendOutput(" cpuinfo CPU details"); appendOutput(" meminfo Memory statistics"); appendOutput(" diskinfo Storage usage"); appendOutput(" processes Running processes"); appendOutput(" netinfo Network interfaces"); appendOutput(" mounts Mounted filesystems"); appendOutput(" selinux SELinux status"); appendOutput(" rootcheck Check root access"); appendOutput(""); appendColored("ROOT COMMANDS:", "#EF4444"); appendOutput(" su Execute as root"); appendOutput(" remount Remount /system r/w"); appendOutput(" reboot Reboot device"); appendOutput(" reboot recovery"); appendOutput(" reboot bootloader"); appendOutput(" dmesg Kernel messages"); appendOutput(" getprop Get system property"); appendOutput(" setprop Set system property"); appendOutput(""); if (hasPro) { appendColored("TERMINAL PRO:", "#A855F7"); appendOutput(" history Command history"); appendOutput(" ll Alias for ls -la"); appendOutput(" la Alias for ls -a"); appendOutput(" l Alias for ls -l"); appendOutput(" c Alias for clear"); appendOutput(" h Alias for history"); appendOutput(" .. Alias for cd .."); appendOutput(""); } appendColored("SHELL:", "#22C55E"); appendOutput(" Any Linux command will be executed"); appendOutput(" Examples: ls, cat, grep, find, etc."); appendOutput(""); } private void showNeofetch() { ThemeManager tm = new ThemeManager(this); String clearance = tm.isFoundation() ? "Foundation" : "Corp"; String rootStatus = hasRoot ? "Enabled" : "Disabled"; String selinux = RootShell.getSelinuxStatus(); appendColored("", "#06B6D4"); appendColored(" ▄▀▀▀▀▄ " + "root@aethex", "#06B6D4"); appendColored(" █ ▄▄▄▄ █ " + "─────────────────────", "#06B6D4"); appendColored(" █ █ █ █ " + "OS: AeThex OS v2.1.0", "#FFFFFF"); appendColored(" █ ▀▀▀▀ █ " + "Host: " + android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL, "#FFFFFF"); appendColored(" ▀▄▄▄▄▀ " + "Kernel: " + RootShell.executeNonRoot("uname -r"), "#FFFFFF"); appendColored(" ▄█████▄ " + "Uptime: " + getUptimeString(), "#FFFFFF"); appendColored(" ▀███████▀ " + "Shell: AeThex Terminal", "#FFFFFF"); appendColored(" █ █ █ " + "Root: " + rootStatus, hasRoot ? "#22C55E" : "#EF4444"); appendColored(" ▀▀▀▀▀▀▀ " + "SELinux: " + selinux, "#FFFFFF"); appendColored(" " + "Android: " + android.os.Build.VERSION.RELEASE, "#FFFFFF"); appendColored(" " + "Clearance: " + clearance, tm.isFoundation() ? "#06B6D4" : "#A855F7"); appendOutput(""); } private void checkRoot() { appendColored("\n═══ Root Status Check ═══", "#06B6D4"); // Check su binary appendOutput("Checking su binary..."); boolean suExists = new File("/system/bin/su").exists() || new File("/system/xbin/su").exists() || new File("/sbin/su").exists(); if (suExists) { appendColored(" ✓ su binary found", "#22C55E"); } else { appendColored(" ✗ su binary not found", "#EF4444"); } // Check root access appendOutput("Testing root access..."); if (hasRoot) { appendColored(" ✓ Root access confirmed (uid=0)", "#22C55E"); String whoami = RootShell.execute("whoami"); appendOutput(" Running as: " + whoami); } else { appendColored(" ✗ Root access denied", "#EF4444"); } // Check busybox appendOutput("Checking busybox..."); String bbCheck = RootShell.executeNonRoot("which busybox 2>/dev/null"); if (!bbCheck.isEmpty() && !bbCheck.startsWith("Error")) { appendColored(" ✓ Busybox found: " + bbCheck, "#22C55E"); } else { appendColored(" - Busybox not installed", "#FBBF24"); } appendOutput(""); } private void showSysInfo() { appendColored("\n═══ System Information ═══", "#06B6D4"); appendOutput(""); appendOutput("Device: " + android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL); appendOutput("Product: " + android.os.Build.PRODUCT); appendOutput("Board: " + android.os.Build.BOARD); appendOutput("Hardware: " + android.os.Build.HARDWARE); appendOutput("Android: " + android.os.Build.VERSION.RELEASE + " (SDK " + android.os.Build.VERSION.SDK_INT + ")"); appendOutput("Build: " + android.os.Build.DISPLAY); appendOutput("Fingerprint: " + android.os.Build.FINGERPRINT); appendOutput("Kernel: " + RootShell.executeNonRoot("uname -r")); appendOutput("Architecture: " + android.os.Build.SUPPORTED_ABIS[0]); appendOutput("Root: " + (hasRoot ? "Yes" : "No")); appendOutput("SELinux: " + RootShell.getSelinuxStatus()); appendOutput(""); } private void showProcesses() { appendColored("\n═══ Running Processes ═══", "#06B6D4"); executeAsync("ps -A 2>/dev/null | head -25 || ps | head -20", hasRoot); } private void showNetInfo() { appendColored("\n═══ Network Interfaces ═══", "#06B6D4"); executeAsync("ip addr 2>/dev/null || ifconfig 2>/dev/null", false); } private void showCpuInfo() { appendColored("\n═══ CPU Information ═══", "#06B6D4"); executeAsync("cat /proc/cpuinfo | head -25", false); } private void showMemInfo() { appendColored("\n═══ Memory Information ═══", "#06B6D4"); executeAsync("cat /proc/meminfo | head -15", false); } private void showDiskInfo() { appendColored("\n═══ Disk Usage ═══", "#06B6D4"); executeAsync("df -h 2>/dev/null || df", false); } private void showMounts() { appendColored("\n═══ Mounted Filesystems ═══", "#06B6D4"); executeAsync("mount | head -20", false); } private void showSelinux() { appendColored("\n═══ SELinux Status ═══", "#06B6D4"); appendOutput("Status: " + RootShell.getSelinuxStatus()); if (hasRoot) { executeAsync("cat /sys/fs/selinux/enforce 2>/dev/null && echo '(1=Enforcing, 0=Permissive)'", true); } appendOutput(""); } private void remountSystem() { if (!hasRoot) { appendColored("Error: Root access required", "#EF4444"); return; } appendColored("Remounting /system as read-write...", "#FBBF24"); executeAsync("mount -o rw,remount /system 2>&1", true); } private void rebootDevice(String[] parts) { if (!hasRoot) { appendColored("Error: Root access required", "#EF4444"); return; } String mode = parts.length > 1 ? parts[1].toLowerCase() : "normal"; String cmd; switch (mode) { case "recovery": appendColored("Rebooting to recovery...", "#FBBF24"); cmd = "reboot recovery"; break; case "bootloader": case "fastboot": appendColored("Rebooting to bootloader...", "#FBBF24"); cmd = "reboot bootloader"; break; case "download": appendColored("Rebooting to download mode...", "#FBBF24"); cmd = "reboot download"; break; default: appendColored("Rebooting device...", "#FBBF24"); cmd = "reboot"; break; } executeAsync(cmd, true); } private void executeAsync(String command, boolean useRoot) { RootShell.executeAsync(command, useRoot, new RootShell.CommandCallback() { @Override public void onOutput(String output) { mainHandler.post(() -> appendOutput(output)); } @Override public void onError(String error) { mainHandler.post(() -> appendColored(error, "#EF4444")); } @Override public void onComplete(int exitCode) { mainHandler.post(() -> { if (exitCode != 0 && exitCode != -1) { appendColored("Exit code: " + exitCode, "#FBBF24"); } appendOutput(""); }); } }); } private String getUptimeString() { long uptimeMs = android.os.SystemClock.elapsedRealtime(); long hours = uptimeMs / 3600000; long mins = (uptimeMs % 3600000) / 60000; return hours + "h " + mins + "m"; } private void appendOutput(String text) { outputView.append(text + "\n"); scrollView.post(() -> scrollView.fullScroll(View.FOCUS_DOWN)); } private void appendColored(String text, String hexColor) { int start = outputView.getText().length(); outputView.append(text + "\n"); // Note: For full color support, would need SpannableString // This is simplified - the text color is set by the view scrollView.post(() -> scrollView.fullScroll(View.FOCUS_DOWN)); } @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) hideSystemUI(); } private void hideSystemUI() { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { final WindowInsetsController c = getWindow().getInsetsController(); if (c != null) { c.hide(WindowInsets.Type.systemBars()); c.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); } } else { getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN); } } }