1 /* 2 * Copyright 2018 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 androidx.browser.customtabs; 18 19 import android.content.ComponentName; 20 import android.content.ServiceConnection; 21 import android.os.IBinder; 22 import android.support.customtabs.ICustomTabsService; 23 24 /** 25 * Abstract {@link ServiceConnection} to use while binding to a {@link CustomTabsService}. Any 26 * client implementing this is responsible for handling changes related with the lifetime of the 27 * connection like rebinding on disconnect. 28 */ 29 public abstract class CustomTabsServiceConnection implements ServiceConnection { 30 31 @Override onServiceConnected(ComponentName name, IBinder service)32 public final void onServiceConnected(ComponentName name, IBinder service) { 33 onCustomTabsServiceConnected(name, new CustomTabsClient( 34 ICustomTabsService.Stub.asInterface(service), name) { 35 }); 36 } 37 38 /** 39 * Called when a connection to the {@link CustomTabsService} has been established. 40 * @param name The concrete component name of the service that has been connected. 41 * @param client {@link CustomTabsClient} that contains the {@link IBinder} with which the 42 * connection have been established. All further communication should be initiated 43 * using this client. 44 */ onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client)45 public abstract void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client); 46 } 47