Home | History | Annotate | Download | only in slpi
      1 /*
      2  * Copyright (C) 2017 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 
     17 #include "chre/platform/slpi/preloaded_nanoapps.h"
     18 
     19 #include "chre/core/nanoapp.h"
     20 #include "chre/platform/fatal_error.h"
     21 #include "chre/util/macros.h"
     22 #include "chre/util/unique_ptr.h"
     23 
     24 namespace chre {
     25 
     26 /**
     27  * Loads nanoapps that are standalone .so file (i.e. not static nanoapps), but
     28  * are pre-loaded in the system image.
     29  *
     30  * @param eventLoop The event loop where these nanoapps should run
     31  */
     32 void loadPreloadedNanoapps(EventLoop *eventLoop) {
     33   struct PreloadedNanoappDescriptor {
     34     const uint64_t appId;
     35     const char *filename;
     36     UniquePtr<Nanoapp> nanoapp;
     37   };
     38 
     39   // The list of nanoapps to be loaded from the filesystem of the device.
     40   // TODO: allow these to be overridden by target-specific build configuration
     41   static PreloadedNanoappDescriptor preloadedNanoapps[] = {
     42     { 0x476f6f676c00100b, "activity.so", MakeUnique<Nanoapp>() },
     43     { 0x476f6f676c001004, "geofence.so", MakeUnique<Nanoapp>() },
     44     { 0x476f6f676c00100c, "wifi_offload.so", MakeUnique<Nanoapp>() },
     45   };
     46 
     47   for (size_t i = 0; i < ARRAY_SIZE(preloadedNanoapps); i++) {
     48     if (preloadedNanoapps[i].nanoapp.isNull()) {
     49       FATAL_ERROR("Couldn't allocate memory for preloaded nanoapp");
     50     } else {
     51       preloadedNanoapps[i].nanoapp->loadFromFile(preloadedNanoapps[i].appId,
     52                                                  preloadedNanoapps[i].filename);
     53       eventLoop->startNanoapp(preloadedNanoapps[i].nanoapp);
     54     }
     55   }
     56 }
     57 
     58 }  // namespace chre
     59