• 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/platform/shared/nanoapp_dso_util.h"
18 
19 #include <chre/version.h>
20 #include <cinttypes>
21 #include <cstring>
22 
23 #include "chre/platform/log.h"
24 
25 namespace chre {
26 
validateAppInfo(uint64_t expectedAppId,uint32_t expectedAppVersion,const struct chreNslNanoappInfo * appInfo)27 bool validateAppInfo(uint64_t expectedAppId, uint32_t expectedAppVersion,
28                      const struct chreNslNanoappInfo *appInfo) {
29   uint32_t ourApiMajorVersion = CHRE_EXTRACT_MAJOR_VERSION(chreGetApiVersion());
30   uint32_t targetApiMajorVersion =
31       CHRE_EXTRACT_MAJOR_VERSION(appInfo->targetApiVersion);
32 
33   bool success = false;
34   if (appInfo->magic != CHRE_NSL_NANOAPP_INFO_MAGIC) {
35     LOGE("Invalid app info magic: got 0x%08" PRIx32 " expected 0x%08" PRIx32,
36          appInfo->magic, static_cast<uint32_t>(CHRE_NSL_NANOAPP_INFO_MAGIC));
37   } else if (appInfo->appId == 0) {
38     LOGE("Rejecting invalid app ID 0");
39   } else if (expectedAppId != 0 && expectedAppId != appInfo->appId) {
40     LOGE("Expected app ID (0x%016" PRIx64
41          ") doesn't match internal one (0x%016" PRIx64 ")",
42          expectedAppId, appInfo->appId);
43   } else if (expectedAppVersion != appInfo->appVersion) {
44     LOGE("Expected app version (0x%" PRIx32
45          ") doesn't match internal one (0x%" PRIx32 ")",
46          expectedAppVersion, appInfo->appVersion);
47   } else if (targetApiMajorVersion != ourApiMajorVersion) {
48     LOGE("App targets a different major API version (%" PRIu32
49          ") than what we provide (%" PRIu32 ")",
50          targetApiMajorVersion, ourApiMajorVersion);
51   } else if (strlen(appInfo->name) > CHRE_NSL_DSO_NANOAPP_STRING_MAX_LEN) {
52     LOGE("App name is too long");
53   } else if (strlen(appInfo->vendor) > CHRE_NSL_DSO_NANOAPP_STRING_MAX_LEN) {
54     LOGE("App vendor is too long");
55   } else {
56     success = true;
57   }
58 
59   return success;
60 }
61 
62 }  // namespace chre
63