Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff6f9862 authored by Hall Liu's avatar Hall Liu
Browse files

Prepare EMBMS apis for un-hiding

Add more documentation to places that were lacking, bring more things in
line with the API guidelines

Change-Id: I809af5534ab425ee7e1e2dc8695d5b7e649dd22d
Test: testapps
Bug: 30981736
parent 11ae580f
Loading
Loading
Loading
Loading
+76 −14
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SystemApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -49,41 +50,82 @@ import java.util.concurrent.atomic.AtomicReference;

import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;

/** @hide */
/**
 * This class provides functionality for file download over MBMS.
 * @hide
 */
public class MbmsDownloadManager {
    private static final String LOG_TAG = MbmsDownloadManager.class.getSimpleName();

    /** @hide */
    // TODO: systemapi
    /**
     * Service action which must be handled by the middleware implementing the MBMS file download
     * interface.
     * @hide
     */
    @SystemApi
    @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
    public static final String MBMS_DOWNLOAD_SERVICE_ACTION =
            "android.telephony.action.EmbmsDownload";

    /**
     * Integer extra indicating the result code of the download. One of
     * {@link #RESULT_SUCCESSFUL}, {@link #RESULT_EXPIRED}, or {@link #RESULT_CANCELLED}.
     * Integer extra that Android will attach to the intent supplied via
     * {@link android.telephony.mbms.DownloadRequest.Builder#setAppIntent(Intent)}
     * Indicates the result code of the download. One of
     * {@link #RESULT_SUCCESSFUL}, {@link #RESULT_EXPIRED}, {@link #RESULT_CANCELLED}, or
     * {@link #RESULT_IO_ERROR}.
     *
     * This extra may also be used by the middleware when it is sending intents to the app.
     */
    public static final String EXTRA_RESULT = "android.telephony.mbms.extra.RESULT";

    /**
     * Extra containing the {@link android.telephony.mbms.FileInfo} for which the download result
     * is for. Must not be null.
     * {@link FileInfo} extra that Android will attach to the intent supplied via
     * {@link android.telephony.mbms.DownloadRequest.Builder#setAppIntent(Intent)}
     * Indicates the file for which the download result is for. Never null.
     *
     * This extra may also be used by the middleware when it is sending intents to the app.
     */
    public static final String EXTRA_FILE_INFO = "android.telephony.mbms.extra.FILE_INFO";

    /**
     * Extra containing a single {@link Uri} indicating the location of the successfully
     * downloaded file. Set on the intent provided via
     * {@link android.telephony.mbms.DownloadRequest.Builder#setAppIntent(Intent)}.
     * Will always be set to a non-null value if {@link #EXTRA_RESULT} is set to
     * {@link Uri} extra that Android will attach to the intent supplied via
     * {@link android.telephony.mbms.DownloadRequest.Builder#setAppIntent(Intent)}
     * Indicates the location of the successfully
     * downloaded file. Will always be set to a non-null value if {@link #EXTRA_RESULT} is set to
     * {@link #RESULT_SUCCESSFUL}.
     */
    public static final String EXTRA_COMPLETED_FILE_URI =
            "android.telephony.mbms.extra.COMPLETED_FILE_URI";

    /**
     * The default directory name for all MBMS temp files. If you call
     * {@link #download(DownloadRequest, DownloadProgressListener)} without first calling
     * {@link #setTempFileRootDirectory(File)}, this directory will be created for you under the
     * path returned by {@link Context#getFilesDir()}.
     */
    public static final String DEFAULT_TOP_LEVEL_TEMP_DIRECTORY = "androidMbmsTempFileRoot";

    /**
     * Indicates that the download was successful.
     */
    public static final int RESULT_SUCCESSFUL = 1;

    /**
     * Indicates that the download was cancelled via {@link #cancelDownload(DownloadRequest)}.
     */
    public static final int RESULT_CANCELLED = 2;

    /**
     * Indicates that the download will not be completed due to the expiration of its download
     * window on the carrier's network.
     */
    public static final int RESULT_EXPIRED = 3;

    /**
     * Indicates that the download will not be completed due to an I/O error incurred while
     * writing to temp files. This commonly indicates that the device is out of storage space,
     * but may indicate other conditions as well (such as an SD card being removed).
     */
    public static final int RESULT_IO_ERROR = 4;
    // TODO - more results!

@@ -93,10 +135,30 @@ public class MbmsDownloadManager {
            STATUS_PENDING_REPAIR, STATUS_PENDING_DOWNLOAD_WINDOW})
    public @interface DownloadStatus {}

    /**
     * Indicates that the middleware has no information on the file.
     */
    public static final int STATUS_UNKNOWN = 0;

    /**
     * Indicates that the file is actively downloading.
     */
    public static final int STATUS_ACTIVELY_DOWNLOADING = 1;

    /**
     * TODO: I don't know...
     */
    public static final int STATUS_PENDING_DOWNLOAD = 2;

    /**
     * Indicates that the file is being repaired after the download being interrupted.
     */
    public static final int STATUS_PENDING_REPAIR = 3;

    /**
     * Indicates that the file is waiting to download because its download window has not yet
     * started.
     */
    public static final int STATUS_PENDING_DOWNLOAD_WINDOW = 4;

    private static AtomicBoolean sIsInitialized = new AtomicBoolean(false);
@@ -269,7 +331,7 @@ public class MbmsDownloadManager {
     * If this method is not called at least once before calling
     * {@link #download(DownloadRequest, DownloadProgressListener)}, the framework
     * will default to a directory formed by the concatenation of the app's files directory and
     * {@link android.telephony.mbms.MbmsTempFileProvider#DEFAULT_TOP_LEVEL_TEMP_DIRECTORY}.
     * {@link MbmsDownloadManager#DEFAULT_TOP_LEVEL_TEMP_DIRECTORY}.
     *
     * Before calling this method, the app must cancel all of its pending
     * {@link DownloadRequest}s via {@link #cancelDownload(DownloadRequest)}. If this is not done,
@@ -347,7 +409,7 @@ public class MbmsDownloadManager {
     *
     * If {@link #setTempFileRootDirectory(File)} has not called after the app has been installed,
     * this method will create a directory at the default location defined at
     * {@link MbmsTempFileProvider#DEFAULT_TOP_LEVEL_TEMP_DIRECTORY} and store that as the temp
     * {@link MbmsDownloadManager#DEFAULT_TOP_LEVEL_TEMP_DIRECTORY} and store that as the temp
     * file root directory.
     *
     * Asynchronous errors through the listener include any of the errors
@@ -368,7 +430,7 @@ public class MbmsDownloadManager {
                MbmsTempFileProvider.TEMP_FILE_ROOT_PREF_FILE_NAME, 0);
        if (prefs.getString(MbmsTempFileProvider.TEMP_FILE_ROOT_PREF_NAME, null) == null) {
            File tempRootDirectory = new File(mContext.getFilesDir(),
                    MbmsTempFileProvider.DEFAULT_TOP_LEVEL_TEMP_DIRECTORY);
                    DEFAULT_TOP_LEVEL_TEMP_DIRECTORY);
            tempRootDirectory.mkdirs();
            setTempFileRootDirectory(tempRootDirectory);
        }
+3 −1
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ package android.telephony.mbms;
import android.os.RemoteException;

/**
 * A optional listener class used by download clients to track progress.
 * A optional listener class used by download clients to track progress. Apps should extend this
 * class and pass an instance into
 * {@link android.telephony.MbmsDownloadManager#download(DownloadRequest, DownloadProgressListener)}
 * @hide
 */
public class DownloadProgressListener extends IDownloadProgressListener.Stub {
+7 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.telephony.mbms;

import android.annotation.SystemApi;
import android.content.Intent;
import android.net.Uri;
import android.os.Parcel;
@@ -37,7 +38,9 @@ import java.security.NoSuchAlgorithmException;
import java.util.Objects;

/**
 * A Parcelable class describing a pending Cell-Broadcast download request
 * Describes a request to download files over cell-broadcast. Instances of this class should be
 * created by the app when requesting a download, and instances of this class will be passed back
 * to the app when the middleware updates the status of the download.
 * @hide
 */
public class DownloadRequest implements Parcelable {
@@ -91,8 +94,8 @@ public class DownloadRequest implements Parcelable {
        /**
         * Set the service ID for the download request. For use by the middleware only.
         * @hide
         * TODO: systemapi
         */
        //@SystemApi
        public Builder setServiceId(String serviceId) {
            fileServiceId = serviceId;
            return this;
@@ -159,9 +162,9 @@ public class DownloadRequest implements Parcelable {
         * @param data A byte array, the contents of which should have been originally obtained
         *             from {@link DownloadRequest#getOpaqueData()}.
         * @return
         * TODO: systemapi
         * @hide
         */
        //@SystemApi
        public Builder setOpaqueData(byte[] data) {
            try {
                ObjectInputStream stream = new ObjectInputStream(new ByteArrayInputStream(data));
@@ -287,8 +290,8 @@ public class DownloadRequest implements Parcelable {
     * {@link Builder#setOpaqueData(byte[])}.
     * @return A byte array of opaque data to persist.
     * @hide
     * TODO: systemapi
     */
    //@SystemApi
    public byte[] getOpaqueData() {
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+10 −10
Original line number Diff line number Diff line
@@ -16,26 +16,19 @@

package android.telephony.mbms;

import android.annotation.SystemApi;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * A Parcelable class Cell-Broadcast downloadable file information.
 * Describes a single file that is available over MBMS.
 * @hide
 */
public class FileInfo implements Parcelable {

    /**
     * The URI into the carriers infrastructure which points to this file.
     * This is used internally but is also one of the few pieces of data about the content that is
     * exposed and may be needed for disambiguation by the application.
     */
    private final Uri uri;

    /**
     * The mime type of the content.
     */
    private final String mimeType;

    public static final Parcelable.Creator<FileInfo> CREATOR =
@@ -53,8 +46,8 @@ public class FileInfo implements Parcelable {

    /**
     * @hide
     * TODO: systemapi
     */
    //@SystemApi
    public FileInfo(Uri uri, String mimeType) {
        this.uri = uri;
        this.mimeType = mimeType;
@@ -76,10 +69,17 @@ public class FileInfo implements Parcelable {
        return 0;
    }

    /**
     * @return The URI in the carrier's infrastructure which points to this file. Apps should
     * negotiate the contents of this URI separately with the carrier.
     */
    public Uri getUri() {
        return uri;
    }

    /**
     * @return The MIME type of the file.
     */
    public String getMimeType() {
        return mimeType;
    }
+10 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.telephony.mbms;

import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

@@ -26,13 +27,15 @@ import java.util.Locale;
import java.util.Map;

/**
 * A Parcelable class Cell-Broadcast downloadable file information.
 * Describes a file service available from the carrier from which files can be downloaded via
 * cell-broadcast.
 * @hide
 */
public class FileServiceInfo extends ServiceInfo implements Parcelable {
    private final List<FileInfo> files;

    /** @hide TODO: systemapi */
    /** @hide */
    @SystemApi
    public FileServiceInfo(Map<Locale, String> newNames, String newClassName,
            List<Locale> newLocales, String newServiceId, Date start, Date end,
            List<FileInfo> newFiles) {
@@ -70,8 +73,12 @@ public class FileServiceInfo extends ServiceInfo implements Parcelable {
        return 0;
    }

    /**
     * @return A list of files available from this service. Note that this list may not be
     * exhaustive -- the middleware may not have information on all files that are available.
     * Consult the carrier for an authoritative and exhaustive list.
     */
    public List<FileInfo> getFiles() {
        return files;
    }

}
Loading