blob: 199f0eb407d8fcd83d625b7cb412a176ef58da18 [file] [log] [blame]
Amit Mahajana25bc112019-09-20 11:13:05 -07001/*
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
17package android.telephony;
18
Sarah Chindf819b62020-01-10 16:09:11 -080019import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.SystemService;
Amit Mahajana25bc112019-09-20 11:13:05 -070022import android.app.ActivityThread;
23import android.app.PendingIntent;
Sarah Chindf819b62020-01-10 16:09:11 -080024import android.content.Context;
Amit Mahajana25bc112019-09-20 11:13:05 -070025import android.net.Uri;
26import android.os.Bundle;
27import android.os.RemoteException;
28import android.os.ServiceManager;
29
30import com.android.internal.telephony.IMms;
31
32/**
33 * Manages MMS operations such as sending multimedia messages.
Sarah Chindf819b62020-01-10 16:09:11 -080034 * Get this object by calling Context#getSystemService(Context#MMS_SERVICE).
Sarah Chin5fe26152020-03-18 13:57:18 -070035 * @hide
Amit Mahajana25bc112019-09-20 11:13:05 -070036 */
Sarah Chindf819b62020-01-10 16:09:11 -080037@SystemService(Context.MMS_SERVICE)
Sarah Chin5dd05a42020-01-10 19:33:35 +000038public class MmsManager {
Amit Mahajana25bc112019-09-20 11:13:05 -070039 private static final String TAG = "MmsManager";
Sarah Chindf819b62020-01-10 16:09:11 -080040 private final Context mContext;
Amit Mahajana25bc112019-09-20 11:13:05 -070041
42 /**
Sarah Chindf819b62020-01-10 16:09:11 -080043 * @hide
Amit Mahajana25bc112019-09-20 11:13:05 -070044 */
Sarah Chindf819b62020-01-10 16:09:11 -080045 public MmsManager(@NonNull Context context) {
46 mContext = context;
Amit Mahajana25bc112019-09-20 11:13:05 -070047 }
48
49 /**
50 * Send an MMS message
51 *
52 * @param subId the subscription id
53 * @param contentUri the content Uri from which the message pdu will be read
54 * @param locationUrl the optional location url where message should be sent to
55 * @param configOverrides the carrier-specific messaging configuration values to override for
56 * sending the message.
57 * @param sentIntent if not NULL this <code>PendingIntent</code> is broadcast when the message
58 * is successfully sent, or failed
59 */
Sarah Chindf819b62020-01-10 16:09:11 -080060 public void sendMultimediaMessage(int subId, @NonNull Uri contentUri,
61 @Nullable String locationUrl, @Nullable Bundle configOverrides,
62 @Nullable PendingIntent sentIntent) {
Amit Mahajana25bc112019-09-20 11:13:05 -070063 try {
64 final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
65 if (iMms == null) {
66 return;
67 }
68
69 iMms.sendMessage(subId, ActivityThread.currentPackageName(), contentUri,
70 locationUrl, configOverrides, sentIntent);
71 } catch (RemoteException e) {
72 // Ignore it
73 }
74 }
75
76 /**
77 * Download an MMS message from carrier by a given location URL
78 *
79 * @param subId the subscription id
80 * @param locationUrl the location URL of the MMS message to be downloaded, usually obtained
81 * from the MMS WAP push notification
82 * @param contentUri the content uri to which the downloaded pdu will be written
83 * @param configOverrides the carrier-specific messaging configuration values to override for
84 * downloading the message.
85 * @param downloadedIntent if not NULL this <code>PendingIntent</code> is
86 * broadcast when the message is downloaded, or the download is failed
87 * @throws IllegalArgumentException if locationUrl or contentUri is empty
88 */
Sarah Chindf819b62020-01-10 16:09:11 -080089 public void downloadMultimediaMessage(int subId, @NonNull String locationUrl,
90 @NonNull Uri contentUri, @Nullable Bundle configOverrides,
91 @Nullable PendingIntent downloadedIntent) {
Amit Mahajana25bc112019-09-20 11:13:05 -070092 try {
93 final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
94 if (iMms == null) {
95 return;
96 }
97 iMms.downloadMessage(subId, ActivityThread.currentPackageName(),
98 locationUrl, contentUri, configOverrides, downloadedIntent);
99 } catch (RemoteException e) {
100 // Ignore it
101 }
102 }
Amit Mahajana25bc112019-09-20 11:13:05 -0700103}