Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 54e54b1e authored by Zhihai Xu's avatar Zhihai Xu Committed by Android (Google) Code Review
Browse files

Merge "Unable to receive Text Message to CAR Kit(nuvi3580LM)" into klp-dev

parents a98645d2 a8ae9a36
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ public class BluetoothMapObexServer extends ServerRequestHandler {

    private BluetoothMapFolderElement mCurrentFolder;

    private BluetoothMnsObexClient mMnsClient;

    private Handler mCallback = null;

    private Context mContext;
@@ -68,12 +70,13 @@ public class BluetoothMapObexServer extends ServerRequestHandler {

    BluetoothMapContent mOutContent;

    public BluetoothMapObexServer(Handler callback, Context context) {
    public BluetoothMapObexServer(Handler callback, Context context,
                                  BluetoothMnsObexClient mns) {
        super();
        mCallback = callback;
        mContext = context;
        mOutContent = new BluetoothMapContent(mContext);

        mMnsClient = mns;
        buildFolderStructure(); /* Build the default folder structure, and set
                                   mCurrentFolder to root folder */
    }
@@ -213,13 +216,14 @@ public class BluetoothMapObexServer extends ServerRequestHandler {

    private int setNotificationRegistration(BluetoothMapAppParams appParams) {
        // Forward the request to the MNS thread as a message - including the MAS instance ID.
        Handler mns = BluetoothMnsObexClient.getMessageHandler();
        Handler mns = mMnsClient.getMessageHandler();
        if(mns != null) {
            Message msg = Message.obtain(mns);
            msg.what = BluetoothMnsObexClient.MSG_MNS_NOTIFICATION_REGISTRATION;
            msg.arg1 = 0; // TODO: Add correct MAS ID, as specified in the SDP record.
            msg.arg2 = appParams.getNotificationStatus();
            msg.sendToTarget();
            if(D) Log.d(TAG,"MSG_MNS_NOTIFICATION_REGISTRATION");
            return ResponseCodes.OBEX_HTTP_OK;
        } else {
            return ResponseCodes.OBEX_HTTP_UNAVAILABLE; // This should not happen.
@@ -248,7 +252,7 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
            bMsgStream = op.openInputStream();
            message = BluetoothMapbMessage.parse(bMsgStream, appParams.getCharset()); // Decode the messageBody
            // Send message
            BluetoothMapContentObserver observer = BluetoothMnsObexClient.getContentObserver();
            BluetoothMapContentObserver observer = mMnsClient.getContentObserver();
            if (observer == null) {
                return ResponseCodes.OBEX_HTTP_UNAVAILABLE; // Should not happen.
            }
@@ -287,7 +291,7 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
           msgHandle == null) {
            return ResponseCodes.OBEX_HTTP_PRECON_FAILED;
        }
        BluetoothMapContentObserver observer = BluetoothMnsObexClient.getContentObserver();
        BluetoothMapContentObserver observer = mMnsClient.getContentObserver();
        if (observer == null) {
            return ResponseCodes.OBEX_HTTP_UNAVAILABLE; // Should not happen.
        }
+40 −44
Original line number Diff line number Diff line
@@ -268,6 +268,12 @@ public class BluetoothMapService extends ProfileService {
        }

        closeConnectionSocket();

        if (mSessionStatusHandler != null) {
            mSessionStatusHandler.removeCallbacksAndMessages(null);
        }
        isWaitingAuthorization = false;

        if (VERBOSE) Log.v(TAG, "MAP Service closeService out");
    }

@@ -283,8 +289,9 @@ public class BluetoothMapService extends ProfileService {
            mWakeLock.acquire();
        }


        mMapServer = new BluetoothMapObexServer(mSessionStatusHandler, this);
        mBluetoothMnsObexClient = new BluetoothMnsObexClient(this, mRemoteDevice);
        mMapServer = new BluetoothMapObexServer(mSessionStatusHandler, this,
                                                mBluetoothMnsObexClient);
        synchronized (this) {
            // We need to get authentication now that obex server is up
            mAuth = new BluetoothMapAuthenticator(mSessionStatusHandler);
@@ -294,8 +301,6 @@ public class BluetoothMapService extends ProfileService {
        // setup RFCOMM transport
        BluetoothMapRfcommTransport transport = new BluetoothMapRfcommTransport(mConnSocket);
        mServerSession = new ServerSession(transport, mMapServer, mAuth);
        mBluetoothMnsObexClient = new BluetoothMnsObexClient(this, mRemoteDevice);
        mBluetoothMnsObexClient.start(); // Initiate the MNS message loop.
        setState(BluetoothMap.STATE_CONNECTED);
        if (VERBOSE) {
            Log.v(TAG, "startObexServerSession() success!");
@@ -615,10 +620,6 @@ public class BluetoothMapService extends ProfileService {

        setState(BluetoothMap.STATE_DISCONNECTED, BluetoothMap.RESULT_CANCELED);
        closeService();
        if(mSessionStatusHandler != null) {
            mSessionStatusHandler.removeCallbacksAndMessages(null);
        }
        isWaitingAuthorization = false;
        return true;
    }

@@ -626,10 +627,6 @@ public class BluetoothMapService extends ProfileService {
        if (DEBUG) Log.d(TAG, "cleanup()");
        setState(BluetoothMap.STATE_DISCONNECTED, BluetoothMap.RESULT_CANCELED);
        closeService();
        if(mSessionStatusHandler != null) {
            mSessionStatusHandler.removeCallbacksAndMessages(null);
        }
        isWaitingAuthorization = false;
        return true;
    }

@@ -647,7 +644,6 @@ public class BluetoothMapService extends ProfileService {
                    if (DEBUG) Log.d(TAG, "STATE_TURNING_OFF");
                    // Release all resources
                    closeService();
                    isWaitingAuthorization = false;
                } else if (state == BluetoothAdapter.STATE_ON) {
                    if (DEBUG) Log.d(TAG, "STATE_ON");
                    mInterrupted = false;
+39 −44
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.ParcelUuid;
@@ -43,27 +44,23 @@ import javax.obex.ResponseCodes;
 * hence all call-backs (and thereby transmission of data) is executed
 * from this thread.
 */
public class BluetoothMnsObexClient extends Thread{
public class BluetoothMnsObexClient {

    private static final String TAG = "BluetoothMnsObexClient";
    private static final boolean D = false;
    private static final boolean V = false;

    public final static int MSG_SESSION_ERROR = 1;
    public final static int MSG_CONNECT_TIMEOUT = 2;

    private ObexTransport mTransport;
    private Context mContext;
    public static Handler mHandler = null;
    public Handler mHandler = null;
    private volatile boolean mWaitingForRemote;
    private static final String TYPE_EVENT = "x-bt/MAP-event-report";
    private ClientSession mClientSession;
    private boolean mConnected = false;
    BluetoothDevice mRemoteDevice;
    private static BluetoothMapContentObserver mObserver;
    private BluetoothMapContentObserver mObserver;
    private boolean mObserverRegistered = false;

    private Looper mLooper = null;
    // Used by the MAS to forward notification registrations
    public static final int MSG_MNS_NOTIFICATION_REGISTRATION = 1;

@@ -76,31 +73,30 @@ public class BluetoothMnsObexClient extends Thread{
        if (remoteDevice == null) {
            throw new NullPointerException("Obex transport is null");
        }
        HandlerThread thread = new HandlerThread("BluetoothMnsObexClient");
        thread.start();
        Looper looper = thread.getLooper();
        mHandler = new MnsObexClientHandler(looper);
        mContext = context;
        mRemoteDevice = remoteDevice;
        mObserver = new BluetoothMapContentObserver(mContext);
        mObserver.init();
    }

    public static Handler getMessageHandler() {
        // TODO: if mHandle is null, we should wait for it to be created.
    public Handler getMessageHandler() {
        return mHandler;
    }

    public static BluetoothMapContentObserver getContentObserver() {
    public BluetoothMapContentObserver getContentObserver() {
        return mObserver;
    }

    @Override
    public void run() {
        Looper.prepare();
        mLooper = Looper.myLooper();


        /* Create the context observer from within the thread to ensure the "content changed"
         * events are handled in this thread. */
        mObserver = new BluetoothMapContentObserver(mContext);
        mObserver.init();
    private final class MnsObexClientHandler extends Handler {
        private MnsObexClientHandler(Looper looper) {
            super(looper);
        }

        mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case MSG_MNS_NOTIFICATION_REGISTRATION:
@@ -110,8 +106,6 @@ public class BluetoothMnsObexClient extends Thread{
                break;
            }
        }
        };
        Looper.loop();
    }

    public boolean isConnected() {
@@ -152,19 +146,19 @@ public class BluetoothMnsObexClient extends Thread{
            mObserver.unregisterObserver();
            mObserverRegistered = false;
        }

        if (mObserver != null) {
            mObserver.deinit();
            mObserver = null;
        }
        if (mHandler != null) {
            // Shut down the thread
        if(mLooper != null)
            mLooper.quit();
        interrupt();
        try {
            join();
        } catch (InterruptedException e) {
            if(V) Log.w(TAG, "got interrupted. Probably a connection shutdown");
            mHandler.removeCallbacksAndMessages(null);
            Looper looper = mHandler.getLooper();
            if (looper != null) {
                looper.quit();
            }
            mHandler = null;
        mObserver = null;
        }
    }

    private HeaderSet hsConnect = null;
@@ -172,7 +166,8 @@ public class BluetoothMnsObexClient extends Thread{
    public void handleRegistration(int masId, int notificationStatus){
        Log.d(TAG, "handleRegistration( " + masId + ", " + notificationStatus + ")");

        if(isConnected() == false) {
        if((isConnected() == false) &&
           (notificationStatus == BluetoothMapAppParams.NOTIFICATION_STATUS_YES)) {
            Log.d(TAG, "handleRegistration: connect");
            connect();
        }