1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.permission.cts; 18 19 import android.content.ContentValues; 20 import android.content.pm.PackageManager; 21 import android.media.tv.TvContract; 22 import android.net.Uri; 23 import android.test.AndroidTestCase; 24 25 /** 26 * Tests for TV API related permissions. 27 */ 28 public class TvPermissionTest extends AndroidTestCase { 29 private static final String DUMMY_INPUT_ID = "dummy"; 30 31 private boolean mHasTvInputFramework; 32 33 @Override 34 protected void setUp() throws Exception { 35 super.setUp(); 36 mHasTvInputFramework = getContext().getPackageManager() 37 .hasSystemFeature(PackageManager.FEATURE_LIVE_TV); 38 } 39 40 @Override 41 protected void tearDown() throws Exception { 42 super.tearDown(); 43 } 44 45 public void verifyInsert(Uri uri, String tableName) throws Exception { 46 try { 47 ContentValues values = new ContentValues(); 48 getContext().getContentResolver().insert(uri, values); 49 fail("Accessing " + tableName + " table should require WRITE_EPG_DATA permission."); 50 } catch (SecurityException e) { 51 // Expected exception 52 } 53 } 54 55 public void verifyUpdate(Uri uri, String tableName) throws Exception { 56 try { 57 ContentValues values = new ContentValues(); 58 getContext().getContentResolver().update(uri, values, null, null); 59 fail("Accessing " + tableName + " table should require WRITE_EPG_DATA permission."); 60 } catch (SecurityException e) { 61 // Expected exception 62 } 63 } 64 65 public void verifyDelete(Uri uri, String tableName) throws Exception { 66 try { 67 getContext().getContentResolver().delete(uri, null, null); 68 fail("Accessing " + tableName + " table should require WRITE_EPG_DATA permission."); 69 } catch (SecurityException e) { 70 // Expected exception 71 } 72 } 73 74 public void testInsertChannels() throws Exception { 75 if (!mHasTvInputFramework) return; 76 verifyInsert(TvContract.Channels.CONTENT_URI, "channels"); 77 } 78 79 public void testUpdateChannels() throws Exception { 80 if (!mHasTvInputFramework) return; 81 verifyUpdate(TvContract.Channels.CONTENT_URI, "channels"); 82 } 83 84 public void testDeleteChannels() throws Exception { 85 if (!mHasTvInputFramework) return; 86 verifyDelete(TvContract.Channels.CONTENT_URI, "channels"); 87 } 88 89 public void testInsertPrograms() throws Exception { 90 if (!mHasTvInputFramework) return; 91 verifyInsert(TvContract.Programs.CONTENT_URI, "programs"); 92 } 93 94 public void testUpdatePrograms() throws Exception { 95 if (!mHasTvInputFramework) return; 96 verifyUpdate(TvContract.Programs.CONTENT_URI, "programs"); 97 } 98 99 public void testDeletePrograms() throws Exception { 100 if (!mHasTvInputFramework) return; 101 verifyDelete(TvContract.Programs.CONTENT_URI, "programs"); 102 } 103 } 104