Merge "Don't show work apps in ignore optimizations list" into mnc-dev
diff --git a/res/layout/bluetooth_pin_confirm.xml b/res/layout/bluetooth_pin_confirm.xml
index 08f5d9f..2968b38 100644
--- a/res/layout/bluetooth_pin_confirm.xml
+++ b/res/layout/bluetooth_pin_confirm.xml
@@ -86,16 +86,15 @@
             android:textColor="@*android:color/secondary_text_material_light"
             android:visibility="gone" />
 
-        <TextView
-            android:id="@+id/phonebook_sharing_message"
+        <CheckBox
+            android:id="@+id/phonebook_sharing_message_confirm_pin"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginStart="@dimen/bluetooth_dialog_padding"
             android:layout_marginEnd="@dimen/bluetooth_dialog_padding"
-            android:layout_marginBottom="@dimen/bluetooth_dialog_padding"
             android:gravity="center_vertical"
-            android:text="@string/bluetooth_pairing_will_share_phonebook"
-            android:textSize="12sp" />
+            android:text="@string/bluetooth_pairing_shares_phonebook"
+            android:textAppearance="?android:attr/textAppearanceSmall" />
 
     </LinearLayout>
 
diff --git a/res/layout/bluetooth_pin_entry.xml b/res/layout/bluetooth_pin_entry.xml
index 6f50cd4..aa9f187 100644
--- a/res/layout/bluetooth_pin_entry.xml
+++ b/res/layout/bluetooth_pin_entry.xml
@@ -87,16 +87,15 @@
             android:textAppearance="@android:style/TextAppearance.Material.Subhead"
             android:textColor="@*android:color/secondary_text_material_light"/>
 
-        <TextView
-            android:id="@+id/phonebook_sharing_message"
+        <CheckBox
+            android:id="@+id/phonebook_sharing_message_entry_pin"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginStart="@dimen/bluetooth_dialog_padding"
             android:layout_marginEnd="@dimen/bluetooth_dialog_padding"
-            android:layout_marginBottom="@dimen/bluetooth_dialog_padding"
             android:gravity="center_vertical"
-            android:text="@string/bluetooth_pairing_will_share_phonebook"
-            android:textSize="12sp" />
+            android:text="@string/bluetooth_pairing_shares_phonebook"
+            android:textAppearance="?android:attr/textAppearanceSmall" />
 
     </LinearLayout>
 
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 789224c..3d74e5d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1155,8 +1155,6 @@
     <!-- Message when bluetooth dialog when passkey or pin needs to be displayed. -->
     <string name="bluetooth_display_passkey_pin_msg">To pair with:<xliff:g id="bold1">&lt;br>&lt;b></xliff:g><xliff:g id="device_name">%1$s</xliff:g><xliff:g id="end_bold1">&lt;/b>&lt;br>&lt;br></xliff:g>Type on it:<xliff:g id="bold2">&lt;br>&lt;b></xliff:g><xliff:g id="passkey">%2$s</xliff:g><xliff:g id="end_bold2">&lt;/b></xliff:g>, then press Return or Enter.</string>
 
-    <!-- Message in pairing dialogs.  [CHAR LIMIT=NONE] -->
-    <string name="bluetooth_pairing_will_share_phonebook">Pairing grants access to your contacts and call history when connected.</string>
     <!-- Checkbox message in pairing dialogs.  [CHAR LIMIT=NONE] -->
     <string name="bluetooth_pairing_shares_phonebook">Grant access to your contacts and call history when connected.</string>
 
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java
index a4ee9616..4b3a7f7 100644
--- a/src/com/android/settings/DataUsageSummary.java
+++ b/src/com/android/settings/DataUsageSummary.java
@@ -588,7 +588,7 @@
         final MenuItem help = menu.findItem(R.id.data_usage_menu_help);
         String helpUrl;
         if (!TextUtils.isEmpty(helpUrl = getResources().getString(R.string.help_url_data_usage))) {
-            HelpUtils.prepareHelpMenuItem(context, help, helpUrl, getClass().getName());
+            HelpUtils.prepareHelpMenuItem(getActivity(), help, helpUrl, getClass().getName());
         } else {
             help.setVisible(false);
         }
diff --git a/src/com/android/settings/HelpUtils.java b/src/com/android/settings/HelpUtils.java
index 0e79c6d..3c36edb 100644
--- a/src/com/android/settings/HelpUtils.java
+++ b/src/com/android/settings/HelpUtils.java
@@ -16,6 +16,7 @@
 
 package com.android.settings;
 
+import android.app.Activity;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -28,6 +29,7 @@
 import android.util.TypedValue;
 import android.view.Menu;
 import android.view.MenuItem;
+import android.view.MenuItem.OnMenuItemClickListener;
 
 import java.net.URISyntaxException;
 import java.util.Locale;
@@ -65,16 +67,16 @@
     /** Static helper that is not instantiable*/
     private HelpUtils() { }
 
-    public static boolean prepareHelpMenuItem(Context context, Menu menu, String helpUri,
+    public static boolean prepareHelpMenuItem(Activity activity, Menu menu, String helpUri,
             String backupContext) {
         MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label);
-        return prepareHelpMenuItem(context, helpItem, helpUri, backupContext);
+        return prepareHelpMenuItem(activity, helpItem, helpUri, backupContext);
     }
 
-    public static boolean prepareHelpMenuItem(Context context, Menu menu, int helpUriResource,
+    public static boolean prepareHelpMenuItem(Activity activity, Menu menu, int helpUriResource,
             String backupContext) {
         MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label);
-        return prepareHelpMenuItem(context, helpItem, context.getString(helpUriResource),
+        return prepareHelpMenuItem(activity, helpItem, activity.getString(helpUriResource),
                 backupContext);
     }
 
@@ -86,7 +88,7 @@
      *
      * @return returns whether the help menu item has been made visible.
      */
-    public static boolean prepareHelpMenuItem(Context context, MenuItem helpMenuItem,
+    public static boolean prepareHelpMenuItem(final Activity activity, MenuItem helpMenuItem,
             String helpUriString, String backupContext) {
         if (TextUtils.isEmpty(helpUriString)) {
             // The help url string is empty or null, so set the help menu item to be invisible.
@@ -95,12 +97,18 @@
             // return that the help menu item is not visible (i.e. false)
             return false;
         } else {
-            Intent intent = getHelpIntent(context, helpUriString, backupContext);
+            final Intent intent = getHelpIntent(activity, helpUriString, backupContext);
 
             // Set the intent to the help menu item, show the help menu item in the overflow
             // menu, and make it visible.
             if (intent != null) {
-                helpMenuItem.setIntent(intent);
+                helpMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+                    @Override
+                    public boolean onMenuItemClick(MenuItem item) {
+                        activity.startActivityForResult(intent, 0);
+                        return true;
+                    }
+                });
                 helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
                 helpMenuItem.setVisible(true);
             } else {
diff --git a/src/com/android/settings/applications/UsageAccessDetails.java b/src/com/android/settings/applications/UsageAccessDetails.java
index 2da3b7c..6d5995b 100644
--- a/src/com/android/settings/applications/UsageAccessDetails.java
+++ b/src/com/android/settings/applications/UsageAccessDetails.java
@@ -17,6 +17,7 @@
 
 import android.app.AlertDialog;
 import android.app.AppOpsManager;
+import android.app.admin.DevicePolicyManager;
 import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
 import android.content.Context;
@@ -50,6 +51,7 @@
     private Preference mUsagePrefs;
     private Intent mSettingsIntent;
     private UsageState mUsageState;
+    private DevicePolicyManager mDpm;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -58,6 +60,7 @@
         Context context = getActivity();
         mUsageBridge = new AppStateUsageBridge(context, mState, null);
         mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
+        mDpm = context.getSystemService(DevicePolicyManager.class);
 
         addPreferencesFromResource(R.xml.usage_access_details);
         mSwitchPref = (SwitchPreference) findPreference(KEY_USAGE_SWITCH);
@@ -90,6 +93,14 @@
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         if (preference == mSwitchPref) {
             if (mUsageState != null && (Boolean) newValue != mUsageState.hasAccess()) {
+                if (mUsageState.hasAccess() && mDpm.isProfileOwnerApp(mPackageName)) {
+                    new AlertDialog.Builder(getContext())
+                            .setIcon(com.android.internal.R.drawable.ic_dialog_alert_material)
+                            .setTitle(android.R.string.dialog_alert_title)
+                            .setMessage(R.string.work_profile_usage_access_warning)
+                            .setPositiveButton(R.string.okay, null)
+                            .show();
+                }
                 setHasAccess(!mUsageState.hasAccess());
                 refreshUi();
             }
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
index ffe4945..29cac62 100755
--- a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
@@ -16,6 +16,7 @@
 
 package com.android.settings.bluetooth;
 
+import android.bluetooth.BluetoothClass;
 import android.bluetooth.BluetoothDevice;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -186,6 +187,24 @@
         TextView messageViewContent = (TextView) view.findViewById(R.id.message_subhead);
         TextView messageView2 = (TextView) view.findViewById(R.id.message_below_pin);
         CheckBox alphanumericPin = (CheckBox) view.findViewById(R.id.alphanumeric_pin);
+        CheckBox contactSharing = (CheckBox) view.findViewById(
+                R.id.phonebook_sharing_message_entry_pin);
+        contactSharing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+            @Override
+            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
+                if (isChecked) {
+                    mDevice.setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
+                } else {
+                    mDevice.setPhonebookAccessPermission(BluetoothDevice.ACCESS_REJECTED);
+                }
+            }
+        });
+        if (mDevice.getBluetoothClass().getDeviceClass()
+                == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE) {
+            contactSharing.setVisibility(View.VISIBLE);
+        } else {
+            contactSharing.setVisibility(View.GONE);
+        }
         mPairingView = (EditText) view.findViewById(R.id.text);
         mPairingView.addTextChangedListener(this);
         alphanumericPin.setOnCheckedChangeListener(this);
@@ -238,6 +257,24 @@
         TextView pairingViewCaption = (TextView) view.findViewById(R.id.pairing_caption);
         TextView pairingViewContent = (TextView) view.findViewById(R.id.pairing_subhead);
         TextView messagePairing = (TextView) view.findViewById(R.id.pairing_code_message);
+        CheckBox contactSharing = (CheckBox) view.findViewById(
+                R.id.phonebook_sharing_message_confirm_pin);
+        contactSharing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+            @Override
+            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
+                if (isChecked) {
+                    mDevice.setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
+                } else {
+                    mDevice.setPhonebookAccessPermission(BluetoothDevice.ACCESS_REJECTED);
+                }
+            }
+        });
+        if (mDevice.getBluetoothClass().getDeviceClass()
+                == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE) {
+            contactSharing.setVisibility(View.VISIBLE);
+        } else {
+            contactSharing.setVisibility(View.GONE);
+        }
 
         String messageCaption = null;
         String pairingContent = null;
diff --git a/src/com/android/settings/fingerprint/FingerprintSettings.java b/src/com/android/settings/fingerprint/FingerprintSettings.java
index fce46fa..b81607b 100644
--- a/src/com/android/settings/fingerprint/FingerprintSettings.java
+++ b/src/com/android/settings/fingerprint/FingerprintSettings.java
@@ -576,7 +576,7 @@
             Context ctx = widget.getContext();
             Intent intent = HelpUtils.getHelpIntent(ctx, getURL(), ctx.getClass().getName());
             try {
-                ctx.startActivity(intent);
+                ((Activity) ctx).startActivityForResult(intent, 0);
             } catch (ActivityNotFoundException e) {
                 Log.w(FingerprintSettingsFragment.TAG,
                         "Actvity was not found for intent, " + intent.toString());