diff options
| author | Amit Mahajan <amitmahajan@google.com> | 2019-10-30 13:25:27 -0700 |
|---|---|---|
| committer | Amit Mahajan <amitmahajan@google.com> | 2019-10-30 13:25:27 -0700 |
| commit | 2f821cea93e65c2e4e69a05b6c4940972bd8d6dd (patch) | |
| tree | 513c6699bd798d3af56661c4d032af5788af7efb /src/com | |
| parent | 35c0b40d1661dc0c8c56496fc055dd25c9bbe9f9 (diff) | |
| download | platform_packages_services_Mms-2f821cea93e65c2e4e69a05b6c4940972bd8d6dd.tar.gz platform_packages_services_Mms-2f821cea93e65c2e4e69a05b6c4940972bd8d6dd.tar.bz2 platform_packages_services_Mms-2f821cea93e65c2e4e69a05b6c4940972bd8d6dd.zip | |
Use CarrierMessagingServiceWrapper.
Instead of using a local wrapper to communicate with
CarrierMessagingService.
Test: basic messaging sanity
Bug: 143609473
Change-Id: I06419b49df06c1771f50ea1e4580bd0fc141bba6
Diffstat (limited to 'src/com')
| -rw-r--r-- | src/com/android/mms/service/CarrierMessagingServiceManager.java | 103 | ||||
| -rw-r--r-- | src/com/android/mms/service/DownloadRequest.java | 10 | ||||
| -rw-r--r-- | src/com/android/mms/service/MmsRequest.java | 4 | ||||
| -rw-r--r-- | src/com/android/mms/service/SendRequest.java | 12 |
4 files changed, 12 insertions, 117 deletions
diff --git a/src/com/android/mms/service/CarrierMessagingServiceManager.java b/src/com/android/mms/service/CarrierMessagingServiceManager.java deleted file mode 100644 index d2616a2..0000000 --- a/src/com/android/mms/service/CarrierMessagingServiceManager.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2019 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.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; -import android.os.IBinder; -import android.service.carrier.CarrierMessagingService; -import android.service.carrier.ICarrierMessagingService; - -import com.android.internal.util.Preconditions; - -/** - * Provides basic structure for platform to connect to the carrier messaging service. - * <p> - * <code> - * CarrierMessagingServiceManager carrierMessagingServiceManager = - * new CarrierMessagingServiceManagerImpl(); - * if (carrierMessagingServiceManager.bindToCarrierMessagingService(context, carrierPackageName)) { - * // wait for onServiceReady callback - * } else { - * // Unable to bind: handle error. - * } - * </code> - * <p> Upon completion {@link #disposeConnection} should be called to unbind the - * CarrierMessagingService. - * @hide - */ - -public abstract class CarrierMessagingServiceManager { - - public CarrierMessagingServiceManager() {} - - // Populated by bindToCarrierMessagingService. bindToCarrierMessagingService must complete - // prior to calling disposeConnection so that mCarrierMessagingServiceConnection is initialized. - private volatile CarrierMessagingServiceConnection mCarrierMessagingServiceConnection; - - /** - * Binds to the carrier messaging service under package {@code carrierPackageName}. This method - * should be called exactly once. - * - * @param context the context - * @param carrierPackageName the carrier package name - * @return true upon successfully binding to a carrier messaging service, false otherwise - */ - public boolean bindToCarrierMessagingService(Context context, String carrierPackageName) { - Preconditions.checkState(mCarrierMessagingServiceConnection == null); - - Intent intent = new Intent(CarrierMessagingService.SERVICE_INTERFACE); - intent.setPackage(carrierPackageName); - mCarrierMessagingServiceConnection = new CarrierMessagingServiceConnection(); - return context.bindService(intent, mCarrierMessagingServiceConnection, - Context.BIND_AUTO_CREATE); - } - - /** - * Unbinds the carrier messaging service. This method should be called exactly once. - * - * @param context the context - */ - public void disposeConnection(Context context) { - Preconditions.checkNotNull(mCarrierMessagingServiceConnection); - context.unbindService(mCarrierMessagingServiceConnection); - mCarrierMessagingServiceConnection = null; - } - - /** - * Implemented by subclasses to use the carrier messaging service once it is ready. - * - * @param carrierMessagingService the carrier messaing service interface - */ - protected abstract void onServiceReady(ICarrierMessagingService carrierMessagingService); - - /** - * A basic {@link ServiceConnection}. - */ - private final class CarrierMessagingServiceConnection implements ServiceConnection { - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - onServiceReady(ICarrierMessagingService.Stub.asInterface(service)); - } - - @Override - public void onServiceDisconnected(ComponentName name) { - } - } -}
\ No newline at end of file diff --git a/src/com/android/mms/service/DownloadRequest.java b/src/com/android/mms/service/DownloadRequest.java index 89fc1ce..8079fa4 100644 --- a/src/com/android/mms/service/DownloadRequest.java +++ b/src/com/android/mms/service/DownloadRequest.java @@ -33,7 +33,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.provider.Telephony; import android.service.carrier.CarrierMessagingService; -import android.service.carrier.ICarrierMessagingService; +import android.service.carrier.CarrierMessagingServiceWrapper; import android.telephony.SmsManager; import android.text.TextUtils; @@ -269,7 +269,7 @@ public class DownloadRequest extends MmsRequest { /** * Downloads the MMS through through the carrier app. */ - private final class CarrierDownloadManager extends CarrierMessagingServiceManager { + private final class CarrierDownloadManager extends CarrierMessagingServiceWrapper { // Initialized in downloadMms private volatile CarrierDownloadCompleteCallback mCarrierDownloadCallback; @@ -286,11 +286,11 @@ public class DownloadRequest extends MmsRequest { } @Override - protected void onServiceReady(ICarrierMessagingService carrierMessagingService) { + public void onServiceReady() { try { - carrierMessagingService.downloadMms(mContentUri, mSubId, Uri.parse(mLocationUrl), + downloadMms(mContentUri, mSubId, Uri.parse(mLocationUrl), mCarrierDownloadCallback); - } catch (RemoteException e) { + } catch (RuntimeException e) { LogUtil.e("Exception downloading MMS using the carrier messaging service: " + e, e); mCarrierDownloadCallback.onDownloadMmsComplete( CarrierMessagingService.DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK); diff --git a/src/com/android/mms/service/MmsRequest.java b/src/com/android/mms/service/MmsRequest.java index 8363686..9f3e620 100644 --- a/src/com/android/mms/service/MmsRequest.java +++ b/src/com/android/mms/service/MmsRequest.java @@ -23,7 +23,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.service.carrier.CarrierMessagingService; -import android.service.carrier.ICarrierMessagingCallback; +import android.service.carrier.CarrierMessagingServiceWrapper.CarrierMessagingCallbackWrapper; import android.telephony.SmsManager; import android.telephony.TelephonyManager; import android.text.TextUtils; @@ -341,7 +341,7 @@ public abstract class MmsRequest { /** * Base class for handling carrier app send / download result. */ - protected abstract class CarrierMmsActionCallback extends ICarrierMessagingCallback.Stub { + protected abstract class CarrierMmsActionCallback extends CarrierMessagingCallbackWrapper { @Override public void onSendSmsComplete(int result, int messageRef) { LogUtil.e("Unexpected onSendSmsComplete call with result: " + result); diff --git a/src/com/android/mms/service/SendRequest.java b/src/com/android/mms/service/SendRequest.java index eb36a13..8446646 100644 --- a/src/com/android/mms/service/SendRequest.java +++ b/src/com/android/mms/service/SendRequest.java @@ -25,11 +25,10 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Binder; import android.os.Bundle; -import android.os.RemoteException; import android.provider.BlockedNumberContract; import android.provider.Telephony; import android.service.carrier.CarrierMessagingService; -import android.service.carrier.ICarrierMessagingService; +import android.service.carrier.CarrierMessagingServiceWrapper; import android.telephony.SmsManager; import android.telephony.TelephonyManager; import android.text.TextUtils; @@ -384,7 +383,7 @@ public class SendRequest extends MmsRequest { /** * Sends the MMS through through the carrier app. */ - private final class CarrierSendManager extends CarrierMessagingServiceManager { + private final class CarrierSendManager extends CarrierMessagingServiceWrapper { // Initialized in sendMms private volatile CarrierSendCompleteCallback mCarrierSendCompleteCallback; @@ -402,15 +401,14 @@ public class SendRequest extends MmsRequest { } @Override - protected void onServiceReady(ICarrierMessagingService carrierMessagingService) { + public void onServiceReady() { try { Uri locationUri = null; if (mLocationUrl != null) { locationUri = Uri.parse(mLocationUrl); } - carrierMessagingService.sendMms(mPduUri, mSubId, locationUri, - mCarrierSendCompleteCallback); - } catch (RemoteException e) { + sendMms(mPduUri, mSubId, locationUri, mCarrierSendCompleteCallback); + } catch (RuntimeException e) { LogUtil.e("Exception sending MMS using the carrier messaging service: " + e, e); mCarrierSendCompleteCallback.onSendMmsComplete( CarrierMessagingService.SEND_STATUS_RETRY_ON_CARRIER_NETWORK, |
