• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    *
36    * <p>For certain devices, despite the initial binding failing, calling unbindService() will throw
37    * an IllegalArgumentException. This is a known issue with certain devices and we should not
38    * crash. See b/353372299 for context.
39    */
tryBind( Context context, ComponentName bindToService, ServiceConnection connection, AvailabilityRestrictions availabilityRestrictions)40   boolean tryBind(
41       Context context,
42       ComponentName bindToService,
43       ServiceConnection connection,
44       AvailabilityRestrictions availabilityRestrictions)
45       throws MissingApiException, UnavailableProfileException, IllegalArgumentException;
46 
47   /**
48    * Return true if there is a profile available to bind to, while enforcing the passed in {@link
49    * AvailabilityRestrictions}.
50    *
51    * <p>This should not be called if {@link #hasPermissionToBind(Context)} returns {@code False}.
52    */
bindingIsPossible(Context context, AvailabilityRestrictions availabilityRestrictions)53   boolean bindingIsPossible(Context context, AvailabilityRestrictions availabilityRestrictions);
54 
55   /**
56    * Return true if the permissions required for {@link #tryBind(Context, ComponentName,
57    * ServiceConnection, AvailabilityRestrictions)} are granted.
58    */
hasPermissionToBind(Context context)59   boolean hasPermissionToBind(Context context);
60 }
61