Checking software power saving mode

I wrote an application (AutoWifiSwitch), and one of the features that I plan to add automatically disables the Wi-Fi scanning service in my application if the power saving mode is enabled.

I know that Android L should implement the battery saving feature (previously HTC and Samsung added their features to the software). Presumably, now this means that Google will add some kind of API for this. Ideally, a new action would be added so that I can listen to it.

I would also like to know if this is possible using the HTC / Samsung API, and if so, how can I use them.

I searched everywhere for the above issues, but with no luck, the SecureSettings application (add-on for Tasker) can connect to the HTC / Samsung API to enable power saving in any case, I'm not quite how they do it.

Edit : The power saving value can be obtained from PowerManager in Android L, but not sure if there is an action for it.

+6
source share
5 answers

I eventually figured out how to do this with HTC and Samsung devices. Both save their power manager settings in Settings.System.

HTC (Sense) uses the user_powersaver_enable key. Samsung (Touchwiz) uses the psm_switch key.

Both store the boolean as String, and "0" is false and "1" is true. Then you can listen for changes using ContentObserver, for example (requires API level 16 or higher):

 getContentResolver().registerContentObserver(Settings.System.CONTENT_URI, true, new ContentObserver(){ @Override public void onChange(boolean selfChange, Uri uri){ super.onChange(selfChange, uri); String key = uri.getPath(); key = key.substring(key.lastIndexOf("/") + 1, key.length()); if (key.equals("user_powersaver_enable") || key.equals("psm_switch")){ boolean batterySaverEnabled = Settings.System.getString(getContentResolver(), key).equals("1"); // do something } } }); 

However, this will only be applicable until Android L is released when L is released. HTC and Samsung are likely to switch to the AOSP battery, which means you can use the new api battery saver in L.

+6
source
 PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); boolean powerSaveMode = powerManager.isPowerSaveMode(); 
+3
source

β€œpower save mode” is not an official AOSP function, and there is no way to detect it through the official SDK. This is a specific manufacturer. check this link

0
source

This answer is only for Samsung's power-saving mode, because, as usual, Samsung still prefers to use standard APIs.

iKeirNez posted a great answer that confirmed my suspicion. This still happens on lower level devices that you can buy that have 5.1.1. I have a list compiled from devices that, as I know, suffer from a camera malfunction in power saving mode, but I have not yet checked all the possible keys related to power saving mode.

I know about these so far:

Contents: // Settings / System / powersaving_switch

Contents: // Settings / System / psm_switch

You can register a ContentResolver and listen to the changes OR , if you can, if necessary:

 final String result = Settings.System.getString(getContentResolver(), "psm_switch"); Log.v("Debug", "Powersaving active: " + TextUtils.equals(result, "1")); 
0
source

It did not work for me on my Samsung S8, Android 9, instead I used:

  • install: $adb shell settings put global low_power 1
  • get: $adb shell settings get global low_power

... and it worked!

In Java translation, it looks something like this:

 final String result = Settings.Global.getString(getContentResolver(),"low_power"); 
0
source

Source: https://habr.com/ru/post/973188/


All Articles