Add BatteryTipDialogFragment.
This DialogFragment handles all the tip related dialogs. This cl makes: 1. All the tips parcelable. 2. Add dialog for HighUsageTip. It also need adapter to populate app list in dialog. 3. Add and update tests Bug: 70570352 Test: RunSettingsRoboTests Change-Id: Ie4c986172cfc73d8746abc7457d966c8600c6145
This commit is contained in:
@@ -4,13 +4,16 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.LinkAddress;
|
||||
@@ -25,6 +28,7 @@ import android.os.storage.VolumeInfo;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.style.TtsSpan;
|
||||
import android.util.IconDrawableFactory;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -46,8 +50,8 @@ import java.util.List;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class UtilsTest {
|
||||
|
||||
private static final String PACKAGE_NAME = "com.android.app";
|
||||
private static final int USER_ID = 1;
|
||||
|
||||
@Mock
|
||||
private WifiManager wifiManager;
|
||||
@@ -59,6 +63,12 @@ public class UtilsTest {
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private IconDrawableFactory mIconDrawableFactory;
|
||||
@Mock
|
||||
private ApplicationInfo mApplicationInfo;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
@@ -332,4 +342,17 @@ public class UtilsTest {
|
||||
|
||||
assertThat(editText.getSelectionEnd()).isEqualTo(length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBadgedIcon_usePackageNameAndUserId() throws
|
||||
PackageManager.NameNotFoundException {
|
||||
doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfo(PACKAGE_NAME,
|
||||
PackageManager.GET_META_DATA);
|
||||
|
||||
Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, PACKAGE_NAME, USER_ID);
|
||||
|
||||
// Verify that it uses the correct user id
|
||||
verify(mIconDrawableFactory).getBadgedIcon(mApplicationInfo, USER_ID);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -67,7 +67,6 @@ public class PowerUsageAnomalyDetailsTest {
|
||||
private static final String PACKAGE_NAME_1 = "com.android.app1";
|
||||
private static final String PACKAGE_NAME_2 = "com.android.app2";
|
||||
private static final String PACKAGE_NAME_3 = "com.android.app3";
|
||||
private static final int USER_ID = 1;
|
||||
|
||||
@Mock
|
||||
private SettingsActivity mSettingsActivity;
|
||||
@@ -198,16 +197,4 @@ public class PowerUsageAnomalyDetailsTest {
|
||||
assertThat(mBundle.getParcelableArrayList(
|
||||
PowerUsageAnomalyDetails.EXTRA_ANOMALY_LIST)).isEqualTo(mAnomalyList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBadgedIcon_usePackageNameAndUserId() throws
|
||||
PackageManager.NameNotFoundException {
|
||||
doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfo(PACKAGE_NAME_1,
|
||||
PackageManager.GET_META_DATA);
|
||||
|
||||
mFragment.getBadgedIcon(PACKAGE_NAME_1, USER_ID);
|
||||
|
||||
// Verify that it uses the correct user id
|
||||
verify(mIconDrawableFactory).getBadgedIcon(mApplicationInfo, USER_ID);
|
||||
}
|
||||
}
|
||||
|
@@ -85,7 +85,7 @@ public class BatteryTipPreferenceControllerTest {
|
||||
mNewBatteryTips.add(new SummaryTip(BatteryTip.StateType.INVISIBLE));
|
||||
|
||||
mBatteryTipPreferenceController = new BatteryTipPreferenceController(mContext, KEY_PREF,
|
||||
mBatteryTipListener);
|
||||
null, mBatteryTipListener);
|
||||
mBatteryTipPreferenceController.mPreferenceGroup = mPreferenceGroup;
|
||||
mBatteryTipPreferenceController.mPrefContext = mContext;
|
||||
}
|
||||
|
@@ -19,6 +19,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
@@ -58,10 +60,32 @@ public class BatteryTipTest {
|
||||
assertThat(preference.getIcon()).isEqualTo(mContext.getDrawable(ICON_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
final BatteryTip batteryTip = new TestBatteryTip();
|
||||
|
||||
Parcel parcel = Parcel.obtain();
|
||||
batteryTip.writeToParcel(parcel, batteryTip.describeContents());
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
final BatteryTip parcelTip = new TestBatteryTip(parcel);
|
||||
|
||||
assertThat(parcelTip.getTitle(mContext)).isEqualTo(TITLE);
|
||||
assertThat(parcelTip.getSummary(mContext)).isEqualTo(SUMMARY);
|
||||
assertThat(parcelTip.getIconId()).isEqualTo(ICON_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to test the non abstract methods in {@link TestBatteryTip}
|
||||
*/
|
||||
public class TestBatteryTip extends BatteryTip {
|
||||
public static class TestBatteryTip extends BatteryTip {
|
||||
TestBatteryTip() {
|
||||
super(TipType.SUMMARY, StateType.NEW, true);
|
||||
}
|
||||
|
||||
TestBatteryTip(Parcel in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(Context context) {
|
||||
@@ -88,10 +112,15 @@ public class BatteryTipTest {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog buildDialog() {
|
||||
return null;
|
||||
}
|
||||
public final Parcelable.Creator CREATOR = new Parcelable.Creator() {
|
||||
public BatteryTip createFromParcel(Parcel in) {
|
||||
return new TestBatteryTip(in);
|
||||
}
|
||||
|
||||
public BatteryTip[] newArray(int size) {
|
||||
return new TestBatteryTip[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.tips;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.text.format.DateUtils;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.fuelgauge.batterytip.HighUsageApp;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class HighUsageTipTest {
|
||||
private static final String PACKAGE_NAME = "com.android.app";
|
||||
private static final long SCREEN_TIME = 30 * DateUtils.MINUTE_IN_MILLIS;
|
||||
|
||||
private Context mContext;
|
||||
private HighUsageTip mBatteryTip;
|
||||
private List<HighUsageApp> mUsageAppList;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mUsageAppList = new ArrayList<>();
|
||||
mUsageAppList.add(new HighUsageApp(PACKAGE_NAME, SCREEN_TIME));
|
||||
mBatteryTip = new HighUsageTip(SCREEN_TIME, mUsageAppList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
|
||||
Parcel parcel = Parcel.obtain();
|
||||
mBatteryTip.writeToParcel(parcel, mBatteryTip.describeContents());
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
final HighUsageTip parcelTip = new HighUsageTip(parcel);
|
||||
|
||||
assertThat(parcelTip.getTitle(mContext)).isEqualTo("Phone used heavily");
|
||||
assertThat(parcelTip.getType()).isEqualTo(BatteryTip.TipType.HIGH_DEVICE_USAGE);
|
||||
assertThat(parcelTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
|
||||
assertThat(parcelTip.getScreenTimeMs()).isEqualTo(SCREEN_TIME);
|
||||
assertThat(parcelTip.mHighUsageAppList.size()).isEqualTo(1);
|
||||
final HighUsageApp app = parcelTip.mHighUsageAppList.get(0);
|
||||
assertThat(app.packageName).isEqualTo(PACKAGE_NAME);
|
||||
assertThat(app.screenOnTimeMs).isEqualTo(SCREEN_TIME);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user