Merge "Adopt robolectric 3.6.1"
diff --git a/res/values/bools.xml b/res/values/bools.xml
index 41d3dbd..e733d5f 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -57,6 +57,9 @@
<!-- Whether location mode is available or not. -->
<bool name="config_location_mode_available">true</bool>
+ <!-- Whether location scanning is available or not. -->
+ <bool name="config_show_location_scanning">true</bool>
+
<!-- Whether high_power_apps should be shown or not. -->
<bool name="config_show_high_power_apps">true</bool>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 76c4c86..46411e6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4809,6 +4809,10 @@
<string name="battery_tip_low_battery_title">Low battery capacity</string>
<!-- Summary for the low battery tip [CHAR LIMIT=NONE] -->
<string name="battery_tip_low_battery_summary">Battery can\'t provide good battery life</string>
+ <!-- Title for the smart battery tip [CHAR LIMIT=NONE] -->
+ <string name="battery_tip_smart_battery_title">Turn on smart battery manager</string>
+ <!-- Summary for the smart battery tip [CHAR LIMIT=NONE] -->
+ <string name="battery_tip_smart_battery_summary">Turn on to optimize battery usage</string>
<!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
<string name="battery_tip_high_usage_title" product="default">Phone used heavily</string>
<!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
diff --git a/res/xml/app_and_notification.xml b/res/xml/app_and_notification.xml
index f08afa8..3548efb 100644
--- a/res/xml/app_and_notification.xml
+++ b/res/xml/app_and_notification.xml
@@ -20,7 +20,7 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="apps_and_notification_screen"
android:title="@string/app_and_notification_dashboard_title"
- settings:initialExpandedChildrenCount="4">
+ settings:initialExpandedChildrenCount="6">
<PreferenceCategory
android:key="recent_apps_category"
@@ -37,7 +37,6 @@
android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.Settings$ManageApplicationsActivity">
- <extra android:name="show_drawer_menu" android:value="true" />
</intent>
</Preference>
</PreferenceCategory>
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index 2d9fd54..4b285d3 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -22,12 +22,14 @@
settings:keywords="@string/keywords_display"
settings:initialExpandedChildrenCount="4">
- <Preference
+ <com.android.settingslib.RestrictedPreference
android:key="brightness"
android:title="@string/brightness"
- settings:keywords="@string/keywords_display_brightness_level">
- <intent android:action="com.android.intent.action.SHOW_BRIGHTNESS_DIALOG" />
- </Preference>
+ settings:keywords="@string/keywords_display_brightness_level"
+ settings:useAdminDisabledSummary="true"
+ settings:userRestriction="no_config_brightness">
+ <intent android:action="com.android.intent.action.SHOW_BRIGHTNESS_DIALOG" />
+ </com.android.settingslib.RestrictedPreference>
<com.android.settings.display.NightDisplayPreference
android:key="night_display"
@@ -38,12 +40,13 @@
settings:keywords="@string/keywords_display_night_display" />
<!-- Cross-listed item, if you change this, also change it in power_usage_summary.xml -->
- <SwitchPreference
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="auto_brightness"
android:title="@string/auto_brightness_title"
settings:keywords="@string/keywords_display_auto_brightness"
android:summary="@string/auto_brightness_summary"
- settings:controller="com.android.settings.display.AutoBrightnessPreferenceController" />
+ settings:useAdminDisabledSummary="true"
+ settings:userRestriction="no_config_brightness" />
<com.android.settingslib.RestrictedPreference
android:key="wallpaper"
diff --git a/res/xml/power_usage_summary_legacy.xml b/res/xml/power_usage_summary_legacy.xml
index 80179c0..5af6bc1 100644
--- a/res/xml/power_usage_summary_legacy.xml
+++ b/res/xml/power_usage_summary_legacy.xml
@@ -61,11 +61,13 @@
android:summary="@string/battery_percentage_description"/>
<!-- Cross-listed item, if you change this, also change it in display_settings.xml -->
- <SwitchPreference
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="auto_brightness_battery"
android:title="@string/auto_brightness_title"
android:summary="@string/auto_brightness_summary"
- settings:keywords="@string/keywords_display_auto_brightness"/>
+ settings:keywords="@string/keywords_display_auto_brightness"
+ settings:useAdminDisabledSummary="true"
+ settings:userRestriction="no_config_brightness" />
<!-- Cross-listed item, if you change this, also change it in display_settings.xml -->
<com.android.settings.TimeoutListPreference
diff --git a/src/com/android/settings/accounts/ManagedProfileSettings.java b/src/com/android/settings/accounts/ManagedProfileSettings.java
index 50b9ecc..3ea7cf7 100644
--- a/src/com/android/settings/accounts/ManagedProfileSettings.java
+++ b/src/com/android/settings/accounts/ManagedProfileSettings.java
@@ -129,7 +129,7 @@
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mWorkModePreference) {
boolean quietModeEnabled = !(boolean) newValue;
- mUserManager.trySetQuietModeEnabled(quietModeEnabled, mManagedUser);
+ mUserManager.requestQuietModeEnabled(quietModeEnabled, mManagedUser);
return true;
}
if (preference == mContactPrefrence) {
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index d19c472..dcdd3b8 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -232,7 +232,7 @@
Intent intent = activity.getIntent();
Bundle args = getArguments();
int screenTitle = intent.getIntExtra(
- SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, R.string.notifications_label);
+ SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, R.string.application_info_label);
String className = args != null ? args.getString(EXTRA_CLASSNAME) : null;
if (className == null) {
className = intent.getComponent().getClassName();
diff --git a/src/com/android/settings/dashboard/conditional/WorkModeCondition.java b/src/com/android/settings/dashboard/conditional/WorkModeCondition.java
index 297e35a..b637137 100644
--- a/src/com/android/settings/dashboard/conditional/WorkModeCondition.java
+++ b/src/com/android/settings/dashboard/conditional/WorkModeCondition.java
@@ -91,7 +91,7 @@
public void onActionClick(int index) {
if (index == 0) {
if (mUserHandle != null) {
- mUm.trySetQuietModeEnabled(false, mUserHandle);
+ mUm.requestQuietModeEnabled(false, mUserHandle);
}
setActive(false);
} else {
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 205ac0b..ec54291 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -266,7 +266,7 @@
KEY_APP_LIST, lifecycle, activity, this);
controllers.add(mBatteryAppListPreferenceController);
mBatteryTipPreferenceController = new BatteryTipPreferenceController(context,
- KEY_BATTERY_TIP, this, this);
+ KEY_BATTERY_TIP, (SettingsActivity) getActivity(), this, this);
controllers.add(mBatteryTipPreferenceController);
controllers.add(new BatterySaverController(context, getLifecycle()));
controllers.add(new BatteryPercentagePreferenceController(context));
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
index 3e091b3..942c42b 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
@@ -27,8 +27,10 @@
import android.view.LayoutInflater;
import com.android.settings.R;
+import com.android.settings.SettingsActivity;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController.BatteryTipListener;
+import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
@@ -97,7 +99,11 @@
if (lsn == null) {
return;
}
- mBatteryTip.action();
+ final BatteryTipAction action = BatteryTipUtils.getActionForBatteryTip(mBatteryTip,
+ (SettingsActivity) getActivity(), this);
+ if (action != null) {
+ action.handlePositiveAction();
+ }
lsn.onBatteryTipHandled(mBatteryTip);
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
index a1db57a..fc6aa57 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
@@ -25,6 +25,7 @@
import com.android.settings.fuelgauge.batterytip.detectors.BatteryTipDetector;
import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
+import com.android.settings.fuelgauge.batterytip.detectors.SmartBatteryDetector;
import com.android.settings.fuelgauge.batterytip.detectors.SummaryDetector;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
@@ -68,6 +69,8 @@
addBatteryTipFromDetector(tips, new LowBatteryDetector(policy, batteryInfo));
addBatteryTipFromDetector(tips,
new HighUsageDetector(getContext(), policy, mBatteryStatsHelper));
+ addBatteryTipFromDetector(tips,
+ new SmartBatteryDetector(policy, getContext().getContentResolver()));
// Add summary detector at last since it need other detectors to update the mVisibleTips
addBatteryTipFromDetector(tips, new SummaryDetector(policy, mVisibleTips));
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
index 9aa70c5..9f5209f 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
@@ -23,7 +23,9 @@
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
+import com.android.settings.SettingsActivity;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
@@ -41,6 +43,7 @@
private BatteryTipListener mBatteryTipListener;
private List<BatteryTip> mBatteryTips;
private Map<String, BatteryTip> mBatteryTipMap;
+ private SettingsActivity mSettingsActivity;
@VisibleForTesting
PreferenceGroup mPreferenceGroup;
@VisibleForTesting
@@ -48,15 +51,17 @@
PreferenceFragment mFragment;
public BatteryTipPreferenceController(Context context, String preferenceKey) {
- this(context, preferenceKey, null, null);
+ this(context, preferenceKey, null, null, null);
}
public BatteryTipPreferenceController(Context context, String preferenceKey,
- PreferenceFragment fragment, BatteryTipListener batteryTipListener) {
+ SettingsActivity settingsActivity, PreferenceFragment fragment,
+ BatteryTipListener batteryTipListener) {
super(context, preferenceKey);
mBatteryTipListener = batteryTipListener;
mBatteryTipMap = new HashMap<>();
mFragment = fragment;
+ mSettingsActivity = settingsActivity;
}
@Override
@@ -107,7 +112,11 @@
dialogFragment.setTargetFragment(mFragment, REQUEST_ANOMALY_ACTION);
dialogFragment.show(mFragment.getFragmentManager(), TAG);
} else {
- batteryTip.action();
+ final BatteryTipAction action = BatteryTipUtils.getActionForBatteryTip(batteryTip,
+ mSettingsActivity, mFragment);
+ if (action != null) {
+ action.handlePositiveAction();
+ }
if (mBatteryTipListener != null) {
mBatteryTipListener.onBatteryTipHandled(batteryTip);
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
new file mode 100644
index 0000000..d10fa37
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import android.app.Fragment;
+
+import com.android.settings.SettingsActivity;
+import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
+import com.android.settings.fuelgauge.batterytip.actions.SmartBatteryAction;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+
+/**
+ * Utility class for {@link BatteryTip}
+ */
+public class BatteryTipUtils {
+
+ /**
+ * Get a corresponding action based on {@code batteryTip}
+ * @param batteryTip used to detect which action to choose
+ * @param settingsActivity used to populate {@link BatteryTipAction}
+ * @param fragment used to populate {@link BatteryTipAction}
+ * @return an action for {@code batteryTip}
+ */
+ public static BatteryTipAction getActionForBatteryTip(BatteryTip batteryTip,
+ SettingsActivity settingsActivity, Fragment fragment) {
+ switch (batteryTip.getType()) {
+ case BatteryTip.TipType.SMART_BATTERY_MANAGER:
+ return new SmartBatteryAction(settingsActivity, fragment);
+ default:
+ return null;
+ }
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/BatteryTipAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/BatteryTipAction.java
new file mode 100644
index 0000000..9fa69fd
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/BatteryTipAction.java
@@ -0,0 +1,37 @@
+/*
+ * 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.actions;
+
+import android.content.Context;
+
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+
+/**
+ * Abstract class for battery tip action, which is triggered if we need to handle the battery tip
+ */
+public abstract class BatteryTipAction {
+ protected Context mContext;
+
+ public BatteryTipAction(Context context) {
+ mContext = context;
+ }
+
+ /**
+ * Handle the action when user clicks positive button
+ */
+ public abstract void handlePositiveAction();
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java
new file mode 100644
index 0000000..a19471e
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java
@@ -0,0 +1,48 @@
+/*
+ * 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.actions;
+
+import android.app.Fragment;
+import android.os.UserHandle;
+import android.support.v14.preference.PreferenceFragment;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.fuelgauge.SmartBatterySettings;
+
+public class SmartBatteryAction extends BatteryTipAction {
+ private SettingsActivity mSettingsActivity;
+ private Fragment mFragment;
+
+ public SmartBatteryAction(SettingsActivity settingsActivity, Fragment fragment) {
+ super(settingsActivity.getApplicationContext());
+ mSettingsActivity = settingsActivity;
+ mFragment = fragment;
+ }
+
+ /**
+ * Handle the action when user clicks positive button
+ */
+ @Override
+ public void handlePositiveAction() {
+ mSettingsActivity.startPreferencePanelAsUser(mFragment,
+ SmartBatterySettings.class.getName(), null /* args */,
+ R.string.smart_battery_manager_title, null /* titleText */,
+ new UserHandle(UserHandle.myUserId()));
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetector.java
new file mode 100644
index 0000000..bff324d
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetector.java
@@ -0,0 +1,47 @@
+/*
+ * 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.detectors;
+
+import android.content.ContentResolver;
+import android.provider.Settings;
+
+import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+import com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip;
+
+/**
+ * Detect whether to show smart battery tip.
+ */
+public class SmartBatteryDetector implements BatteryTipDetector {
+ private BatteryTipPolicy mPolicy;
+ private ContentResolver mContentResolver;
+
+ public SmartBatteryDetector(BatteryTipPolicy policy, ContentResolver contentResolver) {
+ mPolicy = policy;
+ mContentResolver = contentResolver;
+ }
+
+ @Override
+ public BatteryTip detect() {
+ // Show it if there is no other tips shown
+ final boolean smartBatteryOn = Settings.Global.getInt(mContentResolver,
+ Settings.Global.APP_STANDBY_ENABLED, 1) != 0;
+ final int state =
+ smartBatteryOn ? BatteryTip.StateType.INVISIBLE : BatteryTip.StateType.NEW;
+ return new SmartBatteryTip(state);
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
index eadd0e1..292849d 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
@@ -105,11 +105,6 @@
*/
public abstract void updateState(BatteryTip tip);
- /**
- * Execute the action for this {@link BatteryTip}
- */
- public abstract void action();
-
public Preference buildPreference(Context context) {
Preference preference = new Preference(context);
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
index 001a48e..0316832 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
@@ -78,11 +78,6 @@
mState = tip.mState;
}
- @Override
- public void action() {
- // do nothing
- }
-
public long getScreenTimeMs() {
return mScreenTimeMs;
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
index 4a207e0..32cbe02 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
@@ -55,11 +55,6 @@
mState = tip.mState;
}
- @Override
- public void action() {
- // do nothing
- }
-
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public BatteryTip createFromParcel(Parcel in) {
return new LowBatteryTip(in);
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/SmartBatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/SmartBatteryTip.java
new file mode 100644
index 0000000..7b408bb
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/SmartBatteryTip.java
@@ -0,0 +1,68 @@
+/*
+ * 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 android.content.Context;
+import android.os.Parcel;
+import android.provider.Settings;
+
+import com.android.settings.R;
+
+/**
+ * Tip to suggest turn on smart battery if it is not on
+ */
+public class SmartBatteryTip extends BatteryTip {
+
+ public SmartBatteryTip(@StateType int state) {
+ super(TipType.SMART_BATTERY_MANAGER, state, false /* showDialog */);
+ }
+
+ private SmartBatteryTip(Parcel in) {
+ super(in);
+ }
+
+ @Override
+ public CharSequence getTitle(Context context) {
+ return context.getString(R.string.battery_tip_smart_battery_title);
+ }
+
+ @Override
+ public CharSequence getSummary(Context context) {
+ return context.getString(R.string.battery_tip_smart_battery_summary);
+ }
+
+ @Override
+ public int getIconId() {
+ return R.drawable.ic_perm_device_information_red_24dp;
+ }
+
+ @Override
+ public void updateState(BatteryTip tip) {
+ mState = tip.mState;
+ }
+
+ public static final Creator CREATOR = new Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new SmartBatteryTip(in);
+ }
+
+ public BatteryTip[] newArray(int size) {
+ return new SmartBatteryTip[size];
+ }
+ };
+
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java
index 51019a8..458bd2e 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java
@@ -55,11 +55,6 @@
mState = tip.mState;
}
- @Override
- public void action() {
- // do nothing
- }
-
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public BatteryTip createFromParcel(Parcel in) {
return new SummaryTip(in);
diff --git a/src/com/android/settings/location/LocationScanningPreferenceController.java b/src/com/android/settings/location/LocationScanningPreferenceController.java
new file mode 100644
index 0000000..ec487e4
--- /dev/null
+++ b/src/com/android/settings/location/LocationScanningPreferenceController.java
@@ -0,0 +1,41 @@
+/*
+ * 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.location;
+
+import android.content.Context;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.R;
+
+import android.support.annotation.VisibleForTesting;
+
+
+public class LocationScanningPreferenceController extends BasePreferenceController {
+
+ @VisibleForTesting static final String KEY_LOCATION_SCANNING = "location_scanning";
+
+ public LocationScanningPreferenceController(Context context) {
+ super(context, KEY_LOCATION_SCANNING);
+ }
+
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
+ ? AVAILABLE
+ : DISABLED_UNSUPPORTED;
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java
index 563352e..d0fca16 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -141,6 +141,7 @@
new RecentLocationRequestPreferenceController(context, fragment, lifecycle));
controllers.add(
new LocationServicePreferenceController(context, fragment, lifecycle));
+ controllers.add(new LocationScanningPreferenceController(context));
return controllers;
}
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index f19907b..c3ae911 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -34,6 +34,7 @@
<bool name="config_show_data_saver">false</bool>
<bool name="config_show_enabled_vr_listeners">false</bool>
<bool name="config_location_mode_available">false</bool>
+ <bool name="config_show_location_scanning">false</bool>
<bool name="config_show_wallpaper_attribution">false</bool>
<bool name="config_show_default_home">false</bool>
<bool name="config_show_accessibility_shortcut_preference">false</bool>
diff --git a/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java b/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
index dfe8e4c..5341109 100644
--- a/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
@@ -197,11 +197,6 @@
}
@Test
- public void shouldUseStableItemHeight_notificationType_no() {
-
- }
-
- @Test
public void onRebuildComplete_shouldHideLoadingView() {
final Context context = RuntimeEnvironment.application;
final ManageApplications fragment = mock(ManageApplications.class);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java
index 9f0c61f..b4149c1 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java
@@ -15,6 +15,9 @@
*/
package com.android.settings.fuelgauge.batterytip;
+import static com.android.settings.fuelgauge.batterytip.tips.BatteryTip.TipType
+ .SMART_BATTERY_MANAGER;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
@@ -29,6 +32,7 @@
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
+import com.android.settings.SettingsActivity;
import com.android.settings.TestConfig;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
@@ -57,6 +61,8 @@
private PreferenceScreen mPreferenceScreen;
@Mock
private BatteryTip mBatteryTip;
+ @Mock
+ private SettingsActivity mSettingsActivity;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceManager mPreferenceManager;
@@ -85,7 +91,7 @@
mNewBatteryTips.add(new SummaryTip(BatteryTip.StateType.INVISIBLE));
mBatteryTipPreferenceController = new BatteryTipPreferenceController(mContext, KEY_PREF,
- null, mBatteryTipListener);
+ mSettingsActivity, null, mBatteryTipListener);
mBatteryTipPreferenceController.mPreferenceGroup = mPreferenceGroup;
mBatteryTipPreferenceController.mPrefContext = mContext;
}
@@ -109,7 +115,8 @@
}
@Test
- public void testHandlePreferenceTreeClick_noDialog_invokeAction() {
+ public void testHandlePreferenceTreeClick_noDialog_invokeCallback() {
+ doReturn(SMART_BATTERY_MANAGER).when(mBatteryTip).getType();
List<BatteryTip> batteryTips = new ArrayList<>();
batteryTips.add(mBatteryTip);
doReturn(mPreference).when(mBatteryTip).buildPreference(any());
@@ -119,7 +126,7 @@
mBatteryTipPreferenceController.handlePreferenceTreeClick(mPreference);
- verify(mBatteryTip).action();
+ verify(mBatteryTipListener).onBatteryTipHandled(mBatteryTip);
}
private void assertOnlyContainsSummaryTip(final PreferenceGroup preferenceGroup) {
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetectorTest.java
new file mode 100644
index 0000000..8400d89
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetectorTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.detectors;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.TestConfig;
+import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SmartBatteryDetectorTest {
+ private Context mContext;
+ private BatteryTipPolicy mPolicy;
+ private SmartBatteryDetector mSmartBatteryDetector;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ mPolicy = spy(new BatteryTipPolicy(mContext));
+ mSmartBatteryDetector = new SmartBatteryDetector(mPolicy, mContext.getContentResolver());
+ }
+
+ @Test
+ public void testDetect_smartBatteryOff_tipVisible() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.APP_STANDBY_ENABLED, 0);
+
+ assertThat(mSmartBatteryDetector.detect().isVisible()).isTrue();
+ }
+
+ @Test
+ public void testDetect_smartBatteryOn_tipInvisible() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.APP_STANDBY_ENABLED, 1);
+
+ assertThat(mSmartBatteryDetector.detect().isVisible()).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
index 1c6c868..6efd5d3 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
@@ -107,11 +107,6 @@
// do nothing
}
- @Override
- public void action() {
- // do nothing
- }
-
public final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public BatteryTip createFromParcel(Parcel in) {
return new TestBatteryTip(in);
diff --git a/tests/robotests/src/com/android/settings/location/LocationScanningPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationScanningPreferenceControllerTest.java
new file mode 100644
index 0000000..7577ac1
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/location/LocationScanningPreferenceControllerTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.location;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class LocationScanningPreferenceControllerTest {
+
+ private Context mContext;
+ private LocationScanningPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application.getApplicationContext());
+ mController = new LocationScanningPreferenceController(mContext);
+ }
+
+ @Test
+ public void testLocationScanning_byDefault_shouldBeShown() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void testLocationScanning_ifDisabled_shouldNotBeShown() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+}
\ No newline at end of file
diff --git a/tests/unit/src/com/android/settings/core/UserRestrictionTest.java b/tests/unit/src/com/android/settings/core/UserRestrictionTest.java
index da09d3c..f37c30b 100644
--- a/tests/unit/src/com/android/settings/core/UserRestrictionTest.java
+++ b/tests/unit/src/com/android/settings/core/UserRestrictionTest.java
@@ -64,7 +64,8 @@
UserManager.DISALLOW_CONFIG_TETHERING,
UserManager.DISALLOW_CONFIG_VPN,
UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS,
- UserManager.DISALLOW_AIRPLANE_MODE
+ UserManager.DISALLOW_AIRPLANE_MODE,
+ UserManager.DISALLOW_CONFIG_BRIGHTNESS
);
@Before