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

Commit 4f306ded authored by Hall Liu's avatar Hall Liu
Browse files

Fix lint errors in the streaming API

Fix the errors that cropped up when trying to upload the unhide CL in
MR1.

Bug: 30981736
Test: manual, with testapps
Change-Id: If4a9a5533a235a8cc56762ab7a9e32ec89440f1d
parent 1169bc59
Loading
Loading
Loading
Loading
+49 −17
Original line number Diff line number Diff line
@@ -21,8 +21,12 @@ import android.annotation.SystemApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.ServiceConnection;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.telephony.mbms.InternalStreamingManagerCallback;
import android.telephony.mbms.InternalStreamingServiceCallback;
import android.telephony.mbms.MbmsException;
import android.telephony.mbms.MbmsStreamingManagerCallback;
import android.telephony.mbms.MbmsUtils;
@@ -55,17 +59,20 @@ public class MbmsStreamingManager {
            "android.telephony.action.EmbmsStreaming";

    private AtomicReference<IMbmsStreamingService> mService = new AtomicReference<>(null);
    private MbmsStreamingManagerCallback mCallbackToApp;
    private InternalStreamingManagerCallback mInternalCallback;

    private final Context mContext;
    private int mSubscriptionId = INVALID_SUBSCRIPTION_ID;

    /** @hide */
    private MbmsStreamingManager(Context context, MbmsStreamingManagerCallback callback,
                    int subscriptionId) {
                    int subscriptionId, Handler handler) {
        mContext = context;
        mCallbackToApp = callback;
        mSubscriptionId = subscriptionId;
        if (handler == null) {
            handler = new Handler(Looper.getMainLooper());
        }
        mInternalCallback = new InternalStreamingManagerCallback(callback, handler);
    }

    /**
@@ -79,23 +86,38 @@ public class MbmsStreamingManager {
     * @param callback A callback object on which you wish to receive results of asynchronous
     *                 operations.
     * @param subscriptionId The subscription ID to use.
     * @param handler The handler you wish to receive callbacks on. If null, callbacks will be
     *                processed on the main looper (in other words, the looper returned from
     *                {@link Looper#getMainLooper()}).
     */
    public static MbmsStreamingManager create(Context context,
            MbmsStreamingManagerCallback callback, int subscriptionId)
            MbmsStreamingManagerCallback callback, int subscriptionId, Handler handler)
            throws MbmsException {
        MbmsStreamingManager manager = new MbmsStreamingManager(context, callback, subscriptionId);
        MbmsStreamingManager manager = new MbmsStreamingManager(context, callback,
                subscriptionId, handler);
        manager.bindAndInitialize();
        return manager;
    }

    /**
     * Create a new MbmsStreamingManager using the system default data subscription ID.
     * See {@link #create(Context, MbmsStreamingManagerCallback, int)}.
     * See {@link #create(Context, MbmsStreamingManagerCallback, int, Handler)}.
     */
    public static MbmsStreamingManager create(Context context,
            MbmsStreamingManagerCallback callback, Handler handler)
            throws MbmsException {
        return create(context, callback, SubscriptionManager.getDefaultSubscriptionId(), handler);
    }

    /**
     * Create a new MbmsStreamingManager using the system default data subscription ID and
     * default {@link Handler}.
     * See {@link #create(Context, MbmsStreamingManagerCallback, int, Handler)}.
     */
    public static MbmsStreamingManager create(Context context,
            MbmsStreamingManagerCallback callback)
            throws MbmsException {
        return create(context, callback, SubscriptionManager.getDefaultSubscriptionId());
        return create(context, callback, SubscriptionManager.getDefaultSubscriptionId(), null);
    }

    /**
@@ -154,11 +176,11 @@ public class MbmsStreamingManager {
    }

    /**
     * Starts streaming a requested service, reporting status to the indicated listener.
     * Starts streaming a requested service, reporting status to the indicated callback.
     * Returns an object used to control that stream. The stream may not be ready for consumption
     * immediately upon return from this method -- wait until the streaming state has been
     * reported via
     * {@link android.telephony.mbms.StreamingServiceCallback#streamStateUpdated(int, int)}
     * {@link android.telephony.mbms.StreamingServiceCallback#onStreamStateUpdated(int, int)}
     *
     * May throw an
     * {@link MbmsException} containing any of the error codes in
@@ -168,24 +190,33 @@ public class MbmsStreamingManager {
     *
     * May also throw an {@link IllegalArgumentException} or an {@link IllegalStateException}
     *
     * Asynchronous errors through the listener include any of the errors in
     * Asynchronous errors through the callback include any of the errors in
     * {@link android.telephony.mbms.MbmsException.GeneralErrors} or
     * {@link android.telephony.mbms.MbmsException.StreamingErrors}.
     *
     * @param serviceInfo The information about the service to stream.
     * @param listener A listener that'll be called when something about the stream changes.
     * @param callback A callback that'll be called when something about the stream changes.
     * @param handler A handler that calls to {@code callback} should be called on. If null,
     *                defaults to the handler provided via
     *                {@link #create(Context, MbmsStreamingManagerCallback, int, Handler)}.
     * @return An instance of {@link StreamingService} through which the stream can be controlled.
     */
    public StreamingService startStreaming(StreamingServiceInfo serviceInfo,
            StreamingServiceCallback listener) throws MbmsException {
            StreamingServiceCallback callback, Handler handler) throws MbmsException {
        IMbmsStreamingService streamingService = mService.get();
        if (streamingService == null) {
            throw new MbmsException(MbmsException.ERROR_MIDDLEWARE_NOT_BOUND);
        }

        InternalStreamingServiceCallback serviceCallback = new InternalStreamingServiceCallback(
                callback, handler == null ? mInternalCallback.getHandler() : handler);

        StreamingService serviceForApp = new StreamingService(
                mSubscriptionId, streamingService, serviceInfo, serviceCallback);

        try {
            int returnCode = streamingService.startStreaming(
                    mSubscriptionId, serviceInfo.getServiceId(), listener);
                    mSubscriptionId, serviceInfo.getServiceId(), serviceCallback);
            if (returnCode != MbmsException.SUCCESS) {
                throw new MbmsException(returnCode);
            }
@@ -195,7 +226,7 @@ public class MbmsStreamingManager {
            throw new MbmsException(MbmsException.ERROR_MIDDLEWARE_LOST);
        }

        return new StreamingService(mSubscriptionId, streamingService, serviceInfo, listener);
        return serviceForApp;
    }

    private void bindAndInitialize() throws MbmsException {
@@ -207,14 +238,15 @@ public class MbmsStreamingManager {
                                IMbmsStreamingService.Stub.asInterface(service);
                        int result;
                        try {
                            result = streamingService.initialize(mCallbackToApp, mSubscriptionId);
                            result = streamingService.initialize(mInternalCallback,
                                    mSubscriptionId);
                        } catch (RemoteException e) {
                            Log.e(LOG_TAG, "Service died before initialization");
                            return;
                        } catch (RuntimeException e) {
                            Log.e(LOG_TAG, "Runtime exception during initialization");
                            try {
                                mCallbackToApp.error(
                                mInternalCallback.error(
                                        MbmsException.InitializationErrors
                                                .ERROR_UNABLE_TO_INITIALIZE,
                                        e.toString());
@@ -225,7 +257,7 @@ public class MbmsStreamingManager {
                        }
                        if (result != MbmsException.SUCCESS) {
                            try {
                                mCallbackToApp.error(
                                mInternalCallback.error(
                                        result, "Error returned during initialization");
                            } catch (RemoteException e) {
                                // ignore
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package android.telephony.mbms;

import android.os.Handler;
import android.os.RemoteException;
import android.telephony.mbms.IMbmsStreamingManagerCallback;
import android.telephony.mbms.MbmsStreamingManagerCallback;
import android.telephony.mbms.StreamingServiceInfo;

import java.util.List;

/** @hide */
public class InternalStreamingManagerCallback extends IMbmsStreamingManagerCallback.Stub {
    private final Handler mHandler;
    private final MbmsStreamingManagerCallback mAppCallback;

    public InternalStreamingManagerCallback(MbmsStreamingManagerCallback appCallback,
            Handler handler) {
        mAppCallback = appCallback;
        mHandler = handler;
    }

    @Override
    public void error(int errorCode, String message) throws RemoteException {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mAppCallback.onError(errorCode, message);
            }
        });
    }

    @Override
    public void streamingServicesUpdated(List<StreamingServiceInfo> services)
            throws RemoteException {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mAppCallback.onStreamingServicesUpdated(services);
            }
        });
    }

    @Override
    public void middlewareReady() throws RemoteException {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mAppCallback.onMiddlewareReady();
            }
        });
    }

    public Handler getHandler() {
        return mHandler;
    }
}
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package android.telephony.mbms;

import android.os.Handler;
import android.os.RemoteException;

/** @hide */
public class InternalStreamingServiceCallback extends IStreamingServiceCallback.Stub {
    private final StreamingServiceCallback mAppCallback;
    private final Handler mHandler;

    public InternalStreamingServiceCallback(StreamingServiceCallback appCallback, Handler handler) {
        mAppCallback = appCallback;
        mHandler = handler;
    }

    @Override
    public void error(int errorCode, String message) throws RemoteException {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mAppCallback.onError(errorCode, message);
            }
        });
    }

    @Override
    public void streamStateUpdated(int state, int reason) throws RemoteException {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mAppCallback.onStreamStateUpdated(state, reason);
            }
        });
    }

    @Override
    public void mediaDescriptionUpdated() throws RemoteException {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mAppCallback.onMediaDescriptionUpdated();
            }
        });
    }

    @Override
    public void broadcastSignalStrengthUpdated(int signalStrength) throws RemoteException {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mAppCallback.onBroadcastSignalStrengthUpdated(signalStrength);
            }
        });
    }

    @Override
    public void streamMethodUpdated(int methodType) throws RemoteException {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mAppCallback.onStreamMethodUpdated(methodType);
            }
        });
    }
}
+6 −2
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public class MbmsException extends Exception {
     * middleware. They are applicable to both streaming and file-download use-cases.
     */
    public static class InitializationErrors {
        private InitializationErrors() {}
        /**
         * Indicates that the app tried to create more than one instance each of
         * {@link android.telephony.MbmsStreamingManager} or
@@ -61,9 +62,10 @@ public class MbmsException extends Exception {
     * streaming and file-download.
     */
    public static class GeneralErrors {
        private GeneralErrors() {}
        /**
         * Indicates that the app attempted to perform an operation before receiving notification
         * that the middleware is ready via {@link MbmsStreamingManagerCallback#middlewareReady()}
         * that the middleware is ready via {@link MbmsStreamingManagerCallback#onMiddlewareReady()}
         * or TODO: link MbmsDownloadManagerCallback#middlewareReady
         */
        public static final int ERROR_MIDDLEWARE_NOT_YET_READY = 201;
@@ -97,6 +99,7 @@ public class MbmsException extends Exception {
     * Indicates the errors that are applicable only to the streaming use-case
     */
    public static class StreamingErrors {
        private StreamingErrors() {}
        /** Indicates that the middleware cannot start a stream due to too many ongoing streams */
        public static final int ERROR_CONCURRENT_SERVICE_LIMIT_REACHED = 301;

@@ -105,7 +108,8 @@ public class MbmsException extends Exception {

        /**
         * Indicates that the app called
         * {@link android.telephony.MbmsStreamingManager#startStreaming(StreamingServiceInfo, StreamingServiceCallback)}
         * {@link android.telephony.MbmsStreamingManager#startStreaming(
         * StreamingServiceInfo, StreamingServiceCallback, android.os.Handler)}
         * more than once for the same {@link StreamingServiceInfo}.
         */
        public static final int ERROR_DUPLICATE_START_STREAM = 303;
+4 −6
Original line number Diff line number Diff line
@@ -27,14 +27,14 @@ import java.util.List;
 * {@link android.telephony.MbmsStreamingManager#create(Context, MbmsStreamingManagerCallback)}.
 * @hide
 */
public class MbmsStreamingManagerCallback extends IMbmsStreamingManagerCallback.Stub {
public class MbmsStreamingManagerCallback {
    /**
     * Called by the middleware when it has detected an error condition. The possible error codes
     * are listed in {@link MbmsException}.
     * @param errorCode The error code.
     * @param message A human-readable message generated by the middleware for debugging purposes.
     */
    public void error(int errorCode, String message) throws RemoteException {
    public void onError(int errorCode, String message) {
        // default implementation empty
    }

@@ -50,8 +50,7 @@ public class MbmsStreamingManagerCallback extends IMbmsStreamingManagerCallback.
     * @param services a List of StreamingServiceInfos
     *
     */
    public void streamingServicesUpdated(List<StreamingServiceInfo> services)
            throws RemoteException {
    public void onStreamingServicesUpdated(List<StreamingServiceInfo> services) {
        // default implementation empty
    }

@@ -63,8 +62,7 @@ public class MbmsStreamingManagerCallback extends IMbmsStreamingManagerCallback.
     * being thrown with error code {@link MbmsException#ERROR_MIDDLEWARE_NOT_BOUND}
     * or {@link MbmsException.GeneralErrors#ERROR_MIDDLEWARE_NOT_YET_READY}
     */
    @Override
    public void middlewareReady() throws RemoteException {
    public void onMiddlewareReady() {
        // default implementation empty
    }
}
Loading