Home | History | Annotate | Download | only in mms
      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
     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         mCountryIso = mCountryDetector.detectCountry().getCountryIso();
     84 
     85         Context context = getApplicationContext();
     86         mPduLoaderManager = new PduLoaderManager(context);
     87         mThumbnailManager = new ThumbnailManager(context);
     88 
     89         MmsConfig.init(this);
     90         Contact.init(this);
     91         DraftCache.init(this);
     92         Conversation.init(this);
     93         DownloadManager.init(this);
     94         RateController.init(this);
     95         LayoutManager.init(this);
     96         SmileyParser.init(this);
     97         MessagingNotification.init(this);
     98     }
     99 
    100     synchronized public static MmsApp getApplication() {
    101         return sMmsApp;
    102     }
    103 
    104     @Override
    105     public void onTerminate() {
    106         mCountryDetector.removeCountryListener(mCountryListener);
    107     }
    108 
    109     @Override
    110     public void onLowMemory() {
    111         super.onLowMemory();
    112 
    113         mPduLoaderManager.onLowMemory();
    114         mThumbnailManager.onLowMemory();
    115     }
    116 
    117     public PduLoaderManager getPduLoaderManager() {
    118         return mPduLoaderManager;
    119     }
    120 
    121     public ThumbnailManager getThumbnailManager() {
    122         return mThumbnailManager;
    123     }
    124 
    125     @Override
    126     public void onConfigurationChanged(Configuration newConfig) {
    127         LayoutManager.getInstance().onConfigurationChanged(newConfig);
    128     }
    129 
    130     /**
    131      * @return Returns the TelephonyManager.
    132      */
    133     public TelephonyManager getTelephonyManager() {
    134         if (mTelephonyManager == null) {
    135             mTelephonyManager = (TelephonyManager)getApplicationContext()
    136                     .getSystemService(Context.TELEPHONY_SERVICE);
    137         }
    138         return mTelephonyManager;
    139     }
    140 
    141     /**
    142      * Returns the content provider wrapper that allows access to recent searches.
    143      * @return Returns the content provider wrapper that allows access to recent searches.
    144      */
    145     public SearchRecentSuggestions getRecentSuggestions() {
    146         /*
    147         if (mRecentSuggestions == null) {
    148             mRecentSuggestions = new SearchRecentSuggestions(this,
    149                     SuggestionsProvider.AUTHORITY, SuggestionsProvider.MODE);
    150         }
    151         */
    152         return mRecentSuggestions;
    153     }
    154 
    155     public String getCurrentCountryIso() {
    156         return mCountryIso;
    157     }
    158 
    159     public DrmManagerClient getDrmManagerClient() {
    160         if (mDrmManagerClient == null) {
    161             mDrmManagerClient = new DrmManagerClient(getApplicationContext());
    162         }
    163         return mDrmManagerClient;
    164     }
    165 
    166 }
    167