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

Commit aad1ef6e authored by Hemant Gupta's avatar Hemant Gupta
Browse files

MAP: Fix MNS observer sync and sendevent exception issue.

Allow MNS Client sendEvent only when MNS Client is registered
and connected to fix NullPointer exceptions. Mark MNS disconnect
and observer registration as synchronized to handle synchronization
for operations from worker and main threads.

Change-Id: If34a6b67a1774f693ed42cfb6c871cd9563abe55
parent a7caae91
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -262,8 +262,8 @@ public class BluetoothMapContentObserver {
        Log.d(TAG, "sendEvent: " + evt.eventType + " " + evt.handle + " "
        Log.d(TAG, "sendEvent: " + evt.eventType + " " + evt.handle + " "
        + evt.folder + " " + evt.oldFolder + " " + evt.msgType.name());
        + evt.folder + " " + evt.oldFolder + " " + evt.msgType.name());


        if (mMnsClient == null) {
        if (mMnsClient == null || mMnsClient.isConnected() == false) {
            Log.d(TAG, "sendEvent: No MNS client registered - don't send event");
            Log.d(TAG, "sendEvent: No MNS client registered or connected- don't send event");
            return;
            return;
        }
        }


+6 −4
Original line number Original line Diff line number Diff line
@@ -119,7 +119,7 @@ public class BluetoothMnsObexClient {
     * Disconnect the connection to MNS server.
     * Disconnect the connection to MNS server.
     * Call this when the MAS client requests a de-registration on events.
     * Call this when the MAS client requests a de-registration on events.
     */
     */
    public void disconnect() {
    public synchronized void disconnect() {
        try {
        try {
            if (mClientSession != null) {
            if (mClientSession != null) {
                mClientSession.disconnect(null);
                mClientSession.disconnect(null);
@@ -203,12 +203,14 @@ public class BluetoothMnsObexClient {
            /* Connect if we do not have a connection, and start the content observers providing
            /* Connect if we do not have a connection, and start the content observers providing
             * this thread as Handler.
             * this thread as Handler.
             */
             */
            if(mObserverRegistered == false) {
            synchronized (this) {
                if(mObserverRegistered == false && mObserver != null) {
                    mObserver.registerObserver(this, masId);
                    mObserver.registerObserver(this, masId);
                    mObserverRegistered = true;
                    mObserverRegistered = true;
                }
                }
            }
            }
        }
        }
    }


    public void connect() {
    public void connect() {
        Log.d(TAG, "handleRegistration: connect 2");
        Log.d(TAG, "handleRegistration: connect 2");