BT keeps on asking me if I want to allow car to do stuff
Persist the "no" count bug:11176511 Change-Id: I39674334fe8bf09d1f3f2b07c12513a6c46f053b
This commit is contained in:
@@ -68,9 +68,9 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
|
||||
|
||||
private int mMessagePermissionChoice;
|
||||
|
||||
private int mPhonebookRejectedTimes = 0;
|
||||
private int mPhonebookRejectedTimes;
|
||||
|
||||
private int mMessageRejectedTimes = 0;
|
||||
private int mMessageRejectedTimes;
|
||||
|
||||
private final Collection<Callback> mCallbacks = new ArrayList<Callback>();
|
||||
|
||||
@@ -87,6 +87,8 @@ 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";
|
||||
|
||||
/**
|
||||
* When we connect to multiple profiles, we only want to display a single
|
||||
@@ -372,6 +374,8 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
|
||||
updateProfiles();
|
||||
fetchPhonebookPermissionChoice();
|
||||
fetchMessagePermissionChoice();
|
||||
fetchPhonebookRejectTimes();
|
||||
fetchMessageRejectTimes();
|
||||
|
||||
mVisible = false;
|
||||
dispatchAttributesChanged();
|
||||
@@ -538,6 +542,10 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
|
||||
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<CachedBluetoothDevice> {
|
||||
// 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<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;
|
||||
@@ -690,6 +716,7 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
|
||||
// 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<CachedBluetoothDevice> {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user