Merge "Add strings in battery usage page"
This commit is contained in:
committed by
Android (Google) Code Review
commit
31d5b3de6f
@@ -4820,6 +4820,8 @@
|
|||||||
|
|
||||||
<!-- Description for battery usage time for an app, i.e. Used for 30min. Note: ^1 should be used in all translations [CHAR LIMIT=60] -->
|
<!-- Description for battery usage time for an app, i.e. Used for 30min. Note: ^1 should be used in all translations [CHAR LIMIT=60] -->
|
||||||
<string name="battery_used_for">Used for <xliff:g id="time">^1</xliff:g></string>
|
<string name="battery_used_for">Used for <xliff:g id="time">^1</xliff:g></string>
|
||||||
|
<!-- Description for battery usage background time for an app, i.e. Active for 30min. Note: ^1 should be used in all translations [CHAR LIMIT=60] -->
|
||||||
|
<string name="battery_active_for">Active for <xliff:g id="time">^1</xliff:g></string>
|
||||||
<!-- Description for battery screen usage time for an app, i.e. Screen usage 30min. Note: ^1 should be used in all translations [CHAR LIMIT=60] -->
|
<!-- Description for battery screen usage time for an app, i.e. Screen usage 30min. Note: ^1 should be used in all translations [CHAR LIMIT=60] -->
|
||||||
<string name="battery_screen_usage">Screen usage <xliff:g id="time">^1</xliff:g></string>
|
<string name="battery_screen_usage">Screen usage <xliff:g id="time">^1</xliff:g></string>
|
||||||
<!-- Description for battery usage info for an app, i.e. 60% used by facebook. [CHAR LIMIT=60] -->
|
<!-- Description for battery usage info for an app, i.e. 60% used by facebook. [CHAR LIMIT=60] -->
|
||||||
|
@@ -28,6 +28,7 @@ import android.os.UserManager;
|
|||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v14.preference.PreferenceFragment;
|
import android.support.v14.preference.PreferenceFragment;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
@@ -86,9 +87,12 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
BatteryUtils mBatteryUtils;
|
BatteryUtils mBatteryUtils;
|
||||||
|
|
||||||
private Preference mForegroundPreference;
|
@VisibleForTesting
|
||||||
private Preference mBackgroundPreference;
|
Preference mForegroundPreference;
|
||||||
private Preference mPowerUsagePreference;
|
@VisibleForTesting
|
||||||
|
Preference mBackgroundPreference;
|
||||||
|
@VisibleForTesting
|
||||||
|
Preference mPowerUsagePreference;
|
||||||
private AppButtonsPreferenceController mAppButtonsPreferenceController;
|
private AppButtonsPreferenceController mAppButtonsPreferenceController;
|
||||||
|
|
||||||
private DevicePolicyManagerWrapper mDpm;
|
private DevicePolicyManagerWrapper mDpm;
|
||||||
@@ -174,18 +178,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
initHeader();
|
initHeader();
|
||||||
|
initPreference();
|
||||||
final Bundle bundle = getArguments();
|
|
||||||
final Context context = getContext();
|
|
||||||
|
|
||||||
final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
|
|
||||||
final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
|
|
||||||
final String usagePercent = bundle.getString(EXTRA_POWER_USAGE_PERCENT);
|
|
||||||
final int powerMah = bundle.getInt(EXTRA_POWER_USAGE_AMOUNT);
|
|
||||||
mForegroundPreference.setSummary(Utils.formatElapsedTime(context, foregroundTimeMs, false));
|
|
||||||
mBackgroundPreference.setSummary(Utils.formatElapsedTime(context, backgroundTimeMs, false));
|
|
||||||
mPowerUsagePreference.setSummary(
|
|
||||||
getString(R.string.battery_detail_power_percentage, usagePercent, powerMah));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -222,6 +215,25 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
controller.done(context, true /* rebindActions */);
|
controller.done(context, true /* rebindActions */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void initPreference() {
|
||||||
|
final Bundle bundle = getArguments();
|
||||||
|
final Context context = getContext();
|
||||||
|
|
||||||
|
final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
|
||||||
|
final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
|
||||||
|
final String usagePercent = bundle.getString(EXTRA_POWER_USAGE_PERCENT);
|
||||||
|
final int powerMah = bundle.getInt(EXTRA_POWER_USAGE_AMOUNT);
|
||||||
|
mForegroundPreference.setSummary(
|
||||||
|
TextUtils.expandTemplate(getText(R.string.battery_used_for),
|
||||||
|
Utils.formatElapsedTime(context, foregroundTimeMs, false)));
|
||||||
|
mBackgroundPreference.setSummary(
|
||||||
|
TextUtils.expandTemplate(getText(R.string.battery_active_for),
|
||||||
|
Utils.formatElapsedTime(context, backgroundTimeMs, false)));
|
||||||
|
mPowerUsagePreference.setSummary(
|
||||||
|
getString(R.string.battery_detail_power_percentage, usagePercent, powerMah));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
return MetricsEvent.FUELGAUGE_POWER_USAGE_DETAIL;
|
return MetricsEvent.FUELGAUGE_POWER_USAGE_DETAIL;
|
||||||
|
@@ -37,6 +37,7 @@ import android.graphics.drawable.Drawable;
|
|||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
||||||
import com.android.internal.os.BatterySipper;
|
import com.android.internal.os.BatterySipper;
|
||||||
@@ -45,6 +46,7 @@ import com.android.settings.SettingsActivity;
|
|||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.applications.LayoutPreference;
|
import com.android.settings.applications.LayoutPreference;
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||||
import com.android.settings.widget.EntityHeaderController;
|
import com.android.settings.widget.EntityHeaderController;
|
||||||
@@ -73,9 +75,10 @@ public class AdvancedPowerUsageDetailTest {
|
|||||||
private static final String APP_LABEL = "app label";
|
private static final String APP_LABEL = "app label";
|
||||||
private static final String SUMMARY = "summary";
|
private static final String SUMMARY = "summary";
|
||||||
private static final String[] PACKAGE_NAME = {"com.android.app"};
|
private static final String[] PACKAGE_NAME = {"com.android.app"};
|
||||||
private static final String USAGE_PERCENT = "16";
|
private static final String USAGE_PERCENT = "16%";
|
||||||
private static final int ICON_ID = 123;
|
private static final int ICON_ID = 123;
|
||||||
private static final int UID = 1;
|
private static final int UID = 1;
|
||||||
|
private static final int POWER_MAH = 150;
|
||||||
private static final long BACKGROUND_TIME_US = 100 * 1000;
|
private static final long BACKGROUND_TIME_US = 100 * 1000;
|
||||||
private static final long FOREGROUND_TIME_US = 200 * 1000;
|
private static final long FOREGROUND_TIME_US = 200 * 1000;
|
||||||
private static final long BACKGROUND_TIME_MS = 100;
|
private static final long BACKGROUND_TIME_MS = 100;
|
||||||
@@ -83,8 +86,6 @@ public class AdvancedPowerUsageDetailTest {
|
|||||||
private static final long PHONE_FOREGROUND_TIME_MS = 250 * 1000;
|
private static final long PHONE_FOREGROUND_TIME_MS = 250 * 1000;
|
||||||
private static final long PHONE_BACKGROUND_TIME_MS = 0;
|
private static final long PHONE_BACKGROUND_TIME_MS = 0;
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private Context mContext;
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -107,6 +108,10 @@ public class AdvancedPowerUsageDetailTest {
|
|||||||
private BatteryStats.Uid mUid;
|
private BatteryStats.Uid mUid;
|
||||||
@Mock
|
@Mock
|
||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
|
private Context mContext;
|
||||||
|
private Preference mForegroundPreference;
|
||||||
|
private Preference mBackgroundPreference;
|
||||||
|
private Preference mPowerUsagePreference;
|
||||||
private AdvancedPowerUsageDetail mFragment;
|
private AdvancedPowerUsageDetail mFragment;
|
||||||
private FakeFeatureFactory mFeatureFactory;
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
private SettingsActivity mTestActivity;
|
private SettingsActivity mTestActivity;
|
||||||
@@ -114,6 +119,8 @@ public class AdvancedPowerUsageDetailTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
FakeFeatureFactory.setupForTest(mContext);
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||||
|
|
||||||
@@ -170,6 +177,13 @@ public class AdvancedPowerUsageDetailTest {
|
|||||||
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(
|
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(
|
||||||
nullable(Fragment.class), nullable(String.class), captor.capture(), anyInt(),
|
nullable(Fragment.class), nullable(String.class), captor.capture(), anyInt(),
|
||||||
nullable(CharSequence.class), nullable(UserHandle.class));
|
nullable(CharSequence.class), nullable(UserHandle.class));
|
||||||
|
|
||||||
|
mForegroundPreference = new Preference(mContext);
|
||||||
|
mBackgroundPreference = new Preference(mContext);
|
||||||
|
mPowerUsagePreference = new Preference(mContext);
|
||||||
|
mFragment.mForegroundPreference = mForegroundPreference;
|
||||||
|
mFragment.mBackgroundPreference = mBackgroundPreference;
|
||||||
|
mFragment.mPowerUsagePreference = mPowerUsagePreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -305,4 +319,28 @@ public class AdvancedPowerUsageDetailTest {
|
|||||||
"0%");
|
"0%");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInitPreference_hasCorrectSummary() {
|
||||||
|
Bundle bundle = new Bundle(4);
|
||||||
|
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, BACKGROUND_TIME_MS);
|
||||||
|
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, FOREGROUND_TIME_MS);
|
||||||
|
bundle.putString(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_PERCENT, USAGE_PERCENT);
|
||||||
|
bundle.putInt(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_AMOUNT, POWER_MAH);
|
||||||
|
doReturn(bundle).when(mFragment).getArguments();
|
||||||
|
|
||||||
|
doReturn(mContext.getText(R.string.battery_used_for)).when(mFragment).getText(
|
||||||
|
R.string.battery_used_for);
|
||||||
|
doReturn(mContext.getText(R.string.battery_active_for)).when(mFragment).getText(
|
||||||
|
R.string.battery_active_for);
|
||||||
|
doReturn(mContext.getString(R.string.battery_detail_power_percentage, USAGE_PERCENT,
|
||||||
|
POWER_MAH)).when(mFragment)
|
||||||
|
.getString(R.string.battery_detail_power_percentage, USAGE_PERCENT, POWER_MAH);
|
||||||
|
|
||||||
|
mFragment.initPreference();
|
||||||
|
|
||||||
|
assertThat(mForegroundPreference.getSummary().toString()).isEqualTo("Used for 0m");
|
||||||
|
assertThat(mBackgroundPreference.getSummary().toString()).isEqualTo("Active for 0m");
|
||||||
|
assertThat(mPowerUsagePreference.getSummary()).isEqualTo("16% of total app usage (150mAh)");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user