• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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 #define LOG_TAG "isAtLeastRelease"
18 
19 #include <android/api-level.h>
20 #include <android-base/properties.h>
21 #include <utils/Log.h>
22 
23 #include <mutex>
24 #include <string>
25 
26 // current SDK for this device; filled in when initializing the parser.
27 static int mySdk = 0;
28 static std::string myCodeName;
29 
30 // to help address b/388925029
31 
32 /**
33  * support code so a plugin (currently the APV codecs) can self-manage
34  * whether it is running on a sufficiently new code base.
35  *
36  * this is here because the XMLparser for Media codec definitions has
37  * an off-by-one error in how it handles <MediaCodec name=".." ... minsdk="" >
38  *
39  * we will want to fix that starting in Android B/16, but devices in Android V/15
40  * still have issues [and we build the codecs into module code so that it goes back
41  * to older releases].
42  *
43  */
44 
isAtLeastRelease(int minsdk,const char * codename)45 bool isAtLeastRelease(int minsdk, const char *codename) {
46 
47     static std::once_flag sCheckOnce;
48     std::call_once(sCheckOnce, [&](){
49         mySdk = android_get_device_api_level();
50         myCodeName  = android::base::GetProperty("ro.build.version.codename", "<none>");
51     });
52 
53     bool satisfied = false;
54     ALOGI("device sdk %d, minsdk %d", mySdk, minsdk);
55     if (mySdk >= minsdk) {
56         satisfied = true;
57     }
58 
59     // allow the called to skip the codename.
60     if (codename != nullptr) {
61         ALOGI("active codename %s, to match %s", myCodeName.c_str(), codename);
62         if (myCodeName == codename) {
63             satisfied = true;
64         }
65     }
66 
67     return satisfied;
68 }
69