1 /* 2 * Copyright 2021 Google LLC 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 * https://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 package com.google.android.enterprise.connectedapps; 17 18 import android.content.ComponentName; 19 import android.content.Context; 20 import android.content.ServiceConnection; 21 import com.google.android.enterprise.connectedapps.annotations.AvailabilityRestrictions; 22 import com.google.android.enterprise.connectedapps.exceptions.MissingApiException; 23 import com.google.android.enterprise.connectedapps.exceptions.UnavailableProfileException; 24 25 /** {@link ConnectionBinder} instances are used to establish bindings with other profiles. */ 26 public interface ConnectionBinder { 27 28 /** 29 * Try to bind to the given {@link ComponentName} with the given {@link ServiceConnection}. 30 * 31 * <p>{@link AvailabilityRestrictions} should be enforced. 32 * 33 * <p>This should not be called if {@link #hasPermissionToBind(Context)} returns {@code False} or 34 * {@link #bindingIsPossible(Context, AvailabilityRestrictions)} returns {@code False}. 35 */ tryBind( Context context, ComponentName bindToService, ServiceConnection connection, AvailabilityRestrictions availabilityRestrictions)36 boolean tryBind( 37 Context context, 38 ComponentName bindToService, 39 ServiceConnection connection, 40 AvailabilityRestrictions availabilityRestrictions) 41 throws MissingApiException, UnavailableProfileException; 42 43 /** 44 * Return true if there is a profile available to bind to, while enforcing the passed in {@link 45 * AvailabilityRestrictions}. 46 * 47 * <p>This should not be called if {@link #hasPermissionToBind(Context)} returns {@code False}. 48 */ bindingIsPossible(Context context, AvailabilityRestrictions availabilityRestrictions)49 boolean bindingIsPossible(Context context, AvailabilityRestrictions availabilityRestrictions); 50 51 /** 52 * Return true if the permissions required for {@link #tryBind(Context, ComponentName, 53 * ServiceConnection, AvailabilityRestrictions)} are granted. 54 */ hasPermissionToBind(Context context)55 boolean hasPermissionToBind(Context context); 56 } 57