From 1083b4726ba915261034612ae9b757d67ed19fcb Mon Sep 17 00:00:00 2001 From: Zhihai Xu Date: Thu, 17 Oct 2013 17:11:38 -0700 Subject: [PATCH] BT keeps on asking me if I want to allow car to do stuff Persist the "no" count bug:11176511 Change-Id: I39674334fe8bf09d1f3f2b07c12513a6c46f053b --- .../bluetooth/CachedBluetoothDevice.java | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java index 2fb434b624e..77a946291af 100755 --- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java +++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java @@ -68,9 +68,9 @@ final class CachedBluetoothDevice implements Comparable { private int mMessagePermissionChoice; - private int mPhonebookRejectedTimes = 0; + private int mPhonebookRejectedTimes; - private int mMessageRejectedTimes = 0; + private int mMessageRejectedTimes; private final Collection mCallbacks = new ArrayList(); @@ -87,6 +87,8 @@ 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"; /** * When we connect to multiple profiles, we only want to display a single @@ -372,6 +374,8 @@ final class CachedBluetoothDevice implements Comparable { updateProfiles(); fetchPhonebookPermissionChoice(); fetchMessagePermissionChoice(); + fetchPhonebookRejectTimes(); + fetchMessageRejectTimes(); mVisible = false; dispatchAttributesChanged(); @@ -538,6 +542,10 @@ final class CachedBluetoothDevice implements Comparable { mConnectAfterPairing = false; // cancel auto-connect setPhonebookPermissionChoice(ACCESS_UNKNOWN); setMessagePermissionChoice(ACCESS_UNKNOWN); + mPhonebookRejectedTimes = 0; + savePhonebookRejectTimes(); + mMessageRejectedTimes = 0; + saveMessageRejectTimes(); } refresh(); @@ -657,6 +665,7 @@ final class CachedBluetoothDevice implements Comparable { // if user reject it, only save it when reject exceed limit. if (permissionChoice == ACCESS_REJECTED) { mPhonebookRejectedTimes++; + savePhonebookRejectTimes(); if (mPhonebookRejectedTimes < PERSIST_REJECTED_TIMES_LIMIT) { return; } @@ -681,6 +690,23 @@ 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; @@ -690,6 +716,7 @@ final class CachedBluetoothDevice implements Comparable { // if user reject it, only save it when reject exceed limit. if (permissionChoice == ACCESS_REJECTED) { mMessageRejectedTimes++; + saveMessageRejectTimes(); if (mMessageRejectedTimes < PERSIST_REJECTED_TIMES_LIMIT) { return; } @@ -714,4 +741,21 @@ final class CachedBluetoothDevice implements Comparable { ACCESS_UNKNOWN); } + private void fetchMessageRejectTimes() { + SharedPreferences preference = mContext.getSharedPreferences(MESSAGE_REJECT_TIMES, + Context.MODE_PRIVATE); + mMessageRejectedTimes = preference.getInt(mDevice.getAddress(), 0); + } + + private void saveMessageRejectTimes() { + SharedPreferences.Editor editor = + mContext.getSharedPreferences(MESSAGE_REJECT_TIMES, Context.MODE_PRIVATE).edit(); + if (mMessageRejectedTimes == 0) { + editor.remove(mDevice.getAddress()); + } else { + editor.putInt(mDevice.getAddress(), mMessageRejectedTimes); + } + editor.commit(); + } + }