Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.mms.service; |
| 18 | |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 20 | import android.app.PendingIntent; |
| 21 | import android.app.Service; |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 22 | import android.content.ContentResolver; |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 23 | import android.content.ContentUris; |
| 24 | import android.content.ContentValues; |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 25 | import android.content.Context; |
Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 26 | import android.content.Intent; |
Ye Wen | 8c027a6 | 2014-07-14 16:23:31 -0700 | [diff] [blame] | 27 | import android.content.SharedPreferences; |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 28 | import android.database.sqlite.SQLiteException; |
| 29 | import android.net.Uri; |
| 30 | import android.os.Binder; |
Shri Borde | 8a79dc0 | 2014-09-02 09:49:09 -0700 | [diff] [blame] | 31 | import android.os.Bundle; |
Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 32 | import android.os.IBinder; |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 33 | import android.os.ParcelFileDescriptor; |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 34 | import android.os.Process; |
Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 35 | import android.os.RemoteException; |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 36 | import android.provider.Telephony; |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 37 | import android.service.carrier.CarrierMessagingService; |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 38 | import android.telephony.SmsManager; |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 39 | import android.telephony.SubscriptionManager; |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 40 | import android.telephony.TelephonyManager; |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 41 | import android.text.TextUtils; |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 42 | import android.util.SparseArray; |
| 43 | |
| 44 | import com.android.internal.telephony.IMms; |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 45 | import com.google.android.mms.MmsException; |
| 46 | import com.google.android.mms.pdu.DeliveryInd; |
| 47 | import com.google.android.mms.pdu.GenericPdu; |
| 48 | import com.google.android.mms.pdu.NotificationInd; |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 49 | import com.google.android.mms.pdu.PduParser; |
| 50 | import com.google.android.mms.pdu.PduPersister; |
| 51 | import com.google.android.mms.pdu.ReadOrigInd; |
| 52 | import com.google.android.mms.pdu.RetrieveConf; |
| 53 | import com.google.android.mms.pdu.SendReq; |
| 54 | import com.google.android.mms.util.SqliteWrapper; |
Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 55 | |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 56 | import java.io.IOException; |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 57 | import java.util.ArrayDeque; |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 58 | import java.util.Arrays; |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 59 | import java.util.List; |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 60 | import java.util.Queue; |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 61 | import java.util.concurrent.Callable; |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 62 | import java.util.concurrent.ExecutorService; |
| 63 | import java.util.concurrent.Executors; |
| 64 | import java.util.concurrent.Future; |
| 65 | import java.util.concurrent.TimeUnit; |
Ye Wen | b786d3e | 2014-07-03 14:08:16 -0700 | [diff] [blame] | 66 | |
Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 67 | /** |
| 68 | * System service to process MMS API requests |
| 69 | */ |
Ye Wen | b786d3e | 2014-07-03 14:08:16 -0700 | [diff] [blame] | 70 | public class MmsService extends Service implements MmsRequest.RequestManager { |
Ye Wen | b786d3e | 2014-07-03 14:08:16 -0700 | [diff] [blame] | 71 | public static final int QUEUE_INDEX_SEND = 0; |
| 72 | public static final int QUEUE_INDEX_DOWNLOAD = 1; |
| 73 | |
Ye Wen | 8c027a6 | 2014-07-14 16:23:31 -0700 | [diff] [blame] | 74 | private static final String SHARED_PREFERENCES_NAME = "mmspref"; |
| 75 | private static final String PREF_AUTO_PERSISTING = "autopersisting"; |
| 76 | |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 77 | // Maximum time to spend waiting to read data from a content provider before failing with error. |
| 78 | private static final int TASK_TIMEOUT_MS = 30 * 1000; |
| 79 | // Maximum size of MMS service supports - used on occassions when MMS messages are processed |
| 80 | // in a carrier independent manner (for example for imports and drafts) and the carrier |
| 81 | // specific size limit should not be used (as it could be lower on some carriers). |
| 82 | private static final int MAX_MMS_FILE_SIZE = 8 * 1024 * 1024; |
| 83 | |
Ye Wen | a167df7 | 2015-04-01 15:55:06 -0700 | [diff] [blame] | 84 | // The default number of threads allowed to run MMS requests in each queue |
| 85 | public static final int THREAD_POOL_SIZE = 4; |
| 86 | |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 87 | // Pending requests that are waiting for the SIM to be available |
| 88 | // If a different SIM is currently used by previous requests, the following |
| 89 | // requests will stay in this queue until that SIM finishes its current requests in |
| 90 | // RequestQueue. |
| 91 | // Requests are not reordered. So, e.g. if current SIM is SIM1, a request for SIM2 will be |
| 92 | // blocked in the queue. And a later request for SIM1 will be appended to the queue, ordered |
| 93 | // after the request for SIM2, instead of being put into the running queue. |
| 94 | // TODO: persist this in case MmsService crashes |
| 95 | private final Queue<MmsRequest> mPendingSimRequestQueue = new ArrayDeque<>(); |
Ye Wen | b786d3e | 2014-07-03 14:08:16 -0700 | [diff] [blame] | 96 | |
Ye Wen | a167df7 | 2015-04-01 15:55:06 -0700 | [diff] [blame] | 97 | // Thread pool for transferring PDU with MMS apps |
| 98 | private final ExecutorService mPduTransferExecutor = Executors.newCachedThreadPool(); |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 99 | |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 100 | // A cache of MmsNetworkManager for SIMs |
| 101 | private final SparseArray<MmsNetworkManager> mNetworkManagerCache = new SparseArray<>(); |
| 102 | |
| 103 | // The current SIM ID for the running requests. Only one SIM can send/download MMS at a time. |
| 104 | private int mCurrentSubId; |
| 105 | // The current running MmsRequest count. |
| 106 | private int mRunningRequestCount; |
| 107 | |
Ye Wen | a167df7 | 2015-04-01 15:55:06 -0700 | [diff] [blame] | 108 | // Running request queues, one thread pool per queue |
| 109 | // 0: send queue |
| 110 | // 1: download queue |
| 111 | private final ExecutorService[] mRunningRequestExecutors = new ExecutorService[2]; |
Ye Wen | c91cc9d | 2014-05-19 14:41:16 -0700 | [diff] [blame] | 112 | |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 113 | private MmsNetworkManager getNetworkManager(int subId) { |
| 114 | synchronized (mNetworkManagerCache) { |
| 115 | MmsNetworkManager manager = mNetworkManagerCache.get(subId); |
| 116 | if (manager == null) { |
| 117 | manager = new MmsNetworkManager(this, subId); |
| 118 | mNetworkManagerCache.put(subId, manager); |
| 119 | } |
| 120 | return manager; |
| 121 | } |
| 122 | } |
| 123 | |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 124 | private void enforceSystemUid() { |
| 125 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 126 | throw new SecurityException("Only system can call this service"); |
| 127 | } |
| 128 | } |
| 129 | |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 130 | private int checkSubId(int subId) { |
Wink Saville | d16e241 | 2014-12-11 10:10:36 -0800 | [diff] [blame] | 131 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 132 | throw new RuntimeException("Invalid subId " + subId); |
| 133 | } |
Wink Saville | 79ab3ac | 2014-11-20 13:06:47 -0800 | [diff] [blame] | 134 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
Shishir Agrawal | 033ab5c | 2016-01-25 14:07:09 -0800 | [diff] [blame] | 135 | return SubscriptionManager.getDefaultSmsSubscriptionId(); |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 136 | } |
| 137 | return subId; |
| 138 | } |
| 139 | |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 140 | @Nullable |
Sahin Caliskan | d0b410f | 2019-04-01 11:37:19 -0700 | [diff] [blame^] | 141 | private String getCarrierMessagingServicePackageIfExists(int subId) { |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 142 | Intent intent = new Intent(CarrierMessagingService.SERVICE_INTERFACE); |
| 143 | TelephonyManager telephonyManager = |
| 144 | (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); |
Sahin Caliskan | d0b410f | 2019-04-01 11:37:19 -0700 | [diff] [blame^] | 145 | List<String> carrierPackages = telephonyManager.getCarrierPackageNamesForIntentAndPhone( |
| 146 | intent, SubscriptionManager.getPhoneId(subId)); |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 147 | |
| 148 | if (carrierPackages == null || carrierPackages.size() != 1) { |
| 149 | return null; |
| 150 | } else { |
| 151 | return carrierPackages.get(0); |
| 152 | } |
| 153 | } |
| 154 | |
Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 155 | private IMms.Stub mStub = new IMms.Stub() { |
| 156 | @Override |
Wink Saville | a6b72c4 | 2014-10-23 10:17:17 -0700 | [diff] [blame] | 157 | public void sendMessage(int subId, String callingPkg, Uri contentUri, |
Ye Wen | 3e40f4c | 2014-09-04 15:40:52 -0700 | [diff] [blame] | 158 | String locationUrl, Bundle configOverrides, PendingIntent sentIntent) |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 159 | throws RemoteException { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 160 | LogUtil.d("sendMessage"); |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 161 | enforceSystemUid(); |
Shishir Agrawal | d78cb30 | 2014-12-10 10:17:05 -0800 | [diff] [blame] | 162 | |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 163 | // Make sure the subId is correct |
| 164 | subId = checkSubId(subId); |
Shishir Agrawal | d78cb30 | 2014-12-10 10:17:05 -0800 | [diff] [blame] | 165 | |
| 166 | // Make sure the subId is active |
| 167 | if (!isActiveSubId(subId)) { |
| 168 | sendErrorInPendingIntent(sentIntent); |
| 169 | return; |
| 170 | } |
| 171 | |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 172 | final SendRequest request = new SendRequest(MmsService.this, subId, contentUri, |
Jonathan Basseri | 4467007 | 2015-06-09 11:46:26 -0700 | [diff] [blame] | 173 | locationUrl, sentIntent, callingPkg, configOverrides, MmsService.this); |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 174 | |
| 175 | final String carrierMessagingServicePackage = |
Sahin Caliskan | d0b410f | 2019-04-01 11:37:19 -0700 | [diff] [blame^] | 176 | getCarrierMessagingServicePackageIfExists(subId); |
| 177 | |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 178 | if (carrierMessagingServicePackage != null) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 179 | LogUtil.d(request.toString(), "sending message by carrier app"); |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 180 | request.trySendingByCarrierApp(MmsService.this, carrierMessagingServicePackage); |
| 181 | } else { |
| 182 | addSimRequest(request); |
| 183 | } |
Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | @Override |
Wink Saville | a6b72c4 | 2014-10-23 10:17:17 -0700 | [diff] [blame] | 187 | public void downloadMessage(int subId, String callingPkg, String locationUrl, |
Ye Wen | 3e40f4c | 2014-09-04 15:40:52 -0700 | [diff] [blame] | 188 | Uri contentUri, Bundle configOverrides, |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 189 | PendingIntent downloadedIntent) throws RemoteException { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 190 | LogUtil.d("downloadMessage: " + MmsHttpClient.redactUrlForNonVerbose(locationUrl)); |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 191 | enforceSystemUid(); |
Shishir Agrawal | d78cb30 | 2014-12-10 10:17:05 -0800 | [diff] [blame] | 192 | |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 193 | // Make sure the subId is correct |
| 194 | subId = checkSubId(subId); |
Shishir Agrawal | d78cb30 | 2014-12-10 10:17:05 -0800 | [diff] [blame] | 195 | |
Cheuksan Wang | 97e68dd | 2015-05-12 18:36:03 -0700 | [diff] [blame] | 196 | // If the subId is no longer active it could be caused by |
| 197 | // an MVNO using multiple subIds, so we should try to |
| 198 | // download anyway. |
| 199 | // TODO: Fail fast when downloading will fail (i.e. SIM swapped) |
Shishir Agrawal | d78cb30 | 2014-12-10 10:17:05 -0800 | [diff] [blame] | 200 | |
Jonathan Basseri | 4467007 | 2015-06-09 11:46:26 -0700 | [diff] [blame] | 201 | final DownloadRequest request = new DownloadRequest(MmsService.this, subId, locationUrl, |
| 202 | contentUri, downloadedIntent, callingPkg, configOverrides, MmsService.this); |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 203 | final String carrierMessagingServicePackage = |
Sahin Caliskan | d0b410f | 2019-04-01 11:37:19 -0700 | [diff] [blame^] | 204 | getCarrierMessagingServicePackageIfExists(subId); |
| 205 | |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 206 | if (carrierMessagingServicePackage != null) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 207 | LogUtil.d(request.toString(), "downloading message by carrier app"); |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 208 | request.tryDownloadingByCarrierApp(MmsService.this, carrierMessagingServicePackage); |
Ye Wen | b786d3e | 2014-07-03 14:08:16 -0700 | [diff] [blame] | 209 | } else { |
Abhijith Shastry | 1b2066c | 2014-10-31 19:02:28 -0700 | [diff] [blame] | 210 | addSimRequest(request); |
Ye Wen | b786d3e | 2014-07-03 14:08:16 -0700 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
Wink Saville | a6b72c4 | 2014-10-23 10:17:17 -0700 | [diff] [blame] | 214 | public Bundle getCarrierConfigValues(int subId) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 215 | LogUtil.d("getCarrierConfigValues"); |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 216 | // Make sure the subId is correct |
| 217 | subId = checkSubId(subId); |
Jonathan Basseri | 4467007 | 2015-06-09 11:46:26 -0700 | [diff] [blame] | 218 | final Bundle mmsConfig = MmsConfigManager.getInstance().getMmsConfigBySubId(subId); |
Tom Taylor | 76b0e86 | 2014-09-02 14:21:15 -0700 | [diff] [blame] | 219 | if (mmsConfig == null) { |
Shri Borde | 8a79dc0 | 2014-09-02 09:49:09 -0700 | [diff] [blame] | 220 | return new Bundle(); |
Tom Taylor | 76b0e86 | 2014-09-02 14:21:15 -0700 | [diff] [blame] | 221 | } |
Jonathan Basseri | 4467007 | 2015-06-09 11:46:26 -0700 | [diff] [blame] | 222 | return mmsConfig; |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | @Override |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 226 | public Uri importTextMessage(String callingPkg, String address, int type, String text, |
| 227 | long timestampMillis, boolean seen, boolean read) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 228 | LogUtil.d("importTextMessage"); |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 229 | enforceSystemUid(); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 230 | return importSms(address, type, text, timestampMillis, seen, read, callingPkg); |
| 231 | } |
| 232 | |
| 233 | @Override |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 234 | public Uri importMultimediaMessage(String callingPkg, Uri contentUri, |
| 235 | String messageId, long timestampSecs, boolean seen, boolean read) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 236 | LogUtil.d("importMultimediaMessage"); |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 237 | enforceSystemUid(); |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 238 | return importMms(contentUri, messageId, timestampSecs, seen, read, callingPkg); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public boolean deleteStoredMessage(String callingPkg, Uri messageUri) |
| 243 | throws RemoteException { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 244 | LogUtil.d("deleteStoredMessage " + messageUri); |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 245 | enforceSystemUid(); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 246 | if (!isSmsMmsContentUri(messageUri)) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 247 | LogUtil.e("deleteStoredMessage: invalid message URI: " + messageUri.toString()); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 248 | return false; |
| 249 | } |
Ye Wen | c0c6d5e | 2014-07-31 17:19:06 -0700 | [diff] [blame] | 250 | // Clear the calling identity and query the database using the phone user id |
| 251 | // Otherwise the AppOps check in TelephonyProvider would complain about mismatch |
| 252 | // between the calling uid and the package uid |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 253 | final long identity = Binder.clearCallingIdentity(); |
| 254 | try { |
| 255 | if (getContentResolver().delete( |
| 256 | messageUri, null/*where*/, null/*selectionArgs*/) != 1) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 257 | LogUtil.e("deleteStoredMessage: failed to delete"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 258 | return false; |
| 259 | } |
| 260 | } catch (SQLiteException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 261 | LogUtil.e("deleteStoredMessage: failed to delete", e); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 262 | } finally { |
| 263 | Binder.restoreCallingIdentity(identity); |
| 264 | } |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public boolean deleteStoredConversation(String callingPkg, long conversationId) |
| 270 | throws RemoteException { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 271 | LogUtil.d("deleteStoredConversation " + conversationId); |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 272 | enforceSystemUid(); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 273 | if (conversationId == -1) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 274 | LogUtil.e("deleteStoredConversation: invalid thread id"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 275 | return false; |
| 276 | } |
| 277 | final Uri uri = ContentUris.withAppendedId( |
| 278 | Telephony.Threads.CONTENT_URI, conversationId); |
Ye Wen | c0c6d5e | 2014-07-31 17:19:06 -0700 | [diff] [blame] | 279 | // Clear the calling identity and query the database using the phone user id |
| 280 | // Otherwise the AppOps check in TelephonyProvider would complain about mismatch |
| 281 | // between the calling uid and the package uid |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 282 | final long identity = Binder.clearCallingIdentity(); |
| 283 | try { |
| 284 | if (getContentResolver().delete(uri, null, null) != 1) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 285 | LogUtil.e("deleteStoredConversation: failed to delete"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 286 | return false; |
| 287 | } |
| 288 | } catch (SQLiteException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 289 | LogUtil.e("deleteStoredConversation: failed to delete", e); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 290 | } finally { |
| 291 | Binder.restoreCallingIdentity(identity); |
| 292 | } |
| 293 | return true; |
| 294 | } |
| 295 | |
| 296 | @Override |
| 297 | public boolean updateStoredMessageStatus(String callingPkg, Uri messageUri, |
| 298 | ContentValues statusValues) throws RemoteException { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 299 | LogUtil.d("updateStoredMessageStatus " + messageUri); |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 300 | enforceSystemUid(); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 301 | return updateMessageStatus(messageUri, statusValues); |
| 302 | } |
| 303 | |
| 304 | @Override |
Ye Wen | 2704c4b | 2014-07-29 10:43:05 -0700 | [diff] [blame] | 305 | public boolean archiveStoredConversation(String callingPkg, long conversationId, |
| 306 | boolean archived) throws RemoteException { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 307 | LogUtil.d("archiveStoredConversation " + conversationId + " " + archived); |
Ye Wen | 2704c4b | 2014-07-29 10:43:05 -0700 | [diff] [blame] | 308 | if (conversationId == -1) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 309 | LogUtil.e("archiveStoredConversation: invalid thread id"); |
Ye Wen | 2704c4b | 2014-07-29 10:43:05 -0700 | [diff] [blame] | 310 | return false; |
| 311 | } |
| 312 | return archiveConversation(conversationId, archived); |
| 313 | } |
| 314 | |
| 315 | @Override |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 316 | public Uri addTextMessageDraft(String callingPkg, String address, String text) |
| 317 | throws RemoteException { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 318 | LogUtil.d("addTextMessageDraft"); |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 319 | enforceSystemUid(); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 320 | return addSmsDraft(address, text, callingPkg); |
| 321 | } |
| 322 | |
| 323 | @Override |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 324 | public Uri addMultimediaMessageDraft(String callingPkg, Uri contentUri) |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 325 | throws RemoteException { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 326 | LogUtil.d("addMultimediaMessageDraft"); |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 327 | enforceSystemUid(); |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 328 | return addMmsDraft(contentUri, callingPkg); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | @Override |
Wink Saville | a6b72c4 | 2014-10-23 10:17:17 -0700 | [diff] [blame] | 332 | public void sendStoredMessage(int subId, String callingPkg, Uri messageUri, |
Ye Wen | 3e40f4c | 2014-09-04 15:40:52 -0700 | [diff] [blame] | 333 | Bundle configOverrides, PendingIntent sentIntent) throws RemoteException { |
Cheuksan Wang | f6d88a7 | 2014-09-08 19:47:59 -0700 | [diff] [blame] | 334 | throw new UnsupportedOperationException(); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 335 | } |
Shishir Agrawal | 6f31811 | 2014-07-14 13:53:13 -0700 | [diff] [blame] | 336 | |
Ye Wen | 8c027a6 | 2014-07-14 16:23:31 -0700 | [diff] [blame] | 337 | @Override |
| 338 | public void setAutoPersisting(String callingPkg, boolean enabled) throws RemoteException { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 339 | LogUtil.d("setAutoPersisting " + enabled); |
Ye Wen | 0527dc4 | 2014-07-24 17:29:57 -0700 | [diff] [blame] | 340 | enforceSystemUid(); |
Ye Wen | 8c027a6 | 2014-07-14 16:23:31 -0700 | [diff] [blame] | 341 | final SharedPreferences preferences = getSharedPreferences( |
| 342 | SHARED_PREFERENCES_NAME, MODE_PRIVATE); |
| 343 | final SharedPreferences.Editor editor = preferences.edit(); |
| 344 | editor.putBoolean(PREF_AUTO_PERSISTING, enabled); |
| 345 | editor.apply(); |
| 346 | } |
| 347 | |
| 348 | @Override |
| 349 | public boolean getAutoPersisting() throws RemoteException { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 350 | LogUtil.d("getAutoPersisting"); |
Ye Wen | 8c027a6 | 2014-07-14 16:23:31 -0700 | [diff] [blame] | 351 | return getAutoPersistingPref(); |
| 352 | } |
Shishir Agrawal | d78cb30 | 2014-12-10 10:17:05 -0800 | [diff] [blame] | 353 | |
| 354 | /* |
| 355 | * @return true if the subId is active. |
| 356 | */ |
| 357 | private boolean isActiveSubId(int subId) { |
| 358 | return SubscriptionManager.from(MmsService.this).isActiveSubId(subId); |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * Calls the pending intent with <code>MMS_ERROR_NO_DATA_NETWORK</code>. |
| 363 | */ |
| 364 | private void sendErrorInPendingIntent(@Nullable PendingIntent intent) { |
| 365 | if (intent != null) { |
| 366 | try { |
| 367 | intent.send(SmsManager.MMS_ERROR_NO_DATA_NETWORK); |
| 368 | } catch (PendingIntent.CanceledException ex) { |
| 369 | } |
| 370 | } |
| 371 | } |
Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 372 | }; |
| 373 | |
Ye Wen | b786d3e | 2014-07-03 14:08:16 -0700 | [diff] [blame] | 374 | @Override |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 375 | public void addSimRequest(MmsRequest request) { |
Ye Wen | b786d3e | 2014-07-03 14:08:16 -0700 | [diff] [blame] | 376 | if (request == null) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 377 | LogUtil.e("Add running or pending: empty request"); |
Ye Wen | b786d3e | 2014-07-03 14:08:16 -0700 | [diff] [blame] | 378 | return; |
| 379 | } |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 380 | LogUtil.d("Current running=" + mRunningRequestCount + ", " |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 381 | + "current subId=" + mCurrentSubId + ", " |
| 382 | + "pending=" + mPendingSimRequestQueue.size()); |
| 383 | synchronized (this) { |
| 384 | if (mPendingSimRequestQueue.size() > 0 || |
| 385 | (mRunningRequestCount > 0 && request.getSubId() != mCurrentSubId)) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 386 | LogUtil.d("Add request to pending queue." |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 387 | + " Request subId=" + request.getSubId() + "," |
| 388 | + " current subId=" + mCurrentSubId); |
| 389 | mPendingSimRequestQueue.add(request); |
| 390 | if (mRunningRequestCount <= 0) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 391 | LogUtil.e("Nothing's running but queue's not empty"); |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 392 | // Nothing is running but we are accumulating on pending queue. |
| 393 | // This should not happen. But just in case... |
| 394 | movePendingSimRequestsToRunningSynchronized(); |
| 395 | } |
| 396 | } else { |
| 397 | addToRunningRequestQueueSynchronized(request); |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
Ye Wen | a167df7 | 2015-04-01 15:55:06 -0700 | [diff] [blame] | 402 | private void addToRunningRequestQueueSynchronized(final MmsRequest request) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 403 | LogUtil.d("Add request to running queue for subId " + request.getSubId()); |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 404 | // Update current state of running requests |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 405 | final int queue = request.getQueueType(); |
Ye Wen | a167df7 | 2015-04-01 15:55:06 -0700 | [diff] [blame] | 406 | if (queue < 0 || queue >= mRunningRequestExecutors.length) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 407 | LogUtil.e("Invalid request queue index for running request"); |
Ye Wen | a167df7 | 2015-04-01 15:55:06 -0700 | [diff] [blame] | 408 | return; |
| 409 | } |
| 410 | mRunningRequestCount++; |
| 411 | mCurrentSubId = request.getSubId(); |
| 412 | // Send to the corresponding request queue for execution |
| 413 | mRunningRequestExecutors[queue].execute(new Runnable() { |
| 414 | @Override |
| 415 | public void run() { |
| 416 | try { |
| 417 | request.execute(MmsService.this, getNetworkManager(request.getSubId())); |
| 418 | } finally { |
| 419 | synchronized (MmsService.this) { |
| 420 | mRunningRequestCount--; |
| 421 | if (mRunningRequestCount <= 0) { |
| 422 | movePendingSimRequestsToRunningSynchronized(); |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | }); |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | private void movePendingSimRequestsToRunningSynchronized() { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 431 | LogUtil.d("Schedule requests pending on SIM"); |
Wink Saville | 79ab3ac | 2014-11-20 13:06:47 -0800 | [diff] [blame] | 432 | mCurrentSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 433 | while (mPendingSimRequestQueue.size() > 0) { |
| 434 | final MmsRequest request = mPendingSimRequestQueue.peek(); |
| 435 | if (request != null) { |
Wink Saville | d16e241 | 2014-12-11 10:10:36 -0800 | [diff] [blame] | 436 | if (!SubscriptionManager.isValidSubscriptionId(mCurrentSubId) |
| 437 | || mCurrentSubId == request.getSubId()) { |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 438 | // First or subsequent requests with same SIM ID |
| 439 | mPendingSimRequestQueue.remove(); |
| 440 | addToRunningRequestQueueSynchronized(request); |
| 441 | } else { |
| 442 | // Stop if we see a different SIM ID |
| 443 | break; |
| 444 | } |
| 445 | } else { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 446 | LogUtil.e("Schedule pending: found empty request"); |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 447 | mPendingSimRequestQueue.remove(); |
| 448 | } |
| 449 | } |
Ye Wen | c91cc9d | 2014-05-19 14:41:16 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 452 | @Override |
| 453 | public IBinder onBind(Intent intent) { |
| 454 | return mStub; |
| 455 | } |
| 456 | |
| 457 | public final IBinder asBinder() { |
| 458 | return mStub; |
| 459 | } |
| 460 | |
| 461 | @Override |
| 462 | public void onCreate() { |
| 463 | super.onCreate(); |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 464 | LogUtil.d("onCreate"); |
Ye Wen | c91cc9d | 2014-05-19 14:41:16 -0700 | [diff] [blame] | 465 | // Load mms_config |
Tom Taylor | 76b0e86 | 2014-09-02 14:21:15 -0700 | [diff] [blame] | 466 | MmsConfigManager.getInstance().init(this); |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 467 | // Initialize running request state |
Ye Wen | a167df7 | 2015-04-01 15:55:06 -0700 | [diff] [blame] | 468 | for (int i = 0; i < mRunningRequestExecutors.length; i++) { |
| 469 | mRunningRequestExecutors[i] = Executors.newFixedThreadPool(THREAD_POOL_SIZE); |
| 470 | } |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 471 | synchronized (this) { |
Wink Saville | 79ab3ac | 2014-11-20 13:06:47 -0800 | [diff] [blame] | 472 | mCurrentSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Ye Wen | 3cf9a94 | 2014-10-15 13:35:27 -0700 | [diff] [blame] | 473 | mRunningRequestCount = 0; |
| 474 | } |
Ye Wen | c91cc9d | 2014-05-19 14:41:16 -0700 | [diff] [blame] | 475 | } |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 476 | |
Ye Wen | a167df7 | 2015-04-01 15:55:06 -0700 | [diff] [blame] | 477 | @Override |
| 478 | public void onDestroy() { |
| 479 | super.onDestroy(); |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 480 | LogUtil.d("onDestroy"); |
Ye Wen | a167df7 | 2015-04-01 15:55:06 -0700 | [diff] [blame] | 481 | for (ExecutorService executor : mRunningRequestExecutors) { |
| 482 | executor.shutdown(); |
| 483 | } |
| 484 | } |
| 485 | |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 486 | private Uri importSms(String address, int type, String text, long timestampMillis, |
| 487 | boolean seen, boolean read, String creator) { |
| 488 | Uri insertUri = null; |
| 489 | switch (type) { |
| 490 | case SmsManager.SMS_TYPE_INCOMING: |
| 491 | insertUri = Telephony.Sms.Inbox.CONTENT_URI; |
| 492 | |
| 493 | break; |
| 494 | case SmsManager.SMS_TYPE_OUTGOING: |
| 495 | insertUri = Telephony.Sms.Sent.CONTENT_URI; |
| 496 | break; |
| 497 | } |
| 498 | if (insertUri == null) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 499 | LogUtil.e("importTextMessage: invalid message type for importing: " + type); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 500 | return null; |
| 501 | } |
| 502 | final ContentValues values = new ContentValues(6); |
| 503 | values.put(Telephony.Sms.ADDRESS, address); |
| 504 | values.put(Telephony.Sms.DATE, timestampMillis); |
| 505 | values.put(Telephony.Sms.SEEN, seen ? 1 : 0); |
| 506 | values.put(Telephony.Sms.READ, read ? 1 : 0); |
| 507 | values.put(Telephony.Sms.BODY, text); |
| 508 | if (!TextUtils.isEmpty(creator)) { |
| 509 | values.put(Telephony.Mms.CREATOR, creator); |
| 510 | } |
Ye Wen | c0c6d5e | 2014-07-31 17:19:06 -0700 | [diff] [blame] | 511 | // Clear the calling identity and query the database using the phone user id |
| 512 | // Otherwise the AppOps check in TelephonyProvider would complain about mismatch |
| 513 | // between the calling uid and the package uid |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 514 | final long identity = Binder.clearCallingIdentity(); |
| 515 | try { |
| 516 | return getContentResolver().insert(insertUri, values); |
| 517 | } catch (SQLiteException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 518 | LogUtil.e("importTextMessage: failed to persist imported text message", e); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 519 | } finally { |
| 520 | Binder.restoreCallingIdentity(identity); |
| 521 | } |
| 522 | return null; |
| 523 | } |
| 524 | |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 525 | private Uri importMms(Uri contentUri, String messageId, long timestampSecs, |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 526 | boolean seen, boolean read, String creator) { |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 527 | byte[] pduData = readPduFromContentUri(contentUri, MAX_MMS_FILE_SIZE); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 528 | if (pduData == null || pduData.length < 1) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 529 | LogUtil.e("importMessage: empty PDU"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 530 | return null; |
| 531 | } |
Ye Wen | c0c6d5e | 2014-07-31 17:19:06 -0700 | [diff] [blame] | 532 | // Clear the calling identity and query the database using the phone user id |
| 533 | // Otherwise the AppOps check in TelephonyProvider would complain about mismatch |
| 534 | // between the calling uid and the package uid |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 535 | final long identity = Binder.clearCallingIdentity(); |
| 536 | try { |
Ye Wen | a813bdf | 2014-11-17 17:15:07 -0800 | [diff] [blame] | 537 | final GenericPdu pdu = parsePduForAnyCarrier(pduData); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 538 | if (pdu == null) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 539 | LogUtil.e("importMessage: can't parse input PDU"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 540 | return null; |
| 541 | } |
| 542 | Uri insertUri = null; |
| 543 | if (pdu instanceof SendReq) { |
| 544 | insertUri = Telephony.Mms.Sent.CONTENT_URI; |
| 545 | } else if (pdu instanceof RetrieveConf || |
| 546 | pdu instanceof NotificationInd || |
| 547 | pdu instanceof DeliveryInd || |
| 548 | pdu instanceof ReadOrigInd) { |
| 549 | insertUri = Telephony.Mms.Inbox.CONTENT_URI; |
| 550 | } |
| 551 | if (insertUri == null) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 552 | LogUtil.e("importMessage; invalid MMS type: " + pdu.getClass().getCanonicalName()); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 553 | return null; |
| 554 | } |
| 555 | final PduPersister persister = PduPersister.getPduPersister(this); |
| 556 | final Uri uri = persister.persist( |
| 557 | pdu, |
| 558 | insertUri, |
| 559 | true/*createThreadId*/, |
| 560 | true/*groupMmsEnabled*/, |
| 561 | null/*preOpenedFiles*/); |
| 562 | if (uri == null) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 563 | LogUtil.e("importMessage: failed to persist message"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 564 | return null; |
| 565 | } |
| 566 | final ContentValues values = new ContentValues(5); |
| 567 | if (!TextUtils.isEmpty(messageId)) { |
| 568 | values.put(Telephony.Mms.MESSAGE_ID, messageId); |
| 569 | } |
| 570 | if (timestampSecs != -1) { |
| 571 | values.put(Telephony.Mms.DATE, timestampSecs); |
| 572 | } |
| 573 | values.put(Telephony.Mms.READ, seen ? 1 : 0); |
| 574 | values.put(Telephony.Mms.SEEN, read ? 1 : 0); |
| 575 | if (!TextUtils.isEmpty(creator)) { |
| 576 | values.put(Telephony.Mms.CREATOR, creator); |
| 577 | } |
| 578 | if (SqliteWrapper.update(this, getContentResolver(), uri, values, |
| 579 | null/*where*/, null/*selectionArg*/) != 1) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 580 | LogUtil.e("importMessage: failed to update message"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 581 | } |
| 582 | return uri; |
| 583 | } catch (RuntimeException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 584 | LogUtil.e("importMessage: failed to parse input PDU", e); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 585 | } catch (MmsException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 586 | LogUtil.e("importMessage: failed to persist message", e); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 587 | } finally { |
| 588 | Binder.restoreCallingIdentity(identity); |
| 589 | } |
| 590 | return null; |
| 591 | } |
| 592 | |
| 593 | private static boolean isSmsMmsContentUri(Uri uri) { |
| 594 | final String uriString = uri.toString(); |
| 595 | if (!uriString.startsWith("content://sms/") && !uriString.startsWith("content://mms/")) { |
| 596 | return false; |
| 597 | } |
| 598 | if (ContentUris.parseId(uri) == -1) { |
| 599 | return false; |
| 600 | } |
| 601 | return true; |
| 602 | } |
| 603 | |
| 604 | private boolean updateMessageStatus(Uri messageUri, ContentValues statusValues) { |
| 605 | if (!isSmsMmsContentUri(messageUri)) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 606 | LogUtil.e("updateMessageStatus: invalid messageUri: " + messageUri.toString()); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 607 | return false; |
| 608 | } |
| 609 | if (statusValues == null) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 610 | LogUtil.w("updateMessageStatus: empty values to update"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 611 | return false; |
| 612 | } |
| 613 | final ContentValues values = new ContentValues(); |
| 614 | if (statusValues.containsKey(SmsManager.MESSAGE_STATUS_READ)) { |
| 615 | final Integer val = statusValues.getAsInteger(SmsManager.MESSAGE_STATUS_READ); |
| 616 | if (val != null) { |
| 617 | // MMS uses the same column name |
| 618 | values.put(Telephony.Sms.READ, val); |
| 619 | } |
| 620 | } else if (statusValues.containsKey(SmsManager.MESSAGE_STATUS_SEEN)) { |
| 621 | final Integer val = statusValues.getAsInteger(SmsManager.MESSAGE_STATUS_SEEN); |
| 622 | if (val != null) { |
| 623 | // MMS uses the same column name |
| 624 | values.put(Telephony.Sms.SEEN, val); |
| 625 | } |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 626 | } |
| 627 | if (values.size() < 1) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 628 | LogUtil.w("updateMessageStatus: no value to update"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 629 | return false; |
| 630 | } |
Ye Wen | c0c6d5e | 2014-07-31 17:19:06 -0700 | [diff] [blame] | 631 | // Clear the calling identity and query the database using the phone user id |
| 632 | // Otherwise the AppOps check in TelephonyProvider would complain about mismatch |
| 633 | // between the calling uid and the package uid |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 634 | final long identity = Binder.clearCallingIdentity(); |
| 635 | try { |
| 636 | if (getContentResolver().update( |
| 637 | messageUri, values, null/*where*/, null/*selectionArgs*/) != 1) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 638 | LogUtil.e("updateMessageStatus: failed to update database"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 639 | return false; |
| 640 | } |
| 641 | return true; |
| 642 | } catch (SQLiteException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 643 | LogUtil.e("updateMessageStatus: failed to update database", e); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 644 | } finally { |
| 645 | Binder.restoreCallingIdentity(identity); |
| 646 | } |
| 647 | return false; |
| 648 | } |
| 649 | |
Ye Wen | 2704c4b | 2014-07-29 10:43:05 -0700 | [diff] [blame] | 650 | private static final String ARCHIVE_CONVERSATION_SELECTION = Telephony.Threads._ID + "=?"; |
| 651 | private boolean archiveConversation(long conversationId, boolean archived) { |
| 652 | final ContentValues values = new ContentValues(1); |
| 653 | values.put(Telephony.Threads.ARCHIVED, archived ? 1 : 0); |
Ye Wen | c0c6d5e | 2014-07-31 17:19:06 -0700 | [diff] [blame] | 654 | // Clear the calling identity and query the database using the phone user id |
| 655 | // Otherwise the AppOps check in TelephonyProvider would complain about mismatch |
| 656 | // between the calling uid and the package uid |
Ye Wen | 2704c4b | 2014-07-29 10:43:05 -0700 | [diff] [blame] | 657 | final long identity = Binder.clearCallingIdentity(); |
| 658 | try { |
| 659 | if (getContentResolver().update( |
| 660 | Telephony.Threads.CONTENT_URI, |
| 661 | values, |
| 662 | ARCHIVE_CONVERSATION_SELECTION, |
| 663 | new String[] { Long.toString(conversationId)}) != 1) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 664 | LogUtil.e("archiveConversation: failed to update database"); |
Ye Wen | 2704c4b | 2014-07-29 10:43:05 -0700 | [diff] [blame] | 665 | return false; |
| 666 | } |
| 667 | return true; |
| 668 | } catch (SQLiteException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 669 | LogUtil.e("archiveConversation: failed to update database", e); |
Ye Wen | 2704c4b | 2014-07-29 10:43:05 -0700 | [diff] [blame] | 670 | } finally { |
| 671 | Binder.restoreCallingIdentity(identity); |
| 672 | } |
| 673 | return false; |
| 674 | } |
| 675 | |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 676 | private Uri addSmsDraft(String address, String text, String creator) { |
| 677 | final ContentValues values = new ContentValues(5); |
| 678 | values.put(Telephony.Sms.ADDRESS, address); |
| 679 | values.put(Telephony.Sms.BODY, text); |
| 680 | values.put(Telephony.Sms.READ, 1); |
| 681 | values.put(Telephony.Sms.SEEN, 1); |
| 682 | if (!TextUtils.isEmpty(creator)) { |
| 683 | values.put(Telephony.Mms.CREATOR, creator); |
| 684 | } |
Ye Wen | c0c6d5e | 2014-07-31 17:19:06 -0700 | [diff] [blame] | 685 | // Clear the calling identity and query the database using the phone user id |
| 686 | // Otherwise the AppOps check in TelephonyProvider would complain about mismatch |
| 687 | // between the calling uid and the package uid |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 688 | final long identity = Binder.clearCallingIdentity(); |
| 689 | try { |
| 690 | return getContentResolver().insert(Telephony.Sms.Draft.CONTENT_URI, values); |
| 691 | } catch (SQLiteException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 692 | LogUtil.e("addSmsDraft: failed to store draft message", e); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 693 | } finally { |
| 694 | Binder.restoreCallingIdentity(identity); |
| 695 | } |
| 696 | return null; |
| 697 | } |
| 698 | |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 699 | private Uri addMmsDraft(Uri contentUri, String creator) { |
| 700 | byte[] pduData = readPduFromContentUri(contentUri, MAX_MMS_FILE_SIZE); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 701 | if (pduData == null || pduData.length < 1) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 702 | LogUtil.e("addMmsDraft: empty PDU"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 703 | return null; |
| 704 | } |
Ye Wen | c0c6d5e | 2014-07-31 17:19:06 -0700 | [diff] [blame] | 705 | // Clear the calling identity and query the database using the phone user id |
| 706 | // Otherwise the AppOps check in TelephonyProvider would complain about mismatch |
| 707 | // between the calling uid and the package uid |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 708 | final long identity = Binder.clearCallingIdentity(); |
| 709 | try { |
Ye Wen | a813bdf | 2014-11-17 17:15:07 -0800 | [diff] [blame] | 710 | final GenericPdu pdu = parsePduForAnyCarrier(pduData); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 711 | if (pdu == null) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 712 | LogUtil.e("addMmsDraft: can't parse input PDU"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 713 | return null; |
| 714 | } |
| 715 | if (!(pdu instanceof SendReq)) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 716 | LogUtil.e("addMmsDraft; invalid MMS type: " + pdu.getClass().getCanonicalName()); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 717 | return null; |
| 718 | } |
| 719 | final PduPersister persister = PduPersister.getPduPersister(this); |
| 720 | final Uri uri = persister.persist( |
| 721 | pdu, |
| 722 | Telephony.Mms.Draft.CONTENT_URI, |
| 723 | true/*createThreadId*/, |
| 724 | true/*groupMmsEnabled*/, |
| 725 | null/*preOpenedFiles*/); |
| 726 | if (uri == null) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 727 | LogUtil.e("addMmsDraft: failed to persist message"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 728 | return null; |
| 729 | } |
| 730 | final ContentValues values = new ContentValues(3); |
| 731 | values.put(Telephony.Mms.READ, 1); |
| 732 | values.put(Telephony.Mms.SEEN, 1); |
| 733 | if (!TextUtils.isEmpty(creator)) { |
| 734 | values.put(Telephony.Mms.CREATOR, creator); |
| 735 | } |
| 736 | if (SqliteWrapper.update(this, getContentResolver(), uri, values, |
| 737 | null/*where*/, null/*selectionArg*/) != 1) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 738 | LogUtil.e("addMmsDraft: failed to update message"); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 739 | } |
| 740 | return uri; |
| 741 | } catch (RuntimeException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 742 | LogUtil.e("addMmsDraft: failed to parse input PDU", e); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 743 | } catch (MmsException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 744 | LogUtil.e("addMmsDraft: failed to persist message", e); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 745 | } finally { |
| 746 | Binder.restoreCallingIdentity(identity); |
| 747 | } |
| 748 | return null; |
| 749 | } |
| 750 | |
Ye Wen | a813bdf | 2014-11-17 17:15:07 -0800 | [diff] [blame] | 751 | /** |
| 752 | * Try parsing a PDU without knowing the carrier. This is useful for importing |
| 753 | * MMS or storing draft when carrier info is not available |
| 754 | * |
| 755 | * @param data The PDU data |
| 756 | * @return Parsed PDU, null if failed to parse |
| 757 | */ |
| 758 | private static GenericPdu parsePduForAnyCarrier(final byte[] data) { |
| 759 | GenericPdu pdu = null; |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 760 | try { |
Ye Wen | a813bdf | 2014-11-17 17:15:07 -0800 | [diff] [blame] | 761 | pdu = (new PduParser(data, true/*parseContentDisposition*/)).parse(); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 762 | } catch (RuntimeException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 763 | LogUtil.w("parsePduForAnyCarrier: Failed to parse PDU with content disposition", e); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 764 | } |
Ye Wen | a813bdf | 2014-11-17 17:15:07 -0800 | [diff] [blame] | 765 | if (pdu == null) { |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 766 | try { |
Ye Wen | a813bdf | 2014-11-17 17:15:07 -0800 | [diff] [blame] | 767 | pdu = (new PduParser(data, false/*parseContentDisposition*/)).parse(); |
| 768 | } catch (RuntimeException e) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 769 | LogUtil.w("parsePduForAnyCarrier: Failed to parse PDU without content disposition", |
Ye Wen | a813bdf | 2014-11-17 17:15:07 -0800 | [diff] [blame] | 770 | e); |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 771 | } |
| 772 | } |
Ye Wen | a813bdf | 2014-11-17 17:15:07 -0800 | [diff] [blame] | 773 | return pdu; |
Ye Wen | 18aabe2 | 2014-07-09 16:58:26 -0700 | [diff] [blame] | 774 | } |
Ye Wen | 8c027a6 | 2014-07-14 16:23:31 -0700 | [diff] [blame] | 775 | |
| 776 | @Override |
| 777 | public boolean getAutoPersistingPref() { |
| 778 | final SharedPreferences preferences = getSharedPreferences( |
| 779 | SHARED_PREFERENCES_NAME, MODE_PRIVATE); |
| 780 | return preferences.getBoolean(PREF_AUTO_PERSISTING, false); |
| 781 | } |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 782 | |
| 783 | /** |
| 784 | * Read pdu from content provider uri |
| 785 | * @param contentUri content provider uri from which to read |
| 786 | * @param maxSize maximum number of bytes to read |
| 787 | * @return pdu bytes if succeeded else null |
| 788 | */ |
| 789 | public byte[] readPduFromContentUri(final Uri contentUri, final int maxSize) { |
Ye Wen | 8988009 | 2015-03-25 16:03:06 -0700 | [diff] [blame] | 790 | if (contentUri == null) { |
| 791 | return null; |
| 792 | } |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 793 | Callable<byte[]> copyPduToArray = new Callable<byte[]>() { |
| 794 | public byte[] call() { |
| 795 | ParcelFileDescriptor.AutoCloseInputStream inStream = null; |
| 796 | try { |
| 797 | ContentResolver cr = MmsService.this.getContentResolver(); |
| 798 | ParcelFileDescriptor pduFd = cr.openFileDescriptor(contentUri, "r"); |
| 799 | inStream = new ParcelFileDescriptor.AutoCloseInputStream(pduFd); |
| 800 | // Request one extra byte to make sure file not bigger than maxSize |
| 801 | byte[] tempBody = new byte[maxSize+1]; |
| 802 | int bytesRead = inStream.read(tempBody, 0, maxSize+1); |
| 803 | if (bytesRead == 0) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 804 | LogUtil.e("Read empty PDU"); |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 805 | return null; |
| 806 | } |
| 807 | if (bytesRead <= maxSize) { |
| 808 | return Arrays.copyOf(tempBody, bytesRead); |
| 809 | } |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 810 | LogUtil.e("PDU read is too large"); |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 811 | return null; |
| 812 | } catch (IOException ex) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 813 | LogUtil.e("IO exception reading PDU", ex); |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 814 | return null; |
| 815 | } finally { |
| 816 | if (inStream != null) { |
| 817 | try { |
| 818 | inStream.close(); |
| 819 | } catch (IOException ex) { |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | }; |
| 825 | |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 826 | final Future<byte[]> pendingResult = mPduTransferExecutor.submit(copyPduToArray); |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 827 | try { |
Ye Wen | 8988009 | 2015-03-25 16:03:06 -0700 | [diff] [blame] | 828 | return pendingResult.get(TASK_TIMEOUT_MS, TimeUnit.MILLISECONDS); |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 829 | } catch (Exception e) { |
| 830 | // Typically a timeout occurred - cancel task |
| 831 | pendingResult.cancel(true); |
| 832 | } |
| 833 | return null; |
| 834 | } |
| 835 | |
| 836 | /** |
| 837 | * Write pdu bytes to content provider uri |
| 838 | * @param contentUri content provider uri to which bytes should be written |
| 839 | * @param pdu Bytes to write |
| 840 | * @return true if all bytes successfully written else false |
| 841 | */ |
| 842 | public boolean writePduToContentUri(final Uri contentUri, final byte[] pdu) { |
Ye Wen | 8988009 | 2015-03-25 16:03:06 -0700 | [diff] [blame] | 843 | if (contentUri == null || pdu == null) { |
| 844 | return false; |
| 845 | } |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 846 | final Callable<Boolean> copyDownloadedPduToOutput = new Callable<Boolean>() { |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 847 | public Boolean call() { |
| 848 | ParcelFileDescriptor.AutoCloseOutputStream outStream = null; |
| 849 | try { |
| 850 | ContentResolver cr = MmsService.this.getContentResolver(); |
| 851 | ParcelFileDescriptor pduFd = cr.openFileDescriptor(contentUri, "w"); |
| 852 | outStream = new ParcelFileDescriptor.AutoCloseOutputStream(pduFd); |
| 853 | outStream.write(pdu); |
| 854 | return Boolean.TRUE; |
| 855 | } catch (IOException ex) { |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 856 | LogUtil.e("IO exception writing PDU", ex); |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 857 | return Boolean.FALSE; |
| 858 | } finally { |
| 859 | if (outStream != null) { |
| 860 | try { |
| 861 | outStream.close(); |
| 862 | } catch (IOException ex) { |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | }; |
| 868 | |
Ye Wen | 8153aed | 2015-06-16 13:36:31 -0700 | [diff] [blame] | 869 | final Future<Boolean> pendingResult = |
| 870 | mPduTransferExecutor.submit(copyDownloadedPduToOutput); |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 871 | try { |
Ye Wen | 8988009 | 2015-03-25 16:03:06 -0700 | [diff] [blame] | 872 | return pendingResult.get(TASK_TIMEOUT_MS, TimeUnit.MILLISECONDS); |
Julian Odell | b83f2fa | 2014-08-27 17:36:56 -0700 | [diff] [blame] | 873 | } catch (Exception e) { |
| 874 | // Typically a timeout occurred - cancel task |
| 875 | pendingResult.cancel(true); |
| 876 | } |
| 877 | return false; |
| 878 | } |
Ye Wen | 2d860e9 | 2014-05-15 13:05:08 -0700 | [diff] [blame] | 879 | } |