Telegram

LINEAGE OS 23 - SAMSUNG S9 SAFE MODE BUG

Lineage OS 23 - Samsung S9 Safe Mode Bug

At Magisk Modules, we understand the frustration that arises when a custom ROM installation on a beloved device like the Samsung Galaxy S9 (starqlte/around) doesn’t go exactly as planned. Lineage OS 23, based on Android 14, offers a fantastic, bloat-free experience, but occasionally, users encounter specific system-level quirks. One of the most persistent and confusing issues reported by the community is the appearance of a “Safe Mode” indicator in the bottom-left corner of the screen, even though the device is not actually booting into Safe Mode. This bug is often accompanied by a critical failure in the application launcher, where newly installed applications from the Google Play Store or sideloaded APKs fail to appear in the app drawer, and the “Open” button is missing from the store interface.

This comprehensive guide details the root causes of this specific Lineage OS 23 anomaly on the Samsung Galaxy S9 and provides a step-by-step, advanced methodology to resolve it completely. We will explore the system mechanisms behind the bug, the interaction between the custom ROM and the device’s hardware keys, and the necessary remediation steps involving system partitions and Magisk modules.

Understanding the Lineage OS 23 Safe Mode Bug on Galaxy S9

The “Safe Mode” text appearing on the lock screen or home screen is a kernel-level debug flag. In a stock Samsung environment, this is triggered by long-pressing the “Volume Down” key during the boot sequence. However, in Lineage OS, the detection mechanism for hardware keys can sometimes conflict with the Samsung Galaxy S9’s specific hardware abstraction layer (HAL) or key layout files.

The Symptoms of the Anomaly

When this bug manifests, it presents a specific set of symptoms that disrupt the user experience:

  1. Persistent Safe Mode Indicator: A transparent overlay reading “Safe Mode” is permanently visible in the corner of the screen.
  2. Launcher Malfunction: The Trebuchet launcher (Lineage OS’s default) or any third-party launcher fails to register new app installations. The app drawer remains static.
  3. Play Store Limitations: When viewing an installed app in the Google Play Store, the “Open” button is greyed out or entirely absent.
  4. APK Installation Failure: Sideloaded APKs install successfully according to the package manager, but no launch icon is generated in the system UI.

Root Cause Analysis: Key Interception and SystemUI

The root cause is typically a mismatch in the /vendor/usr/keylayout files or a conflict within the SystemUI responsible for rendering the safe mode overlay. The Galaxy S9 utilizes a specific key layout for its physical buttons. If Lineage OS 23 does not correctly map the “Volume Down” key release event during the boot cycle, the system may flag the safe_mode property as true.

Simultaneously, the failure of apps to appear in the launcher is often linked to the Intent Broadcast System. When an app is installed, the Package Manager sends a broadcast intent (ACTION_PACKAGE_ADDED) to the launcher. If the SystemUI is hung in a perceived “Safe Mode” state, it may suppress these broadcasts to prevent “untrusted” apps from launching, a legacy security feature from Android’s earlier iterations that sometimes glitches in custom ROMs.

Prerequisites for Troubleshooting

Before attempting to resolve the Safe Mode bug, ensure you have the following ready. We assume a basic level of ADB (Android Debug Bridge) familiarity and that your device is unlocked with a custom recovery (such as TWRP) installed.

Method 1: The ADB Shell Property Reset (Non-Invasive)

The first line of defense is to manually reset the system flags governing Safe Mode. This method attempts to force the persist.sys.safemode property to 0 and clear the cache associated with the SystemUI.

Executing the Command Line Fix

Connect your Samsung Galaxy S9 to your computer via USB. Open a command prompt or terminal window and execute the following steps:

  1. Verify Connection:

    adb devices
    

    Ensure your device serial number is listed.

  2. Remount the System Partition as Read/Write:

    adb shell
    su
    mount -o rw,remount /system
    
  3. Reset Safe Mode Properties: We need to clear the global settings that might be holding the Safe Mode state.

    settings put global safe_boot_disallowed 0
    settings put global device_provisioned 1
    
  4. Clear the SystemUI Cache and Data: This forces the UI to redraw the overlay and reload the app intent filters.

    pm clear com.android.systemui
    pm clear com.google.android.setupwizard
    
  5. Force Restart the Device:

    reboot
    

If the “Safe Mode” text persists after this reboot, the issue is likely hardcoded into the /system partition or the kernel boot animation script, requiring a more aggressive approach involving TWRP and file modification.

Method 2: Manual File Modification via TWRP

If the ADB method fails, we must manually inspect and modify the system files responsible for the key layout and the boot animation overlay. This requires booting into TWRP recovery.

Correcting the Samsung Key Layout Files

The Galaxy S9 has specific key layout files that define how physical buttons behave. Lineage OS sometimes overwrites these incorrectly during the initial ROM flash.

  1. Boot into TWRP Recovery: Power off the device, then hold Volume Up + Bixby + Power.
  2. Mount System: Tap “Mount” and check “System”.
  3. Open File Manager: Navigate to /vendor/usr/keylayout/.
  4. Locate gpio-keys.kl or sec_touchkey.kl: These files handle the volume keys and capacitive buttons.
  5. Edit the File: Look for lines referencing KEYCODE_VOLUME_DOWN. Ensure the key value is correct (usually 25) and that the flags are empty.
    • Incorrect: key 25 VOLUME_DOWN WAKE_DURING_KEYGUARD
    • Correct: key 25 VOLUME_DOWN
    • Note: Removing WAKE_DURING_KEYGUARD can sometimes stop the system from detecting a stuck key.

Verifying the build.prop Flags

Navigate to /system/build.prop (or /system/system/build.prop in Android 10+ ROMs like Lineage 23). Use the TWRP text editor to ensure the following lines are either absent or set to false. If they exist, modify them:

ro.sys.safemode=0
persist.sys.safemode=0
ro.bootmode=recovery

Note: If ro.bootmode is stuck on safe, it indicates a kernel-level detection issue.

Method 3: The Magisk Module Solution

At Magisk Modules, we advocate for non-destructive modifications. Since the issue involves system-level broadcast suppression and key detection, we can create or utilize a Magisk module to patch the behavior at runtime without altering the /system partition permanently.

Creating a Runtime Fix Module

You can create a simple module to override the Safe Mode detection and force the launcher to accept new intents.

  1. Create a Directory: On your device, create a folder named S9_Lineage_SafeFix in /data/adb/modules/.

  2. Create module.prop:

    id=s9_lineage_safefix
    name=Lineage 23 S9 Safe Mode Fix
    version=1.0
    versionCode=1
    author=Magisk Modules
    description=Fixes Safe Mode overlay and app launcher intent issues on Galaxy S9 Lineage OS 23.
    
  3. Create service.sh: This script will run late_start in the boot process to reset the properties.

    #!/system/bin/sh
    # Do not run until boot is largely complete
    sleep 30
    
    # Reset Safe Mode flags
    setprop persist.sys.safemode 0
    setprop sys.safemode 0
    
    # Force reload of launcher components
    am broadcast -a android.intent.action.BOOT_COMPLETED
    

    Ensure the file is executable (chmod 755 service.sh).

  4. Universal Intent Fix (Optional but Recommended): Create a file named system.prop in the module directory to force the Package Manager to always broadcast install intents:

    persist.sys.force.rescue=0
    

Reboot the device after installing this module. This often resolves the “Open” button issue in the Play Store by ensuring the system recognizes the apps as valid launchable entities.

Method 4: The “Clean Flash” Protocol (The Ultimate Fix)

If the bug persists despite the above interventions, the corruption is likely deep within the /system or /vendor partition, possibly caused by a dirty flash or残留 (leftover) data from a previous ROM installation. The only guaranteed solution is a clean installation of Lineage OS 23.

Wiping Data Correctly

Many users wipe Data, Cache, and Dalvik but forget System or Vendor. For Lineage OS 23 on the Samsung S9, we recommend the following strict sequence in TWRP:

  1. Backup: Backup your current Data (including internal storage) to an external SD card or PC.
  2. Format Data: Do not just wipe; go to “Wipe” -> “Format Data”. Type yes to confirm. This removes encryption and clears residual metadata.
  3. Wipe System/Vendor: Go to “Wipe” -> “Advanced Wipe”. Select System, Vendor, and Cache. Swipe to wipe.
    • Note: On Android 14 (Lineage 23), the Vendor partition structure is critical. Corrupt Vendor files often cause the Safe Mode overlay bug.
  4. Flash GApps: If using Google Apps (e.g., MindTheGapps or OpenGApps), flash them immediately after the ROM zip.
  5. Flash Magisk: Always flash the Magisk zip last to ensure root is active.

Post-Installation Configuration

Upon the first boot (which may take longer than usual), do not restore app data immediately. Manually install apps from the Play Store first to verify the “Open” button functions. If the Safe Mode text appears even on a clean install, check the XDA Developers forum for your specific S9 variant (e.g., starqltecan) for kernel updates or Lineage OS hotfixes.

Advanced Diagnosis: Analyzing Logcat

For users comfortable with command-line diagnostics, viewing the system log can pinpoint the exact process triggering the Safe Mode overlay.

  1. Enable Developer Options: Tap “Build Number” 7 times in Settings.
  2. Run Logcat: Connect via ADB and run:
    adb logcat -v threadtime > lineage_s9_bug.txt
    
  3. Reproduce the Bug: Install an app from the Play Store and observe the failure to launch.
  4. Analyze the Output: Search the text file for keywords:
    • SafeMode
    • KeyLayout
    • PackageManager
    • Trebuchet

Look for lines indicating W/WindowManager: Attempted to add window with non-zero token. If the SystemUI is crashing repeatedly, it may be causing the Safe Mode overlay to stick. If you see I/ActivityManager: Force stopping package, the system is explicitly killing the newly installed app’s launch process, confirming the broadcast suppression theory.

Specifics for Samsung Galaxy S9 Hardware (Starqlte)

The Samsung Galaxy S9 series has unique hardware quirks that influence Lineage OS behavior.

The Bixby Button Interference

Lineage OS 23 attempts to remap the Bixby button. If the mapping fails or conflicts with the Volume Down key detection (due to shared GPIO lines in the kernel), the system may interpret a “stuck” signal as a Safe Mode request. We recommend disabling the Bixby key remap in Lineage OS settings (Settings -> System -> Buttons -> Bixby key) and setting it to “Do nothing” to rule out hardware conflict.

SELinux Policies

Lineage OS 23 enforces strict SELinux (Security-Enhanced Linux) policies. If a module or Magisk modification has altered the SELinux context of the /vendor partition, the SystemUI may lose permission to read the safe_mode flag correctly, defaulting to a “Safe” state. To check this, run:

adb shell getenforce

If it returns Enforcing and you suspect a policy violation, temporarily setting it to Permissive via a Magisk module (kernel-level) can help diagnose if SELinux is the culprit. Note: We do not recommend leaving SELinux in Permissive mode for security reasons.

Resolving the “No Open Button” / App Not Showing Issue

This specific symptom is directly tied to the LauncherApps service. When Safe Mode is active, the service blocks queryActivities for non-system apps.

Clearing the Launcher Database

Sometimes, the launcher’s database (Homespace.db) becomes desynchronized.

  1. Access Shell:
    adb shell
    su
    
  2. Delete Launcher Database:
    rm /data/data/com.lineageos.trebuchet/databases/homespace.db
    rm /data/data/com.lineageos.trebuchet/databases/launcher.db
    
  3. Restart the Launcher:
    am force-stop com.lineageos.trebuchet
    

This forces the Trebuchet launcher to rebuild its index of installed applications from scratch, usually picking up the missing apps that were previously suppressed by the Safe Mode bug.

Preventing Future Occurrences

To ensure this bug does not reappear after a system update or reboot:

  1. Disable Key Disabler: If you use Lineage OS’s built-in “Key Disabler” (often used to disable hardware keys), toggle it off and on. Corruption in this setting file can trigger the Safe Mode state.
  2. Keep Vendor Updated: Ensure you are flashing the correct vendor.img for your specific firmware build. Mismatched vendor bases (e.g., using a November patch vendor with a December patch ROM) are a common source of hardware detection bugs.
  3. Magisk Module Hygiene: Avoid using multiple Magisk modules that modify the SystemUI or Keyguard simultaneously. Incompatibilities here are a primary cause of persistent overlays.

Conclusion

The Lineage OS 23 Safe Mode bug on the Samsung Galaxy S9 is a complex interplay between hardware key detection, system property flags, and the application launcher’s broadcast receiver. While the “Safe Mode” text is merely a visual annoyance, the accompanying failure to launch apps severely hampers usability.

By following the advanced troubleshooting steps outlined above—ranging from ADB property resets and key layout edits to Magisk runtime patches and clean flashes—you can restore full functionality to your device. We at Magisk Modules are committed to providing the Android community with deep-dive technical solutions. If you continue to experience issues, ensure your device logs are captured and shared with the developer community for further analysis.

Explore More
Redirecting in 20 seconds...