Merge "OBEX: Avoid BluetoothExt process kill for active MAP or FTP Session."
diff --git a/res/values/strings_ftp.xml b/res/values/strings_ftp.xml
index 2c75d2f..8381134 100644
--- a/res/values/strings_ftp.xml
+++ b/res/values/strings_ftp.xml
@@ -41,6 +41,11 @@
<!-- Notification message when a Bluetooth device wants to pair with us -->
<string name="ftp_notif_message">"Touch to connect to \u0022<xliff:g id="device_name">%1$s</xliff:g>\u0022."</string>
<!-- Activity label of BluetoothFtpPermissionActivity, also used as Strings in the permission dialog [CHAR LIMIT=none] -->
+ <!--Notification Title for ACTIVE SESSION -->
+ <string name="ftp_notif_active_session">Bluetooth FTP Active Session </string>
+ <!--Notification message for ACTIVE SESSION -->
+ <string name="ftp_notif_connected">"Bluetotoh File Transfer Access to \u0022<xliff:g id="device_name">%1$s</xliff:g>\u0022."</string>
+
<string name="bluetooth_ftp_request">"Ftp request"</string>
<!-- Bluetooth FTP permission Alert Activity text [CHAR LIMIT=none] -->
diff --git a/res/values/strings_map.xml b/res/values/strings_map.xml
index 5ed01c7..2357db8 100644
--- a/res/values/strings_map.xml
+++ b/res/values/strings_map.xml
@@ -36,6 +36,10 @@
<string name="map_acceptance_timeout_message">There was time out to accept connection with %1$s</string>
<string name="map_authentication_timeout_message">There was time out to input session key with %1$s</string>
<string name="map_notif_ticker">Bluetooth connection request</string>
+ <!--Notification Title for ACTIVE SESSION -->
+ <string name="map_notif_active_session">Bluetooth MAP Active Session </string>
+ <!--Notification message for ACTIVE SESSION -->
+ <string name="map_notif_connected">"Bluetooth Message Access to \u0022<xliff:g id="device_name">%1$s</xliff:g>\u0022."</string>
<!-- Notification title when a Bluetooth device wants to pair with us -->
<string name="map_notif_title">Session Key Request for MAP</string>
<!-- Notification message when a Bluetooth device wants to pair with us -->
diff --git a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
index 565fb05..4608214 100644
--- a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
+++ b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
@@ -190,6 +190,8 @@
private static final int NOTIFICATION_ID_AUTH = -1000006;
+ private static final int NOTIFICATION_ID_CONNECTED = -1000010;
+
private static final int FTP_MEDIA_SCANNED = 4;
private static final int FTP_MEDIA_SCANNED_FAILED = 5;
@@ -206,6 +208,8 @@
private WakeLock mWakeLock;
+ private Notification mConnectedNotification = null;
+
private BluetoothAdapter mAdapter;
private RfcommSocketAcceptThread mRfcommAcceptThread = null;
@@ -698,8 +702,13 @@
break;
case MSG_SERVERSESSION_CLOSE:
stopObexServerSession();
+ stopForeground(true);
+ mConnectedNotification = null;
break;
case MSG_SESSION_ESTABLISHED:
+ if(mConnectedNotification == null)
+ mConnectedNotification = createFtpConnectedNotification();
+ startForeground(NOTIFICATION_ID_CONNECTED, mConnectedNotification);
break;
case MSG_SESSION_DISCONNECTED:
break;
@@ -754,6 +763,18 @@
}
}
};
+ private Notification createFtpConnectedNotification() {
+ if (VERBOSE) Log.v(TAG, "Creating FTP access CONNECTED");
+
+ Notification notification = new Notification(android.R.drawable.stat_sys_data_bluetooth,
+ getString(R.string.ftp_notif_active_session), System.currentTimeMillis());
+ notification.setLatestEventInfo(this, getString(R.string.ftp_notif_active_session),
+ getString( R.string.ftp_notif_connected , getRemoteDeviceName()), null);
+ notification.flags |= Notification.FLAG_AUTO_CANCEL;
+ notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
+ notification.defaults = Notification.DEFAULT_SOUND;
+ return notification;
+ }
private void createFtpNotification(String action) {
NotificationManager nm = (NotificationManager)
diff --git a/src/org/codeaurora/bluetooth/map/BluetoothMasService.java b/src/org/codeaurora/bluetooth/map/BluetoothMasService.java
index a72b155..b19c50a 100755
--- a/src/org/codeaurora/bluetooth/map/BluetoothMasService.java
+++ b/src/org/codeaurora/bluetooth/map/BluetoothMasService.java
@@ -170,7 +170,10 @@
ParcelUuid.fromString("00001133-0000-1000-8000-00805f9b34fb");
// Ensure not conflict with Opp notification ID
- private static final int NOTIFICATION_ID_ACCESS = -1000005;
+ private static final int NOTIFICATION_ID_ACCESS = -1000007;
+ private static final int NOTIFICATION_ID_CONNECTED = -1000008;
+
+ private Notification mConnectedNotification = null;
private BluetoothAdapter mAdapter;
@@ -488,9 +491,25 @@
{
final int masId = msg.arg1;
mConnectionManager.stopObexServerSession(masId);
+ //Dismiss CONNECTED Notification if no Active Connections
+ boolean stopFgNotification = true;
+ for (BluetoothMasObexConnection connection : mConnectionManager.mConnections) {
+ if (connection.mConnSocket != null) {
+ if(VERBOSE) Log.v(TAG,"Active Session exists ");
+ stopFgNotification = false;
+ break;
+ }
+ }
+ if(stopFgNotification == true){
+ stopForeground(true);
+ mConnectedNotification=null;
+ }
break;
}
case MSG_SESSION_ESTABLISHED:
+ if(mConnectedNotification == null)
+ mConnectedNotification = createMapConnectedNotification(mRemoteDevice);
+ startForeground(NOTIFICATION_ID_CONNECTED, mConnectedNotification);
break;
case MSG_SESSION_DISCONNECTED:
break;
@@ -500,6 +519,24 @@
}
};
+ private Notification createMapConnectedNotification(BluetoothDevice device) {
+ if (VERBOSE) Log.v(TAG, "Creating MAS access CONNECTED");
+
+ Notification notification = new Notification(android.R.drawable.stat_sys_data_bluetooth,
+ getString(R.string.map_notif_active_session), System.currentTimeMillis());
+ String name = device.getName();
+ if (TextUtils.isEmpty(name)) {
+ name = getString(R.string.defaultname);
+ }
+ notification.setLatestEventInfo(this, getString(R.string.map_notif_active_session),
+ getString( R.string.map_notif_connected ,name), null);
+ notification.flags |= Notification.FLAG_AUTO_CANCEL;
+ notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
+ notification.defaults = Notification.DEFAULT_SOUND;
+ return notification;
+
+
+ }
private void createMapNotification(BluetoothDevice device) {
if (VERBOSE) Log.v(TAG, "Creating MAS access notification");
mIsRequestBeingNotified = true;
@@ -924,7 +961,6 @@
Log.i(TAG, "CONNECTION SOCKET NULL");
break;
}
-
mRemoteDevice = mConnSocket.getRemoteDevice();
if (mRemoteDevice == null) {
Log.i(TAG, "getRemoteDevice() = null");