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 | |
Sarah Chin | 4affb51 | 2020-01-10 16:09:11 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
| 21 | import android.annotation.SystemService; |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 22 | import android.app.ActivityThread; |
| 23 | import android.app.PendingIntent; |
Sarah Chin | 4affb51 | 2020-01-10 16:09:11 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 25 | import android.net.Uri; |
| 26 | import android.os.Bundle; |
| 27 | import android.os.RemoteException; |
| 28 | import android.os.ServiceManager; |
| 29 | |
| 30 | import com.android.internal.telephony.IMms; |
| 31 | |
| 32 | /** |
| 33 | * Manages MMS operations such as sending multimedia messages. |
Sarah Chin | 4affb51 | 2020-01-10 16:09:11 -0800 | [diff] [blame] | 34 | * Get this object by calling Context#getSystemService(Context#MMS_SERVICE). |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 35 | */ |
Sarah Chin | 4affb51 | 2020-01-10 16:09:11 -0800 | [diff] [blame] | 36 | @SystemService(Context.MMS_SERVICE) |
Sarah Chin | ee13f12 | 2020-01-10 19:23:33 +0000 | [diff] [blame] | 37 | public class MmsManager { |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 38 | private static final String TAG = "MmsManager"; |
Sarah Chin | 4affb51 | 2020-01-10 16:09:11 -0800 | [diff] [blame] | 39 | private final Context mContext; |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
Sarah Chin | 4affb51 | 2020-01-10 16:09:11 -0800 | [diff] [blame] | 42 | * @hide |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 43 | */ |
Sarah Chin | 4affb51 | 2020-01-10 16:09:11 -0800 | [diff] [blame] | 44 | public MmsManager(@NonNull Context context) { |
| 45 | mContext = context; |
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 | 4affb51 | 2020-01-10 16:09:11 -0800 | [diff] [blame] | 59 | public void sendMultimediaMessage(int subId, @NonNull Uri contentUri, |
| 60 | @Nullable String locationUrl, @Nullable Bundle configOverrides, |
| 61 | @Nullable PendingIntent sentIntent) { |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 62 | try { |
| 63 | final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms")); |
| 64 | if (iMms == null) { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | iMms.sendMessage(subId, ActivityThread.currentPackageName(), contentUri, |
| 69 | locationUrl, configOverrides, sentIntent); |
| 70 | } catch (RemoteException e) { |
| 71 | // Ignore it |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Download an MMS message from carrier by a given location URL |
| 77 | * |
| 78 | * @param subId the subscription id |
| 79 | * @param locationUrl the location URL of the MMS message to be downloaded, usually obtained |
| 80 | * from the MMS WAP push notification |
| 81 | * @param contentUri the content uri to which the downloaded pdu will be written |
| 82 | * @param configOverrides the carrier-specific messaging configuration values to override for |
| 83 | * downloading the message. |
| 84 | * @param downloadedIntent if not NULL this <code>PendingIntent</code> is |
| 85 | * broadcast when the message is downloaded, or the download is failed |
| 86 | * @throws IllegalArgumentException if locationUrl or contentUri is empty |
| 87 | */ |
Sarah Chin | 4affb51 | 2020-01-10 16:09:11 -0800 | [diff] [blame] | 88 | public void downloadMultimediaMessage(int subId, @NonNull String locationUrl, |
| 89 | @NonNull Uri contentUri, @Nullable Bundle configOverrides, |
| 90 | @Nullable PendingIntent downloadedIntent) { |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 91 | try { |
| 92 | final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms")); |
| 93 | if (iMms == null) { |
| 94 | return; |
| 95 | } |
| 96 | iMms.downloadMessage(subId, ActivityThread.currentPackageName(), |
| 97 | locationUrl, contentUri, configOverrides, downloadedIntent); |
| 98 | } catch (RemoteException e) { |
| 99 | // Ignore it |
| 100 | } |
| 101 | } |
Amit Mahajan | 24c01a2 | 2019-09-20 11:13:05 -0700 | [diff] [blame] | 102 | } |