diff options
author | Ye Wen <ywen@google.com> | 2015-06-16 13:36:31 -0700 |
---|---|---|
committer | Ye Wen <ywen@google.com> | 2015-06-16 14:05:37 -0700 |
commit | 8153aed48a84305533f26c06a07a51bd358cee41 (patch) | |
tree | 24750767c555a579cb2c38cc4c0ca9cbd8994e17 | |
parent | 4467007f09a9f2319ba25aa18e04f54693e6bfa1 (diff) | |
download | android_packages_services_Mms-8153aed48a84305533f26c06a07a51bd358cee41.tar.gz android_packages_services_Mms-8153aed48a84305533f26c06a07a51bd358cee41.tar.bz2 android_packages_services_Mms-8153aed48a84305533f26c06a07a51bd358cee41.zip |
Better logging for MmsService
- Annotate most logging with request id
- Added logging for IO exception when transferring downloaded PDU
b/21701652
b/21815174
Change-Id: I98554219ae0b2bcfb4450b9e783bd634908b34e7
-rw-r--r-- | src/com/android/mms/service/ApnSettings.java | 15 | ||||
-rw-r--r-- | src/com/android/mms/service/DownloadRequest.java | 43 | ||||
-rw-r--r-- | src/com/android/mms/service/LogUtil.java | 86 | ||||
-rw-r--r-- | src/com/android/mms/service/MmsConfigManager.java | 23 | ||||
-rw-r--r-- | src/com/android/mms/service/MmsHttpClient.java | 45 | ||||
-rw-r--r-- | src/com/android/mms/service/MmsNetworkManager.java | 28 | ||||
-rw-r--r-- | src/com/android/mms/service/MmsRequest.java | 50 | ||||
-rw-r--r-- | src/com/android/mms/service/MmsService.java | 134 | ||||
-rw-r--r-- | src/com/android/mms/service/PhoneUtils.java | 4 | ||||
-rw-r--r-- | src/com/android/mms/service/SendRequest.java | 41 |
10 files changed, 271 insertions, 198 deletions
diff --git a/src/com/android/mms/service/ApnSettings.java b/src/com/android/mms/service/ApnSettings.java index c15ba67..9a2b7ca 100644 --- a/src/com/android/mms/service/ApnSettings.java +++ b/src/com/android/mms/service/ApnSettings.java @@ -23,7 +23,6 @@ import android.net.NetworkUtils; import android.net.Uri; import android.provider.Telephony; import android.text.TextUtils; -import android.util.Log; import com.android.internal.telephony.PhoneConstants; import com.android.mms.service.exception.ApnException; @@ -35,8 +34,6 @@ import java.net.URISyntaxException; * APN settings used for MMS transactions */ public class ApnSettings { - private static final String TAG = MmsService.TAG; - // MMSC URL private final String mServiceCenter; // MMSC proxy address @@ -86,15 +83,13 @@ public class ApnSettings { /** * Load APN settings from system - * - * @param context + * @param context * @param apnName the optional APN name to match + * @param requestId the request ID for logging */ - public static ApnSettings load(Context context, String apnName, int subId) + public static ApnSettings load(Context context, String apnName, int subId, String requestId) throws ApnException { - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.v(TAG, "ApnSettings: apnName " + apnName); - } + LogUtil.i(requestId, "Loading APN using name " + apnName); // TODO: CURRENT semantics is currently broken in telephony. Revive this when it is fixed. //String selection = Telephony.Carriers.CURRENT + " IS NOT NULL"; String selection = null; @@ -142,7 +137,7 @@ public class ApnSettings { try { proxyPort = Integer.parseInt(portString); } catch (NumberFormatException e) { - Log.e(TAG, "Invalid port " + portString); + LogUtil.e(requestId, "Invalid port " + portString); throw new ApnException("Invalid port " + portString); } } diff --git a/src/com/android/mms/service/DownloadRequest.java b/src/com/android/mms/service/DownloadRequest.java index 5e4d0a4..318e2df 100644 --- a/src/com/android/mms/service/DownloadRequest.java +++ b/src/com/android/mms/service/DownloadRequest.java @@ -33,16 +33,12 @@ import android.os.UserHandle; import android.os.UserManager; import android.provider.Telephony; import android.service.carrier.CarrierMessagingService; -import android.service.carrier.ICarrierMessagingCallback; import android.service.carrier.ICarrierMessagingService; import android.telephony.CarrierMessagingServiceManager; import android.telephony.SmsManager; -import android.telephony.TelephonyManager; import android.text.TextUtils; -import android.util.Log; import com.android.mms.service.exception.MmsHttpException; - import com.google.android.mms.MmsException; import com.google.android.mms.pdu.GenericPdu; import com.google.android.mms.pdu.PduHeaders; @@ -51,8 +47,6 @@ import com.google.android.mms.pdu.PduPersister; import com.google.android.mms.pdu.RetrieveConf; import com.google.android.mms.util.SqliteWrapper; -import java.util.List; - /** * Request to download an MMS */ @@ -76,9 +70,10 @@ public class DownloadRequest extends MmsRequest { @Override protected byte[] doHttp(Context context, MmsNetworkManager netMgr, ApnSettings apn) throws MmsHttpException { + final String requestId = this.toString(); final MmsHttpClient mmsHttpClient = netMgr.getOrCreateHttpClient(); if (mmsHttpClient == null) { - Log.e(MmsService.TAG, "MMS network is not ready!"); + LogUtil.e(requestId, "MMS network is not ready!"); throw new MmsHttpException(0/*statusCode*/, "MMS network is not ready"); } return mmsHttpClient.execute( @@ -89,7 +84,8 @@ public class DownloadRequest extends MmsRequest { apn.getProxyAddress(), apn.getProxyPort(), mMmsConfig, - mSubId); + mSubId, + requestId); } @Override @@ -104,15 +100,16 @@ public class DownloadRequest extends MmsRequest { @Override protected Uri persistIfRequired(Context context, int result, byte[] response) { + final String requestId = this.toString(); // Let any mms apps running as secondary user know that a new mms has been downloaded. notifyOfDownload(context); if (!mRequestManager.getAutoPersistingPref()) { return null; } - Log.d(MmsService.TAG, "DownloadRequest.persistIfRequired"); + LogUtil.d(requestId, "persistIfRequired"); if (response == null || response.length < 1) { - Log.e(MmsService.TAG, "DownloadRequest.persistIfRequired: empty response"); + LogUtil.e(requestId, "persistIfRequired: empty response"); return null; } final long identity = Binder.clearCallingIdentity(); @@ -121,14 +118,13 @@ public class DownloadRequest extends MmsRequest { mMmsConfig.getBoolean(SmsManager.MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION); final GenericPdu pdu = (new PduParser(response, supportMmsContentDisposition)).parse(); if (pdu == null || !(pdu instanceof RetrieveConf)) { - Log.e(MmsService.TAG, "DownloadRequest.persistIfRequired: invalid parsed PDU"); + LogUtil.e(requestId, "persistIfRequired: invalid parsed PDU"); return null; } final RetrieveConf retrieveConf = (RetrieveConf) pdu; final int status = retrieveConf.getRetrieveStatus(); if (status != PduHeaders.RETRIEVE_STATUS_OK) { - Log.e(MmsService.TAG, "DownloadRequest.persistIfRequired: retrieve failed " - + status); + LogUtil.e(requestId, "persistIfRequired: retrieve failed " + status); // Update the retrieve status of the NotificationInd final ContentValues values = new ContentValues(1); values.put(Telephony.Mms.RETRIEVE_STATUS, status); @@ -153,7 +149,7 @@ public class DownloadRequest extends MmsRequest { true/*groupMmsEnabled*/, null/*preOpenedFiles*/); if (messageUri == null) { - Log.e(MmsService.TAG, "DownloadRequest.persistIfRequired: can not persist message"); + LogUtil.e(requestId, "persistIfRequired: can not persist message"); return null; } // Update some of the properties of the message @@ -172,7 +168,7 @@ public class DownloadRequest extends MmsRequest { values, null/*where*/, null/*selectionArg*/) != 1) { - Log.e(MmsService.TAG, "DownloadRequest.persistIfRequired: can not update message"); + LogUtil.e(requestId, "persistIfRequired: can not update message"); } // Delete the corresponding NotificationInd SqliteWrapper.delete(context, @@ -186,11 +182,11 @@ public class DownloadRequest extends MmsRequest { return messageUri; } catch (MmsException e) { - Log.e(MmsService.TAG, "DownloadRequest.persistIfRequired: can not persist message", e); + LogUtil.e(requestId, "persistIfRequired: can not persist message", e); } catch (SQLiteException e) { - Log.e(MmsService.TAG, "DownloadRequest.persistIfRequired: can not update message", e); + LogUtil.e(requestId, "persistIfRequired: can not update message", e); } catch (RuntimeException e) { - Log.e(MmsService.TAG, "DownloadRequest.persistIfRequired: can not parse response", e); + LogUtil.e(requestId, "persistIfRequired: can not parse response", e); } finally { Binder.restoreCallingIdentity(identity); } @@ -282,9 +278,9 @@ public class DownloadRequest extends MmsRequest { CarrierDownloadCompleteCallback carrierDownloadCallback) { mCarrierDownloadCallback = carrierDownloadCallback; if (bindToCarrierMessagingService(context, carrierMessagingServicePackage)) { - Log.v(MmsService.TAG, "bindService() for carrier messaging service succeeded"); + LogUtil.v("bindService() for carrier messaging service succeeded"); } else { - Log.e(MmsService.TAG, "bindService() for carrier messaging service failed"); + LogUtil.e("bindService() for carrier messaging service failed"); carrierDownloadCallback.onDownloadMmsComplete( CarrierMessagingService.DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK); } @@ -296,8 +292,7 @@ public class DownloadRequest extends MmsRequest { carrierMessagingService.downloadMms(mContentUri, mSubId, Uri.parse(mLocationUrl), mCarrierDownloadCallback); } catch (RemoteException e) { - Log.e(MmsService.TAG, - "Exception downloading MMS using the carrier messaging service: " + e); + LogUtil.e("Exception downloading MMS using the carrier messaging service: " + e, e); mCarrierDownloadCallback.onDownloadMmsComplete( CarrierMessagingService.DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK); } @@ -321,12 +316,12 @@ public class DownloadRequest extends MmsRequest { @Override public void onSendMmsComplete(int result, byte[] sendConfPdu) { - Log.e(MmsService.TAG, "Unexpected onSendMmsComplete call with result: " + result); + LogUtil.e("Unexpected onSendMmsComplete call with result: " + result); } @Override public void onDownloadMmsComplete(int result) { - Log.d(MmsService.TAG, "Carrier app result for download: " + result); + LogUtil.d("Carrier app result for download: " + result); mCarrierDownloadManager.disposeConnection(mContext); if (!maybeFallbackToRegularDelivery(result)) { diff --git a/src/com/android/mms/service/LogUtil.java b/src/com/android/mms/service/LogUtil.java new file mode 100644 index 0000000..349af32 --- /dev/null +++ b/src/com/android/mms/service/LogUtil.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * 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.service; + +import android.util.Log; + +/** + * Logging utility + */ +public class LogUtil { + private static final String TAG = "MmsService"; + + public static void i(final String requestId, final String message) { + Log.i(TAG, "[" + requestId + "] " + message); + } + + public static void i(final String message) { + Log.i(TAG, message); + } + + public static void d(final String requestId, final String message) { + Log.d(TAG, "[" + requestId + "] " + message); + } + + public static void d(final String message) { + Log.d(TAG, message); + } + + public static void v(final String requestId, final String message) { + Log.v(TAG, "[" + requestId + "] " + message); + } + + public static void v(final String message) { + Log.v(TAG, message); + } + + public static void e(final String requestId, final String message, final Throwable t) { + Log.e(TAG, "[" + requestId + "] " + message, t); + } + + public static void e(final String message, final Throwable t) { + Log.e(TAG, message, t); + } + + public static void e(final String requestId, final String message) { + Log.e(TAG, "[" + requestId + "] " + message); + } + + public static void e(final String message) { + Log.e(TAG, message); + } + + public static void w(final String requestId, final String message, final Throwable t) { + Log.w(TAG, "[" + requestId + "] " + message, t); + } + + public static void w(final String message, final Throwable t) { + Log.w(TAG, message, t); + } + + public static void w(final String requestId, final String message) { + Log.w(TAG, "[" + requestId + "] " + message); + } + + public static void w(final String message) { + Log.w(TAG, message); + } + + public static boolean isLoggable(final int logLevel) { + return Log.isLoggable(TAG, logLevel); + } +} diff --git a/src/com/android/mms/service/MmsConfigManager.java b/src/com/android/mms/service/MmsConfigManager.java index 7aa60f6..8ba5400 100644 --- a/src/com/android/mms/service/MmsConfigManager.java +++ b/src/com/android/mms/service/MmsConfigManager.java @@ -26,16 +26,15 @@ import android.os.PersistableBundle; import android.telephony.CarrierConfigManager; import android.telephony.SmsManager; import android.telephony.SubscriptionInfo; -import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; import android.telephony.SubscriptionManager; +import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; import android.util.ArrayMap; -import android.util.Log; + +import com.android.internal.telephony.IccCardConstants; import java.util.List; import java.util.Map; -import com.android.internal.telephony.IccCardConstants; - /** * This class manages cached copies of all the MMS configuration for each subscription ID. * A subscription ID loosely corresponds to a particular SIM. See the @@ -43,8 +42,6 @@ import com.android.internal.telephony.IccCardConstants; * */ public class MmsConfigManager { - private static final String TAG = MmsService.TAG; - private static volatile MmsConfigManager sInstance = new MmsConfigManager(); public static MmsConfigManager getInstance() { @@ -66,7 +63,7 @@ public class MmsConfigManager { private final BroadcastReceiver mReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - Log.i(TAG, "mReceiver action: " + action); + LogUtil.i("MmsConfigManager receiver action: " + action); if (action.equals(IccCardConstants.INTENT_VALUE_ICC_LOADED)) { loadInBackground(); } @@ -87,7 +84,7 @@ public class MmsConfigManager { mSubscriptionManager = SubscriptionManager.from(context); // TODO: When this object "finishes" we should unregister. - IntentFilter intentFilterLoaded = + final IntentFilter intentFilterLoaded = new IntentFilter(IccCardConstants.INTENT_VALUE_ICC_LOADED); context.registerReceiver(mReceiver, intentFilterLoaded); @@ -110,7 +107,7 @@ public class MmsConfigManager { Configuration configuration = mContext.getResources().getConfiguration(); // Always put the mnc/mcc in the log so we can tell which mms_config.xml // was loaded. - Log.i(TAG, "MmsConfigManager.loadInBackground(): mcc/mnc: " + + LogUtil.i("MmsConfigManager loads in background mcc/mnc: " + configuration.mcc + "/" + configuration.mnc); load(mContext); } @@ -131,7 +128,7 @@ public class MmsConfigManager { synchronized(mSubIdConfigMap) { mmsConfig = mSubIdConfigMap.get(subId); } - Log.i(TAG, "getMmsConfigBySubId -- for sub: " + subId + " mmsConfig: " + mmsConfig); + LogUtil.i("mms config for sub " + subId + ": " + mmsConfig); // Return a copy so that callers can mutate it. if (mmsConfig != null) { return new Bundle(mmsConfig); @@ -148,16 +145,16 @@ public class MmsConfigManager { private void load(Context context) { List<SubscriptionInfo> subs = mSubscriptionManager.getActiveSubscriptionInfoList(); if (subs == null || subs.size() < 1) { - Log.e(TAG, "MmsConfigManager.load -- empty getActiveSubInfoList"); + LogUtil.e(" Failed to load mms config: empty getActiveSubInfoList"); return; } // Load all the config bundles into a new map and then swap it with the real map to avoid // blocking. final Map<Integer, Bundle> newConfigMap = new ArrayMap<Integer, Bundle>(); - CarrierConfigManager configManager = + final CarrierConfigManager configManager = (CarrierConfigManager) context.getSystemService(Context.CARRIER_CONFIG_SERVICE); for (SubscriptionInfo sub : subs) { - int subId = sub.getSubscriptionId(); + final int subId = sub.getSubscriptionId(); PersistableBundle config = configManager.getConfigForSubId(subId); newConfigMap.put(subId, SmsManager.getMmsConfig(config)); } diff --git a/src/com/android/mms/service/MmsHttpClient.java b/src/com/android/mms/service/MmsHttpClient.java index da36f26..e09695c 100644 --- a/src/com/android/mms/service/MmsHttpClient.java +++ b/src/com/android/mms/service/MmsHttpClient.java @@ -94,13 +94,14 @@ public class MmsHttpClient { * @param proxyPort The proxy port * @param mmsConfig The MMS config to use * @param subId The subscription ID used to get line number, etc. + * @param requestId The request ID for logging * @return The HTTP response body * @throws MmsHttpException For any failures */ public byte[] execute(String urlString, byte[] pdu, String method, boolean isProxySet, - String proxyHost, int proxyPort, Bundle mmsConfig, int subId) + String proxyHost, int proxyPort, Bundle mmsConfig, int subId, String requestId) throws MmsHttpException { - Log.d(MmsService.TAG, "HTTP: " + method + " " + redactUrlForNonVerbose(urlString) + LogUtil.d(requestId, "HTTP: " + method + " " + redactUrlForNonVerbose(urlString) + (isProxySet ? (", proxy=" + proxyHost + ":" + proxyPort) : "") + ", PDU size=" + (pdu != null ? pdu.length : 0)); checkMethod(method); @@ -124,14 +125,14 @@ public class MmsHttpClient { HEADER_ACCEPT_LANGUAGE, getCurrentAcceptLanguage(Locale.getDefault())); // Header: User-Agent final String userAgent = mmsConfig.getString(SmsManager.MMS_CONFIG_USER_AGENT); - Log.i(MmsService.TAG, "HTTP: User-Agent=" + userAgent); + LogUtil.i(requestId, "HTTP: User-Agent=" + userAgent); connection.setRequestProperty(HEADER_USER_AGENT, userAgent); // Header: x-wap-profile final String uaProfUrlTagName = mmsConfig.getString(SmsManager.MMS_CONFIG_UA_PROF_TAG_NAME); final String uaProfUrl = mmsConfig.getString(SmsManager.MMS_CONFIG_UA_PROF_URL); if (uaProfUrl != null) { - Log.i(MmsService.TAG, "HTTP: UaProfUrl=" + uaProfUrl); + LogUtil.i(requestId, "HTTP: UaProfUrl=" + uaProfUrl); connection.setRequestProperty(uaProfUrlTagName, uaProfUrl); } // Add extra headers specified by mms_config.xml's httpparams @@ -139,7 +140,7 @@ public class MmsHttpClient { // Different stuff for GET and POST if (METHOD_POST.equals(method)) { if (pdu == null || pdu.length < 1) { - Log.e(MmsService.TAG, "HTTP: empty pdu"); + LogUtil.e(requestId, "HTTP: empty pdu"); throw new MmsHttpException(0/*statusCode*/, "Sending empty PDU"); } connection.setDoOutput(true); @@ -151,8 +152,8 @@ public class MmsHttpClient { connection.setRequestProperty(HEADER_CONTENT_TYPE, HEADER_VALUE_CONTENT_TYPE_WITHOUT_CHARSET); } - if (Log.isLoggable(MmsService.TAG, Log.VERBOSE)) { - logHttpHeaders(connection.getRequestProperties()); + if (LogUtil.isLoggable(Log.VERBOSE)) { + logHttpHeaders(connection.getRequestProperties(), requestId); } connection.setFixedLengthStreamingMode(pdu.length); // Sending request body @@ -162,17 +163,17 @@ public class MmsHttpClient { out.flush(); out.close(); } else if (METHOD_GET.equals(method)) { - if (Log.isLoggable(MmsService.TAG, Log.VERBOSE)) { - logHttpHeaders(connection.getRequestProperties()); + if (LogUtil.isLoggable(Log.VERBOSE)) { + logHttpHeaders(connection.getRequestProperties(), requestId); } connection.setRequestMethod(METHOD_GET); } // Get response final int responseCode = connection.getResponseCode(); final String responseMessage = connection.getResponseMessage(); - Log.d(MmsService.TAG, "HTTP: " + responseCode + " " + responseMessage); - if (Log.isLoggable(MmsService.TAG, Log.VERBOSE)) { - logHttpHeaders(connection.getHeaderFields()); + LogUtil.d(requestId, "HTTP: " + responseCode + " " + responseMessage); + if (LogUtil.isLoggable(Log.VERBOSE)) { + logHttpHeaders(connection.getHeaderFields(), requestId); } if (responseCode / 100 != 2) { throw new MmsHttpException(responseCode, responseMessage); @@ -186,19 +187,19 @@ public class MmsHttpClient { } in.close(); final byte[] responseBody = byteOut.toByteArray(); - Log.d(MmsService.TAG, "HTTP: response size=" + LogUtil.d(requestId, "HTTP: response size=" + (responseBody != null ? responseBody.length : 0)); return responseBody; } catch (MalformedURLException e) { final String redactedUrl = redactUrlForNonVerbose(urlString); - Log.e(MmsService.TAG, "HTTP: invalid URL " + redactedUrl, e); + LogUtil.e(requestId, "HTTP: invalid URL " + redactedUrl, e); throw new MmsHttpException(0/*statusCode*/, "Invalid URL " + redactedUrl, e); } catch (ProtocolException e) { final String redactedUrl = redactUrlForNonVerbose(urlString); - Log.e(MmsService.TAG, "HTTP: invalid URL protocol " + redactedUrl, e); + LogUtil.e(requestId, "HTTP: invalid URL protocol " + redactedUrl, e); throw new MmsHttpException(0/*statusCode*/, "Invalid URL protocol " + redactedUrl, e); } catch (IOException e) { - Log.e(MmsService.TAG, "HTTP: IO failure", e); + LogUtil.e(requestId, "HTTP: IO failure", e); throw new MmsHttpException(0/*statusCode*/, e); } finally { if (connection != null) { @@ -207,7 +208,7 @@ public class MmsHttpClient { } } - private static void logHttpHeaders(Map<String, List<String>> headers) { + private static void logHttpHeaders(Map<String, List<String>> headers, String requestId) { final StringBuilder sb = new StringBuilder(); if (headers != null) { for (Map.Entry<String, List<String>> entry : headers.entrySet()) { @@ -219,7 +220,7 @@ public class MmsHttpClient { } } } - Log.v(MmsService.TAG, "HTTP: headers\n" + sb.toString()); + LogUtil.v(requestId, "HTTP: headers\n" + sb.toString()); } } @@ -359,7 +360,7 @@ public class MmsHttpClient { * @return */ public static String redactUrlForNonVerbose(String urlString) { - if (Log.isLoggable(MmsService.TAG, Log.VERBOSE)) { + if (LogUtil.isLoggable(Log.VERBOSE)) { // Don't redact for VERBOSE level logging return urlString; } @@ -409,7 +410,7 @@ public class MmsHttpClient { } else if (MACRO_NAI.equals(macro)) { return getNai(context, mmsConfig, subId); } - Log.e(MmsService.TAG, "invalid macro " + macro); + LogUtil.e("Invalid macro " + macro); return null; } @@ -442,8 +443,8 @@ public class MmsHttpClient { final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService( Context.TELEPHONY_SERVICE); String nai = telephonyManager.getNai(SubscriptionManager.getSlotId(subId)); - if (Log.isLoggable(MmsService.TAG, Log.VERBOSE)) { - Log.v(MmsService.TAG, "getNai: nai=" + nai); + if (LogUtil.isLoggable(Log.VERBOSE)) { + LogUtil.v("getNai: nai=" + nai); } if (!TextUtils.isEmpty(nai)) { diff --git a/src/com/android/mms/service/MmsNetworkManager.java b/src/com/android/mms/service/MmsNetworkManager.java index 758d665..ea2fa90 100644 --- a/src/com/android/mms/service/MmsNetworkManager.java +++ b/src/com/android/mms/service/MmsNetworkManager.java @@ -23,7 +23,6 @@ import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.NetworkRequest; import android.os.SystemClock; -import android.util.Log; import com.android.mms.service.exception.MmsNetworkException; @@ -67,7 +66,7 @@ public class MmsNetworkManager { @Override public void onAvailable(Network network) { super.onAvailable(network); - Log.d(MmsService.TAG, "NetworkCallbackListener.onAvailable: network=" + network); + LogUtil.i("NetworkCallbackListener.onAvailable: network=" + network); synchronized (MmsNetworkManager.this) { mNetwork = network; MmsNetworkManager.this.notifyAll(); @@ -77,7 +76,7 @@ public class MmsNetworkManager { @Override public void onLost(Network network) { super.onLost(network); - Log.d(MmsService.TAG, "NetworkCallbackListener.onLost: network=" + network); + LogUtil.w("NetworkCallbackListener.onLost: network=" + network); synchronized (MmsNetworkManager.this) { releaseRequestLocked(this); MmsNetworkManager.this.notifyAll(); @@ -87,7 +86,7 @@ public class MmsNetworkManager { @Override public void onUnavailable() { super.onUnavailable(); - Log.d(MmsService.TAG, "NetworkCallbackListener.onUnavailable"); + LogUtil.w("NetworkCallbackListener.onUnavailable"); synchronized (MmsNetworkManager.this) { releaseRequestLocked(this); MmsNetworkManager.this.notifyAll(); @@ -113,19 +112,20 @@ public class MmsNetworkManager { /** * Acquire the MMS network * + * @param requestId request ID for logging * @throws com.android.mms.service.exception.MmsNetworkException if we fail to acquire it */ - public void acquireNetwork() throws MmsNetworkException { + public void acquireNetwork(final String requestId) throws MmsNetworkException { synchronized (this) { mMmsRequestCount += 1; if (mNetwork != null) { // Already available - Log.d(MmsService.TAG, "MmsNetworkManager: already available"); + LogUtil.d(requestId, "MmsNetworkManager: already available"); return; } // Not available, so start a new request if not done yet if (mNetworkCallback == null) { - Log.d(MmsService.TAG, "MmsNetworkManager: start new network request"); + LogUtil.d(requestId, "MmsNetworkManager: start new network request"); startNewNetworkRequestLocked(); } final long shouldEnd = SystemClock.elapsedRealtime() + NETWORK_ACQUIRE_TIMEOUT_MILLIS; @@ -134,7 +134,7 @@ public class MmsNetworkManager { try { this.wait(waitTime); } catch (InterruptedException e) { - Log.w(MmsService.TAG, "MmsNetworkManager: acquire network wait interrupted"); + LogUtil.w(requestId, "MmsNetworkManager: acquire network wait interrupted"); } if (mNetwork != null) { // Success @@ -144,7 +144,7 @@ public class MmsNetworkManager { waitTime = shouldEnd - SystemClock.elapsedRealtime(); } // Timed out, so release the request and fail - Log.d(MmsService.TAG, "MmsNetworkManager: timed out"); + LogUtil.e(requestId, "MmsNetworkManager: timed out"); releaseRequestLocked(mNetworkCallback); throw new MmsNetworkException("Acquiring network timed out"); } @@ -152,12 +152,14 @@ public class MmsNetworkManager { /** * Release the MMS network when nobody is holding on to it. + * + * @param requestId request ID for logging */ - public void releaseNetwork() { + public void releaseNetwork(final String requestId) { synchronized (this) { if (mMmsRequestCount > 0) { mMmsRequestCount -= 1; - Log.d(MmsService.TAG, "MmsNetworkManager: release, count=" + mMmsRequestCount); + LogUtil.d(requestId, "MmsNetworkManager: release, count=" + mMmsRequestCount); if (mMmsRequestCount < 1) { releaseRequestLocked(mNetworkCallback); } @@ -232,18 +234,16 @@ public class MmsNetworkManager { Network network = null; synchronized (this) { if (mNetwork == null) { - Log.d(MmsService.TAG, "MmsNetworkManager: getApnName: network not available"); return null; } network = mNetwork; } String apnName = null; final ConnectivityManager connectivityManager = getConnectivityManager(); - NetworkInfo mmsNetworkInfo = connectivityManager.getNetworkInfo(network); + final NetworkInfo mmsNetworkInfo = connectivityManager.getNetworkInfo(network); if (mmsNetworkInfo != null) { apnName = mmsNetworkInfo.getExtraInfo(); } - Log.d(MmsService.TAG, "MmsNetworkManager: getApnName: " + apnName); return apnName; } } diff --git a/src/com/android/mms/service/MmsRequest.java b/src/com/android/mms/service/MmsRequest.java index 9255c16..1b6845b 100644 --- a/src/com/android/mms/service/MmsRequest.java +++ b/src/com/android/mms/service/MmsRequest.java @@ -27,7 +27,6 @@ import android.service.carrier.ICarrierMessagingCallback; import android.telephony.SmsManager; import android.telephony.TelephonyManager; import android.text.TextUtils; -import android.util.Log; import com.android.mms.service.exception.ApnException; import com.android.mms.service.exception.MmsHttpException; @@ -107,13 +106,13 @@ public abstract class MmsRequest { mMmsConfig = config; // TODO: Make MmsConfigManager authoritative for user agent and don't consult // TelephonyManager. - TelephonyManager telephonyManager = + final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); - String userAgent = telephonyManager.getMmsUserAgent(); + final String userAgent = telephonyManager.getMmsUserAgent(); if (!TextUtils.isEmpty(userAgent)) { config.putString(SmsManager.MMS_CONFIG_USER_AGENT, userAgent); } - String userAgentProfileUrl = telephonyManager.getMmsUAProfUrl(); + final String userAgentProfileUrl = telephonyManager.getMmsUAProfUrl(); if (!TextUtils.isEmpty(userAgentProfileUrl)) { config.putString(SmsManager.MMS_CONFIG_UA_PROF_URL, userAgentProfileUrl); } @@ -133,61 +132,64 @@ public abstract class MmsRequest { * @param networkManager The network manager to use */ public void execute(Context context, MmsNetworkManager networkManager) { + final String requestId = this.toString(); + LogUtil.i(requestId, "Executing..."); int result = SmsManager.MMS_ERROR_UNSPECIFIED; int httpStatusCode = 0; byte[] response = null; // TODO: add mms data channel check back to fast fail if no way to send mms, // when telephony provides such API. if (!ensureMmsConfigLoaded()) { // Check mms config - Log.e(MmsService.TAG, "MmsRequest: mms config is not loaded yet"); + LogUtil.e(requestId, "mms config is not loaded yet"); result = SmsManager.MMS_ERROR_CONFIGURATION_ERROR; } else if (!prepareForHttpRequest()) { // Prepare request, like reading pdu data from user - Log.e(MmsService.TAG, "MmsRequest: failed to prepare for request"); + LogUtil.e(requestId, "Failed to prepare for request"); result = SmsManager.MMS_ERROR_IO_ERROR; } else { // Execute long retryDelaySecs = 2; // Try multiple times of MMS HTTP request for (int i = 0; i < RETRY_TIMES; i++) { try { - networkManager.acquireNetwork(); + networkManager.acquireNetwork(requestId); final String apnName = networkManager.getApnName(); + LogUtil.d(requestId, "APN name is " + apnName); try { ApnSettings apn = null; try { - apn = ApnSettings.load(context, apnName, mSubId); + apn = ApnSettings.load(context, apnName, mSubId, requestId); } catch (ApnException e) { // If no APN could be found, fall back to trying without the APN name if (apnName == null) { // If the APN name was already null then don't need to retry throw (e); } - Log.i(MmsService.TAG, "MmsRequest: No match with APN name:" + LogUtil.i(requestId, "No match with APN name: " + apnName + ", try with no name"); - apn = ApnSettings.load(context, null, mSubId); + apn = ApnSettings.load(context, null, mSubId, requestId); } - Log.i(MmsService.TAG, "MmsRequest: using " + apn.toString()); + LogUtil.i(requestId, "Using " + apn.toString()); response = doHttp(context, networkManager, apn); result = Activity.RESULT_OK; // Success break; } finally { - networkManager.releaseNetwork(); + networkManager.releaseNetwork(requestId); } } catch (ApnException e) { - Log.e(MmsService.TAG, "MmsRequest: APN failure", e); + LogUtil.e(requestId, "APN failure", e); result = SmsManager.MMS_ERROR_INVALID_APN; break; } catch (MmsNetworkException e) { - Log.e(MmsService.TAG, "MmsRequest: MMS network acquiring failure", e); + LogUtil.e(requestId, "MMS network acquiring failure", e); result = SmsManager.MMS_ERROR_UNABLE_CONNECT_MMS; // Retry } catch (MmsHttpException e) { - Log.e(MmsService.TAG, "MmsRequest: HTTP or network I/O failure", e); + LogUtil.e(requestId, "HTTP or network I/O failure", e); result = SmsManager.MMS_ERROR_HTTP_FAILURE; httpStatusCode = e.getStatusCode(); // Retry } catch (Exception e) { - Log.e(MmsService.TAG, "MmsRequest: unexpected failure", e); + LogUtil.e(requestId, "Unexpected failure", e); result = SmsManager.MMS_ERROR_UNSPECIFIED; break; } @@ -232,7 +234,7 @@ public abstract class MmsRequest { } pendingIntent.send(context, result, fillIn); } catch (PendingIntent.CanceledException e) { - Log.e(MmsService.TAG, "MmsRequest: sending pending intent canceled", e); + LogUtil.e(this.toString(), "Sending pending intent canceled", e); } } @@ -248,7 +250,7 @@ public abstract class MmsRequest { == CarrierMessagingService.SEND_STATUS_RETRY_ON_CARRIER_NETWORK || carrierMessagingAppResult == CarrierMessagingService.DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK) { - Log.d(MmsService.TAG, "Sending/downloading MMS by IP failed."); + LogUtil.d(this.toString(), "Sending/downloading MMS by IP failed."); mRequestManager.addSimRequest(MmsRequest.this); return true; } else { @@ -270,6 +272,11 @@ public abstract class MmsRequest { } } + @Override + public String toString() { + return getClass().getSimpleName() + '@' + Integer.toHexString(hashCode()); + } + /** * Making the HTTP request to MMSC * @@ -331,18 +338,17 @@ public abstract class MmsRequest { protected abstract class CarrierMmsActionCallback extends ICarrierMessagingCallback.Stub { @Override public void onSendSmsComplete(int result, int messageRef) { - Log.e(MmsService.TAG, "Unexpected onSendSmsComplete call with result: " + result); + LogUtil.e("Unexpected onSendSmsComplete call with result: " + result); } @Override public void onSendMultipartSmsComplete(int result, int[] messageRefs) { - Log.e(MmsService.TAG, "Unexpected onSendMultipartSmsComplete call with result: " - + result); + LogUtil.e("Unexpected onSendMultipartSmsComplete call with result: " + result); } @Override public void onFilterComplete(boolean keepMessage) { - Log.e(MmsService.TAG, "Unexpected onFilterComplete call with result: " + keepMessage); + LogUtil.e("Unexpected onFilterComplete call with result: " + keepMessage); } } } diff --git a/src/com/android/mms/service/MmsService.java b/src/com/android/mms/service/MmsService.java index c6a3b8f..45af90b 100644 --- a/src/com/android/mms/service/MmsService.java +++ b/src/com/android/mms/service/MmsService.java @@ -39,7 +39,6 @@ import android.telephony.SmsManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; -import android.util.Log; import android.util.SparseArray; import com.android.internal.telephony.IMms; @@ -69,8 +68,6 @@ import java.util.concurrent.TimeUnit; * System service to process MMS API requests */ public class MmsService extends Service implements MmsRequest.RequestManager { - public static final String TAG = "MmsService"; - public static final int QUEUE_INDEX_SEND = 0; public static final int QUEUE_INDEX_DOWNLOAD = 1; @@ -159,7 +156,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { public void sendMessage(int subId, String callingPkg, Uri contentUri, String locationUrl, Bundle configOverrides, PendingIntent sentIntent) throws RemoteException { - Log.d(TAG, "sendMessage"); + LogUtil.d("sendMessage"); enforceSystemUid(); // Make sure the subId is correct @@ -177,7 +174,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { final String carrierMessagingServicePackage = getCarrierMessagingServicePackageIfExists(); if (carrierMessagingServicePackage != null) { - Log.d(TAG, "sending message by carrier app"); + LogUtil.d(request.toString(), "sending message by carrier app"); request.trySendingByCarrierApp(MmsService.this, carrierMessagingServicePackage); } else { addSimRequest(request); @@ -188,7 +185,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { public void downloadMessage(int subId, String callingPkg, String locationUrl, Uri contentUri, Bundle configOverrides, PendingIntent downloadedIntent) throws RemoteException { - Log.d(TAG, "downloadMessage: " + MmsHttpClient.redactUrlForNonVerbose(locationUrl)); + LogUtil.d("downloadMessage: " + MmsHttpClient.redactUrlForNonVerbose(locationUrl)); enforceSystemUid(); // Make sure the subId is correct @@ -204,7 +201,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { final String carrierMessagingServicePackage = getCarrierMessagingServicePackageIfExists(); if (carrierMessagingServicePackage != null) { - Log.d(TAG, "downloading message by carrier app"); + LogUtil.d(request.toString(), "downloading message by carrier app"); request.tryDownloadingByCarrierApp(MmsService.this, carrierMessagingServicePackage); } else { addSimRequest(request); @@ -212,7 +209,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { } public Bundle getCarrierConfigValues(int subId) { - Log.d(TAG, "getCarrierConfigValues"); + LogUtil.d("getCarrierConfigValues"); // Make sure the subId is correct subId = checkSubId(subId); final Bundle mmsConfig = MmsConfigManager.getInstance().getMmsConfigBySubId(subId); @@ -225,7 +222,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public Uri importTextMessage(String callingPkg, String address, int type, String text, long timestampMillis, boolean seen, boolean read) { - Log.d(TAG, "importTextMessage"); + LogUtil.d("importTextMessage"); enforceSystemUid(); return importSms(address, type, text, timestampMillis, seen, read, callingPkg); } @@ -233,7 +230,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public Uri importMultimediaMessage(String callingPkg, Uri contentUri, String messageId, long timestampSecs, boolean seen, boolean read) { - Log.d(TAG, "importMultimediaMessage"); + LogUtil.d("importMultimediaMessage"); enforceSystemUid(); return importMms(contentUri, messageId, timestampSecs, seen, read, callingPkg); } @@ -241,10 +238,10 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public boolean deleteStoredMessage(String callingPkg, Uri messageUri) throws RemoteException { - Log.d(TAG, "deleteStoredMessage " + messageUri); + LogUtil.d("deleteStoredMessage " + messageUri); enforceSystemUid(); if (!isSmsMmsContentUri(messageUri)) { - Log.e(TAG, "deleteStoredMessage: invalid message URI: " + messageUri.toString()); + LogUtil.e("deleteStoredMessage: invalid message URI: " + messageUri.toString()); return false; } // Clear the calling identity and query the database using the phone user id @@ -254,11 +251,11 @@ public class MmsService extends Service implements MmsRequest.RequestManager { try { if (getContentResolver().delete( messageUri, null/*where*/, null/*selectionArgs*/) != 1) { - Log.e(TAG, "deleteStoredMessage: failed to delete"); + LogUtil.e("deleteStoredMessage: failed to delete"); return false; } } catch (SQLiteException e) { - Log.e(TAG, "deleteStoredMessage: failed to delete", e); + LogUtil.e("deleteStoredMessage: failed to delete", e); } finally { Binder.restoreCallingIdentity(identity); } @@ -268,10 +265,10 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public boolean deleteStoredConversation(String callingPkg, long conversationId) throws RemoteException { - Log.d(TAG, "deleteStoredConversation " + conversationId); + LogUtil.d("deleteStoredConversation " + conversationId); enforceSystemUid(); if (conversationId == -1) { - Log.e(TAG, "deleteStoredConversation: invalid thread id"); + LogUtil.e("deleteStoredConversation: invalid thread id"); return false; } final Uri uri = ContentUris.withAppendedId( @@ -282,11 +279,11 @@ public class MmsService extends Service implements MmsRequest.RequestManager { final long identity = Binder.clearCallingIdentity(); try { if (getContentResolver().delete(uri, null, null) != 1) { - Log.e(TAG, "deleteStoredConversation: failed to delete"); + LogUtil.e("deleteStoredConversation: failed to delete"); return false; } } catch (SQLiteException e) { - Log.e(TAG, "deleteStoredConversation: failed to delete", e); + LogUtil.e("deleteStoredConversation: failed to delete", e); } finally { Binder.restoreCallingIdentity(identity); } @@ -296,7 +293,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public boolean updateStoredMessageStatus(String callingPkg, Uri messageUri, ContentValues statusValues) throws RemoteException { - Log.d(TAG, "updateStoredMessageStatus " + messageUri); + LogUtil.d("updateStoredMessageStatus " + messageUri); enforceSystemUid(); return updateMessageStatus(messageUri, statusValues); } @@ -304,9 +301,9 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public boolean archiveStoredConversation(String callingPkg, long conversationId, boolean archived) throws RemoteException { - Log.d(TAG, "archiveStoredConversation " + conversationId + " " + archived); + LogUtil.d("archiveStoredConversation " + conversationId + " " + archived); if (conversationId == -1) { - Log.e(TAG, "archiveStoredConversation: invalid thread id"); + LogUtil.e("archiveStoredConversation: invalid thread id"); return false; } return archiveConversation(conversationId, archived); @@ -315,7 +312,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public Uri addTextMessageDraft(String callingPkg, String address, String text) throws RemoteException { - Log.d(TAG, "addTextMessageDraft"); + LogUtil.d("addTextMessageDraft"); enforceSystemUid(); return addSmsDraft(address, text, callingPkg); } @@ -323,7 +320,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public Uri addMultimediaMessageDraft(String callingPkg, Uri contentUri) throws RemoteException { - Log.d(TAG, "addMultimediaMessageDraft"); + LogUtil.d("addMultimediaMessageDraft"); enforceSystemUid(); return addMmsDraft(contentUri, callingPkg); } @@ -336,7 +333,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public void setAutoPersisting(String callingPkg, boolean enabled) throws RemoteException { - Log.d(TAG, "setAutoPersisting " + enabled); + LogUtil.d("setAutoPersisting " + enabled); enforceSystemUid(); final SharedPreferences preferences = getSharedPreferences( SHARED_PREFERENCES_NAME, MODE_PRIVATE); @@ -347,7 +344,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public boolean getAutoPersisting() throws RemoteException { - Log.d(TAG, "getAutoPersisting"); + LogUtil.d("getAutoPersisting"); return getAutoPersistingPref(); } @@ -374,21 +371,21 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public void addSimRequest(MmsRequest request) { if (request == null) { - Log.e(TAG, "Add running or pending: empty request"); + LogUtil.e("Add running or pending: empty request"); return; } - Log.d(TAG, "Current running=" + mRunningRequestCount + ", " + LogUtil.d("Current running=" + mRunningRequestCount + ", " + "current subId=" + mCurrentSubId + ", " + "pending=" + mPendingSimRequestQueue.size()); synchronized (this) { if (mPendingSimRequestQueue.size() > 0 || (mRunningRequestCount > 0 && request.getSubId() != mCurrentSubId)) { - Log.d(TAG, "Add request to pending queue." + LogUtil.d("Add request to pending queue." + " Request subId=" + request.getSubId() + "," + " current subId=" + mCurrentSubId); mPendingSimRequestQueue.add(request); if (mRunningRequestCount <= 0) { - Log.e(TAG, "Nothing's running but queue's not empty"); + LogUtil.e("Nothing's running but queue's not empty"); // Nothing is running but we are accumulating on pending queue. // This should not happen. But just in case... movePendingSimRequestsToRunningSynchronized(); @@ -400,11 +397,11 @@ public class MmsService extends Service implements MmsRequest.RequestManager { } private void addToRunningRequestQueueSynchronized(final MmsRequest request) { - Log.d(TAG, "Add request to running queue for subId " + request.getSubId()); + LogUtil.d("Add request to running queue for subId " + request.getSubId()); // Update current state of running requests final int queue = request.getQueueType(); if (queue < 0 || queue >= mRunningRequestExecutors.length) { - Log.e(TAG, "Invalid request queue index for running request"); + LogUtil.e("Invalid request queue index for running request"); return; } mRunningRequestCount++; @@ -428,7 +425,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { } private void movePendingSimRequestsToRunningSynchronized() { - Log.d(TAG, "Schedule requests pending on SIM"); + LogUtil.d("Schedule requests pending on SIM"); mCurrentSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; while (mPendingSimRequestQueue.size() > 0) { final MmsRequest request = mPendingSimRequestQueue.peek(); @@ -443,7 +440,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { break; } } else { - Log.e(TAG, "Schedule pending: found empty request"); + LogUtil.e("Schedule pending: found empty request"); mPendingSimRequestQueue.remove(); } } @@ -461,7 +458,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public void onCreate() { super.onCreate(); - Log.d(TAG, "onCreate"); + LogUtil.d("onCreate"); // Load mms_config MmsConfigManager.getInstance().init(this); // Initialize running request state @@ -477,7 +474,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { @Override public void onDestroy() { super.onDestroy(); - Log.d(TAG, "onDestroy"); + LogUtil.d("onDestroy"); for (ExecutorService executor : mRunningRequestExecutors) { executor.shutdown(); } @@ -496,7 +493,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { break; } if (insertUri == null) { - Log.e(TAG, "importTextMessage: invalid message type for importing: " + type); + LogUtil.e("importTextMessage: invalid message type for importing: " + type); return null; } final ContentValues values = new ContentValues(6); @@ -515,7 +512,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { try { return getContentResolver().insert(insertUri, values); } catch (SQLiteException e) { - Log.e(TAG, "importTextMessage: failed to persist imported text message", e); + LogUtil.e("importTextMessage: failed to persist imported text message", e); } finally { Binder.restoreCallingIdentity(identity); } @@ -526,7 +523,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { boolean seen, boolean read, String creator) { byte[] pduData = readPduFromContentUri(contentUri, MAX_MMS_FILE_SIZE); if (pduData == null || pduData.length < 1) { - Log.e(TAG, "importMessage: empty PDU"); + LogUtil.e("importMessage: empty PDU"); return null; } // Clear the calling identity and query the database using the phone user id @@ -536,7 +533,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { try { final GenericPdu pdu = parsePduForAnyCarrier(pduData); if (pdu == null) { - Log.e(TAG, "importMessage: can't parse input PDU"); + LogUtil.e("importMessage: can't parse input PDU"); return null; } Uri insertUri = null; @@ -549,7 +546,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { insertUri = Telephony.Mms.Inbox.CONTENT_URI; } if (insertUri == null) { - Log.e(TAG, "importMessage; invalid MMS type: " + pdu.getClass().getCanonicalName()); + LogUtil.e("importMessage; invalid MMS type: " + pdu.getClass().getCanonicalName()); return null; } final PduPersister persister = PduPersister.getPduPersister(this); @@ -560,7 +557,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { true/*groupMmsEnabled*/, null/*preOpenedFiles*/); if (uri == null) { - Log.e(TAG, "importMessage: failed to persist message"); + LogUtil.e("importMessage: failed to persist message"); return null; } final ContentValues values = new ContentValues(5); @@ -577,13 +574,13 @@ public class MmsService extends Service implements MmsRequest.RequestManager { } if (SqliteWrapper.update(this, getContentResolver(), uri, values, null/*where*/, null/*selectionArg*/) != 1) { - Log.e(TAG, "importMessage: failed to update message"); + LogUtil.e("importMessage: failed to update message"); } return uri; } catch (RuntimeException e) { - Log.e(TAG, "importMessage: failed to parse input PDU", e); + LogUtil.e("importMessage: failed to parse input PDU", e); } catch (MmsException e) { - Log.e(TAG, "importMessage: failed to persist message", e); + LogUtil.e("importMessage: failed to persist message", e); } finally { Binder.restoreCallingIdentity(identity); } @@ -603,11 +600,11 @@ public class MmsService extends Service implements MmsRequest.RequestManager { private boolean updateMessageStatus(Uri messageUri, ContentValues statusValues) { if (!isSmsMmsContentUri(messageUri)) { - Log.e(TAG, "updateMessageStatus: invalid messageUri: " + messageUri.toString()); + LogUtil.e("updateMessageStatus: invalid messageUri: " + messageUri.toString()); return false; } if (statusValues == null) { - Log.w(TAG, "updateMessageStatus: empty values to update"); + LogUtil.w("updateMessageStatus: empty values to update"); return false; } final ContentValues values = new ContentValues(); @@ -625,7 +622,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { } } if (values.size() < 1) { - Log.w(TAG, "updateMessageStatus: no value to update"); + LogUtil.w("updateMessageStatus: no value to update"); return false; } // Clear the calling identity and query the database using the phone user id @@ -635,12 +632,12 @@ public class MmsService extends Service implements MmsRequest.RequestManager { try { if (getContentResolver().update( messageUri, values, null/*where*/, null/*selectionArgs*/) != 1) { - Log.e(TAG, "updateMessageStatus: failed to update database"); + LogUtil.e("updateMessageStatus: failed to update database"); return false; } return true; } catch (SQLiteException e) { - Log.e(TAG, "updateMessageStatus: failed to update database", e); + LogUtil.e("updateMessageStatus: failed to update database", e); } finally { Binder.restoreCallingIdentity(identity); } @@ -661,12 +658,12 @@ public class MmsService extends Service implements MmsRequest.RequestManager { values, ARCHIVE_CONVERSATION_SELECTION, new String[] { Long.toString(conversationId)}) != 1) { - Log.e(TAG, "archiveConversation: failed to update database"); + LogUtil.e("archiveConversation: failed to update database"); return false; } return true; } catch (SQLiteException e) { - Log.e(TAG, "archiveConversation: failed to update database", e); + LogUtil.e("archiveConversation: failed to update database", e); } finally { Binder.restoreCallingIdentity(identity); } @@ -689,7 +686,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { try { return getContentResolver().insert(Telephony.Sms.Draft.CONTENT_URI, values); } catch (SQLiteException e) { - Log.e(TAG, "addSmsDraft: failed to store draft message", e); + LogUtil.e("addSmsDraft: failed to store draft message", e); } finally { Binder.restoreCallingIdentity(identity); } @@ -699,7 +696,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { private Uri addMmsDraft(Uri contentUri, String creator) { byte[] pduData = readPduFromContentUri(contentUri, MAX_MMS_FILE_SIZE); if (pduData == null || pduData.length < 1) { - Log.e(TAG, "addMmsDraft: empty PDU"); + LogUtil.e("addMmsDraft: empty PDU"); return null; } // Clear the calling identity and query the database using the phone user id @@ -709,11 +706,11 @@ public class MmsService extends Service implements MmsRequest.RequestManager { try { final GenericPdu pdu = parsePduForAnyCarrier(pduData); if (pdu == null) { - Log.e(TAG, "addMmsDraft: can't parse input PDU"); + LogUtil.e("addMmsDraft: can't parse input PDU"); return null; } if (!(pdu instanceof SendReq)) { - Log.e(TAG, "addMmsDraft; invalid MMS type: " + pdu.getClass().getCanonicalName()); + LogUtil.e("addMmsDraft; invalid MMS type: " + pdu.getClass().getCanonicalName()); return null; } final PduPersister persister = PduPersister.getPduPersister(this); @@ -724,7 +721,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { true/*groupMmsEnabled*/, null/*preOpenedFiles*/); if (uri == null) { - Log.e(TAG, "addMmsDraft: failed to persist message"); + LogUtil.e("addMmsDraft: failed to persist message"); return null; } final ContentValues values = new ContentValues(3); @@ -735,13 +732,13 @@ public class MmsService extends Service implements MmsRequest.RequestManager { } if (SqliteWrapper.update(this, getContentResolver(), uri, values, null/*where*/, null/*selectionArg*/) != 1) { - Log.e(TAG, "addMmsDraft: failed to update message"); + LogUtil.e("addMmsDraft: failed to update message"); } return uri; } catch (RuntimeException e) { - Log.e(TAG, "addMmsDraft: failed to parse input PDU", e); + LogUtil.e("addMmsDraft: failed to parse input PDU", e); } catch (MmsException e) { - Log.e(TAG, "addMmsDraft: failed to persist message", e); + LogUtil.e("addMmsDraft: failed to persist message", e); } finally { Binder.restoreCallingIdentity(identity); } @@ -760,13 +757,13 @@ public class MmsService extends Service implements MmsRequest.RequestManager { try { pdu = (new PduParser(data, true/*parseContentDisposition*/)).parse(); } catch (RuntimeException e) { - Log.d(TAG, "parsePduForAnyCarrier: Failed to parse PDU with content disposition", e); + LogUtil.w("parsePduForAnyCarrier: Failed to parse PDU with content disposition", e); } if (pdu == null) { try { pdu = (new PduParser(data, false/*parseContentDisposition*/)).parse(); } catch (RuntimeException e) { - Log.d(TAG, "parsePduForAnyCarrier: Failed to parse PDU without content disposition", + LogUtil.w("parsePduForAnyCarrier: Failed to parse PDU without content disposition", e); } } @@ -801,17 +798,16 @@ public class MmsService extends Service implements MmsRequest.RequestManager { byte[] tempBody = new byte[maxSize+1]; int bytesRead = inStream.read(tempBody, 0, maxSize+1); if (bytesRead == 0) { - Log.e(MmsService.TAG, "MmsService.readPduFromContentUri: empty PDU"); + LogUtil.e("Read empty PDU"); return null; } if (bytesRead <= maxSize) { return Arrays.copyOf(tempBody, bytesRead); } - Log.e(MmsService.TAG, "MmsService.readPduFromContentUri: PDU too large"); + LogUtil.e("PDU read is too large"); return null; } catch (IOException ex) { - Log.e(MmsService.TAG, - "MmsService.readPduFromContentUri: IO exception reading PDU", ex); + LogUtil.e("IO exception reading PDU", ex); return null; } finally { if (inStream != null) { @@ -824,7 +820,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { } }; - Future<byte[]> pendingResult = mPduTransferExecutor.submit(copyPduToArray); + final Future<byte[]> pendingResult = mPduTransferExecutor.submit(copyPduToArray); try { return pendingResult.get(TASK_TIMEOUT_MS, TimeUnit.MILLISECONDS); } catch (Exception e) { @@ -844,7 +840,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { if (contentUri == null || pdu == null) { return false; } - Callable<Boolean> copyDownloadedPduToOutput = new Callable<Boolean>() { + final Callable<Boolean> copyDownloadedPduToOutput = new Callable<Boolean>() { public Boolean call() { ParcelFileDescriptor.AutoCloseOutputStream outStream = null; try { @@ -854,6 +850,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { outStream.write(pdu); return Boolean.TRUE; } catch (IOException ex) { + LogUtil.e("IO exception writing PDU", ex); return Boolean.FALSE; } finally { if (outStream != null) { @@ -866,7 +863,8 @@ public class MmsService extends Service implements MmsRequest.RequestManager { } }; - Future<Boolean> pendingResult = mPduTransferExecutor.submit(copyDownloadedPduToOutput); + final Future<Boolean> pendingResult = + mPduTransferExecutor.submit(copyDownloadedPduToOutput); try { return pendingResult.get(TASK_TIMEOUT_MS, TimeUnit.MILLISECONDS); } catch (Exception e) { diff --git a/src/com/android/mms/service/PhoneUtils.java b/src/com/android/mms/service/PhoneUtils.java index 8de881a..54b7ba9 100644 --- a/src/com/android/mms/service/PhoneUtils.java +++ b/src/com/android/mms/service/PhoneUtils.java @@ -60,12 +60,12 @@ public class PhoneUtils { if (phoneNumberUtil.isValidNumber(phoneNumber)) { return phoneNumber; } else { - Log.e(MmsService.TAG, "getParsedNumber: not a valid phone number" + LogUtil.e("getParsedNumber: not a valid phone number" + " for country " + country); return null; } } catch (final NumberParseException e) { - Log.e(MmsService.TAG, "getParsedNumber: Not able to parse phone number"); + LogUtil.e("getParsedNumber: Not able to parse phone number", e); return null; } } diff --git a/src/com/android/mms/service/SendRequest.java b/src/com/android/mms/service/SendRequest.java index d1781b1..37704c8 100644 --- a/src/com/android/mms/service/SendRequest.java +++ b/src/com/android/mms/service/SendRequest.java @@ -17,7 +17,6 @@ package com.android.mms.service; import android.app.Activity; -import android.app.AppOpsManager; import android.app.PendingIntent; import android.content.ContentValues; import android.content.Context; @@ -26,19 +25,15 @@ import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.RemoteException; -import android.os.UserHandle; import android.provider.Telephony; import android.service.carrier.CarrierMessagingService; import android.service.carrier.ICarrierMessagingService; import android.telephony.CarrierMessagingServiceManager; import android.telephony.SmsManager; -import android.telephony.TelephonyManager; import android.text.TextUtils; -import android.util.Log; import com.android.internal.telephony.SmsApplication; import com.android.mms.service.exception.MmsHttpException; - import com.google.android.mms.MmsException; import com.google.android.mms.pdu.GenericPdu; import com.google.android.mms.pdu.PduHeaders; @@ -48,8 +43,6 @@ import com.google.android.mms.pdu.SendConf; import com.google.android.mms.pdu.SendReq; import com.google.android.mms.util.SqliteWrapper; -import java.util.List; - /** * Request to send an MMS */ @@ -71,9 +64,10 @@ public class SendRequest extends MmsRequest { @Override protected byte[] doHttp(Context context, MmsNetworkManager netMgr, ApnSettings apn) throws MmsHttpException { + final String requestId = this.toString(); final MmsHttpClient mmsHttpClient = netMgr.getOrCreateHttpClient(); if (mmsHttpClient == null) { - Log.e(MmsService.TAG, "MMS network is not ready!"); + LogUtil.e(requestId, "MMS network is not ready!"); throw new MmsHttpException(0/*statusCode*/, "MMS network is not ready"); } return mmsHttpClient.execute( @@ -84,7 +78,8 @@ public class SendRequest extends MmsRequest { apn.getProxyAddress(), apn.getProxyPort(), mMmsConfig, - mSubId); + mSubId, + requestId); } @Override @@ -99,13 +94,14 @@ public class SendRequest extends MmsRequest { @Override protected Uri persistIfRequired(Context context, int result, byte[] response) { + final String requestId = this.toString(); if (!SmsApplication.shouldWriteMessageForPackage(mCreator, context)) { // Not required to persist return null; } - Log.d(MmsService.TAG, "SendRequest.persistIfRequired"); + LogUtil.d(requestId, "persistIfRequired"); if (mPduData == null) { - Log.e(MmsService.TAG, "SendRequest.persistIfRequired: empty PDU"); + LogUtil.e(requestId, "persistIfRequired: empty PDU"); return null; } final long identity = Binder.clearCallingIdentity(); @@ -115,11 +111,11 @@ public class SendRequest extends MmsRequest { // Persist the request PDU first GenericPdu pdu = (new PduParser(mPduData, supportContentDisposition)).parse(); if (pdu == null) { - Log.e(MmsService.TAG, "SendRequest.persistIfRequired: can't parse input PDU"); + LogUtil.e(requestId, "persistIfRequired: can't parse input PDU"); return null; } if (!(pdu instanceof SendReq)) { - Log.d(MmsService.TAG, "SendRequest.persistIfRequired: not SendReq"); + LogUtil.d(requestId, "persistIfRequired: not SendReq"); return null; } final PduPersister persister = PduPersister.getPduPersister(context); @@ -130,7 +126,7 @@ public class SendRequest extends MmsRequest { true/*groupMmsEnabled*/, null/*preOpenedFiles*/); if (messageUri == null) { - Log.e(MmsService.TAG, "SendRequest.persistIfRequired: can not persist message"); + LogUtil.e(requestId, "persistIfRequired: can not persist message"); return null; } // Update the additional columns based on the send result @@ -166,13 +162,13 @@ public class SendRequest extends MmsRequest { values.put(Telephony.Mms.SUBSCRIPTION_ID, mSubId); if (SqliteWrapper.update(context, context.getContentResolver(), messageUri, values, null/*where*/, null/*selectionArg*/) != 1) { - Log.e(MmsService.TAG, "SendRequest.persistIfRequired: failed to update message"); + LogUtil.e(requestId, "persistIfRequired: failed to update message"); } return messageUri; } catch (MmsException e) { - Log.e(MmsService.TAG, "SendRequest.persistIfRequired: can not persist message", e); + LogUtil.e(requestId, "persistIfRequired: can not persist message", e); } catch (RuntimeException e) { - Log.e(MmsService.TAG, "SendRequest.persistIfRequired: unexpected parsing failure", e); + LogUtil.e(requestId, "persistIfRequired: unexpected parsing failure", e); } finally { Binder.restoreCallingIdentity(identity); } @@ -248,9 +244,9 @@ public class SendRequest extends MmsRequest { CarrierSendCompleteCallback carrierSendCompleteCallback) { mCarrierSendCompleteCallback = carrierSendCompleteCallback; if (bindToCarrierMessagingService(context, carrierMessagingServicePackage)) { - Log.v(MmsService.TAG, "bindService() for carrier messaging service succeeded"); + LogUtil.v("bindService() for carrier messaging service succeeded"); } else { - Log.e(MmsService.TAG, "bindService() for carrier messaging service failed"); + LogUtil.e("bindService() for carrier messaging service failed"); carrierSendCompleteCallback.onSendMmsComplete( CarrierMessagingService.SEND_STATUS_RETRY_ON_CARRIER_NETWORK, null /* no sendConfPdu */); @@ -267,8 +263,7 @@ public class SendRequest extends MmsRequest { carrierMessagingService.sendMms(mPduUri, mSubId, locationUri, mCarrierSendCompleteCallback); } catch (RemoteException e) { - Log.e(MmsService.TAG, - "Exception sending MMS using the carrier messaging service: " + e); + LogUtil.e("Exception sending MMS using the carrier messaging service: " + e, e); mCarrierSendCompleteCallback.onSendMmsComplete( CarrierMessagingService.SEND_STATUS_RETRY_ON_CARRIER_NETWORK, null /* no sendConfPdu */); @@ -292,7 +287,7 @@ public class SendRequest extends MmsRequest { @Override public void onSendMmsComplete(int result, byte[] sendConfPdu) { - Log.d(MmsService.TAG, "Carrier app result for send: " + result); + LogUtil.d("Carrier app result for send: " + result); mCarrierSendManager.disposeConnection(mContext); if (!maybeFallbackToRegularDelivery(result)) { @@ -303,7 +298,7 @@ public class SendRequest extends MmsRequest { @Override public void onDownloadMmsComplete(int result) { - Log.e(MmsService.TAG, "Unexpected onDownloadMmsComplete call with result: " + result); + LogUtil.e("Unexpected onDownloadMmsComplete call with result: " + result); } } } |