Merge "Added contentDescription for fingerprint on the confirmCredential screen" into mnc-dev
diff --git a/res/layout/reset_network.xml b/res/layout/reset_network.xml
index ab96ea7..82769db 100644
--- a/res/layout/reset_network.xml
+++ b/res/layout/reset_network.xml
@@ -35,6 +35,7 @@
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:textSize="18sp"
+                android:textDirection="locale"
                 android:text="@string/reset_network_desc" />
 
         </LinearLayout>
diff --git a/src/com/android/settings/InstrumentedFragment.java b/src/com/android/settings/InstrumentedFragment.java
index a857642..453dbd0 100644
--- a/src/com/android/settings/InstrumentedFragment.java
+++ b/src/com/android/settings/InstrumentedFragment.java
@@ -27,6 +27,7 @@
     public static final int UNDECLARED = 100000;
 
     public static final int ABOUT_LEGAL_SETTINGS = UNDECLARED + 1;
+    public static final int ACTION_SEARCH_RESULTS = UNDECLARED + 2;
 
     /**
      * Declare the view of this category.
diff --git a/src/com/android/settings/ScreenPinningSettings.java b/src/com/android/settings/ScreenPinningSettings.java
index cfeddbb..bf17b9f 100644
--- a/src/com/android/settings/ScreenPinningSettings.java
+++ b/src/com/android/settings/ScreenPinningSettings.java
@@ -93,6 +93,10 @@
     private void setLockToAppEnabled(boolean isEnabled) {
         Settings.System.putInt(getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED,
                 isEnabled ? 1 : 0);
+        if (isEnabled) {
+            // Set the value to match what we have defaulted to in the UI.
+            setScreenLockUsedSetting(isScreenLockUsed());
+        }
     }
 
     private boolean isScreenLockUsed() {
@@ -115,9 +119,13 @@
                 return false;
             }
         }
+        setScreenLockUsedSetting(isEnabled);
+        return true;
+    }
+
+    private void setScreenLockUsedSetting(boolean isEnabled) {
         Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCK_TO_APP_EXIT_LOCKED,
                 isEnabled ? 1 : 0);
-        return true;
     }
 
     @Override
diff --git a/src/com/android/settings/dashboard/SearchResultsSummary.java b/src/com/android/settings/dashboard/SearchResultsSummary.java
index af7cf4a..7a83a85 100644
--- a/src/com/android/settings/dashboard/SearchResultsSummary.java
+++ b/src/com/android/settings/dashboard/SearchResultsSummary.java
@@ -83,6 +83,8 @@
         @Override
         protected void onPostExecute(Cursor cursor) {
             if (!isCancelled()) {
+                MetricsLogger.action(getContext(), InstrumentedFragment.ACTION_SEARCH_RESULTS,
+                        cursor.getCount());
                 setResultsCursor(cursor);
                 setResultsVisibility(cursor.getCount() > 0);
             } else if (cursor != null) {
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index cce1966..0ea7da9 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -23,7 +23,10 @@
 import android.app.AlertDialog;
 import android.app.AppGlobals;
 import android.app.Dialog;
+import android.app.admin.DeviceAdminInfo;
 import android.app.admin.DevicePolicyManager;
+import android.app.admin.DevicePolicyManagerInternal;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -48,6 +51,7 @@
 import android.os.UserManager;
 import android.preference.Preference;
 import android.preference.PreferenceScreen;
+import android.provider.Settings;
 import android.text.Spannable;
 import android.text.style.TextAppearanceSpan;
 import android.util.Log;
@@ -65,6 +69,7 @@
 import android.widget.Toast;
 
 import com.android.internal.logging.MetricsLogger;
+import com.android.server.LocalServices;
 import com.android.settings.LinkifyUtils;
 import com.android.settings.R;
 import com.android.settings.RestrictedSettingsFragment;
@@ -933,31 +938,58 @@
         };
 
     /**
-     * Returns true if the config is not editable/removable except by its creating Device Owner.
+     * Returns true if the config is not editable through Settings.
+     * @param context Context of caller
      * @param config The WiFi config.
-     * @return true if the config is not editable/removable except by its creating Device Owner.
+     * @return true if the config is not editable through Settings.
      */
     static boolean isEditabilityLockedDown(Context context, WifiConfiguration config) {
+        return !canModifyNetwork(context, config);
+    }
+
+    /**
+     * This method is a stripped version of WifiConfigStore.canModifyNetwork.
+     * TODO: refactor to have only one method.
+     * @param context Context of caller
+     * @param config The WiFi config.
+     * @return true if Settings can modify the config.
+     */
+    static boolean canModifyNetwork(Context context, WifiConfiguration config) {
         if (config == null) {
-            return false;
+            return true;
         }
+
         final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
                 Context.DEVICE_POLICY_SERVICE);
-        final String deviceOwnerPackageName = dpm.getDeviceOwner();
-        if (deviceOwnerPackageName == null) {
-            return false;
-        }
-        UserManager um = UserManager.get(context);
-        if (um.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI)) {
-            return false;
-        }
+
+        // Check if device has DPM capability. If it has and dpm is still null, then we
+        // treat this case with suspicion and bail out.
         final PackageManager pm = context.getPackageManager();
-        try {
-            final int deviceOwnerUid = pm.getPackageUid(deviceOwnerPackageName,
-                    UserHandle.getUserId(config.creatorUid));
-            return deviceOwnerUid == config.creatorUid;
-        } catch (NameNotFoundException e) {
+        if (pm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN) && dpm == null) {
             return false;
         }
+
+        boolean isConfigEligibleForLockdown = false;
+        if (dpm != null) {
+            final String deviceOwnerPackageName = dpm.getDeviceOwner();
+            if (deviceOwnerPackageName != null) {
+                try {
+                    final int deviceOwnerUid = pm.getPackageUid(deviceOwnerPackageName,
+                            UserHandle.USER_OWNER);
+                    isConfigEligibleForLockdown = deviceOwnerUid == config.creatorUid;
+                } catch (NameNotFoundException e) {
+                    // don't care
+                }
+            }
+        }
+        if (!isConfigEligibleForLockdown) {
+            return true;
+        }
+
+        final ContentResolver resolver = context.getContentResolver();
+        final boolean isLockdownFeatureEnabled = Settings.Global.getInt(resolver,
+                Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, 0) != 0;
+        return !isLockdownFeatureEnabled;
     }
+
 }