summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAshwini Munigala <AshwiniM@codeaurora.org>2013-07-09 11:08:36 +0530
committerAshwini Munigala <AshwiniM@codeaurora.org>2013-07-09 11:08:36 +0530
commitddf68064e76f05c71ba9584483068eb8f4179aa5 (patch)
tree2dac6a6646d6ac59cdd765224c14604b9eb4285f /src
parent77b4192fe6764babf541c23bd9260c8ce5430581 (diff)
downloadandroid_packages_apps_BluetoothExt-ddf68064e76f05c71ba9584483068eb8f4179aa5.tar.gz
android_packages_apps_BluetoothExt-ddf68064e76f05c71ba9584483068eb8f4179aa5.tar.bz2
android_packages_apps_BluetoothExt-ddf68064e76f05c71ba9584483068eb8f4179aa5.zip
MAP: Fix Issues for MAP Server on Bluedroid.
Handle SDP registeration and serversocket binding on START/STOP MAP Service, instead from every MAP session CONNECT/DISCONNECT . Allow EMPTY Recipient address for pushEmail Drafts. MAP and FTP concurrency issue fix. Optimization for retreiving email message size for GetMessagesListing Email. Reject pushSMS for Vcard containing , or ; in Tel entry. Change-Id: I738c416c2ea1296ea2b0af193bc5240d22a77185 CRs-fixed: 504042
Diffstat (limited to 'src')
-rw-r--r--src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java8
-rw-r--r--src/org/codeaurora/bluetooth/map/BluetoothMasAppEmail.java15
-rw-r--r--src/org/codeaurora/bluetooth/map/BluetoothMasService.java88
-rw-r--r--src/org/codeaurora/bluetooth/map/MapUtils/EmailUtils.java18
-rw-r--r--src/org/codeaurora/bluetooth/map/MapUtils/MapUtils.java10
5 files changed, 80 insertions, 59 deletions
diff --git a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
index 9a18cc6..2f9c2c9 100644
--- a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
+++ b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
@@ -339,7 +339,7 @@ public class BluetoothFtpService extends Service {
notifyAuthCancelled();
removeAuthChallTimer();
removeFtpNotification(NOTIFICATION_ID_ACCESS);
- } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
+ } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED) && isWaitingAuthorization) {
BluetoothDevice device =
intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (device != null && device.equals(mRemoteDevice)) {
@@ -457,12 +457,14 @@ public class BluetoothFtpService extends Service {
if (mRfcommServerSocket != null) {
mRfcommServerSocket.close();
+ mRfcommServerSocket =null ;
}
}
if (accept == true) {
if (mConnSocket != null) {
mConnSocket.close();
+ mConnSocket = null;
}
}
}
@@ -490,9 +492,6 @@ public class BluetoothFtpService extends Service {
}
}
- mRfcommServerSocket = null;
- mConnSocket = null;
-
mHasStarted = false;
if (stopSelfResult(mStartId)) {
if (VERBOSE) Log.v(TAG, "successfully stopped ftp service");
@@ -557,7 +556,6 @@ public class BluetoothFtpService extends Service {
try {
closeRfcommSocket(false, true);
- mConnSocket = null;
} catch (IOException e) {
Log.e(TAG, "closeSocket error: " + e.toString());
}
diff --git a/src/org/codeaurora/bluetooth/map/BluetoothMasAppEmail.java b/src/org/codeaurora/bluetooth/map/BluetoothMasAppEmail.java
index f827205..27fc0cd 100644
--- a/src/org/codeaurora/bluetooth/map/BluetoothMasAppEmail.java
+++ b/src/org/codeaurora/bluetooth/map/BluetoothMasAppEmail.java
@@ -689,13 +689,6 @@ public class BluetoothMasAppEmail extends BluetoothMasAppIf {
String readStr, String name) throws BadRequestException {
if (V) Log.v(TAG, " Before fromBmessageemail method:: "+readStr);
- BmessageConsts bMsg = MapUtils.fromBmessageEmail(mContext,readStr,mMasId);
- String address = bMsg.getRecipientVcard_email();
- String text = bMsg.getBody_msg();
- String subject = bMsg.getSubject();
- String originator = bMsg.getOriginatorVcard_email();
- String origName = bMsg.getOriginatorVcard_name();
-
String fullPath = (name == null || name.length() == 0)
? mCurrentPath : mCurrentPath + "/" + name;
String splitStrings[] = fullPath.split("/");
@@ -711,6 +704,14 @@ public class BluetoothMasAppEmail extends BluetoothMasAppIf {
} else {
folderName = splitStrings[tmp - 1];
}
+
+ BmessageConsts bMsg = MapUtils.fromBmessageEmail(mContext, readStr, mMasId, folderName);
+ String address = bMsg.getRecipientVcard_email();
+ String text = bMsg.getBody_msg();
+ String subject = bMsg.getSubject();
+ String originator = bMsg.getOriginatorVcard_email();
+ String origName = bMsg.getOriginatorVcard_name();
+
if (!isAllowedEmailFolderForPush(folderName)) {
rsp.msgHandle = null;
rsp.response = ResponseCodes.OBEX_HTTP_FORBIDDEN;
diff --git a/src/org/codeaurora/bluetooth/map/BluetoothMasService.java b/src/org/codeaurora/bluetooth/map/BluetoothMasService.java
index e53c2f3..9ab9ecc 100644
--- a/src/org/codeaurora/bluetooth/map/BluetoothMasService.java
+++ b/src/org/codeaurora/bluetooth/map/BluetoothMasService.java
@@ -803,15 +803,32 @@ public class BluetoothMasService extends Service {
return initSocketOK;
}
- private final void closeSocket() throws IOException {
- if (mConnSocket != null) {
- mConnSocket.close();
- mConnSocket = null;
- }
- }
+ private final void closeRfcommSocket(boolean server, boolean accept) throws IOException {
+ if (server == true) {
+ // Stop the possible trying to init serverSocket
+ mInterrupted = false;
+
+ if (mServerSocket != null) {
+ mServerSocket.close();
+ mServerSocket =null ;
+ }
+ }
+
+ if (accept == true) {
+ if (mConnSocket != null) {
+ mConnSocket.close();
+ mConnSocket = null;
+ }
+ }
+ }
public void closeConnection() {
if (VERBOSE) Log.v(TAG, "Mas connection closing");
+ try {
+ closeRfcommSocket(true, true);
+ } catch (IOException ex) {
+ Log.e(TAG, "CloseSocket error: " + ex);
+ }
if (mAcceptThread != null) {
try {
@@ -829,11 +846,6 @@ public class BluetoothMasService extends Service {
mServerSession = null;
}
- try {
- closeSocket();
- } catch (IOException ex) {
- Log.e(TAG, "CloseSocket error: " + ex);
- }
if (VERBOSE) Log.v(TAG, "Mas connection closed");
}
@@ -875,7 +887,27 @@ public class BluetoothMasService extends Service {
private void stopObexServerSession() {
if (VERBOSE) Log.v(TAG, "Map Service stopObexServerSession ");
- closeConnection();
+ try {
+ closeRfcommSocket(false, true);
+ } catch (IOException ex) {
+ Log.e(TAG, "CloseSocket error: " + ex);
+ }
+
+ if (mAcceptThread != null) {
+ try {
+ mAcceptThread.shutdown();
+ mAcceptThread.join();
+ } catch (InterruptedException ex) {
+ Log.w(TAG, "mAcceptThread close error" + ex);
+ } finally {
+ mAcceptThread = null;
+ }
+ }
+
+ if (mServerSession != null) {
+ mServerSession.close();
+ mServerSession = null;
+ }
// Last obex transaction is finished, we start to listen for incoming
// connection again
@@ -904,28 +936,30 @@ public class BluetoothMasService extends Service {
public void run() {
while (!stopped) {
try {
- BluetoothSocket connSocket = mServerSocket.accept();
+ mConnSocket = mServerSocket.accept();
+ if (mConnSocket == null) {
+ Log.i(TAG, "CONNECTION SOCKET NULL");
+ break;
+ }
- BluetoothDevice device = connSocket.getRemoteDevice();
- mRemoteDevice = device;
- if (device == null) {
+ mRemoteDevice = mConnSocket.getRemoteDevice();
+ if (mRemoteDevice == null) {
Log.i(TAG, "getRemoteDevice() = null");
break;
}
- String remoteDeviceName = device.getName();
+ String remoteDeviceName = mRemoteDevice.getName();
// In case getRemoteName failed and return null
if (TextUtils.isEmpty(remoteDeviceName)) {
remoteDeviceName = getString(R.string.defaultname);
}
- if (!mConnectionManager.isAllowedConnection(device)) {
- connSocket.close();
+ if (!mConnectionManager.isAllowedConnection(mRemoteDevice)) {
+ mConnSocket.close();
continue;
}
- mConnSocket = connSocket;
boolean trust = false;
if (trustDevices != null)
- trust = trustDevices.contains(device);
+ trust = trustDevices.contains(mRemoteDevice);
if (VERBOSE) Log.v(TAG, "GetTrustState() = " + trust);
if (mIsRequestBeingNotified) {
if (VERBOSE) Log.v(TAG, "Request notification is still on going.");
@@ -938,7 +972,7 @@ public class BluetoothMasService extends Service {
+ remoteDeviceName + " automatically as trusted device");
}
try {
- startObexServerSession(device, mnsObj);
+ startObexServerSession(mRemoteDevice, mnsObj);
} catch (IOException ex) {
Log.e(TAG, "catch exception starting obex server session"
+ ex.toString());
@@ -946,7 +980,7 @@ public class BluetoothMasService extends Service {
} else {
if (VERBOSE) Log.v(TAG, "trust is false.");
mConnectionManager.setWaitingForConfirmation(mMasId);
- createMapNotification(device);
+ createMapNotification(mRemoteDevice);
if (VERBOSE) Log.v(TAG, "incomming connection accepted from: "
+ remoteDeviceName);
mSessionStatusHandler.sendMessageDelayed(
@@ -968,14 +1002,6 @@ public class BluetoothMasService extends Service {
if (VERBOSE) Log.v(TAG, "AcceptThread shutdown for MAS id: " + mMasId);
stopped = true;
interrupt();
- if (mServerSocket != null) {
- try {
- mServerSocket.close();
- mServerSocket = null;
- } catch (IOException e) {
- Log.e(TAG, "Failed to close socket", e);
- }
- }
}
}
}
diff --git a/src/org/codeaurora/bluetooth/map/MapUtils/EmailUtils.java b/src/org/codeaurora/bluetooth/map/MapUtils/EmailUtils.java
index 5f92b3c..e333b34 100644
--- a/src/org/codeaurora/bluetooth/map/MapUtils/EmailUtils.java
+++ b/src/org/codeaurora/bluetooth/map/MapUtils/EmailUtils.java
@@ -140,25 +140,19 @@ public class EmailUtils {
if (V){
Log.v(TAG, ":: Message Id in getMessageSizeEmail ::"+ messageId);
}
- int msgSize = 0;
+ int msgSize = -1;
+ String[] EMAIL_MSGSIZE_PROJECTION = new String[] { "LENGTH(textContent)", "LENGTH(htmlContent)" };
String textContent, htmlContent;
Uri uri = Uri.parse("content://com.android.email.provider/body");
Cursor cr = context.getContentResolver().query(
- uri, null, "messageKey = "+ messageId , null, null);
+ uri, EMAIL_MSGSIZE_PROJECTION, "messageKey = "+ messageId , null, null);
if (cr != null && cr.moveToFirst()) {
do {
- textContent = cr.getString(cr.getColumnIndex("textContent"));
- htmlContent = cr.getString(cr.getColumnIndex("htmlContent"));
- if(textContent != null && textContent.length() != 0){
- msgSize = textContent.length();
- }
- else if(textContent == null){
- if(htmlContent != null && htmlContent.length() != 0){
- msgSize = htmlContent.length();
- }
- }
+ msgSize = cr.getInt(0);
+ if(msgSize == -1 || msgSize == 0)
+ msgSize = cr.getInt(1);
break;
} while (cr.moveToNext());
}
diff --git a/src/org/codeaurora/bluetooth/map/MapUtils/MapUtils.java b/src/org/codeaurora/bluetooth/map/MapUtils/MapUtils.java
index 6def60e..f2f6f31 100644
--- a/src/org/codeaurora/bluetooth/map/MapUtils/MapUtils.java
+++ b/src/org/codeaurora/bluetooth/map/MapUtils/MapUtils.java
@@ -59,6 +59,7 @@ import static com.android.vcard.VCardConstants.PROPERTY_N;
import static com.android.vcard.VCardConstants.PROPERTY_TEL;
import static com.android.vcard.VCardConstants.VERSION_V21;
import static com.android.vcard.VCardConstants.VERSION_V30;
+import static org.codeaurora.bluetooth.map.MapUtils.SmsMmsUtils.DRAFT;
/**
* MapUtils is a class of utility methods that provide routines for converting
@@ -920,7 +921,7 @@ public class MapUtils {
String vCard = fetchRecipientVcard(bmsg);
RecipientVCard recipient = parseVCard(vCard);
- if (recipient.mTel.length() == 0) {
+ if (recipient.mTel.length() == 0 || recipient.mTel.contains(",") || recipient.mTel.contains(";")) {
throw new BadRequestException("No TEL in vCard");
}
bMsgObj.setRecipientVcard_phone_number(recipient.mTel);
@@ -974,7 +975,8 @@ public class MapUtils {
RecipientVCard recipient = parseVCard(vCard);
if (recipient.mEmail.length() > 0) {
phoneNumber = recipient.mEmail;
- } else if (recipient.mTel.length() > 0) {
+ } else if (recipient.mTel.length() == 0 || recipient.mTel.contains(",")
+ || recipient.mTel.contains(";")) {
phoneNumber = recipient.mTel;
} else {
throw new BadRequestException("No Email/Tel in vCard");
@@ -1024,13 +1026,13 @@ public class MapUtils {
*/
public static BmessageConsts fromBmessageEmail(Context context,
- String bmsg, int mMasId) throws BadRequestException {
+ String bmsg, int mMasId, String folderName) throws BadRequestException {
BmessageConsts bMsgObj = new BmessageConsts();
String vCard = fetchRecipientVcard(bmsg);
if (V) Log.v(TAG, "vCard Info: " + vCard);
RecipientVCard recipient = parseVCard(vCard);
- if (recipient.mEmail.length() == 0) {
+ if (recipient.mEmail.length() == 0 && !(DRAFT.equalsIgnoreCase(folderName))) {
throw new BadRequestException("No Email in recipient vCard");
}
bMsgObj.setRecipientVcard_email(recipient.mEmail);