From: Edward Jee Date: Fri, 5 Sep 2014 05:18:21 +0000 (-0700) Subject: Do not show phonebook access permission dialog if pairing dialog has already been... X-Git-Tag: android-x86-6.0-r1~671^2~30^2~57^2~25^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=a539716a94cbfe33e32229549b70d7cb418d8840;p=android-x86%2Fpackages-apps-Settings.git Do not show phonebook access permission dialog if pairing dialog has already been shown. Bug: 16964116, 13886947, 16345619 Change-Id: I9cf2622b49c3812771d57432fed030affaa5ba48 --- diff --git a/res/layout/bluetooth_pin_confirm.xml b/res/layout/bluetooth_pin_confirm.xml index 2e2cd7ff45..241bedc5a6 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" /> + + diff --git a/res/layout/bluetooth_pin_entry.xml b/res/layout/bluetooth_pin_entry.xml index caca4fb502..7161342ab7 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" /> + + diff --git a/res/values/strings.xml b/res/values/strings.xml index e054423b7c..25bf2787f2 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1165,6 +1165,9 @@ Cancel + + Pairing grants access to your contacts and call history when connected. + diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java index 02eed9954a..6d0e690916 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 3b64ade0b9..c1e75c0b96 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 { private int mMessagePermissionChoice; - private int mPhonebookRejectedTimes; - private int mMessageRejectedTimes; private final Collection mCallbacks = new ArrayList(); @@ -87,7 +85,6 @@ final class CachedBluetoothDevice implements Comparable { 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 { updateProfiles(); fetchPhonebookPermissionChoice(); fetchMessagePermissionChoice(); - fetchPhonebookRejectTimes(); fetchMessageRejectTimes(); mVisible = false; @@ -541,8 +537,6 @@ final class CachedBluetoothDevice implements Comparable { 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 { } 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 { 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 5c2beba38c..c94c2cfc09 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) {