1 /*
2  * Copyright (C) 2015 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 package com.android.providers.contacts;
17 
18 import android.content.ContentValues;
19 import android.content.Context;
20 import android.database.sqlite.SQLiteDatabase;
21 import android.provider.CallLog.Calls;
22 import junit.framework.Assert;
23 
24 public class CallLogProviderTestable extends CallLogProvider {
25     private CallLogDatabaseHelperTestable mDbHelper;
26 
27     private SQLiteDatabase mContactsDbForMigration;
28 
setContactsDbForMigration(SQLiteDatabase db)29     public void setContactsDbForMigration(SQLiteDatabase db) {
30         Assert.assertNull(
31                 "setContactsDbForMigration() must be called before DB helepr is instantiated",
32                 mDbHelper);
33         mContactsDbForMigration = db;
34     }
35 
36     @Override
getDatabaseHelper(final Context context)37     protected CallLogDatabaseHelper getDatabaseHelper(final Context context) {
38         if (mDbHelper == null) {
39             mDbHelper = new CallLogDatabaseHelperTestable(context, mContactsDbForMigration);
40         }
41         return mDbHelper;
42     }
43 
44     @Override
createCallLogInsertionHelper(Context context)45     protected CallLogInsertionHelper createCallLogInsertionHelper(Context context) {
46         return new CallLogInsertionHelper() {
47             @Override
48             public String getGeocodedLocationFor(String number, String countryIso) {
49                 return "usa";
50             }
51 
52             @Override
53             public void addComputedValues(ContentValues values) {
54                 values.put(Calls.COUNTRY_ISO, "us");
55                 values.put(Calls.GEOCODED_LOCATION, "usa");
56             }
57         };
58     }
59 }
60