Enhance battery settings limit charge tip
- Add dialog for limit charge tips - Add action button to make limit charge tips can bypass charge limited - Fix layout typo Screenshot: https://screenshot.googleplex.com/5ngtD2sJAKSQZD3.png Bug: 196315151 Bug: 197769934 Test: make SettingsRoboTests Change-Id: I0901c56ae93691c984376852da78cde9078caaf0 Merged-In: I0901c56ae93691c984376852da78cde9078caaf0
This commit is contained in:
@@ -155,4 +155,9 @@ public class PowerUsageFeatureProviderImplTest {
|
||||
|
||||
assertThat(mPowerFeatureProvider.isSmartBatterySupported()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResumeChargeIntent_returnNull() {
|
||||
assertThat(mPowerFeatureProvider.getResumeChargeIntent()).isNull();
|
||||
}
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
|
||||
@@ -74,6 +75,7 @@ public class BatteryTipDialogFragmentTest {
|
||||
private RestrictAppTip mRestrictTwoAppsTip;
|
||||
private UnrestrictAppTip mUnrestrictAppTip;
|
||||
private SummaryTip mSummaryTip;
|
||||
private BatteryDefenderTip mDefenderTip;
|
||||
private AppInfo mAppInfo;
|
||||
private ShadowPackageManager mPackageManager;
|
||||
|
||||
@@ -116,6 +118,7 @@ public class BatteryTipDialogFragmentTest {
|
||||
mUnrestrictAppTip = new UnrestrictAppTip(BatteryTip.StateType.NEW, mAppInfo);
|
||||
mSummaryTip = spy(new SummaryTip(BatteryTip.StateType.NEW,
|
||||
EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN));
|
||||
mDefenderTip = new BatteryDefenderTip(BatteryTip.StateType.NEW);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -243,4 +246,20 @@ public class BatteryTipDialogFragmentTest {
|
||||
+ "your phone will suggest actions you can take.\n\nYou can always turn"
|
||||
+ " on Battery Saver if you’re running low on battery.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCreateDialog_defenderTip_fireDialog() {
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mDefenderTip, METRICS_KEY);
|
||||
|
||||
FragmentController.setupFragment(mDialogFragment, FragmentActivity.class,
|
||||
0 /* containerViewId */, null /* bundle */);
|
||||
|
||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||
|
||||
assertThat(shadowDialog.getTitle()).isEqualTo(
|
||||
mContext.getString(R.string.battery_tip_limited_temporarily_title));
|
||||
assertThat(shadowDialog.getMessage()).isEqualTo(
|
||||
mContext.getString(R.string.battery_tip_limited_temporarily_dialog_msg, "80%"));
|
||||
}
|
||||
}
|
||||
|
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.batterytip.actions;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class BatteryDefenderActionTest {
|
||||
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private BatteryDefenderAction mBatteryDefenderAction;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
@Mock private SettingsActivity mSettingsActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mContext).when(mSettingsActivity).getApplicationContext();
|
||||
mBatteryDefenderAction = new BatteryDefenderAction(mSettingsActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePositiveAction_logMetric() {
|
||||
final int metricKey = 10;
|
||||
mBatteryDefenderAction.handlePositiveAction(metricKey);
|
||||
|
||||
verify(mMetricsFeatureProvider).action(mContext,
|
||||
SettingsEnums.ACTION_TIP_BATTERY_DEFENDER, metricKey);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user