blob: 65542673a6075b381a9816212f975e7ccfeaf4b7 [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
19import android.app.ActivityThread;
20import android.app.PendingIntent;
21import android.net.Uri;
22import android.os.Bundle;
23import android.os.RemoteException;
24import android.os.ServiceManager;
25
26import com.android.internal.telephony.IMms;
27
28/**
29 * Manages MMS operations such as sending multimedia messages.
Sarah Chinee13f122020-01-10 19:23:33 +000030 * Get this object by calling the static method {@link #getInstance()}.
31 * @hide
Amit Mahajan24c01a22019-09-20 11:13:05 -070032 */
Sarah Chinee13f122020-01-10 19:23:33 +000033public class MmsManager {
Amit Mahajan24c01a22019-09-20 11:13:05 -070034 private static final String TAG = "MmsManager";
Sarah Chinee13f122020-01-10 19:23:33 +000035
36 /** Singleton object constructed during class initialization. */
37 private static final MmsManager sInstance = new MmsManager();
Amit Mahajan24c01a22019-09-20 11:13:05 -070038
39 /**
Sarah Chinee13f122020-01-10 19:23:33 +000040 * Get the MmsManager singleton instance.
41 *
42 * @return the {@link MmsManager} singleton instance.
Amit Mahajan24c01a22019-09-20 11:13:05 -070043 */
Sarah Chinee13f122020-01-10 19:23:33 +000044 public static MmsManager getInstance() {
45 return sInstance;
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
58 */
Sarah Chinee13f122020-01-10 19:23:33 +000059 public void sendMultimediaMessage(int subId, Uri contentUri, String locationUrl,
60 Bundle configOverrides, PendingIntent sentIntent) {
Amit Mahajan24c01a22019-09-20 11:13:05 -070061 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 Chinee13f122020-01-10 19:23:33 +000087 public void downloadMultimediaMessage(int subId, String locationUrl, Uri contentUri,
88 Bundle configOverrides, PendingIntent downloadedIntent) {
Amit Mahajan24c01a22019-09-20 11:13:05 -070089 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 Mahajan24c01a22019-09-20 11:13:05 -0700100}