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 17 package com.android.messaging; 18 19 import android.content.Context; 20 21 import com.android.messaging.datamodel.DataModel; 22 import com.android.messaging.datamodel.MemoryCacheManager; 23 import com.android.messaging.datamodel.ParticipantRefresh.ContactContentObserver; 24 import com.android.messaging.datamodel.media.MediaCacheManager; 25 import com.android.messaging.datamodel.media.MediaResourceManager; 26 import com.android.messaging.sms.BugleCarrierConfigValuesLoader; 27 import com.android.messaging.ui.UIIntents; 28 import com.android.messaging.util.Assert; 29 import com.android.messaging.util.BugleGservices; 30 import com.android.messaging.util.BuglePrefs; 31 import com.android.messaging.util.MediaUtil; 32 import com.android.messaging.util.PhoneUtils; 33 import com.google.common.annotations.VisibleForTesting; 34 35 public abstract class Factory { 36 37 // Making this volatile because on the unit tests, setInstance is called from a unit test 38 // thread, and then it's read on the UI thread. 39 private static volatile Factory sInstance; 40 @VisibleForTesting 41 protected static boolean sRegistered; 42 @VisibleForTesting 43 protected static boolean sInitialized; 44 get()45 public static Factory get() { 46 return sInstance; 47 } 48 setInstance(final Factory factory)49 protected static void setInstance(final Factory factory) { 50 // Not allowed to call this after real application initialization is complete 51 Assert.isTrue(!sRegistered); 52 Assert.isTrue(!sInitialized); 53 sInstance = factory; 54 } onRequiredPermissionsAcquired()55 public abstract void onRequiredPermissionsAcquired(); 56 getApplicationContext()57 public abstract Context getApplicationContext(); getDataModel()58 public abstract DataModel getDataModel(); getBugleGservices()59 public abstract BugleGservices getBugleGservices(); getApplicationPrefs()60 public abstract BuglePrefs getApplicationPrefs(); getSubscriptionPrefs(int subId)61 public abstract BuglePrefs getSubscriptionPrefs(int subId); getWidgetPrefs()62 public abstract BuglePrefs getWidgetPrefs(); getUIIntents()63 public abstract UIIntents getUIIntents(); getMemoryCacheManager()64 public abstract MemoryCacheManager getMemoryCacheManager(); getMediaResourceManager()65 public abstract MediaResourceManager getMediaResourceManager(); getMediaCacheManager()66 public abstract MediaCacheManager getMediaCacheManager(); getContactContentObserver()67 public abstract ContactContentObserver getContactContentObserver(); getPhoneUtils(int subId)68 public abstract PhoneUtils getPhoneUtils(int subId); getMediaUtil()69 public abstract MediaUtil getMediaUtil(); getCarrierConfigValuesLoader()70 public abstract BugleCarrierConfigValuesLoader getCarrierConfigValuesLoader(); 71 // Note this needs to run from any thread reclaimMemory()72 public abstract void reclaimMemory(); 73 onActivityResume()74 public abstract void onActivityResume(); 75 } 76