Merge "Import translations. DO NOT MERGE"
diff --git a/res/layout/apn_disallowed_preference_screen.xml b/res/layout/apn_disallowed_preference_screen.xml
index 25f6f37..6ac8137 100644
--- a/res/layout/apn_disallowed_preference_screen.xml
+++ b/res/layout/apn_disallowed_preference_screen.xml
@@ -30,7 +30,7 @@
                 android:cacheColorHint="@android:color/white"
                 android:fadingEdgeLength="16dip" />
 
-        <TextView android:id="@+android:id/empty"
+        <TextView android:id="@android:id/empty"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:gravity="center"
diff --git a/res/layout/credentials_disallowed_preference_screen.xml b/res/layout/credentials_disallowed_preference_screen.xml
new file mode 100644
index 0000000..c4e8934
--- /dev/null
+++ b/res/layout/credentials_disallowed_preference_screen.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright (C) 2014 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.
+ */
+-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+             android:id="@+id/listContainer"
+             android:layout_width="match_parent"
+             android:layout_height="match_parent">
+
+        <ListView android:id="@android:id/list"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:drawSelectorOnTop="false"
+                android:scrollbarStyle="insideOverlay"
+                android:background="@android:color/white"
+                android:cacheColorHint="@android:color/white"
+                android:fadingEdgeLength="16dip" />
+
+        <TextView android:id="@android:id/empty"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:gravity="center"
+                android:text="@string/credentials_settings_not_available"
+                android:textAppearance="?android:attr/textAppearanceMedium" />
+</FrameLayout>
\ No newline at end of file
diff --git a/res/layout/dream_info_row.xml b/res/layout/dream_info_row.xml
index e8dd824..7ed26cb 100644
--- a/res/layout/dream_info_row.xml
+++ b/res/layout/dream_info_row.xml
@@ -15,7 +15,9 @@
 -->
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content" >
+    android:layout_height="wrap_content"
+    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
 
     <!-- Dream selectable row (icon, caption, radio button) -->
 
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 7118865..0708163 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -895,6 +895,33 @@
         <item>Use ART debug build</item>
     </string-array>
 
+    <!-- Titles for logd limit size selection preference. [CHAR LIMIT=14] -->
+    <string-array name="select_logd_size_titles">
+        <item>64K</item>
+        <item>256K</item>
+        <item>1M</item>
+        <item>4M</item>
+        <item>16M</item>
+    </string-array>
+
+    <!-- Values for logd limit size selection preference. -->
+    <string-array name="select_logd_size_values" translatable="false" >
+        <item>65536</item>
+        <item>262144</item>
+        <item>1048576</item>
+        <item>4194304</item>
+        <item>16777216</item>
+    </string-array>
+
+    <!-- Summaries for logd limit size selection preference. [CHAR LIMIT=19]-->
+    <string-array name="select_logd_size_summaries" >
+        <item>64K per log buffer</item>
+        <item>256K per log buffer</item>
+        <item>1M per log buffer</item>
+        <item>4M per log buffer</item>
+        <item>16M per log buffer</item>
+    </string-array>
+
     <!-- Titles for HDCP checking preference. [CHAR LIMIT=35] -->
     <string-array name="hdcp_checking_titles">
         <item>Never check</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e50f8e9..a49e118 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -797,6 +797,10 @@
     <!-- Informational text on the progress screen while encrypting the device -->
     <string name="crypt_keeper_setup_description" product="default">Wait while your phone
     is being encrypted. <xliff:g id="percent" example="50">^1</xliff:g>% complete.</string>
+    <string name="crypt_keeper_setup_time_remaining" product="tablet">Wait while your tablet
+    is being encrypted. Time remaining: <xliff:g id="duration" example="1:23">^1</xliff:g></string>
+    <string name="crypt_keeper_setup_time_remaining" product="default">Wait while your phone
+    is being encrypted. Time remaining: <xliff:g id="duration" example="1:23">^1</xliff:g></string>
 
     <!-- Informational text on the password entry screen when password entry fails-->
     <string name="crypt_keeper_cooldown">Try again in <xliff:g id="delay" example="15">^1</xliff:g> seconds.</string>
@@ -3171,6 +3175,10 @@
     <string name="wifi_display_certification_summary">Show options for wireless display certification</string>
     <!-- Setting Checkbox title whether to enable Wifi verbose Logging [CHAR LIMIT=80] -->
     <string name="wifi_verbose_logging_summary">Increase Wifi logging level, show per SSID RSSI in WiFi Picker</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=34] -->
+    <string name="select_logd_size_dialog_title">Select Logger sizes per log buffer</string>
     <!-- Setting Checkbox title whether to allow mock locations -->
     <string name="allow_mock_location">Allow mock locations</string>
     <!-- setting Checkbox summary whether to allow mock locations  -->
@@ -4019,6 +4027,8 @@
     <string name="credential_storage_type_hardware">Hardware-backed</string>
     <!-- Summary text for preference showing what type of credential storage this device has when it is stored in software only (as opposed to "hardware-backed") [CHAR LIMIT=NONE] -->
     <string name="credential_storage_type_software">Software only</string>
+    <!-- Error message for users that aren't allowed to see or modify credentials [CHAR LIMIT=none] -->
+    <string name="credentials_settings_not_available">Credentials are not available for this user</string>
 
     <!-- Message to draw an unlock pattern when installing credentials -->
     <string name="credentials_install_gesture_prompt">Draw your unlock pattern</string>
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index d435371..f0b17f9 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -111,6 +111,13 @@
             android:title="@string/wifi_verbose_logging" />
             android:summary="@string/wifi_verbose_logging_summary"/>
 
+        <ListPreference
+            android:key="select_logd_size"
+            android:title="@string/select_logd_size_title"
+            android:dialogTitle="@string/select_logd_size_dialog_title"
+            android:entries="@array/select_logd_size_titles"
+            android:entryValues="@array/select_logd_size_values" />
+
     </PreferenceCategory>
 
     <PreferenceCategory android:key="debug_input_category"
diff --git a/src/com/android/settings/CredentialStorage.java b/src/com/android/settings/CredentialStorage.java
index 44e966c..f515b36 100644
--- a/src/com/android/settings/CredentialStorage.java
+++ b/src/com/android/settings/CredentialStorage.java
@@ -19,6 +19,7 @@
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.admin.DevicePolicyManager;
+import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.res.Resources;
@@ -26,6 +27,7 @@
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.os.Process;
+import android.os.UserManager;
 import android.security.Credentials;
 import android.security.KeyChain.KeyChainConnection;
 import android.security.KeyChain;
@@ -38,8 +40,8 @@
 import android.widget.Button;
 import android.widget.TextView;
 import android.widget.Toast;
-import com.android.internal.widget.LockPatternUtils;
 
+import com.android.internal.widget.LockPatternUtils;
 import com.android.org.bouncycastle.asn1.ASN1InputStream;
 import com.android.org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
 
@@ -119,16 +121,20 @@
 
         Intent intent = getIntent();
         String action = intent.getAction();
-
-        if (ACTION_RESET.equals(action)) {
-            new ResetDialog();
-        } else {
-            if (ACTION_INSTALL.equals(action)
-                    && "com.android.certinstaller".equals(getCallingPackage())) {
-                mInstallBundle = intent.getExtras();
+        UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
+        if (!userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) {
+            if (ACTION_RESET.equals(action)) {
+                new ResetDialog();
+            } else {
+                if (ACTION_INSTALL.equals(action)
+                        && "com.android.certinstaller".equals(getCallingPackage())) {
+                    mInstallBundle = intent.getExtras();
+                }
+                // ACTION_UNLOCK also handled here in addition to ACTION_INSTALL
+                handleUnlockOrInstall();
             }
-            // ACTION_UNLOCK also handled here in addition to ACTION_INSTALL
-            handleUnlockOrInstall();
+        } else {
+            finish();
         }
     }
 
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java
index d24c741..4e20823 100644
--- a/src/com/android/settings/CryptKeeper.java
+++ b/src/com/android/settings/CryptKeeper.java
@@ -40,6 +40,7 @@
 import android.text.Editable;
 import android.text.TextUtils;
 import android.text.TextWatcher;
+import android.text.format.DateUtils;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
@@ -508,23 +509,40 @@
             return;
         }
 
-        int progress = 0;
+        // Get status as percentage first
+        CharSequence status = getText(R.string.crypt_keeper_setup_description);
+        int percent = 0;
         try {
             // Force a 50% progress state when debugging the view.
-            progress = isDebugView() ? 50 : Integer.parseInt(state);
+            percent = isDebugView() ? 50 : Integer.parseInt(state);
         } catch (Exception e) {
             Log.w(TAG, "Error parsing progress: " + e.toString());
         }
+        String progress = Integer.toString(percent);
 
-        final CharSequence status = getText(R.string.crypt_keeper_setup_description);
+        // Now try to get status as time remaining and replace as appropriate
         Log.v(TAG, "Encryption progress: " + progress);
+        try {
+            final String timeProperty = SystemProperties.get("vold.encrypt_time_remaining");
+            int time = Integer.parseInt(timeProperty);
+            if (time >= 0) {
+                // Round up to multiple of 10 - this way display is less jerky
+                time = (time + 9) / 10 * 10;
+                progress = DateUtils.formatElapsedTime(time);
+                status = getText(R.string.crypt_keeper_setup_time_remaining);
+            }
+        } catch (Exception e) {
+            // Will happen if no time etc - show percentage
+        }
+
         final TextView tv = (TextView) findViewById(R.id.status);
         if (tv != null) {
-            tv.setText(TextUtils.expandTemplate(status, Integer.toString(progress)));
+            tv.setText(TextUtils.expandTemplate(status, progress));
         }
-        // Check the progress every 5 seconds
+
+        // Check the progress every 1 seconds
         mHandler.removeMessages(MESSAGE_UPDATE_PROGRESS);
-        mHandler.sendEmptyMessageDelayed(MESSAGE_UPDATE_PROGRESS, 5000);
+        mHandler.sendEmptyMessageDelayed(MESSAGE_UPDATE_PROGRESS, 1000);
     }
 
     /** Disable password input for a while to force the user to waste time between retries */
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index 6d1cadc..02045ab 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -139,6 +139,9 @@
     private static final String DEBUG_APPLICATIONS_CATEGORY_KEY = "debug_applications_category";
     private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification";
     private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging";
+    private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size";
+    private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
+    private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size";
 
     private static final String OPENGL_TRACES_KEY = "enable_opengl_traces";
 
@@ -201,6 +204,7 @@
     private CheckBoxPreference mDebugLayout;
     private CheckBoxPreference mForceRtlLayout;
     private ListPreference mDebugHwOverdraw;
+    private ListPreference mLogdSize;
     private ListPreference mTrackFrameTime;
     private ListPreference mShowNonRectClip;
     private ListPreference mWindowAnimationScale;
@@ -316,6 +320,8 @@
         mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY);
         mWifiDisplayCertification = findAndInitCheckboxPref(WIFI_DISPLAY_CERTIFICATION_KEY);
         mWifiVerboseLogging = findAndInitCheckboxPref(WIFI_VERBOSE_LOGGING_KEY);
+        mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
+
         mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY);
         mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY);
         mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY);
@@ -520,6 +526,7 @@
         updateVerifyAppsOverUsbOptions();
         updateBugreportOptions();
         updateForceRtlOptions();
+        updateLogdSizeValues();
         updateWifiDisplayCertificationOptions();
         updateWifiVerboseLoggingOptions();
         updateSimulateColorSpace();
@@ -536,6 +543,7 @@
             }
         }
         resetDebuggerOptions();
+        writeLogdSizeOption(null);
         writeAnimationScaleOption(0, mWindowAnimationScale, null);
         writeAnimationScaleOption(1, mTransitionAnimationScale, null);
         writeAnimationScaleOption(2, mAnimatorDurationScale, null);
@@ -1037,6 +1045,43 @@
         mWifiManager.enableVerboseLogging(mWifiVerboseLogging.isChecked() ? 1 : 0);
     }
 
+    private void updateLogdSizeValues() {
+        if (mLogdSize != null) {
+            String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY);
+            if (currentValue == null) {
+                currentValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY);
+                if (currentValue == null) {
+                    currentValue = "256K";
+                }
+            }
+            String[] values = getResources().getStringArray(R.array.select_logd_size_values);
+            String[] titles = getResources().getStringArray(R.array.select_logd_size_titles);
+            String[] summaries = getResources().getStringArray(R.array.select_logd_size_summaries);
+            int index = 1; // punt to second entry if not found
+            for (int i = 0; i < values.length; i++) {
+                if (currentValue.equals(values[i])
+                        || currentValue.equals(titles[i])) {
+                    index = i;
+                    break;
+                }
+            }
+            mLogdSize.setValue(values[index]);
+            mLogdSize.setSummary(summaries[index]);
+            mLogdSize.setOnPreferenceChangeListener(this);
+        }
+    }
+
+    private void writeLogdSizeOption(Object newValue) {
+        SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, newValue.toString());
+        pokeSystemProperties();
+        try {
+            Process p = Runtime.getRuntime().exec("logcat -b all -G " + newValue.toString());
+            int status = p.waitFor();
+        } catch (Exception e) {
+        }
+        updateLogdSizeValues();
+    }
+
     private void updateCpuUsageOptions() {
         updateCheckBox(mShowCpuUsage, Settings.Global.getInt(getActivity().getContentResolver(),
                 Settings.Global.SHOW_PROCESSES, 0) != 0);
@@ -1383,6 +1428,9 @@
             updateHdcpValues();
             pokeSystemProperties();
             return true;
+        } else if (preference == mLogdSize) {
+            writeLogdSizeOption(newValue);
+            return true;
         } else if (preference == mWindowAnimationScale) {
             writeAnimationScaleOption(0, mWindowAnimationScale, newValue);
             return true;
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 5091eea..60a086a 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -58,7 +58,7 @@
 /**
  * Gesture lock pattern settings.
  */
-public class SecuritySettings extends RestrictedSettingsFragment
+public class SecuritySettings extends SettingsPreferenceFragment
         implements OnPreferenceChangeListener, DialogInterface.OnClickListener, Indexable {
     static final String TAG = "SecuritySettings";
     private static final Intent TRUST_AGENT_INTENT =
@@ -115,10 +115,6 @@
 
     private boolean mIsPrimary;
 
-    public SecuritySettings() {
-        super(null /* Don't ask for restrictions pin on creation. */);
-    }
-
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -274,6 +270,7 @@
 
         } else {
             removePreference(KEY_CREDENTIALS_MANAGER);
+            removePreference(KEY_CREDENTIALS_INSTALL);
         }
 
         // Application install
@@ -282,9 +279,12 @@
         mToggleAppInstallation = (CheckBoxPreference) findPreference(
                 KEY_TOGGLE_INSTALL_APPLICATIONS);
         mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
-
         // Side loading of apps.
         mToggleAppInstallation.setEnabled(mIsPrimary);
+        if (um.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES)
+                || um.hasUserRestriction(UserManager.DISALLOW_INSTALL_APPS)) {
+            mToggleAppInstallation.setEnabled(false);
+        }
 
         // Package verification, only visible to primary user and if enabled
         mToggleVerifyApps = (CheckBoxPreference) findPreference(KEY_TOGGLE_VERIFY_APPLICATIONS);
@@ -302,12 +302,8 @@
                 mToggleVerifyApps.setEnabled(false);
             }
         }
-
-        if (shouldBePinProtected(RESTRICTIONS_PIN_SET)) {
-            protectByRestrictions(mToggleAppInstallation);
-            protectByRestrictions(mToggleVerifyApps);
-            protectByRestrictions(mResetCredentials);
-            protectByRestrictions(root.findPreference(KEY_CREDENTIALS_INSTALL));
+        if (um.hasUserRestriction(UserManager.ENSURE_VERIFY_APPS)) {
+            mToggleVerifyApps.setEnabled(false);
         }
 
         // Trust Agent preferences
@@ -504,9 +500,6 @@
 
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
-        if (ensurePinRestrictedPreference(preference)) {
-            return true;
-        }
         final String key = preference.getKey();
 
         final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
diff --git a/src/com/android/settings/TrustedCredentialsSettings.java b/src/com/android/settings/TrustedCredentialsSettings.java
index 65d0934..eb7b142 100644
--- a/src/com/android/settings/TrustedCredentialsSettings.java
+++ b/src/com/android/settings/TrustedCredentialsSettings.java
@@ -47,6 +47,7 @@
 import android.widget.Spinner;
 import android.widget.TabHost;
 import android.widget.TextView;
+
 import java.security.cert.CertificateEncodingException;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
@@ -170,6 +171,10 @@
 
     @Override public View onCreateView(
             LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
+        if (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) {
+            return inflater.inflate(R.layout.credentials_disallowed_preference_screen,
+                    parent, false);
+        }
         mTabHost = (TabHost) inflater.inflate(R.layout.trusted_credentials, parent, false);
         mTabHost.setup();
         addTab(Tab.SYSTEM);
diff --git a/src/com/android/settings/dashboard/SearchResultsSummary.java b/src/com/android/settings/dashboard/SearchResultsSummary.java
index 6981634..5f23671 100644
--- a/src/com/android/settings/dashboard/SearchResultsSummary.java
+++ b/src/com/android/settings/dashboard/SearchResultsSummary.java
@@ -216,6 +216,11 @@
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 // We have a header, so we need to decrement the position by one
                 position--;
+                // Some Monkeys could create a case where they were probably clicking on the
+                // List Header and thus the position passed was "0" and then by decrement was "-1"
+                if (position < 0) {
+                    return;
+                }
                 final Cursor cursor = mSuggestionsAdapter.mCursor;
                 cursor.moveToPosition(position);