Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 android.telephony; |
| 18 | |
| 19 | import android.app.ActivityThread; |
| 20 | import android.app.PendingIntent; |
| 21 | import android.net.Uri; |
| 22 | import android.os.Bundle; |
| 23 | import android.os.RemoteException; |
| 24 | import android.os.ServiceManager; |
| 25 | |
| 26 | import com.android.internal.telephony.IMms; |
| 27 | |
| 28 | /** |
| 29 | * Manages MMS operations such as sending multimedia messages. |
| 30 | * Get this object by calling the static method {@link #getInstance()}. |
| 31 | * @hide |
| 32 | */ |
| 33 | public class MmsManager { |
| 34 | private static final String TAG = "MmsManager"; |
| 35 | |
| 36 | /** Singleton object constructed during class initialization. */ |
| 37 | private static final MmsManager sInstance = new MmsManager(); |
| 38 | |
| 39 | /** |
| 40 | * Get the MmsManager singleton instance. |
| 41 | * |
| 42 | * @return the {@link MmsManager} singleton instance. |
| 43 | */ |
| 44 | public static MmsManager getInstance() { |
| 45 | return sInstance; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Send an MMS message |
| 50 | * |
| 51 | * @param subId the subscription id |
| 52 | * @param contentUri the content Uri from which the message pdu will be read |
| 53 | * @param locationUrl the optional location url where message should be sent to |
| 54 | * @param configOverrides the carrier-specific messaging configuration values to override for |
| 55 | * sending the message. |
| 56 | * @param sentIntent if not NULL this <code>PendingIntent</code> is broadcast when the message |
| 57 | * is successfully sent, or failed |
| 58 | */ |
| 59 | public void sendMultimediaMessage(int subId, Uri contentUri, String locationUrl, |
| 60 | Bundle configOverrides, PendingIntent sentIntent) { |
| 61 | try { |
| 62 | final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms")); |
| 63 | if (iMms == null) { |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | iMms.sendMessage(subId, ActivityThread.currentPackageName(), contentUri, |
| 68 | locationUrl, configOverrides, sentIntent); |
| 69 | } catch (RemoteException e) { |
| 70 | // Ignore it |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Download an MMS message from carrier by a given location URL |
| 76 | * |
| 77 | * @param subId the subscription id |
| 78 | * @param locationUrl the location URL of the MMS message to be downloaded, usually obtained |
| 79 | * from the MMS WAP push notification |
| 80 | * @param contentUri the content uri to which the downloaded pdu will be written |
| 81 | * @param configOverrides the carrier-specific messaging configuration values to override for |
| 82 | * downloading the message. |
| 83 | * @param downloadedIntent if not NULL this <code>PendingIntent</code> is |
| 84 | * broadcast when the message is downloaded, or the download is failed |
| 85 | * @throws IllegalArgumentException if locationUrl or contentUri is empty |
| 86 | */ |
| 87 | public void downloadMultimediaMessage(int subId, String locationUrl, Uri contentUri, |
| 88 | Bundle configOverrides, PendingIntent downloadedIntent) { |
| 89 | try { |
| 90 | final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms")); |
| 91 | if (iMms == null) { |
| 92 | return; |
| 93 | } |
| 94 | iMms.downloadMessage(subId, ActivityThread.currentPackageName(), |
| 95 | locationUrl, contentUri, configOverrides, downloadedIntent); |
| 96 | } catch (RemoteException e) { |
| 97 | // Ignore it |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Get carrier-dependent configuration values. |
| 103 | * |
| 104 | * @param subId the subscription id |
| 105 | * @return bundle key/values pairs of configuration values |
| 106 | */ |
| 107 | public Bundle getCarrierConfigValues(int subId) { |
| 108 | try { |
| 109 | IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms")); |
| 110 | if (iMms != null) { |
| 111 | return iMms.getCarrierConfigValues(subId); |
| 112 | } |
| 113 | } catch (RemoteException ex) { |
| 114 | // ignore it |
| 115 | } |
| 116 | return null; |
| 117 | } |
| 118 | } |