1. seandroid
  2. Untitled project
  3. packages/apps/Settings

Commits

Zhihai Xu  committed 290404d

BT keeps on asking me if I want to allow car to do stuff

Persist the "no" count
bug:11176511

Change-Id: I39674334fe8bf09d1f3f2b07c12513a6c46f053b

  • Participants
  • Parent commits 4f14ef2
  • Branches kitkat-release, seandroid-4.4

Comments (0)

Files changed (1)

File src/com/android/settings/bluetooth/CachedBluetoothDevice.java

View file
  • Ignore whitespace
 
     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>();
 
 
     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
         updateProfiles();
         fetchPhonebookPermissionChoice();
         fetchMessagePermissionChoice();
+        fetchPhonebookRejectTimes();
+        fetchMessageRejectTimes();
 
         mVisible = false;
         dispatchAttributesChanged();
             mConnectAfterPairing = false;  // cancel auto-connect
             setPhonebookPermissionChoice(ACCESS_UNKNOWN);
             setMessagePermissionChoice(ACCESS_UNKNOWN);
+            mPhonebookRejectedTimes = 0;
+            savePhonebookRejectTimes();
+            mMessageRejectedTimes = 0;
+            saveMessageRejectTimes();
         }
 
         refresh();
         // if user reject it, only save it when reject exceed limit.
         if (permissionChoice == ACCESS_REJECTED) {
             mPhonebookRejectedTimes++;
+            savePhonebookRejectTimes();
             if (mPhonebookRejectedTimes < PERSIST_REJECTED_TIMES_LIMIT) {
                 return;
             }
                                                        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;
         // if user reject it, only save it when reject exceed limit.
         if (permissionChoice == ACCESS_REJECTED) {
             mMessageRejectedTimes++;
+            saveMessageRejectTimes();
             if (mMessageRejectedTimes < PERSIST_REJECTED_TIMES_LIMIT) {
                 return;
             }
                                                        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();
+    }
+
 }