summaryrefslogtreecommitdiffstats
path: root/src/com/android/bluetooth/map
diff options
context:
space:
mode:
authorPradeep Panigrahi <pradeepp@codeaurora.org>2014-09-19 12:00:55 +0530
committerLinux Build Service Account <lnxbuild@localhost>2014-11-04 08:26:15 -0700
commitd4d4b642999ff3716ca78cb94010c13f8fe42f93 (patch)
treec220df7cb71f96e4e3c71a7879bf9b8ec92f00d7 /src/com/android/bluetooth/map
parent6710ad8d0b9ae08676c532150233bf7e72835ee2 (diff)
downloadandroid_packages_apps_Bluetooth-d4d4b642999ff3716ca78cb94010c13f8fe42f93.tar.gz
android_packages_apps_Bluetooth-d4d4b642999ff3716ca78cb94010c13f8fe42f93.tar.bz2
android_packages_apps_Bluetooth-d4d4b642999ff3716ca78cb94010c13f8fe42f93.zip
MAP: Add MAPEmail support in SDP only when email account available.
Register primary email account configuration or deletion to update MAP Email support dynamically from MAP Server SDP only when primary email is configured or available. CRs-fixed: 727015 Change-Id: I7328e210d51e7a15f1493e00846f22688ff03148
Diffstat (limited to 'src/com/android/bluetooth/map')
-rw-r--r--[-rwxr-xr-x]src/com/android/bluetooth/map/BluetoothMapService.java114
1 files changed, 113 insertions, 1 deletions
diff --git a/src/com/android/bluetooth/map/BluetoothMapService.java b/src/com/android/bluetooth/map/BluetoothMapService.java
index f3e7049df..7736f6429 100755..100644
--- a/src/com/android/bluetooth/map/BluetoothMapService.java
+++ b/src/com/android/bluetooth/map/BluetoothMapService.java
@@ -47,6 +47,13 @@ import android.util.Log;
import android.provider.Settings;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
+import android.net.Uri;
+import android.content.ContentResolver;
+import android.database.ContentObserver;
+import com.android.bluetooth.map.BluetoothMapUtils.*;
+import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
+import android.database.sqlite.SQLiteException;
+
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
@@ -113,6 +120,8 @@ public class BluetoothMapService extends ProfileService {
private static final int DISCONNECT_MAP = 3;
+ private static final int MSG_INTERNAL_REGISTER_EMAIL = 4;
+
private static final int RELEASE_WAKE_LOCK_DELAY = 10000;
private PowerManager.WakeLock mWakeLock = null;
@@ -163,12 +172,50 @@ public class BluetoothMapService extends ProfileService {
public static final int MAX_INSTANCES = 2;
BluetoothMapObexConnectionManager mConnectionManager = null;
public static final int MAS_INS_INFO[] = {MESSAGE_TYPE_SMS_MMS, MESSAGE_TYPE_EMAIL};
+ private ContentObserver mEmailAccountObserver;
+ public static final String AUTHORITY = "com.android.email.provider";
+ public static final Uri EMAIL_URI = Uri.parse("content://" + AUTHORITY);
+ public static final Uri EMAIL_ACCOUNT_URI = Uri.withAppendedPath(EMAIL_URI, "account");
+ public static boolean isMapEmailRequestON = false;
public BluetoothMapService() {
mState = BluetoothMap.STATE_DISCONNECTED;
mConnectionManager = new BluetoothMapObexConnectionManager();
if (VERBOSE)
Log.v(TAG, "BluetoothMapService: mIsEmailEnabled: " + mIsEmailEnabled);
+ mEmailAccountObserver = new ContentObserver(null) {
+ @Override
+ public void onChange(boolean selfChange) {
+ long isEmailConfigured = -1;
+ Context context = mConnectionManager.getEmailContext();
+ //Handle only email configuration changes
+ if (context != null )
+ isEmailConfigured = BluetoothMapUtils.getEmailAccountId(context) ;
+ boolean isMapEmailStarted = mConnectionManager.isMapEmailON();
+
+ if (VERBOSE) {
+ Log.v(TAG,"onChange mEmailAccountObserver Configured Account: "+ isEmailConfigured
+ + "IsMapEmailRequstInprogress " + isMapEmailRequestON + "isMAP AlreadyStarted "+ isMapEmailStarted);
+ }
+ if( mSessionStatusHandler.hasMessages(MSG_INTERNAL_REGISTER_EMAIL)) {
+ // Remove any pending requests in queue
+ mSessionStatusHandler.removeMessages(MSG_INTERNAL_REGISTER_EMAIL);
+ }
+ // Donot send request if Inprogress or already ON
+ if( isEmailConfigured != -1 && !isMapEmailRequestON && !isMapEmailStarted) {
+ if ( mAdapter != null) {
+ int state = mAdapter.getState();
+ if (state == BluetoothAdapter.STATE_ON ) {
+ mSessionStatusHandler.sendEmptyMessage(MSG_INTERNAL_REGISTER_EMAIL);
+ } else if (VERBOSE) {
+ Log.v(TAG, "BT is not ON, no start");
+ }
+ }
+ } else if(isEmailConfigured == -1) {
+ mConnectionManager.closeMapEmail();
+ }
+ }
+ };
}
private final void closeService() {
if (VERBOSE) Log.v(TAG, "closeService");
@@ -186,6 +233,14 @@ public class BluetoothMapService extends ProfileService {
mConnectionManager.startAll();
}
break;
+
+ case MSG_INTERNAL_REGISTER_EMAIL:
+ Log.d(TAG,"received MSG_INTERNAL_REGISTER_EMAIL");
+ if ((mAdapter != null) && mAdapter.isEnabled()) {
+ mConnectionManager.startMapEmail();
+ }
+ break;
+
case USER_TIMEOUT:
Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
@@ -381,6 +436,14 @@ public class BluetoothMapService extends ProfileService {
mSessionStatusHandler.sendMessage(mSessionStatusHandler
.obtainMessage(START_LISTENER));
}
+ // Register EmailAccountObserver for dynamic SDP update
+ try {
+ if (DEBUG) Log.d(TAG,"Registering observer");
+ getContentResolver().registerContentObserver(
+ EMAIL_ACCOUNT_URI, false, mEmailAccountObserver);
+ } catch (SQLiteException e) {
+ Log.e(TAG, "SQLite exception: " + e);
+ }
return true;
}
@@ -395,6 +458,12 @@ public class BluetoothMapService extends ProfileService {
setState(BluetoothMap.STATE_DISCONNECTED, BluetoothMap.RESULT_CANCELED);
closeService();
+ try {
+ if (DEBUG) Log.d(TAG,"Unregistering Email account observer");
+ getContentResolver().unregisterContentObserver(mEmailAccountObserver);
+ } catch (SQLiteException e) {
+ Log.e(TAG, "SQLite exception: " + e);
+ }
return true;
}
@@ -532,6 +601,39 @@ public class BluetoothMapService extends ProfileService {
connection.startRfcommSocketListener();
}
}
+ public boolean isMapEmailON () {
+ final BluetoothMapObexConnection connect = mConnections.get(1);
+ if(connect != null && connect.mMasId == 1 && connect.mServerSocket != null
+ && connect.mAcceptThread != null )
+ return true;
+ return false;
+ }
+ public Context getEmailContext () {
+ final BluetoothMapObexConnection connect = mConnections.get(1);
+ return connect.context;
+ }
+ public void startMapEmail() {
+ final BluetoothMapObexConnection connect = mConnections.get(1);
+ if (connect != null) {
+ // SET Email Inprogress ON
+ isMapEmailRequestON = true;
+ // Start Listener and add email support in SDP
+ connect.startRfcommSocketListener();
+ }
+ // SET Email Inprogress OFF
+ isMapEmailRequestON = false;
+ }
+
+ public void closeMapEmail() {
+ final BluetoothMapObexConnection connect = mConnections.get(1);
+ if (connect != null) {
+ // Handle common flag for MAP instances
+ boolean isWaitingAuth = isWaitingAuthorization;
+ // Stop Listener and remove email support in SDP
+ connect.closeConnection();
+ isWaitingAuthorization = isWaitingAuth;
+ }
+ }
public void init() {
for (BluetoothMapObexConnection connection: mConnections) {
@@ -584,6 +686,7 @@ public class BluetoothMapService extends ProfileService {
private ServerSession mServerSession = null;
private int mSupportedMessageTypes;
private int mMasId;
+ private Context context;
boolean mWaitingForConfirmation = false;
public BluetoothMapObexConnection(int supportedMessageTypes, int masId) {
@@ -599,6 +702,16 @@ public class BluetoothMapService extends ProfileService {
Log.v(TAG, "Map Service startRfcommSocketListener");
Log.v(TAG, "mMasId is "+mMasId);
}
+
+ context = getApplicationContext();
+ // Promote Email Instance only if primary email account configured
+ if(mMasId == 1) {
+ if (BluetoothMapUtils.getEmailAccountId(context) == -1) {
+ if (VERBOSE) Log.v(TAG, "account is not configured");
+ return;
+ }
+ }
+
if (mServerSocket == null) {
if (!initSocket()) {
closeConnection();
@@ -728,7 +841,6 @@ public class BluetoothMapService extends ProfileService {
Log.d(TAG, "Map Service startObexServerSession");
Log.d(TAG, "mMasId is "+mMasId);
}
- Context context = getApplicationContext();
if(VERBOSE) Log.d(TAG, "after getting application context");
if(mBluetoothMnsObexClient == null)
mBluetoothMnsObexClient = new BluetoothMnsObexClient(context, mRemoteDevice);