Merge "Added new setting for gestures." into nyc-mr1-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 971ec82..a5142e6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5335,13 +5335,13 @@
     </plurals>
     <!-- Text of message to show to device owner user whose administrator has installed a SSL CA Cert.  [CHAR LIMIT=NONE] -->
     <plurals name="ssl_ca_cert_info_message_device_owner">
-        <item quantity="one"><xliff:g id="managing_domain">%s</xliff:g> has installed a certificate authority on your device, which may allow them to monitor your device network activity, including emails, apps, and secure websites. You can choose to either trust or remove this certificate.\n\nFor more information about this certificate, contact your admin.</item>
-        <item quantity="other"><xliff:g id="managing_domain">%s</xliff:g> has installed certificate authorities on your device, which may allow them to monitor your device network activity, including emails, apps, and secure websites. You can choose to either trust or remove these certificates.\n\nFor more information about these certificates, contact your admin.</item>
+        <item quantity="one"><xliff:g id="managing_domain">%s</xliff:g> has installed a certificate authority on your device, which may allow them to monitor your device network activity, including emails, apps, and secure websites.\n\nFor more information about this certificate, contact your admin.</item>
+        <item quantity="other"><xliff:g id="managing_domain">%s</xliff:g> has installed certificate authorities on your device, which may allow them to monitor your device network activity, including emails, apps, and secure websites.\n\nFor more information about these certificates, contact your admin.</item>
     </plurals>
     <!-- Text of message to show to work profile users whose administrator has installed a SSL CA Cert.  [CHAR LIMIT=NONE] -->
     <plurals name="ssl_ca_cert_info_message">
-        <item quantity="one"><xliff:g id="managing_domain">%s</xliff:g> has installed a certificate authority for your work profile, which may allow them to monitor work network activity, including emails, apps, and secure websites. You can choose to either trust or remove this certificate.\n\nFor more information about this certificate, contact your admin.</item>
-        <item quantity="other"><xliff:g id="managing_domain">%s</xliff:g> has installed certificate authorities for your work profile, which may allow them to monitor work network activity, including emails, apps, and secure websites. You can choose to either trust or remove these certificates.\n\nFor more information about these certificates, contact your admin.</item>
+        <item quantity="one"><xliff:g id="managing_domain">%s</xliff:g> has installed a certificate authority for your work profile, which may allow them to monitor work network activity, including emails, apps, and secure websites.\n\nFor more information about this certificate, contact your admin.</item>
+        <item quantity="other"><xliff:g id="managing_domain">%s</xliff:g> has installed certificate authorities for your work profile, which may allow them to monitor work network activity, including emails, apps, and secure websites.\n\nFor more information about these certificates, contact your admin.</item>
     </plurals>
     <!-- Text of warning to show to users that have a SSL CA Cert installed.  [CHAR LIMIT=NONE] -->
     <string name="ssl_ca_cert_warning_message">A third party is capable of monitoring your network activity, including emails, apps, and secure websites.\n\nA trusted credential installed on your device is making this possible.</string>
diff --git a/src/com/android/settings/ShowAdminSupportDetailsDialog.java b/src/com/android/settings/ShowAdminSupportDetailsDialog.java
index 152a89c..8ee07f9 100644
--- a/src/com/android/settings/ShowAdminSupportDetailsDialog.java
+++ b/src/com/android/settings/ShowAdminSupportDetailsDialog.java
@@ -59,14 +59,13 @@
         mDpm = getSystemService(DevicePolicyManager.class);
         mEnforcedAdmin = getAdminDetailsFromIntent(getIntent());
 
-        mDialogView = LayoutInflater.from(this).inflate(
+        AlertDialog.Builder builder = new AlertDialog.Builder(this);
+        mDialogView = LayoutInflater.from(builder.getContext()).inflate(
                 R.layout.admin_support_details_dialog, null);
         initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId);
-
-        new AlertDialog.Builder(this)
-                .setView(mDialogView)
+        builder.setOnDismissListener(this)
                 .setPositiveButton(R.string.okay, null)
-                .setOnDismissListener(this)
+                .setView(mDialogView)
                 .show();
     }
 
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
index 6163576..670eed1 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
@@ -18,7 +18,6 @@
 
 import android.app.Activity;
 import android.content.Context;
-import android.content.SharedPreferences;
 import android.content.res.Resources;
 import android.os.Bundle;
 import android.provider.Settings;
@@ -46,11 +45,9 @@
         OnPreferenceChangeListener, Preference.OnPreferenceClickListener {
     public static final int DEFAULT_DAYS_TO_RETAIN = 90;
 
-    private static final String SHARED_PREFRENCES_NAME = "automatic_storage_manager_settings";
     private static final String KEY_DAYS = "days";
     private static final String KEY_DELETION_HELPER = "deletion_helper";
     private static final String KEY_STORAGE_MANAGER_SWITCH = "storage_manager_active";
-    private static final String KEY_DAYS_TO_RETAIN = "days_to_retain";
 
     private DropDownPreference mDaysToRetain;
     private Preference mDeletionHelper;
@@ -72,16 +69,11 @@
         mDeletionHelper.setOnPreferenceClickListener(this);
 
         mStorageManagerSwitch = (SwitchPreference) findPreference(KEY_STORAGE_MANAGER_SWITCH);
-        boolean isChecked =
-                Settings.Secure.getInt(getContentResolver(),
-                        Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
-        mStorageManagerSwitch.setChecked(isChecked);
         mStorageManagerSwitch.setOnPreferenceChangeListener(this);
 
-        SharedPreferences sharedPreferences =
-                getContext().getSharedPreferences(SHARED_PREFRENCES_NAME,
-                        Context.MODE_PRIVATE);
-        int value = sharedPreferences.getInt(KEY_DAYS_TO_RETAIN, DEFAULT_DAYS_TO_RETAIN);
+        int value = Settings.Secure.getInt(getContentResolver(),
+                Settings.Secure.AUTOMATIC_STORAGE_MANAGER_DAYS_TO_RETAIN,
+                Settings.Secure.AUTOMATIC_STORAGE_MANAGER_DAYS_TO_RETAIN_DEFAULT);
         String[] stringValues =
                 getResources().getStringArray(R.array.automatic_storage_management_days_values);
         mDaysToRetain.setValue(stringValues[daysValueToIndex(value, stringValues)]);
@@ -90,7 +82,11 @@
     @Override
     public void onResume() {
         super.onResume();
-        mDaysToRetain.setEnabled(mStorageManagerSwitch.isChecked());
+        boolean isChecked =
+                Settings.Secure.getInt(getContentResolver(),
+                        Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
+        mStorageManagerSwitch.setChecked(isChecked);
+        mDaysToRetain.setEnabled(isChecked);
     }
 
     @Override
@@ -103,11 +99,9 @@
                         Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, checked ? 1 : 0);
                 break;
             case KEY_DAYS:
-                SharedPreferences.Editor editor =
-                        getContext().getSharedPreferences(SHARED_PREFRENCES_NAME,
-                                Context.MODE_PRIVATE).edit();
-                editor.putInt(KEY_DAYS_TO_RETAIN, Integer.parseInt((String) newValue));
-                editor.apply();
+                Settings.Secure.putInt(getContentResolver(),
+                        Settings.Secure.AUTOMATIC_STORAGE_MANAGER_DAYS_TO_RETAIN,
+                        Integer.parseInt((String) newValue));
                 break;
         }
         return true;
diff --git a/src/com/android/settings/vpn2/AppDialogFragment.java b/src/com/android/settings/vpn2/AppDialogFragment.java
index 097001a..8013780 100644
--- a/src/com/android/settings/vpn2/AppDialogFragment.java
+++ b/src/com/android/settings/vpn2/AppDialogFragment.java
@@ -28,6 +28,7 @@
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.UserHandle;
+import android.os.UserManager;
 import android.util.Log;
 
 import com.android.internal.net.VpnConfig;
@@ -48,6 +49,7 @@
     private PackageInfo mPackageInfo;
     private Listener mListener;
 
+    private UserManager mUserManager;
     private final IConnectivityManager mService = IConnectivityManager.Stub.asInterface(
             ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
 
@@ -80,6 +82,12 @@
     }
 
     @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mUserManager = UserManager.get(getContext());
+    }
+
+    @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
         Bundle args = getArguments();
         final String label = args.getString(ARG_LABEL);
@@ -96,7 +104,7 @@
                     .setMessage(getActivity().getString(R.string.vpn_disconnect_confirm))
                     .setNegativeButton(getActivity().getString(R.string.vpn_cancel), null);
 
-            if (connected) {
+            if (connected && !isUiRestricted()) {
                 dlog.setPositiveButton(getActivity().getString(R.string.vpn_disconnect),
                         new DialogInterface.OnClickListener() {
                             @Override
@@ -120,7 +128,10 @@
 
     @Override
     public void onForget(final DialogInterface dialog) {
-        final int userId = UserHandle.getUserId(mPackageInfo.applicationInfo.uid);
+        if (isUiRestricted()) {
+            return;
+        }
+        final int userId = getUserId();
         try {
             mService.setVpnPackageAuthorization(mPackageInfo.packageName, userId, false);
             onDisconnect(dialog);
@@ -135,7 +146,10 @@
     }
 
     private void onDisconnect(final DialogInterface dialog) {
-        final int userId = UserHandle.getUserId(mPackageInfo.applicationInfo.uid);
+        if (isUiRestricted()) {
+            return;
+        }
+        final int userId = getUserId();
         try {
             if (mPackageInfo.packageName.equals(getConnectedPackage(mService, userId))) {
                 mService.setAlwaysOnVpnPackage(userId, null, /* lockdownEnabled */ false);
@@ -147,6 +161,15 @@
         }
     }
 
+    private boolean isUiRestricted() {
+        final UserHandle userHandle = UserHandle.of(getUserId());
+        return mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN, userHandle);
+    }
+
+    private int getUserId() {
+        return UserHandle.getUserId(mPackageInfo.applicationInfo.uid);
+    }
+
     private static String getConnectedPackage(IConnectivityManager service, final int userId)
             throws RemoteException {
         final VpnConfig config = service.getVpnConfig(userId);