/*
* Copyright (C) 2007-2008 Esmertec AG.
* Copyright (C) 2007-2008 The Android Open Source Project
* Copyright (c) 2012 The Linux Foundation. All rights reserved.
*
* Not a Contribution.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.mms.transaction;
import android.app.NotificationManager;
import android.app.Notification;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.SystemProperties;
import android.provider.Telephony.Mms;
import android.provider.Telephony.MmsSms;
import android.provider.Telephony.MmsSms.PendingMessages;
import android.telephony.MSimTelephonyManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyProperties;
import com.android.mms.LogTag;
import com.android.mms.MmsConfig;
import com.android.mms.R;
import com.android.mms.ui.MessageUtils;
import com.android.mms.util.DownloadManager;
import com.android.mms.util.MultiSimUtility;
import com.android.mms.util.RateController;
import com.google.android.mms.pdu.GenericPdu;
import com.google.android.mms.pdu.NotificationInd;
import com.google.android.mms.pdu.PduHeaders;
import com.google.android.mms.pdu.PduParser;
import com.google.android.mms.pdu.PduPersister;
import java.io.IOException;
import java.util.ArrayList;
/**
* The TransactionService of the MMS Client is responsible for handling requests
* to initiate client-transactions sent from:
* <ul>
* <li>The Proxy-Relay (Through Push messages)</li>
* <li>The composer/viewer activities of the MMS Client (Through intents)</li>
* </ul>
* The TransactionService runs locally in the same process as the application.
* It contains a HandlerThread to which messages are posted from the
* intent-receivers of this application.
* <p/>
* <b>IMPORTANT</b>: This is currently the only instance in the system in
* which simultaneous connectivity to both the mobile data network and
* a Wi-Fi network is allowed. This makes the code for handling network
* connectivity somewhat different than it is in other applications. In
* particular, we want to be able to send or receive MMS messages when
* a Wi-Fi connection is active (which implies that there is no connection
* to the mobile data network). This has two main consequences:
* <ul>
* <li>Testing for current network connectivity ({@link android.net.NetworkInfo#isConnected()} is
* not sufficient. Instead, the correct test is for network availability
* ({@link android.net.NetworkInfo#isAvailable()}).</li>
* <li>If the mobile data network is not in the connected state, but it is available,
* we must initiate setup of the mobile data connection, and defer handling
* the MMS transaction until the connection is established.</li>
* </ul>
*/
public class TransactionService extends Service implements Observer {
private static final String TAG = "TransactionService";
private static final boolean DEBUG = true;
/**
* Used to identify notification intents broadcasted by the
* TransactionService when a Transaction is completed.
*/
public static final String TRANSACTION_COMPLETED_ACTION =
"android.intent.action.TRANSACTION_COMPLETED_ACTION";
/**
* Action for the Intent which is sent by Alarm service to launch
* TransactionService.
*/
public static final String ACTION_ONALARM = "android.intent.action.ACTION_ONALARM";
/**
* Action for the Intent which is sent when the user turns on the auto-retrieve setting.
* This service gets started to auto-retrieve any undownloaded messages.
*/
public static final String ACTION_ENABLE_AUTO_RETRIEVE
= "android.intent.action.ACTION_ENABLE_AUTO_RETRIEVE";
/**
* Used as extra key in notification intents broadcasted by the TransactionService
* when a Transaction is completed (TRANSACTION_COMPLETED_ACTION intents).
* Allowed values for this key are: TransactionState.INITIALIZED,
* TransactionState.SUCCESS, TransactionState.FAILED.
*/
public static final String STATE = "state";
/**
* Used as extra key in notification intents broadcasted by the TransactionService
* when a Transaction is completed (TRANSACTION_COMPLETED_ACTION intents).
* Allowed values for this key are any valid content uri.
*/
public static final String STATE_URI = "uri";
public static final String CANCEL_URI = "canceluri";
private static final int EVENT_TRANSACTION_REQUEST = 1;
private static final int EVENT_CONTINUE_MMS_CONNECTIVITY = 3;
private static final int EVENT_HANDLE_NEXT_PENDING_TRANSACTION = 4;
private static final int EVENT_NEW_INTENT = 5;
private static final int EVENT_MMS_CONNECTIVITY_TIMEOUT = 6;
private static final int EVENT_QUIT = 100;
// delay 75 seconds to check whether we have enabled mms connectivity
private static final int MMS_CONNECTIVITY_DELAY = 75 * 1000;
private static final int MMS_CONNECTIVITY_RETRY_TIMES = 3;
private static final int TOAST_MSG_QUEUED = 1;
private static final int TOAST_DOWNLOAD_LATER = 2;
private static final int TOAST_NONE = -1;
/*AddBy:yabin.huang BugID:SWBUG00029243 Date:20140515*/
private static final int MMS_AUTO_OPEN_CONNECTIVITY_DELAY = 1 * 1000;
// How often to extend the use of the MMS APN while a transaction
// is still being processed.
private static final int APN_EXTENSION_WAIT = 30 * 1000;
// Retry limit times indicate the pending messages retried in current sub
// if need to switch data back.
private static final int CURRENT_SUB_RETRY_LIMIT = 1;
private ServiceHandler mServiceHandler;
private Looper mServiceLooper;
private final ArrayList<Transaction> mProcessing = new ArrayList<Transaction>();
private final ArrayList<Transaction> mPending = new ArrayList<Transaction>();
private ConnectivityManager mConnMgr;
private ConnectivityBroadcastReceiver mReceiver;
private static TransactionService sInstance;
private PowerManager.WakeLock mWakeLock;
private int mMmsConnecvivityRetryCount;
private Integer mRef = 0;
private int launchRetryAttempt;
private final int maxLaunchRetryAttempts = 5;
private ArrayList<TxnRequest> mTxnSubIdMap = new ArrayList();
public Handler mToastHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
String str = null;
if (msg.what == TOAST_MSG_QUEUED) {
str = getString(R.string.message_queued);
} else if (msg.what == TOAST_DOWNLOAD_LATER) {
str = getString(R.string.download_later);
}
if (str != null) {
Toast.makeText(TransactionService.this, str,
Toast.LENGT
收发彩信,自动打开数据连接
5星 · 超过95%的资源 需积分: 31 106 浏览量
2014-07-07
15:39:13
上传
评论 1
收藏 15KB GZ 举报
高桐@BILL
- 粉丝: 3077
- 资源: 43
最新资源
- +2022%E5%B9%B49%E6%9C%888%E6%97%A5%E6%8B%9F%E5%AF%B9%E5%BB%BA%E8%AE%BE%E9%A1%B9%E7%9B%AE%E7%8E%AF%E8%AF%84%E6%96%87%E4%BB%B6%E4%BD%9C%E5%87%BA%E5%AE%A1%E6%89%B9%E6%84%8F%E8%A7%81%E7%9A%84%E5%85%AC%E7%A4%BA.doc
- 游戏开发游戏开发游戏开发游戏开发游戏开发游戏开发.zip
- 爆破字典集,多用于弱口令于安全测试
- NeteaseCloudMusic_YYJY_netease_2.9.2.240428155332_.apk
- 基于springboot+vue的考试安排系统
- 548KW屋顶分布式光伏发电系统设计整套图纸.zip
- 深度学习实战:Python构建卷积神经网络(CNN)图像识别教程
- VdhCoApp1.3(全套本地安装)
- SOW_龙华NVD設備管理專案V1.6.pdf
- 1. 将⼀些数据库信息导出为Excel表格 2. 将Excel表格数据导⼊数据库 3. ⼤量的数据的导⼊导出操作
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈