blob: 7638312de6ae536d260edd58949898d5e2bebf22 [file] [log] [blame]
Santos Cordon63aeb162014-02-10 09:20:40 -08001/*
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
17package com.android.telecomm;
18
19import android.content.ComponentName;
Santos Cordon63aeb162014-02-10 09:20:40 -080020import android.os.IBinder;
21import android.os.RemoteException;
22import android.telecomm.ICallServiceLookupResponse;
23import android.telecomm.ICallServiceProvider;
Santos Cordon63aeb162014-02-10 09:20:40 -080024
25/**
26 * Wrapper for {@link ICallServiceProvider}s, handles binding to {@link ICallServiceProvider} and
27 * keeps track of when the object can safely be unbound. Other classes should not use
28 * {@link ICallServiceProvider} directly and instead should use this class to invoke methods of
29 * {@link ICallServiceProvider}.
30 * TODO(santoscordon): Keep track of when the service can be safely unbound.
Santos Cordon63aeb162014-02-10 09:20:40 -080031 */
32public class CallServiceProviderWrapper extends ServiceBinder<ICallServiceProvider> {
33 /**
34 * The service action used to bind to ICallServiceProvider implementations.
35 * TODO(santoscordon): Move this to TelecommConstants.
36 */
37 static final String CALL_SERVICE_PROVIDER_ACTION = ICallServiceProvider.class.getName();
38
Santos Cordon63aeb162014-02-10 09:20:40 -080039 /** The actual service implementation. */
40 private ICallServiceProvider mServiceInterface;
41
42 /**
Santos Cordon63aeb162014-02-10 09:20:40 -080043 * Creates a call-service provider for the specified component.
Santos Cordonc195e362014-02-11 17:05:31 -080044 *
45 * @param componentName The component name of the service to bind to.
46 * @param repository The call-service repository.
Santos Cordon63aeb162014-02-10 09:20:40 -080047 */
Santos Cordon5c12c6e2014-02-13 14:35:31 -080048 public CallServiceProviderWrapper(
49 ComponentName componentName, CallServiceRepository repository) {
50
Santos Cordon63aeb162014-02-10 09:20:40 -080051 super(CALL_SERVICE_PROVIDER_ACTION, componentName);
Santos Cordon63aeb162014-02-10 09:20:40 -080052 }
53
Santos Cordonc195e362014-02-11 17:05:31 -080054 /**
55 * See {@link ICallServiceProvider#lookupCallServices}.
56 */
Santos Cordon63aeb162014-02-10 09:20:40 -080057 public void lookupCallServices(ICallServiceLookupResponse response) {
58 try {
59 if (mServiceInterface == null) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080060 Log.wtf(this, "lookupCallServices() invoked while the service is unbound.");
Santos Cordon63aeb162014-02-10 09:20:40 -080061 } else {
62 mServiceInterface.lookupCallServices(response);
63 }
64 } catch (RemoteException e) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080065 Log.e(this, e, "Failed to lookupCallServices.");
Santos Cordon63aeb162014-02-10 09:20:40 -080066 }
67 }
Ben Giladbb167cd2014-02-25 16:24:05 -080068
69 /** {@inheritDoc} */
70 @Override protected void setServiceInterface(IBinder binder) {
71 mServiceInterface = ICallServiceProvider.Stub.asInterface(binder);
72 }
Santos Cordon63aeb162014-02-10 09:20:40 -080073}