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

Commit bd308ffb authored by Kyunglyul Hyun's avatar Kyunglyul Hyun
Browse files

Ensure UpdateNotificationThread being terminated

There are cases where the NotificationUpdateThread
continues running after a test finishes.
This can interfere with susequent tests and
potentially cause failures.

Ensure the thread is terminated to prevent these issuse.

Flag: EXEMPT, test change
Bug: 369936658
Test: atest BluetoothOppServiceCleanupTest BluetoothOppServiceTest
--iterations 100

Change-Id: Iaddd50df409c335019213de3b21d741808e4d2ec
parent 9dfd223e
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -141,7 +141,7 @@ class BluetoothOppNotification {


    private final HashMap<String, NotificationItem> mNotifications = new HashMap<>();
    private final HashMap<String, NotificationItem> mNotifications = new HashMap<>();


    private NotificationUpdateThread mUpdateNotificationThread;
    @VisibleForTesting NotificationUpdateThread mUpdateNotificationThread;


    private int mPendingUpdate = 0;
    private int mPendingUpdate = 0;


+1 −1
Original line number Original line Diff line number Diff line
@@ -135,7 +135,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
    private BluetoothShareContentObserver mObserver;
    private BluetoothShareContentObserver mObserver;


    /** Class to handle Notification Manager updates */
    /** Class to handle Notification Manager updates */
    private BluetoothOppNotification mNotifier;
    @VisibleForTesting BluetoothOppNotification mNotifier;


    private boolean mPendingUpdate;
    private boolean mPendingUpdate;


+9 −2
Original line number Original line Diff line number Diff line
@@ -46,7 +46,7 @@ public class BluetoothOppServiceCleanupTest {


    @Test
    @Test
    @UiThreadTest
    @UiThreadTest
    public void testStopAndCleanup() {
    public void testStopAndCleanup() throws Exception {
        AdapterService adapterService = new AdapterService(mTargetContext);
        AdapterService adapterService = new AdapterService(mTargetContext);


        // Don't need to disable again since it will be handled in OppService.stop
        // Don't need to disable again since it will be handled in OppService.stop
@@ -58,8 +58,9 @@ public class BluetoothOppServiceCleanupTest {
            mTargetContext.getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
            mTargetContext.getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
        }
        }


        BluetoothOppService service = null;
        try {
        try {
            BluetoothOppService service = new BluetoothOppService(adapterService);
            service = new BluetoothOppService(adapterService);
            service.start();
            service.start();
            service.setAvailable(true);
            service.setAvailable(true);


@@ -67,6 +68,12 @@ public class BluetoothOppServiceCleanupTest {
            service.stop();
            service.stop();
            service.cleanup();
            service.cleanup();
        } finally {
        } finally {
            if (service != null) {
                Thread updateNotificationThread = service.mNotifier.mUpdateNotificationThread;
                if (updateNotificationThread != null) {
                    updateNotificationThread.join();
                }
            }
            mTargetContext.getContentResolver().delete(BluetoothShare.CONTENT_URI, null, null);
            mTargetContext.getContentResolver().delete(BluetoothShare.CONTENT_URI, null, null);
        }
        }
    }
    }
+4 −0
Original line number Original line Diff line number Diff line
@@ -107,6 +107,10 @@ public class BluetoothOppServiceTest {
        BluetoothOppService service = mService;
        BluetoothOppService service = mService;
        if (service != null) {
        if (service != null) {
            service.mUpdateThread = null;
            service.mUpdateThread = null;
            Thread updateNotificationThread = service.mNotifier.mUpdateNotificationThread;
            if (updateNotificationThread != null) {
                updateNotificationThread.join();
            }
        }
        }


        BluetoothMethodProxy.setInstanceForTesting(null);
        BluetoothMethodProxy.setInstanceForTesting(null);