Merge "Shrink the progress bar on storage items." into oc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c7610f6..b38cea7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -166,7 +166,7 @@
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.network.NetworkDashboardFragment"/>
<meta-data android:name="com.android.settings.summary"
- android:value="@string/network_dashboard_summary"/>
+ android:resource="@string/network_dashboard_summary"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
@@ -193,7 +193,7 @@
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.homepage"/>
<meta-data android:name="com.android.settings.summary"
- android:value="@string/connected_devices_dashboard_summary"/>
+ android:resource="@string/connected_devices_dashboard_summary"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
@@ -877,7 +877,7 @@
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
<meta-data android:name="com.android.settings.summary"
- android:value="@string/display_dashboard_summary"/>
+ android:resource="@string/display_dashboard_summary"/>
</activity>
<!-- Keep compatibility with old shortcuts. -->
@@ -2560,7 +2560,7 @@
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
<meta-data android:name="com.android.settings.summary"
- android:value="@string/sound_dashboard_summary"/>
+ android:resource="@string/sound_dashboard_summary"/>
</activity>
<!-- Keep compatibility with old shortcuts. -->
@@ -2966,7 +2966,7 @@
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.homepage"/>
<meta-data android:name="com.android.settings.summary"
- android:value="@string/app_and_notification_dashboard_summary"/>
+ android:resource="@string/app_and_notification_dashboard_summary"/>
</activity>
<activity android:name=".Settings$UserAndAccountDashboardActivity"
@@ -2998,7 +2998,7 @@
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.system.SystemDashboardFragment"/>
<meta-data android:name="com.android.settings.summary"
- android:value="@string/system_dashboard_summary"/>
+ android:resource="@string/system_dashboard_summary"/>
</activity>
<activity android:name=".Settings$SupportDashboardActivity"
diff --git a/res/color/battery_icon_color_error.xml b/res/color/battery_icon_color_error.xml
new file mode 100644
index 0000000..3a71aae
--- /dev/null
+++ b/res/color/battery_icon_color_error.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:alpha="@*android:dimen/secondary_content_alpha_material_dark"
+ android:color="?android:attr/colorError"/>
+</selector>
\ No newline at end of file
diff --git a/res/drawable/ic_media_stream_on_24dp.xml b/res/drawable/ic_media_stream_on_24dp.xml
new file mode 100644
index 0000000..3db55dd
--- /dev/null
+++ b/res/drawable/ic_media_stream_on_24dp.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2017 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.
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M18,3h-5c-0.55,0 -1,0.45 -1,1v8.3a3.88,3.88 0,0 0,-2.9 -0.04c-1.79,0.67 -3.11,2.35 -3.1,4.26A4.483,4.483 0,0 0,10.5 21c2.5,0 4.5,-2.3 4.5,-4.5V6h3c0.55,0 1,-0.45 1,-1V4c0,-0.55 -0.45,-1 -1,-1z"/>
+</vector>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 019712d..dea40b6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3740,6 +3740,9 @@
<!-- Manage applications, individual application info screen, summary for the option which will trigger application info in it's installer [CHAR_LIMIT=50] -->
<string name="app_install_details_summary">App installed from <xliff:g id="app_store">%1$s</xliff:g></string>
+ <!-- Manage applications, individual application info screen, summary for the option which will trigger instant app info in it's installer [CHAR_LIMIT=50] -->
+ <string name="instant_app_details_summary">More info on <xliff:g id="app_store">%1$s</xliff:g></string>
+
<!-- App Ops Settings --> <skip />
<!-- [CHAR LIMIT=NONE] App ops settings title, on main settings screen. If clicked, the user is taken to a settings screen for app operations -->
<string name="app_ops_settings">App ops</string>
diff --git a/res/xml/app_memory_settings.xml b/res/xml/app_memory_settings.xml
index 53a71ff..308f189 100644
--- a/res/xml/app_memory_settings.xml
+++ b/res/xml/app_memory_settings.xml
@@ -18,26 +18,25 @@
android:title="@string/memory_usage">
<PreferenceCategory
- android:title="@string/average_memory_use"/>
+ android:title="@string/average_memory_use">
- <com.android.settings.SummaryPreference
- android:key="status_header"
- android:selectable="false" />
+ <com.android.settings.SummaryPreference
+ android:key="status_header"
+ android:selectable="false" />
- <com.android.settings.applications.SpacePreference
- android:layout_height="5dp" />
+ <Preference
+ android:key="frequency"
+ android:selectable="false"
+ android:layout="@layout/horizontal_preference"
+ android:title="@string/running_frequency" />
- <Preference
- android:key="frequency"
- android:selectable="false"
- android:layout="@layout/horizontal_preference"
- android:title="@string/running_frequency" />
+ <Preference
+ android:key="max_usage"
+ android:selectable="false"
+ android:layout="@layout/horizontal_preference"
+ android:title="@string/memory_maximum_usage" />
- <Preference
- android:key="max_usage"
- android:selectable="false"
- android:layout="@layout/horizontal_preference"
- android:title="@string/memory_maximum_usage" />
+ </PreferenceCategory>
<PreferenceCategory
android:key="processes"
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index e870539..54eb878 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -209,6 +209,11 @@
android:title="@string/bluetooth_disable_absolute_volume"
android:summary="@string/bluetooth_disable_absolute_volume_summary"/>
+ <SwitchPreference
+ android:key="bluetooth_enable_inband_ringing"
+ android:title="@string/bluetooth_enable_inband_ringing"
+ android:summary="@string/bluetooth_enable_inband_ringing_summary"/>
+
<ListPreference
android:key="bluetooth_select_avrcp_version"
android:title="@string/bluetooth_select_avrcp_version_string"
diff --git a/res/xml/installed_app_details_ia.xml b/res/xml/installed_app_details_ia.xml
index b092753..538205f 100644
--- a/res/xml/installed_app_details_ia.xml
+++ b/res/xml/installed_app_details_ia.xml
@@ -52,6 +52,11 @@
android:summary="@string/summary_placeholder"
android:selectable="true"/>
+ <com.android.settings.applications.AppDomainsPreference
+ android:key="instant_app_launch_supported_domain_urls"
+ android:title="@string/app_launch_supported_domain_urls_title"
+ android:selectable="true" />
+
<Preference
android:key="data_settings"
android:title="@string/data_usage_summary_title"
diff --git a/res/xml/power_usage_detail_ia.xml b/res/xml/power_usage_detail_ia.xml
index cfaa712..39e6c38 100644
--- a/res/xml/power_usage_detail_ia.xml
+++ b/res/xml/power_usage_detail_ia.xml
@@ -56,7 +56,7 @@
<Preference
android:key="battery_optimization"
- android:title="@string/battery_detail_background"
+ android:title="@string/high_power_apps"
android:summary="@string/high_power_off"
android:selectable="true"/>
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 015af17..34990ec 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -83,7 +83,10 @@
// Constants for state save/restore
private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
- private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
+ @VisibleForTesting
+ static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
+ @VisibleForTesting
+ static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
/**
* When starting this activity, the invoking Intent can contain this extra
@@ -192,8 +195,10 @@
private Button mNextButton;
- private boolean mDisplayHomeAsUpEnabled;
- private boolean mDisplaySearch;
+ @VisibleForTesting
+ boolean mDisplayHomeAsUpEnabled;
+ @VisibleForTesting
+ boolean mDisplaySearch;
private boolean mIsShowingDashboard;
private boolean mIsShortcut;
@@ -230,7 +235,6 @@
if (!mDisplaySearch) {
return false;
}
-
mSearchFeatureProvider.setUpSearchMenu(menu, this);
return true;
}
@@ -513,12 +517,28 @@
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
+ saveState(outState);
+ }
+ /**
+ * For testing purposes to avoid crashes from final variables in Activity's onSaveInstantState.
+ */
+ @VisibleForTesting
+ void saveState(Bundle outState) {
if (mCategories.size() > 0) {
outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
}
outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
+ outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+
+ mDisplayHomeAsUpEnabled = savedInstanceState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
+ mDisplaySearch = savedInstanceState.getBoolean(SAVE_KEY_SHOW_SEARCH);
}
@Override
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 2fcecd8..7510146 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -17,6 +17,7 @@
package com.android.settings.applications;
import android.Manifest.permission;
+import android.annotation.IdRes;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
@@ -112,6 +113,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -158,6 +160,8 @@
private static final String KEY_BATTERY = "battery";
private static final String KEY_MEMORY = "memory";
private static final String KEY_VERSION = "app_version";
+ private static final String KEY_INSTANT_APP_SUPPORTED_LINKS =
+ "instant_app_launch_supported_domain_urls";
private final HashSet<String> mHomePackages = new HashSet<>();
@@ -175,6 +179,7 @@
private Preference mDataPreference;
private Preference mMemoryPreference;
private Preference mVersionPreference;
+ private AppDomainsPreference mInstantAppDomainsPreference;
private boolean mDisableAfterUninstall;
@@ -432,7 +437,8 @@
mMemoryPreference = findPreference(KEY_MEMORY);
mMemoryPreference.setOnPreferenceClickListener(this);
mVersionPreference = findPreference(KEY_VERSION);
-
+ mInstantAppDomainsPreference =
+ (AppDomainsPreference) findPreference(KEY_INSTANT_APP_SUPPORTED_LINKS);
mLaunchPreference = findPreference(KEY_LAUNCH);
if (mAppEntry != null && mAppEntry.info != null) {
if ((mAppEntry.info.flags&ApplicationInfo.FLAG_INSTALLED) == 0 ||
@@ -550,6 +556,25 @@
public void onLoaderReset(Loader<AppStorageStats> loader) {
}
+ /**
+ * Utility method to hide and show specific preferences based on whether the app being displayed
+ * is an Instant App or an installed app.
+ */
+ @VisibleForTesting
+ void prepareInstantAppPrefs() {
+ final boolean isInstant = AppUtils.isInstant(mPackageInfo.applicationInfo);
+ if (isInstant) {
+ Set<String> handledDomainSet = Utils.getHandledDomains(mPm, mPackageInfo.packageName);
+ String[] handledDomains = handledDomainSet.toArray(new String[handledDomainSet.size()]);
+ mInstantAppDomainsPreference.setTitles(handledDomains);
+ // Dummy values, unused in the implementation
+ mInstantAppDomainsPreference.setValues(new int[handledDomains.length]);
+ getPreferenceScreen().removePreference(mLaunchPreference);
+ } else {
+ getPreferenceScreen().removePreference(mInstantAppDomainsPreference);
+ }
+ }
+
// Utility method to set application label and icon.
private void setAppLabelAndIcon(PackageInfo pkgInfo) {
final View appSnippet = mHeader.findViewById(R.id.app_snippet);
@@ -641,6 +666,7 @@
checkForceStop();
setAppLabelAndIcon(mPackageInfo);
initUninstallButtons();
+ prepareInstantAppPrefs();
// Update the preference summaries.
Activity context = getActivity();
@@ -1114,13 +1140,16 @@
if (installerLabel == null) {
return;
}
+ final int detailsStringId = AppUtils.isInstant(mPackageInfo.applicationInfo)
+ ? R.string.instant_app_details_summary
+ : R.string.app_install_details_summary;
PreferenceCategory category = new PreferenceCategory(getPrefContext());
category.setTitle(R.string.app_install_details_group_title);
screen.addPreference(category);
Preference pref = new Preference(getPrefContext());
pref.setTitle(R.string.app_install_details_title);
pref.setKey("app_info_store");
- pref.setSummary(getString(R.string.app_install_details_summary, installerLabel));
+ pref.setSummary(getString(detailsStringId, installerLabel));
Intent intent =
AppStoreUtil.getAppStoreLink(getContext(), installerPackageName, mPackageName);
diff --git a/src/com/android/settings/applications/MusicViewHolderController.java b/src/com/android/settings/applications/MusicViewHolderController.java
index 4599fcc..69f8958 100644
--- a/src/com/android/settings/applications/MusicViewHolderController.java
+++ b/src/com/android/settings/applications/MusicViewHolderController.java
@@ -61,7 +61,7 @@
@Override
public void setupView(AppViewHolder holder) {
- holder.appIcon.setImageDrawable(mContext.getDrawable(R.drawable.empty_icon));
+ holder.appIcon.setImageDrawable(mContext.getDrawable(R.drawable.ic_media_stream_on_24dp));
holder.appName.setText(mContext.getText(R.string.audio_files_title));
holder.summary.setText(Formatter.formatFileSize(mContext, mMusicSize));
}
diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java
index 3deedaf..bfb9f0f 100644
--- a/src/com/android/settings/development/DevelopmentSettings.java
+++ b/src/com/android/settings/development/DevelopmentSettings.java
@@ -28,6 +28,7 @@
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
+import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
@@ -205,7 +206,10 @@
"persist.bluetooth.disableabsvol";
private static final String BLUETOOTH_AVRCP_VERSION_PROPERTY =
"persist.bluetooth.avrcpversion";
+ private static final String BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY =
+ "persist.bluetooth.enableinbandringing";
+ private static final String BLUETOOTH_ENABLE_INBAND_RINGING_KEY = "bluetooth_enable_inband_ringing";
private static final String BLUETOOTH_SELECT_AVRCP_VERSION_KEY = "bluetooth_select_avrcp_version";
private static final String BLUETOOTH_SELECT_A2DP_CODEC_KEY = "bluetooth_select_a2dp_codec";
private static final String BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY = "bluetooth_select_a2dp_sample_rate";
@@ -278,6 +282,7 @@
private SwitchPreference mWifiAggressiveHandover;
private SwitchPreference mMobileDataAlwaysOn;
private SwitchPreference mBluetoothDisableAbsVolume;
+ private SwitchPreference mBluetoothEnableInbandRinging;
private BluetoothA2dp mBluetoothA2dp;
private final Object mBluetoothA2dpLock = new Object();
@@ -494,6 +499,11 @@
mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
mWebViewMultiprocess = findAndInitSwitchPref(WEBVIEW_MULTIPROCESS_KEY);
mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);
+ mBluetoothEnableInbandRinging = findAndInitSwitchPref(BLUETOOTH_ENABLE_INBAND_RINGING_KEY);
+ if (!BluetoothHeadset.isInbandRingingSupported(getContext())) {
+ removePreference(mBluetoothEnableInbandRinging);
+ mBluetoothEnableInbandRinging = null;
+ }
mBluetoothSelectAvrcpVersion = addListPreference(BLUETOOTH_SELECT_AVRCP_VERSION_KEY);
mBluetoothSelectA2dpCodec = addListPreference(BLUETOOTH_SELECT_A2DP_CODEC_KEY);
@@ -810,6 +820,7 @@
updateColorTemperature();
}
updateBluetoothDisableAbsVolumeOptions();
+ updateBluetoothEnableInbandRingingOptions();
updateBluetoothA2dpConfigurationValues();
}
@@ -1503,6 +1514,20 @@
mBluetoothDisableAbsVolume.isChecked() ? "true" : "false");
}
+ private void updateBluetoothEnableInbandRingingOptions() {
+ if (mBluetoothEnableInbandRinging != null) {
+ updateSwitchPreference(mBluetoothEnableInbandRinging,
+ SystemProperties.getBoolean(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY, false));
+ }
+ }
+
+ private void writeBluetoothEnableInbandRingingOptions() {
+ if (mBluetoothEnableInbandRinging != null) {
+ SystemProperties.set(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY,
+ mBluetoothEnableInbandRinging.isChecked() ? "true" : "false");
+ }
+ }
+
private void updateMobileDataAlwaysOnOptions() {
updateSwitchPreference(mMobileDataAlwaysOn, Settings.Global.getInt(
getActivity().getContentResolver(),
@@ -2524,6 +2549,8 @@
writeForceResizableOptions();
} else if (preference == mBluetoothDisableAbsVolume) {
writeBluetoothDisableAbsVolumeOptions();
+ } else if (preference == mBluetoothEnableInbandRinging) {
+ writeBluetoothEnableInbandRingingOptions();
} else if (preference == mWebViewMultiprocess) {
writeWebViewMultiprocessOptions();
} else if (SHORTCUT_MANAGER_RESET_KEY.equals(preference.getKey())) {
diff --git a/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java b/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
index 463d4dc..60a94dd 100644
--- a/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
@@ -55,16 +55,14 @@
public void updateState(Preference preference) {
final int mode = mAppOpsManager
.checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, mUid, mTargetPackage);
-
if (mode == AppOpsManager.MODE_ERRORED) {
preference.setEnabled(false);
- preference.setSummary(R.string.background_activity_summary_disabled);
} else {
final boolean checked = mode != AppOpsManager.MODE_IGNORED;
((SwitchPreference) preference).setChecked(checked);
- preference.setSummary(checked ? R.string.background_activity_summary_on
- : R.string.background_activity_summary_off);
}
+
+ updateSummary(preference);
}
@Override
@@ -92,6 +90,8 @@
boolean switchOn = (Boolean) newValue;
mAppOpsManager.setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, mUid, mTargetPackage,
switchOn ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
+
+ updateSummary(preference);
return true;
}
@@ -113,4 +113,18 @@
return false;
}
+
+ @VisibleForTesting
+ void updateSummary(Preference preference) {
+ final int mode = mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, mUid, mTargetPackage);
+
+ if (mode == AppOpsManager.MODE_ERRORED) {
+ preference.setSummary(R.string.background_activity_summary_disabled);
+ } else {
+ final boolean checked = mode != AppOpsManager.MODE_IGNORED;
+ preference.setSummary(checked ? R.string.background_activity_summary_on
+ : R.string.background_activity_summary_off);
+ }
+ }
}
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
index 7b89fb1..8588f77 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
@@ -511,7 +511,7 @@
elapsedRealtimeUs);
mDrainString = "";
mChargeDurationString = "";
- setContentDescription(mInfo.mChargeLabelString);
+ setContentDescription(mInfo.chargeLabelString);
int pos = 0;
int lastInteresting = 0;
@@ -589,7 +589,7 @@
mMaxPercentLabelStringWidth = (int)mTextPaint.measureText(mMaxPercentLabelString);
mMinPercentLabelStringWidth = (int)mTextPaint.measureText(mMinPercentLabelString);
mDrainStringWidth = (int)mHeaderTextPaint.measureText(mDrainString);
- mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mInfo.mChargeLabelString);
+ mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mInfo.chargeLabelString);
mChargeDurationStringWidth = (int)mHeaderTextPaint.measureText(mChargeDurationString);
mTextAscent = (int)mTextPaint.ascent();
mTextDescent = (int)mTextPaint.descent();
@@ -974,7 +974,7 @@
}
}
}
-
+
i++;
}
mStats.finishIteratingHistoryLocked();
@@ -983,9 +983,9 @@
if (lastY < 0 || lastX < 0) {
// Didn't get any data...
x = lastX = mLevelLeft;
- y = lastY = mLevelTop + levelh - ((mInfo.mBatteryLevel-batLow)*(levelh-1))/batChange;
+ y = lastY = mLevelTop + levelh - ((mInfo.batteryLevel -batLow)*(levelh-1))/batChange;
Path path;
- byte value = (byte)mInfo.mBatteryLevel;
+ byte value = (byte)mInfo.batteryLevel;
if (value <= mBatteryCriticalLevel) path = mBatCriticalPath;
else if (value <= mBatteryWarnLevel) path = mBatWarnPath;
else path = null; //mBatGoodPath;
@@ -1014,7 +1014,7 @@
mTimeRemainPath.moveTo(x, lastY);
int fullY = mLevelTop + levelh - ((100-batLow)*(levelh-1))/batChange;
int emptyY = mLevelTop + levelh - ((0-batLow)*(levelh-1))/batChange;
- if (mInfo.mDischarging) {
+ if (mInfo.discharging) {
mTimeRemainPath.lineTo(mLevelRight, emptyY);
} else {
mTimeRemainPath.lineTo(mLevelRight, fullY);
@@ -1211,8 +1211,8 @@
int headerTop = -mHeaderTextAscent + (mHeaderTextDescent-mHeaderTextAscent)/3;
mHeaderTextPaint.setTextAlign(textAlignLeft);
- if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mInfo.mChargeLabelString);
- canvas.drawText(mInfo.mChargeLabelString, textStartX, headerTop, mHeaderTextPaint);
+ if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mInfo.chargeLabelString);
+ canvas.drawText(mInfo.chargeLabelString, textStartX, headerTop, mHeaderTextPaint);
int stringHalfWidth = mChargeDurationStringWidth / 2;
if (layoutRtl) stringHalfWidth = -stringHalfWidth;
int headerCenter = ((width-mChargeDurationStringWidth-mDrainStringWidth)/2)
diff --git a/src/com/android/settings/fuelgauge/BatteryMeterView.java b/src/com/android/settings/fuelgauge/BatteryMeterView.java
index dcbf472..c450b90 100644
--- a/src/com/android/settings/fuelgauge/BatteryMeterView.java
+++ b/src/com/android/settings/fuelgauge/BatteryMeterView.java
@@ -18,17 +18,25 @@
import android.annotation.Nullable;
import android.content.Context;
+import android.graphics.Color;
+import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.support.annotation.VisibleForTesting;
import android.util.AttributeSet;
import android.widget.ImageView;
+
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.graph.BatteryMeterDrawableBase;
public class BatteryMeterView extends ImageView {
- private BatteryMeterDrawable mDrawable;
+ @VisibleForTesting
+ BatteryMeterDrawable mDrawable;
+ @VisibleForTesting
+ ColorFilter mErrorColorFilter;
+ @VisibleForTesting
+ ColorFilter mAccentColorFilter;
public BatteryMeterView(Context context) {
this(context, null, 0);
@@ -42,21 +50,30 @@
super(context, attrs, defStyleAttr);
final int frameColor = context.getColor(R.color.batterymeter_frame_color);
- final int tintColor = Utils.getColorAttr(context, android.R.attr.colorAccent);
+ mAccentColorFilter = new PorterDuffColorFilter(
+ Utils.getColorAttr(context, android.R.attr.colorAccent), PorterDuff.Mode.SRC_IN);
+ mErrorColorFilter = new PorterDuffColorFilter(
+ context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN);
mDrawable = new BatteryMeterDrawable(context, frameColor);
- mDrawable.setColorFilter(new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN));
mDrawable.setShowPercent(false);
+ mDrawable.setBatteryColorFilter(mAccentColorFilter);
+ mDrawable.setWarningColorFilter(
+ new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));
setImageDrawable(mDrawable);
}
- public void setBatteryInfo(int level) {
+ public void setBatteryLevel(int level) {
mDrawable.setBatteryLevel(level);
+ if (level < mDrawable.getCriticalLevel()) {
+ mDrawable.setBatteryColorFilter(mErrorColorFilter);
+ } else {
+ mDrawable.setBatteryColorFilter(mAccentColorFilter);
+ }
}
- @VisibleForTesting
- void setBatteryDrawable(BatteryMeterDrawable drawable) {
- mDrawable = drawable;
+ public void setCharging(boolean charging) {
+ mDrawable.setCharging(charging);
}
public static class BatteryMeterDrawable extends BatteryMeterDrawableBase {
@@ -81,6 +98,16 @@
public int getIntrinsicHeight() {
return mIntrinsicHeight;
}
+
+ public void setWarningColorFilter(@Nullable ColorFilter colorFilter) {
+ mWarningTextPaint.setColorFilter(colorFilter);
+ }
+
+ public void setBatteryColorFilter(@Nullable ColorFilter colorFilter) {
+ mFramePaint.setColorFilter(colorFilter);
+ mBatteryPaint.setColorFilter(colorFilter);
+ mBoltPaint.setColorFilter(colorFilter);
+ }
}
}
diff --git a/src/com/android/settings/fuelgauge/FakeUid.java b/src/com/android/settings/fuelgauge/FakeUid.java
index 770c567..8bb7d88 100644
--- a/src/com/android/settings/fuelgauge/FakeUid.java
+++ b/src/com/android/settings/fuelgauge/FakeUid.java
@@ -266,11 +266,6 @@
}
@Override
- public long getCpuPowerMaUs(int which) {
- return 0;
- }
-
- @Override
public BatteryStats.ControllerActivityCounter getWifiControllerActivity() {
return null;
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index f701684..ac041b8 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -561,14 +561,15 @@
.findViewById(R.id.battery_header_icon);
final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.battery_percent);
final TextView summary1 = (TextView) mBatteryLayoutPref.findViewById(R.id.summary1);
- timeText.setText(Utils.formatPercentage(info.mBatteryLevel));
+ timeText.setText(Utils.formatPercentage(info.batteryLevel));
if (info.remainingLabel == null ) {
summary1.setText(info.statusLabel);
} else {
summary1.setText(info.remainingLabel);
}
- batteryView.setBatteryInfo(info.mBatteryLevel);
+ batteryView.setBatteryLevel(info.batteryLevel);
+ batteryView.setCharging(!info.discharging);
}
@VisibleForTesting
@@ -695,7 +696,7 @@
BatteryInfo.getBatteryInfo(mContext, new BatteryInfo.Callback() {
@Override
public void onBatteryInfoLoaded(BatteryInfo info) {
- mLoader.setSummary(SummaryProvider.this, info.mChargeLabelString);
+ mLoader.setSummary(SummaryProvider.this, info.chargeLabelString);
}
});
}
diff --git a/tests/robotests/src/com/android/settings/SettingsActivityTest.java b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
index 9d53bc8..65e9708 100644
--- a/tests/robotests/src/com/android/settings/SettingsActivityTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
@@ -16,20 +16,28 @@
package com.android.settings;
+import android.app.Activity;
import android.app.ActivityManager;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
+import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
+import android.os.Bundle;
+import android.view.Menu;
+import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
@@ -42,6 +50,9 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingsActivityTest {
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+
@Mock
private FragmentManager mFragmentManager;
@Mock
@@ -50,10 +61,15 @@
private Bitmap mBitmap;
private SettingsActivity mActivity;
+ private FakeFeatureFactory mFeatureFactory;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest(mContext);
+ mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+
mActivity = spy(new SettingsActivity());
doReturn(mBitmap).when(mActivity).getBitmapFromXmlResource(anyInt());
}
@@ -61,7 +77,6 @@
@Test
public void launchSettingFragment_nullExtraShowFragment_shouldNotCrash()
throws ClassNotFoundException {
- mActivity = spy(new SettingsActivity());
when(mActivity.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class));
@@ -76,4 +91,51 @@
verify(mTaskDescription).setIcon(any());
}
+
+ @Test
+ public void testCreateOptionsMenu_setsUpSearch() {
+ ReflectionHelpers.setField(mActivity, "mSearchFeatureProvider",
+ mFeatureFactory.getSearchFeatureProvider());
+ mActivity.mDisplaySearch = true;
+ mActivity.onCreateOptionsMenu(null);
+
+ verify(mFeatureFactory.getSearchFeatureProvider()).setUpSearchMenu(any(Menu.class),
+ any(Activity.class));
+ }
+
+ @Test
+ public void testSaveState_DisplaySearchSaved() {
+ mActivity.mDisplaySearch = true;
+ Bundle bundle = new Bundle();
+ mActivity.saveState(bundle);
+
+ assertThat((boolean) bundle.get(SettingsActivity.SAVE_KEY_SHOW_SEARCH)).isTrue();
+ }
+
+ @Test
+ public void testSaveState_EnabledHomeSaved() {
+ mActivity.mDisplayHomeAsUpEnabled = true;
+ Bundle bundle = new Bundle();
+ mActivity.saveState(bundle);
+
+ assertThat((boolean) bundle.get(SettingsActivity.SAVE_KEY_SHOW_HOME_AS_UP)).isTrue();
+ }
+
+ @Test
+ public void testRestoreState_DisplaySearchRestored() {
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(SettingsActivity.SAVE_KEY_SHOW_SEARCH, true);
+ mActivity.onRestoreInstanceState(bundle);
+
+ assertThat(mActivity.mDisplaySearch).isTrue();
+ }
+
+ @Test
+ public void testRestoreState_EnabledHomeRestored() {
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(SettingsActivity.SAVE_KEY_SHOW_SEARCH, true);
+ mActivity.onRestoreInstanceState(bundle);
+
+ assertThat(mActivity.mDisplaySearch).isTrue();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
index 5b1019e..f372836 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
@@ -17,21 +17,34 @@
package com.android.settings.applications;
-import android.app.Activity;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+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.app.AlertDialog;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.os.BatteryStats;
import android.os.UserManager;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceScreen;
import android.view.View;
import android.widget.Button;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatteryStatsHelper;
-import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
@@ -39,8 +52,8 @@
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
-import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
+import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
import org.junit.Before;
import org.junit.Test;
@@ -52,18 +65,6 @@
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -315,4 +316,43 @@
verify(buttonsController).setPackageName(anyString());
verify(buttonsController).show();
}
+
+ @Test
+ public void instantApps_removeCorrectPref() {
+ PreferenceScreen mockPreferenceScreen = mock(PreferenceScreen.class);
+ PreferenceManager mockPreferenceManager = mock(PreferenceManager.class);
+ AppDomainsPreference mockAppDomainsPref = mock(AppDomainsPreference.class);
+ Preference mockLaunchPreference = mock(Preference.class);
+ PackageInfo mockPackageInfo = mock(PackageInfo.class);
+ PackageManager mockPackageManager = mock(PackageManager.class);
+ ReflectionHelpers.setField(
+ mAppDetail, "mLaunchPreference", mockLaunchPreference);
+ ReflectionHelpers.setField(
+ mAppDetail, "mInstantAppDomainsPreference", mockAppDomainsPref);
+ ReflectionHelpers.setField(
+ mAppDetail, "mPreferenceManager", mockPreferenceManager);
+ ReflectionHelpers.setField(
+ mAppDetail, "mPackageInfo", mockPackageInfo);
+ ReflectionHelpers.setField(
+ mAppDetail, "mPm", mockPackageManager);
+ when(mockPreferenceManager.getPreferenceScreen()).thenReturn(mockPreferenceScreen);
+
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> false));
+ mAppDetail.prepareInstantAppPrefs();
+
+ // For the non instant case we remove the app domain pref, and leave the launch pref
+ verify(mockPreferenceScreen).removePreference(mockAppDomainsPref);
+ verify(mockPreferenceScreen, never()).removePreference(mockLaunchPreference);
+
+ // For the instant app case we remove the launch preff, and leave the app domain pref
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> true));
+
+ mAppDetail.prepareInstantAppPrefs();
+ verify(mockPreferenceScreen).removePreference(mockLaunchPreference);
+ // Will be 1 still due to above call
+ verify(mockPreferenceScreen, times(1))
+ .removePreference(mockAppDomainsPref);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
index 0813478..4f48945 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
@@ -23,7 +23,9 @@
import android.os.Build;
import android.support.v14.preference.SwitchPreference;
+import com.android.settings.R;
import com.android.settings.TestConfig;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,9 +33,12 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -54,17 +59,18 @@
@Mock
private AppOpsManager mAppOpsManager;
@Mock
- private SwitchPreference mPreference;
- @Mock
private ApplicationInfo mHighApplicationInfo;
@Mock
private ApplicationInfo mLowApplicationInfo;
private BackgroundActivityPreferenceController mController;
+ private SwitchPreference mPreference;
+ private Context mShadowContext;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
+ mShadowContext = RuntimeEnvironment.application;
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
when(mPackageManager.getPackagesForUid(UID_NORMAL)).thenReturn(PACKAGES_NORMAL);
@@ -77,7 +83,8 @@
mHighApplicationInfo.targetSdkVersion = Build.VERSION_CODES.O;
mLowApplicationInfo.targetSdkVersion = Build.VERSION_CODES.L;
- mController = new BackgroundActivityPreferenceController(mContext, UID_NORMAL);
+ mPreference = new SwitchPreference(mShadowContext);
+ mController = spy(new BackgroundActivityPreferenceController(mContext, UID_NORMAL));
mController.isAvailable();
}
@@ -87,14 +94,16 @@
verify(mAppOpsManager).setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL,
mController.getTargetPackage(), AppOpsManager.MODE_ALLOWED);
+ verify(mController).updateSummary(mPreference);
}
@Test
public void testOnPreferenceChange_TurnOffCheck_MethodInvoked() {
- mController.onPreferenceChange(null, false);
+ mController.onPreferenceChange(mPreference, false);
verify(mAppOpsManager).setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL,
mController.getTargetPackage(), AppOpsManager.MODE_IGNORED);
+ verify(mController).updateSummary(mPreference);
}
@Test
@@ -105,7 +114,8 @@
mController.updateState(mPreference);
- verify(mPreference).setChecked(true);
+ assertThat(mPreference.isChecked()).isTrue();
+ verify(mController).updateSummary(mPreference);
}
@Test
@@ -116,7 +126,46 @@
mController.updateState(mPreference);
- verify(mPreference).setChecked(false);
+ assertThat(mPreference.isChecked()).isFalse();
+ verify(mController).updateSummary(mPreference);
+ }
+
+ @Test
+ public void testUpdateSummary_modeError_showSummaryDisabled() {
+ when(mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL, LOW_SDK_PACKAGE))
+ .thenReturn(AppOpsManager.MODE_ERRORED);
+ final CharSequence expectedSummary = mShadowContext.getText(
+ R.string.background_activity_summary_disabled);
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
+ }
+
+ @Test
+ public void testUpdateSummary_modeDefault_showSummaryOn() {
+ when(mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL, LOW_SDK_PACKAGE))
+ .thenReturn(AppOpsManager.MODE_DEFAULT);
+ final CharSequence expectedSummary = mShadowContext.getText(
+ R.string.background_activity_summary_on);
+
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
+ }
+
+ @Test
+ public void testUpdateSummary_modeIgnored_showSummaryOff() {
+ when(mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL, LOW_SDK_PACKAGE))
+ .thenReturn(AppOpsManager.MODE_IGNORED);
+ final CharSequence expectedSummary = mShadowContext.getText(
+ R.string.background_activity_summary_off);
+
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
}
@Test
@@ -144,6 +193,6 @@
assertThat(available).isTrue();
// Should get status from LOW_SDK_PACKAGE
- verify(mPreference).setChecked(true);
+ assertThat(mPreference.isChecked()).isTrue();
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
index 85b893a..cb37a6e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
@@ -15,12 +15,17 @@
*/
package com.android.settings.fuelgauge;
+import static com.google.common.truth.Truth.assertThat;
+
import android.content.Context;
+import android.graphics.ColorFilter;
+
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.SettingsShadowResources.SettingsShadowTheme;
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,6 +34,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -42,10 +49,15 @@
})
public class BatteryMeterViewTest {
private static final int BATTERY_LEVEL = 100;
+ private static final int BATTERY_CRITICAL_LEVEL = 15;
+ private static final int BATTERY_LOW_LEVEL = 3;
@Mock
- private BatteryMeterView.BatteryMeterDrawable mDrawable;
+ private ColorFilter mErrorColorFilter;
+ @Mock
+ private ColorFilter mAccentColorFilter;
private Context mContext;
private BatteryMeterView mBatteryMeterView;
+ private BatteryMeterView.BatteryMeterDrawable mDrawable;
@Before
public void setUp() {
@@ -53,13 +65,33 @@
mContext = RuntimeEnvironment.application;
mBatteryMeterView = new BatteryMeterView(mContext);
- mBatteryMeterView.setBatteryDrawable(mDrawable);
+ mDrawable = spy(new BatteryMeterView.BatteryMeterDrawable(mContext, 0));
+
+ mBatteryMeterView.mDrawable = mDrawable;
+ mBatteryMeterView.mAccentColorFilter = mAccentColorFilter;
+ mBatteryMeterView.mErrorColorFilter = mErrorColorFilter;
+
+ doReturn(BATTERY_CRITICAL_LEVEL).when(mDrawable).getCriticalLevel();
}
@Test
- public void testSetBatteryInfo_SetCorrectly() {
- mBatteryMeterView.setBatteryInfo(BATTERY_LEVEL);
+ public void testSetBatteryInfo_setCorrectly() {
+ mBatteryMeterView.setBatteryLevel(BATTERY_LEVEL);
- verify(mDrawable).setBatteryLevel(BATTERY_LEVEL);
+ assertThat(mDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL);
+ }
+
+ @Test
+ public void testSetBatteryInfo_levelLow_setErrorColor() {
+ mBatteryMeterView.setBatteryLevel(BATTERY_LOW_LEVEL);
+
+ verify(mDrawable).setBatteryColorFilter(mErrorColorFilter);
+ }
+
+ @Test
+ public void testSetBatteryInfo_levelNormal_setNormalColor() {
+ mBatteryMeterView.setBatteryLevel(BATTERY_LEVEL);
+
+ verify(mDrawable).setBatteryColorFilter(mAccentColorFilter);
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index 72dd28e..39c386b 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -37,6 +37,8 @@
import com.android.settings.Utils;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
import com.android.settingslib.BatteryInfo;
import org.junit.Before;
@@ -74,7 +76,13 @@
*/
// TODO: Improve this test class so that it starts up the real activity and fragment.
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH,
+ sdk = TestConfig.SDK_VERSION,
+ shadows = {
+ SettingsShadowResources.class,
+ SettingsShadowResources.SettingsShadowTheme.class,
+ ShadowDynamicIndexableContentMonitor.class
+ })
public class PowerUsageSummaryTest {
private static final String[] PACKAGE_NAMES = {"com.app1", "com.app2"};
private static final String TIME_LEFT = "2h30min";
@@ -119,8 +127,6 @@
@Mock
private LayoutPreference mBatteryLayoutPref;
@Mock
- private BatteryMeterView mBatteryMeterView;
- @Mock
private TextView mBatteryPercentText;
@Mock
private TextView mSummary1;
@@ -141,6 +147,7 @@
private Context mRealContext;
private TestFragment mFragment;
private FakeFeatureFactory mFeatureFactory;
+ private BatteryMeterView mBatteryMeterView;
@Before
public void setUp() {
@@ -153,6 +160,8 @@
mFragment = spy(new TestFragment(mContext));
mFragment.initFeatureProvider();
+ mBatteryMeterView = new BatteryMeterView(mRealContext);
+ mBatteryMeterView.mDrawable = new BatteryMeterView.BatteryMeterDrawable(mRealContext, 0);
when(mFragment.getActivity()).thenReturn(mSettingsActivity);
when(mAdditionalBatteryInfoMenu.getItemId())
@@ -192,7 +201,7 @@
mFragment.mScreenUsagePref = mScreenUsagePref;
mFragment.mLastFullChargePref = mLastFullChargePref;
- mBatteryInfo.mBatteryLevel = BATTERY_LEVEL;
+ mBatteryInfo.batteryLevel = BATTERY_LEVEL;
}
@Test
@@ -317,6 +326,18 @@
}
@Test
+ public void testUpdatePreference_updateBatteryInfo() {
+ mBatteryInfo.remainingLabel = TIME_LEFT;
+ mBatteryInfo.batteryLevel = BATTERY_LEVEL;
+ mBatteryInfo.discharging = true;
+
+ mFragment.updateHeaderPreference(mBatteryInfo);
+
+ assertThat(mBatteryMeterView.mDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL);
+ assertThat(mBatteryMeterView.mDrawable.getCharging()).isEqualTo(false);
+ }
+
+ @Test
public void testUpdatePreference_noRemainingTime_showStatusLabel() {
mBatteryInfo.remainingLabel = null;
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
index e87e9c5..724909d 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
@@ -5,9 +5,12 @@
import android.content.res.Resources.NotFoundException;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
+import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.ArrayRes;
+import android.support.annotation.ColorRes;
+import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.TypedValue;
@@ -53,6 +56,14 @@
}
@Implementation
+ public int getColor(@ColorRes int id, @Nullable Theme theme) throws NotFoundException {
+ if (id == R.color.battery_icon_color_error) {
+ return Color.WHITE;
+ }
+ return directlyOn(realResources, Resources.class).getColor(id, theme);
+ }
+
+ @Implementation
public Drawable loadDrawable(TypedValue value, int id, Theme theme)
throws NotFoundException {
// The drawable item in switchbar_background.xml refers to a very recent color attribute