Snap for 12052458 from 8d5d69d62f to 24Q4-release

Change-Id: I592160fe66e9951db31d00ec1c81c5dab89891f8
This commit is contained in:
Android Build Coastguard Worker
2024-07-04 23:22:11 +00:00
7 changed files with 52 additions and 15 deletions

View File

@@ -235,9 +235,6 @@
Can be overridden for specific product builds if the target device does not support it -->
<bool name="config_media_vibration_supported">true</bool>
<!-- Whether to show Keyboard vibration settings in the vibration and haptics screen. -->
<bool name="config_keyboard_vibration_supported">false</bool>
<!--
Whether or not the homepage should be powered by legacy suggestion (versus contextual cards)
Default to true as not all devices support contextual cards.

View File

@@ -111,9 +111,8 @@ public class KeyboardVibrationTogglePreferenceController extends TogglePreferenc
@Override
public int getAvailabilityStatus() {
if (Flags.keyboardCategoryEnabled()
&& mContext.getResources().getBoolean(R.bool.config_keyboard_vibration_supported)
&& mContext.getResources().getFloat(
com.android.internal.R.dimen.config_keyboardHapticFeedbackFixedAmplitude) > 0) {
&& mContext.getResources().getBoolean(
com.android.internal.R.bool.config_keyboardVibrationSettingsSupported)) {
return AVAILABLE;
}
return UNSUPPORTED_ON_DEVICE;

View File

@@ -166,6 +166,9 @@ public interface PowerUsageFeatureProvider {
/** Whether the device is under the battery defender mode */
boolean isBatteryDefend(BatteryInfo info);
/** Whether the battery usage reattribute is eabled or not. */
boolean isBatteryUsageReattributeEnabled();
/** Collect and process battery reattribute data if needed. */
boolean processBatteryReattributeData(
@NonNull Context context,

View File

@@ -256,6 +256,11 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
return info.isLongLife && !isExtraDefend();
}
@Override
public boolean isBatteryUsageReattributeEnabled() {
return false;
}
@Override
public boolean processBatteryReattributeData(
@NonNull Context context,

View File

@@ -38,6 +38,7 @@ import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDao;
import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDatabase;
import com.android.settings.fuelgauge.batteryusage.db.BatteryUsageSlotDao;
import com.android.settings.fuelgauge.batteryusage.db.BatteryUsageSlotEntity;
import com.android.settings.overlay.FeatureFactory;
import java.io.PrintWriter;
import java.time.Clock;
@@ -132,14 +133,23 @@ public final class LogUtils {
}
static void dumpBatteryReattributeDatabaseHist(Context context, PrintWriter writer) {
dumpBatteryReattributeDatabaseHist(
BatteryStateDatabase.getInstance(context).batteryReattributeDao(),
writer);
try {
dumpBatteryReattributeDatabaseHist(
BatteryStateDatabase.getInstance(context).batteryReattributeDao(),
writer);
} catch (Exception e) {
Log.e(TAG, "failed to run dumpBatteryReattributeDatabaseHist()", e);
}
}
@VisibleForTesting
static void dumpBatteryReattributeDatabaseHist(
BatteryReattributeDao batteryReattributeDao, PrintWriter writer) {
if (!FeatureFactory.getFeatureFactory().getPowerUsageFeatureProvider()
.isBatteryUsageReattributeEnabled()) {
writer.println("\n\tBatteryReattribute is disabled!");
return;
}
writer.println("\n\tBatteryReattribute DatabaseHistory:");
final List<BatteryReattributeEntity> entities =
batteryReattributeDao.getAllAfter(

View File

@@ -88,10 +88,9 @@ public class KeyboardVibrationTogglePreferenceControllerTest {
@Test
public void getAvailabilityStatus_featureSupported_available() {
mSetFlagsRule.enableFlags(Flags.FLAG_KEYBOARD_CATEGORY_ENABLED);
when(mResources.getBoolean(R.bool.config_keyboard_vibration_supported)).thenReturn(true);
when(mResources.getFloat(
com.android.internal.R.dimen.config_keyboardHapticFeedbackFixedAmplitude))
.thenReturn(0.8f);
when(mResources.getBoolean(
com.android.internal.R.bool.config_keyboardVibrationSettingsSupported))
.thenReturn(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@@ -99,7 +98,9 @@ public class KeyboardVibrationTogglePreferenceControllerTest {
@Test
public void getAvailabilityStatus_featureNotSupported_unavailable() {
mSetFlagsRule.enableFlags(Flags.FLAG_KEYBOARD_CATEGORY_ENABLED);
when(mResources.getBoolean(R.bool.config_keyboard_vibration_supported)).thenReturn(false);
when(mResources.getBoolean(
com.android.internal.R.bool.config_keyboardVibrationSettingsSupported))
.thenReturn(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@@ -107,7 +108,9 @@ public class KeyboardVibrationTogglePreferenceControllerTest {
@Test
public void getAvailabilityStatus_keyboardCategoryDisabled_unavailable() {
mSetFlagsRule.disableFlags(Flags.FLAG_KEYBOARD_CATEGORY_ENABLED);
when(mResources.getBoolean(R.bool.config_keyboard_vibration_supported)).thenReturn(true);
when(mResources.getBoolean(
com.android.internal.R.bool.config_keyboardVibrationSettingsSupported))
.thenReturn(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}

View File

@@ -18,15 +18,19 @@ package com.android.settings.fuelgauge.batteryusage.bugreport;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.fuelgauge.batteryusage.BatteryReattribute;
import com.android.settings.fuelgauge.batteryusage.db.BatteryReattributeDao;
import com.android.settings.fuelgauge.batteryusage.db.BatteryReattributeEntity;
import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDatabase;
import com.android.settings.testutils.BatteryTestUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.After;
import org.junit.Before;
@@ -48,6 +52,7 @@ public final class LogUtilsTest {
private Context mContext;
private BatteryStateDatabase mDatabase;
private BatteryReattributeDao mBatteryReattributeDao;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
@Before
public void setUp() {
@@ -56,6 +61,8 @@ public final class LogUtilsTest {
mTestPrintWriter = new PrintWriter(mTestStringWriter);
mDatabase = BatteryTestUtils.setUpBatteryStateDatabase(mContext);
mBatteryReattributeDao = mDatabase.batteryReattributeDao();
mPowerUsageFeatureProvider = FakeFeatureFactory.setupForTest().powerUsageFeatureProvider;
when(mPowerUsageFeatureProvider.isBatteryUsageReattributeEnabled()).thenReturn(true);
}
@After
@@ -99,4 +106,17 @@ public final class LogUtilsTest {
assertThat(result).contains(batteryReattribute1.toString());
assertThat(result).contains(batteryReattribute2.toString());
}
@Test
public void dumpBatteryReattributeDatabaseHist_featureDisable_notPrintData() {
mBatteryReattributeDao.insert(new BatteryReattributeEntity(
BatteryReattribute.getDefaultInstance()));
when(mPowerUsageFeatureProvider.isBatteryUsageReattributeEnabled()).thenReturn(false);
LogUtils.dumpBatteryReattributeDatabaseHist(mBatteryReattributeDao, mTestPrintWriter);
final String result = mTestStringWriter.toString();
assertThat(result).contains("BatteryReattribute is disabled!");
assertThat(result.contains("BatteryReattribute DatabaseHistory:")).isFalse();
}
}