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 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         // Figure out the country *before* loading contacts and formatting numbers
     67         mCountryDetector = (CountryDetector) getSystemService(Context.COUNTRY_DETECTOR);
     68         mCountryListener = new CountryListener() {
     69             @Override
     70             public synchronized void onCountryDetected(Country country) {
     71                 mCountryIso = country.getCountryIso();
     72             }
     73         };
     74         mCountryDetector.addCountryListener(mCountryListener, getMainLooper());
     75         mCountryIso = mCountryDetector.detectCountry().getCountryIso();
     76 
     77         MmsConfig.init(this);
     78         Contact.init(this);
     79         DraftCache.init(this);
     80         Conversation.init(this);
     81         DownloadManager.init(this);
     82         RateController.init(this);
     83         DrmUtils.cleanupStorage(this);
     84         LayoutManager.init(this);
     85         SmileyParser.init(this);
     86         MessagingNotification.init(this);
     87     }
     88 
     89     synchronized public static MmsApp getApplication() {
     90         return sMmsApp;
     91     }
     92 
     93     @Override
     94     public void onTerminate() {
     95         DrmUtils.cleanupStorage(this);
     96         mCountryDetector.removeCountryListener(mCountryListener);
     97     }
     98 
     99     @Override
    100     public void onConfigurationChanged(Configuration newConfig) {
    101         LayoutManager.getInstance().onConfigurationChanged(newConfig);
    102     }
    103 
    104     /**
    105      * @return Returns the TelephonyManager.
    106      */
    107     public TelephonyManager getTelephonyManager() {
    108         if (mTelephonyManager == null) {
    109             mTelephonyManager = (TelephonyManager)getApplicationContext()
    110                     .getSystemService(Context.TELEPHONY_SERVICE);
    111         }
    112         return mTelephonyManager;
    113     }
    114 
    115     /**
    116      * Returns the content provider wrapper that allows access to recent searches.
    117      * @return Returns the content provider wrapper that allows access to recent searches.
    118      */
    119     public SearchRecentSuggestions getRecentSuggestions() {
    120         /*
    121         if (mRecentSuggestions == null) {
    122             mRecentSuggestions = new SearchRecentSuggestions(this,
    123                     SuggestionsProvider.AUTHORITY, SuggestionsProvider.MODE);
    124         }
    125         */
    126         return mRecentSuggestions;
    127     }
    128 
    129     public String getCurrentCountryIso() {
    130         return mCountryIso;
    131     }
    132 }
    133