• 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.Context;
19 import com.google.android.enterprise.connectedapps.exceptions.UnavailableProfileException;
20 
21 /** A {@link ProfileConnector} is used to manage the connection between profiles. */
22 public interface ProfileConnector {
23   /**
24    * Start trying to connect to the other profile and start manually managing the connection.
25    *
26    * <p>This will mean that the connection will not be dropped automatically to save resources.
27    *
28    * <p>Must be called before interacting with synchronous cross-profile methods.
29    *
30    * <p>If the connection can not be made, then no errors will be thrown and connections will
31    * re-attempted indefinitely.
32    *
33    * @see #connect()
34    * @see #stopManualConnectionManagement()
35    */
startConnecting()36   void startConnecting();
37 
38   /**
39    * Attempt to connect to the other profile and start manually managing the connection.
40    *
41    * <p>This will mean that the connection will not be dropped automatically to save resources.
42    *
43    * <p>Must be called before interacting with synchronous cross-profile methods.
44    *
45    * <p>This must not be called from the main thread.
46    *
47    * @see #startConnecting()
48    * @see #stopManualConnectionManagement()
49    * @throws UnavailableProfileException If the connection cannot be made.
50    */
connect()51   void connect() throws UnavailableProfileException;
52 
53   /**
54    * Stop manual connection management.
55    *
56    * <p>This can be called after {@link #startConnecting()} to return connection management
57    * responsibilities to the SDK.
58    *
59    * <p>You should not make any synchronous cross-profile calls after calling this method.
60    */
stopManualConnectionManagement()61   void stopManualConnectionManagement();
62 
63   /**
64    * Return the {@link CrossProfileSender} being used for this connection.
65    *
66    * <p>This API should only be used by generated code.
67    */
crossProfileSender()68   CrossProfileSender crossProfileSender();
69 
70   /**
71    * Register a listener to be called when a profile is connected or disconnected.
72    *
73    * <p>{@link #isConnected()} can be called to check if a connection is established.
74    *
75    * @see #unregisterConnectionListener(ConnectionListener)
76    */
registerConnectionListener(ConnectionListener listener)77   void registerConnectionListener(ConnectionListener listener);
78 
79   /**
80    * Unregister a listener registered using {@link #registerConnectionListener(
81    * ConnectionListener)}.
82    */
unregisterConnectionListener(ConnectionListener listener)83   void unregisterConnectionListener(ConnectionListener listener);
84 
85   /**
86    * Register a listener to be called when a profile becomes available or unavailable.
87    *
88    * <p>{@link #isAvailable()} can be called to check if a profile is available.
89    *
90    * @see #unregisterAvailabilityListener(AvailabilityListener)
91    */
registerAvailabilityListener(AvailabilityListener listener)92   void registerAvailabilityListener(AvailabilityListener listener);
93 
94   /**
95    * Unregister a listener registered using {@link #registerAvailabilityListener(
96    * AvailabilityListener)}.
97    */
unregisterAvailabilityListener(AvailabilityListener listener)98   void unregisterAvailabilityListener(AvailabilityListener listener);
99 
100   /**
101    * Return true if there is another profile which could be connected to.
102    *
103    * <p>If this returns true, then asynchronous calls should succeed. Synchronous calls will only
104    * succeed if {@link #isConnected()} also returns true.
105    */
isAvailable()106   boolean isAvailable();
107 
108   /**
109    * Return true if there is another profile connected.
110    *
111    * <p>If this returns true, then synchronous calls should succeed unless they are disconnected
112    * before the call completes.
113    */
isConnected()114   boolean isConnected();
115 
116   /** Return an instance of {@link ConnectedAppsUtils} for dealing with this connection. */
utils()117   ConnectedAppsUtils utils();
118 
permissions()119   Permissions permissions();
120 
121   /** Return the application context used by this connector. */
applicationContext()122   Context applicationContext();
123 
124   /**
125    * Returns true if this connection is being managed manually.
126    *
127    * <p>Use {@link #startConnecting()} to begin manual connection management, and {@link
128    * #stopManualConnectionManagement()} to end it.
129    */
isManuallyManagingConnection()130   boolean isManuallyManagingConnection();
131 }
132