Home | History | Annotate | Download | only in hostside
      1 /*
      2  * Copyright (C) 2016 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 com.android.cts.numberblocking.hostside;
     18 
     19 import android.content.ContentValues;
     20 import android.provider.BlockedNumberContract;
     21 
     22 /**
     23  * Tests number blocking features as a privileged app that can block numbers.
     24  */
     25 public class NumberBlockingAppTest extends BaseNumberBlockingClientTest {
     26     public void testCleanupBlockedNumberAsPrimaryUserSucceeds() throws Exception {
     27         assertTrue(BlockedNumberContract.canCurrentUserBlockNumbers(mContext));
     28 
     29         assertTrue(mContext.getContentResolver().delete(
     30                 BlockedNumberContract.BlockedNumbers.CONTENT_URI,
     31                 BlockedNumberContract.BlockedNumbers.COLUMN_ORIGINAL_NUMBER + "= ?",
     32                 new String[]{mBlockedPhoneNumber}) <= 1);
     33     }
     34 
     35     public void testBlockNumberAsPrimaryUserSucceeds() throws Exception {
     36         assertTrue(BlockedNumberContract.canCurrentUserBlockNumbers(mContext));
     37 
     38         verifyInsertBlockedNumberSucceeds();
     39     }
     40 
     41     public void testSecondaryUserCannotBlockNumbers() throws Exception {
     42         assertFalse(BlockedNumberContract.canCurrentUserBlockNumbers(mContext));
     43 
     44         try {
     45             BlockedNumberContract.isBlocked(mContext, mBlockedPhoneNumber);
     46             fail("Expected SecurityException.");
     47         } catch (SecurityException expected) {
     48         }
     49     }
     50 
     51     public void testUnblockNumberAsPrimaryUserSucceeds() throws Exception {
     52         assertTrue(BlockedNumberContract.canCurrentUserBlockNumbers(mContext));
     53 
     54         assertEquals(1, mContext.getContentResolver().delete(
     55                 BlockedNumberContract.BlockedNumbers.CONTENT_URI,
     56                 BlockedNumberContract.BlockedNumbers.COLUMN_ORIGINAL_NUMBER + "= ?",
     57                 new String[]{mBlockedPhoneNumber}));
     58     }
     59 
     60     private void verifyInsertBlockedNumberSucceeds() {
     61         ContentValues cv = new ContentValues();
     62         cv.put(BlockedNumberContract.BlockedNumbers.COLUMN_ORIGINAL_NUMBER, mBlockedPhoneNumber);
     63         mContext.getContentResolver().insert(
     64                 BlockedNumberContract.BlockedNumbers.CONTENT_URI, cv);
     65         assertTrue(BlockedNumberContract.isBlocked(mContext, mBlockedPhoneNumber));
     66     }
     67 }
     68