Loading android/app/src/com/android/bluetooth/BluetoothMethodProxy.java +10 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } } android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java +2 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading android/app/src/com/android/bluetooth/opp/BluetoothOppService.java +4 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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); } Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceTest.java +13 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -56,6 +58,7 @@ public class BluetoothOppServiceTest { BluetoothMethodProxy mMethodProxy; private BluetoothOppService mService = null; private BluetoothAdapter mAdapter = null; @Mock private AdapterService mAdapterService; Loading @@ -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); Loading Loading
android/app/src/com/android/bluetooth/BluetoothMethodProxy.java +10 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } }
android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java +2 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppService.java +4 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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); } Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceTest.java +13 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -56,6 +58,7 @@ public class BluetoothOppServiceTest { BluetoothMethodProxy mMethodProxy; private BluetoothOppService mService = null; private BluetoothAdapter mAdapter = null; @Mock private AdapterService mAdapterService; Loading @@ -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); Loading