1 /* 2 * Copyright (C) 2008 Esmertec AG. 3 * Copyright (C) 2008 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.mms; 19 20 import android.app.Application; 21 import android.content.Context; 22 import android.content.res.Configuration; 23 import android.drm.DrmManagerClient; 24 import android.location.Country; 25 import android.location.CountryDetector; 26 import android.location.CountryListener; 27 import android.os.StrictMode; 28 import android.preference.PreferenceManager; 29 import android.provider.SearchRecentSuggestions; 30 import android.telephony.TelephonyManager; 31 import android.util.Log; 32 33 import com.android.mms.data.Contact; 34 import com.android.mms.data.Conversation; 35 import com.android.mms.layout.LayoutManager; 36 import com.android.mms.transaction.MessagingNotification; 37 import com.android.mms.util.DownloadManager; 38 import com.android.mms.util.DraftCache; 39 import com.android.mms.util.PduLoaderManager; 40 import com.android.mms.util.RateController; 41 import com.android.mms.util.SmileyParser; 42 import com.android.mms.util.ThumbnailManager; 43 44 public class MmsApp extends Application { 45 public static final String LOG_TAG = "Mms"; 46 47 private SearchRecentSuggestions mRecentSuggestions; 48 private TelephonyManager mTelephonyManager; 49 private CountryDetector mCountryDetector; 50 private CountryListener mCountryListener; 51 private String mCountryIso; 52 private static MmsApp sMmsApp = null; 53 private PduLoaderManager mPduLoaderManager; 54 private ThumbnailManager mThumbnailManager; 55 private DrmManagerClient mDrmManagerClient; 56 57 @Override onCreate()58 public void onCreate() { 59 super.onCreate(); 60 61 if (Log.isLoggable(LogTag.STRICT_MODE_TAG, Log.DEBUG)) { 62 // Log tag for enabling/disabling StrictMode violation log. This will dump a stack 63 // in the log that shows the StrictMode violator. 64 // To enable: adb shell setprop log.tag.Mms:strictmode DEBUG 65 StrictMode.setThreadPolicy( 66 new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); 67 } 68 69 sMmsApp = this; 70 71 // Load the default preference values 72 PreferenceManager.setDefaultValues(this, R.xml.preferences, false); 73 74 // Figure out the country *before* loading contacts and formatting numbers 75 mCountryDetector = (CountryDetector) getSystemService(Context.COUNTRY_DETECTOR); 76 mCountryListener = new CountryListener() { 77 @Override 78 public synchronized void onCountryDetected(Country country) { 79 mCountryIso = country.getCountryIso(); 80 } 81 }; 82 mCountryDetector.addCountryListener(mCountryListener, getMainLooper()); 83 84 Context context = getApplicationContext(); 85 mPduLoaderManager = new PduLoaderManager(context); 86 mThumbnailManager = new ThumbnailManager(context); 87 88 MmsConfig.init(this); 89 Contact.init(this); 90 DraftCache.init(this); 91 Conversation.init(this); 92 DownloadManager.init(this); 93 RateController.init(this); 94 LayoutManager.init(this); 95 SmileyParser.init(this); 96 MessagingNotification.init(this); 97 } 98 getApplication()99 synchronized public static MmsApp getApplication() { 100 return sMmsApp; 101 } 102 103 @Override onTerminate()104 public void onTerminate() { 105 mCountryDetector.removeCountryListener(mCountryListener); 106 } 107 108 @Override onLowMemory()109 public void onLowMemory() { 110 super.onLowMemory(); 111 112 mPduLoaderManager.onLowMemory(); 113 mThumbnailManager.onLowMemory(); 114 } 115 getPduLoaderManager()116 public PduLoaderManager getPduLoaderManager() { 117 return mPduLoaderManager; 118 } 119 getThumbnailManager()120 public ThumbnailManager getThumbnailManager() { 121 return mThumbnailManager; 122 } 123 124 @Override onConfigurationChanged(Configuration newConfig)125 public void onConfigurationChanged(Configuration newConfig) { 126 LayoutManager.getInstance().onConfigurationChanged(newConfig); 127 } 128 129 /** 130 * @return Returns the TelephonyManager. 131 */ getTelephonyManager()132 public TelephonyManager getTelephonyManager() { 133 if (mTelephonyManager == null) { 134 mTelephonyManager = (TelephonyManager)getApplicationContext() 135 .getSystemService(Context.TELEPHONY_SERVICE); 136 } 137 return mTelephonyManager; 138 } 139 140 /** 141 * Returns the content provider wrapper that allows access to recent searches. 142 * @return Returns the content provider wrapper that allows access to recent searches. 143 */ getRecentSuggestions()144 public SearchRecentSuggestions getRecentSuggestions() { 145 /* 146 if (mRecentSuggestions == null) { 147 mRecentSuggestions = new SearchRecentSuggestions(this, 148 SuggestionsProvider.AUTHORITY, SuggestionsProvider.MODE); 149 } 150 */ 151 return mRecentSuggestions; 152 } 153 154 // This function CAN return null. getCurrentCountryIso()155 public String getCurrentCountryIso() { 156 if (mCountryIso == null) { 157 Country country = mCountryDetector.detectCountry(); 158 if (country != null) { 159 mCountryIso = country.getCountryIso(); 160 } 161 } 162 return mCountryIso; 163 } 164 getDrmManagerClient()165 public DrmManagerClient getDrmManagerClient() { 166 if (mDrmManagerClient == null) { 167 mDrmManagerClient = new DrmManagerClient(getApplicationContext()); 168 } 169 return mDrmManagerClient; 170 } 171 172 } 173