sqlitewhere-clauseandroid-contentresolverandroid-tvepg

Loading EPG programs on AndroidTv, with a where-clause/selection-filter


I have a problem, properly just cause of confusion, when fetching programs through the ContentResolver for a channel, with a selection variable..

I get the following exception:

java.lang.SecurityException: Selection not allowed for content://android.media.tv/program?channel=5

I can fetch all the programs for a channel without problems, but when i add the selection (where-clause) to the query-method, i get the above security exception, no matter the selection string, even on 1=1:

Cursor cursor = resolver.query(programsUri, null, "1 = 1", null, null);

I find it really weird, since i don't have problems fetching all programs for the channel with:

Cursor cursor = resolver.query(programsUri, null, null, null, null);

I was told by a colleague that this is due to my app not being a system app on the device i am developing on, but again i find this weird, since i am allowed fetch all the programs without the selection-property, so why would it require extra permissions in order to do a where-clause? Really hope someone can help me out, since it would be nice not to be forced to fetch all programs and do the selection-filter my self, but use the supplied selection-property.. Thanks in advance :-)

OBS: The channel (?channel=5) is created by the app and not a third party tv-input channel.


Solution

  • I figured out the problem...

    The problem is that my app which want to filter on the channel programs is a third party app. This means, the app is not allowed by android to make the selection-argument in order to prevent SQL injections by third party apps in android, which makes sense.

    The way to filter in the way we want then needs to be defined in one of the build methods TvContract.buildProgramUriXXX(). In my case i could use buildProgramsUriForChannel(Uri channelUri, long startTime, long endTime).

    To my knowlege, if a build-method is not available for the desired filtration logic, we need to do it "manually" after fetching all the programs for the channel.. unless of course the app is a system app, and we thereby have access to use the selection-argument.