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

Commit 8791667a authored by Gubbala Venugopal Rao's avatar Gubbala Venugopal Rao
Browse files

A2dp: Validate Current Device before Usage

Check for the validity of Current Device before usage to avoid
NULL Exception.

Change-Id: I3bbd961937df4a8070a7fe56a233037d6cd58b61
CRs-Fixed: 591361
parent 9da7ce94
Loading
Loading
Loading
Loading
+20 −10
Original line number Diff line number Diff line
@@ -206,6 +206,7 @@ final class A2dpStateMachine extends StateMachine {
                    break;
                case STACK_EVENT:
                    StackEvent event = (StackEvent) message.obj;
                    log("Stack Event: " + event.type);
                    switch (event.type) {
                        case EVENT_TYPE_CONNECTION_STATE_CHANGED:
                            processConnectionEvent(event.valueInt, event.device);
@@ -320,6 +321,7 @@ final class A2dpStateMachine extends StateMachine {
                    break;
                case STACK_EVENT:
                    StackEvent event = (StackEvent) message.obj;
                    log("Stack Event: " + event.type);
                    switch (event.type) {
                        case EVENT_TYPE_CONNECTION_STATE_CHANGED:
                            removeMessages(CONNECT_TIMEOUT);
@@ -546,6 +548,7 @@ final class A2dpStateMachine extends StateMachine {
                    break;
                case STACK_EVENT:
                    StackEvent event = (StackEvent) message.obj;
                    log("Stack Event: " + event.type);
                    switch (event.type) {
                        case EVENT_TYPE_CONNECTION_STATE_CHANGED:
                            processConnectionEvent(event.valueInt, event.device);
@@ -624,7 +627,7 @@ final class A2dpStateMachine extends StateMachine {
                                                           mCurrentDevice);
                return;
            }
            log("processAudioStateEvent  %d" + state);
            log("processAudioStateEvent  " + state);
            switch (state) {
                case AUDIO_STATE_STARTED:
                    if (mPlayingA2dpDevice == null) {
@@ -858,6 +861,7 @@ final class A2dpStateMachine extends StateMachine {
            log("onAudioFocusChangeListener  focuschange" + focusChange);
            switch(focusChange){
                case AudioManager.AUDIOFOCUS_LOSS:
                    if (mCurrentDevice != null) {
                        if (isSrcNative(getByteAddress(mCurrentDevice))) {
                            // in case of perm loss, disconnect the link
                            disconnectA2dpNative(getByteAddress(mCurrentDevice));
@@ -865,9 +869,14 @@ final class A2dpStateMachine extends StateMachine {
                            int status = mAudioManager.abandonAudioFocus(mAudioFocusListener);
                            log("abandonAudioFocus returned" + status);
                        }
                    } else {
                        int status = mAudioManager.abandonAudioFocus(mAudioFocusListener);
                        log("abandonAudioFocus returned" + status);
                    }
                    break;
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                    if ((getCurrentState() == mConnected)&& (isPlaying(mCurrentDevice))) {
                    if ((mCurrentDevice != null) && (getCurrentState() == mConnected) &&
                        (isPlaying(mCurrentDevice))) {
                        // we need to send AVDT_SUSPEND from here
                        suspendA2dpNative();
                    }
@@ -875,7 +884,8 @@ final class A2dpStateMachine extends StateMachine {
                case AudioManager.AUDIOFOCUS_GAIN:
                    // we got focus gain
                    log(" Received Focus Gain");
                    if ((getCurrentState() == mConnected)&& (!isPlaying(mCurrentDevice))){
                    if ((mCurrentDevice != null) && (getCurrentState() == mConnected) &&
                        (!isPlaying(mCurrentDevice))){
                        resumeA2dpNative();
                    }
                    break;