@Test public void testBrowserCallback_onChildrenChangedIsCalledWhenSubscribed2() throws InterruptedException { prepareLooper(); final String expectedParentId = "expectedParentId"; final int testChildrenCount = 101; final Bundle testExtras = TestUtils.createTestBundle(); final CountDownLatch latch = new CountDownLatch(1); final MediaLibrarySessionCallback sessionCallback = new MediaLibrarySessionCallback() { @Override public void onSubscribe(@NonNull MediaLibrarySession session, @NonNull ControllerInfo controller, @NonNull String parentId, @Nullable Bundle extras) { if (Process.myUid() == controller.getUid()) { session.notifyChildrenChanged( controller, expectedParentId, testChildrenCount, testExtras); } } @Override public List<MediaItem2> onGetChildren(MediaLibrarySession session, ControllerInfo controller, String parentId, int page, int pageSize, Bundle extras) { return TestUtils.createPlaylist(testChildrenCount); } }; final BrowserCallback controllerCallbackProxy = new BrowserCallback() { @Override public void onChildrenChanged(MediaBrowser2 browser, String parentId, int itemCount, Bundle extras) { assertEquals(expectedParentId, parentId); assertEquals(testChildrenCount, itemCount); assertTrue(TestUtils.equals(testExtras, extras)); latch.countDown(); } }; TestServiceRegistry.getInstance().setSessionCallback(sessionCallback); final SessionToken2 token = MockMediaLibraryService2.getToken(mContext); final MediaBrowser2 browser = (MediaBrowser2) createController( token, true, controllerCallbackProxy); browser.subscribe(expectedParentId, null); assertTrue(latch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); }
public void subscribe(@NonNull String parentId, @Nullable Bundle extras) { if (parentId == null) { throw new IllegalArgumentException("parentId shouldn't be null"); } MediaBrowserCompat browser = getBrowserCompat(); if (browser == null) { return; } SubscribeCallback callback = new SubscribeCallback(); synchronized (mLock) { List<SubscribeCallback> list = mSubscribeCallbacks.get(parentId); if (list == null) { list = new ArrayList<>(); mSubscribeCallbacks.put(parentId, list); } list.add(callback); } Bundle options = new Bundle(); options.putBundle(ARGUMENT_EXTRAS, extras); options.putBoolean(MEDIA_BROWSER2_SUBSCRIBE, true); browser.subscribe(parentId, options, callback); }
MediaBrowser2 extends MediaController2 { public void subscribe(@NonNull String parentId, @Nullable Bundle extras) { if (parentId == null) { throw new IllegalArgumentException("parentId shouldn't be null"); } MediaBrowserCompat browser = getBrowserCompat(); if (browser == null) { return; } SubscribeCallback callback = new SubscribeCallback(); synchronized (mLock) { List<SubscribeCallback> list = mSubscribeCallbacks.get(parentId); if (list == null) { list = new ArrayList<>(); mSubscribeCallbacks.put(parentId, list); } list.add(callback); } Bundle options = new Bundle(); options.putBundle(ARGUMENT_EXTRAS, extras); options.putBoolean(MEDIA_BROWSER2_SUBSCRIBE, true); browser.subscribe(parentId, options, callback); } }
MediaBrowser2 extends MediaController2 { public void subscribe(@NonNull String parentId, @Nullable Bundle extras) { if (parentId == null) { throw new IllegalArgumentException("parentId shouldn't be null"); } MediaBrowserCompat browser = getBrowserCompat(); if (browser == null) { return; } SubscribeCallback callback = new SubscribeCallback(); synchronized (mLock) { List<SubscribeCallback> list = mSubscribeCallbacks.get(parentId); if (list == null) { list = new ArrayList<>(); mSubscribeCallbacks.put(parentId, list); } list.add(callback); } Bundle options = new Bundle(); options.putBundle(ARGUMENT_EXTRAS, extras); options.putBoolean(MEDIA_BROWSER2_SUBSCRIBE, true); browser.subscribe(parentId, options, callback); } MediaBrowser2(@NonNull Context context, @NonNull SessionToken2 token,
            @NonNull /*@CallbackExecutor*/ Executor executor, @NonNull BrowserCallback callback); }
MediaBrowser2 extends MediaController2 { public void subscribe(@NonNull String parentId, @Nullable Bundle extras) { if (parentId == null) { throw new IllegalArgumentException("parentId shouldn't be null"); } MediaBrowserCompat browser = getBrowserCompat(); if (browser == null) { return; } SubscribeCallback callback = new SubscribeCallback(); synchronized (mLock) { List<SubscribeCallback> list = mSubscribeCallbacks.get(parentId); if (list == null) { list = new ArrayList<>(); mSubscribeCallbacks.put(parentId, list); } list.add(callback); } Bundle options = new Bundle(); options.putBundle(ARGUMENT_EXTRAS, extras); options.putBoolean(MEDIA_BROWSER2_SUBSCRIBE, true); browser.subscribe(parentId, options, callback); } MediaBrowser2(@NonNull Context context, @NonNull SessionToken2 token,
            @NonNull /*@CallbackExecutor*/ Executor executor, @NonNull BrowserCallback callback); @Override void close(); void getLibraryRoot(@Nullable final Bundle extras); void subscribe(@NonNull String parentId, @Nullable Bundle extras); void unsubscribe(@NonNull String parentId); void getChildren(@NonNull String parentId, int page, int pageSize,
            @Nullable Bundle extras); void getItem(@NonNull final String mediaId); void search(@NonNull String query, @Nullable Bundle extras); void getSearchResult(final @NonNull String query, final int page, final int pageSize,
            final @Nullable Bundle extras); }
MediaBrowser2 extends MediaController2 { public void subscribe(@NonNull String parentId, @Nullable Bundle extras) { if (parentId == null) { throw new IllegalArgumentException("parentId shouldn't be null"); } MediaBrowserCompat browser = getBrowserCompat(); if (browser == null) { return; } SubscribeCallback callback = new SubscribeCallback(); synchronized (mLock) { List<SubscribeCallback> list = mSubscribeCallbacks.get(parentId); if (list == null) { list = new ArrayList<>(); mSubscribeCallbacks.put(parentId, list); } list.add(callback); } Bundle options = new Bundle(); options.putBundle(ARGUMENT_EXTRAS, extras); options.putBoolean(MEDIA_BROWSER2_SUBSCRIBE, true); browser.subscribe(parentId, options, callback); } MediaBrowser2(@NonNull Context context, @NonNull SessionToken2 token,
            @NonNull /*@CallbackExecutor*/ Executor executor, @NonNull BrowserCallback callback); @Override void close(); void getLibraryRoot(@Nullable final Bundle extras); void subscribe(@NonNull String parentId, @Nullable Bundle extras); void unsubscribe(@NonNull String parentId); void getChildren(@NonNull String parentId, int page, int pageSize,
            @Nullable Bundle extras); void getItem(@NonNull final String mediaId); void search(@NonNull String query, @Nullable Bundle extras); void getSearchResult(final @NonNull String query, final int page, final int pageSize,
            final @Nullable Bundle extras); @RestrictTo(LIBRARY_GROUP)
    static final String EXTRA_ITEM_COUNT; @RestrictTo(LIBRARY_GROUP)
    static final String MEDIA_BROWSER2_SUBSCRIBE; }