android.media.tv.TvContract Java Examples

The following examples show how to use android.media.tv.TvContract. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TvInputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 7 votes vote down vote up
@Override
public void requestChannelBrowsable(Uri channelUri, int userId)
        throws RemoteException {
    final String callingPackageName = getCallingPackageName();
    final long identity = Binder.clearCallingIdentity();
    final int callingUid = Binder.getCallingUid();
    final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid,
        userId, "requestChannelBrowsable");
    try {
        Intent intent = new Intent(TvContract.ACTION_CHANNEL_BROWSABLE_REQUESTED);
        List<ResolveInfo> list = getContext().getPackageManager()
            .queryBroadcastReceivers(intent, 0);
        if (list != null) {
            for (ResolveInfo info : list) {
                String receiverPackageName = info.activityInfo.packageName;
                intent.putExtra(TvContract.EXTRA_CHANNEL_ID, ContentUris.parseId(
                        channelUri));
                intent.putExtra(TvContract.EXTRA_PACKAGE_NAME, callingPackageName);
                intent.setPackage(receiverPackageName);
                getContext().sendBroadcastAsUser(intent, new UserHandle(resolvedUserId));
            }
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
 
Example #2
Source File: TvInputProvider.java    From ChannelSurfer with MIT License 7 votes vote down vote up
/**
     * If you don't have access to an EPG or don't want to supply programs, you can simply
     * add several instances of this generic program object.
     *
     * Note you will have to set the start and end times manually.
     * @param channel The channel for which the program will be displayed
     * @return A very generic program object
     */
    public Program getGenericProgram(Channel channel) {
        TvContentRating rating = RATING_PG;
        return new Program.Builder()
                .setTitle(channel.getName() + " Live")
                .setProgramId(channel.getServiceId())
//                .setEpisodeNumber(1)
//                .setSeasonNumber(1)
//                .setEpisodeTitle("Streaming")
                .setDescription("Currently streaming")
                .setLongDescription(channel.getName() + " is currently streaming live.")
                .setCanonicalGenres(new String[]{TvContract.Programs.Genres.ENTERTAINMENT})
                .setThumbnailUri(channel.getLogoUrl())
                .setPosterArtUri(channel.getLogoUrl())
                .setInternalProviderData(channel.getName())
                .setContentRatings(new TvContentRating[] {rating})
                .setVideoHeight(1080)
                .setVideoWidth(1920)
                .build();
    }
 
Example #3
Source File: ModelUtils.java    From xipl with Apache License 2.0 7 votes vote down vote up
/**
 * Returns the current list of programs on a given channel.
 *
 * @param resolver Application's ContentResolver.
 * @param channelUri Channel's Uri.
 * @return List of programs.
 * @hide
 */
public static List<Program> getPrograms(ContentResolver resolver, Uri channelUri) {
    if (channelUri == null) {
        return null;
    }
    Uri uri = TvContract.buildProgramsUriForChannel(channelUri);
    List<Program> programs = new ArrayList<>();
    // TvProvider returns programs in chronological order by default.
    Cursor cursor = null;
    try {
        cursor = resolver.query(uri, Program.PROJECTION, null, null, null);
        if (cursor == null || cursor.getCount() == 0) {
            return programs;
        }
        while (cursor.moveToNext()) {
            programs.add(Program.fromCursor(cursor));
        }
    } catch (Exception e) {
        Log.w(TAG, "Unable to get programs for " + channelUri, e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return programs;
}
 
Example #4
Source File: EpgSyncWithAdsJobServiceTest.java    From androidtv-sample-inputs with Apache License 2.0 7 votes vote down vote up
@Test
public void testOriginalChannelsProgramSync() throws EpgSyncException {
    // Tests that programs and channels were correctly obtained from the EpgSyncJobService
    Uri channelUri = TvContract.buildChannelUri(mChannelMap.keyAt(0));
    Channel firstChannel = mChannelList.get(0);
    assertEquals("Test Channel", firstChannel.getDisplayName());
    assertNotNull(firstChannel.getInternalProviderData());
    assertTrue(firstChannel.getInternalProviderData().isRepeatable());

    mProgramList =
            mSampleJobService.getOriginalProgramsForChannel(
                    channelUri, firstChannel, mStartMs, mEndMs);
    assertEquals(1, mProgramList.size());

    channelUri = TvContract.buildChannelUri(mChannelMap.keyAt(1));
    Channel secondChannel = mChannelList.get(1);
    assertEquals("XML Test Channel", secondChannel.getDisplayName());
    assertNotNull(secondChannel.getInternalProviderData());
    assertTrue(secondChannel.getInternalProviderData().isRepeatable());

    mProgramList =
            mSampleJobService.getOriginalProgramsForChannel(
                    channelUri, secondChannel, mStartMs, mEndMs);
    assertEquals(5, mProgramList.size());
}
 
Example #5
Source File: JsonChannel.java    From CumulusTV with MIT License 7 votes vote down vote up
public String[] getGenres() {
    if(getGenresString() == null) {
        return new String[]{TvContract.Programs.Genres.MOVIES};
    }
    if(getGenresString().isEmpty()) {
        return new String[]{TvContract.Programs.Genres.MOVIES};
    }
    else {
        //Parse genres
        CommaArray ca = new CommaArray(getGenresString());
        Iterator<String> it = ca.getIterator();
        ArrayList<String> arrayList = new ArrayList<>();
        while(it.hasNext()) {
            String i = it.next();
            arrayList.add(i);
        }
        return arrayList.toArray(new String[arrayList.size()]);
    }
}
 
Example #6
Source File: PeriodicEpgSyncJobServiceTest.java    From androidtv-sample-inputs with Apache License 2.0 7 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();
    injectInstrumentation(InstrumentationRegistry.getInstrumentation());
    getActivity();
    // Delete all channels
    getActivity().getContentResolver().delete(TvContract.buildChannelsUriForInput(mInputId),
            null, null);

    mSampleJobService = new TestJobService();
    mSampleJobService.mContext = getActivity();
    mChannelList = mSampleJobService.getChannels();
    ModelUtils.updateChannels(getActivity(), mInputId, mChannelList, null);
    mChannelMap = ModelUtils.buildChannelMap(getActivity().getContentResolver(), mInputId);
    assertEquals(2, mChannelMap.size());
}
 
Example #7
Source File: MainFragment.java    From leanback-homescreen-channels with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(Long channelId) {
    Intent intent = new Intent(TvContract.ACTION_REQUEST_CHANNEL_BROWSABLE);
    intent.putExtra(TvContractCompat.EXTRA_CHANNEL_ID, channelId);
    try {
        startActivityForResult(intent, ADD_CHANNEL_REQUEST);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "could not start add channel approval UI", e);
    }
}
 
Example #8
Source File: EpgSyncJobServiceTest.java    From xipl with Apache License 2.0 6 votes vote down vote up
@Test
public void testChannelsProgramSync() {
    // Tests that programs and channels were correctly obtained from the EpgSyncJobService
    Uri channelUri =  TvContract.buildChannelUri(mChannelMap.keyAt(0));
    Channel firstChannel = mChannelList.get(0);
    assertEquals("Test Channel", firstChannel.getDisplayName());
    assertNotNull(firstChannel.getInternalProviderData());
    assertTrue(firstChannel.getInternalProviderData().isRepeatable());

    mProgramList = mSampleJobService.getProgramsForChannel(channelUri, firstChannel, mStartMs,
            mEndMs);
    assertEquals(1, mProgramList.size());

    channelUri =  TvContract.buildChannelUri(mChannelMap.keyAt(1));
    Channel secondChannel = mChannelList.get(1);
    assertEquals("XML Test Channel", secondChannel.getDisplayName());
    assertNotNull(secondChannel.getInternalProviderData());
    assertTrue(secondChannel.getInternalProviderData().isRepeatable());

    mProgramList = mSampleJobService.getProgramsForChannel(channelUri, secondChannel, mStartMs,
            mEndMs);
    assertEquals(5, mProgramList.size());
}
 
Example #9
Source File: EpgSyncJobServiceTest.java    From xipl with Apache License 2.0 6 votes vote down vote up
@Test
public void testRequestSync() throws InterruptedException {
    // Tests that a sync can be requested and complete
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(
            mSyncStatusChangedReceiver,
            new IntentFilter(EpgSyncJobService.ACTION_SYNC_STATUS_CHANGED));
    mSyncStatusLatch = new CountDownLatch(2);
    EpgSyncJobService.cancelAllSyncRequests(getActivity());
    EpgSyncJobService.requestImmediateSync(getActivity(), TestTvInputService.INPUT_ID,
            1000 * 60 * 60, // 1 hour sync period
            new ComponentName(getActivity(), TestJobService.class));
    mSyncStatusLatch.await();

    // Sync is completed
    List<Channel> channelList = ModelUtils.getChannels(getActivity().getContentResolver());
    Log.d("TvContractUtils", channelList.toString());
    assertEquals(2, channelList.size());
    List<Program> programList = ModelUtils.getPrograms(getActivity().getContentResolver(),
            TvContract.buildChannelUri(channelList.get(0).getId()));
    assertEquals(5, programList.size());
}
 
Example #10
Source File: Channel.java    From xipl with Apache License 2.0 6 votes vote down vote up
private static String[] getProjection() {
    String[] baseColumns =
            new String[] {
                TvContract.Channels._ID,
                TvContract.Channels.COLUMN_DESCRIPTION,
                TvContract.Channels.COLUMN_DISPLAY_NAME,
                TvContract.Channels.COLUMN_DISPLAY_NUMBER,
                TvContract.Channels.COLUMN_INPUT_ID,
                TvContract.Channels.COLUMN_INTERNAL_PROVIDER_DATA,
                TvContract.Channels.COLUMN_NETWORK_AFFILIATION,
                TvContract.Channels.COLUMN_ORIGINAL_NETWORK_ID,
                TvContract.Channels.COLUMN_PACKAGE_NAME,
                TvContract.Channels.COLUMN_SEARCHABLE,
                TvContract.Channels.COLUMN_SERVICE_ID,
                TvContract.Channels.COLUMN_SERVICE_TYPE,
                TvContract.Channels.COLUMN_TRANSPORT_STREAM_ID,
                TvContract.Channels.COLUMN_TYPE,
                TvContract.Channels.COLUMN_VIDEO_FORMAT,
            };
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String[] marshmallowColumns =
                new String[] {
                    TvContract.Channels.COLUMN_APP_LINK_COLOR,
                    TvContract.Channels.COLUMN_APP_LINK_ICON_URI,
                    TvContract.Channels.COLUMN_APP_LINK_INTENT_URI,
                    TvContract.Channels.COLUMN_APP_LINK_POSTER_ART_URI,
                    TvContract.Channels.COLUMN_APP_LINK_TEXT
                };
        return CollectionUtils.concatAll(baseColumns, marshmallowColumns);
    }
    return baseColumns;
}
 
Example #11
Source File: BaseTvInputService.java    From xipl with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    // Create background thread
    mDbHandlerThread = new HandlerThread(getClass().getSimpleName());
    mDbHandlerThread.start();

    // Initialize the channel map and set observer for changes
    mContentResolver = BaseTvInputService.this.getContentResolver();
    updateChannelMap();
    mChannelObserver =
            new ContentObserver(new Handler(mDbHandlerThread.getLooper())) {
                @Override
                public void onChange(boolean selfChange) {
                    updateChannelMap();
                }
            };
    mContentResolver.registerContentObserver(
            TvContract.Channels.CONTENT_URI, true, mChannelObserver);

    // Setup our BroadcastReceiver
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TvInputManager.ACTION_BLOCKED_RATINGS_CHANGED);
    intentFilter.addAction(TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED);
    registerReceiver(mParentalControlsBroadcastReceiver, intentFilter);
}
 
Example #12
Source File: EpgSyncWithAdsJobServiceTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();
    injectInstrumentation(InstrumentationRegistry.getInstrumentation());
    getActivity();
    // Delete all channels
    getActivity()
            .getContentResolver()
            .delete(
                    TvContract.buildChannelsUriForInput(TestTvInputService.INPUT_ID),
                    null,
                    null);

    mSampleJobService = new TestJobService();
    mSampleJobService.mContext = getActivity();
    mChannelList = mSampleJobService.getChannels();
    ModelUtils.updateChannels(getActivity(), TestTvInputService.INPUT_ID, mChannelList, null);
    mChannelMap =
            ModelUtils.buildChannelMap(
                    getActivity().getContentResolver(), TestTvInputService.INPUT_ID);
    assertNotNull(mChannelMap);
    assertEquals(2, mChannelMap.size());

    // Round start time to the current hour
    mStartMs = System.currentTimeMillis() - System.currentTimeMillis() % (1000 * 60 * 60);
    mEndMs = mStartMs + 1000 * 60 * 60 * 24 * 7 * 2; // Two week long sync period
    assertTrue(mStartMs < mEndMs);

    Uri channelUri = TvContract.buildChannelUri(mChannelMap.keyAt(0));
    Channel firstChannel = mChannelList.get(0);
    assertEquals("Test Channel", firstChannel.getDisplayName());
    assertNotNull(firstChannel.getInternalProviderData());
    assertTrue(firstChannel.getInternalProviderData().isRepeatable());

    mProgramList =
            mSampleJobService.getProgramsForChannel(channelUri, firstChannel, mStartMs, mEndMs);
}
 
Example #13
Source File: TifDatabaseIntegrationTest.java    From CumulusTV with MIT License 5 votes vote down vote up
@Before
public void insertChannels() {
    Context context = getActivity();
    ContentValues contentValues = new ContentValues();
    contentValues.put(TvContract.Channels.COLUMN_ORIGINAL_NETWORK_ID, 1);
    contentValues.put(TvContract.Channels.COLUMN_DISPLAY_NAME, "Hello");
    contentValues.put(TvContract.Channels.COLUMN_DISPLAY_NUMBER, "123");
    contentValues.put(TvContract.Channels.COLUMN_INPUT_ID,
            ActivityUtils.TV_INPUT_SERVICE.flattenToString());
    contentValues.put(TvContract.Channels.COLUMN_INTERNAL_PROVIDER_DATA, MEDIA_URL);
    Uri databaseUri = context.getContentResolver().insert(TvContract.Channels.CONTENT_URI,
            contentValues);
    Log.d(TAG, "Inserted in Uri " + databaseUri);

    // Make sure we actually inserted something
    ContentResolver contentResolver = context.getContentResolver();
    Cursor cursor = contentResolver.query(TvContract.Channels.CONTENT_URI,
            null, null, null, null);
    assertNotNull(cursor);
    assertEquals(1, cursor.getCount());
    assertTrue(cursor.moveToNext());
    assertEquals(1, cursor.getLong(cursor.getColumnIndex(
            TvContract.Channels.COLUMN_ORIGINAL_NETWORK_ID)));
    cursor.close();
}
 
Example #14
Source File: EpgSyncWithAdsJobServiceTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Test
public void testRequestSync() throws InterruptedException {
    // Tests that a sync can be requested and complete
    LocalBroadcastManager.getInstance(getActivity())
            .registerReceiver(
                    mSyncStatusChangedReceiver,
                    new IntentFilter(EpgSyncJobService.ACTION_SYNC_STATUS_CHANGED));
    mSyncStatusLatch = new CountDownLatch(2);
    EpgSyncJobService.cancelAllSyncRequests(getActivity());
    EpgSyncJobService.requestImmediateSync(
            getActivity(),
            TestTvInputService.INPUT_ID,
            1000 * 60 * 60, // 1 hour sync period
            new ComponentName(getActivity(), TestJobService.class));
    mSyncStatusLatch.await();

    // Sync is completed
    List<Channel> channelList = ModelUtils.getChannels(getActivity().getContentResolver());
    Log.d("TvContractUtils", channelList.toString());
    assertEquals(2, channelList.size());
    List<Program> programList =
            ModelUtils.getPrograms(
                    getActivity().getContentResolver(),
                    TvContract.buildChannelUri(channelList.get(0).getId()));
    assertEquals(5, programList.size());
}
 
Example #15
Source File: PeriodicEpgSyncJobServiceTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Override
public void tearDown() throws Exception {
    super.tearDown();
    LocalBroadcastManager.getInstance(getActivity())
            .unregisterReceiver(mSyncStatusChangedReceiver);

    // Delete these programs
    getActivity().getContentResolver().delete(TvContract.buildChannelsUriForInput(mInputId),
            null, null);
}
 
Example #16
Source File: ChannelDatabase.java    From CumulusTV with MIT License 5 votes vote down vote up
/**
 * Creates a link between the database Uris and the JSONChannels
 * @param context The application's context for the {@link ContentResolver}.
 */
protected void initializeHashMap(final Context context) {
    mWorker = new Thread(new Runnable() {
        @Override
        public void run() {
            ContentResolver contentResolver = context.getContentResolver();
            Uri channelsUri = TvContract.buildChannelsUriForInput(
                    ActivityUtils.TV_INPUT_SERVICE.flattenToString());
            Cursor cursor = contentResolver.query(channelsUri, null, null, null, null);
            mDatabaseHashMap = new HashMap<>();
            Log.d(TAG, "Initialize CD HashMap");
            if (cursor != null) {
                while (cursor.moveToNext()) {
                    try {
                        InternalProviderData ipd = new InternalProviderData(
                                cursor.getBlob(cursor.getColumnIndex(
                                TvContract.Channels.COLUMN_INTERNAL_PROVIDER_DATA)));
                        String mediaUrl = ipd.getVideoUrl();
                        long rowId = cursor.getLong(cursor.getColumnIndex(TvContract.Channels._ID));
                        Log.d(TAG, "Try to match " + mediaUrl + " " + rowId);
                        for (JsonChannel jsonChannel : getJsonChannels()) {
                            if (jsonChannel.getMediaUrl().equals(mediaUrl)) {
                                mDatabaseHashMap.put(jsonChannel.getMediaUrl(), rowId);
                            }
                        }
                    } catch (InternalProviderData.ParseException e) {
                        e.printStackTrace();
                    } catch (JSONException ignored) {
                    }
                }
                cursor.close();
            }
        }
    });
    mWorker.start();
}
 
Example #17
Source File: EpgSyncWithAdsJobServiceTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Override
public void tearDown() throws Exception {
    super.tearDown();
    LocalBroadcastManager.getInstance(getActivity())
            .unregisterReceiver(mSyncStatusChangedReceiver);

    // Delete these programs
    getActivity()
            .getContentResolver()
            .delete(
                    TvContract.buildChannelsUriForInput(TestTvInputService.INPUT_ID),
                    null,
                    null);
}
 
Example #18
Source File: ChannelSetupFragmentTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Override
public void tearDown() throws Exception {
    super.tearDown();
    // Delete content
    getActivity().getContentResolver().delete(TvContract.buildChannelsUriForInput(
            TestTvInputService.INPUT_ID), null, null);
    LocalBroadcastManager.getInstance(getActivity())
            .unregisterReceiver(mSyncStatusChangedReceiver);
}
 
Example #19
Source File: EpgSyncWithAdsJobServiceTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Test
public void testEpgSyncTask_GetPrograms() throws EpgSyncException {
    // For repeating channels, test that the program list will continually repeat for the
    // desired length of time
    Uri channelUri = TvContract.buildChannelUri(mChannelMap.keyAt(0));
    Channel firstChannel = mChannelList.get(0);
    mProgramList =
            mSampleJobService.getProgramsForChannel(channelUri, firstChannel, mStartMs, mEndMs);

    assertEquals(336 * 60 / 15, mProgramList.size());
}
 
Example #20
Source File: XmlTvParserTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Test
public void testProgramParsing() throws XmlTvParser.XmlTvParseException {
    String testXmlFile = "xmltv.xml";
    String APRIL_FOOLS_SOURCE = "https://commondatastorage.googleapis.com/android-tv/Sample%2" +
            "0videos/April%20Fool's%202013/Introducing%20Google%20Fiber%20to%20the%20Pole.mp4";
    String ELEPHANTS_DREAM_POSTER_ART = "https://storage.googleapis.com/gtv-videos-bucket/sam" +
            "ple/images_480x270/ElephantsDream.jpg";
    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(testXmlFile);
    XmlTvParser.TvListing listings = XmlTvParser.parse(inputStream);
    assertEquals(9, listings.getAllPrograms().size());
    assertEquals("Introducing Gmail Blue", listings.getAllPrograms().get(0).getTitle());
    assertEquals("Introducing Gmail Blue",
            listings.getPrograms(listings.getChannels().get(0)).get(0).getTitle());
    assertEquals(TvContract.Programs.Genres.TECH_SCIENCE,
            listings.getAllPrograms().get(1).getCanonicalGenres()[1]);
    assertEquals(listings.getAllPrograms().get(2).getChannelId(),
            listings.getChannels().get(0).getOriginalNetworkId());
    assertNotNull(listings.getAllPrograms().get(3).getInternalProviderData());
    assertEquals(APRIL_FOOLS_SOURCE,
            listings.getAllPrograms().get(3).getInternalProviderData().getVideoUrl());
    assertEquals("Introducing Google Nose", listings.getAllPrograms().get(4).getDescription());
    assertEquals(ELEPHANTS_DREAM_POSTER_ART,
            listings.getAllPrograms().get(5).getPosterArtUri());
    InternalProviderData internalProviderData = new InternalProviderData();
    internalProviderData.setVideoType(TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE);
    internalProviderData.setVideoUrl(APRIL_FOOLS_SOURCE);
    assertEquals(internalProviderData,
            listings.getAllPrograms().get(3).getInternalProviderData());
}
 
Example #21
Source File: EpgSyncTest.java    From CumulusTV with MIT License 5 votes vote down vote up
/**
 * From a resource file, we will try to pull EPG data for a channel.
 */
@Test
public void testPullFromXmlTvResource() throws JSONException, InterruptedException {
    VolatileChannelDatabase.getMockedInstance(getActivity()).add(
            new JsonChannel.Builder()
                    .setName("Name")
                    .setNumber("Number")
                    .setMediaUrl(MEDIA_URL)
                    .setEpgUrl("http://example.com/epg.xml")
                    .setLogo("http://static-cdn1.ustream.tv/i/channel/picture/9/4/0/8/9408562/9408562_iss_hr_1330361780,256x144,r:1.jpg")
                    .build());
    CumulusJobService.requestImmediateSync1(getActivity(),
            "com.felkertech.cumulustv.tv.CumulusTvTifService", CumulusJobService.DEFAULT_IMMEDIATE_EPG_DURATION_MILLIS,
            new ComponentName(getActivity(), CumulusJobService.class));
    // Wait for sync to complete
    Thread.sleep(1000 * 10);
    ChannelDatabase channelDatabase = VolatileChannelDatabase.getMockedInstance(getActivity());

    // Get our channel row
    Thread.sleep(1000 * 5);
    HashMap<String, Long> databaseRowMap = channelDatabase.getHashMap();
    assertTrue(databaseRowMap.containsKey(MEDIA_URL));
    long rowId = databaseRowMap.get(MEDIA_URL);
    assertTrue(rowId > 0);

    // Get programs
    Cursor cursor = getActivity().getContentResolver().query(
            TvContract.buildProgramsUriForChannel(rowId), null, null, null, null);
    assertNotNull(cursor);
    assertTrue(cursor.moveToFirst());
    Program program = Program.fromCursor(cursor);
    if (!(program.getTitle().equals("Elephants Dream") ||
            program.getTitle().equals("Sintel"))) {
        Assert.fail("Neither program was found.");
    }
}
 
Example #22
Source File: DataReceiver.java    From CumulusTV with MIT License 5 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    if (DEBUG) {
        Log.d(TAG, "Connected - Sync w/ drive");
    }
    //Let's sync with GDrive
    ActivityUtils.writeDriveData(mContext, gapi);

    final String info = TvContract.buildInputId(ActivityUtils.TV_INPUT_SERVICE);
    CumulusJobService.requestImmediateSync1(mContext, info, CumulusJobService.DEFAULT_IMMEDIATE_EPG_DURATION_MILLIS,
            new ComponentName(mContext, CumulusJobService.class));
}
 
Example #23
Source File: ChannelDatabase.java    From CumulusTV with MIT License 5 votes vote down vote up
public static String[] getAllGenres() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        return new String[] {
                TvContract.Programs.Genres.ANIMAL_WILDLIFE,
                TvContract.Programs.Genres.ARTS,
                TvContract.Programs.Genres.COMEDY,
                TvContract.Programs.Genres.DRAMA,
                TvContract.Programs.Genres.EDUCATION,
                TvContract.Programs.Genres.ENTERTAINMENT,
                TvContract.Programs.Genres.FAMILY_KIDS,
                TvContract.Programs.Genres.GAMING,
                TvContract.Programs.Genres.LIFE_STYLE,
                TvContract.Programs.Genres.MOVIES,
                TvContract.Programs.Genres.MUSIC,
                TvContract.Programs.Genres.NEWS,
                TvContract.Programs.Genres.PREMIER,
                TvContract.Programs.Genres.SHOPPING,
                TvContract.Programs.Genres.SPORTS,
                TvContract.Programs.Genres.TECH_SCIENCE,
                TvContract.Programs.Genres.TRAVEL,
        };
    }
    return new String[] {
        TvContract.Programs.Genres.ANIMAL_WILDLIFE,
        TvContract.Programs.Genres.COMEDY,
        TvContract.Programs.Genres.DRAMA,
        TvContract.Programs.Genres.EDUCATION,
        TvContract.Programs.Genres.FAMILY_KIDS,
        TvContract.Programs.Genres.GAMING,
        TvContract.Programs.Genres.MOVIES,
        TvContract.Programs.Genres.NEWS,
        TvContract.Programs.Genres.SHOPPING,
        TvContract.Programs.Genres.SPORTS,
        TvContract.Programs.Genres.TRAVEL,
    };
}
 
Example #24
Source File: Channel.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
private static String[] getProjection() {
    String[] baseColumns =
            new String[] {
                TvContract.Channels._ID,
                TvContract.Channels.COLUMN_DESCRIPTION,
                TvContract.Channels.COLUMN_DISPLAY_NAME,
                TvContract.Channels.COLUMN_DISPLAY_NUMBER,
                TvContract.Channels.COLUMN_INPUT_ID,
                TvContract.Channels.COLUMN_INTERNAL_PROVIDER_DATA,
                TvContract.Channels.COLUMN_NETWORK_AFFILIATION,
                TvContract.Channels.COLUMN_ORIGINAL_NETWORK_ID,
                TvContract.Channels.COLUMN_PACKAGE_NAME,
                TvContract.Channels.COLUMN_SEARCHABLE,
                TvContract.Channels.COLUMN_SERVICE_ID,
                TvContract.Channels.COLUMN_SERVICE_TYPE,
                TvContract.Channels.COLUMN_TRANSPORT_STREAM_ID,
                TvContract.Channels.COLUMN_TYPE,
                TvContract.Channels.COLUMN_VIDEO_FORMAT,
            };
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String[] marshmallowColumns =
                new String[] {
                    TvContract.Channels.COLUMN_APP_LINK_COLOR,
                    TvContract.Channels.COLUMN_APP_LINK_ICON_URI,
                    TvContract.Channels.COLUMN_APP_LINK_INTENT_URI,
                    TvContract.Channels.COLUMN_APP_LINK_POSTER_ART_URI,
                    TvContract.Channels.COLUMN_APP_LINK_TEXT
                };
        return CollectionUtils.concatAll(baseColumns, marshmallowColumns);
    }
    return baseColumns;
}
 
Example #25
Source File: ChannelDatabase.java    From CumulusTV with MIT License 5 votes vote down vote up
public void resetPossibleGenres() throws JSONException {
    JSONArray genres = new JSONArray();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        genres.put(TvContract.Programs.Genres.ANIMAL_WILDLIFE);
        genres.put(TvContract.Programs.Genres.ARTS);
        genres.put(TvContract.Programs.Genres.COMEDY);
        genres.put(TvContract.Programs.Genres.DRAMA);
        genres.put(TvContract.Programs.Genres.EDUCATION);
        genres.put(TvContract.Programs.Genres.ENTERTAINMENT);
        genres.put(TvContract.Programs.Genres.FAMILY_KIDS);
        genres.put(TvContract.Programs.Genres.GAMING);
        genres.put(TvContract.Programs.Genres.LIFE_STYLE);
        genres.put(TvContract.Programs.Genres.MOVIES);
        genres.put(TvContract.Programs.Genres.MUSIC);
        genres.put(TvContract.Programs.Genres.NEWS);
        genres.put(TvContract.Programs.Genres.PREMIER);
        genres.put(TvContract.Programs.Genres.SHOPPING);
        genres.put(TvContract.Programs.Genres.SPORTS);
        genres.put(TvContract.Programs.Genres.TECH_SCIENCE);
        genres.put(TvContract.Programs.Genres.TRAVEL);
    } else {
        genres.put(TvContract.Programs.Genres.ANIMAL_WILDLIFE);
        genres.put(TvContract.Programs.Genres.COMEDY);
        genres.put(TvContract.Programs.Genres.DRAMA);
        genres.put(TvContract.Programs.Genres.EDUCATION);
        genres.put(TvContract.Programs.Genres.FAMILY_KIDS);
        genres.put(TvContract.Programs.Genres.GAMING);
        genres.put(TvContract.Programs.Genres.MOVIES);
        genres.put(TvContract.Programs.Genres.NEWS);
        genres.put(TvContract.Programs.Genres.SHOPPING);
        genres.put(TvContract.Programs.Genres.SPORTS);
        genres.put(TvContract.Programs.Genres.TRAVEL);
    }
    mJsonObject.put("possibleGenres", genres);
}
 
Example #26
Source File: ActivityUtils.java    From CumulusTV with MIT License 5 votes vote down vote up
public static void launchLiveChannels(Activity activity) {
    Intent i = new Intent(Intent.ACTION_VIEW, TvContract.Channels.CONTENT_URI);
    try {
        activity.startActivity(i);
    } catch (Exception e) {
        Toast.makeText(activity, R.string.no_live_channels, Toast.LENGTH_SHORT).show();
    }
}
 
Example #27
Source File: ActivityUtils.java    From CumulusTV with MIT License 5 votes vote down vote up
private static void actuallyWriteData(final Context context, GoogleApiClient gapi) {
        DriveSettingsManager sm = new DriveSettingsManager(context);
        sm.setGoogleDriveSyncable(gapi, new DriveSettingsManager.GoogleDriveListener() {
            @Override
            public void onActionFinished(boolean cloudToLocal) {
                Log.d(TAG, "Action finished " + cloudToLocal);
            }
        });
        try {
            sm.writeToGoogleDrive(DriveId.decodeFromString(sm.getString(R.string.sm_google_drive_id)),
                    ChannelDatabase.getInstance(context).toString());
            GoogleDriveBroadcastReceiver.changeStatus(context,
                    GoogleDriveBroadcastReceiver.EVENT_UPLOAD_COMPLETE);

            final String info = TvContract.buildInputId(TV_INPUT_SERVICE);
            CumulusJobService.requestImmediateSync1(context, info, CumulusJobService.DEFAULT_IMMEDIATE_EPG_DURATION_MILLIS,
                    new ComponentName(context, CumulusJobService.class));
            Log.d(TAG, "Data actually written");
//            Toast.makeText(context, "Channels uploaded", Toast.LENGTH_SHORT).show();
        } catch(Exception e) {
            // Probably invalid drive id. No worries, just let someone know
            Log.e(TAG, e.getMessage() + "");
            Toast.makeText(context, R.string.invalid_file,
                    Toast.LENGTH_SHORT).show();
        }
    }
 
Example #28
Source File: LeanbackFragment.java    From CumulusTV with MIT License 5 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    ActivityUtils.onConnected(CloudStorageProvider.getInstance().getClient());
    Log.d(TAG, "onConnected");

    sm.setGoogleDriveSyncable(CloudStorageProvider.getInstance().getClient(), new DriveSettingsManager.GoogleDriveListener() {
        @Override
        public void onActionFinished(boolean cloudToLocal) {
            Log.d(TAG, "Sync req after drive action");
            final String info = TvContract.buildInputId(ActivityUtils.TV_INPUT_SERVICE);
            CumulusJobService.requestImmediateSync1(mActivity, info, CumulusJobService.DEFAULT_IMMEDIATE_EPG_DURATION_MILLIS,
                    new ComponentName(mActivity, CumulusJobService.class));
            if (cloudToLocal) {
                Toast.makeText(getActivity(), R.string.download_complete, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getActivity(), R.string.upload_complete, Toast.LENGTH_SHORT).show();
            }
        }
    }); //Enable GDrive
    Log.d(TAG, sm.getString(R.string.sm_google_drive_id) + "<< for onConnected");
    if(sm.getString(R.string.sm_google_drive_id).isEmpty()) {
        //We need a new file
        ActivityUtils.createDriveData(mActivity, CloudStorageProvider.getInstance().getClient(),
                driveContentsCallback);
    } else {
        //Great, user already has sync enabled, let's resync
        ActivityUtils.readDriveData(mActivity, CloudStorageProvider.getInstance().getClient());
        Handler h = new Handler(Looper.getMainLooper()){
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                refreshUI();
            }
        };
        h.sendEmptyMessageDelayed(0, 4000);
    }
}
 
Example #29
Source File: RecordedProgramTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
@Test
public void testFullyPopulatedRecording() {
    // Tests that every attribute in a RecordedProgram can be set and persist through database
    // I/O operations
    RecordedProgram fullyPopulatedProgram = new RecordedProgram.Builder()
            .setAudioLanguages("en-us")
            .setBroadcastGenres(new String[]{"Sports"})
            .setCanonicalGenres(new String[]{TvContract.Programs.Genres.ANIMAL_WILDLIFE})
            .setContentRatings(new TvContentRating[]{TvContentRating.UNRATED})
            .setEpisodeDisplayNumber("24", 24)
            .setEpisodeTitle("Sample Episode")
            .setInputId(TEST_INPUT_ID)
            .setTitle("Sample Title")
            .setSearchable(false)
            .setStartTimeUtcMillis(0)
            .setEndTimeUtcMillis(1000)
            .setInternalProviderData(new InternalProviderData())
            .setRecordingDataBytes(1024 * 1024)
            .setRecordingDataUri("file://sdcard/TV.apk")
            .setRecordingDurationMillis(1000)
            .setSeasonTitle("First Season")
            .setSeasonDisplayNumber("1", 1)
            .setVideoHeight(1080)
            .setVideoWidth(1920)
            .build();

    ContentValues contentValues = fullyPopulatedProgram.toContentValues();
    compareRecordedProgram(fullyPopulatedProgram,
            RecordedProgram.fromCursor(getRecordedProgramCursor(contentValues)));

    RecordedProgram clonedFullyPopulatedProgram =
            new RecordedProgram.Builder(fullyPopulatedProgram).build();
    compareRecordedProgram(fullyPopulatedProgram, clonedFullyPopulatedProgram);
}
 
Example #30
Source File: ChannelTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Test
public void testFullyPopulatedChannel() throws InternalProviderData.ParseException {
    // Tests cloning and database I/O of a channel with every value being defined.
    InternalProviderData internalProviderData = new InternalProviderData();
    internalProviderData.setRepeatable(true);
    internalProviderData.put(KEY_SPLASHSCREEN, SPLASHSCREEN_URL);
    internalProviderData.put(KEY_PREMIUM_CHANNEL, false);
    Channel fullyPopulatedChannel = new Channel.Builder()
            .setAppLinkColor(RuntimeEnvironment.application.getResources()
                    .getColor(android.R.color.holo_orange_light))
            .setAppLinkIconUri("http://example.com/icon.png")
            .setAppLinkIntent(new Intent())
            .setAppLinkPosterArtUri("http://example.com/poster.png")
            .setAppLinkText("Open an intent")
            .setDescription("Channel description")
            .setDisplayName("Display Name")
            .setDisplayNumber("100")
            .setInternalProviderData(internalProviderData)
            .setInputId("TestInputService")
            .setNetworkAffiliation("Network Affiliation")
            .setOriginalNetworkId(2)
            .setPackageName("com.example.android.sampletvinput")
            .setSearchable(false)
            .setServiceId(3)
            .setTransportStreamId(4)
            .setType(TvContract.Channels.TYPE_1SEG)
            .setServiceType(TvContract.Channels.SERVICE_TYPE_AUDIO_VIDEO)
            .setVideoFormat(TvContract.Channels.VIDEO_FORMAT_240P)
            .build();
    ContentValues contentValues = fullyPopulatedChannel.toContentValues();
    compareChannel(fullyPopulatedChannel, Channel.fromCursor(getChannelCursor(contentValues)));

    Channel clonedFullyPopulatedChannel = new Channel.Builder(fullyPopulatedChannel).build();
    compareChannel(fullyPopulatedChannel, clonedFullyPopulatedChannel);
}