Home | History | Annotate | Download | only in tv
      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 com.android.providers.tv;
     18 
     19 import android.content.ContentValues;
     20 import android.database.sqlite.SQLiteDatabase;
     21 import android.media.tv.TvContract;
     22 import android.net.Uri;
     23 
     24 class TvProviderForTesting extends TvProvider {
     25     private static final String FAKE_SESSION_TOKEN = "TvProviderForTesting";
     26 
     27     String callingPackage;
     28 
     29     @Override
     30     void scheduleEpgDataCleanup() {}
     31 
     32     @Override
     33     String getCallingPackage_() {
     34         if (callingPackage != null) {
     35             return callingPackage;
     36         }
     37         return getContext().getPackageName();
     38     }
     39 
     40     void setTransientRowHelper(TransientRowHelper helper) {
     41         mTransientRowHelper = helper;
     42     }
     43 
     44     // This method is a bypass for testing to avoid async'ly updating restriction of TvProvider
     45     Uri insertWatchedProgramSync(ContentValues values) {
     46         values.put(WATCHED_PROGRAMS_COLUMN_CONSOLIDATED, 1);
     47         values.put(TvContract.WatchedPrograms.COLUMN_INTERNAL_SESSION_TOKEN, FAKE_SESSION_TOKEN);
     48         DatabaseHelper helper = DatabaseHelper.getInstance(getContext());
     49         SQLiteDatabase db = helper.getWritableDatabase();
     50         long rowId = db.insert(WATCHED_PROGRAMS_TABLE, null, values);
     51         return TvContract.buildWatchedProgramUri(rowId);
     52     }
     53 }
     54