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 java.io.File; 21 import java.util.Locale; 22 23 import com.android.mms.data.Contact; 24 import com.android.mms.data.Conversation; 25 import com.android.mms.layout.LayoutManager; 26 import com.android.mms.util.DownloadManager; 27 import com.android.mms.util.DraftCache; 28 import com.android.mms.drm.DrmUtils; 29 import com.android.mms.util.SmileyParser; 30 import com.android.mms.util.RateController; 31 import com.android.mms.MmsConfig; 32 import com.android.mms.transaction.MessagingNotification; 33 import com.google.android.mms.MmsException; 34 35 import android.app.Application; 36 import android.content.Context; 37 import android.content.res.Configuration; 38 import android.location.Country; 39 import android.location.CountryDetector; 40 import android.location.CountryListener; 41 import android.net.Uri; 42 import android.preference.PreferenceManager; 43 import android.provider.SearchRecentSuggestions; 44 import android.telephony.TelephonyManager; 45 import android.util.Log; 46 47 public class MmsApp extends Application { 48 public static final String LOG_TAG = "Mms"; 49 50 private SearchRecentSuggestions mRecentSuggestions; 51 private TelephonyManager mTelephonyManager; 52 private CountryDetector mCountryDetector; 53 private CountryListener mCountryListener; 54 private String mCountryIso; 55 private static MmsApp sMmsApp = null; 56 57 @Override 58 public void onCreate() { 59 super.onCreate(); 60 61 sMmsApp = this; 62 63 // Load the default preference values 64 PreferenceManager.setDefaultValues(this, R.xml.preferences, false); 65 66 MmsConfig.init(this); 67 Contact.init(this); 68 DraftCache.init(this); 69 Conversation.init(this); 70 DownloadManager.init(this); 71 RateController.init(this); 72 DrmUtils.cleanupStorage(this); 73 LayoutManager.init(this); 74 SmileyParser.init(this); 75 MessagingNotification.init(this); 76 mCountryDetector = (CountryDetector) getSystemService(Context.COUNTRY_DETECTOR); 77 mCountryListener = new CountryListener() { 78 @Override 79 public synchronized void onCountryDetected(Country country) { 80 mCountryIso = country.getCountryIso(); 81 } 82 }; 83 mCountryDetector.addCountryListener(mCountryListener, getMainLooper()); 84 mCountryDetector.detectCountry(); 85 } 86 87 synchronized public static MmsApp getApplication() { 88 return sMmsApp; 89 } 90 91 @Override 92 public void onTerminate() { 93 DrmUtils.cleanupStorage(this); 94 mCountryDetector.removeCountryListener(mCountryListener); 95 } 96 97 @Override 98 public void onConfigurationChanged(Configuration newConfig) { 99 LayoutManager.getInstance().onConfigurationChanged(newConfig); 100 } 101 102 /** 103 * @return Returns the TelephonyManager. 104 */ 105 public TelephonyManager getTelephonyManager() { 106 if (mTelephonyManager == null) { 107 mTelephonyManager = (TelephonyManager)getApplicationContext() 108 .getSystemService(Context.TELEPHONY_SERVICE); 109 } 110 return mTelephonyManager; 111 } 112 113 /** 114 * Returns the content provider wrapper that allows access to recent searches. 115 * @return Returns the content provider wrapper that allows access to recent searches. 116 */ 117 public SearchRecentSuggestions getRecentSuggestions() { 118 /* 119 if (mRecentSuggestions == null) { 120 mRecentSuggestions = new SearchRecentSuggestions(this, 121 SuggestionsProvider.AUTHORITY, SuggestionsProvider.MODE); 122 } 123 */ 124 return mRecentSuggestions; 125 } 126 127 public String getCurrentCountryIso() { 128 return mCountryIso == null ? Locale.getDefault().getCountry() : mCountryIso; 129 } 130 } 131