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. |
Sarah Chin | ee13f12 | 2020-01-10 19:23:33 +0000 | [diff] [blame] | 30 | * Get this object by calling the static method {@link #getInstance()}. |
| 31 | * @hide |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 32 | */ |
Sarah Chin | ee13f12 | 2020-01-10 19:23:33 +0000 | [diff] [blame] | 33 | public class MmsManager { |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 34 | private static final String TAG = "MmsManager"; |
Sarah Chin | ee13f12 | 2020-01-10 19:23:33 +0000 | [diff] [blame] | 35 | |
| 36 | /** Singleton object constructed during class initialization. */ |
| 37 | private static final MmsManager sInstance = new MmsManager(); |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
Sarah Chin | ee13f12 | 2020-01-10 19:23:33 +0000 | [diff] [blame] | 40 | * Get the MmsManager singleton instance. |
| 41 | * |
| 42 | * @return the {@link MmsManager} singleton instance. |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 43 | */ |
Sarah Chin | ee13f12 | 2020-01-10 19:23:33 +0000 | [diff] [blame] | 44 | public static MmsManager getInstance() { |
| 45 | return sInstance; |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 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 | */ |
Sarah Chin | ee13f12 | 2020-01-10 19:23:33 +0000 | [diff] [blame] | 59 | public void sendMultimediaMessage(int subId, Uri contentUri, String locationUrl, |
| 60 | Bundle configOverrides, PendingIntent sentIntent) { |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 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 | */ |
Sarah Chin | ee13f12 | 2020-01-10 19:23:33 +0000 | [diff] [blame] | 87 | public void downloadMultimediaMessage(int subId, String locationUrl, Uri contentUri, |
| 88 | Bundle configOverrides, PendingIntent downloadedIntent) { |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 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 | } |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 100 | } |