Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 1, 2025

This PR addresses the issue where battery optimization "mercilessly reaps app on Oppo et al" by enhancing the existing battery optimization dialog with OEM-specific detection and guidance.

Problem

OEM devices like Oppo, OnePlus, Vivo, Xiaomi, and Huawei have custom battery management systems separate from Android's standard battery optimization. The standard PowerManager.isIgnoringBatteryOptimizations() API and Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS intent don't access these OEM-specific settings, leaving users unable to properly whitelist the app from aggressive battery management.

Solution

Added comprehensive OEM detection and handling:

New OemBatteryOptimizationHelper utility class

  • Detects device manufacturer using Build.MANUFACTURER
  • Maps OEM-specific intents for battery optimization settings
  • Provides manufacturer-specific user instructions
  • Supports Xiaomi/MIUI, Oppo/ColorOS, OnePlus, Vivo, Huawei/EMUI, Honor, and Realme

Enhanced battery optimization dialog

  • Shows OEM-specific instructions when applicable (e.g., "ColorOS devices require disabling battery optimization in both Android settings and ColorOS's Auto-launch management")
  • Adds "Device Settings" button for direct access to OEM battery management
  • Maintains backward compatibility with standard Android devices
  • Graceful error handling when OEM settings are unavailable

Example for Oppo users

The enhanced dialog now shows:

  • Clear instructions about ColorOS Auto-launch management requirements
  • Direct access to ColorOS settings via "Device Settings" button
  • Fallback to manual navigation if automatic opening fails

Technical Details

  • Conservative approach: Only shows dialog when standard battery optimization is active
  • Multiple fallback intents per OEM for maximum compatibility
  • Robust error handling with user-friendly messages
  • No breaking changes to existing functionality

This enhancement should significantly reduce background app termination issues on OEM devices by properly guiding users to the correct settings.

Fixes #9.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.13-all/54h0s9kvb6g2sinako7ub77ku/gradle-8.13/lib/gradle-daemon-main-8.13.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.13-all/54h0s9kvb6g2sinako7ub77ku/gradle-8.13/lib/agents/gradle-instrumentation-agent-8.13.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.13 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Battery optimization mercilessly reaps app on Oppo et al Enhance battery optimization handling for OEM devices (Oppo, Xiaomi, OnePlus, etc.) Sep 1, 2025
Copilot AI requested a review from hussainmohd-a September 1, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Battery optimization mercilessly reaps app on Oppo et al

2 participants