SecurityException: Selection not allowed for content://android.media.tv/channel

Viewed 501

Here in my code snippet:

val uri: Uri = TvContractCompat.Channels.CONTENT_URI
context.contentResolver.query(uri, null, null, null, null)?.let { cursor->
    if(cursor.count > 0) {
        cursor.moveToFirst()
        do {
            val channel = Channel.fromCursor(cursor)
        } while (cursor.moveToNext() && cursor.isLast.not())
    }
} 

I get following error message:

2021-03-11 20:32:29.509 7285-7285/com.example.tvapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.tvapp, PID: 7285 java.lang.SecurityException: Selection not allowed for content://android.media.tv/channel at android.os.Parcel.createException(Parcel.java:1950) at android.os.Parcel.readException(Parcel.java:1918) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135) at android.content.ContentProviderProxy.query(ContentProviderNative.java:418) at android.content.ContentResolver.query(ContentResolver.java:802) at android.content.ContentResolver.query(ContentResolver.java:752) at android.content.ContentResolver.query(ContentResolver.java:710)

In my Manifest I already have:

    <uses-permission android:name="com.android.providers.tv.permission.READ_EPG_DATA" />
    <uses-permission android:name="com.android.providers.tv.permission.ACCESS_ALL_EPG_DATA"/>

Since I do not write anything to EPG I do not have the other permission:

Anyway, also with that permission, I get that errror.

Btw. when I run the app from my /system folder (a bit higher access level) the code is working and I get the Channels

1 Answers

I cannot reproduce your issue, so I have decided to post the relevant code - maybe it will help you somehow. So, the app starts fine and no exception is thrown.

app/build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.sampletv"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'com.android.support:leanback-v17:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.github.bumptech.glide:glide:3.8.0'
    implementation 'androidx.tvprovider:tvprovider:1.0.0'
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.sampletv">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA" />

    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />
    <uses-feature
        android:name="android.software.leanback"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.Sampletv">
        <activity
            android:name=".MainActivity"
            android:banner="@drawable/app_icon_your_company"
            android:icon="@drawable/app_icon_your_company"
            android:label="@string/app_name"
            android:logo="@drawable/app_icon_your_company"
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity.kt

package com.example.sampletv

import android.app.Activity
import android.net.Uri
import android.os.Bundle
import androidx.tvprovider.media.tv.Channel
import androidx.tvprovider.media.tv.TvContractCompat

class MainActivity : Activity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val uri: Uri = TvContractCompat.Channels.CONTENT_URI
        contentResolver.query(uri, null, null, null, null)?.let { cursor->
            if(cursor.count > 0) {
                cursor.moveToFirst()
                do {
                    val channel = Channel.fromCursor(cursor)
                } while (cursor.moveToNext() && cursor.isLast.not())
            }
        }
    }
}
Related