Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014, 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 | |
| 17 | package com.android.telecomm; |
| 18 | |
| 19 | import android.content.ComponentName; |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 20 | import android.os.IBinder; |
| 21 | import android.os.RemoteException; |
Sailesh Nepal | a439e1b | 2014-03-11 18:19:58 -0700 | [diff] [blame^] | 22 | import android.telecomm.TelecommConstants; |
| 23 | |
| 24 | import com.android.internal.telecomm.ICallServiceLookupResponse; |
| 25 | import com.android.internal.telecomm.ICallServiceProvider; |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Wrapper for {@link ICallServiceProvider}s, handles binding to {@link ICallServiceProvider} and |
| 29 | * keeps track of when the object can safely be unbound. Other classes should not use |
| 30 | * {@link ICallServiceProvider} directly and instead should use this class to invoke methods of |
| 31 | * {@link ICallServiceProvider}. |
| 32 | * TODO(santoscordon): Keep track of when the service can be safely unbound. |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 33 | */ |
| 34 | public class CallServiceProviderWrapper extends ServiceBinder<ICallServiceProvider> { |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 35 | /** The actual service implementation. */ |
| 36 | private ICallServiceProvider mServiceInterface; |
| 37 | |
| 38 | /** |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 39 | * Creates a call-service provider for the specified component. |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 40 | * |
| 41 | * @param componentName The component name of the service to bind to. |
| 42 | * @param repository The call-service repository. |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 43 | */ |
Santos Cordon | 5c12c6e | 2014-02-13 14:35:31 -0800 | [diff] [blame] | 44 | public CallServiceProviderWrapper( |
| 45 | ComponentName componentName, CallServiceRepository repository) { |
| 46 | |
Sailesh Nepal | a439e1b | 2014-03-11 18:19:58 -0700 | [diff] [blame^] | 47 | super(TelecommConstants.ACTION_CALL_SERVICE_PROVIDER, componentName); |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 50 | /** |
| 51 | * See {@link ICallServiceProvider#lookupCallServices}. |
| 52 | */ |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 53 | public void lookupCallServices(ICallServiceLookupResponse response) { |
| 54 | try { |
| 55 | if (mServiceInterface == null) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 56 | Log.wtf(this, "lookupCallServices() invoked while the service is unbound."); |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 57 | } else { |
| 58 | mServiceInterface.lookupCallServices(response); |
| 59 | } |
| 60 | } catch (RemoteException e) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 61 | Log.e(this, e, "Failed to lookupCallServices."); |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 62 | } |
| 63 | } |
Ben Gilad | bb167cd | 2014-02-25 16:24:05 -0800 | [diff] [blame] | 64 | |
| 65 | /** {@inheritDoc} */ |
| 66 | @Override protected void setServiceInterface(IBinder binder) { |
| 67 | mServiceInterface = ICallServiceProvider.Stub.asInterface(binder); |
| 68 | } |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 69 | } |