Merge "Add a broadcast to manifest-register receivers for power save mode changes." into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6ce4cf2f90
@@ -4421,4 +4421,8 @@
|
||||
|
||||
<!-- The max scale for the wallpaper when it's zoomed in -->
|
||||
<item name="config_wallpaperMaxScale" format="float" type="dimen">1</item>
|
||||
|
||||
<!-- Package name that will receive an explicit manifest broadcast for
|
||||
android.os.action.POWER_SAVE_MODE_CHANGED. -->
|
||||
<string name="config_powerSaveModeChangedListenerPackage" translatable="false"></string>
|
||||
</resources>
|
||||
|
||||
@@ -3615,6 +3615,7 @@
|
||||
<java-symbol type="bool" name="config_batterySaverStickyBehaviourDisabled" />
|
||||
<java-symbol type="integer" name="config_dynamicPowerSavingsDefaultDisableThreshold" />
|
||||
<java-symbol type="string" name="config_batterySaverScheduleProvider" />
|
||||
<java-symbol type="string" name="config_powerSaveModeChangedListenerPackage" />
|
||||
|
||||
<!-- For car devices -->
|
||||
<java-symbol type="string" name="car_loading_profile" />
|
||||
|
||||
@@ -991,4 +991,9 @@ public abstract class PackageManagerInternal {
|
||||
* @param enabled true if visibility blocks should be logged
|
||||
*/
|
||||
public abstract void setVisibilityLogging(String packageName, boolean enabled);
|
||||
|
||||
/**
|
||||
* Returns if a package name is a valid system package.
|
||||
*/
|
||||
public abstract boolean isSystemPackage(@NonNull String packageName);
|
||||
}
|
||||
|
||||
@@ -24192,6 +24192,12 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
}
|
||||
mAppsFilter.getFeatureConfig().enableLogging(pkg.appId, enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSystemPackage(@NonNull String packageName) {
|
||||
return packageName.equals(
|
||||
PackageManagerService.this.ensureSystemPackageName(packageName));
|
||||
}
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
package com.android.server.power.batterysaver;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.ActivityManagerInternal;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManagerInternal;
|
||||
import android.hardware.power.V1_0.PowerHint;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.BatterySaverPolicyConfig;
|
||||
@@ -35,6 +37,7 @@ import android.os.UserHandle;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Slog;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
@@ -49,6 +52,7 @@ import com.android.server.power.batterysaver.BatterySavingStats.InteractiveState
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Responsible for battery saver mode transition logic.
|
||||
@@ -112,6 +116,14 @@ public class BatterySaverController implements BatterySaverPolicyListener {
|
||||
*/
|
||||
private final Plugin[] mPlugins;
|
||||
|
||||
/**
|
||||
* Package name that will receive an explicit manifest broadcast for
|
||||
* {@link PowerManager#ACTION_POWER_SAVE_MODE_CHANGED}. It's {@code null} if it hasn't been
|
||||
* retrieved yet.
|
||||
*/
|
||||
@Nullable
|
||||
private Optional<String> mPowerSaveModeChangedListenerPackage;
|
||||
|
||||
public static final int REASON_PERCENTAGE_AUTOMATIC_ON = 0;
|
||||
public static final int REASON_PERCENTAGE_AUTOMATIC_OFF = 1;
|
||||
public static final int REASON_MANUAL_ON = 2;
|
||||
@@ -494,6 +506,14 @@ public class BatterySaverController implements BatterySaverPolicyListener {
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
|
||||
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
|
||||
|
||||
// Send the broadcast to a manifest-registered receiver that is specified in the config.
|
||||
if (getPowerSaveModeChangedListenerPackage().isPresent()) {
|
||||
intent = new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)
|
||||
.setPackage(getPowerSaveModeChangedListenerPackage().get())
|
||||
.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
|
||||
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
|
||||
}
|
||||
|
||||
// Send internal version that requires signature permission.
|
||||
intent = new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED_INTERNAL);
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
|
||||
@@ -508,6 +528,20 @@ public class BatterySaverController implements BatterySaverPolicyListener {
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<String> getPowerSaveModeChangedListenerPackage() {
|
||||
if (mPowerSaveModeChangedListenerPackage == null) {
|
||||
String configPowerSaveModeChangedListenerPackage =
|
||||
mContext.getString(R.string.config_powerSaveModeChangedListenerPackage);
|
||||
mPowerSaveModeChangedListenerPackage =
|
||||
LocalServices
|
||||
.getService(PackageManagerInternal.class)
|
||||
.isSystemPackage(configPowerSaveModeChangedListenerPackage)
|
||||
? Optional.of(configPowerSaveModeChangedListenerPackage)
|
||||
: Optional.empty();
|
||||
}
|
||||
return mPowerSaveModeChangedListenerPackage;
|
||||
}
|
||||
|
||||
private void updateBatterySavingStats() {
|
||||
final PowerManager pm = getPowerManager();
|
||||
if (pm == null) {
|
||||
|
||||
Reference in New Issue
Block a user