arekolek / simple-phone

Bare minimum implementation of an Android Phone app
MIT License
198 stars 71 forks source link

Ongoing.call is sometimes null in when answer/hangup #12

Closed max-mayorov closed 5 months ago

max-mayorov commented 4 years ago

Hello,

Thanks for this little app, it is really amazing! However, recently I receive kotlin.KotlinNullPointerException in OngoingCall.answer with stack trace:

com.github.arekolek.phone.OngoingCall.answer OngoingCall.kt:29
com.github.arekolek.phone.CallActivity$onStart$7.invoke CallActivity.kt:85
com.github.arekolek.phone.CallActivity$onStart$7.invoke CallActivity.kt:27
com.github.arekolek.phone.CallActivity$subscribeWithDelay$2.accept CallActivity.kt:128
io.reactivex.internal.observers.LambdaObserver.onNext LambdaObserver.java:63
io.reactivex.observers.SerializedObserver.onNext SerializedObserver.java:111
io.reactivex.internal.operators.observable.ObservableDelay$DelayObserver$OnNext.run ObservableDelay.java:114
io.reactivex.internal.schedulers.ScheduledRunnable.run ScheduledRunnable.java:66
io.reactivex.internal.schedulers.ScheduledRunnable.call ScheduledRunnable.java:57
java.util.concurrent.FutureTask.run FutureTask.java:266

The stack trace is not showing CallActivity$onStart$.onClick because here I pickup phone automatically with delay in CallActivity

        // Autopickup with delay
        OngoingCall.state
                .filter{ it == Call.STATE_RINGING && isAutopickup() }
                .subscribeWithDelay(
                        Random.nextLong(pickupDelayFrom, pickupDelayTo),
                        "$autopickupNumber will be picked after {delay} sec"
                ) { OngoingCall.answer()
                    muteMic() }
                .addTo(disposables)

I was looking through the code and I really can't see a situation when OngoingCall.call will be null at this step...

Maybe you have any ideas on why this could happen? So I can try to build a workaround...

Kind regards! Max