Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | package android.hardware.location; |
| 17 | |
| 18 | import android.annotation.SystemApi; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 19 | import android.content.Context; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 20 | import android.os.Handler; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 21 | import android.os.IBinder; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 22 | import android.os.Looper; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 23 | import android.os.RemoteException; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 24 | import android.os.ServiceManager; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 25 | import android.util.Log; |
| 26 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 27 | /** |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 28 | * A class that exposes the Context hubs on a device to applications. |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 29 | * |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 30 | * Please note that this class is not expected to be used by unbundled applications. Also, calling |
| 31 | * applications are expected to have LOCATION_HARDWARE permissions to use this class. |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 32 | * |
| 33 | * @hide |
| 34 | */ |
| 35 | @SystemApi |
| 36 | public final class ContextHubManager { |
| 37 | |
| 38 | private static final String TAG = "ContextHubManager"; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 39 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 40 | private final Looper mMainLooper; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 41 | private IContextHubService mContextHubService; |
Greg Kaiser | 6ba60e6 | 2016-03-18 10:08:39 -0700 | [diff] [blame] | 42 | private Callback mCallback; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 43 | private Handler mCallbackHandler; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 44 | |
| 45 | /** |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 46 | * A special context hub identifier meaning any possible hub on the system. |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 47 | */ |
| 48 | public static final int ANY_HUB = -1; |
| 49 | /** |
| 50 | * A constant denoting a message to load a a Nano App |
| 51 | */ |
| 52 | public static final int MSG_LOAD_NANO_APP = 1; |
| 53 | /** |
| 54 | * A constant denoting a message to unload a a Nano App |
| 55 | */ |
| 56 | public static final int MSG_UNLOAD_NANO_APP = 2; |
| 57 | /** |
| 58 | * A constant denoting a message to send a message |
| 59 | */ |
| 60 | public static final int MSG_DATA_SEND = 3; |
| 61 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 62 | /** |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 63 | * An interface to receive asynchronous communication from the context hub. |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 64 | */ |
Greg Kaiser | 6ba60e6 | 2016-03-18 10:08:39 -0700 | [diff] [blame] | 65 | public abstract static class Callback { |
| 66 | protected Callback() {} |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 67 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 68 | /** |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 69 | * Callback function called on message receipt from context hub. |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 70 | * |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 71 | * @param hubHandle Handle (system-wide unique identifier) of the hub of the message. |
| 72 | * @param nanoAppHandle Handle (unique identifier) for the app that sent the message. |
| 73 | * @param message The context hub message. |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 74 | * |
| 75 | * @see ContextHubMessage |
| 76 | */ |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 77 | public abstract void onMessageReceipt( |
| 78 | int hubHandle, |
| 79 | int nanoAppHandle, |
| 80 | ContextHubMessage message); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 81 | } |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * Get a handle to all the context hubs in the system |
| 85 | * @return array of context hub handles |
| 86 | */ |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 87 | public int[] getContextHubHandles() { |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 88 | int[] retVal = null; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 89 | try { |
| 90 | retVal = getBinder().getContextHubHandles(); |
| 91 | } catch (RemoteException e) { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 92 | Log.e(TAG, "Could not fetch context hub handles : " + e); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 93 | } |
| 94 | return retVal; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Get more information about a specific hub. |
| 99 | * |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 100 | * @param hubHandle Handle (system-wide unique identifier) of a context hub. |
| 101 | * @return ContextHubInfo Information about the requested context hub. |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 102 | * |
| 103 | * @see ContextHubInfo |
| 104 | */ |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 105 | public ContextHubInfo getContextHubInfo(int hubHandle) { |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 106 | ContextHubInfo retVal = null; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 107 | try { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 108 | retVal = getBinder().getContextHubInfo(hubHandle); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 109 | } catch (RemoteException e) { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 110 | Log.e(TAG, "Could not fetch context hub info :" + e); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 113 | return retVal; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 117 | * Load a nano app on a specified context hub. |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 118 | * |
| 119 | * @param hubHandle handle of context hub to load the app on. |
| 120 | * @param app the nanoApp to load on the hub |
| 121 | * |
| 122 | * @return int nanoAppInstance of the loaded nanoApp on success, |
| 123 | * -1 otherwise |
| 124 | * |
| 125 | * @see NanoApp |
| 126 | */ |
| 127 | public int loadNanoApp(int hubHandle, NanoApp app) { |
| 128 | int retVal = -1; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 129 | if (app == null) { |
| 130 | return retVal; |
| 131 | } |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 132 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 133 | try { |
| 134 | retVal = getBinder().loadNanoApp(hubHandle, app); |
| 135 | } catch (RemoteException e) { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 136 | Log.e(TAG, "Could not fetch load nanoApp :" + e); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | return retVal; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Unload a specified nanoApp |
| 144 | * |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 145 | * @param nanoAppHandle handle of the nanoApp to load |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 146 | * |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 147 | * @return int 0 on success, -1 otherwise |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 148 | */ |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 149 | public int unloadNanoApp(int nanoAppHandle) { |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 150 | int retVal = -1; |
| 151 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 152 | try { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 153 | retVal = getBinder().unloadNanoApp(nanoAppHandle); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 154 | } catch (RemoteException e) { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 155 | Log.e(TAG, "Could not fetch unload nanoApp :" + e); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | return retVal; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * get information about the nano app instance |
| 163 | * |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 164 | * @param nanoAppHandle handle of the nanoAppInstance |
| 165 | * @return NanoAppInstanceInfo Information about the nano app instance. |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 166 | * |
| 167 | * @see NanoAppInstanceInfo |
| 168 | */ |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 169 | public NanoAppInstanceInfo getNanoAppInstanceInfo(int nanoAppHandle) { |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 170 | NanoAppInstanceInfo retVal = null; |
| 171 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 172 | try { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 173 | retVal = getBinder().getNanoAppInstanceInfo(nanoAppHandle); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 174 | } catch (RemoteException e) { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 175 | Log.e(TAG, "Could not fetch nanoApp info :" + e); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | return retVal; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Find a specified nano app on the system |
| 183 | * |
| 184 | * @param hubHandle handle of hub to search for nano app |
| 185 | * @param filter filter specifying the search criteria for app |
| 186 | * |
| 187 | * @see NanoAppFilter |
| 188 | * |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 189 | * @return int[] Array of handles to any found nano apps |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 190 | */ |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 191 | public int[] findNanoAppOnHub(int hubHandle, NanoAppFilter filter) { |
| 192 | int[] retVal = null; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 193 | try { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 194 | retVal = getBinder().findNanoAppOnHub(hubHandle, filter); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 195 | } catch (RemoteException e) { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 196 | Log.e(TAG, "Could not query nanoApp instance :" + e); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 197 | } |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 198 | return retVal; |
| 199 | } |
| 200 | |
| 201 | /** |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 202 | * Send a message to a specific nano app instance on a context hub. |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 203 | * |
| 204 | * @param hubHandle handle of the hub to send the message to |
| 205 | * @param nanoAppHandle handle of the nano app to send to |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 206 | * @param message Message to be sent |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 207 | * |
| 208 | * @see ContextHubMessage |
| 209 | * |
| 210 | * @return int 0 on success, -1 otherwise |
| 211 | */ |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 212 | public int sendMessage(int hubHandle, int nanoAppHandle, ContextHubMessage message) { |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 213 | int retVal = -1; |
| 214 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 215 | try { |
| 216 | retVal = getBinder().sendMessage(hubHandle, nanoAppHandle, message); |
| 217 | } catch (RemoteException e) { |
| 218 | Log.e(TAG, "Could not fetch send message :" + e.toString()); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | return retVal; |
| 222 | } |
| 223 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 224 | /** |
| 225 | * Set a callback to receive messages from the context hub |
| 226 | * |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 227 | * @param callback Callback object |
| 228 | * |
Greg Kaiser | 6ba60e6 | 2016-03-18 10:08:39 -0700 | [diff] [blame] | 229 | * @see Callback |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 230 | * |
| 231 | * @return int 0 on success, -1 otherwise |
| 232 | */ |
Greg Kaiser | 6ba60e6 | 2016-03-18 10:08:39 -0700 | [diff] [blame] | 233 | public int registerCallback(Callback callback) { |
| 234 | return registerCallback(callback, null); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Set a callback to receive messages from the context hub |
| 239 | * |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 240 | * @param callback Callback object |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 241 | * @param handler Handler object |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 242 | * |
Greg Kaiser | 6ba60e6 | 2016-03-18 10:08:39 -0700 | [diff] [blame] | 243 | * @see Callback |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 244 | * |
| 245 | * @return int 0 on success, -1 otherwise |
| 246 | */ |
Greg Kaiser | 6ba60e6 | 2016-03-18 10:08:39 -0700 | [diff] [blame] | 247 | public int registerCallback(Callback callback, Handler handler) { |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 248 | synchronized(this) { |
| 249 | if (mCallback != null) { |
| 250 | Log.e(TAG, "Max number of callbacks reached!"); |
| 251 | return -1; |
| 252 | } |
| 253 | mCallback = callback; |
| 254 | mCallbackHandler = handler; |
| 255 | } |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | /** |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 260 | * Unregister a callback for receive messages from the context hub. |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 261 | * |
Greg Kaiser | 6ba60e6 | 2016-03-18 10:08:39 -0700 | [diff] [blame] | 262 | * @see Callback |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 263 | * |
| 264 | * @param callback method to deregister |
| 265 | * |
| 266 | * @return int 0 on success, -1 otherwise |
| 267 | */ |
Greg Kaiser | 6ba60e6 | 2016-03-18 10:08:39 -0700 | [diff] [blame] | 268 | public int unregisterCallback(Callback callback) { |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 269 | synchronized(this) { |
| 270 | if (callback != mCallback) { |
| 271 | Log.e(TAG, "Cannot recognize callback!"); |
| 272 | return -1; |
| 273 | } |
| 274 | |
| 275 | mCallback = null; |
| 276 | mCallbackHandler = null; |
| 277 | } |
| 278 | return 0; |
| 279 | } |
| 280 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 281 | private IContextHubCallback.Stub mClientCallback = new IContextHubCallback.Stub() { |
| 282 | @Override |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 283 | public void onMessageReceipt(final int hubId, final int nanoAppId, |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 284 | final ContextHubMessage message) { |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 285 | if (mCallback != null) { |
| 286 | synchronized(this) { |
Greg Kaiser | 6ba60e6 | 2016-03-18 10:08:39 -0700 | [diff] [blame] | 287 | final Callback callback = mCallback; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 288 | Handler handler = mCallbackHandler == null ? |
| 289 | new Handler(mMainLooper) : mCallbackHandler; |
| 290 | handler.post(new Runnable() { |
| 291 | @Override |
| 292 | public void run() { |
| 293 | callback.onMessageReceipt(hubId, nanoAppId, message); |
| 294 | } |
| 295 | }); |
| 296 | } |
| 297 | } else { |
| 298 | Log.d(TAG, "Context hub manager client callback is NULL"); |
| 299 | } |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 300 | } |
| 301 | }; |
| 302 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 303 | /** @hide */ |
| 304 | public ContextHubManager(Context context, Looper mainLooper) { |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 305 | mMainLooper = mainLooper; |
| 306 | |
| 307 | IBinder b = ServiceManager.getService(ContextHubService.CONTEXTHUB_SERVICE); |
| 308 | if (b != null) { |
| 309 | mContextHubService = IContextHubService.Stub.asInterface(b); |
| 310 | |
| 311 | try { |
| 312 | getBinder().registerCallback(mClientCallback); |
| 313 | } catch (RemoteException e) { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 314 | Log.e(TAG, "Could not register callback:" + e); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | } else { |
| 318 | Log.d(TAG, "failed to getService"); |
| 319 | } |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 322 | private IContextHubService getBinder() throws RemoteException { |
| 323 | if (mContextHubService == null) { |
| 324 | throw new RemoteException("Service not connected."); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 325 | } |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 326 | return mContextHubService; |
| 327 | } |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 328 | } |