• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/apps/apps.h"
18 #include "chre/core/event_loop_manager.h"
19 #include "chre/core/static_nanoapps.h"
20 #include "chre/util/macros.h"
21 
22 namespace chre {
23 
24 // The CHRE build variant can supply this macro to override the default list of
25 // static nanoapps. Most production variants will supply this macro as these
26 // nanoapps are mostly intended for testing and evaluation purposes. This list
27 // is supplied empty to ensure that the symbol is avilable for platforms with
28 // no static nanoapps.
29 #ifndef CHRE_VARIANT_SUPPLIES_STATIC_NANOAPP_LIST
30 
31 //! The default list of static nanoapps to load.
32 const StaticNanoappInitFunction kStaticNanoappList[] = {};
33 
34 //! The size of the default static nanoapp list.
35 const size_t kStaticNanoappCount = ARRAY_SIZE(kStaticNanoappList);
36 
37 #endif  // CHRE_VARIANT_SUPPLIES_STATIC_NANOAPP_LIST
38 
loadStaticNanoapps()39 void loadStaticNanoapps() {
40   // Compare with zero to allow the compiler to optimize away the loop.
41   // Tautological comparisons are not warnings when comparing a const with
42   // another const.
43   if (kStaticNanoappCount > 0) {
44     // Cast the kStaticNanoappCount to size_t to avoid tautological comparison
45     // warnings when the kStaticNanoappCount is zero.
46     for (size_t i = 0; i < reinterpret_cast<size_t>(kStaticNanoappCount); i++) {
47       UniquePtr<Nanoapp> nanoapp = kStaticNanoappList[i]();
48       EventLoopManagerSingleton::get()->getEventLoop().startNanoapp(nanoapp);
49     }
50   }
51 }
52 
53 }  // namespace chre
54