Merge "Add enum to record power save manual enabled entry" into udc-dev

This commit is contained in:
Wesley Wang
2023-04-07 09:39:36 +00:00
committed by Android (Google) Code Review
2 changed files with 71 additions and 11 deletions

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settingslib.fuelgauge;
import android.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Utilities related to battery saver logging.
*/
public final class BatterySaverLogging {
/**
* Record the reason while enabling power save mode manually.
* See {@link SaverManualEnabledReason} for all available states.
*/
public static final String EXTRA_POWER_SAVE_MODE_MANUAL_ENABLED_REASON =
"extra_power_save_mode_manual_enabled_reason";
/** Broadcast action to record battery saver manual enabled reason. */
public static final String ACTION_SAVER_MANUAL_ENABLED_REASON =
"com.android.settingslib.fuelgauge.ACTION_SAVER_MANUAL_ENABLED_REASON";
/** An interface for the battery saver manual enable reason. */
@Retention(RetentionPolicy.SOURCE)
@IntDef({SAVER_ENABLED_UNKNOWN, SAVER_ENABLED_CONFIRMATION, SAVER_ENABLED_VOICE,
SAVER_ENABLED_SETTINGS, SAVER_ENABLED_QS, SAVER_ENABLED_LOW_WARNING,
SAVER_ENABLED_SEVERE_WARNING})
public @interface SaverManualEnabledReason {}
public static final int SAVER_ENABLED_UNKNOWN = 0;
public static final int SAVER_ENABLED_CONFIRMATION = 1;
public static final int SAVER_ENABLED_VOICE = 2;
public static final int SAVER_ENABLED_SETTINGS = 3;
public static final int SAVER_ENABLED_QS = 4;
public static final int SAVER_ENABLED_LOW_WARNING = 5;
public static final int SAVER_ENABLED_SEVERE_WARNING = 6;
}

View File

@@ -16,6 +16,10 @@
package com.android.settingslib.fuelgauge;
import static com.android.settingslib.fuelgauge.BatterySaverLogging.ACTION_SAVER_MANUAL_ENABLED_REASON;
import static com.android.settingslib.fuelgauge.BatterySaverLogging.EXTRA_POWER_SAVE_MODE_MANUAL_ENABLED_REASON;
import static com.android.settingslib.fuelgauge.BatterySaverLogging.SaverManualEnabledReason;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -145,7 +149,8 @@ public class BatterySaverUtils {
&& Global.getInt(cr, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0) == 0
&& Secure.getInt(cr,
Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0) == 0) {
showAutoBatterySaverSuggestion(context, confirmationExtras);
sendSystemUiBroadcast(context, ACTION_SHOW_AUTO_SAVER_SUGGESTION,
confirmationExtras);
}
}
@@ -175,21 +180,23 @@ public class BatterySaverUtils {
// Already shown.
return false;
}
context.sendBroadcast(
getSystemUiBroadcast(ACTION_SHOW_START_SAVER_CONFIRMATION, extras));
sendSystemUiBroadcast(context, ACTION_SHOW_START_SAVER_CONFIRMATION, extras);
return true;
}
private static void showAutoBatterySaverSuggestion(Context context, Bundle extras) {
context.sendBroadcast(getSystemUiBroadcast(ACTION_SHOW_AUTO_SAVER_SUGGESTION, extras));
private static void recordBatterySaverEnabledReason(Context context,
@SaverManualEnabledReason int reason) {
final Bundle enabledReasonExtras = new Bundle(1);
enabledReasonExtras.putInt(EXTRA_POWER_SAVE_MODE_MANUAL_ENABLED_REASON, reason);
sendSystemUiBroadcast(context, ACTION_SAVER_MANUAL_ENABLED_REASON, enabledReasonExtras);
}
private static Intent getSystemUiBroadcast(String action, Bundle extras) {
final Intent i = new Intent(action);
i.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
i.setPackage(SYSUI_PACKAGE);
i.putExtras(extras);
return i;
private static void sendSystemUiBroadcast(Context context, String action, Bundle extras) {
final Intent intent = new Intent(action);
intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
intent.setPackage(SYSUI_PACKAGE);
intent.putExtras(extras);
context.sendBroadcast(intent);
}
private static void setBatterySaverConfirmationAcknowledged(Context context) {