blob: 8cbdfbf8fab205150b8c8326795c18ae78f93561 [file] [log] [blame]
Dmitri Plotnikovf049ff02010-11-29 10:15:24 -08001/*
2 * Copyright (C) 2010 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
17package com.android.contacts;
18
Dmitri Plotnikov169ff2a2010-11-29 16:58:31 -080019import com.android.contacts.model.AccountTypes;
Dmitri Plotnikov43fd1e82011-01-09 11:29:39 -080020import com.android.contacts.test.InjectedServices;
Dmitri Plotnikov169ff2a2010-11-29 16:58:31 -080021
Dmitri Plotnikovf049ff02010-11-29 10:15:24 -080022import android.app.Application;
Dmitri Plotnikov43fd1e82011-01-09 11:29:39 -080023import android.content.ContentResolver;
Dmitri Plotnikov3b7dedd2010-11-29 14:46:10 -080024import android.content.Context;
Dmitri Plotnikovf049ff02010-11-29 10:15:24 -080025import android.os.StrictMode;
Dmitri Plotnikov3b7dedd2010-11-29 14:46:10 -080026import android.preference.PreferenceManager;
27
Dmitri Plotnikovf049ff02010-11-29 10:15:24 -080028public final class ContactsApplication extends Application {
29
Dmitri Plotnikov43fd1e82011-01-09 11:29:39 -080030 private static InjectedServices sInjectedServices;
31
32 /**
33 * Overrides the system services with mocks for testing.
34 */
35 public static void injectContentResolver(InjectedServices services) {
36 sInjectedServices = services;
37 }
38
39 @Override
40 public ContentResolver getContentResolver() {
41 if (sInjectedServices != null) {
42 ContentResolver resolver = sInjectedServices.getContentResolver();
43 if (resolver != null) {
44 return resolver;
45 }
46 }
47 return super.getContentResolver();
48 }
49
Dmitri Plotnikovf049ff02010-11-29 10:15:24 -080050 @Override
51 public void onCreate() {
52 super.onCreate();
53
Dmitri Plotnikov3b7dedd2010-11-29 14:46:10 -080054 // Priming caches to placate the StrictMode police
55 Context context = getApplicationContext();
56 PreferenceManager.getDefaultSharedPreferences(context);
Dmitri Plotnikov3b7dedd2010-11-29 14:46:10 -080057 AccountTypes.getInstance(context);
58
Dmitri Plotnikovf049ff02010-11-29 10:15:24 -080059 StrictMode.setThreadPolicy(
60 new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
61 }
62}