Merge "Make Settings dashboard items focusable." into nyc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f6c7957..a8e2ab4 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2716,6 +2716,7 @@
         <activity android:name="Settings$SimSettingsActivity"
                 android:label="@string/sim_settings_title"
                 android:icon="@drawable/ic_settings_sim"
+                android:enabled="false"
                 android:taskAffinity="">
             <intent-filter android:priority="1">
                 <action android:name="com.android.settings.sim.SIM_SUB_INFO_SETTINGS" />
@@ -2914,5 +2915,27 @@
             </intent-filter>
        </receiver>
 
+        <!-- Quick Settings tiles for Developer Options -->
+        <service
+                android:name=".qstile.DevelopmentTiles$ShowLayout"
+                android:label="@string/debug_layout"
+                android:icon="@drawable/tile_icon_show_layout"
+                android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
+                android:enabled="false">
+            <intent-filter>
+                <action android:name="android.service.quicksettings.action.QS_TILE" />
+            </intent-filter>
+        </service>
+        <service
+                android:name=".qstile.DevelopmentTiles$GPUProfiling"
+                android:label="@string/track_frame_time"
+                android:icon="@drawable/tile_icon_graphics"
+                android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
+                android:enabled="false">
+            <intent-filter>
+                <action android:name="android.service.quicksettings.action.QS_TILE" />
+            </intent-filter>
+        </service>
+        <!-- This is the longest AndroidManifest.xml ever. -->
     </application>
 </manifest>
diff --git a/res/drawable/tile_icon_graphics.xml b/res/drawable/tile_icon_graphics.xml
new file mode 100644
index 0000000..84a0a5a
--- /dev/null
+++ b/res/drawable/tile_icon_graphics.xml
@@ -0,0 +1,52 @@
+<!--
+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.
+-->
+<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="#FFFFFFFF"
+        android:pathData="M23,1v22H1V1H23 M24,0H0v24h24V0L24,0z"/>
+    <path
+        android:strokeColor="#FFFFFFFF"
+        android:strokeWidth="0.667"
+        android:pathData="M5,19L1,23"/>
+    <path
+        android:strokeColor="#FFFFFFFF"
+        android:strokeWidth="0.667"
+        android:pathData="M1,1L5,5"/>
+    <path
+        android:strokeColor="#FFFFFFFF"
+        android:strokeWidth="0.667"
+        android:pathData="M19,5L23,1"/>
+    <path
+        android:strokeColor="#FFFFFFFF"
+        android:strokeWidth="0.667"
+        android:pathData="M19,19L23,23"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M14,3.8l-4,0l-0.2,-0.8l4.4,0z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M18.8,5.2v13.5H5.2V5.2H18.8 M19.5,4.5h-15v15h15V4.5L19.5,4.5z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M6.5,9.5h5v11h-5z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M12.5,16.5h5v5h-5z"/>
+</vector>
diff --git a/res/drawable/tile_icon_show_layout.xml b/res/drawable/tile_icon_show_layout.xml
new file mode 100644
index 0000000..b9b825e
--- /dev/null
+++ b/res/drawable/tile_icon_show_layout.xml
@@ -0,0 +1,60 @@
+<!--
+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.
+-->
+<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="#FFFFFFFF"
+        android:pathData="M12,7.2c-3.2,0 -5.9,2 -7,4.8c1.1,2.8 3.8,4.8 7,4.8s5.9,-2 7,-4.8C17.9,9.2 15.2,7.2 12,7.2zM12,15.2c-1.8,0 -3.2,-1.4 -3.2,-3.2s1.4,-3.2 3.2,-3.2s3.2,1.4 3.2,3.2S13.8,15.2 12,15.2zM12,10.1c-1.1,0 -1.9,0.9 -1.9,1.9s0.9,1.9 1.9,1.9s1.9,-0.9 1.9,-1.9S13.1,10.1 12,10.1z"/>
+    <path
+        android:fillColor="#80FFFFFF"
+        android:pathData="M0.0,6.0h1.0v12.0h-1.0z"/>
+    <path
+        android:fillColor="#80FFFFFF"
+        android:pathData="M6.0,0.0h12.0v1.0h-12.0z"/>
+    <path
+        android:fillColor="#80FFFFFF"
+        android:pathData="M23.0,6.0h1.0v12.0h-1.0z"/>
+    <path
+        android:fillColor="#80FFFFFF"
+        android:pathData="M6.0,23.0h12.0v1.0h-12.0z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M1.0,23.0l0.0,-5.0l-1.0,0.0l0.0,6.0l6.0,0.0l0.0,-1.0z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M1.0,1.0l5.0,0.0l0.0,-1.0l-6.0,0.0l0.0,6.0l1.0,0.0z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M18.0,0.0l0.0,1.0l5.0,0.0l0.0,5.0l1.0,0.0l0.0,-6.0z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M23.0,23.0l-5.0,0.0l0.0,1.0l6.0,0.0l0.0,-6.0l-1.0,0.0z"/>
+    <path
+        android:fillColor="#80FFFFFF"
+        android:pathData="M9.5,6.0h5.0v1.0h-5.0z"/>
+    <path
+        android:fillColor="#80FFFFFF"
+        android:pathData="M9.5,17.0h5.0v1.0h-5.0z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M4.5,7.0l5.0,0.0l0.0,-1.0l-6.0,0.0l0.0,6.0l0.0,6.0l6.0,0.0l0.0,-1.0l-5.0,0.0l0.0,-5.0z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M14.5,6.0l0.0,1.0l5.0,0.0l0.0,5.0l0.0,5.0l-5.0,0.0l0.0,1.0l6.0,0.0l0.0,-6.0l0.0,-6.0z"/>
+</vector>
diff --git a/res/values-night/colors.xml b/res/values-night/colors.xml
deleted file mode 100644
index dba17bd..0000000
--- a/res/values-night/colors.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
-    <color name="card_background">#ff424242</color>
-    <color name="lock_pattern_view_regular_color">@*android:color/secondary_text_default_material_dark</color>
-
-</resources>
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index 5036b9f..760e2b8 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -2078,7 +2078,7 @@
         }
     };
 
-    static class SystemPropPoker extends AsyncTask<Void, Void, Void> {
+    public static class SystemPropPoker extends AsyncTask<Void, Void, Void> {
         @Override
         protected Void doInBackground(Void... params) {
             String[] services = ServiceManager.listServices();
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 616fe39..45a1294 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -104,6 +104,7 @@
 import com.android.settings.notification.ZenModeVisualInterruptionSettings;
 import com.android.settings.print.PrintJobSettingsFragment;
 import com.android.settings.print.PrintSettingsFragment;
+import com.android.settings.qstile.DevelopmentTiles;
 import com.android.settings.search.DynamicIndexableContentMonitor;
 import com.android.settings.search.Index;
 import com.android.settings.sim.SimSettings;
@@ -1067,12 +1068,14 @@
                 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
 
         final boolean showDev = mDevelopmentPreferences.getBoolean(
-                DevelopmentSettings.PREF_SHOW,
-                android.os.Build.TYPE.equals("eng"));
+                    DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
+                && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
         setTileEnabled(new ComponentName(packageName,
                         Settings.DevelopmentSettingsActivity.class.getName()),
-                showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
-                isAdmin, pm);
+                showDev, isAdmin, pm);
+
+        // Reveal development-only quick settings tiles
+        DevelopmentTiles.setTilesEnabled(this, showDev);
 
         if (UserHandle.MU_ENABLED && !isAdmin) {
             // When on restricted users, disable all extra categories (but only the settings ones).
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 5113dc6..b8270e1 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -80,21 +80,23 @@
         mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK);
         mSilent = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_SILENT);
 
-        mAppRow = mBackend.loadAppRow(mContext, mPm, mPkgInfo);
+        if (mPkgInfo != null) {
+            mAppRow = mBackend.loadAppRow(mContext, mPm, mPkgInfo);
 
-        NotificationManager.Policy policy =
-                NotificationManager.from(mContext).getNotificationPolicy();
-        mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
+            NotificationManager.Policy policy =
+                    NotificationManager.from(mContext).getNotificationPolicy();
+            mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
 
-        // load settings intent
-        ArrayMap<String, AppRow> rows = new ArrayMap<String, AppRow>();
-        rows.put(mAppRow.pkg, mAppRow);
-        collectConfigActivities(rows);
+            // load settings intent
+            ArrayMap<String, AppRow> rows = new ArrayMap<String, AppRow>();
+            rows.put(mAppRow.pkg, mAppRow);
+            collectConfigActivities(rows);
 
-        setupImportancePrefs(mAppRow.systemApp, mAppRow.appImportance, mAppRow.banned);
-        setupPriorityPref(mAppRow.appBypassDnd);
-        setupVisOverridePref(mAppRow.appVisOverride);
-        updateDependents(mAppRow.appImportance);
+            setupImportancePrefs(mAppRow.systemApp, mAppRow.appImportance, mAppRow.banned);
+            setupPriorityPref(mAppRow.appBypassDnd);
+            setupVisOverridePref(mAppRow.appVisOverride);
+            updateDependents(mAppRow.appImportance);
+        }
     }
 
     @Override
diff --git a/src/com/android/settings/notification/ImportanceSeekBarPreference.java b/src/com/android/settings/notification/ImportanceSeekBarPreference.java
index 46f9b3f..cca70b4 100644
--- a/src/com/android/settings/notification/ImportanceSeekBarPreference.java
+++ b/src/com/android/settings/notification/ImportanceSeekBarPreference.java
@@ -124,12 +124,13 @@
     private void applyAutoUi(ImageView autoButton) {
         mSeekBar.setEnabled(!mAutoOn);
 
-        final ColorStateList tint = mAutoOn ? mInactiveSliderTint : mActiveSliderTint;
+        final ColorStateList sliderTint = mAutoOn ? mInactiveSliderTint : mActiveSliderTint;
+        final ColorStateList starTint = mAutoOn ?  mActiveSliderTint : mInactiveSliderTint;
         Drawable icon = autoButton.getDrawable().mutate();
-        icon.setTintList(tint);
+        icon.setTintList(starTint);
         autoButton.setImageDrawable(icon);
-        mSeekBar.setProgressTintList(tint);
-        mSeekBar.setThumbTintList(tint);
+        mSeekBar.setProgressTintList(sliderTint);
+        mSeekBar.setThumbTintList(sliderTint);
 
         if (mAutoOn) {
             mSummary = getProgressSummary(
diff --git a/src/com/android/settings/qstile/DevelopmentTiles.java b/src/com/android/settings/qstile/DevelopmentTiles.java
new file mode 100644
index 0000000..0d8e7db
--- /dev/null
+++ b/src/com/android/settings/qstile/DevelopmentTiles.java
@@ -0,0 +1,95 @@
+/*
+ * 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.qstile;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.SystemProperties;
+import android.service.quicksettings.Tile;
+import android.service.quicksettings.TileService;
+import android.view.ThreadedRenderer;
+import android.view.View;
+import com.android.settings.DevelopmentSettings;
+
+public class DevelopmentTiles {
+    // List of components that need to be enabled when developer tools are turned on
+    static final Class[] TILE_CLASSES = new Class[] {
+            ShowLayout.class,
+            GPUProfiling.class,
+    };
+    public static void setTilesEnabled(Context context, boolean enable) {
+        final PackageManager pm = context.getPackageManager();
+        for (Class cls : TILE_CLASSES) {
+            pm.setComponentEnabledSetting(new ComponentName(context, cls),
+                    enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
+                           : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
+                    PackageManager.DONT_KILL_APP);
+        }
+    }
+
+    /**
+     * Tile to control the "Show layout bounds" developer setting
+     */
+    public static class ShowLayout extends TileService {
+        @Override
+        public void onStartListening() {
+            super.onStartListening();
+            refresh();
+        }
+
+        public void refresh() {
+            final boolean enabled = SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false);
+            getQsTile().setState(enabled ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
+            getQsTile().updateTile();
+        }
+
+        @Override
+        public void onClick() {
+            SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
+                    getQsTile().getState() == Tile.STATE_INACTIVE ? "true" : "false");
+            new DevelopmentSettings.SystemPropPoker().execute(); // Settings app magic
+            refresh();
+        }
+    }
+
+    /**
+     * Tile to control the "GPU profiling" developer setting
+     */
+    public static class GPUProfiling extends TileService {
+        @Override
+        public void onStartListening() {
+            super.onStartListening();
+            refresh();
+        }
+
+        public void refresh() {
+            final String value = SystemProperties.get(ThreadedRenderer.PROFILE_PROPERTY);
+            getQsTile().setState(value.equals("visual_bars")
+                    ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
+            getQsTile().updateTile();
+        }
+
+        @Override
+        public void onClick() {
+            SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY,
+                    getQsTile().getState() == Tile.STATE_INACTIVE ? "visual_bars" : "");
+            new DevelopmentSettings.SystemPropPoker().execute(); // Settings app magic
+            refresh();
+        }
+    }
+}
\ No newline at end of file