diff --git a/res/layout/bluetooth_pb_access.xml b/res/layout/bluetooth_access.xml
similarity index 92%
rename from res/layout/bluetooth_pb_access.xml
rename to res/layout/bluetooth_access.xml
index 01218d6593a..3bfb68901de 100644
--- a/res/layout/bluetooth_pb_access.xml
+++ b/res/layout/bluetooth_access.xml
@@ -36,12 +36,12 @@
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium" />
-
+ android:text="@string/bluetooth_remember_choice" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 01011bbd35c..812b4912f40 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -355,8 +355,19 @@
%1$s wants to access your contacts and call history. Give access to %2$s?
+ Don\'t ask again
+
Don\'t ask again
+
+ "Message request"
+
+
+ %1$s wants to access your messages. Give access to %2$s?
+
+
+
+
Date & time settings
diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java b/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java
index 16476fad309..aac1d4eacf2 100755
--- a/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java
+++ b/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java
@@ -58,7 +58,7 @@ public class BluetoothPermissionActivity extends AlertActivity implements
private CheckBox mRememberChoice;
private boolean mRememberChoiceValue = false;
-
+ private int mRequestType = 0;
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -91,15 +91,18 @@ public class BluetoothPermissionActivity extends AlertActivity implements
mDevice = i.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
mReturnPackage = i.getStringExtra(BluetoothDevice.EXTRA_PACKAGE_NAME);
mReturnClass = i.getStringExtra(BluetoothDevice.EXTRA_CLASS_NAME);
- int requestType = i.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
+ mRequestType = i.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
- if (requestType == BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION) {
- showConnectionDialog();
- } else if (requestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
- showPhonebookDialog();
- } else {
- Log.e(TAG, "Error: bad request type: " + requestType);
+ if (mRequestType == BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION) {
+ showDialog(getString(R.string.bluetooth_connection_permission_request), mRequestType);
+ } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
+ showDialog(getString(R.string.bluetooth_phonebook_request), mRequestType);
+ } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
+ showDialog(getString(R.string.bluetooth_map_request), mRequestType);
+ }
+ else {
+ Log.e(TAG, "Error: bad request type: " + mRequestType);
finish();
return;
}
@@ -108,62 +111,57 @@ public class BluetoothPermissionActivity extends AlertActivity implements
mReceiverRegistered = true;
}
- private void showConnectionDialog() {
+
+ private void showDialog(String title, int requestType)
+ {
final AlertController.AlertParams p = mAlertParams;
p.mIconId = android.R.drawable.ic_dialog_info;
- p.mTitle = getString(R.string.bluetooth_connection_permission_request);
- p.mView = createConnectionDialogView();
+ p.mTitle = title;
+ switch(requestType)
+ {
+ case BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION:
+ p.mView = createConnectionDialogView();
+ break;
+ case BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS:
+ p.mView = createPhonebookDialogView();
+ break;
+ case BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS:
+ p.mView = createMapDialogView();
+ break;
+ }
p.mPositiveButtonText = getString(R.string.yes);
p.mPositiveButtonListener = this;
p.mNegativeButtonText = getString(R.string.no);
p.mNegativeButtonListener = this;
mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
setupAlert();
+
}
- private void showPhonebookDialog() {
- final AlertController.AlertParams p = mAlertParams;
- p.mIconId = android.R.drawable.ic_dialog_info;
- p.mTitle = getString(R.string.bluetooth_phonebook_request);
- p.mView = createPhonebookDialogView();
- p.mPositiveButtonText = getString(android.R.string.yes);
- p.mPositiveButtonListener = this;
- p.mNegativeButtonText = getString(android.R.string.no);
- p.mNegativeButtonListener = this;
- mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
- setupAlert();
- }
-
- private String createConnectionDisplayText() {
- String mRemoteName = mDevice != null ? mDevice.getAliasName() : null;
-
- if (mRemoteName == null) mRemoteName = getString(R.string.unknown);
- String mMessage1 = getString(R.string.bluetooth_connection_dialog_text,
- mRemoteName);
+ private String createDisplayText(String message) {
+ String mMessage1 = message;
return mMessage1;
}
- private String createPhonebookDisplayText() {
+ private String createRemoteName()
+ {
String mRemoteName = mDevice != null ? mDevice.getAliasName() : null;
-
if (mRemoteName == null) mRemoteName = getString(R.string.unknown);
- String mMessage1 = getString(R.string.bluetooth_pb_acceptance_dialog_text,
- mRemoteName, mRemoteName);
- return mMessage1;
+ return mRemoteName;
}
private View createConnectionDialogView() {
+ String mRemoteName = createRemoteName();
mView = getLayoutInflater().inflate(R.layout.bluetooth_connection_access, null);
messageView = (TextView)mView.findViewById(R.id.message);
- messageView.setText(createConnectionDisplayText());
+ messageView.setText(createDisplayText(getString(R.string.bluetooth_connection_dialog_text,
+ mRemoteName)));
return mView;
}
- private View createPhonebookDialogView() {
- mView = getLayoutInflater().inflate(R.layout.bluetooth_pb_access, null);
- messageView = (TextView)mView.findViewById(R.id.message);
- messageView.setText(createPhonebookDisplayText());
- mRememberChoice = (CheckBox)mView.findViewById(R.id.bluetooth_pb_remember_choice);
+ private void createCheckbox(int viewId)
+ {
+ mRememberChoice = (CheckBox)mView.findViewById(viewId);
mRememberChoice.setChecked(false);
mRememberChoice.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@@ -174,26 +172,42 @@ public class BluetoothPermissionActivity extends AlertActivity implements
}
}
});
+ }
+ private View createPhonebookDialogView() {
+ String mRemoteName = createRemoteName();
+ mView = getLayoutInflater().inflate(R.layout.bluetooth_access, null);
+ messageView = (TextView)mView.findViewById(R.id.message);
+ messageView.setText(createDisplayText(getString(R.string.bluetooth_pb_acceptance_dialog_text,
+ mRemoteName, mRemoteName)));
+ createCheckbox(R.id.bluetooth_remember_choice);
+ return mView;
+ }
+ private View createMapDialogView() {
+ String mRemoteName = createRemoteName();
+ mView = getLayoutInflater().inflate(R.layout.bluetooth_access, null);
+ messageView = (TextView)mView.findViewById(R.id.message);
+ messageView.setText(createDisplayText(getString(R.string.bluetooth_map_acceptance_dialog_text,
+ mRemoteName, mRemoteName)));
+ createCheckbox(R.id.bluetooth_remember_choice);
return mView;
}
private void onPositive() {
if (DEBUG) Log.d(TAG, "onPositive mRememberChoiceValue: " + mRememberChoiceValue);
+ if (mRememberChoiceValue)
+ savePermissionChoice(mRequestType, CachedBluetoothDevice.ACCESS_ALLOWED);
- if (mRememberChoiceValue) {
- savePhonebookPermissionChoice(CachedBluetoothDevice.PHONEBOOK_ACCESS_ALLOWED);
- }
sendIntentToReceiver(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY, true,
- BluetoothDevice.EXTRA_ALWAYS_ALLOWED, mRememberChoiceValue);
+ BluetoothDevice.EXTRA_ALWAYS_ALLOWED, mRememberChoiceValue);
finish();
}
private void onNegative() {
if (DEBUG) Log.d(TAG, "onNegative mRememberChoiceValue: " + mRememberChoiceValue);
- if (mRememberChoiceValue) {
- savePhonebookPermissionChoice(CachedBluetoothDevice.PHONEBOOK_ACCESS_REJECTED);
- }
+ if (mRememberChoiceValue)
+ savePermissionChoice(mRequestType, CachedBluetoothDevice.ACCESS_REJECTED);
+
sendIntentToReceiver(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY, false,
null, false // dummy value, no effect since last param is null
);
@@ -246,18 +260,23 @@ public class BluetoothPermissionActivity extends AlertActivity implements
return true;
}
- private void savePhonebookPermissionChoice(int permissionChoice) {
+ private void savePermissionChoice(int permissionType, int permissionChoice) {
LocalBluetoothManager bluetoothManager = LocalBluetoothManager.getInstance(this);
CachedBluetoothDeviceManager cachedDeviceManager =
bluetoothManager.getCachedDeviceManager();
CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(mDevice);
- if (cachedDevice != null ) {
- cachedDevice.setPhonebookPermissionChoice(permissionChoice);
- } else {
+ if (DEBUG) Log.d(TAG, "savePermissionChoice permissionType: " + permissionType);
+ if (cachedDevice == null ) {
cachedDevice = cachedDeviceManager.addDevice(bluetoothManager.getBluetoothAdapter(),
bluetoothManager.getProfileManager(),
mDevice);
- cachedDevice.setPhonebookPermissionChoice(permissionChoice);
}
+ if (permissionType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS){
+ cachedDevice.setPhonebookPermissionChoice(permissionChoice);
+ }else if (permissionType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS){
+ cachedDevice.setMessagePermissionChoice(permissionChoice);
+ }
+
}
+
}
diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
index e2231bbac71..343018e9d40 100644
--- a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
+++ b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
@@ -128,8 +128,10 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
private boolean checkUserChoice() {
boolean processed = false;
- // we only remember PHONEBOOK permission
- if (mRequestType != BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
+ // ignore if it is something else than phonebook/message settings it wants us to remember
+ if (mRequestType != BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS
+ && mRequestType != BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
+ if (DEBUG) Log.d(TAG, "Unknown RequestType: " + mRequestType);
return processed;
}
@@ -143,23 +145,45 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
bluetoothManager.getProfileManager(), mDevice);
}
- int phonebookPermission = cachedDevice.getPhonebookPermissionChoice();
+ if(mRequestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
- if (phonebookPermission == CachedBluetoothDevice.PHONEBOOK_ACCESS_UNKNOWN) {
- return processed;
- }
+ int phonebookPermission = cachedDevice.getPhonebookPermissionChoice();
- String intentName = BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY;
- if (phonebookPermission == CachedBluetoothDevice.PHONEBOOK_ACCESS_ALLOWED) {
- sendIntentToReceiver(intentName, true, BluetoothDevice.EXTRA_ALWAYS_ALLOWED, true);
- processed = true;
- } else if (phonebookPermission == CachedBluetoothDevice.PHONEBOOK_ACCESS_REJECTED) {
- sendIntentToReceiver(intentName, false,
- null, false // dummy value, no effect since previous param is null
- );
- processed = true;
- } else {
- Log.e(TAG, "Bad phonebookPermission: " + phonebookPermission);
+ if (phonebookPermission == CachedBluetoothDevice.ACCESS_UNKNOWN) {
+ return processed;
+ }
+
+ String intentName = BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY;
+ if (phonebookPermission == CachedBluetoothDevice.ACCESS_ALLOWED) {
+ sendIntentToReceiver(intentName, true, BluetoothDevice.EXTRA_ALWAYS_ALLOWED, true);
+ processed = true;
+ } else if (phonebookPermission == CachedBluetoothDevice.ACCESS_REJECTED) {
+ sendIntentToReceiver(intentName, false,
+ null, false ); // dummy value, no effect since previous param is null
+ processed = true;
+ } else {
+ Log.e(TAG, "Bad phonebookPermission: " + phonebookPermission);
+ }
+
+ } else if(mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
+
+ int messagePermission = cachedDevice.getMessagePermissionChoice();
+
+ if (messagePermission == CachedBluetoothDevice.ACCESS_UNKNOWN) {
+ return processed;
+ }
+
+ String intentName = BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY;
+ if (messagePermission == CachedBluetoothDevice.ACCESS_ALLOWED) {
+ sendIntentToReceiver(intentName, true, BluetoothDevice.EXTRA_ALWAYS_ALLOWED, true);
+ processed = true;
+ } else if (messagePermission == CachedBluetoothDevice.ACCESS_REJECTED) {
+ sendIntentToReceiver(intentName, false,
+ null, false); // dummy value, no effect since previous param is null
+ processed = true;
+ } else {
+ Log.e(TAG, "Bad messagePermission: " + messagePermission);
+ }
}
return processed;
}
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index 4b19b9c1172..97420272cef 100755
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -66,17 +66,22 @@ final class CachedBluetoothDevice implements Comparable {
private int mPhonebookPermissionChoice;
+ private int mMessagePermissionChoice;
+
+
private final Collection mCallbacks = new ArrayList();
- // 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 {
fetchBtClass();
updateProfiles();
fetchPhonebookPermissionChoice();
+ fetchMessagePermissionChoice();
mVisible = false;
dispatchAttributesChanged();
@@ -513,7 +519,8 @@ final class CachedBluetoothDevice implements Comparable {
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 {
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 {
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);
}
}