MAP 1.1 Review fixes
- Fixes to the issues found during review. - added support for BluetoothProfile ProfileService Classes - Added new MapProfile.java to comply with new structure - changed ORDINAL to use BluetoothProfile.MAP directly - Moved construction of MapProfile to LocalBluetoothProfileManager constructor - Added support for multiple concurent permission activities and/or multiple notifications (i.e. pbap and map permission request right after each other) - cleanup - changed settings to use Notification.Builder - made the notifications for map/pbab more informative - added handling of back button + "clear all notifications" Bug:10692365 Change-Id: I9803c9658a96b1a9c1d4734d2fdd22f1421d2827
This commit is contained in:
@@ -36,7 +36,11 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "BluetoothPermissionRequest";
|
||||
private static final boolean DEBUG = Utils.V;
|
||||
public static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth;
|
||||
private static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth;
|
||||
|
||||
private static final String NOTIFICATION_TAG_PBAP = "Phonebook Access" ;
|
||||
private static final String NOTIFICATION_TAG_MAP = "Message Access";
|
||||
|
||||
|
||||
Context mContext;
|
||||
int mRequestType;
|
||||
@@ -49,7 +53,7 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
mContext = context;
|
||||
String action = intent.getAction();
|
||||
|
||||
if (DEBUG) Log.d(TAG, "onReceive");
|
||||
if (DEBUG) Log.d(TAG, "onReceive" + action);
|
||||
|
||||
if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REQUEST)) {
|
||||
// convert broadcast intent into activity intent (same action string)
|
||||
@@ -59,14 +63,8 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
mReturnPackage = intent.getStringExtra(BluetoothDevice.EXTRA_PACKAGE_NAME);
|
||||
mReturnClass = intent.getStringExtra(BluetoothDevice.EXTRA_CLASS_NAME);
|
||||
|
||||
Intent connectionAccessIntent = new Intent(action);
|
||||
connectionAccessIntent.setClass(context, BluetoothPermissionActivity.class);
|
||||
connectionAccessIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
|
||||
mRequestType);
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_PACKAGE_NAME, mReturnPackage);
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_CLASS_NAME, mReturnClass);
|
||||
if (DEBUG) Log.d(TAG, "onReceive request type: " + mRequestType + " return "
|
||||
+ mReturnPackage + "," + mReturnClass);
|
||||
|
||||
// Check if user had made decisions on accepting or rejecting the phonebook access
|
||||
// request. If there is, reply the request and return, no need to start permission
|
||||
@@ -75,8 +73,22 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
return;
|
||||
}
|
||||
|
||||
String deviceAddress = mDevice != null ? mDevice.getAddress() : null;
|
||||
Intent connectionAccessIntent = new Intent(action);
|
||||
connectionAccessIntent.setClass(context, BluetoothPermissionActivity.class);
|
||||
// We use the FLAG_ACTIVITY_MULTIPLE_TASK since we can have multiple concurrent access requests
|
||||
connectionAccessIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
connectionAccessIntent.setType(Integer.toString(mRequestType)); /* This is needed to create two pending
|
||||
intents to the same activity.
|
||||
The value is not used in the activity. */
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
|
||||
mRequestType);
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_PACKAGE_NAME, mReturnPackage);
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_CLASS_NAME, mReturnClass);
|
||||
|
||||
String deviceAddress = mDevice != null ? mDevice.getAddress() : null;
|
||||
String title = null;
|
||||
String message = null;
|
||||
PowerManager powerManager =
|
||||
(PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
|
||||
@@ -93,33 +105,61 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
deleteIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
|
||||
deleteIntent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT,
|
||||
BluetoothDevice.CONNECTION_ACCESS_NO);
|
||||
|
||||
Notification notification = new Notification(
|
||||
android.R.drawable.stat_sys_data_bluetooth,
|
||||
context.getString(R.string.bluetooth_connection_permission_request),
|
||||
System.currentTimeMillis());
|
||||
deleteIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
|
||||
String deviceName = mDevice != null ? mDevice.getAliasName() : null;
|
||||
notification.setLatestEventInfo(context,
|
||||
context.getString(R.string.bluetooth_connection_permission_request),
|
||||
context.getString(R.string.bluetooth_connection_notif_message, deviceName),
|
||||
PendingIntent.getActivity(context, 0, connectionAccessIntent, 0));
|
||||
notification.flags = Notification.FLAG_AUTO_CANCEL |
|
||||
Notification.FLAG_ONLY_ALERT_ONCE;
|
||||
notification.defaults = Notification.DEFAULT_SOUND;
|
||||
notification.deleteIntent = PendingIntent.getBroadcast(context, 0, deleteIntent, 0);
|
||||
switch (mRequestType) {
|
||||
case BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS:
|
||||
title = context.getString(R.string.bluetooth_phonebook_request);
|
||||
message = context.getString(R.string.bluetooth_pb_acceptance_dialog_text, deviceName, deviceName);
|
||||
break;
|
||||
case BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS:
|
||||
title = context.getString(R.string.bluetooth_map_request);
|
||||
message = context.getString(R.string.bluetooth_map_acceptance_dialog_text, deviceName, deviceName);
|
||||
break;
|
||||
default:
|
||||
title = context.getString(R.string.bluetooth_connection_permission_request);
|
||||
message = context.getString(R.string.bluetooth_connection_dialog_text, deviceName, deviceName);
|
||||
break;
|
||||
}
|
||||
Notification notification = new Notification.Builder(context)
|
||||
.setContentTitle(title)
|
||||
.setTicker(message)
|
||||
.setContentText(message)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
|
||||
.setAutoCancel(true)
|
||||
.setPriority(Notification.PRIORITY_MAX)
|
||||
.setOnlyAlertOnce(false)
|
||||
.setDefaults(Notification.DEFAULT_ALL)
|
||||
.setContentIntent(PendingIntent.getActivity(context, 0, connectionAccessIntent, 0))
|
||||
.setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
|
||||
.build();
|
||||
|
||||
notification.flags |= Notification.FLAG_NO_CLEAR; /* cannot be set with the builder */
|
||||
|
||||
NotificationManager notificationManager =
|
||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.notify(NOTIFICATION_ID, notification);
|
||||
|
||||
notificationManager.notify(getNotificationTag(mRequestType),NOTIFICATION_ID, notification);
|
||||
}
|
||||
} else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL)) {
|
||||
// Remove the notification
|
||||
NotificationManager manager = (NotificationManager) context
|
||||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
manager.cancel(NOTIFICATION_ID);
|
||||
mRequestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
|
||||
BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
|
||||
manager.cancel(getNotificationTag(mRequestType), NOTIFICATION_ID);
|
||||
}
|
||||
}
|
||||
|
||||
private String getNotificationTag(int requestType) {
|
||||
if(requestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
|
||||
return NOTIFICATION_TAG_PBAP;
|
||||
} else if(mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
|
||||
return NOTIFICATION_TAG_MAP;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true user had made a choice, this method replies to the request according
|
||||
* to user's previous decision
|
||||
@@ -185,6 +225,7 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
Log.e(TAG, "Bad messagePermission: " + messagePermission);
|
||||
}
|
||||
}
|
||||
if(DEBUG) Log.d(TAG,"checkUserChoice(): returning " + processed);
|
||||
return processed;
|
||||
}
|
||||
|
||||
@@ -204,6 +245,7 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
intent.putExtra(extraName, extraValue);
|
||||
}
|
||||
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
|
||||
intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
|
||||
mContext.sendBroadcast(intent, android.Manifest.permission.BLUETOOTH_ADMIN);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user