OEM-Specific Behavior

Many Android OEMs implement aggressive battery optimization beyond stock Android. This guide documents known behaviors and workarounds.

Warning

OEM restrictions are often undocumented and can change with firmware updates. Always test on target devices.

Aggressive OEMs

The following manufacturers are known to have aggressive background process killing:

OEM Severity Key Issues
Xiaomi / Redmi 🔴 Very High MIUI kills apps aggressively, requires special permissions
Oppo / Realme 🔴 Very High ColorOS has hidden battery optimizer
Vivo 🔴 Very High Funtouch OS blocks background starts
Samsung (OneUI) 🟠 High Sleeping apps, adaptive battery aggressive
Huawei / Honor 🔴 Very High EMUI has strictest restrictions
OnePlus 🟠 High OxygenOS inherits Oppo behavior
Google Pixel 🟢 Low Stock Android, predictable behavior

What Will Get Your App Killed

These patterns trigger aggressive app killing:

Background polling

Periodic network requests from background are detected and blocked

Long-running background services

Services without foreground notification are terminated

Frequent wakeups

Apps that wake the device frequently are penalized

Persistent sockets

Long-lived network connections are closed proactively

Xiaomi / Redmi (MIUI)

Required Settings

  1. Settings → Apps → Manage apps → [Your App] → Autostart: Enable
  2. Settings → Battery & performance → [Your App] → No restrictions
  3. Recent apps → Lock the app (prevents swipe-kill)

Programmatic Detection

fun isMIUI(): Boolean {
    return !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.name"))
}

fun showMIUISettings(context: Context) {
    try {
        val intent = Intent().apply {
            component = ComponentName(
                "com.miui.securitycenter",
                "com.miui.permcenter.autostart.AutoStartManagementActivity"
            )
        }
        context.startActivity(intent)
    } catch (e: Exception) {
        // Fallback to app settings
        openAppSettings(context)
    }
}

Samsung (OneUI)

Required Settings

  1. Settings → Battery → Background usage limits → Never sleeping apps → Add app
  2. Settings → Apps → [Your App] → Battery → Unrestricted

Programmatic Guidance

fun isSamsung(): Boolean {
    return Build.MANUFACTURER.equals("samsung", ignoreCase = true)
}

fun showSamsungBatterySettings(context: Context) {
    try {
        val intent = Intent().apply {
            component = ComponentName(
                "com.samsung.android.lool",
                "com.samsung.android.sm.ui.battery.BatteryActivity"
            )
        }
        context.startActivity(intent)
    } catch (e: Exception) {
        openAppSettings(context)
    }
}

Huawei / Honor (EMUI)

Required Settings

  1. Settings → Battery → App launch → [Your App] → Manage manually → Enable all
  2. Settings → Apps → [Your App] → Battery → Unrestricted
  3. Phone Manager → Lock screen cleanup → [Your App] → Disable

Oppo / Vivo / Realme

Required Settings

  1. Settings → Battery → [Your App] → Allow background activity
  2. Settings → Apps → [Your App] → Auto-launch → Enable
  3. Recent apps → Lock the app

OEM Detection Helper

LiteP2P provides a helper to detect and guide users:

// Check if device needs special configuration
if (LiteP2P.needsOEMConfiguration(context)) {
    val oemInfo = LiteP2P.getOEMInfo(context)

    // Show appropriate guidance
    showOEMConfigDialog(
        oemName = oemInfo.manufacturer,
        instructions = oemInfo.instructions,
        settingsIntent = oemInfo.settingsIntent
    )
}

// Or use built-in UI
LiteP2P.showOEMConfigurationGuide(activity) { completed ->
    if (completed) {
        Log.d("LiteP2P", "User completed OEM configuration")
    }
}

Testing Recommendations

Test on at least one device from each aggressive OEM
Test with app in background for 1+ hours
Test after device reboot
Test with battery saver enabled
Test push notification wake-up reliability