1d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/*
2d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2015 The Android Open Source Project
3d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *
4d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Licensed under the Apache License, Version 2.0 (the "License");
5d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * you may not use this file except in compliance with the License.
6d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * You may obtain a copy of the License at
7d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *
8d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *      http://www.apache.org/licenses/LICENSE-2.0
9d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *
10d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Unless required by applicable law or agreed to in writing, software
11d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * distributed under the License is distributed on an "AS IS" BASIS,
12d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * See the License for the specific language governing permissions and
14d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * limitations under the License.
15d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */
16d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging;
18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context;
20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.DataModel;
22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.MemoryCacheManager;
23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.ParticipantRefresh.ContactContentObserver;
24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.media.MediaCacheManager;
25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.media.MediaResourceManager;
26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.sms.BugleCarrierConfigValuesLoader;
27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.ui.UIIntents;
28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.Assert;
29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.BugleGservices;
30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.BuglePrefs;
31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.MediaUtil;
32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.PhoneUtils;
33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.google.common.annotations.VisibleForTesting;
34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic abstract class Factory {
36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    // Making this volatile because on the unit tests, setInstance is called from a unit test
38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    // thread, and then it's read on the UI thread.
39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    private static volatile Factory sInstance;
40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    @VisibleForTesting
41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    protected static boolean sRegistered;
42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    @VisibleForTesting
43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    protected static boolean sInitialized;
44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public static Factory get() {
46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        return sInstance;
47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    protected static void setInstance(final Factory factory) {
50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        // Not allowed to call this after real application initialization is complete
51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        Assert.isTrue(!sRegistered);
52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        Assert.isTrue(!sInitialized);
53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        sInstance = factory;
54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract void onRequiredPermissionsAcquired();
56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract Context getApplicationContext();
58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract DataModel getDataModel();
59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract BugleGservices getBugleGservices();
60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract BuglePrefs getApplicationPrefs();
61d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract BuglePrefs getSubscriptionPrefs(int subId);
62d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract BuglePrefs getWidgetPrefs();
63d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract UIIntents getUIIntents();
64d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract MemoryCacheManager getMemoryCacheManager();
65d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract MediaResourceManager getMediaResourceManager();
66d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract MediaCacheManager getMediaCacheManager();
67d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract ContactContentObserver getContactContentObserver();
68d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract PhoneUtils getPhoneUtils(int subId);
69d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract MediaUtil getMediaUtil();
70d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract BugleCarrierConfigValuesLoader getCarrierConfigValuesLoader();
71d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    // Note this needs to run from any thread
72d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract void reclaimMemory();
73d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
74d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract void onActivityResume();
75d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd}
76