Merge "Import translations. DO NOT MERGE" into mnc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 2bba142..6fd534c 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -76,6 +76,7 @@
     <uses-permission android:name="android.permission.USE_FINGERPRINT" />
     <uses-permission android:name="android.permission.MANAGE_FINGERPRINT" />
     <uses-permission android:name="android.permission.USER_ACTIVITY" />
+    <uses-permission android:name="android.permission.CHANGE_APP_IDLE_STATE" />
 
     <application android:label="@string/settings_label"
             android:icon="@mipmap/ic_launcher_settings"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2376761..6e8fba4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3537,7 +3537,6 @@
     <!-- Warning dialog message to confirm user wishes to enable OEM unlock and disable theft protection features -->
     <string name="confirm_enable_oem_unlock_text">WARNING: Device protection features will not work on this device while this setting is turned on.</string>
 
-
     <!-- UI debug setting: limit size of Android logger buffers -->
     <string name="select_logd_size_title">Logger buffer sizes</string>
     <!-- UI debug setting: limit size of Android logger buffers [CHAR LIMIT=59] -->
@@ -6628,4 +6627,11 @@
          usb_use_file_transfer, use_use_photo_transfer, and usb_use_MIDI -->
     <string name="usb_use">Use USB for</string>
 
+    <!-- Settings item title for inactive apps [CHAR LIMIT=35] -->
+    <string name="inactive_apps_title">Inactive apps</string>
+    <!-- Settings item summary for inactive app [CHAR LIMIT=100] -->
+    <string name="inactive_app_inactive_summary">Inactive. Touch to toggle.</string>
+    <!-- Settings item summary for active app [CHAR LIMIT=100] -->
+    <string name="inactive_app_active_summary">Active. Touch to toggle.</string>
+
 </resources>
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 32c96c1..a9ca053 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -341,6 +341,10 @@
             android:title="@string/show_all_anrs"
             android:summary="@string/show_all_anrs_summary"/>
 
+        <Preference
+                android:key="inactive_apps"
+                android:title="@string/inactive_apps_title" />
+
      </PreferenceCategory>
 
 </PreferenceScreen>
diff --git a/res/xml/inactive_apps.xml b/res/xml/inactive_apps.xml
new file mode 100644
index 0000000..27fda55
--- /dev/null
+++ b/res/xml/inactive_apps.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+</PreferenceScreen>
+
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index a647dcc..dbbf6ba 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -73,8 +73,10 @@
 import android.widget.TextView;
 
 import com.android.internal.logging.MetricsLogger;
+import com.android.settings.fuelgauge.InactiveApps;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
+import com.android.settings.users.UserDetailsSettings;
 import com.android.settings.widget.SwitchBar;
 
 import java.lang.Process;
@@ -165,6 +167,8 @@
     private static final String WIFI_LEGACY_DHCP_CLIENT_KEY = "legacy_dhcp_client";
     private static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on";
 
+    private static final String INACTIVE_APPS_KEY = "inactive_apps";
+
     private static final String OPENGL_TRACES_KEY = "enable_opengl_traces";
 
     private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY
@@ -1728,6 +1732,8 @@
             writeUseAwesomePlayerOptions();
         } else if (preference == mUSBAudio) {
             writeUSBAudioOptions();
+        } else if (INACTIVE_APPS_KEY.equals(preference.getKey())) {
+            startInactiveAppsFragment();
         } else {
             return super.onPreferenceTreeClick(preferenceScreen, preference);
         }
@@ -1735,6 +1741,12 @@
         return false;
     }
 
+    private void startInactiveAppsFragment() {
+        ((SettingsActivity) getActivity()).startPreferencePanel(
+                InactiveApps.class.getName(),
+                null, R.string.inactive_apps_title, null, null, 0);
+    }
+
     private boolean showKeyguardConfirmation(Resources resources, int requestCode) {
         return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
                 requestCode, resources.getString(R.string.oem_unlock_enable));
diff --git a/src/com/android/settings/fuelgauge/InactiveApps.java b/src/com/android/settings/fuelgauge/InactiveApps.java
new file mode 100644
index 0000000..58fc39c
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/InactiveApps.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2015 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;
+
+import android.app.usage.UsageStatsManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceGroup;
+
+import com.android.settings.InstrumentedFragment;
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+import java.util.List;
+
+public class InactiveApps extends SettingsPreferenceFragment implements OnPreferenceClickListener {
+
+    private UsageStatsManager mUsageStats;
+
+    @Override
+    protected int getMetricsCategory() {
+        return InstrumentedFragment.VIEW_CATEGORY_UNDECLARED;
+    }
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+
+        mUsageStats = getActivity().getSystemService(UsageStatsManager.class);
+        addPreferencesFromResource(R.xml.inactive_apps);
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        init();
+    }
+
+    private void init() {
+        PreferenceGroup screen = getPreferenceScreen();
+        screen.removeAll();
+        screen.setOrderingAsAdded(false);
+        final Context context = getActivity();
+        final PackageManager pm = context.getPackageManager();
+        final UsageStatsManager usm = context.getSystemService(UsageStatsManager.class);
+
+        Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
+        launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+        List<ResolveInfo> apps = pm.queryIntentActivities(launcherIntent, 0);
+        for (ResolveInfo app : apps) {
+            String packageName = app.activityInfo.applicationInfo.packageName;
+            Preference p = new Preference(context);
+            p.setTitle(app.loadLabel(pm));
+            p.setIcon(app.loadIcon(pm));
+            p.setKey(packageName);
+            updateSummary(p);
+            p.setOnPreferenceClickListener(this);
+
+            screen.addPreference(p);
+        }
+    }
+
+    private void updateSummary(Preference p) {
+        boolean inactive = mUsageStats.isAppInactive(p.getKey());
+        p.setSummary(inactive
+                ? R.string.inactive_app_inactive_summary
+                : R.string.inactive_app_active_summary);
+    }
+
+    @Override
+    public boolean onPreferenceClick(Preference preference) {
+        String packageName = preference.getKey();
+        mUsageStats.setAppInactive(packageName, !mUsageStats.isAppInactive(packageName));
+        updateSummary(preference);
+        return false;
+    }
+}