From 2a9bf57176e9818badf4e7d0b521c4c6fe4120e3 Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Wed, 23 Dec 2020 19:14:32 -0800 Subject: [PATCH] Add content type to the picture upload method To avoid Telephony parsing the picture in order to determine its content type, request it from the sending app so we can include it in the HTTP request to the carrier. Bug: 175435766 Test: CTS Change-Id: Iaa8697df5797e5e0c0ce9fb2f3253d7fd8af8bf4 --- core/api/current.txt | 5 ++-- .../android/telephony/TelephonyManager.java | 28 +++++++++++++++---- .../internal/telephony/ITelephony.aidl | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index ba3f6364f646d..bf668612ef8e6 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -41850,8 +41850,8 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void switchMultiSimConfig(int); method public void unregisterPhoneStateListener(@NonNull android.telephony.PhoneStateListener); method public void updateAvailableNetworks(@NonNull java.util.List, @Nullable java.util.concurrent.Executor, @Nullable java.util.function.Consumer); - method public void uploadCallComposerPicture(@NonNull java.nio.file.Path, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver); - method public void uploadCallComposerPicture(@NonNull java.io.InputStream, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver); + method public void uploadCallComposerPicture(@NonNull java.nio.file.Path, @NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver); + method public void uploadCallComposerPicture(@NonNull java.io.InputStream, @NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver); field public static final String ACTION_CARRIER_MESSAGING_CLIENT_SERVICE = "android.telephony.action.CARRIER_MESSAGING_CLIENT_SERVICE"; field public static final String ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE = "android.telephony.action.CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE"; field public static final String ACTION_CARRIER_SIGNAL_PCO_VALUE = "android.telephony.action.CARRIER_SIGNAL_PCO_VALUE"; @@ -42002,6 +42002,7 @@ package android.telephony { field public static final int ERROR_FILE_TOO_LARGE = 2; // 0x2 field public static final int ERROR_INPUT_CLOSED = 4; // 0x4 field public static final int ERROR_IO_EXCEPTION = 5; // 0x5 + field public static final int ERROR_NETWORK_UNAVAILABLE = 6; // 0x6 field public static final int ERROR_REMOTE_END_CLOSED = 1; // 0x1 field public static final int ERROR_UNKNOWN = 0; // 0x0 } diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index bfd37cd608064..27025759a317d 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -564,9 +564,10 @@ public class TelephonyManager { /** * Indicates the maximum size of the call composure picture. * - * Pictures sent via {@link #uploadCallComposerPicture(InputStream, Executor, OutcomeReceiver)} - * or {@link #uploadCallComposerPicture(Path, Executor, OutcomeReceiver)} must not exceed this - * size, or an error will be returned via the callback in those methods. + * Pictures sent via + * {@link #uploadCallComposerPicture(InputStream, String, Executor, OutcomeReceiver)} + * or {@link #uploadCallComposerPicture(Path, String, Executor, OutcomeReceiver)} must not + * exceed this size, or an error will be returned via the callback in those methods. * * @return Maximum file size in bytes. */ @@ -4310,6 +4311,15 @@ public class TelephonyManager { */ public static final int ERROR_IO_EXCEPTION = 5; + /** + * Indicates that the device is currently not connected to a network that's capable of + * reaching a carrier's RCS servers. + * + * Clients should prompt the user to remedy the issue by moving to an area with better + * signal, by connecting to a different network, or to retry at another time. + */ + public static final int ERROR_NETWORK_UNAVAILABLE = 6; + /** @hide */ @IntDef(prefix = {"ERROR_"}, value = { ERROR_UNKNOWN, @@ -4318,7 +4328,9 @@ public class TelephonyManager { ERROR_AUTHENTICATION_FAILED, ERROR_INPUT_CLOSED, ERROR_IO_EXCEPTION, + ERROR_NETWORK_UNAVAILABLE, }) + @Retention(RetentionPolicy.SOURCE) public @interface CallComposerError {} @@ -4355,14 +4367,16 @@ public class TelephonyManager { /** * Uploads a picture to the carrier network for use with call composer. * - * @see #uploadCallComposerPicture(InputStream, Executor, OutcomeReceiver) + * @see #uploadCallComposerPicture(InputStream, String, Executor, OutcomeReceiver) * @param pictureToUpload Path to a local file containing the picture to upload. + * @param contentType The MIME type of the picture you're uploading (e.g. image/jpeg) * @param executor The {@link Executor} on which the {@code pictureToUpload} file will be read * from disk, as well as on which {@code callback} will be called. * @param callback A callback called when the upload operation terminates, either in success * or in error. */ public void uploadCallComposerPicture(@NonNull Path pictureToUpload, + @NonNull String contentType, @CallbackExecutor @NonNull Executor executor, @NonNull OutcomeReceiver callback) { Objects.requireNonNull(pictureToUpload); @@ -4390,7 +4404,7 @@ public class TelephonyManager { } InputStream fileStream = Files.newInputStream(pictureToUpload); try { - uploadCallComposerPicture(fileStream, executor, + uploadCallComposerPicture(fileStream, contentType, executor, new OutcomeReceiver() { @Override public void onResult(ParcelUuid result) { @@ -4455,12 +4469,14 @@ public class TelephonyManager { * of {@link #getMaximumCallComposerPictureSize()}, the upload will be * aborted and the callback will be called with an exception containing * {@link CallComposerException#ERROR_FILE_TOO_LARGE}. + * @param contentType The MIME type of the picture you're uploading (e.g. image/jpeg) * @param executor The {@link Executor} on which the {@code pictureToUpload} stream will be * read, as well as on which the callback will be called. * @param callback A callback called when the upload operation terminates, either in success * or in error. */ public void uploadCallComposerPicture(@NonNull InputStream pictureToUpload, + @NonNull String contentType, @CallbackExecutor @NonNull Executor executor, @NonNull OutcomeReceiver callback) { Objects.requireNonNull(pictureToUpload); @@ -4488,7 +4504,7 @@ public class TelephonyManager { try { telephony.uploadCallComposerPicture(getSubId(), mContext.getOpPackageName(), - readFd, new ResultReceiver(null) { + contentType, readFd, new ResultReceiver(null) { @Override protected void onReceiveResult(int resultCode, Bundle result) { if (resultCode != CallComposerException.SUCCESS) { diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 83fb38be820d1..46c9dde6023ec 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -1262,7 +1262,7 @@ interface ITelephony { int getRadioAccessFamily(in int phoneId, String callingPackage); void uploadCallComposerPicture(int subscriptionId, String callingPackage, - in ParcelFileDescriptor fd, in ResultReceiver callback); + String contentType, in ParcelFileDescriptor fd, in ResultReceiver callback); /** * Enables or disables video calling.