blob: f07cd5e340629cfdeb8e0b8dc9b03ba820962a83 [file] [log] [blame]
Amit Mahajan24c01a22019-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 Chin4affb512020-01-10 16:09:11 -080019import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.SystemService;
Amit Mahajan24c01a22019-09-20 11:13:05 -070022import android.app.ActivityThread;
23import android.app.PendingIntent;
Sarah Chin4affb512020-01-10 16:09:11 -080024import android.content.Context;
Amit Mahajan24c01a22019-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 Chin4affb512020-01-10 16:09:11 -080034 * Get this object by calling Context#getSystemService(Context#MMS_SERVICE).
Amit Mahajan24c01a22019-09-20 11:13:05 -070035 */
Sarah Chin4affb512020-01-10 16:09:11 -080036@SystemService(Context.MMS_SERVICE)
Sarah Chinee13f122020-01-10 19:23:33 +000037public class MmsManager {
Amit Mahajan24c01a22019-09-20 11:13:05 -070038 private static final String TAG = "MmsManager";
Sarah Chin4affb512020-01-10 16:09:11 -080039 private final Context mContext;
Amit Mahajan24c01a22019-09-20 11:13:05 -070040
41 /**
Sarah Chin4affb512020-01-10 16:09:11 -080042 * @hide
Amit Mahajan24c01a22019-09-20 11:13:05 -070043 */
Sarah Chin4affb512020-01-10 16:09:11 -080044 public MmsManager(@NonNull Context context) {
45 mContext = context;
Amit Mahajan24c01a22019-09-20 11:13:05 -070046 }
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
Tom Taylor03079ec2020-01-24 10:21:50 -080058 * @param messageId an id that uniquely identifies the message requested to be sent.
59 * Used for logging and diagnostics purposes. The id may be 0.
Amit Mahajan24c01a22019-09-20 11:13:05 -070060 */
Sarah Chin4affb512020-01-10 16:09:11 -080061 public void sendMultimediaMessage(int subId, @NonNull Uri contentUri,
62 @Nullable String locationUrl, @Nullable Bundle configOverrides,
Tom Taylor03079ec2020-01-24 10:21:50 -080063 @Nullable PendingIntent sentIntent, long messageId) {
Amit Mahajan24c01a22019-09-20 11:13:05 -070064 try {
65 final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
66 if (iMms == null) {
67 return;
68 }
69
70 iMms.sendMessage(subId, ActivityThread.currentPackageName(), contentUri,
Tom Taylor03079ec2020-01-24 10:21:50 -080071 locationUrl, configOverrides, sentIntent, messageId);
Amit Mahajan24c01a22019-09-20 11:13:05 -070072 } catch (RemoteException e) {
73 // Ignore it
74 }
75 }
76
77 /**
78 * Download an MMS message from carrier by a given location URL
79 *
80 * @param subId the subscription id
81 * @param locationUrl the location URL of the MMS message to be downloaded, usually obtained
82 * from the MMS WAP push notification
83 * @param contentUri the content uri to which the downloaded pdu will be written
84 * @param configOverrides the carrier-specific messaging configuration values to override for
85 * downloading the message.
86 * @param downloadedIntent if not NULL this <code>PendingIntent</code> is
87 * broadcast when the message is downloaded, or the download is failed
Tom Taylor03079ec2020-01-24 10:21:50 -080088 * @param messageId an id that uniquely identifies the message requested to be downloaded.
89 * Used for logging and diagnostics purposes. The id may be 0.
90 * downloaded.
Amit Mahajan24c01a22019-09-20 11:13:05 -070091 * @throws IllegalArgumentException if locationUrl or contentUri is empty
92 */
Sarah Chin4affb512020-01-10 16:09:11 -080093 public void downloadMultimediaMessage(int subId, @NonNull String locationUrl,
94 @NonNull Uri contentUri, @Nullable Bundle configOverrides,
Tom Taylor03079ec2020-01-24 10:21:50 -080095 @Nullable PendingIntent downloadedIntent, long messageId) {
Amit Mahajan24c01a22019-09-20 11:13:05 -070096 try {
97 final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
98 if (iMms == null) {
99 return;
100 }
101 iMms.downloadMessage(subId, ActivityThread.currentPackageName(),
Tom Taylor03079ec2020-01-24 10:21:50 -0800102 locationUrl, contentUri, configOverrides, downloadedIntent,
103 messageId);
Amit Mahajan24c01a22019-09-20 11:13:05 -0700104 } catch (RemoteException e) {
105 // Ignore it
106 }
107 }
Amit Mahajan24c01a22019-09-20 11:13:05 -0700108}