• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Intent;
23 import android.content.res.Configuration;
24 import android.drm.DrmManagerClient;
25 import android.location.Country;
26 import android.location.CountryDetector;
27 import android.location.CountryListener;
28 import android.os.StrictMode;
29 import android.preference.PreferenceManager;
30 import android.provider.SearchRecentSuggestions;
31 import android.telephony.TelephonyManager;
32 import android.util.Log;
33 
34 import com.android.mms.data.Contact;
35 import com.android.mms.data.Conversation;
36 import com.android.mms.layout.LayoutManager;
37 import com.android.mms.transaction.MessagingNotification;
38 import com.android.mms.transaction.MmsSystemEventReceiver;
39 import com.android.mms.transaction.SmsReceiver;
40 import com.android.mms.transaction.SmsReceiverService;
41 import com.android.mms.util.DownloadManager;
42 import com.android.mms.util.DraftCache;
43 import com.android.mms.util.PduLoaderManager;
44 import com.android.mms.util.RateController;
45 import com.android.mms.util.ThumbnailManager;
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     private PduLoaderManager mPduLoaderManager;
57     private ThumbnailManager mThumbnailManager;
58     private DrmManagerClient mDrmManagerClient;
59 
60     @Override
onCreate()61     public void onCreate() {
62         super.onCreate();
63 
64         if (Log.isLoggable(LogTag.STRICT_MODE_TAG, Log.DEBUG)) {
65             // Log tag for enabling/disabling StrictMode violation log. This will dump a stack
66             // in the log that shows the StrictMode violator.
67             // To enable: adb shell setprop log.tag.Mms:strictmode DEBUG
68             StrictMode.setThreadPolicy(
69                     new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
70         }
71 
72         sMmsApp = this;
73 
74         // Load the default preference values
75         PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
76 
77         // Figure out the country *before* loading contacts and formatting numbers
78         mCountryDetector = (CountryDetector) getSystemService(Context.COUNTRY_DETECTOR);
79         mCountryListener = new CountryListener() {
80             @Override
81             public synchronized void onCountryDetected(Country country) {
82                 mCountryIso = country.getCountryIso();
83             }
84         };
85         mCountryDetector.addCountryListener(mCountryListener, getMainLooper());
86 
87         Context context = getApplicationContext();
88         mPduLoaderManager = new PduLoaderManager(context);
89         mThumbnailManager = new ThumbnailManager(context);
90 
91         MmsConfig.init(this);
92         Contact.init(this);
93         DraftCache.init(this);
94         Conversation.init(this);
95         DownloadManager.init(this);
96         RateController.init(this);
97         LayoutManager.init(this);
98         MessagingNotification.init(this);
99 
100         activePendingMessages();
101     }
102 
103     /**
104      * Try to process all pending messages(which were interrupted by user, OOM, Mms crashing,
105      * etc...) when Mms app is (re)launched.
106      */
activePendingMessages()107     private void activePendingMessages() {
108         // For Mms: try to process all pending transactions if possible
109         MmsSystemEventReceiver.wakeUpService(this);
110 
111         // For Sms: retry to send smses in outbox and queued box
112         sendBroadcast(new Intent(SmsReceiverService.ACTION_SEND_INACTIVE_MESSAGE,
113                 null,
114                 this,
115                 SmsReceiver.class));
116     }
117 
getApplication()118     synchronized public static MmsApp getApplication() {
119         return sMmsApp;
120     }
121 
122     @Override
onTerminate()123     public void onTerminate() {
124         mCountryDetector.removeCountryListener(mCountryListener);
125     }
126 
127     @Override
onLowMemory()128     public void onLowMemory() {
129         super.onLowMemory();
130 
131         mPduLoaderManager.onLowMemory();
132         mThumbnailManager.onLowMemory();
133     }
134 
getPduLoaderManager()135     public PduLoaderManager getPduLoaderManager() {
136         return mPduLoaderManager;
137     }
138 
getThumbnailManager()139     public ThumbnailManager getThumbnailManager() {
140         return mThumbnailManager;
141     }
142 
143     @Override
onConfigurationChanged(Configuration newConfig)144     public void onConfigurationChanged(Configuration newConfig) {
145         LayoutManager.getInstance().onConfigurationChanged(newConfig);
146     }
147 
148     /**
149      * @return Returns the TelephonyManager.
150      */
getTelephonyManager()151     public TelephonyManager getTelephonyManager() {
152         if (mTelephonyManager == null) {
153             mTelephonyManager = (TelephonyManager)getApplicationContext()
154                     .getSystemService(Context.TELEPHONY_SERVICE);
155         }
156         return mTelephonyManager;
157     }
158 
159     /**
160      * Returns the content provider wrapper that allows access to recent searches.
161      * @return Returns the content provider wrapper that allows access to recent searches.
162      */
getRecentSuggestions()163     public SearchRecentSuggestions getRecentSuggestions() {
164         /*
165         if (mRecentSuggestions == null) {
166             mRecentSuggestions = new SearchRecentSuggestions(this,
167                     SuggestionsProvider.AUTHORITY, SuggestionsProvider.MODE);
168         }
169         */
170         return mRecentSuggestions;
171     }
172 
173     // This function CAN return null.
getCurrentCountryIso()174     public String getCurrentCountryIso() {
175         if (mCountryIso == null) {
176             Country country = mCountryDetector.detectCountry();
177             if (country != null) {
178                 mCountryIso = country.getCountryIso();
179             }
180         }
181         return mCountryIso;
182     }
183 
getDrmManagerClient()184     public DrmManagerClient getDrmManagerClient() {
185         if (mDrmManagerClient == null) {
186             mDrmManagerClient = new DrmManagerClient(getApplicationContext());
187         }
188         return mDrmManagerClient;
189     }
190 
191 }
192