156fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee/*
256fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee * Copyright (C) 2013 The Android Open Source Project
356fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee *
456fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee * Licensed under the Apache License, Version 2.0 (the "License");
556fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee * you may not use this file except in compliance with the License.
656fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee * You may obtain a copy of the License at
756fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee *
856fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee *      http://www.apache.org/licenses/LICENSE-2.0
956fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee *
1056fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee * Unless required by applicable law or agreed to in writing, software
1156fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee * distributed under the License is distributed on an "AS IS" BASIS,
1256fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1356fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee * See the License for the specific language governing permissions and
1456fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee * limitations under the License
1556fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee */
1605de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albert
1705de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albertpackage com.android.dialer;
1805de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albert
1905de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albertimport android.app.Application;
2013825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwellimport android.content.Context;
21f5554ceb3c152949b4b6278b7f5e1522148a574cYorke Leeimport android.os.Trace;
2203dffbf949a9758da1b296369d29ef8b3aecae38Brandon Maxwellimport android.preference.PreferenceManager;
2313825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwellimport android.support.annotation.Nullable;
2405de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albert
2505de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albertimport com.android.contacts.common.extensions.ExtensionsFactory;
2613825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwellimport com.android.contacts.common.testing.NeededForTesting;
2703dffbf949a9758da1b296369d29ef8b3aecae38Brandon Maxwellimport com.android.dialer.database.FilteredNumberAsyncQueryHandler;
2803dffbf949a9758da1b296369d29ef8b3aecae38Brandon Maxwellimport com.android.dialer.filterednumber.BlockedNumbersAutoMigrator;
2905de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albert
3005de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albertpublic class DialerApplication extends Application {
3105de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albert
32f5554ceb3c152949b4b6278b7f5e1522148a574cYorke Lee    private static final String TAG = "DialerApplication";
3356fe5898b2c995ceab5b171af7daf1f7b2e8d4dbYorke Lee
3413825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell    private static Context sContext;
3513825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell
3605de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albert    @Override
3705de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albert    public void onCreate() {
3813825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell        sContext = this;
39f5554ceb3c152949b4b6278b7f5e1522148a574cYorke Lee        Trace.beginSection(TAG + " onCreate");
4005de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albert        super.onCreate();
41f5554ceb3c152949b4b6278b7f5e1522148a574cYorke Lee        Trace.beginSection(TAG + " ExtensionsFactory initialization");
4205de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albert        ExtensionsFactory.init(getApplicationContext());
43f5554ceb3c152949b4b6278b7f5e1522148a574cYorke Lee        Trace.endSection();
4403dffbf949a9758da1b296369d29ef8b3aecae38Brandon Maxwell        new BlockedNumbersAutoMigrator(PreferenceManager.getDefaultSharedPreferences(this),
4503dffbf949a9758da1b296369d29ef8b3aecae38Brandon Maxwell                new FilteredNumberAsyncQueryHandler(getContentResolver())).autoMigrate();
46f5554ceb3c152949b4b6278b7f5e1522148a574cYorke Lee        Trace.endSection();
4705de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albert    }
4813825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell
4913825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell    @Nullable
5013825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell    public static Context getContext() {
5113825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell        return sContext;
5213825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell    }
5313825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell
5413825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell    @NeededForTesting
5513825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell    public static void setContextForTest(Context context) {
5613825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell        sContext = context;
5713825f0533ec175928406f5e9b79c54305e8c5b0Brandon Maxwell    }
5805de701306a4986e91a9b2b2eed3bce71d6d9e6fAlon Albert}
59