• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007-2008 Esmertec AG.
3  * Copyright (C) 2007-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.transaction;
19 
20 import android.content.BroadcastReceiver;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.net.ConnectivityManager;
24 import android.net.NetworkInfo;
25 import android.net.Uri;
26 import android.provider.Telephony.Mms;
27 import android.util.Log;
28 
29 import com.android.mms.LogTag;
30 import com.android.mms.MmsApp;
31 
32 /**
33  * MmsSystemEventReceiver receives the
34  * {@link android.content.intent.ACTION_BOOT_COMPLETED},
35  * {@link com.android.internal.telephony.TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED}
36  * and performs a series of operations which may include:
37  * <ul>
38  * <li>Show/hide the icon in notification area which is used to indicate
39  * whether there is new incoming message.</li>
40  * <li>Resend the MM's in the outbox.</li>
41  * </ul>
42  */
43 public class MmsSystemEventReceiver extends BroadcastReceiver {
44     private static final String TAG = "MmsSystemEventReceiver";
45     private static ConnectivityManager mConnMgr = null;
46 
wakeUpService(Context context)47     public static void wakeUpService(Context context) {
48         if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
49             Log.v(TAG, "wakeUpService: start transaction service ...");
50         }
51 
52         context.startService(new Intent(context, TransactionService.class));
53     }
54 
55     @Override
onReceive(Context context, Intent intent)56     public void onReceive(Context context, Intent intent) {
57         if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
58             Log.v(TAG, "Intent received: " + intent);
59         }
60 
61         String action = intent.getAction();
62         if (action.equals(Mms.Intents.CONTENT_CHANGED_ACTION)) {
63             Uri changed = (Uri) intent.getParcelableExtra(Mms.Intents.DELETED_CONTENTS);
64             MmsApp.getApplication().getPduLoaderManager().removePdu(changed);
65         } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
66             if (mConnMgr == null) {
67                 mConnMgr = (ConnectivityManager) context
68                         .getSystemService(Context.CONNECTIVITY_SERVICE);
69             }
70             if (!mConnMgr.getMobileDataEnabled()) {
71                 if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
72                     Log.v(TAG, "mobile data turned off, bailing");
73                 }
74                 return;
75             }
76             NetworkInfo mmsNetworkInfo = mConnMgr
77                     .getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS);
78             boolean available = mmsNetworkInfo.isAvailable();
79             boolean isConnected = mmsNetworkInfo.isConnected();
80 
81             if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
82                 Log.v(TAG, "TYPE_MOBILE_MMS available = " + available +
83                            ", isConnected = " + isConnected);
84             }
85 
86             // Wake up transact service when MMS data is available and isn't connected.
87             if (available && !isConnected) {
88                 wakeUpService(context);
89             }
90         } else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
91             // We should check whether there are unread incoming
92             // messages in the Inbox and then update the notification icon.
93             // Called on the UI thread so don't block.
94             MessagingNotification.nonBlockingUpdateNewMessageIndicator(
95                     context, MessagingNotification.THREAD_NONE, false);
96 
97             // Scan and send pending Mms once after boot completed since
98             // ACTION_ANY_DATA_CONNECTION_STATE_CHANGED wasn't registered in a whole life cycle
99             wakeUpService(context);
100         }
101     }
102 }
103