-
Notifications
You must be signed in to change notification settings - Fork 1
/
Utils.cpp
64 lines (55 loc) · 1.99 KB
/
Utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Utils.h"
#include <hwbinder/HidlSupport.h>
#include <string.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
namespace android::hardware {
void zeroMemory(uint8_t* data, size_t size) {
memset(data, 0, size);
}
static bool isHwServiceManagerInstalled() {
return access("/system_ext/bin/hwservicemanager", F_OK) == 0 ||
access("/system/system_ext/bin/hwservicemanager", F_OK) == 0 ||
access("/system/bin/hwservicemanager", F_OK) == 0;
}
static bool waitForHwServiceManager() {
if (!isHwServiceManagerInstalled()) {
return false;
}
// TODO(b/31559095): need bionic host so that we can use 'prop_info' returned
// from WaitForProperty
#ifdef __ANDROID__
static const char* kHwServicemanagerReadyProperty = "hwservicemanager.ready";
using std::literals::chrono_literals::operator""s;
using android::base::WaitForProperty;
while (true) {
if (base::GetBoolProperty("hwservicemanager.disabled", false)) {
return false;
}
if (WaitForProperty(kHwServicemanagerReadyProperty, "true", 1s)) {
return true;
}
LOG(WARNING) << "Waited for hwservicemanager.ready for a second, waiting another...";
}
#endif // __ANDROID__
return true;
}
bool isHwbinderSupportedBlocking() {
return waitForHwServiceManager();
}
} // namespace android::hardware