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

Commit ab349c7f authored by William Escande's avatar William Escande
Browse files

Notification: Fix auto discard

Some profiles (Opp / pbap) are discarding all bluetooth notifications at
startup of Bluetooth.
This change will make the opp notification behind discard by opp and the
pbap being discard by pbap, allowing the other notification to persist
untiil the user dismiss them (airplane / auto on / …)

Bug: 331896688
Fix: 331896688
Test: m com.android.btservices
Test: Full manual There is no test around notification lifecycle
Change-Id: I6d4f1b540b0bc6809584958ac477dc35051e5bc3
parent 6b9f6fe4
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ class BluetoothOppNotification {

    private Context mContext;

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

    private NotificationUpdateThread mUpdateNotificationThread;

@@ -179,7 +179,6 @@ class BluetoothOppNotification {
                NotificationManager.IMPORTANCE_HIGH);

        mNotificationMgr.createNotificationChannel(mNotificationChannel);
        mNotifications = new HashMap<String, NotificationItem>();
        // Get Content Resolver object one time
        mContentResolver = mContext.getContentResolver();
    }
@@ -704,9 +703,12 @@ class BluetoothOppNotification {
        cursor.close();
    }

    void cancelNotifications() {
        Log.v(TAG, "cancelNotifications ");
    void cancelOppNotifications() {
        Log.v(TAG, "cancelOppNotifications ");
        mHandler.removeCallbacksAndMessages(null);
        mNotificationMgr.cancelAll();
        mNotificationMgr.cancel(NOTIFICATION_ID_PROGRESS);
        mNotificationMgr.cancel(NOTIFICATION_ID_OUTBOUND_COMPLETE);
        mNotificationMgr.cancel(NOTIFICATION_ID_INBOUND_COMPLETE);
        mNotificationMgr.cancel(NOTIFICATION_ID_COMPLETE_SUMMARY);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -266,7 +266,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        mObserver = new BluetoothShareContentObserver();
        getContentResolver().registerContentObserver(BluetoothShare.CONTENT_URI, true, mObserver);
        mNotifier = new BluetoothOppNotification(this);
        mNotifier.mNotificationMgr.cancelAll();
        mNotifier.cancelOppNotifications();
        updateFromProvider();
        setBluetoothOppService(this);
    }
@@ -618,7 +618,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        }

        if (mNotifier != null) {
            mNotifier.cancelNotifications();
            mNotifier.cancelOppNotifications();
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -476,7 +476,7 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
        } else {
            Log.d(TAG, "Notification Not Required.");
            if (sNotificationManager != null) {
                sNotificationManager.cancelAll();
                sNotificationManager.cancel(android.R.drawable.stat_sys_data_bluetooth);
            }
        }
    }
+2 −4
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ public class BluetoothOppNotificationTest {
                mReceiverName, COMPONENT_ENABLED_STATE_ENABLED, DONT_KILL_APP);

        // clear all OPP notifications before each test
        mOppNotification.cancelNotifications();
        mOppNotification.cancelOppNotifications();
    }

    @After
@@ -117,7 +117,7 @@ public class BluetoothOppNotificationTest {
                mReceiverName, mPreviousState, DONT_KILL_APP);

        // clear all OPP notifications after each test
        mOppNotification.cancelNotifications();
        mOppNotification.cancelOppNotifications();
    }

    @Ignore("b/288660228")
@@ -164,8 +164,6 @@ public class BluetoothOppNotificationTest {
        device.wait(Until.hasObject(By.text(titleString)), TIMEOUT_MS);
        UiObject2 title = device.findObject(By.text(titleString));
        assertThat(title).isNotNull();

        mOppNotification.cancelNotifications();
    }

    @Test