1*4d7e907cSAndroid Build Coastguard Worker/* 2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2016 The Android Open Source Project 3*4d7e907cSAndroid Build Coastguard Worker * 4*4d7e907cSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*4d7e907cSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*4d7e907cSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*4d7e907cSAndroid Build Coastguard Worker * 8*4d7e907cSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*4d7e907cSAndroid Build Coastguard Worker * 10*4d7e907cSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*4d7e907cSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*4d7e907cSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*4d7e907cSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*4d7e907cSAndroid Build Coastguard Worker * limitations under the License. 15*4d7e907cSAndroid Build Coastguard Worker */ 16*4d7e907cSAndroid Build Coastguard Worker 17*4d7e907cSAndroid Build Coastguard Workerpackage [email protected]; 18*4d7e907cSAndroid Build Coastguard Worker 19*4d7e907cSAndroid Build Coastguard Workerimport IContexthubCallback; 20*4d7e907cSAndroid Build Coastguard Worker 21*4d7e907cSAndroid Build Coastguard Worker/** 22*4d7e907cSAndroid Build Coastguard Worker * The Context Hub HAL provides an interface to a separate low-power processing 23*4d7e907cSAndroid Build Coastguard Worker * domain that has direct access to contextual information, such as sensors. 24*4d7e907cSAndroid Build Coastguard Worker * Native applications that run within a context hub are known as nanoapps, and 25*4d7e907cSAndroid Build Coastguard Worker * they execute within the Context Hub Runtime Environment (CHRE), which is 26*4d7e907cSAndroid Build Coastguard Worker * standardized via the CHRE API, defined elsewhere. 27*4d7e907cSAndroid Build Coastguard Worker */ 28*4d7e907cSAndroid Build Coastguard Workerinterface IContexthub { 29*4d7e907cSAndroid Build Coastguard Worker /** 30*4d7e907cSAndroid Build Coastguard Worker * Enumerate all available context hubs on the system. 31*4d7e907cSAndroid Build Coastguard Worker * 32*4d7e907cSAndroid Build Coastguard Worker * @return hubs list of hubs on this system. 33*4d7e907cSAndroid Build Coastguard Worker */ 34*4d7e907cSAndroid Build Coastguard Worker getHubs() generates (vec<ContextHub> hubs); 35*4d7e907cSAndroid Build Coastguard Worker 36*4d7e907cSAndroid Build Coastguard Worker /** 37*4d7e907cSAndroid Build Coastguard Worker * Register a callback for the HAL implementation to send asynchronous 38*4d7e907cSAndroid Build Coastguard Worker * messages to the service from a context hub. There can be a maximum of 39*4d7e907cSAndroid Build Coastguard Worker * one callback registered with the HAL. A call to this function when a 40*4d7e907cSAndroid Build Coastguard Worker * callback has already been registered must override the previous 41*4d7e907cSAndroid Build Coastguard Worker * registration. 42*4d7e907cSAndroid Build Coastguard Worker * 43*4d7e907cSAndroid Build Coastguard Worker * @param hubId identifier for the hub 44*4d7e907cSAndroid Build Coastguard Worker * @param callback an implementation of the IContextHubCallbacks 45*4d7e907cSAndroid Build Coastguard Worker * 46*4d7e907cSAndroid Build Coastguard Worker * @return result OK on success 47*4d7e907cSAndroid Build Coastguard Worker * BAD_VALUE if parameters are not sane 48*4d7e907cSAndroid Build Coastguard Worker * 49*4d7e907cSAndroid Build Coastguard Worker */ 50*4d7e907cSAndroid Build Coastguard Worker registerCallback(uint32_t hubId, IContexthubCallback cb) generates (Result result); 51*4d7e907cSAndroid Build Coastguard Worker 52*4d7e907cSAndroid Build Coastguard Worker /** 53*4d7e907cSAndroid Build Coastguard Worker * Send a message to a hub 54*4d7e907cSAndroid Build Coastguard Worker * 55*4d7e907cSAndroid Build Coastguard Worker * @param hubId identifier for hub to send message to 56*4d7e907cSAndroid Build Coastguard Worker * @param msg message to be sent 57*4d7e907cSAndroid Build Coastguard Worker * 58*4d7e907cSAndroid Build Coastguard Worker * @return result OK if successful, error code otherwise 59*4d7e907cSAndroid Build Coastguard Worker * BAD_VALUE if parameters are not sane 60*4d7e907cSAndroid Build Coastguard Worker * TRANSACTION_FAILED if message send failed 61*4d7e907cSAndroid Build Coastguard Worker */ 62*4d7e907cSAndroid Build Coastguard Worker sendMessageToHub(uint32_t hubId, ContextHubMsg msg) 63*4d7e907cSAndroid Build Coastguard Worker generates (Result result); 64*4d7e907cSAndroid Build Coastguard Worker 65*4d7e907cSAndroid Build Coastguard Worker /** 66*4d7e907cSAndroid Build Coastguard Worker * Loads a nanoApp. After loading, the nanoApp's init method must be called. 67*4d7e907cSAndroid Build Coastguard Worker * After the init method for nanoApp returns success, this must be indicated 68*4d7e907cSAndroid Build Coastguard Worker * to the service by an asynchronous call to handleTxnResult. 69*4d7e907cSAndroid Build Coastguard Worker * 70*4d7e907cSAndroid Build Coastguard Worker * Loading a nanoapp must not take more than 30 seconds. 71*4d7e907cSAndroid Build Coastguard Worker * 72*4d7e907cSAndroid Build Coastguard Worker * Depending on the implementation, nanoApps loaded via this API may or may 73*4d7e907cSAndroid Build Coastguard Worker * not persist across reboots of the hub. If they do persist, the 74*4d7e907cSAndroid Build Coastguard Worker * implementation must initially place nanoApps in the disabled state upon a 75*4d7e907cSAndroid Build Coastguard Worker * reboot, and not start them until a call is made to enableNanoApp(). In 76*4d7e907cSAndroid Build Coastguard Worker * this case, the app must also be unloaded upon a factory reset of the 77*4d7e907cSAndroid Build Coastguard Worker * device. 78*4d7e907cSAndroid Build Coastguard Worker * 79*4d7e907cSAndroid Build Coastguard Worker * @param hubId identifer of the contextHub 80*4d7e907cSAndroid Build Coastguard Worker * @param appBinary contains the binary representation of the nanoApp, plus 81*4d7e907cSAndroid Build Coastguard Worker * metadata 82*4d7e907cSAndroid Build Coastguard Worker * @param transactionId transactionId for this call 83*4d7e907cSAndroid Build Coastguard Worker * 84*4d7e907cSAndroid Build Coastguard Worker * @return result OK if transation started 85*4d7e907cSAndroid Build Coastguard Worker * BAD_VALUE if parameters are not sane 86*4d7e907cSAndroid Build Coastguard Worker * TRANSACTION_PENDING if hub is busy with another 87*4d7e907cSAndroid Build Coastguard Worker * load/unload transaction 88*4d7e907cSAndroid Build Coastguard Worker * TRANSACTION_FAILED if load failed synchronously 89*4d7e907cSAndroid Build Coastguard Worker * 90*4d7e907cSAndroid Build Coastguard Worker */ 91*4d7e907cSAndroid Build Coastguard Worker loadNanoApp(uint32_t hubId, 92*4d7e907cSAndroid Build Coastguard Worker NanoAppBinary appBinary, 93*4d7e907cSAndroid Build Coastguard Worker uint32_t transactionId) 94*4d7e907cSAndroid Build Coastguard Worker generates (Result result); 95*4d7e907cSAndroid Build Coastguard Worker 96*4d7e907cSAndroid Build Coastguard Worker /** 97*4d7e907cSAndroid Build Coastguard Worker * Unloads a nanoApp. Before the unload, the apps deinit method is called. 98*4d7e907cSAndroid Build Coastguard Worker * After this, success must be indicated to the service through an 99*4d7e907cSAndroid Build Coastguard Worker * asynchronous call to handleTxnResult. 100*4d7e907cSAndroid Build Coastguard Worker * 101*4d7e907cSAndroid Build Coastguard Worker * Unloading a nanoapp must not take more than 5 seconds. 102*4d7e907cSAndroid Build Coastguard Worker * 103*4d7e907cSAndroid Build Coastguard Worker * @param hubId identifer of the contextHub 104*4d7e907cSAndroid Build Coastguard Worker * @param appId appIdentifier returned by the HAL 105*4d7e907cSAndroid Build Coastguard Worker * @param msg message to be sent 106*4d7e907cSAndroid Build Coastguard Worker * 107*4d7e907cSAndroid Build Coastguard Worker * @return result OK if transation started 108*4d7e907cSAndroid Build Coastguard Worker * BAD_VALUE if parameters are not sane 109*4d7e907cSAndroid Build Coastguard Worker * TRANSACTION_PENDING if hub is busy with another 110*4d7e907cSAndroid Build Coastguard Worker * load/unload transaction 111*4d7e907cSAndroid Build Coastguard Worker * TRANSACTION_FAILED if unload failed synchronously 112*4d7e907cSAndroid Build Coastguard Worker * 113*4d7e907cSAndroid Build Coastguard Worker */ 114*4d7e907cSAndroid Build Coastguard Worker unloadNanoApp(uint32_t hubId, uint64_t appId, uint32_t transactionId) 115*4d7e907cSAndroid Build Coastguard Worker generates (Result result); 116*4d7e907cSAndroid Build Coastguard Worker 117*4d7e907cSAndroid Build Coastguard Worker /** 118*4d7e907cSAndroid Build Coastguard Worker * Enables a nanoApp. The app's init method is called. 119*4d7e907cSAndroid Build Coastguard Worker * After this, success must be indicated to the service through an 120*4d7e907cSAndroid Build Coastguard Worker * asynchronous message. 121*4d7e907cSAndroid Build Coastguard Worker * 122*4d7e907cSAndroid Build Coastguard Worker * Enabling a nanoapp must not take more than 5 seconds. 123*4d7e907cSAndroid Build Coastguard Worker * 124*4d7e907cSAndroid Build Coastguard Worker * @param hubId identifer of the contextHub 125*4d7e907cSAndroid Build Coastguard Worker * @param appId appIdentifier returned by the HAL 126*4d7e907cSAndroid Build Coastguard Worker * @param msg message to be sent 127*4d7e907cSAndroid Build Coastguard Worker * 128*4d7e907cSAndroid Build Coastguard Worker * @return result OK if transation started 129*4d7e907cSAndroid Build Coastguard Worker * BAD_VALUE if parameters are not sane 130*4d7e907cSAndroid Build Coastguard Worker * TRANSACTION_PENDING if hub is busy with another 131*4d7e907cSAndroid Build Coastguard Worker * load/unload transaction 132*4d7e907cSAndroid Build Coastguard Worker * FAILED_TRANSACTION if load fails immediately 133*4d7e907cSAndroid Build Coastguard Worker * 134*4d7e907cSAndroid Build Coastguard Worker */ 135*4d7e907cSAndroid Build Coastguard Worker enableNanoApp(uint32_t hubId, uint64_t appId, uint32_t transactionId) 136*4d7e907cSAndroid Build Coastguard Worker generates (Result result); 137*4d7e907cSAndroid Build Coastguard Worker 138*4d7e907cSAndroid Build Coastguard Worker /** 139*4d7e907cSAndroid Build Coastguard Worker * Disables a nanoApp. The app's deinit method is called. 140*4d7e907cSAndroid Build Coastguard Worker * After this, success must be indicated to the service through an 141*4d7e907cSAndroid Build Coastguard Worker * asynchronous message. 142*4d7e907cSAndroid Build Coastguard Worker * 143*4d7e907cSAndroid Build Coastguard Worker * Disabling a nanoapp must not take more than 5 seconds. 144*4d7e907cSAndroid Build Coastguard Worker * 145*4d7e907cSAndroid Build Coastguard Worker * @param hubId identifer of the contextHub 146*4d7e907cSAndroid Build Coastguard Worker * @param appId appIdentifier returned by the HAL 147*4d7e907cSAndroid Build Coastguard Worker * @param msg message to be sent 148*4d7e907cSAndroid Build Coastguard Worker * 149*4d7e907cSAndroid Build Coastguard Worker * @return result OK if transation started 150*4d7e907cSAndroid Build Coastguard Worker * BAD_VALUE if parameters are not sane 151*4d7e907cSAndroid Build Coastguard Worker * TRANSACTION_PENDING if hub is busy with another 152*4d7e907cSAndroid Build Coastguard Worker * load/unload transaction 153*4d7e907cSAndroid Build Coastguard Worker * FAILED_TRANSACTION if load fails immediately 154*4d7e907cSAndroid Build Coastguard Worker * 155*4d7e907cSAndroid Build Coastguard Worker */ 156*4d7e907cSAndroid Build Coastguard Worker disableNanoApp(uint32_t hubId, uint64_t appId, uint32_t transactionId) 157*4d7e907cSAndroid Build Coastguard Worker generates (Result result); 158*4d7e907cSAndroid Build Coastguard Worker 159*4d7e907cSAndroid Build Coastguard Worker /** 160*4d7e907cSAndroid Build Coastguard Worker * Queries for Loaded apps on the hub 161*4d7e907cSAndroid Build Coastguard Worker * 162*4d7e907cSAndroid Build Coastguard Worker * @param hubId identifer of the contextHub 163*4d7e907cSAndroid Build Coastguard Worker * 164*4d7e907cSAndroid Build Coastguard Worker * @return apps all nanoApps on the hub. 165*4d7e907cSAndroid Build Coastguard Worker * All nanoApps that can be modified by the service must 166*4d7e907cSAndroid Build Coastguard Worker * be returned. A non-modifiable nanoapps must not be 167*4d7e907cSAndroid Build Coastguard Worker * returned. A modifiable nanoApp is one that can be 168*4d7e907cSAndroid Build Coastguard Worker * unloaded/disabled/enabled by the service. 169*4d7e907cSAndroid Build Coastguard Worker * 170*4d7e907cSAndroid Build Coastguard Worker */ 171*4d7e907cSAndroid Build Coastguard Worker queryApps(uint32_t hubId) generates (Result result); 172*4d7e907cSAndroid Build Coastguard Worker}; 173