Merge "Support incompatible charger state in the battery main page" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
54de6fd80b
@@ -11,10 +11,7 @@
|
||||
* 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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -29,6 +26,9 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.hardware.usb.UsbPort;
|
||||
import android.hardware.usb.UsbPortStatus;
|
||||
import android.icu.text.NumberFormat;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.PowerManager;
|
||||
@@ -43,6 +43,7 @@ import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip;
|
||||
import com.android.settings.testutils.BatteryTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
@@ -85,6 +86,13 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
private UsageProgressBarPreference mBatteryUsageProgressBarPref;
|
||||
@Mock
|
||||
private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
|
||||
@Mock
|
||||
private UsbPort mUsbPort;
|
||||
@Mock
|
||||
private UsbManager mUsbManager;
|
||||
@Mock
|
||||
private UsbPortStatus mUsbPortStatus;
|
||||
|
||||
private BatteryHeaderPreferenceController mController;
|
||||
private Context mContext;
|
||||
private ShadowPowerManager mShadowPowerManager;
|
||||
@@ -99,6 +107,7 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(UsbManager.class)).thenReturn(mUsbManager);
|
||||
ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
|
||||
|
||||
mBatteryIntent = new Intent();
|
||||
@@ -289,6 +298,16 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_incompatibleCharger_showNotChargingState() {
|
||||
BatteryTestUtils.setupIncompatibleEvent(mUsbPort, mUsbManager, mUsbPortStatus);
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(
|
||||
mContext.getString(R.string.battery_info_status_not_charging));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quickUpdateHeaderPreference_onlyUpdateBatteryLevelAndChargingState() {
|
||||
mController.quickUpdateHeaderPreference();
|
||||
|
@@ -36,6 +36,7 @@ import androidx.preference.Preference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.BatteryTestUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
@@ -136,7 +137,7 @@ public class TopLevelBatteryPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getDashboardLabel_incompatibleCharger_returnsCorrectLabel() {
|
||||
setupIncompatibleEvent();
|
||||
BatteryTestUtils.setupIncompatibleEvent(mUsbPort, mUsbManager, mUsbPortStatus);
|
||||
mController.mPreference = new Preference(mContext);
|
||||
BatteryInfo info = new BatteryInfo();
|
||||
|
||||
@@ -150,14 +151,4 @@ public class TopLevelBatteryPreferenceControllerTest {
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.battery_missing_message));
|
||||
}
|
||||
|
||||
private void setupIncompatibleEvent() {
|
||||
final List<UsbPort> usbPorts = new ArrayList<>();
|
||||
usbPorts.add(mUsbPort);
|
||||
when(mUsbManager.getPorts()).thenReturn(usbPorts);
|
||||
when(mUsbPort.getStatus()).thenReturn(mUsbPortStatus);
|
||||
when(mUsbPort.supportsComplianceWarnings()).thenReturn(true);
|
||||
when(mUsbPortStatus.isConnected()).thenReturn(true);
|
||||
when(mUsbPortStatus.getComplianceWarnings()).thenReturn(new int[]{1});
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,15 @@
|
||||
|
||||
package com.android.settings.testutils;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.hardware.usb.UsbPort;
|
||||
import android.hardware.usb.UsbPortStatus;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.room.Room;
|
||||
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryInformation;
|
||||
@@ -36,6 +40,9 @@ import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.robolectric.Shadows;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BatteryTestUtils {
|
||||
|
||||
public static Intent getChargingIntent() {
|
||||
@@ -163,6 +170,7 @@ public class BatteryTestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets customized battery changed intent. */
|
||||
public static Intent getCustomBatteryIntent(int plugged, int level, int scale, int status) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(BatteryManager.EXTRA_PLUGGED, plugged);
|
||||
@@ -172,4 +180,16 @@ public class BatteryTestUtils {
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
/** Configures the incompatible charger environment. */
|
||||
public static void setupIncompatibleEvent(
|
||||
UsbPort mockUsbPort, UsbManager mockUsbManager, UsbPortStatus mockUsbPortStatus) {
|
||||
final List<UsbPort> usbPorts = new ArrayList<>();
|
||||
usbPorts.add(mockUsbPort);
|
||||
when(mockUsbManager.getPorts()).thenReturn(usbPorts);
|
||||
when(mockUsbPort.getStatus()).thenReturn(mockUsbPortStatus);
|
||||
when(mockUsbPort.supportsComplianceWarnings()).thenReturn(true);
|
||||
when(mockUsbPortStatus.isConnected()).thenReturn(true);
|
||||
when(mockUsbPortStatus.getComplianceWarnings()).thenReturn(new int[]{1});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user