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

Commit 367de85b authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Simplify the setA2dpService() implementation so it is less error prone

This fixes A2DP connectivity issue.

Previously, the setA2dpService() was checking whether the A2dpService
itself was available. However, setA2dpService() is called
during A2dpService.start(), hence at that time the service is not
ready yet.
In the past, setA2dpService() worked because ProfileService.isAvailable()
was returning true even before the corresponding service had finished
the start() execution.

Also, simplify the getA2dpService() error handling.

Fixes: 72574372
Test: Manual
Change-Id: I52f86f24bba2309e3ed979ba6bf64a9bf9e1fb78
parent c005f73b
Loading
Loading
Loading
Loading
+10 −21
Original line number Diff line number Diff line
@@ -192,37 +192,26 @@ public class A2dpService extends ProfileService {
    }

    public static synchronized A2dpService getA2dpService() {
        if (sA2dpService != null && sA2dpService.isAvailable()) {
        if (sA2dpService == null) {
            if (DBG) {
                Log.d(TAG, "getA2dpService(): returning " + sA2dpService);
                Log.d(TAG, "getA2dpService(): service is NULL");
            }
            return sA2dpService;
            return null;
        }
        if (!sA2dpService.isAvailable()) {
            if (DBG) {
            if (sA2dpService == null) {
                Log.d(TAG, "getA2dpService(): service is NULL");
            } else if (!(sA2dpService.isAvailable())) {
                Log.d(TAG, "getA2dpService(): service is not available");
            }
        }
            return null;
        }
        return sA2dpService;
    }

    private static synchronized void setA2dpService(A2dpService instance) {
        if (instance != null && instance.isAvailable()) {
        if (DBG) {
            Log.d(TAG, "setA2dpService(): set to: " + instance);
        }
        sA2dpService = instance;
        } else {
            if (DBG) {
                if (sA2dpService == null) {
                    Log.d(TAG, "setA2dpService(): service not available");
                } else if (!sA2dpService.isAvailable()) {
                    Log.d(TAG, "setA2dpService(): service is cleaning up");
                }
            }
        }
    }

    private static synchronized void clearA2dpService() {