summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/layout/bluetooth_pin_confirm.xml11
-rw-r--r--res/layout/bluetooth_pin_entry.xml11
-rw-r--r--res/values/strings.xml3
-rwxr-xr-xsrc/com/android/settings/bluetooth/BluetoothPairingDialog.java55
-rwxr-xr-xsrc/com/android/settings/bluetooth/CachedBluetoothDevice.java33
-rwxr-xr-xsrc/com/android/settings/bluetooth/DeviceProfilesSettings.java19
6 files changed, 69 insertions, 63 deletions
diff --git a/res/layout/bluetooth_pin_confirm.xml b/res/layout/bluetooth_pin_confirm.xml
index 2e2cd7f..241bedc 100644
--- a/res/layout/bluetooth_pin_confirm.xml
+++ b/res/layout/bluetooth_pin_confirm.xml
@@ -85,6 +85,17 @@
android:textColor="@*android:color/secondary_text_material_light"
android:visibility="gone" />
+ <TextView
+ android:id="@+id/phonebook_sharing_message"
+ 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" />
+
</LinearLayout>
</ScrollView>
diff --git a/res/layout/bluetooth_pin_entry.xml b/res/layout/bluetooth_pin_entry.xml
index caca4fb..7161342 100644
--- a/res/layout/bluetooth_pin_entry.xml
+++ b/res/layout/bluetooth_pin_entry.xml
@@ -86,6 +86,17 @@
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
+ <TextView
+ android:id="@+id/phonebook_sharing_message"
+ 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" />
+
</LinearLayout>
</ScrollView>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e054423..25bf278 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1165,6 +1165,9 @@
<!-- Button text for declining an incoming pairing request. [CHAR LIMIT=20] -->
<string name="bluetooth_pairing_decline">Cancel</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>
+
<!-- Title for BT error dialogs. -->
<string name="bluetooth_error_title"></string>
<!-- Message for the error dialog when BT pairing fails generically. -->
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
index 02eed99..6d0e690 100755
--- a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
@@ -55,6 +55,9 @@ public final class BluetoothPairingDialog extends AlertActivity implements
private static final int BLUETOOTH_PIN_MAX_LENGTH = 16;
private static final int BLUETOOTH_PASSKEY_MAX_LENGTH = 6;
+
+ private LocalBluetoothManager mBluetoothManager;
+ private CachedBluetoothDeviceManager mCachedDeviceManager;
private BluetoothDevice mDevice;
private int mType;
private String mPairingKey;
@@ -98,13 +101,13 @@ public final class BluetoothPairingDialog extends AlertActivity implements
return;
}
- LocalBluetoothManager manager = LocalBluetoothManager.getInstance(this);
- if (manager == null) {
+ mBluetoothManager = LocalBluetoothManager.getInstance(this);
+ if (mBluetoothManager == null) {
Log.e(TAG, "Error: BluetoothAdapter not supported by system");
finish();
return;
}
- CachedBluetoothDeviceManager deviceManager = manager.getCachedDeviceManager();
+ mCachedDeviceManager = mBluetoothManager.getCachedDeviceManager();
mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
mType = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR);
@@ -112,7 +115,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements
switch (mType) {
case BluetoothDevice.PAIRING_VARIANT_PIN:
case BluetoothDevice.PAIRING_VARIANT_PASSKEY:
- createUserEntryDialog(deviceManager);
+ createUserEntryDialog();
break;
case BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION:
@@ -123,12 +126,12 @@ public final class BluetoothPairingDialog extends AlertActivity implements
return;
}
mPairingKey = String.format(Locale.US, "%06d", passkey);
- createConfirmationDialog(deviceManager);
+ createConfirmationDialog();
break;
case BluetoothDevice.PAIRING_VARIANT_CONSENT:
case BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT:
- createConsentDialog(deviceManager);
+ createConsentDialog();
break;
case BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY:
@@ -144,7 +147,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements
} else {
mPairingKey = String.format("%04d", pairingKey);
}
- createDisplayPasskeyOrPinDialog(deviceManager);
+ createDisplayPasskeyOrPinDialog();
break;
default:
@@ -159,10 +162,10 @@ public final class BluetoothPairingDialog extends AlertActivity implements
registerReceiver(mReceiver, new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED));
}
- private void createUserEntryDialog(CachedBluetoothDeviceManager deviceManager) {
+ private void createUserEntryDialog() {
final AlertController.AlertParams p = mAlertParams;
p.mTitle = getString(R.string.bluetooth_pairing_request);
- p.mView = createPinEntryView(deviceManager.getName(mDevice));
+ p.mView = createPinEntryView();
p.mPositiveButtonText = getString(android.R.string.ok);
p.mPositiveButtonListener = this;
p.mNegativeButtonText = getString(android.R.string.cancel);
@@ -173,7 +176,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements
mOkButton.setEnabled(false);
}
- private View createPinEntryView(String deviceName) {
+ private View createPinEntryView() {
View view = getLayoutInflater().inflate(R.layout.bluetooth_pin_entry, null);
TextView messageViewCaption = (TextView) view.findViewById(R.id.message_caption);
TextView messageViewContent = (TextView) view.findViewById(R.id.message_subhead);
@@ -208,7 +211,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements
}
messageViewCaption.setText(messageId1);
- messageViewContent.setText(deviceName);
+ messageViewContent.setText(mCachedDeviceManager.getName(mDevice));
messageView2.setText(messageId2);
mPairingView.setInputType(InputType.TYPE_CLASS_NUMBER);
mPairingView.setFilters(new InputFilter[] {
@@ -217,10 +220,10 @@ public final class BluetoothPairingDialog extends AlertActivity implements
return view;
}
- private View createView(CachedBluetoothDeviceManager deviceManager) {
+ private View createView() {
View view = getLayoutInflater().inflate(R.layout.bluetooth_pin_confirm, null);
// Escape device name to avoid HTML injection.
- String name = Html.escapeHtml(deviceManager.getName(mDevice));
+ String name = Html.escapeHtml(mCachedDeviceManager.getName(mDevice));
TextView messageViewCaption = (TextView) view.findViewById(R.id.message_caption);
TextView messageViewContent = (TextView) view.findViewById(R.id.message_subhead);
TextView pairingViewCaption = (TextView) view.findViewById(R.id.pairing_caption);
@@ -262,10 +265,10 @@ public final class BluetoothPairingDialog extends AlertActivity implements
return view;
}
- private void createConfirmationDialog(CachedBluetoothDeviceManager deviceManager) {
+ private void createConfirmationDialog() {
final AlertController.AlertParams p = mAlertParams;
p.mTitle = getString(R.string.bluetooth_pairing_request);
- p.mView = createView(deviceManager);
+ p.mView = createView();
p.mPositiveButtonText = getString(R.string.bluetooth_pairing_accept);
p.mPositiveButtonListener = this;
p.mNegativeButtonText = getString(R.string.bluetooth_pairing_decline);
@@ -273,10 +276,10 @@ public final class BluetoothPairingDialog extends AlertActivity implements
setupAlert();
}
- private void createConsentDialog(CachedBluetoothDeviceManager deviceManager) {
+ private void createConsentDialog() {
final AlertController.AlertParams p = mAlertParams;
p.mTitle = getString(R.string.bluetooth_pairing_request);
- p.mView = createView(deviceManager);
+ p.mView = createView();
p.mPositiveButtonText = getString(R.string.bluetooth_pairing_accept);
p.mPositiveButtonListener = this;
p.mNegativeButtonText = getString(R.string.bluetooth_pairing_decline);
@@ -284,11 +287,10 @@ public final class BluetoothPairingDialog extends AlertActivity implements
setupAlert();
}
- private void createDisplayPasskeyOrPinDialog(
- CachedBluetoothDeviceManager deviceManager) {
+ private void createDisplayPasskeyOrPinDialog() {
final AlertController.AlertParams p = mAlertParams;
p.mTitle = getString(R.string.bluetooth_pairing_request);
- p.mView = createView(deviceManager);
+ p.mView = createView();
p.mNegativeButtonText = getString(android.R.string.cancel);
p.mNegativeButtonListener = this;
setupAlert();
@@ -315,7 +317,20 @@ public final class BluetoothPairingDialog extends AlertActivity implements
}
}
+ private void allowPhonebookAccess() {
+ CachedBluetoothDevice cachedDevice = mCachedDeviceManager.findDevice(mDevice);
+ if (cachedDevice == null) {
+ cachedDevice = mCachedDeviceManager.addDevice(
+ mBluetoothManager.getBluetoothAdapter(),
+ mBluetoothManager.getProfileManager(),
+ mDevice);
+ }
+ cachedDevice.setPhonebookPermissionChoice(CachedBluetoothDevice.ACCESS_ALLOWED);
+ }
+
private void onPair(String value) {
+ allowPhonebookAccess();
+
switch (mType) {
case BluetoothDevice.PAIRING_VARIANT_PIN:
byte[] pinBytes = BluetoothDevice.convertPinToBytes(value);
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index 3b64ade..c1e75c0 100755
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -68,8 +68,6 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
private int mMessagePermissionChoice;
- private int mPhonebookRejectedTimes;
-
private int mMessageRejectedTimes;
private final Collection<Callback> mCallbacks = new ArrayList<Callback>();
@@ -87,7 +85,6 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
private final static String PHONEBOOK_PREFS_NAME = "bluetooth_phonebook_permission";
private final static String MESSAGE_PREFS_NAME = "bluetooth_message_permission";
- private final static String PHONEBOOK_REJECT_TIMES = "bluetooth_phonebook_reject";
private final static String MESSAGE_REJECT_TIMES = "bluetooth_message_reject";
/**
@@ -372,7 +369,6 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
updateProfiles();
fetchPhonebookPermissionChoice();
fetchMessagePermissionChoice();
- fetchPhonebookRejectTimes();
fetchMessageRejectTimes();
mVisible = false;
@@ -541,8 +537,6 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
mConnectAfterPairing = false; // cancel auto-connect
setPhonebookPermissionChoice(ACCESS_UNKNOWN);
setMessagePermissionChoice(ACCESS_UNKNOWN);
- mPhonebookRejectedTimes = 0;
- savePhonebookRejectTimes();
mMessageRejectedTimes = 0;
saveMessageRejectTimes();
}
@@ -661,15 +655,6 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
}
void setPhonebookPermissionChoice(int permissionChoice) {
- // if user reject it, only save it when reject exceed limit.
- if (permissionChoice == ACCESS_REJECTED) {
- mPhonebookRejectedTimes++;
- savePhonebookRejectTimes();
- if (mPhonebookRejectedTimes < PERSIST_REJECTED_TIMES_LIMIT) {
- return;
- }
- }
-
mPhonebookPermissionChoice = permissionChoice;
SharedPreferences.Editor editor =
@@ -689,24 +674,6 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
ACCESS_UNKNOWN);
}
- private void fetchPhonebookRejectTimes() {
- SharedPreferences preference = mContext.getSharedPreferences(PHONEBOOK_REJECT_TIMES,
- Context.MODE_PRIVATE);
- mPhonebookRejectedTimes = preference.getInt(mDevice.getAddress(), 0);
- }
-
- private void savePhonebookRejectTimes() {
- SharedPreferences.Editor editor =
- mContext.getSharedPreferences(PHONEBOOK_REJECT_TIMES,
- Context.MODE_PRIVATE).edit();
- if (mPhonebookRejectedTimes == 0) {
- editor.remove(mDevice.getAddress());
- } else {
- editor.putInt(mDevice.getAddress(), mPhonebookRejectedTimes);
- }
- editor.commit();
- }
-
int getMessagePermissionChoice() {
return mMessagePermissionChoice;
}
diff --git a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
index 5c2beba..c94c2cf 100755
--- a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
+++ b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
@@ -151,7 +151,6 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
final PbapServerProfile psp = mManager.getProfileManager().getPbapProfile();
CheckBoxPreference pbapPref = createProfilePreference(psp);
- pbapPref.setChecked(pbapPermission == CachedBluetoothDevice.ACCESS_ALLOWED);
mProfileContainer.addPreference(pbapPref);
}
@@ -191,11 +190,6 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
pref.setIcon(getResources().getDrawable(iconResource));
}
- /**
- * Gray out profile while connecting and disconnecting
- */
- pref.setEnabled(!mCachedDevice.isBusy());
-
refreshProfilePreference(pref, profile);
return pref;
@@ -310,11 +304,16 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
LocalBluetoothProfile profile) {
BluetoothDevice device = mCachedDevice.getDevice();
- /*
- * Gray out checkbox while connecting and disconnecting
- */
+ // Gray out checkbox while connecting and disconnecting.
profilePref.setEnabled(!mCachedDevice.isBusy());
- profilePref.setChecked(profile.isPreferred(device));
+
+ if (profile instanceof PbapServerProfile) {
+ // Handle PBAP specially.
+ profilePref.setChecked(mCachedDevice.getPhonebookPermissionChoice()
+ == CachedBluetoothDevice.ACCESS_ALLOWED);
+ } else {
+ profilePref.setChecked(profile.isPreferred(device));
+ }
}
private LocalBluetoothProfile getProfileOf(Preference pref) {