Bluetooth MAP profile - sms and mms support initial check-in

bug:10116530

Change-Id: I3f50e66420e53bf21a1ecba06aed6b8261ff3064
This commit is contained in:
Matthew Xie
2013-07-18 17:16:27 -07:00
committed by Zhihai Xu
parent 2f219c51ad
commit 5b5b1e39dd
5 changed files with 164 additions and 79 deletions

View File

@@ -66,17 +66,22 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
private int mPhonebookPermissionChoice;
private int mMessagePermissionChoice;
private final Collection<Callback> mCallbacks = new ArrayList<Callback>();
// Following constants indicate the user's choices of Phone book access settings
// Following constants indicate the user's choices of Phone book/message access settings
// User hasn't made any choice or settings app has wiped out the memory
final static int PHONEBOOK_ACCESS_UNKNOWN = 0;
final static int ACCESS_UNKNOWN = 0;
// User has accepted the connection and let Settings app remember the decision
final static int PHONEBOOK_ACCESS_ALLOWED = 1;
final static int ACCESS_ALLOWED = 1;
// User has rejected the connection and let Settings app remember the decision
final static int PHONEBOOK_ACCESS_REJECTED = 2;
final static int ACCESS_REJECTED = 2;
private final static String PHONEBOOK_PREFS_NAME = "bluetooth_phonebook_permission";
private final static String MESSAGE_PREFS_NAME = "bluetooth_message_permission";
/**
* When we connect to multiple profiles, we only want to display a single
@@ -349,6 +354,7 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
fetchBtClass();
updateProfiles();
fetchPhonebookPermissionChoice();
fetchMessagePermissionChoice();
mVisible = false;
dispatchAttributesChanged();
@@ -513,7 +519,8 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
if (bondState == BluetoothDevice.BOND_NONE) {
mProfiles.clear();
mConnectAfterPairing = false; // cancel auto-connect
setPhonebookPermissionChoice(PHONEBOOK_ACCESS_UNKNOWN);
setPhonebookPermissionChoice(ACCESS_UNKNOWN);
setMessagePermissionChoice(ACCESS_UNKNOWN);
}
refresh();
@@ -632,7 +639,7 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
void setPhonebookPermissionChoice(int permissionChoice) {
SharedPreferences.Editor editor =
mContext.getSharedPreferences(PHONEBOOK_PREFS_NAME, Context.MODE_PRIVATE).edit();
if (permissionChoice == PHONEBOOK_ACCESS_UNKNOWN) {
if (permissionChoice == ACCESS_UNKNOWN) {
editor.remove(mDevice.getAddress());
} else {
editor.putInt(mDevice.getAddress(), permissionChoice);
@@ -645,7 +652,31 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
SharedPreferences preference = mContext.getSharedPreferences(PHONEBOOK_PREFS_NAME,
Context.MODE_PRIVATE);
mPhonebookPermissionChoice = preference.getInt(mDevice.getAddress(),
PHONEBOOK_ACCESS_UNKNOWN);
ACCESS_UNKNOWN);
}
int getMessagePermissionChoice() {
return mMessagePermissionChoice;
}
void setMessagePermissionChoice(int permissionChoice) {
SharedPreferences.Editor editor =
mContext.getSharedPreferences(MESSAGE_PREFS_NAME, Context.MODE_PRIVATE).edit();
if (permissionChoice == ACCESS_UNKNOWN) {
editor.remove(mDevice.getAddress());
} else {
editor.putInt(mDevice.getAddress(), permissionChoice);
}
editor.commit();
mMessagePermissionChoice = permissionChoice;
}
private void fetchMessagePermissionChoice() {
SharedPreferences preference = mContext.getSharedPreferences(MESSAGE_PREFS_NAME,
Context.MODE_PRIVATE);
mMessagePermissionChoice = preference.getInt(mDevice.getAddress(),
ACCESS_UNKNOWN);
}
}