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 | |
Ashutosh Joshi | 420e45e | 2016-12-20 16:34:41 -0800 | [diff] [blame] | 17 | package com.android.server.location; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 18 | |
Arthur Ishiguro | 82ed3af | 2018-11-09 13:20:30 -0800 | [diff] [blame] | 19 | import android.app.PendingIntent; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 21 | import android.hardware.contexthub.V1_0.AsyncEventType; |
| 22 | import android.hardware.contexthub.V1_0.ContextHub; |
| 23 | import android.hardware.contexthub.V1_0.ContextHubMsg; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 24 | import android.hardware.contexthub.V1_0.HubAppInfo; |
| 25 | import android.hardware.contexthub.V1_0.IContexthub; |
| 26 | import android.hardware.contexthub.V1_0.IContexthubCallback; |
| 27 | import android.hardware.contexthub.V1_0.Result; |
| 28 | import android.hardware.contexthub.V1_0.TransactionResult; |
Ashutosh Joshi | 420e45e | 2016-12-20 16:34:41 -0800 | [diff] [blame] | 29 | import android.hardware.location.ContextHubInfo; |
Ashutosh Joshi | 420e45e | 2016-12-20 16:34:41 -0800 | [diff] [blame] | 30 | import android.hardware.location.ContextHubMessage; |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 31 | import android.hardware.location.ContextHubTransaction; |
Ashutosh Joshi | 420e45e | 2016-12-20 16:34:41 -0800 | [diff] [blame] | 32 | import android.hardware.location.IContextHubCallback; |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 33 | import android.hardware.location.IContextHubClient; |
| 34 | import android.hardware.location.IContextHubClientCallback; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 35 | import android.hardware.location.IContextHubService; |
| 36 | import android.hardware.location.IContextHubTransactionCallback; |
Ashutosh Joshi | 420e45e | 2016-12-20 16:34:41 -0800 | [diff] [blame] | 37 | import android.hardware.location.NanoApp; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 38 | import android.hardware.location.NanoAppBinary; |
| 39 | import android.hardware.location.NanoAppFilter; |
Ashutosh Joshi | 420e45e | 2016-12-20 16:34:41 -0800 | [diff] [blame] | 40 | import android.hardware.location.NanoAppInstanceInfo; |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 41 | import android.hardware.location.NanoAppMessage; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 42 | import android.hardware.location.NanoAppState; |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 43 | import android.os.RemoteCallbackList; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 44 | import android.os.RemoteException; |
| 45 | import android.util.Log; |
| 46 | |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 47 | import com.android.internal.util.DumpUtils; |
| 48 | |
Ashutosh Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 49 | import java.io.FileDescriptor; |
| 50 | import java.io.PrintWriter; |
Ashutosh Joshi | 19753cc | 2016-11-23 13:56:39 -0800 | [diff] [blame] | 51 | import java.nio.ByteBuffer; |
| 52 | import java.nio.ByteOrder; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 53 | import java.util.ArrayList; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 54 | import java.util.Collections; |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 55 | import java.util.HashMap; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 56 | import java.util.List; |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 57 | import java.util.Map; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 58 | import java.util.NoSuchElementException; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * @hide |
| 62 | */ |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 63 | public class ContextHubService extends IContextHubService.Stub { |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 64 | private static final String TAG = "ContextHubService"; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 65 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 66 | /* |
| 67 | * Constants for the type of transaction that is defined by ContextHubService. |
| 68 | * This is used to report the transaction callback to clients, and is different from |
| 69 | * ContextHubTransaction.Type. |
| 70 | */ |
| 71 | public static final int MSG_ENABLE_NANO_APP = 1; |
| 72 | public static final int MSG_DISABLE_NANO_APP = 2; |
| 73 | public static final int MSG_LOAD_NANO_APP = 3; |
Ashutosh Joshi | cafdee9 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 74 | public static final int MSG_UNLOAD_NANO_APP = 4; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 75 | public static final int MSG_QUERY_NANO_APPS = 5; |
| 76 | public static final int MSG_QUERY_MEMORY = 6; |
| 77 | public static final int MSG_HUB_RESET = 7; |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 78 | |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 79 | private static final int OS_APP_INSTANCE = -1; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 80 | |
Arthur Ishiguro | b4f5987 | 2018-07-31 16:38:08 -0700 | [diff] [blame] | 81 | /* |
| 82 | * Local flag to enable debug logging. |
| 83 | */ |
| 84 | private static final boolean DEBUG_LOG_ENABLED = false; |
| 85 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 86 | private final Context mContext; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 87 | |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 88 | private final Map<Integer, ContextHubInfo> mContextHubIdToInfoMap; |
Arthur Ishiguro | fdbbd46 | 2017-11-27 16:33:36 -0800 | [diff] [blame] | 89 | private final List<ContextHubInfo> mContextHubInfoList; |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 90 | private final RemoteCallbackList<IContextHubCallback> mCallbacksList = |
| 91 | new RemoteCallbackList<>(); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 92 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 93 | // Proxy object to communicate with the Context Hub HAL |
| 94 | private final IContexthub mContextHubProxy; |
| 95 | |
| 96 | // The manager for transaction queue |
| 97 | private final ContextHubTransactionManager mTransactionManager; |
| 98 | |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 99 | // The manager for sending messages to/from clients |
| 100 | private final ContextHubClientManager mClientManager; |
| 101 | |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 102 | // The default client for old API clients |
| 103 | private final Map<Integer, IContextHubClient> mDefaultClientMap; |
| 104 | |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 105 | // The manager for the internal nanoapp state cache |
| 106 | private final NanoAppStateManager mNanoAppStateManager = new NanoAppStateManager(); |
| 107 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 108 | /** |
| 109 | * Class extending the callback to register with a Context Hub. |
| 110 | */ |
| 111 | private class ContextHubServiceCallback extends IContexthubCallback.Stub { |
| 112 | private final int mContextHubId; |
| 113 | |
| 114 | ContextHubServiceCallback(int contextHubId) { |
| 115 | mContextHubId = contextHubId; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void handleClientMsg(ContextHubMsg message) { |
| 120 | handleClientMessageCallback(mContextHubId, message); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public void handleTxnResult(int transactionId, int result) { |
| 125 | handleTransactionResultCallback(mContextHubId, transactionId, result); |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public void handleHubEvent(int eventType) { |
| 130 | handleHubEventCallback(mContextHubId, eventType); |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public void handleAppAbort(long nanoAppId, int abortCode) { |
| 135 | handleAppAbortCallback(mContextHubId, nanoAppId, abortCode); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public void handleAppsInfo(ArrayList<HubAppInfo> nanoAppInfoList) { |
| 140 | handleQueryAppsCallback(mContextHubId, nanoAppInfoList); |
| 141 | } |
| 142 | } |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 143 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 144 | public ContextHubService(Context context) { |
| 145 | mContext = context; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 146 | |
| 147 | mContextHubProxy = getContextHubProxy(); |
| 148 | if (mContextHubProxy == null) { |
| 149 | mTransactionManager = null; |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 150 | mClientManager = null; |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 151 | mDefaultClientMap = Collections.emptyMap(); |
| 152 | mContextHubIdToInfoMap = Collections.emptyMap(); |
Arthur Ishiguro | fdbbd46 | 2017-11-27 16:33:36 -0800 | [diff] [blame] | 153 | mContextHubInfoList = Collections.emptyList(); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 154 | return; |
| 155 | } |
| 156 | |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 157 | mClientManager = new ContextHubClientManager(mContext, mContextHubProxy); |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 158 | mTransactionManager = new ContextHubTransactionManager( |
| 159 | mContextHubProxy, mClientManager, mNanoAppStateManager); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 160 | |
| 161 | List<ContextHub> hubList; |
| 162 | try { |
| 163 | hubList = mContextHubProxy.getHubs(); |
| 164 | } catch (RemoteException e) { |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 165 | Log.e(TAG, "RemoteException while getting Context Hub info", e); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 166 | hubList = Collections.emptyList(); |
| 167 | } |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 168 | mContextHubIdToInfoMap = Collections.unmodifiableMap( |
| 169 | ContextHubServiceUtil.createContextHubInfoMap(hubList)); |
Arthur Ishiguro | fdbbd46 | 2017-11-27 16:33:36 -0800 | [diff] [blame] | 170 | mContextHubInfoList = new ArrayList<>(mContextHubIdToInfoMap.values()); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 171 | |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 172 | HashMap<Integer, IContextHubClient> defaultClientMap = new HashMap<>(); |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 173 | for (int contextHubId : mContextHubIdToInfoMap.keySet()) { |
Arthur Ishiguro | 622ebcb | 2018-10-17 14:02:27 -0700 | [diff] [blame] | 174 | ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId); |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 175 | IContextHubClient client = mClientManager.registerClient( |
Arthur Ishiguro | 793d3d1 | 2018-11-15 13:10:24 -0800 | [diff] [blame] | 176 | contextHubInfo, createDefaultClientCallback(contextHubId)); |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 177 | defaultClientMap.put(contextHubId, client); |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 178 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 179 | try { |
| 180 | mContextHubProxy.registerCallback( |
| 181 | contextHubId, new ContextHubServiceCallback(contextHubId)); |
| 182 | } catch (RemoteException e) { |
| 183 | Log.e(TAG, "RemoteException while registering service callback for hub (ID = " |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 184 | + contextHubId + ")", e); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 185 | } |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 186 | |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 187 | // Do a query to initialize the service cache list of nanoapps |
| 188 | // TODO(b/69270990): Remove this when old API is deprecated |
| 189 | queryNanoAppsInternal(contextHubId); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 190 | } |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 191 | mDefaultClientMap = Collections.unmodifiableMap(defaultClientMap); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 192 | } |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 193 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 194 | /** |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 195 | * Creates a default client callback for old API clients. |
| 196 | * |
| 197 | * @param contextHubId the ID of the hub to attach this client to |
| 198 | * @return the internal callback interface |
| 199 | */ |
| 200 | private IContextHubClientCallback createDefaultClientCallback(int contextHubId) { |
| 201 | return new IContextHubClientCallback.Stub() { |
| 202 | @Override |
| 203 | public void onMessageFromNanoApp(NanoAppMessage message) { |
Arthur Ishiguro | 2fc5a4b | 2017-12-11 15:15:44 -0800 | [diff] [blame] | 204 | int nanoAppHandle = mNanoAppStateManager.getNanoAppHandle( |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 205 | contextHubId, message.getNanoAppId()); |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 206 | |
| 207 | onMessageReceiptOldApi( |
Arthur Ishiguro | 2fc5a4b | 2017-12-11 15:15:44 -0800 | [diff] [blame] | 208 | message.getMessageType(), contextHubId, nanoAppHandle, |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 209 | message.getMessageBody()); |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public void onHubReset() { |
Arthur Ishiguro | 6d47c54 | 2017-11-17 15:49:07 -0800 | [diff] [blame] | 214 | byte[] data = {TransactionResult.SUCCESS}; |
| 215 | onMessageReceiptOldApi(MSG_HUB_RESET, contextHubId, OS_APP_INSTANCE, data); |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public void onNanoAppAborted(long nanoAppId, int abortCode) { |
| 220 | } |
| 221 | |
| 222 | @Override |
| 223 | public void onNanoAppLoaded(long nanoAppId) { |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public void onNanoAppUnloaded(long nanoAppId) { |
| 228 | } |
| 229 | |
| 230 | @Override |
| 231 | public void onNanoAppEnabled(long nanoAppId) { |
| 232 | } |
| 233 | |
| 234 | @Override |
| 235 | public void onNanoAppDisabled(long nanoAppId) { |
| 236 | } |
| 237 | }; |
| 238 | } |
| 239 | |
| 240 | /** |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 241 | * @return the IContexthub proxy interface |
| 242 | */ |
| 243 | private IContexthub getContextHubProxy() { |
| 244 | IContexthub proxy = null; |
| 245 | try { |
| 246 | proxy = IContexthub.getService(true /* retry */); |
| 247 | } catch (RemoteException e) { |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 248 | Log.e(TAG, "RemoteException while attaching to Context Hub HAL proxy", e); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 249 | } catch (NoSuchElementException e) { |
| 250 | Log.i(TAG, "Context Hub HAL service not found"); |
| 251 | } |
| 252 | |
| 253 | return proxy; |
| 254 | } |
| 255 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 256 | @Override |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 257 | public int registerCallback(IContextHubCallback callback) throws RemoteException { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 258 | checkPermissions(); |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 259 | mCallbacksList.register(callback); |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 260 | |
Ashutosh Joshi | 1d94181 | 2017-03-09 15:21:24 -0800 | [diff] [blame] | 261 | Log.d(TAG, "Added callback, total callbacks " + |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 262 | mCallbacksList.getRegisteredCallbackCount()); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | @Override |
| 267 | public int[] getContextHubHandles() throws RemoteException { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 268 | checkPermissions(); |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 269 | return ContextHubServiceUtil.createPrimitiveIntArray(mContextHubIdToInfoMap.keySet()); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | @Override |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 273 | public ContextHubInfo getContextHubInfo(int contextHubHandle) throws RemoteException { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 274 | checkPermissions(); |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 275 | if (!mContextHubIdToInfoMap.containsKey(contextHubHandle)) { |
| 276 | Log.e(TAG, "Invalid Context Hub handle " + contextHubHandle + " in getContextHubInfo"); |
| 277 | return null; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 280 | return mContextHubIdToInfoMap.get(contextHubHandle); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /** |
Arthur Ishiguro | fdbbd46 | 2017-11-27 16:33:36 -0800 | [diff] [blame] | 284 | * Returns a List of ContextHubInfo object describing the available hubs. |
| 285 | * |
| 286 | * @return the List of ContextHubInfo objects |
| 287 | */ |
| 288 | @Override |
| 289 | public List<ContextHubInfo> getContextHubs() throws RemoteException { |
| 290 | checkPermissions(); |
| 291 | return mContextHubInfoList; |
| 292 | } |
| 293 | |
| 294 | /** |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 295 | * Creates an internal load transaction callback to be used for old API clients |
| 296 | * |
| 297 | * @param contextHubId the ID of the hub to load the binary |
| 298 | * @param nanoAppBinary the binary to load |
| 299 | * @return the callback interface |
| 300 | */ |
| 301 | private IContextHubTransactionCallback createLoadTransactionCallback( |
| 302 | int contextHubId, NanoAppBinary nanoAppBinary) { |
| 303 | return new IContextHubTransactionCallback.Stub() { |
| 304 | @Override |
| 305 | public void onTransactionComplete(int result) { |
| 306 | handleLoadResponseOldApi(contextHubId, result, nanoAppBinary); |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public void onQueryResponse(int result, List<NanoAppState> nanoAppStateList) { |
| 311 | } |
| 312 | }; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Creates an internal unload transaction callback to be used for old API clients |
| 317 | * |
| 318 | * @param contextHubId the ID of the hub to unload the nanoapp |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 319 | * @return the callback interface |
| 320 | */ |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 321 | private IContextHubTransactionCallback createUnloadTransactionCallback(int contextHubId) { |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 322 | return new IContextHubTransactionCallback.Stub() { |
| 323 | @Override |
| 324 | public void onTransactionComplete(int result) { |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 325 | handleUnloadResponseOldApi(contextHubId, result); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public void onQueryResponse(int result, List<NanoAppState> nanoAppStateList) { |
| 330 | } |
| 331 | }; |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Creates an internal query transaction callback to be used for old API clients |
| 336 | * |
| 337 | * @param contextHubId the ID of the hub to query |
| 338 | * @return the callback interface |
| 339 | */ |
| 340 | private IContextHubTransactionCallback createQueryTransactionCallback(int contextHubId) { |
| 341 | return new IContextHubTransactionCallback.Stub() { |
| 342 | @Override |
| 343 | public void onTransactionComplete(int result) { |
| 344 | } |
| 345 | |
| 346 | @Override |
| 347 | public void onQueryResponse(int result, List<NanoAppState> nanoAppStateList) { |
| 348 | byte[] data = {(byte) result}; |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 349 | onMessageReceiptOldApi(MSG_QUERY_NANO_APPS, contextHubId, OS_APP_INSTANCE, data); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 350 | } |
| 351 | }; |
| 352 | } |
| 353 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 354 | @Override |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 355 | public int loadNanoApp(int contextHubHandle, NanoApp nanoApp) throws RemoteException { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 356 | checkPermissions(); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 357 | if (mContextHubProxy == null) { |
| 358 | return -1; |
| 359 | } |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 360 | if (!isValidContextHubId(contextHubHandle)) { |
| 361 | Log.e(TAG, "Invalid Context Hub handle " + contextHubHandle + " in loadNanoApp"); |
Ashutosh Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 362 | return -1; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 363 | } |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 364 | if (nanoApp == null) { |
| 365 | Log.e(TAG, "NanoApp cannot be null in loadNanoApp"); |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 366 | return -1; |
| 367 | } |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 368 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 369 | // Create an internal IContextHubTransactionCallback for the old API clients |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 370 | NanoAppBinary nanoAppBinary = new NanoAppBinary(nanoApp.getAppBinary()); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 371 | IContextHubTransactionCallback onCompleteCallback = |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 372 | createLoadTransactionCallback(contextHubHandle, nanoAppBinary); |
Ashutosh Joshi | 54787a5 | 2016-04-27 11:19:16 -0700 | [diff] [blame] | 373 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 374 | ContextHubServiceTransaction transaction = mTransactionManager.createLoadTransaction( |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 375 | contextHubHandle, nanoAppBinary, onCompleteCallback); |
Ashutosh Joshi | 54787a5 | 2016-04-27 11:19:16 -0700 | [diff] [blame] | 376 | |
Arthur Ishiguro | e60f91a | 2017-11-30 09:48:00 -0800 | [diff] [blame] | 377 | mTransactionManager.addTransaction(transaction); |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 378 | return 0; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 379 | } |
| 380 | |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 381 | @Override |
Arthur Ishiguro | 2fc5a4b | 2017-12-11 15:15:44 -0800 | [diff] [blame] | 382 | public int unloadNanoApp(int nanoAppHandle) throws RemoteException { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 383 | checkPermissions(); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 384 | if (mContextHubProxy == null) { |
| 385 | return -1; |
| 386 | } |
| 387 | |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 388 | NanoAppInstanceInfo info = |
Arthur Ishiguro | 2fc5a4b | 2017-12-11 15:15:44 -0800 | [diff] [blame] | 389 | mNanoAppStateManager.getNanoAppInstanceInfo(nanoAppHandle); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 390 | if (info == null) { |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 391 | Log.e(TAG, "Invalid nanoapp handle " + nanoAppHandle + " in unloadNanoApp"); |
Arthur Ishiguro | 2fc5a4b | 2017-12-11 15:15:44 -0800 | [diff] [blame] | 392 | return -1; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 393 | } |
| 394 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 395 | int contextHubId = info.getContexthubId(); |
| 396 | long nanoAppId = info.getAppId(); |
| 397 | IContextHubTransactionCallback onCompleteCallback = |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 398 | createUnloadTransactionCallback(contextHubId); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 399 | ContextHubServiceTransaction transaction = mTransactionManager.createUnloadTransaction( |
| 400 | contextHubId, nanoAppId, onCompleteCallback); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 401 | |
Arthur Ishiguro | e60f91a | 2017-11-30 09:48:00 -0800 | [diff] [blame] | 402 | mTransactionManager.addTransaction(transaction); |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 403 | return 0; |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 404 | } |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 405 | |
| 406 | @Override |
Arthur Ishiguro | 2fc5a4b | 2017-12-11 15:15:44 -0800 | [diff] [blame] | 407 | public NanoAppInstanceInfo getNanoAppInstanceInfo(int nanoAppHandle) throws RemoteException { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 408 | checkPermissions(); |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 409 | |
Arthur Ishiguro | 2fc5a4b | 2017-12-11 15:15:44 -0800 | [diff] [blame] | 410 | return mNanoAppStateManager.getNanoAppInstanceInfo(nanoAppHandle); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | @Override |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 414 | public int[] findNanoAppOnHub( |
| 415 | int contextHubHandle, NanoAppFilter filter) throws RemoteException { |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 416 | checkPermissions(); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 417 | |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 418 | ArrayList<Integer> foundInstances = new ArrayList<>(); |
Arthur Ishiguro | 1194634 | 2018-10-30 09:29:09 -0700 | [diff] [blame] | 419 | if (filter != null) { |
| 420 | mNanoAppStateManager.foreachNanoAppInstanceInfo((info) -> { |
| 421 | if (filter.testMatch(info)) { |
| 422 | foundInstances.add(info.getHandle()); |
| 423 | } |
| 424 | }); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | int[] retArray = new int[foundInstances.size()]; |
| 428 | for (int i = 0; i < foundInstances.size(); i++) { |
| 429 | retArray[i] = foundInstances.get(i).intValue(); |
| 430 | } |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 431 | return retArray; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 434 | /** |
| 435 | * Performs a query at the specified hub. |
| 436 | * |
| 437 | * This method should only be invoked internally by the service, either to update the service |
| 438 | * cache or as a result of an explicit query requested by a client through the sendMessage API. |
| 439 | * |
| 440 | * @param contextHubId the ID of the hub to do the query |
| 441 | * @return the result of the query |
Arthur Ishiguro | e60f91a | 2017-11-30 09:48:00 -0800 | [diff] [blame] | 442 | * |
| 443 | * @throws IllegalStateException if the transaction queue is full |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 444 | */ |
| 445 | private int queryNanoAppsInternal(int contextHubId) { |
| 446 | if (mContextHubProxy == null) { |
| 447 | return Result.UNKNOWN_FAILURE; |
| 448 | } |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 449 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 450 | IContextHubTransactionCallback onCompleteCallback = |
| 451 | createQueryTransactionCallback(contextHubId); |
| 452 | ContextHubServiceTransaction transaction = mTransactionManager.createQueryTransaction( |
| 453 | contextHubId, onCompleteCallback); |
| 454 | |
Arthur Ishiguro | e60f91a | 2017-11-30 09:48:00 -0800 | [diff] [blame] | 455 | mTransactionManager.addTransaction(transaction); |
| 456 | return Result.OK; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | @Override |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 460 | public int sendMessage(int contextHubHandle, int nanoAppHandle, ContextHubMessage msg) |
| 461 | throws RemoteException { |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 462 | checkPermissions(); |
| 463 | if (mContextHubProxy == null) { |
| 464 | return -1; |
| 465 | } |
| 466 | if (msg == null) { |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 467 | Log.e(TAG, "ContextHubMessage cannot be null in sendMessage"); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 468 | return -1; |
| 469 | } |
| 470 | if (msg.getData() == null) { |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 471 | Log.e(TAG, "ContextHubMessage message body cannot be null in sendMessage"); |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 472 | return -1; |
| 473 | } |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 474 | if (!isValidContextHubId(contextHubHandle)) { |
| 475 | Log.e(TAG, "Invalid Context Hub handle " + contextHubHandle + " in sendMessage"); |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 476 | return -1; |
| 477 | } |
| 478 | |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 479 | boolean success = false; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 480 | if (nanoAppHandle == OS_APP_INSTANCE) { |
| 481 | if (msg.getMsgType() == MSG_QUERY_NANO_APPS) { |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 482 | success = (queryNanoAppsInternal(contextHubHandle) == Result.OK); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 483 | } else { |
| 484 | Log.e(TAG, "Invalid OS message params of type " + msg.getMsgType()); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 485 | } |
| 486 | } else { |
| 487 | NanoAppInstanceInfo info = getNanoAppInstanceInfo(nanoAppHandle); |
| 488 | if (info != null) { |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 489 | NanoAppMessage message = NanoAppMessage.createMessageToNanoApp( |
| 490 | info.getAppId(), msg.getMsgType(), msg.getData()); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 491 | |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 492 | IContextHubClient client = mDefaultClientMap.get(contextHubHandle); |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 493 | success = (client.sendMessageToNanoApp(message) == |
Arthur Ishiguro | 6100aa7 | 2017-12-20 09:35:00 -0800 | [diff] [blame] | 494 | ContextHubTransaction.RESULT_SUCCESS); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 495 | } else { |
Arthur Ishiguro | 2fc5a4b | 2017-12-11 15:15:44 -0800 | [diff] [blame] | 496 | Log.e(TAG, "Failed to send nanoapp message - nanoapp with handle " |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 497 | + nanoAppHandle + " does not exist."); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Arthur Ishiguro | ebb0e86 | 2017-11-17 14:55:32 -0800 | [diff] [blame] | 501 | return success ? 0 : -1; |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Handles a unicast or broadcast message from a nanoapp. |
| 506 | * |
| 507 | * @param contextHubId the ID of the hub the message came from |
| 508 | * @param message the message contents |
| 509 | */ |
| 510 | private void handleClientMessageCallback(int contextHubId, ContextHubMsg message) { |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 511 | mClientManager.onMessageFromNanoApp(contextHubId, message); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /** |
| 515 | * A helper function to handle a load response from the Context Hub for the old API. |
| 516 | * |
| 517 | * TODO(b/69270990): Remove this once the old APIs are obsolete. |
| 518 | */ |
| 519 | private void handleLoadResponseOldApi( |
| 520 | int contextHubId, int result, NanoAppBinary nanoAppBinary) { |
| 521 | if (nanoAppBinary == null) { |
| 522 | Log.e(TAG, "Nanoapp binary field was null for a load transaction"); |
| 523 | return; |
| 524 | } |
| 525 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 526 | byte[] data = new byte[5]; |
| 527 | data[0] = (byte) result; |
Arthur Ishiguro | 2fc5a4b | 2017-12-11 15:15:44 -0800 | [diff] [blame] | 528 | int nanoAppHandle = mNanoAppStateManager.getNanoAppHandle( |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 529 | contextHubId, nanoAppBinary.getNanoAppId()); |
Arthur Ishiguro | 2fc5a4b | 2017-12-11 15:15:44 -0800 | [diff] [blame] | 530 | ByteBuffer.wrap(data, 1, 4).order(ByteOrder.nativeOrder()).putInt(nanoAppHandle); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 531 | |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 532 | onMessageReceiptOldApi(MSG_LOAD_NANO_APP, contextHubId, OS_APP_INSTANCE, data); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /** |
| 536 | * A helper function to handle an unload response from the Context Hub for the old API. |
| 537 | * |
| 538 | * TODO(b/69270990): Remove this once the old APIs are obsolete. |
| 539 | */ |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 540 | private void handleUnloadResponseOldApi(int contextHubId, int result) { |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 541 | byte[] data = new byte[1]; |
| 542 | data[0] = (byte) result; |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 543 | onMessageReceiptOldApi(MSG_UNLOAD_NANO_APP, contextHubId, OS_APP_INSTANCE, data); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /** |
| 547 | * Handles a transaction response from a Context Hub. |
| 548 | * |
| 549 | * @param contextHubId the ID of the hub the response came from |
| 550 | * @param transactionId the ID of the transaction |
| 551 | * @param result the result of the transaction reported by the hub |
| 552 | */ |
| 553 | private void handleTransactionResultCallback(int contextHubId, int transactionId, int result) { |
| 554 | mTransactionManager.onTransactionResponse(transactionId, result); |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Handles an asynchronous event from a Context Hub. |
| 559 | * |
| 560 | * @param contextHubId the ID of the hub the response came from |
| 561 | * @param eventType the type of the event as defined in Context Hub HAL AsyncEventType |
| 562 | */ |
| 563 | private void handleHubEventCallback(int contextHubId, int eventType) { |
| 564 | if (eventType == AsyncEventType.RESTARTED) { |
| 565 | mTransactionManager.onHubReset(); |
| 566 | queryNanoAppsInternal(contextHubId); |
| 567 | |
Arthur Ishiguro | 6d47c54 | 2017-11-17 15:49:07 -0800 | [diff] [blame] | 568 | mClientManager.onHubReset(contextHubId); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 569 | } else { |
| 570 | Log.i(TAG, "Received unknown hub event (hub ID = " + contextHubId + ", type = " |
| 571 | + eventType + ")"); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * Handles an asynchronous abort event of a nanoapp. |
| 577 | * |
| 578 | * @param contextHubId the ID of the hub that the nanoapp aborted in |
| 579 | * @param nanoAppId the ID of the aborted nanoapp |
| 580 | * @param abortCode the nanoapp-specific abort code |
| 581 | */ |
| 582 | private void handleAppAbortCallback(int contextHubId, long nanoAppId, int abortCode) { |
Arthur Ishiguro | 02ff50b | 2017-12-18 10:02:35 -0800 | [diff] [blame] | 583 | mClientManager.onNanoAppAborted(contextHubId, nanoAppId, abortCode); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /** |
| 587 | * Handles a query response from a Context Hub. |
| 588 | * |
| 589 | * @param contextHubId the ID of the hub of the response |
| 590 | * @param nanoAppInfoList the list of loaded nanoapps |
| 591 | */ |
| 592 | private void handleQueryAppsCallback(int contextHubId, List<HubAppInfo> nanoAppInfoList) { |
| 593 | List<NanoAppState> nanoAppStateList = |
| 594 | ContextHubServiceUtil.createNanoAppStateList(nanoAppInfoList); |
| 595 | |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 596 | mNanoAppStateManager.updateCache(contextHubId, nanoAppInfoList); |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 597 | mTransactionManager.onQueryResponse(nanoAppStateList); |
| 598 | } |
| 599 | |
| 600 | /** |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 601 | * @param contextHubId the hub ID to validate |
| 602 | * @return {@code true} if the ID represents that of an available hub, {@code false} otherwise |
| 603 | */ |
| 604 | private boolean isValidContextHubId(int contextHubId) { |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 605 | return mContextHubIdToInfoMap.containsKey(contextHubId); |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Creates and registers a client at the service for the specified Context Hub. |
| 610 | * |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 611 | * @param contextHubId the ID of the hub this client is attached to |
Arthur Ishiguro | 793d3d1 | 2018-11-15 13:10:24 -0800 | [diff] [blame] | 612 | * @param clientCallback the client interface to register with the service |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 613 | * @return the generated client interface, null if registration was unsuccessful |
| 614 | * |
| 615 | * @throws IllegalArgumentException if contextHubId is not a valid ID |
| 616 | * @throws IllegalStateException if max number of clients have already registered |
| 617 | * @throws NullPointerException if clientCallback is null |
| 618 | */ |
| 619 | @Override |
| 620 | public IContextHubClient createClient( |
Arthur Ishiguro | 793d3d1 | 2018-11-15 13:10:24 -0800 | [diff] [blame] | 621 | int contextHubId, IContextHubClientCallback clientCallback) throws RemoteException { |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 622 | checkPermissions(); |
| 623 | if (!isValidContextHubId(contextHubId)) { |
| 624 | throw new IllegalArgumentException("Invalid context hub ID " + contextHubId); |
| 625 | } |
| 626 | if (clientCallback == null) { |
| 627 | throw new NullPointerException("Cannot register client with null callback"); |
| 628 | } |
| 629 | |
Arthur Ishiguro | 622ebcb | 2018-10-17 14:02:27 -0700 | [diff] [blame] | 630 | ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId); |
Arthur Ishiguro | 793d3d1 | 2018-11-15 13:10:24 -0800 | [diff] [blame] | 631 | return mClientManager.registerClient(contextHubInfo, clientCallback); |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 632 | } |
| 633 | |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 634 | /** |
Arthur Ishiguro | 82ed3af | 2018-11-09 13:20:30 -0800 | [diff] [blame] | 635 | * Creates and registers a PendingIntent client at the service for the specified Context Hub. |
| 636 | * |
| 637 | * @param contextHubId the ID of the hub this client is attached to |
| 638 | * @param pendingIntent the PendingIntent associated with this client |
| 639 | * @param nanoAppId the ID of the nanoapp PendingIntent events will be sent for |
| 640 | * @return the generated client interface |
| 641 | * |
| 642 | * @throws IllegalArgumentException if hubInfo does not represent a valid hub |
| 643 | * @throws IllegalStateException if there were too many registered clients at the service |
| 644 | */ |
| 645 | @Override |
| 646 | public IContextHubClient createPendingIntentClient( |
| 647 | int contextHubId, PendingIntent pendingIntent, long nanoAppId) throws RemoteException { |
| 648 | checkPermissions(); |
| 649 | if (!isValidContextHubId(contextHubId)) { |
| 650 | throw new IllegalArgumentException("Invalid context hub ID " + contextHubId); |
| 651 | } |
| 652 | |
| 653 | ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId); |
| 654 | return mClientManager.registerClient(contextHubInfo, pendingIntent, nanoAppId); |
| 655 | } |
| 656 | |
| 657 | /** |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 658 | * Loads a nanoapp binary at the specified Context hub. |
| 659 | * |
Arthur Ishiguro | 0ed545c | 2017-12-12 15:01:32 -0800 | [diff] [blame] | 660 | * @param contextHubId the ID of the hub to load the binary |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 661 | * @param transactionCallback the client-facing transaction callback interface |
Arthur Ishiguro | 0ed545c | 2017-12-12 15:01:32 -0800 | [diff] [blame] | 662 | * @param nanoAppBinary the binary to load |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 663 | * |
Arthur Ishiguro | e60f91a | 2017-11-30 09:48:00 -0800 | [diff] [blame] | 664 | * @throws IllegalStateException if the transaction queue is full |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 665 | */ |
| 666 | @Override |
| 667 | public void loadNanoAppOnHub( |
| 668 | int contextHubId, IContextHubTransactionCallback transactionCallback, |
| 669 | NanoAppBinary nanoAppBinary) throws RemoteException { |
| 670 | checkPermissions(); |
Arthur Ishiguro | 4493e14 | 2017-11-27 16:26:34 -0800 | [diff] [blame] | 671 | if (!checkHalProxyAndContextHubId( |
| 672 | contextHubId, transactionCallback, ContextHubTransaction.TYPE_LOAD_NANOAPP)) { |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 673 | return; |
| 674 | } |
| 675 | if (nanoAppBinary == null) { |
| 676 | Log.e(TAG, "NanoAppBinary cannot be null in loadNanoAppOnHub"); |
| 677 | transactionCallback.onTransactionComplete( |
Arthur Ishiguro | 6100aa7 | 2017-12-20 09:35:00 -0800 | [diff] [blame] | 678 | ContextHubTransaction.RESULT_FAILED_BAD_PARAMS); |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 679 | return; |
| 680 | } |
| 681 | |
| 682 | ContextHubServiceTransaction transaction = mTransactionManager.createLoadTransaction( |
| 683 | contextHubId, nanoAppBinary, transactionCallback); |
Arthur Ishiguro | e60f91a | 2017-11-30 09:48:00 -0800 | [diff] [blame] | 684 | mTransactionManager.addTransaction(transaction); |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | /** |
| 688 | * Unloads a nanoapp from the specified Context Hub. |
| 689 | * |
Arthur Ishiguro | 0ed545c | 2017-12-12 15:01:32 -0800 | [diff] [blame] | 690 | * @param contextHubId the ID of the hub to unload the nanoapp |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 691 | * @param transactionCallback the client-facing transaction callback interface |
Arthur Ishiguro | 0ed545c | 2017-12-12 15:01:32 -0800 | [diff] [blame] | 692 | * @param nanoAppId the ID of the nanoapp to unload |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 693 | * |
Arthur Ishiguro | e60f91a | 2017-11-30 09:48:00 -0800 | [diff] [blame] | 694 | * @throws IllegalStateException if the transaction queue is full |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 695 | */ |
| 696 | @Override |
| 697 | public void unloadNanoAppFromHub( |
| 698 | int contextHubId, IContextHubTransactionCallback transactionCallback, long nanoAppId) |
| 699 | throws RemoteException { |
| 700 | checkPermissions(); |
Arthur Ishiguro | 4493e14 | 2017-11-27 16:26:34 -0800 | [diff] [blame] | 701 | if (!checkHalProxyAndContextHubId( |
| 702 | contextHubId, transactionCallback, ContextHubTransaction.TYPE_UNLOAD_NANOAPP)) { |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 703 | return; |
| 704 | } |
| 705 | |
| 706 | ContextHubServiceTransaction transaction = mTransactionManager.createUnloadTransaction( |
| 707 | contextHubId, nanoAppId, transactionCallback); |
Arthur Ishiguro | e60f91a | 2017-11-30 09:48:00 -0800 | [diff] [blame] | 708 | mTransactionManager.addTransaction(transaction); |
Arthur Ishiguro | 4493e14 | 2017-11-27 16:26:34 -0800 | [diff] [blame] | 709 | } |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 710 | |
Arthur Ishiguro | 4493e14 | 2017-11-27 16:26:34 -0800 | [diff] [blame] | 711 | /** |
Arthur Ishiguro | 0ed545c | 2017-12-12 15:01:32 -0800 | [diff] [blame] | 712 | * Enables a nanoapp at the specified Context Hub. |
| 713 | * |
| 714 | * @param contextHubId the ID of the hub to enable the nanoapp |
| 715 | * @param transactionCallback the client-facing transaction callback interface |
| 716 | * @param nanoAppId the ID of the nanoapp to enable |
| 717 | * |
| 718 | * @throws IllegalStateException if the transaction queue is full |
| 719 | */ |
| 720 | @Override |
| 721 | public void enableNanoApp( |
| 722 | int contextHubId, IContextHubTransactionCallback transactionCallback, long nanoAppId) |
| 723 | throws RemoteException { |
| 724 | checkPermissions(); |
| 725 | if (!checkHalProxyAndContextHubId( |
| 726 | contextHubId, transactionCallback, ContextHubTransaction.TYPE_ENABLE_NANOAPP)) { |
| 727 | return; |
| 728 | } |
| 729 | |
| 730 | ContextHubServiceTransaction transaction = mTransactionManager.createEnableTransaction( |
| 731 | contextHubId, nanoAppId, transactionCallback); |
| 732 | mTransactionManager.addTransaction(transaction); |
| 733 | } |
| 734 | |
| 735 | /** |
Arthur Ishiguro | 54e1a89 | 2017-12-12 15:09:31 -0800 | [diff] [blame] | 736 | * Disables a nanoapp at the specified Context Hub. |
| 737 | * |
| 738 | * @param contextHubId the ID of the hub to disable the nanoapp |
| 739 | * @param transactionCallback the client-facing transaction callback interface |
| 740 | * @param nanoAppId the ID of the nanoapp to disable |
| 741 | * |
| 742 | * @throws IllegalStateException if the transaction queue is full |
| 743 | */ |
| 744 | @Override |
| 745 | public void disableNanoApp( |
| 746 | int contextHubId, IContextHubTransactionCallback transactionCallback, long nanoAppId) |
| 747 | throws RemoteException { |
| 748 | checkPermissions(); |
| 749 | if (!checkHalProxyAndContextHubId( |
| 750 | contextHubId, transactionCallback, ContextHubTransaction.TYPE_DISABLE_NANOAPP)) { |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | ContextHubServiceTransaction transaction = mTransactionManager.createDisableTransaction( |
| 755 | contextHubId, nanoAppId, transactionCallback); |
| 756 | mTransactionManager.addTransaction(transaction); |
| 757 | } |
| 758 | |
| 759 | /** |
Arthur Ishiguro | 4493e14 | 2017-11-27 16:26:34 -0800 | [diff] [blame] | 760 | * Queries for a list of nanoapps from the specified Context hub. |
| 761 | * |
Arthur Ishiguro | 0ed545c | 2017-12-12 15:01:32 -0800 | [diff] [blame] | 762 | * @param contextHubId the ID of the hub to query |
Arthur Ishiguro | 4493e14 | 2017-11-27 16:26:34 -0800 | [diff] [blame] | 763 | * @param transactionCallback the client-facing transaction callback interface |
| 764 | * |
Arthur Ishiguro | e60f91a | 2017-11-30 09:48:00 -0800 | [diff] [blame] | 765 | * @throws IllegalStateException if the transaction queue is full |
Arthur Ishiguro | 4493e14 | 2017-11-27 16:26:34 -0800 | [diff] [blame] | 766 | */ |
| 767 | @Override |
| 768 | public void queryNanoApps(int contextHubId, IContextHubTransactionCallback transactionCallback) |
| 769 | throws RemoteException { |
| 770 | checkPermissions(); |
| 771 | if (!checkHalProxyAndContextHubId( |
| 772 | contextHubId, transactionCallback, ContextHubTransaction.TYPE_QUERY_NANOAPPS)) { |
| 773 | return; |
| 774 | } |
| 775 | |
Arthur Ishiguro | 0ed545c | 2017-12-12 15:01:32 -0800 | [diff] [blame] | 776 | ContextHubServiceTransaction transaction = mTransactionManager.createQueryTransaction( |
| 777 | contextHubId, transactionCallback); |
Arthur Ishiguro | e60f91a | 2017-11-30 09:48:00 -0800 | [diff] [blame] | 778 | mTransactionManager.addTransaction(transaction); |
Arthur Ishiguro | e1ade43 | 2017-11-27 10:45:33 -0800 | [diff] [blame] | 779 | } |
| 780 | |
Ashutosh Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 781 | @Override |
| 782 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 783 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
Ashutosh Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 784 | |
| 785 | pw.println("Dumping ContextHub Service"); |
| 786 | |
| 787 | pw.println(""); |
| 788 | // dump ContextHubInfo |
| 789 | pw.println("=================== CONTEXT HUBS ===================="); |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 790 | for (ContextHubInfo hubInfo : mContextHubIdToInfoMap.values()) { |
| 791 | pw.println(hubInfo); |
Ashutosh Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 792 | } |
| 793 | pw.println(""); |
| 794 | pw.println("=================== NANOAPPS ===================="); |
| 795 | // Dump nanoAppHash |
Arthur Ishiguro | 1194634 | 2018-10-30 09:29:09 -0700 | [diff] [blame] | 796 | mNanoAppStateManager.foreachNanoAppInstanceInfo((info) -> pw.println(info)); |
Ashutosh Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 797 | |
| 798 | // dump eventLog |
| 799 | } |
| 800 | |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 801 | private void checkPermissions() { |
Arthur Ishiguro | 4e39aa1 | 2017-11-14 14:59:08 -0800 | [diff] [blame] | 802 | ContextHubServiceUtil.checkPermissions(mContext); |
destradaa | 8bad3fe | 2016-03-15 12:33:40 -0700 | [diff] [blame] | 803 | } |
Ashutosh Joshi | 2c697fb | 2016-04-01 20:48:13 +0000 | [diff] [blame] | 804 | |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 805 | private int onMessageReceiptOldApi( |
| 806 | int msgType, int contextHubHandle, int appInstance, byte[] data) { |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 807 | if (data == null) { |
| 808 | return -1; |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 809 | } |
Ashutosh Joshi | 1d94181 | 2017-03-09 15:21:24 -0800 | [diff] [blame] | 810 | |
Arthur Ishiguro | 7a23a96 | 2017-11-01 10:52:28 -0700 | [diff] [blame] | 811 | int msgVersion = 0; |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 812 | int callbacksCount = mCallbacksList.beginBroadcast(); |
Arthur Ishiguro | b4f5987 | 2018-07-31 16:38:08 -0700 | [diff] [blame] | 813 | if (DEBUG_LOG_ENABLED) { |
| 814 | Log.v(TAG, "Sending message " + msgType + " version " + msgVersion + " from hubHandle " |
| 815 | + contextHubHandle + ", appInstance " + appInstance + ", callBackCount " |
| 816 | + callbacksCount); |
| 817 | } |
Ashutosh Joshi | 1d94181 | 2017-03-09 15:21:24 -0800 | [diff] [blame] | 818 | |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 819 | if (callbacksCount < 1) { |
Arthur Ishiguro | b4f5987 | 2018-07-31 16:38:08 -0700 | [diff] [blame] | 820 | if (DEBUG_LOG_ENABLED) { |
| 821 | Log.v(TAG, "No message callbacks registered."); |
| 822 | } |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 823 | return 0; |
| 824 | } |
Ashutosh Joshi | 54787a5 | 2016-04-27 11:19:16 -0700 | [diff] [blame] | 825 | |
Ashutosh Joshi | 1d94181 | 2017-03-09 15:21:24 -0800 | [diff] [blame] | 826 | ContextHubMessage msg = new ContextHubMessage(msgType, msgVersion, data); |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 827 | for (int i = 0; i < callbacksCount; ++i) { |
| 828 | IContextHubCallback callback = mCallbacksList.getBroadcastItem(i); |
| 829 | try { |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 830 | callback.onMessageReceipt(contextHubHandle, appInstance, msg); |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 831 | } catch (RemoteException e) { |
| 832 | Log.i(TAG, "Exception (" + e + ") calling remote callback (" + callback + ")."); |
| 833 | continue; |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 834 | } |
| 835 | } |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 836 | mCallbacksList.finishBroadcast(); |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 837 | return 0; |
| 838 | } |
| 839 | |
Arthur Ishiguro | 4493e14 | 2017-11-27 16:26:34 -0800 | [diff] [blame] | 840 | /** |
| 841 | * Validates the HAL proxy state and context hub ID to see if we can start the transaction. |
| 842 | * |
| 843 | * @param contextHubId the ID of the hub to start the transaction |
| 844 | * @param callback the client transaction callback interface |
| 845 | * @param transactionType the type of the transaction |
| 846 | * |
| 847 | * @return {@code true} if mContextHubProxy and contextHubId is valid, {@code false} otherwise |
| 848 | */ |
| 849 | private boolean checkHalProxyAndContextHubId( |
| 850 | int contextHubId, IContextHubTransactionCallback callback, |
| 851 | @ContextHubTransaction.Type int transactionType) { |
| 852 | if (mContextHubProxy == null) { |
| 853 | try { |
| 854 | callback.onTransactionComplete( |
Arthur Ishiguro | 6100aa7 | 2017-12-20 09:35:00 -0800 | [diff] [blame] | 855 | ContextHubTransaction.RESULT_FAILED_HAL_UNAVAILABLE); |
Arthur Ishiguro | 4493e14 | 2017-11-27 16:26:34 -0800 | [diff] [blame] | 856 | } catch (RemoteException e) { |
| 857 | Log.e(TAG, "RemoteException while calling onTransactionComplete", e); |
| 858 | } |
| 859 | return false; |
| 860 | } |
| 861 | if (!isValidContextHubId(contextHubId)) { |
| 862 | Log.e(TAG, "Cannot start " |
| 863 | + ContextHubTransaction.typeToString(transactionType, false /* upperCase */) |
| 864 | + " transaction for invalid hub ID " + contextHubId); |
| 865 | try { |
Arthur Ishiguro | 6100aa7 | 2017-12-20 09:35:00 -0800 | [diff] [blame] | 866 | callback.onTransactionComplete(ContextHubTransaction.RESULT_FAILED_BAD_PARAMS); |
Arthur Ishiguro | 4493e14 | 2017-11-27 16:26:34 -0800 | [diff] [blame] | 867 | } catch (RemoteException e) { |
| 868 | Log.e(TAG, "RemoteException while calling onTransactionComplete", e); |
| 869 | } |
| 870 | return false; |
| 871 | } |
| 872 | |
| 873 | return true; |
| 874 | } |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 875 | } |