Merge "Adds a menu item for additional battery info to battery settings." into nyc-mr2-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 68b0e49..63fe51f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6900,6 +6900,9 @@
     <!-- Label for list to control apps that ignore battery saving restrictions [CHAR LIMIT=27]-->
     <string name="high_power_apps">Battery optimization</string>
 
+    <!-- Label for menu to launch additional battery info -->
+    <string name="additional_battery_info" translatable="false">Additional battery info</string>
+
     <!-- Filter for apps allowed to use a lot of power [CHAR LIMIT=25] -->
     <string name="high_power_filter_on">Not optimized</string>
 
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java
index 269249a..1af9df1 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java
@@ -25,6 +25,7 @@
 import android.os.Handler;
 import android.os.Message;
 import android.os.UserManager;
+import android.support.annotation.VisibleForTesting;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -39,7 +40,8 @@
 public abstract class PowerUsageBase extends SettingsPreferenceFragment {
 
     // +1 to allow ordering for PowerUsageSummary.
-    private static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
+    @VisibleForTesting
+    static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
 
     protected BatteryStatsHelper mStatsHelper;
     protected UserManager mUm;
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
new file mode 100644
index 0000000..7d63470
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2016 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;
+
+/**
+ * Feature Provider used in power usage
+ */
+public interface PowerUsageFeatureProvider {
+
+  boolean isAdditionalBatteryInfoEnabled();
+}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 443b480..5f17860 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -26,6 +26,7 @@
 import android.os.Message;
 import android.os.Process;
 import android.os.UserHandle;
+import android.support.annotation.VisibleForTesting;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceGroup;
 import android.text.TextUtils;
@@ -43,6 +44,7 @@
 import com.android.settings.SettingsActivity;
 import com.android.settings.applications.ManageApplications;
 import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.BatteryInfo;
 
 import java.util.ArrayList;
@@ -67,7 +69,9 @@
 
     private static final int MENU_STATS_TYPE = Menu.FIRST;
     private static final int MENU_HIGH_POWER_APPS = Menu.FIRST + 3;
-    private static final int MENU_HELP = Menu.FIRST + 4;
+    @VisibleForTesting
+    static final int MENU_ADDITIONAL_BATTERY_INFO = Menu.FIRST + 4;
+    private static final int MENU_HELP = Menu.FIRST + 5;
 
     private BatteryHistoryPreference mHistPref;
     private PreferenceGroup mAppListGroup;
@@ -130,12 +134,20 @@
     @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
         if (DEBUG) {
-            menu.add(0, MENU_STATS_TYPE, 0, R.string.menu_stats_total)
+            menu.add(Menu.NONE, MENU_STATS_TYPE, Menu.NONE, R.string.menu_stats_total)
                     .setIcon(com.android.internal.R.drawable.ic_menu_info_details)
                     .setAlphabeticShortcut('t');
         }
 
-        menu.add(0, MENU_HIGH_POWER_APPS, 0, R.string.high_power_apps);
+        menu.add(Menu.NONE, MENU_HIGH_POWER_APPS, Menu.NONE, R.string.high_power_apps);
+
+        PowerUsageFeatureProvider powerUsageFeatureProvider =
+                FeatureFactory.getFactory(getContext()).getPowerUsageFeatureProvider(getContext());
+        if (powerUsageFeatureProvider != null &&
+                powerUsageFeatureProvider.isAdditionalBatteryInfoEnabled()) {
+            menu.add(Menu.NONE, MENU_ADDITIONAL_BATTERY_INFO,
+                    Menu.NONE, R.string.additional_battery_info);
+        }
         super.onCreateOptionsMenu(menu, inflater);
     }
 
diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java
index 615bb12..287a661 100644
--- a/src/com/android/settings/overlay/FeatureFactory.java
+++ b/src/com/android/settings/overlay/FeatureFactory.java
@@ -21,6 +21,7 @@
 import android.util.Log;
 
 import com.android.settings.R;
+import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
 
 /**
  * Abstract class for creating feature controllers. Allows OEM implementations to define their own
@@ -61,6 +62,8 @@
 
     public abstract SupportFeatureProvider getSupportFeatureProvider(Context context);
 
+    public abstract PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context);
+
     public abstract SurveyFeatureProvider getSurveyFeatureProvider(Context context);
 
     public static final class FactoryNotFoundException extends RuntimeException {
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index 9152331..0abd865 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.support.annotation.Keep;
+import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
 
 /**
  * {@link FeatureFactory} implementation for AOSP Settings.
@@ -31,6 +32,11 @@
     }
 
     @Override
+    public PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context) {
+        return null;
+    }
+
+    @Override
     public SurveyFeatureProvider getSurveyFeatureProvider(Context context) {
         return null;
     }