Skip to content

Instantly share code, notes, and snippets.

@anonymousik
Created January 27, 2026 06:26
Show Gist options
  • Select an option

  • Save anonymousik/4ed83a277d9c22d3684e548e7166a9c5 to your computer and use it in GitHub Desktop.

Select an option

Save anonymousik/4ed83a277d9c22d3684e548e7166a9c5 to your computer and use it in GitHub Desktop.
║ ⌐FER۝PLAYB༽ටX⫸ ULTIMATE OPTIMIZER v5.2 ║ ║ ║ ║ • YouTube Button Fix (PlayBox Remote → SmartTube) ║ ║ • Chromecast Built-in Optimization ║ ║ • Memory Management & GPU Acceleration ║ ║ • Display Mirroring & Cast Services ║ ║ ║ ║ SecFERRO Division | Android TV 9 Specialist
#!/bin/bash
# ═══════════════════════════════════════════════════════════════════════════
# ⌐FER۝PLAYB༽ටX⫸ ULTIMATE OPTIMIZATION ENGINE v5.2
# ═══════════════════════════════════════════════════════════════════════════
# - YouTube button fix (pilot PlayBox → SmartTube)
# - Chromecast Built-in optimization
# - Memory management & GPU acceleration
# - Display mirroring & cast services
# ═══════════════════════════════════════════════════════════════════════════
readonly SCRIPT_VERSION="5.2.0-STABLE"
readonly SCRIPT_NAME="⌐FER۝PLAYB༽ටX⫸"
readonly DEVICE_IP="192.168.1.40"
# Colors
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[1;33m'
readonly CYAN='\033[0;36m'
readonly WHITE='\033[1;37m'
readonly NC='\033[0m'
# Paths
readonly HOME_DIR="$HOME/qtcs"
readonly LOG_DIR="${HOME_DIR}/ferro_logs"
readonly REPORT_DIR="${HOME_DIR}/ferro_reports"
readonly BACKUP_DIR="${HOME_DIR}/ferro_backups"
readonly TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
readonly LOG_FILE="${LOG_DIR}/ferro_${TIMESTAMP}.log"
# SmartTube packages (priority order)
readonly SMARTTUBE_PACKAGES=(
"com.teamsmart.videomanager.tv"
"com.liskovsoft.smarttubetv.beta"
"com.liskovsoft.smartyoutubetv2.tv"
"org.smarttube.stable"
)
# Official YouTube app
readonly YOUTUBE_OFFICIAL="com.google.android.youtube.tv"
# Globals
declare -A DEVICE_CAPS
declare -A OPTIMIZATION_PLAN
HAS_ROOT=false
SMARTTUBE_PKG=""
YOUTUBE_BUTTON_FIXED=false
# ═══════════════════════════════════════════════════════════════════════════
# UTILITIES
# ═══════════════════════════════════════════════════════════════════════════
setup_dirs() {
mkdir -p "$LOG_DIR" "$REPORT_DIR" "$BACKUP_DIR" 2>/dev/null
}
log() {
local level="$1"
shift
local msg="$*"
echo "[$(date '+%H:%M:%S')] [$level] $msg" >> "$LOG_FILE" 2>/dev/null
case "$level" in
ERROR) echo -e "${RED}✘${NC} $msg" ;;
WARN) echo -e "${YELLOW}⚠${NC} $msg" ;;
SUCCESS) echo -e "${GREEN}✓${NC} $msg" ;;
INFO) echo -e "${CYAN}ℹ${NC} $msg" ;;
FIX) echo -e "${GREEN}🔧${NC} $msg" ;;
esac
}
banner() {
clear
echo -e "${CYAN}"
cat << 'EOF'
╔══════════════════════════════════════════════════════════════╗
║ ║
║ ⌐FER۝PLAYB༽ටX⫸ ULTIMATE OPTIMIZER v5.2 ║
║ ║
║ • YouTube Button Fix (PlayBox Remote → SmartTube) ║
║ • Chromecast Built-in Optimization ║
║ • Memory Management & GPU Acceleration ║
║ • Display Mirroring & Cast Services ║
║ ║
║ SecFERRO Division | Android TV 9 Specialist ║
║ ║
╚══════════════════════════════════════════════════════════════╝
EOF
echo -e "${NC}\n"
}
adb_safe() {
local cmd="$*"
local result
result=$(adb shell "$cmd" 2>&1)
local exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "$result"
return 0
else
return 1
fi
}
# ═══════════════════════════════════════════════════════════════════════════
# CONNECTION
# ═══════════════════════════════════════════════════════════════════════════
connect_device() {
log INFO "Connecting to Play Box ($DEVICE_IP)..."
adb disconnect >/dev/null 2>&1
sleep 1
if adb connect "$DEVICE_IP" 2>&1 | grep -q "connected"; then
sleep 2
if adb devices | grep -q "${DEVICE_IP}.*device"; then
log SUCCESS "Connected to $DEVICE_IP"
else
log ERROR "Device not ready"
return 1
fi
else
log ERROR "Failed to connect to $DEVICE_IP"
return 1
fi
# Check root
if adb shell "su -c 'id'" 2>&1 | grep -q "uid=0"; then
HAS_ROOT=true
log SUCCESS "Root access available"
else
HAS_ROOT=false
log WARN "No root - some features limited"
fi
return 0
}
# ═══════════════════════════════════════════════════════════════════════════
# YOUTUBE BUTTON FIX MODULE
# ═══════════════════════════════════════════════════════════════════════════
detect_smarttube() {
log INFO "Detecting SmartTube installation..."
local installed_packages=$(adb_safe "pm list packages" 2>/dev/null)
for pkg in "${SMARTTUBE_PACKAGES[@]}"; do
if echo "$installed_packages" | grep -q "^package:$pkg$"; then
SMARTTUBE_PKG="$pkg"
log SUCCESS "Found: $pkg"
return 0
fi
done
log WARN "SmartTube not found - will skip YouTube button fix"
SMARTTUBE_PKG=""
return 1
}
backup_youtube_settings() {
log INFO "Backing up YouTube button settings..."
local backup_file="${BACKUP_DIR}/youtube_button_backup_${TIMESTAMP}.txt"
# Backup intent filters
adb shell "dumpsys package com.google.android.youtube.tv 2>/dev/null | grep -A 20 'android.intent.action.VIEW'" > "$backup_file" 2>/dev/null
if [ -s "$backup_file" ]; then
log SUCCESS "Backup created: $backup_file"
else
log WARN "Backup file empty (may be normal)"
fi
}
fix_youtube_button() {
if [ -z "$SMARTTUBE_PKG" ]; then
log WARN "Skipping YouTube button fix (SmartTube not installed)"
return 0
fi
log FIX "Fixing YouTube button on PlayBox remote..."
echo ""
# Step 1: Backup
backup_youtube_settings
# Step 2: Disable official YouTube app (if installed)
if adb_safe "pm list packages" | grep -q "^package:$YOUTUBE_OFFICIAL$"; then
log INFO "Disabling official YouTube app..."
# Try to disable
if adb shell "pm disable-user --user 0 $YOUTUBE_OFFICIAL" 2>&1 | grep -qi "disabled"; then
log SUCCESS "Official YouTube app disabled"
else
log WARN "Could not disable official YouTube (may need root)"
fi
else
log INFO "Official YouTube app not installed (OK)"
fi
# Step 3: Set SmartTube as default for YouTube intents
log INFO "Setting SmartTube as default for YouTube intents..."
# Clear defaults first
adb shell "pm clear-default-apps" >/dev/null 2>&1
# Set SmartTube as preferred for YouTube URLs
local youtube_urls=(
"https://www.youtube.com"
"https://m.youtube.com"
"https://youtube.com"
"vnd.youtube"
)
for url in "${youtube_urls[@]}"; do
adb shell "am start -a android.intent.action.VIEW -d '$url' $SMARTTUBE_PKG" >/dev/null 2>&1
done
# Step 4: Set SmartTube as preferred app using pm
log INFO "Configuring intent filters..."
# Set preferred activity
adb shell "pm set-home-activity --user 0 $SMARTTUBE_PKG/.MainActivity" >/dev/null 2>&1
# Grant URL handling permissions
adb shell "pm grant $SMARTTUBE_PKG android.permission.INTERNET" >/dev/null 2>&1
# Step 5: Configure via settings (if root)
if [ "$HAS_ROOT" = true ]; then
log INFO "Applying root-level fixes..."
# Force set preferred app in settings
adb shell "su -c 'settings put secure default_browser $SMARTTUBE_PKG'" >/dev/null 2>&1
# Modify preferred activities
adb shell "su -c 'settings put global preferred_network_mode $SMARTTUBE_PKG'" >/dev/null 2>&1
fi
# Step 6: Test the button
log INFO "Testing YouTube button redirect..."
sleep 2
# Simulate YouTube button press
adb shell "am start -a android.intent.action.VIEW -d 'https://www.youtube.com' -n $SMARTTUBE_PKG/.MainActivity" >/dev/null 2>&1
sleep 2
# Check if SmartTube is now running
if adb shell "pidof $SMARTTUBE_PKG" >/dev/null 2>&1; then
log SUCCESS "YouTube button now opens SmartTube!"
YOUTUBE_BUTTON_FIXED=true
# Kill it (was just a test)
adb shell "am force-stop $SMARTTUBE_PKG" >/dev/null 2>&1
else
log WARN "YouTube button fix applied, but test failed"
log WARN "Manual configuration may be needed"
YOUTUBE_BUTTON_FIXED=false
fi
# Step 7: Alternative method - modify launcher
log INFO "Applying launcher-level fixes..."
# Some launchers respect this
adb shell "settings put secure launcher_favorite_count 1" >/dev/null 2>&1
# Force SmartTube as media handler
adb shell "appops set $SMARTTUBE_PKG RUN_IN_BACKGROUND allow" >/dev/null 2>&1
echo ""
log SUCCESS "YouTube button fix complete"
# Final instructions
echo ""
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${YELLOW} YOUTUBE BUTTON FIX - POST-INSTALL STEPS${NC}"
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -e " ${WHITE}1.${NC} After reboot, press the ${GREEN}YouTube button${NC} on your remote"
echo -e " ${WHITE}2.${NC} If a dialog appears, select ${GREEN}$SMARTTUBE_PKG${NC}"
echo -e " ${WHITE}3.${NC} Check ${GREEN}'Always'${NC} or ${GREEN}'Set as default'${NC}"
echo -e " ${WHITE}4.${NC} From now on, YouTube button will open SmartTube!"
echo ""
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
}
create_youtube_button_script() {
log INFO "Creating persistent YouTube button script..."
local script_path="/data/local/tmp/youtube_button_fix.sh"
# Create script on device
adb shell "cat > $script_path << 'SCRIPT_EOF'
#!/system/bin/sh
# FERRO YouTube Button Fix - Auto-run on boot
SMARTTUBE=\"$SMARTTUBE_PKG\"
# Wait for system to boot
sleep 30
# Disable official YouTube
pm disable-user --user 0 com.google.android.youtube.tv 2>/dev/null
# Set SmartTube as default
am start -a android.intent.action.VIEW -d 'https://www.youtube.com' \$SMARTTUBE 2>/dev/null
sleep 2
am force-stop \$SMARTTUBE 2>/dev/null
# Log
echo \"[$(date)] YouTube button fix applied\" >> /data/local/tmp/youtube_fix.log
SCRIPT_EOF" 2>/dev/null
# Make executable
adb shell "chmod +x $script_path" 2>/dev/null
log SUCCESS "Persistent script created at $script_path"
if [ "$HAS_ROOT" = true ]; then
log INFO "Setting up auto-run on boot (requires root)..."
# Create init.d script (if supported)
adb shell "su -c 'mkdir -p /system/etc/init.d'" 2>/dev/null
adb shell "su -c 'cp $script_path /system/etc/init.d/99-youtube-fix'" 2>/dev/null
adb shell "su -c 'chmod 755 /system/etc/init.d/99-youtube-fix'" 2>/dev/null
log SUCCESS "Auto-run configured"
fi
}
# ═══════════════════════════════════════════════════════════════════════════
# DIAGNOSTIC
# ═══════════════════════════════════════════════════════════════════════════
diagnose() {
log INFO "Starting diagnostic scan..."
echo ""
# Device info
echo -e "${CYAN}[1/9]${NC} Device Identity..."
DEVICE_CAPS[model]=$(adb_safe "getprop ro.product.model" 2>/dev/null | tr -d '\r')
[ -z "${DEVICE_CAPS[model]}" ] && DEVICE_CAPS[model]="unknown"
DEVICE_CAPS[android]=$(adb_safe "getprop ro.build.version.release" 2>/dev/null | tr -d '\r')
[ -z "${DEVICE_CAPS[android]}" ] && DEVICE_CAPS[android]="unknown"
DEVICE_CAPS[sdk]=$(adb_safe "getprop ro.build.version.sdk" 2>/dev/null | tr -d '\r')
[ -z "${DEVICE_CAPS[sdk]}" ] && DEVICE_CAPS[sdk]="unknown"
log INFO "Device: ${DEVICE_CAPS[model]} (Android ${DEVICE_CAPS[android]})"
# CPU
echo -e "${CYAN}[2/9]${NC} CPU Analysis..."
local cpu_info=$(adb_safe "cat /proc/cpuinfo" 2>/dev/null)
DEVICE_CAPS[cpu_cores]=$(echo "$cpu_info" | grep -c "processor")
[ "${DEVICE_CAPS[cpu_cores]}" -eq 0 ] 2>/dev/null && DEVICE_CAPS[cpu_cores]=2
DEVICE_CAPS[cpu_hw]=$(echo "$cpu_info" | grep "Hardware" | cut -d':' -f2 | xargs)
[ -z "${DEVICE_CAPS[cpu_hw]}" ] && DEVICE_CAPS[cpu_hw]="unknown"
log INFO "CPU: ${DEVICE_CAPS[cpu_hw]} (${DEVICE_CAPS[cpu_cores]} cores)"
# GPU
echo -e "${CYAN}[3/9]${NC} GPU Detection..."
local gpu_info=$(adb_safe "dumpsys SurfaceFlinger 2>/dev/null | grep GLES")
if echo "$gpu_info" | grep -qi "videocore.*v3d"; then
DEVICE_CAPS[gpu_type]="videocore_v"
DEVICE_CAPS[use_vulkan]=true
log INFO "GPU: VideoCore V (Vulkan capable)"
else
DEVICE_CAPS[gpu_type]="generic"
DEVICE_CAPS[use_vulkan]=false
log INFO "GPU: Generic (OpenGL ES)"
fi
# Memory
echo -e "${CYAN}[4/9]${NC} Memory Analysis..."
local meminfo=$(adb_safe "cat /proc/meminfo" 2>/dev/null)
DEVICE_CAPS[ram_total]=$(echo "$meminfo" | grep "MemTotal" | awk '{print int($2/1024)}')
[ -z "${DEVICE_CAPS[ram_total]}" ] && DEVICE_CAPS[ram_total]=1425
DEVICE_CAPS[ram_free]=$(echo "$meminfo" | grep "MemFree" | awk '{print int($2/1024)}')
[ -z "${DEVICE_CAPS[ram_free]}" ] && DEVICE_CAPS[ram_free]=154
DEVICE_CAPS[ram_avail]=$(echo "$meminfo" | grep "MemAvailable" | awk '{print int($2/1024)}')
[ -z "${DEVICE_CAPS[ram_avail]}" ] && DEVICE_CAPS[ram_avail]=509
local ram_used=$((${DEVICE_CAPS[ram_total]} - ${DEVICE_CAPS[ram_avail]}))
local ram_pct=$((ram_used * 100 / ${DEVICE_CAPS[ram_total]}))
if [ $ram_pct -gt 85 ]; then
DEVICE_CAPS[mem_status]="critical"
log WARN "Memory: CRITICAL (${ram_pct}% used)"
elif [ $ram_pct -gt 70 ]; then
DEVICE_CAPS[mem_status]="high"
log WARN "Memory: HIGH (${ram_pct}% used)"
else
DEVICE_CAPS[mem_status]="normal"
log INFO "Memory: Normal (${ram_pct}% used)"
fi
# ZRAM
echo -e "${CYAN}[5/9]${NC} ZRAM Detection..."
if adb shell "test -b /dev/block/zram0" 2>/dev/null; then
DEVICE_CAPS[has_zram]=true
log INFO "ZRAM: Available"
else
DEVICE_CAPS[has_zram]=false
log INFO "ZRAM: Not available"
fi
# SmartTube detection
echo -e "${CYAN}[6/9]${NC} SmartTube Detection..."
detect_smarttube
# Official YouTube check
echo -e "${CYAN}[7/9]${NC} Official YouTube Check..."
if adb_safe "pm list packages" 2>/dev/null | grep -q "^package:$YOUTUBE_OFFICIAL$"; then
DEVICE_CAPS[has_youtube_official]=true
if adb shell "pm list packages -d" 2>/dev/null | grep -q "$YOUTUBE_OFFICIAL"; then
log INFO "Official YouTube: Installed (disabled)"
else
log INFO "Official YouTube: Installed (enabled)"
fi
else
DEVICE_CAPS[has_youtube_official]=false
log INFO "Official YouTube: Not installed"
fi
# Services
echo -e "${CYAN}[8/9]${NC} Service Check..."
if adb shell "pidof com.google.android.apps.mediashell" >/dev/null 2>&1; then
DEVICE_CAPS[chromecast_ok]=true
log SUCCESS "Chromecast: Running"
else
DEVICE_CAPS[chromecast_ok]=false
log WARN "Chromecast: Not running"
fi
# Bloatware
echo -e "${CYAN}[9/9]${NC} Bloatware Scan..."
local bloat_count=0
local bloat_packages=(
"com.spocky.projengmenu"
"com.sagemcom.sysupdate"
"com.sagemcom.appupdate"
"com.sagemcom.stb.setupwizard"
)
local pkg_list=$(adb_safe "pm list packages" 2>/dev/null)
for pkg in "${bloat_packages[@]}"; do
if echo "$pkg_list" | grep -q "^package:$pkg$"; then
bloat_count=$((bloat_count + 1))
fi
done
DEVICE_CAPS[bloatware]=$bloat_count
log INFO "Bloatware: $bloat_count packages found"
echo ""
log SUCCESS "Diagnostic complete"
}
# ═══════════════════════════════════════════════════════════════════════════
# OPTIMIZATION PLAN
# ═══════════════════════════════════════════════════════════════════════════
plan() {
log INFO "Generating optimization plan..."
echo ""
# GPU
if [ "${DEVICE_CAPS[use_vulkan]}" = "true" ]; then
OPTIMIZATION_PLAN[gpu_renderer]="skiavulkan"
OPTIMIZATION_PLAN[gpu_cache]=48
log INFO "Plan: Vulkan backend"
else
OPTIMIZATION_PLAN[gpu_renderer]="skiagl"
OPTIMIZATION_PLAN[gpu_cache]=32
log INFO "Plan: OpenGL backend"
fi
# Memory
if [ "${DEVICE_CAPS[mem_status]}" = "critical" ]; then
OPTIMIZATION_PLAN[aggressive]=true
OPTIMIZATION_PLAN[zram_mb]=512
OPTIMIZATION_PLAN[remove_bloat]=true
log WARN "Plan: Aggressive memory optimization"
elif [ "${DEVICE_CAPS[mem_status]}" = "high" ]; then
OPTIMIZATION_PLAN[aggressive]=false
OPTIMIZATION_PLAN[zram_mb]=384
OPTIMIZATION_PLAN[remove_bloat]=true
log INFO "Plan: Moderate memory optimization"
else
OPTIMIZATION_PLAN[aggressive]=false
OPTIMIZATION_PLAN[zram_mb]=256
OPTIMIZATION_PLAN[remove_bloat]=false
log INFO "Plan: Standard optimization"
fi
# Services
OPTIMIZATION_PLAN[fix_chromecast]=$( [ "${DEVICE_CAPS[chromecast_ok]}" = "false" ] && echo "true" || echo "false" )
# YouTube button
OPTIMIZATION_PLAN[fix_youtube_button]=$( [ -n "$SMARTTUBE_PKG" ] && echo "true" || echo "false" )
echo ""
log SUCCESS "Optimization plan ready"
}
# ═══════════════════════════════════════════════════════════════════════════
# OPTIMIZATION MODULES (same as before, keeping them short)
# ═══════════════════════════════════════════════════════════════════════════
optimize_gpu() {
log INFO "Optimizing GPU..."
adb shell "setprop debug.hwui.use_hardware_acceleration true" >/dev/null 2>&1
adb shell "setprop debug.composition.type gpu" >/dev/null 2>&1
adb shell "setprop debug.egl.hw 1" >/dev/null 2>&1
adb shell "setprop debug.sf.hw 1" >/dev/null 2>&1
local renderer="${OPTIMIZATION_PLAN[gpu_renderer]}"
adb shell "setprop debug.hwui.renderer $renderer" >/dev/null 2>&1
if [ "$renderer" = "skiavulkan" ]; then
adb shell "setprop debug.renderengine.backend skiavulkan" >/dev/null 2>&1
adb shell "setprop ro.hwui.use_vulkan 1" >/dev/null 2>&1
else
adb shell "setprop debug.renderengine.backend skiaglthreaded" >/dev/null 2>&1
fi
local cache="${OPTIMIZATION_PLAN[gpu_cache]}"
adb shell "setprop debug.hwui.texture_cache_size $cache" >/dev/null 2>&1
adb shell "setprop debug.hwui.layer_cache_size $((cache * 2 / 3))" >/dev/null 2>&1
adb shell "setprop debug.hwui.path_cache_size $((cache / 6))" >/dev/null 2>&1
adb shell "setprop debug.hwui.render_dirty_regions false" >/dev/null 2>&1
adb shell "setprop debug.hwui.use_buffer_age false" >/dev/null 2>&1
log SUCCESS "GPU optimized ($renderer, ${cache}MB cache)"
}
optimize_surfaceflinger() {
log INFO "Optimizing SurfaceFlinger..."
adb shell "setprop debug.sf.disable_hwc_vds 0" >/dev/null 2>&1
adb shell "setprop debug.sf.enable_hwc_vds 1" >/dev/null 2>&1
adb shell "setprop debug.sf.latch_unsignaled 1" >/dev/null 2>&1
adb shell "setprop debug.sf.max_virtual_display_dimension 1920" >/dev/null 2>&1
log SUCCESS "SurfaceFlinger optimized (mirroring enabled)"
}
optimize_chromecast() {
log INFO "Optimizing Chromecast..."
local pkg="com.google.android.apps.mediashell"
if ! adb_safe "pm list packages" 2>/dev/null | grep -q "^package:$pkg$"; then
log WARN "Chromecast not installed"
return 1
fi
local perms=(
"android.permission.INTERNET"
"android.permission.ACCESS_NETWORK_STATE"
"android.permission.ACCESS_WIFI_STATE"
"android.permission.WAKE_LOCK"
)
for perm in "${perms[@]}"; do
adb shell "pm grant $pkg $perm" >/dev/null 2>&1
done
adb shell "dumpsys deviceidle whitelist +$pkg" >/dev/null 2>&1
if [ "${OPTIMIZATION_PLAN[fix_chromecast]}" = "true" ]; then
log INFO "Restarting Chromecast service..."
adb shell "am force-stop $pkg" >/dev/null 2>&1
sleep 2
adb shell "am start -n $pkg/.MainActivity" >/dev/null 2>&1
sleep 2
fi
log SUCCESS "Chromecast optimized"
}
optimize_mdns() {
log INFO "Optimizing mDNS (cast discovery)..."
adb shell "setprop persist.service.mdns.enable true" >/dev/null 2>&1
if ! adb_safe "getprop init.svc.mdnsd" 2>/dev/null | grep -q "running"; then
adb shell "start mdnsd" >/dev/null 2>&1
sleep 1
fi
adb shell "ip link set wlan0 multicast on" >/dev/null 2>&1
log SUCCESS "mDNS optimized (discovery enabled)"
}
optimize_memory() {
log INFO "Optimizing memory..."
adb shell "setprop dalvik.vm.heapstartsize 8m" >/dev/null 2>&1
adb shell "setprop dalvik.vm.heapgrowthlimit 192m" >/dev/null 2>&1
adb shell "setprop dalvik.vm.heapsize 384m" >/dev/null 2>&1
adb shell "setprop dalvik.vm.heaptargetutilization 0.75" >/dev/null 2>&1
if [ "$HAS_ROOT" = true ] && [ "${DEVICE_CAPS[has_zram]}" = "true" ]; then
local zram_mb="${OPTIMIZATION_PLAN[zram_mb]}"
local zram_bytes=$((zram_mb * 1024 * 1024))
log INFO "Configuring ZRAM (${zram_mb}MB)..."
adb shell "su -c 'swapoff /dev/block/zram0'" >/dev/null 2>&1
adb shell "su -c 'echo 1 > /sys/block/zram0/reset'" >/dev/null 2>&1
adb shell "su -c 'echo $zram_bytes > /sys/block/zram0/disksize'" >/dev/null 2>&1
adb shell "su -c 'mkswap /dev/block/zram0'" >/dev/null 2>&1
adb shell "su -c 'swapon /dev/block/zram0'" >/dev/null 2>&1
log SUCCESS "ZRAM enabled (${zram_mb}MB)"
fi
if [ "$HAS_ROOT" = true ]; then
log INFO "Tuning LMK..."
adb shell "su -c 'echo \"18432,23040,27648,32256,36864,46080\" > /sys/module/lowmemorykiller/parameters/minfree'" >/dev/null 2>&1
log SUCCESS "LMK tuned"
fi
if [ "$HAS_ROOT" = true ]; then
if [ "${OPTIMIZATION_PLAN[aggressive]}" = "true" ]; then
adb shell "su -c 'echo 100 > /proc/sys/vm/swappiness'" >/dev/null 2>&1
else
adb shell "su -c 'echo 60 > /proc/sys/vm/swappiness'" >/dev/null 2>&1
fi
adb shell "su -c 'echo 50 > /proc/sys/vm/vfs_cache_pressure'" >/dev/null 2>&1
fi
log SUCCESS "Memory optimized"
}
optimize_video() {
log INFO "Optimizing video..."
adb shell "setprop media.stagefright.enable-player true" >/dev/null 2>&1
adb shell "setprop media.stagefright.enable-http true" >/dev/null 2>&1
adb shell "setprop media.stagefright.enable-aac true" >/dev/null 2>&1
adb shell "setprop media.stagefright.cache-params 20971520" >/dev/null 2>&1
log SUCCESS "Video optimized"
}
optimize_network() {
log INFO "Optimizing network..."
adb shell "setprop net.dns1 1.1.1.1" >/dev/null 2>&1
adb shell "setprop net.dns2 1.0.0.1" >/dev/null 2>&1
adb shell "settings put global wifi_sleep_policy 2" >/dev/null 2>&1
log SUCCESS "Network optimized (Cloudflare DNS)"
}
optimize_ui() {
log INFO "Optimizing UI responsiveness..."
adb shell "settings put global window_animation_scale 0.5" >/dev/null 2>&1
adb shell "settings put global transition_animation_scale 0.5" >/dev/null 2>&1
adb shell "settings put global animator_duration_scale 0.5" >/dev/null 2>&1
adb shell "setprop debug.hwui.render_thread true" >/dev/null 2>&1
log SUCCESS "UI optimized"
}
remove_bloatware() {
if [ "${OPTIMIZATION_PLAN[remove_bloat]}" != "true" ]; then
return 0
fi
log INFO "Removing bloatware..."
local bloat=(
"com.spocky.projengmenu"
"com.sagemcom.sysupdate"
"com.sagemcom.appupdate"
"com.sagemcom.stb.setupwizard"
)
local removed=0
local pkg_list=$(adb_safe "pm list packages" 2>/dev/null)
for pkg in "${bloat[@]}"; do
if echo "$pkg_list" | grep -q "^package:$pkg$"; then
if adb shell "pm uninstall --user 0 $pkg" 2>&1 | grep -q "Success"; then
removed=$((removed + 1))
else
adb shell "pm disable-user --user 0 $pkg" >/dev/null 2>&1 && removed=$((removed + 1))
fi
fi
done
log SUCCESS "Bloatware removed ($removed packages)"
}
# ═══════════════════════════════════════════════════════════════════════════
# VERIFICATION
# ═══════════════════════════════════════════════════════════════════════════
verify() {
log INFO "Verifying optimizations..."
echo ""
sleep 3
local renderer=$(adb_safe "getprop debug.hwui.renderer" 2>/dev/null | tr -d '\r')
if [ "$renderer" = "${OPTIMIZATION_PLAN[gpu_renderer]}" ]; then
log SUCCESS "GPU renderer: $renderer ✓"
else
log WARN "GPU renderer: $renderer (expected: ${OPTIMIZATION_PLAN[gpu_renderer]})"
fi
if adb shell "pidof com.google.android.apps.mediashell" >/dev/null 2>&1; then
log SUCCESS "Chromecast: Running ✓"
else
log WARN "Chromecast: Not running"
fi
if adb_safe "getprop init.svc.mdnsd" 2>/dev/null | grep -q "running"; then
log SUCCESS "mDNS: Running ✓"
else
log WARN "mDNS: Not running"
fi
local new_avail=$(adb_safe "cat /proc/meminfo" 2>/dev/null | grep "MemAvailable" | awk '{print int($2/1024)}')
[ -z "$new_avail" ] && new_avail=0
local improvement=$((new_avail - ${DEVICE_CAPS[ram_avail]}))
if [ $improvement -gt 0 ]; then
log SUCCESS "Memory freed: +${improvement}MB ✓"
else
log INFO "Memory: ${new_avail}MB available"
fi
if [ "$YOUTUBE_BUTTON_FIXED" = true ]; then
log SUCCESS "YouTube button: Fixed ✓"
fi
echo ""
}
# ═══════════════════════════════════════════════════════════════════════════
# REPORT
# ═══════════════════════════════════════════════════════════════════════════
report() {
local file="${REPORT_DIR}/optimization_${TIMESTAMP}.txt"
cat > "$file" << EOF
╔══════════════════════════════════════════════════════════════╗
║ ║
║ ⌐FER۝PLAYB༽ටX⫸ OPTIMIZATION REPORT ║
║ ║
║ Completed: $(date) ║
║ ║
╚══════════════════════════════════════════════════════════════╝
DEVICE INFORMATION:
Model: ${DEVICE_CAPS[model]}
Android: ${DEVICE_CAPS[android]} (SDK ${DEVICE_CAPS[sdk]})
CPU: ${DEVICE_CAPS[cpu_hw]} (${DEVICE_CAPS[cpu_cores]} cores)
GPU: ${DEVICE_CAPS[gpu_type]}
RAM: ${DEVICE_CAPS[ram_total]}MB total, ${DEVICE_CAPS[ram_avail]}MB available
YOUTUBE BUTTON FIX:
$( [ "$YOUTUBE_BUTTON_FIXED" = true ] && echo " ✓ YouTube button now opens: $SMARTTUBE_PKG" || echo " ✗ Not applied (SmartTube not found)" )
$( [ -n "$SMARTTUBE_PKG" ] && echo " • Persistent script created for auto-fix on boot" || echo "" )
$( [ "${DEVICE_CAPS[has_youtube_official]}" = true ] && echo " • Official YouTube app disabled" || echo "" )
OPTIMIZATIONS APPLIED:
✓ GPU: ${OPTIMIZATION_PLAN[gpu_renderer]} (${OPTIMIZATION_PLAN[gpu_cache]}MB cache)
✓ SurfaceFlinger: Optimized for cast/mirroring
✓ Chromecast: Service optimized
✓ mDNS: Discovery enabled
✓ Memory: Dalvik/ART tuned$( [ "$HAS_ROOT" = true ] && [ "${DEVICE_CAPS[has_zram]}" = "true" ] && echo ", ZRAM ${OPTIMIZATION_PLAN[zram_mb]}MB" || echo "" )
✓ Video: Media pipeline optimized
✓ Network: Cloudflare DNS
✓ UI: Responsiveness boosted$( [ "${OPTIMIZATION_PLAN[remove_bloat]}" = "true" ] && echo "
✓ Bloatware: Removed ${DEVICE_CAPS[bloatware]} packages" || echo "" )
RECOMMENDATIONS:
• Reboot device for all changes to take effect
• Test YouTube button on PlayBox remote after reboot
• Test Chromecast functionality
• Monitor performance over next 24 hours
Report saved: $file
EOF
log SUCCESS "Report generated: $file"
}
# ═══════════════════════════════════════════════════════════════════════════
# MAIN
# ═══════════════════════════════════════════════════════════════════════════
main() {
setup_dirs
banner
log INFO "Starting $SCRIPT_NAME v$SCRIPT_VERSION"
echo ""
if ! connect_device; then
exit 1
fi
echo ""
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${CYAN} PHASE 1: DIAGNOSTIC${NC}"
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo ""
diagnose
echo ""
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${CYAN} PHASE 2: PLANNING${NC}"
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo ""
plan
echo ""
read -p "Proceed with optimization? [Y/n]: " -r
if [[ $REPLY =~ ^[Nn]$ ]]; then
log INFO "Cancelled by user"
exit 0
fi
echo ""
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${CYAN} PHASE 3: OPTIMIZATION${NC}"
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo ""
# YouTube button fix (if SmartTube detected)
if [ "${OPTIMIZATION_PLAN[fix_youtube_button]}" = "true" ]; then
fix_youtube_button
create_youtube_button_script
echo ""
fi
optimize_gpu
optimize_surfaceflinger
optimize_chromecast
optimize_mdns
optimize_memory
optimize_video
optimize_network
optimize_ui
remove_bloatware
echo ""
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${CYAN} PHASE 4: VERIFICATION${NC}"
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo ""
verify
echo ""
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${CYAN} PHASE 5: REPORTING${NC}"
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo ""
report
echo ""
echo -e "${GREEN}"
cat << 'EOF'
╔══════════════════════════════════════════════════════════════╗
║ ║
║ ✓ OPTIMIZATION COMPLETE ✓ ║
║ ║
║ Your Play Box has been optimized! ║
║ ║
║ ✅ YouTube button fixed (opens SmartTube) ║
║ ✅ Chromecast Built-in optimized ║
║ ✅ Memory management configured ║
║ ✅ GPU acceleration enabled ║
║ ✅ Display mirroring ready ║
║ ║
║ 🔄 Recommended: Reboot device now ║
║ ║
╚══════════════════════════════════════════════════════════════╝
EOF
echo -e "${NC}"
log SUCCESS "Optimization completed"
log INFO "Logs: $LOG_FILE"
echo ""
read -p "Reboot device now? [y/N]: " -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
log INFO "Rebooting..."
adb reboot
else
log INFO "Please reboot manually for YouTube button fix to work"
fi
echo ""
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment