blob: ac2927711c9acf661000f402acd0bc319e1b980e [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;
Nikhil Kumar3df02a72024-07-08 17:01:09 +010029import android.os.UserHandle;
Amit Mahajan24c01a22019-09-20 11:13:05 -070030
31import com.android.internal.telephony.IMms;
32
33/**
34 * Manages MMS operations such as sending multimedia messages.
Sarah Chin4affb512020-01-10 16:09:11 -080035 * Get this object by calling Context#getSystemService(Context#MMS_SERVICE).
Sarah Chin8ac7ce52020-03-18 13:57:18 -070036 * @hide
Amit Mahajan24c01a22019-09-20 11:13:05 -070037 */
Sarah Chin4affb512020-01-10 16:09:11 -080038@SystemService(Context.MMS_SERVICE)
Sarah Chinee13f122020-01-10 19:23:33 +000039public class MmsManager {
Amit Mahajan24c01a22019-09-20 11:13:05 -070040 private static final String TAG = "MmsManager";
Sarah Chin4affb512020-01-10 16:09:11 -080041 private final Context mContext;
Amit Mahajan24c01a22019-09-20 11:13:05 -070042
43 /**
Sarah Chin4affb512020-01-10 16:09:11 -080044 * @hide
Amit Mahajan24c01a22019-09-20 11:13:05 -070045 */
Sarah Chin4affb512020-01-10 16:09:11 -080046 public MmsManager(@NonNull Context context) {
47 mContext = context;
Amit Mahajan24c01a22019-09-20 11:13:05 -070048 }
49
50 /**
51 * Send an MMS message
52 *
53 * @param subId the subscription id
54 * @param contentUri the content Uri from which the message pdu will be read
55 * @param locationUrl the optional location url where message should be sent to
56 * @param configOverrides the carrier-specific messaging configuration values to override for
57 * sending the message.
58 * @param sentIntent if not NULL this <code>PendingIntent</code> is broadcast when the message
59 * is successfully sent, or failed
Tom Taylor03079ec2020-01-24 10:21:50 -080060 * @param messageId an id that uniquely identifies the message requested to be sent.
Tom Taylorc03117f2020-02-19 16:13:13 -080061 * Used for logging and diagnostics purposes. The id may be 0. The messageId
62 * can be found in radio logs from logcat.
Amit Mahajan24c01a22019-09-20 11:13:05 -070063 */
Sarah Chin4affb512020-01-10 16:09:11 -080064 public void sendMultimediaMessage(int subId, @NonNull Uri contentUri,
65 @Nullable String locationUrl, @Nullable Bundle configOverrides,
Tom Taylor03079ec2020-01-24 10:21:50 -080066 @Nullable PendingIntent sentIntent, long messageId) {
Amit Mahajan24c01a22019-09-20 11:13:05 -070067 try {
68 final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
69 if (iMms == null) {
70 return;
71 }
72
Nikhil Kumar3df02a72024-07-08 17:01:09 +010073 iMms.sendMessage(subId, /* placeholder callingUser= */ UserHandle.USER_NULL,
74 ActivityThread.currentPackageName(), contentUri, locationUrl,
75 configOverrides, sentIntent, messageId, mContext.getAttributionTag());
Amit Mahajan24c01a22019-09-20 11:13:05 -070076 } catch (RemoteException e) {
77 // Ignore it
78 }
79 }
80
81 /**
82 * Download an MMS message from carrier by a given location URL
83 *
84 * @param subId the subscription id
85 * @param locationUrl the location URL of the MMS message to be downloaded, usually obtained
86 * from the MMS WAP push notification
87 * @param contentUri the content uri to which the downloaded pdu will be written
88 * @param configOverrides the carrier-specific messaging configuration values to override for
89 * downloading the message.
90 * @param downloadedIntent if not NULL this <code>PendingIntent</code> is
91 * broadcast when the message is downloaded, or the download is failed
Tom Taylor03079ec2020-01-24 10:21:50 -080092 * @param messageId an id that uniquely identifies the message requested to be downloaded.
Tom Taylorc03117f2020-02-19 16:13:13 -080093 * Used for logging and diagnostics purposes. The id may be 0. The messageId
94 * can be found in radio logs from logcat.
Amit Mahajan24c01a22019-09-20 11:13:05 -070095 * @throws IllegalArgumentException if locationUrl or contentUri is empty
96 */
Sarah Chin4affb512020-01-10 16:09:11 -080097 public void downloadMultimediaMessage(int subId, @NonNull String locationUrl,
98 @NonNull Uri contentUri, @Nullable Bundle configOverrides,
Tom Taylor03079ec2020-01-24 10:21:50 -080099 @Nullable PendingIntent downloadedIntent, long messageId) {
Amit Mahajan24c01a22019-09-20 11:13:05 -0700100 try {
101 final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
102 if (iMms == null) {
103 return;
104 }
Nikhil Kumar3df02a72024-07-08 17:01:09 +0100105 iMms.downloadMessage(subId, /* placeholder callingUser= */ UserHandle.USER_NULL,
106 ActivityThread.currentPackageName(), locationUrl, contentUri,
107 configOverrides, downloadedIntent, messageId, mContext.getAttributionTag());
Amit Mahajan24c01a22019-09-20 11:13:05 -0700108 } catch (RemoteException e) {
109 // Ignore it
110 }
111 }
Amit Mahajan24c01a22019-09-20 11:13:05 -0700112}