14f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu/* 24f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * Copyright (C) 2017 The Android Open Source Project 34f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * 44f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * Licensed under the Apache License, Version 2.0 (the "License"); 54f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * you may not use this file except in compliance with the License. 64f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * You may obtain a copy of the License at 74f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * 84f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * http://www.apache.org/licenses/LICENSE-2.0 94f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * 104f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * Unless required by applicable law or agreed to in writing, software 114f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * distributed under the License is distributed on an "AS IS" BASIS, 124f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * See the License for the specific language governing permissions and 144f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu * limitations under the License 154f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu */ 164f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu 174f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liupackage android.telephony.mbms; 184f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu 194f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liuimport android.os.Handler; 204f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liuimport android.os.RemoteException; 214f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu 224f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu/** @hide */ 234f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liupublic class InternalStreamingServiceCallback extends IStreamingServiceCallback.Stub { 244f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu private final StreamingServiceCallback mAppCallback; 254f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu private final Handler mHandler; 26a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu private volatile boolean mIsStopped = false; 274f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu 284f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu public InternalStreamingServiceCallback(StreamingServiceCallback appCallback, Handler handler) { 294f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mAppCallback = appCallback; 304f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mHandler = handler; 314f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu } 324f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu 334f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu @Override 341a5b1304687d591cd5f913e50e8636d139ec1a25Hall Liu public void onError(final int errorCode, final String message) throws RemoteException { 35a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu if (mIsStopped) { 36a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu return; 37a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu } 38a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu 394f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mHandler.post(new Runnable() { 404f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu @Override 414f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu public void run() { 424f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mAppCallback.onError(errorCode, message); 434f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu } 444f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu }); 454f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu } 464f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu 474f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu @Override 481a5b1304687d591cd5f913e50e8636d139ec1a25Hall Liu public void onStreamStateUpdated(final int state, final int reason) throws RemoteException { 49a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu if (mIsStopped) { 50a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu return; 51a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu } 52a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu 534f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mHandler.post(new Runnable() { 544f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu @Override 554f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu public void run() { 564f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mAppCallback.onStreamStateUpdated(state, reason); 574f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu } 584f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu }); 594f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu } 604f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu 614f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu @Override 62a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu public void onMediaDescriptionUpdated() throws RemoteException { 63a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu if (mIsStopped) { 64a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu return; 65a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu } 66a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu 674f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mHandler.post(new Runnable() { 684f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu @Override 694f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu public void run() { 704f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mAppCallback.onMediaDescriptionUpdated(); 714f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu } 724f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu }); 734f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu } 744f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu 754f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu @Override 761a5b1304687d591cd5f913e50e8636d139ec1a25Hall Liu public void onBroadcastSignalStrengthUpdated(final int signalStrength) throws RemoteException { 77a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu if (mIsStopped) { 78a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu return; 79a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu } 80a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu 814f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mHandler.post(new Runnable() { 824f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu @Override 834f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu public void run() { 844f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mAppCallback.onBroadcastSignalStrengthUpdated(signalStrength); 854f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu } 864f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu }); 874f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu } 884f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu 894f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu @Override 901a5b1304687d591cd5f913e50e8636d139ec1a25Hall Liu public void onStreamMethodUpdated(final int methodType) throws RemoteException { 91a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu if (mIsStopped) { 92a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu return; 93a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu } 94a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu 954f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mHandler.post(new Runnable() { 964f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu @Override 974f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu public void run() { 984f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu mAppCallback.onStreamMethodUpdated(methodType); 994f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu } 1004f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu }); 1014f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu } 102a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu 103a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu public void stop() { 104a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu mIsStopped = true; 105a96478a9b7d7be9c646a5679b817ea2fae27d704Hall Liu } 1064f306dedc58c24b4e16c2418f26961d06d9a2d1aHall Liu} 107