Merge 24Q3 (ab/AP3A.240905.001) to aosp-main-future
Bug: 347831320 Merged-In: I2489a64804f068a957f9be3f87847d6911b24447 Change-Id: I1885ef34f69ac4eb6e76ac903fcacdebe4139ae1
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.biometrics.fingerprint;
|
||||
|
||||
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_POWER_BUTTON;
|
||||
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_REAR;
|
||||
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
|
||||
|
||||
import static com.android.settings.biometrics.fingerprint.FingerprintSettings.FingerprintSettingsFragment;
|
||||
@@ -34,16 +33,13 @@ import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.hardware.biometrics.ComponentInfoInternal;
|
||||
import android.hardware.biometrics.SensorProperties;
|
||||
import android.hardware.fingerprint.Fingerprint;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.hardware.fingerprint.FingerprintSensorProperties;
|
||||
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
|
||||
@@ -84,7 +80,6 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowSettingsPreferenceFragment.class, ShadowUtils.class, ShadowFragment.class,
|
||||
@@ -152,6 +147,7 @@ public class FingerprintSettingsFragmentTest {
|
||||
public void testCancellationSignalLifeCycle() {
|
||||
setUpFragment(false);
|
||||
|
||||
mFingerprintAuthenticateSidecar.setFingerprintManager(mFingerprintManager);
|
||||
|
||||
doNothing().when(mFingerprintManager).authenticate(any(),
|
||||
mCancellationSignalArgumentCaptor.capture(),
|
||||
@@ -217,7 +213,6 @@ public class FingerprintSettingsFragmentTest {
|
||||
doReturn(fragmentManager).when(mActivity).getSupportFragmentManager();
|
||||
|
||||
mFingerprintAuthenticateSidecar = new FingerprintAuthenticateSidecar();
|
||||
mFingerprintAuthenticateSidecar.setFingerprintManager(mFingerprintManager);
|
||||
doReturn(mFingerprintAuthenticateSidecar).when(fragmentManager).findFragmentByTag(
|
||||
"authenticate_sidecar");
|
||||
|
||||
@@ -251,27 +246,4 @@ public class FingerprintSettingsFragmentTest {
|
||||
true /* resetLockoutRequiresHardwareAuthToken */));
|
||||
doReturn(props).when(mFingerprintManager).getSensorPropertiesInternal();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthOnFragmentSetup() {
|
||||
doReturn(List.of(new Fingerprint("Finger 1", 1, 2, 3)))
|
||||
.when(mFingerprintManager).getEnrolledFingerprints(anyInt());
|
||||
setUpFragment(false, 1, TYPE_REAR);
|
||||
|
||||
verify(mFingerprintManager).authenticate(any(), any(),
|
||||
any(), any(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorCancelledRestartsAuth() {
|
||||
doReturn(List.of(new Fingerprint("Finger 1", 1, 2, 3)))
|
||||
.when(mFingerprintManager).getEnrolledFingerprints(anyInt());
|
||||
setUpFragment(false, 1, TYPE_REAR);
|
||||
|
||||
// When we receive a cancel, we should restart auth.
|
||||
mFragment.handleError(FingerprintManager.FINGERPRINT_ERROR_CANCELED, "blah");
|
||||
|
||||
verify(mFingerprintManager, times(2)).authenticate(any(), any(),
|
||||
any(), any(), anyInt());
|
||||
}
|
||||
}
|
||||
|
@@ -21,26 +21,35 @@ import static android.media.Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.media.AudioDeviceAttributes;
|
||||
import android.media.AudioDeviceInfo;
|
||||
import android.media.AudioManager;
|
||||
import android.media.Spatializer;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
||||
import com.android.settingslib.bluetooth.HearingAidProfile;
|
||||
import com.android.settingslib.bluetooth.LeAudioProfile;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -54,7 +63,8 @@ import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetailsControllerTestBase {
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C";
|
||||
private static final String KEY_SPATIAL_AUDIO = "spatial_audio";
|
||||
private static final String KEY_HEAD_TRACKING = "head_tracking";
|
||||
@@ -64,6 +74,9 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
|
||||
@Mock private Lifecycle mSpatialAudioLifecycle;
|
||||
@Mock private PreferenceCategory mProfilesContainer;
|
||||
@Mock private BluetoothDevice mBluetoothDevice;
|
||||
@Mock private A2dpProfile mA2dpProfile;
|
||||
@Mock private LeAudioProfile mLeAudioProfile;
|
||||
@Mock private HearingAidProfile mHearingAidProfile;
|
||||
|
||||
private AudioDeviceAttributes mAvailableDevice;
|
||||
|
||||
@@ -83,6 +96,12 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
|
||||
when(mAudioManager.getSpatializer()).thenReturn(mSpatializer);
|
||||
when(mCachedDevice.getAddress()).thenReturn(MAC_ADDRESS);
|
||||
when(mCachedDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
when(mCachedDevice.getProfiles())
|
||||
.thenReturn(List.of(mA2dpProfile, mLeAudioProfile, mHearingAidProfile));
|
||||
when(mA2dpProfile.isEnabled(mBluetoothDevice)).thenReturn(true);
|
||||
when(mA2dpProfile.getProfileId()).thenReturn(BluetoothProfile.A2DP);
|
||||
when(mLeAudioProfile.getProfileId()).thenReturn(BluetoothProfile.LE_AUDIO);
|
||||
when(mHearingAidProfile.getProfileId()).thenReturn(BluetoothProfile.HEARING_AID);
|
||||
when(mBluetoothDevice.getAnonymizedAddress()).thenReturn(MAC_ADDRESS);
|
||||
when(mFeatureFactory.getBluetoothFeatureProvider().getSpatializer(mContext))
|
||||
.thenReturn(mSpatializer);
|
||||
@@ -272,6 +291,52 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
|
||||
false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_DETERMINING_SPATIAL_AUDIO_ATTRIBUTES_BY_PROFILE)
|
||||
public void refresh_leAudioProfileEnabledForHeadset_useLeAudioHeadsetAttributes() {
|
||||
when(mLeAudioProfile.isEnabled(mBluetoothDevice)).thenReturn(true);
|
||||
when(mA2dpProfile.isEnabled(mBluetoothDevice)).thenReturn(false);
|
||||
when(mHearingAidProfile.isEnabled(mBluetoothDevice)).thenReturn(false);
|
||||
when(mAudioManager.getBluetoothAudioDeviceCategory(MAC_ADDRESS))
|
||||
.thenReturn(AudioManager.AUDIO_DEVICE_CATEGORY_HEADPHONES);
|
||||
when(mSpatializer.isAvailableForDevice(any())).thenReturn(true);
|
||||
|
||||
mController.refresh();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mController.mAudioDevice.getType()).isEqualTo(AudioDeviceInfo.TYPE_BLE_HEADSET);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_DETERMINING_SPATIAL_AUDIO_ATTRIBUTES_BY_PROFILE)
|
||||
public void refresh_leAudioProfileEnabledForSpeaker_useLeAudioSpeakerAttributes() {
|
||||
when(mLeAudioProfile.isEnabled(mBluetoothDevice)).thenReturn(true);
|
||||
when(mA2dpProfile.isEnabled(mBluetoothDevice)).thenReturn(false);
|
||||
when(mHearingAidProfile.isEnabled(mBluetoothDevice)).thenReturn(false);
|
||||
when(mAudioManager.getBluetoothAudioDeviceCategory(MAC_ADDRESS))
|
||||
.thenReturn(AudioManager.AUDIO_DEVICE_CATEGORY_SPEAKER);
|
||||
when(mSpatializer.isAvailableForDevice(any())).thenReturn(true);
|
||||
|
||||
mController.refresh();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mController.mAudioDevice.getType()).isEqualTo(AudioDeviceInfo.TYPE_BLE_SPEAKER);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_DETERMINING_SPATIAL_AUDIO_ATTRIBUTES_BY_PROFILE)
|
||||
public void refresh_hearingAidProfileEnabled_useHearingAidAttributes() {
|
||||
when(mLeAudioProfile.isEnabled(mBluetoothDevice)).thenReturn(false);
|
||||
when(mA2dpProfile.isEnabled(mBluetoothDevice)).thenReturn(false);
|
||||
when(mHearingAidProfile.isEnabled(mBluetoothDevice)).thenReturn(true);
|
||||
when(mSpatializer.isAvailableForDevice(any())).thenReturn(true);
|
||||
|
||||
mController.refresh();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mController.mAudioDevice.getType()).isEqualTo(AudioDeviceInfo.TYPE_HEARING_AID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void turnedOnSpatialAudio_invokesAddCompatibleAudioDevice() {
|
||||
mController.setAvailableDevice(mAvailableDevice);
|
||||
|
@@ -703,4 +703,26 @@ public final class ConvertUtilsTest {
|
||||
/* taskRootPackageName= */ ""))
|
||||
.isEqualTo(packageName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeBatteryReattribute_returnExpectedResult() {
|
||||
final BatteryReattribute batteryReattribute =
|
||||
BatteryReattribute.newBuilder()
|
||||
.setTimestampStart(100L)
|
||||
.setTimestampEnd(200L)
|
||||
.putReattributeData(1001, 0.2f)
|
||||
.putReattributeData(2001, 0.8f)
|
||||
.build();
|
||||
|
||||
final BatteryReattribute decodeResult = ConvertUtils.decodeBatteryReattribute(
|
||||
ConvertUtils.encodeBatteryReattribute(batteryReattribute));
|
||||
|
||||
assertThat(decodeResult.getTimestampStart()).isEqualTo(100L);
|
||||
assertThat(decodeResult.getTimestampEnd()).isEqualTo(200L);
|
||||
final Map<Integer, Float> reattributeDataMap = decodeResult.getReattributeDataMap();
|
||||
// Verify the reattribute data in the map.
|
||||
assertThat(reattributeDataMap).hasSize(2);
|
||||
assertThat(reattributeDataMap.get(1001)).isEqualTo(0.2f);
|
||||
assertThat(reattributeDataMap.get(2001)).isEqualTo(0.8f);
|
||||
}
|
||||
}
|
||||
|
@@ -112,6 +112,7 @@ public final class DataProcessManagerTest {
|
||||
mContext,
|
||||
/* handler= */ null,
|
||||
mUserIdsSeries,
|
||||
/* isFromPeriodJob= */ false,
|
||||
/* rawStartTimestamp= */ 0L,
|
||||
/* lastFullChargeTimestamp= */ 0L,
|
||||
/* callbackFunction= */ null,
|
||||
@@ -258,6 +259,7 @@ public final class DataProcessManagerTest {
|
||||
mContext,
|
||||
/* handler= */ null,
|
||||
mUserIdsSeries,
|
||||
/* isFromPeriodJob= */ false,
|
||||
/* rawStartTimestamp= */ 2L,
|
||||
/* lastFullChargeTimestamp= */ 1L,
|
||||
/* callbackFunction= */ null,
|
||||
|
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.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;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class LogUtilsTest {
|
||||
|
||||
private StringWriter mTestStringWriter;
|
||||
private PrintWriter mTestPrintWriter;
|
||||
private Context mContext;
|
||||
private BatteryStateDatabase mDatabase;
|
||||
private BatteryReattributeDao mBatteryReattributeDao;
|
||||
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mTestStringWriter = new StringWriter();
|
||||
mTestPrintWriter = new PrintWriter(mTestStringWriter);
|
||||
mDatabase = BatteryTestUtils.setUpBatteryStateDatabase(mContext);
|
||||
mBatteryReattributeDao = mDatabase.batteryReattributeDao();
|
||||
mPowerUsageFeatureProvider = FakeFeatureFactory.setupForTest().powerUsageFeatureProvider;
|
||||
when(mPowerUsageFeatureProvider.isBatteryUsageReattributeEnabled()).thenReturn(true);
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
mBatteryReattributeDao.clearAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dumpBatteryReattributeDatabaseHist_noData_printExpectedResult() {
|
||||
LogUtils.dumpBatteryReattributeDatabaseHist(mBatteryReattributeDao, mTestPrintWriter);
|
||||
|
||||
assertThat(mTestStringWriter.toString())
|
||||
.contains("BatteryReattribute DatabaseHistory:");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dumpBatteryReattributeDatabaseHist_printExpectedResult() {
|
||||
final long currentTimeMillis = System.currentTimeMillis();
|
||||
// Insert the first testing data.
|
||||
final BatteryReattribute batteryReattribute1 =
|
||||
BatteryReattribute.newBuilder()
|
||||
.setTimestampStart(currentTimeMillis - 20000)
|
||||
.setTimestampEnd(currentTimeMillis - 10000)
|
||||
.putReattributeData(1001, 0.1f)
|
||||
.putReattributeData(1002, 0.99f)
|
||||
.build();
|
||||
mBatteryReattributeDao.insert(new BatteryReattributeEntity(batteryReattribute1));
|
||||
// Insert the second testing data.
|
||||
final BatteryReattribute batteryReattribute2 =
|
||||
BatteryReattribute.newBuilder()
|
||||
.setTimestampStart(currentTimeMillis - 40000)
|
||||
.setTimestampEnd(currentTimeMillis - 20000)
|
||||
.putReattributeData(1003, 1f)
|
||||
.build();
|
||||
mBatteryReattributeDao.insert(new BatteryReattributeEntity(batteryReattribute2));
|
||||
|
||||
LogUtils.dumpBatteryReattributeDatabaseHist(mBatteryReattributeDao, mTestPrintWriter);
|
||||
|
||||
final String result = mTestStringWriter.toString();
|
||||
assertThat(result).contains("BatteryReattribute DatabaseHistory:");
|
||||
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();
|
||||
}
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.settings.fuelgauge.batteryusage.db;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.testutils.BatteryTestUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link BatteryReattributeDao}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class BatteryReattributeDaoTest {
|
||||
|
||||
private Context mContext;
|
||||
private BatteryStateDatabase mDatabase;
|
||||
private BatteryReattributeDao mBatteryReattributeDao;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mDatabase = BatteryTestUtils.setUpBatteryStateDatabase(mContext);
|
||||
mBatteryReattributeDao = mDatabase.batteryReattributeDao();
|
||||
insert(100L, 200L, "reattributeData1");
|
||||
insert(300L, 400L, "reattributeData3");
|
||||
insert(200L, 300L, "reattributeData2");
|
||||
insert(400L, 500L, "reattributeData4");
|
||||
// Ensure there was data inserted into the database.
|
||||
assertThat(getAllEntityData()).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllAfter_returnExpectedEntityData() {
|
||||
final List<BatteryReattributeEntity> entityDataList =
|
||||
mBatteryReattributeDao.getAllAfter(/* timestampStart= */ 300L);
|
||||
|
||||
assertThat(entityDataList).hasSize(2);
|
||||
assertEntity(entityDataList.get(0), 400L, 500L, "reattributeData4");
|
||||
assertEntity(entityDataList.get(1), 300L, 400L, "reattributeData3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearAll_clearAllData() {
|
||||
mBatteryReattributeDao.clearAll();
|
||||
|
||||
assertThat(getAllEntityData()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearAllBefore_clearAllExpectedData() {
|
||||
mBatteryReattributeDao.clearAllBefore(/* timestampStart= */ 300L);
|
||||
|
||||
final List<BatteryReattributeEntity> entityDataList = getAllEntityData();
|
||||
assertThat(entityDataList).hasSize(1);
|
||||
assertEntity(entityDataList.get(0), 400L, 500L, "reattributeData4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearAllAfter_clearAllExpectedData() {
|
||||
mBatteryReattributeDao.clearAllAfter(/* timestampStart= */ 300L);
|
||||
|
||||
final List<BatteryReattributeEntity> entityDataList = getAllEntityData();
|
||||
assertThat(entityDataList).hasSize(2);
|
||||
assertEntity(entityDataList.get(0), 200L, 300L, "reattributeData2");
|
||||
assertEntity(entityDataList.get(1), 100L, 200L, "reattributeData1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insert_samePrimaryKeyEntityData_replaceIntoNewEntityData() {
|
||||
// Verify the original data before update.
|
||||
assertEntity(getAllEntityData().get(0), 400L, 500L, "reattributeData4");
|
||||
|
||||
insert(400L, 600L, "reattribute4Update");
|
||||
|
||||
// Verify the new update entity data.
|
||||
assertEntity(getAllEntityData().get(0), 400L, 600L, "reattribute4Update");
|
||||
}
|
||||
|
||||
private void insert(long timestampStart, long timestampEnd, String reattributeData) {
|
||||
mBatteryReattributeDao.insert(
|
||||
new BatteryReattributeEntity(
|
||||
timestampStart, timestampEnd, reattributeData));
|
||||
}
|
||||
|
||||
private List<BatteryReattributeEntity> getAllEntityData() {
|
||||
return mBatteryReattributeDao.getAllAfter(/* timestampStart= */ 0L);
|
||||
}
|
||||
|
||||
private static void assertEntity(BatteryReattributeEntity entity, long timestampStart,
|
||||
long timestampEnd, String reattributeData) {
|
||||
assertThat(entity.timestampStart).isEqualTo(timestampStart);
|
||||
assertThat(entity.timestampEnd).isEqualTo(timestampEnd);
|
||||
assertThat(entity.reattributeData).isEqualTo(reattributeData);
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.settings.fuelgauge.batteryusage.db;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryReattribute;
|
||||
import com.android.settings.fuelgauge.batteryusage.ConvertUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link BatteryReattributeEntity}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class BatteryReattributeEntityTest {
|
||||
|
||||
@Test
|
||||
public void constructor_createExpectedData() {
|
||||
final BatteryReattribute batteryReattribute =
|
||||
BatteryReattribute.newBuilder()
|
||||
.setTimestampStart(100L)
|
||||
.setTimestampEnd(200L)
|
||||
.putReattributeData(1001, 0.2f)
|
||||
.putReattributeData(2001, 0.8f)
|
||||
.build();
|
||||
|
||||
final BatteryReattributeEntity batteryReattributeEntity =
|
||||
new BatteryReattributeEntity(batteryReattribute);
|
||||
|
||||
assertThat(batteryReattributeEntity.timestampStart)
|
||||
.isEqualTo(batteryReattribute.getTimestampStart());
|
||||
assertThat(batteryReattributeEntity.timestampEnd)
|
||||
.isEqualTo(batteryReattribute.getTimestampEnd());
|
||||
// Verify the BatteryReattribute data.
|
||||
final BatteryReattribute decodeResult =
|
||||
ConvertUtils.decodeBatteryReattribute(batteryReattributeEntity.reattributeData);
|
||||
assertThat(decodeResult).isEqualTo(batteryReattribute);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user