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

Commit 15438256 authored by Hieu Dang's avatar Hieu Dang Committed by Automerger Merge Worker
Browse files

Merge "Cherry-pick ag/21002020 to aosp" am: a754508e

parents a666a9d2 a754508e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.util.Log;
import com.android.bluetooth.gatt.AppAdvertiseStats;
import com.android.bluetooth.gatt.ContextMap;
import com.android.bluetooth.gatt.GattService;
import com.android.bluetooth.opp.BluetoothOppNotification;
import com.android.internal.annotations.VisibleForTesting;
import com.android.obex.HeaderSet;

@@ -249,4 +250,13 @@ public class BluetoothMethodProxy {
            ContextMap map, GattService service) {
        return new AppAdvertiseStats(appUid, id, name, map, service);
    }


    /**
     * Proxies {@link com.android.bluetooth.opp.BluetoothOppNotification#BluetoothOppNotification(
     * Context)}.
     */
    public BluetoothOppNotification newBluetoothOppNotification(final Context context) {
        return new BluetoothOppNotification(context);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ import java.util.HashMap;
 * where there is an ongoing transfer, incoming transfer need confirm and
 * complete (successful or failed) transfer.
 */
class BluetoothOppNotification {
public class BluetoothOppNotification {
    private static final String TAG = "BluetoothOppNotification";
    private static final boolean V = Constants.VERBOSE;

@@ -152,7 +152,7 @@ class BluetoothOppNotification {
     * @param ctx The context to use to obtain access to the Notification
     *            Service
     */
    BluetoothOppNotification(Context ctx) {
    public BluetoothOppNotification(Context ctx) {
        mContext = ctx;
        mNotificationMgr = mContext.getSystemService(NotificationManager.class);
        mNotificationChannel = new NotificationChannel(OPP_NOTIFICATION_CHANNEL,
+4 −2
Original line number Diff line number Diff line
@@ -129,7 +129,8 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
    private BluetoothShareContentObserver mObserver;

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

    private boolean mPendingUpdate;

@@ -265,7 +266,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        mAdapterService = AdapterService.getAdapterService();
        mObserver = new BluetoothShareContentObserver();
        getContentResolver().registerContentObserver(BluetoothShare.CONTENT_URI, true, mObserver);
        mNotifier = new BluetoothOppNotification(this);
        mNotifier = BluetoothMethodProxy.getInstance().newBluetoothOppNotification(this);
        mNotifier.mNotificationMgr.cancelAll();
        mNotifier.updateNotification();
        updateFromProvider();
@@ -1128,6 +1129,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        // remove the invisible/unconfirmed inbound shares
        int delNum = BluetoothMethodProxy.getInstance().contentResolverDelete(
                contentResolver, BluetoothShare.CONTENT_URI, WHERE_INVISIBLE_UNCONFIRMED, null);

        if (V) {
            Log.v(TAG, "Deleted shares, number = " + delNum);
        }
+13 −1
Original line number Diff line number Diff line
@@ -26,9 +26,11 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import android.app.NotificationManager;
import android.bluetooth.BluetoothAdapter;
import android.content.ContentResolver;
import android.database.MatrixCursor;
import android.os.Handler;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ServiceTestRule;
@@ -56,6 +58,7 @@ public class BluetoothOppServiceTest {
    BluetoothMethodProxy mMethodProxy;
    private BluetoothOppService mService = null;
    private BluetoothAdapter mAdapter = null;

    @Mock
    private AdapterService mAdapterService;

@@ -64,9 +67,18 @@ public class BluetoothOppServiceTest {
        Assume.assumeTrue("Ignore test when BluetoothOppService is not enabled",
                BluetoothOppService.isEnabled());
        MockitoAnnotations.initMocks(this);

        BluetoothMethodProxy.setInstanceForTesting(mMethodProxy);

        // To void mockito multi-thread inter-tests problem
        // If the thread still run in the next test, it will raise un-related mockito error
        BluetoothOppNotification bluetoothOppNotification = mock(BluetoothOppNotification.class);
        bluetoothOppNotification.mNotificationMgr = mock(NotificationManager.class);
        doReturn(bluetoothOppNotification).when(mMethodProxy).newBluetoothOppNotification(any());

        TestUtils.setAdapterService(mAdapterService);
        doReturn(true, false).when(mAdapterService).isStartedProfile(anyString());

        TestUtils.startService(mServiceRule, BluetoothOppService.class);
        mService = BluetoothOppService.getBluetoothOppService();
        Assert.assertNotNull(mService);