summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-10 07:05:36 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-10 07:05:36 +0000
commit7561e720e9c20ddd4c01d749017b9558aea16c15 (patch)
treeacc3454a8dcf5518a2d717fb43d6cfa19cd34ac5
parent75a32633b8fce7c03ee778bb97c0c2b3c2341fc3 (diff)
parent9bd4a7ddb2d7623ceb4c13e5d3e2702520d7ae94 (diff)
downloadlibhardware_legacy-android13-mainline-permission-release.tar.gz
Change-Id: I2773d144e519d5c670a518aac6761f4e3a40509f
-rw-r--r--Android.bp13
-rw-r--r--Android.mk1
-rw-r--r--include/hardware_legacy/link_layer_stats.h8
-rw-r--r--include/hardware_legacy/rtt.h8
-rw-r--r--include/hardware_legacy/wifi_hal.h141
-rw-r--r--include/hardware_legacy/wifi_nan.h68
-rw-r--r--power.cpp75
7 files changed, 267 insertions, 47 deletions
diff --git a/Android.bp b/Android.bp
index c10cff3..7be18c7 100644
--- a/Android.bp
+++ b/Android.bp
@@ -40,11 +40,16 @@ cc_library {
defaults: ["libpower_defaults"],
srcs: ["power.cpp"],
export_include_dirs: ["include"],
- shared_libs: ["android.system.suspend@1.0"],
+ shared_libs: ["android.system.suspend-V1-ndk"],
vendor_available: true,
vndk: {
enabled: true,
},
+ apex_available: [
+ "//apex_available:platform",
+ "com.android.uwb",
+ ],
+ min_sdk_version: "Tiramisu",
}
cc_test {
@@ -54,7 +59,7 @@ cc_test {
static_libs: ["libpower"],
shared_libs: [
"android.system.suspend.control.internal-cpp",
- "android.system.suspend@1.0",
+ "android.system.suspend-V1-ndk",
],
test_suites: ["device-tests"],
require_root: true,
@@ -69,7 +74,7 @@ cc_library_shared {
},
shared_libs: [
- "android.system.suspend@1.0",
+ "android.system.suspend-V1-ndk",
"libdl",
],
@@ -98,7 +103,7 @@ cc_test {
srcs: ["block_suspend.cpp"],
static_libs: ["libpower"],
shared_libs: [
- "android.system.suspend@1.0",
+ "android.system.suspend-V1-ndk",
],
gtest: false,
}
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..e019b18
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1 @@
+$(eval $(call declare-1p-copy-files,hardware/libhardware_legacy,))
diff --git a/include/hardware_legacy/link_layer_stats.h b/include/hardware_legacy/link_layer_stats.h
index 9b67f6d..bac84e1 100644
--- a/include/hardware_legacy/link_layer_stats.h
+++ b/include/hardware_legacy/link_layer_stats.h
@@ -61,7 +61,7 @@ typedef struct {
/* channel information */
typedef struct {
- wifi_channel_width width; // channel width (20, 40, 80, 80+80, 160)
+ wifi_channel_width width; // channel width (20, 40, 80, 80+80, 160, 320)
wifi_channel center_freq; // primary 20 MHz channel
wifi_channel center_freq0; // center frequency (MHz) first segment
wifi_channel center_freq1; // center frequency (MHz) second segment
@@ -69,11 +69,11 @@ typedef struct {
/* wifi rate */
typedef struct {
- u32 preamble :3; // 0: OFDM, 1:CCK, 2:HT 3:VHT 4:HE 5..7 reserved
+ u32 preamble :3; // 0: OFDM, 1:CCK, 2:HT 3:VHT 4:HE 5:EHT 6..7 reserved
u32 nss :2; // 0:1x1, 1:2x2, 3:3x3, 4:4x4
- u32 bw :3; // 0:20MHz, 1:40Mhz, 2:80Mhz, 3:160Mhz
+ u32 bw :3; // 0:20MHz, 1:40Mhz, 2:80Mhz, 3:160Mhz 4:320Mhz
u32 rateMcsIdx :8; // OFDM/CCK rate code would be as per ieee std in the units of 0.5mbps
- // HT/VHT/HE it would be mcs index
+ // HT/VHT/HE/EHT it would be mcs index
u32 reserved :16; // reserved
u32 bitrate; // units of 100 Kbps
} wifi_rate;
diff --git a/include/hardware_legacy/rtt.h b/include/hardware_legacy/rtt.h
index 5084bec..4ef7770 100644
--- a/include/hardware_legacy/rtt.h
+++ b/include/hardware_legacy/rtt.h
@@ -43,7 +43,8 @@ typedef enum {
WIFI_RTT_BW_20 = 0x04,
WIFI_RTT_BW_40 = 0x08,
WIFI_RTT_BW_80 = 0x10,
- WIFI_RTT_BW_160 = 0x20
+ WIFI_RTT_BW_160 = 0x20,
+ WIFI_RTT_BW_320 = 0x40
} wifi_rtt_bw;
/* RTT Measurement Preamble */
@@ -51,7 +52,8 @@ typedef enum {
WIFI_RTT_PREAMBLE_LEGACY = 0x1,
WIFI_RTT_PREAMBLE_HT = 0x2,
WIFI_RTT_PREAMBLE_VHT = 0x4,
- WIFI_RTT_PREAMBLE_HE = 0x8
+ WIFI_RTT_PREAMBLE_HE = 0x8,
+ WIFI_RTT_PREAMBLE_EHT = 0x10,
} wifi_rtt_preamble;
/* RTT Type */
@@ -186,6 +188,7 @@ wifi_error wifi_rtt_channel_map_clear(wifi_request_id id, wifi_interface_handle
#define PREAMBLE_HT 0x2
#define PREAMBLE_VHT 0x4
#define PREAMBLE_HE 0x8
+#define PREAMBLE_EHT 0x10
// BW definition for bit mask used in wifi_rtt_capabilities
#define BW_5_SUPPORT 0x1
@@ -194,6 +197,7 @@ wifi_error wifi_rtt_channel_map_clear(wifi_request_id id, wifi_interface_handle
#define BW_40_SUPPORT 0x8
#define BW_80_SUPPORT 0x10
#define BW_160_SUPPORT 0x20
+#define BW_320_SUPPORT 0x40
/* RTT Capabilities */
typedef struct {
diff --git a/include/hardware_legacy/wifi_hal.h b/include/hardware_legacy/wifi_hal.h
index 81948d6..952e894 100644
--- a/include/hardware_legacy/wifi_hal.h
+++ b/include/hardware_legacy/wifi_hal.h
@@ -60,6 +60,7 @@ typedef enum {
WIFI_CHAN_WIDTH_80P80 = 4,
WIFI_CHAN_WIDTH_5 = 5,
WIFI_CHAN_WIDTH_10 = 6,
+ WIFI_CHAN_WIDTH_320 = 7,
WIFI_CHAN_WIDTH_INVALID = -1
} wifi_channel_width;
@@ -80,6 +81,18 @@ typedef enum {
WIFI_POWER_SCENARIO_ON_BODY_HOTSPOT_BT = 10,
WIFI_POWER_SCENARIO_ON_BODY_HOTSPOT_MMW = 11,
WIFI_POWER_SCENARIO_ON_BODY_HOTSPOT_BT_MMW = 12,
+ WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF_UNFOLDED = 13,
+ WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON_UNFOLDED = 14,
+ WIFI_POWER_SCENARIO_ON_HEAD_HOTSPOT_UNFOLDED = 15,
+ WIFI_POWER_SCENARIO_ON_HEAD_HOTSPOT_MMW_UNFOLDED = 16,
+ WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF_UNFOLDED = 17,
+ WIFI_POWER_SCENARIO_ON_BODY_BT_UNFOLDED = 18,
+ WIFI_POWER_SCENARIO_ON_BODY_CELL_ON_UNFOLDED = 19,
+ WIFI_POWER_SCENARIO_ON_BODY_CELL_ON_BT_UNFOLDED = 20,
+ WIFI_POWER_SCENARIO_ON_BODY_HOTSPOT_UNFOLDED = 21,
+ WIFI_POWER_SCENARIO_ON_BODY_HOTSPOT_BT_UNFOLDED = 22,
+ WIFI_POWER_SCENARIO_ON_BODY_HOTSPOT_MMW_UNFOLDED = 23,
+ WIFI_POWER_SCENARIO_ON_BODY_HOTSPOT_BT_MMW_UNFOLDED = 24,
} wifi_power_scenario;
typedef enum {
@@ -128,6 +141,13 @@ typedef enum {
WLAN_MAC_60_0_BAND = 1 << 3,
} wlan_mac_band;
+/* List of chre nan rtt state */
+typedef enum {
+ CHRE_PREEMPTED = 0,
+ CHRE_UNAVAILABLE = 1,
+ CHRE_AVAILABLE = 2,
+} chre_nan_rtt_state;
+
typedef struct {
wifi_channel_width width;
int center_frequency0;
@@ -142,7 +162,7 @@ typedef struct {
typedef struct {
/* Channel frequency in MHz */
wifi_channel freq;
- /* Channel operating width (20, 40, 80, 160 etc.) */
+ /* Channel operating width (20, 40, 80, 160, 320 etc.) */
wifi_channel_width width;
/* BIT MASK of BIT(WIFI_INTERFACE_*) represented by |wifi_interface_mode|
* Bitmask does not represent concurrency.
@@ -180,6 +200,14 @@ typedef enum {
* P2P GO may be supported by some vendors on the same STA channel.
*/
WIFI_USABLE_CHANNEL_FILTER_CONCURRENCY = 1 << 1,
+ /* This Filter queries Wifi channels and bands that are supported for
+ * NAN3.1 Instant communication mode. This filter should only be applied to NAN interface.
+ * If 5G is supported default discovery channel 149/44 is considered,
+ * If 5G is not supported then channel 6 has to be considered.
+ * Based on regulatory domain if channel 149 and 44 are restricted, channel 6 should
+ * be considered for instant communication channel
+ */
+ WIFI_USABLE_CHANNEL_FILTER_NAN_INSTANT_MODE = 1 << 2,
} wifi_usable_channel_filter;
typedef enum {
@@ -204,6 +232,50 @@ typedef enum {
WIFI_ACCESS_CATEGORY_VOICE = 3
} wifi_access_category;
+/* Antenna configuration */
+typedef enum {
+ WIFI_ANTENNA_UNSPECIFIED = 0,
+ WIFI_ANTENNA_1X1 = 1,
+ WIFI_ANTENNA_2X2 = 2,
+ WIFI_ANTENNA_3X3 = 3,
+ WIFI_ANTENNA_4X4 = 4,
+} wifi_antenna_configuration;
+
+/* Wifi Radio configuration */
+typedef struct {
+ /* Operating band */
+ wlan_mac_band band;
+ /* Antenna configuration */
+ wifi_antenna_configuration antenna_cfg;
+} wifi_radio_configuration;
+
+/* WiFi Radio Combination */
+typedef struct {
+ u32 num_radio_configurations;
+ wifi_radio_configuration radio_configurations[];
+} wifi_radio_combination;
+
+/* WiFi Radio combinations matrix */
+/* For Example in case of a chip which has two radios, where one radio is
+ * capable of 2.4GHz 2X2 only and another radio which is capable of either
+ * 5GHz or 6GHz 2X2, number of possible radio combinations in this case
+ * are 5 and possible combinations are
+ * {{{2G 2X2}}, //Standalone 2G
+ * {{5G 2X2}}, //Standalone 5G
+ * {{6G 2X2}}, //Standalone 6G
+ * {{2G 2X2}, {5G 2X2}}, //2G+5G DBS
+ * {{2G 2X2}, {6G 2X2}}} //2G+6G DBS
+ * Note: Since this chip doesn’t support 5G+6G simultaneous operation
+ * as there is only one radio which can support both, So it can only
+ * do MCC 5G+6G. This table should not get populated with possible MCC
+ * configurations. This is only for simultaneous radio configurations
+ * (such as Standalone, multi band simultaneous or single band simultaneous).
+ */
+typedef struct {
+ u32 num_radio_combinations;
+ /* Each row represents possible radio combinations */
+ wifi_radio_combination radio_combinations[];
+} wifi_radio_combination_matrix;
/* Initialize/Cleanup */
@@ -255,6 +327,7 @@ void wifi_get_error_info(wifi_error err, const char **msg); // return a pointer
#define WIFI_FEATURE_SCAN_RAND (uint64_t)0x2000000 // Support MAC & Probe Sequence Number randomization
#define WIFI_FEATURE_SET_TX_POWER_LIMIT (uint64_t)0x4000000 // Support Tx Power Limit setting
#define WIFI_FEATURE_USE_BODY_HEAD_SAR (uint64_t)0x8000000 // Support Using Body/Head Proximity for SAR
+#define WIFI_FEATURE_DYNAMIC_SET_MAC (uint64_t)0x10000000 // Support changing MAC address without iface reset(down and up)
#define WIFI_FEATURE_SET_LATENCY_MODE (uint64_t)0x40000000 // Support Latency mode setting
#define WIFI_FEATURE_P2P_RAND_MAC (uint64_t)0x80000000 // Support P2P MAC randomization
#define WIFI_FEATURE_INFRA_60G (uint64_t)0x100000000 // Support for 60GHz Band
@@ -379,6 +452,10 @@ typedef struct {
void (*on_subsystem_restart)(const char* error);
} wifi_subsystem_restart_handler;
+typedef struct {
+ void (*on_chre_nan_rtt_change)(chre_nan_rtt_state state);
+} wifi_chre_handler;
+
wifi_error wifi_set_iface_event_handler(wifi_request_id id, wifi_interface_handle iface, wifi_event_handler eh);
wifi_error wifi_reset_iface_event_handler(wifi_request_id id, wifi_interface_handle iface);
@@ -887,6 +964,68 @@ typedef struct {
* Trigger wifi subsystem restart to reload firmware
*/
wifi_error (*wifi_trigger_subsystem_restart)(wifi_handle handle);
+
+ /**
+ * Invoked to set that the device is operating in an indoor environment.
+ * @param handle global wifi_handle
+ * @param isIndoor: true if the device is operating in an indoor
+ * environment, false otherwise.
+ * @return Synchronous wifi_error
+ */
+ wifi_error (*wifi_set_indoor_state)(wifi_handle handle, bool isIndoor);
+
+ /**@brief wifi_get_supported_radio_combinations_matrix
+ * Request all the possible radio combinations this device can offer.
+ * @param handle global wifi_handle
+ * @param max_size maximum size allocated for filling the wifi_radio_combination_matrix
+ * @param wifi_radio_combination_matrix to return all the possible radio
+ * combinations.
+ * @param size actual size of wifi_radio_combination_matrix returned from
+ * lower layer
+ *
+ */
+ wifi_error (*wifi_get_supported_radio_combinations_matrix)(
+ wifi_handle handle, u32 max_size, u32 *size,
+ wifi_radio_combination_matrix *radio_combination_matrix);
+
+ /**@brief wifi_nan_rtt_chre_enable_request
+ * Request to enable CHRE NAN RTT
+ * @param transaction_id: NAN transaction id
+ * @param wifi_interface_handle
+ * @param NanEnableRequest request message
+ * @return Synchronous wifi_error
+ */
+ wifi_error (*wifi_nan_rtt_chre_enable_request)(transaction_id id,
+ wifi_interface_handle iface,
+ NanEnableRequest* msg);
+
+ /**@brief wifi_nan_rtt_chre_disable_request
+ * Request to disable CHRE NAN RTT
+ * @param transaction_id: NAN transaction id
+ * @param wifi_interface_handle
+ * @return Synchronous wifi_error
+ */
+ wifi_error (*wifi_nan_rtt_chre_disable_request)(transaction_id id, wifi_interface_handle iface);
+
+ /**@brief wifi_chre_register_handler
+ * register a handler to get the state of CHR
+ * @param wifi_interface_handle
+ * @param wifi_chre_handler: callback function pointer
+ * @return Synchronous wifi_error
+ */
+ wifi_error (*wifi_chre_register_handler)(wifi_interface_handle iface,
+ wifi_chre_handler handler);
+
+ /**@brief wifi_enable_tx_power_limits
+ * Enable WiFi Tx power limis
+ * @param wifi_interface_handle
+ * @param isEnable : If enable TX limit or not
+ * @return Synchronous wifi_error
+ */
+ wifi_error (*wifi_enable_tx_power_limits) (wifi_interface_handle iface,
+ bool isEnable);
+
+
/*
* when adding new functions make sure to add stubs in
* hal_tool.cpp::init_wifi_stub_hal_func_table
diff --git a/include/hardware_legacy/wifi_nan.h b/include/hardware_legacy/wifi_nan.h
index 1fb7138..8437a1d 100644
--- a/include/hardware_legacy/wifi_nan.h
+++ b/include/hardware_legacy/wifi_nan.h
@@ -305,10 +305,12 @@ typedef struct {
} body;
} NanSecurityKeyInfo;
-/* NAN Shared Key Security Cipher Suites Mask */
-#define NAN_CIPHER_SUITE_SHARED_KEY_NONE 0x00
-#define NAN_CIPHER_SUITE_SHARED_KEY_128_MASK 0x01
-#define NAN_CIPHER_SUITE_SHARED_KEY_256_MASK 0x02
+/* NAN Security Cipher Suites Mask */
+#define NAN_CIPHER_SUITE_SHARED_KEY_NONE 0x00
+#define NAN_CIPHER_SUITE_SHARED_KEY_128_MASK 0x01
+#define NAN_CIPHER_SUITE_SHARED_KEY_256_MASK 0x02
+#define NAN_CIPHER_SUITE_PUBLIC_KEY_2WDH_128_MASK 0x04
+#define NAN_CIPHER_SUITE_PUBLIC_KEY_2WDH_256_MASK 0x08
/* NAN ranging indication condition MASKS */
#define NAN_RANGING_INDICATE_CONTINUOUS_MASK 0x01
@@ -1041,6 +1043,17 @@ typedef struct {
*/
u8 config_enable_instant_mode;
u32 enable_instant_mode;
+ /*
+ Config NAN v3.1 instant communication channel frequency selected over NFC/OOB method.
+ If dual band is supported default channel is 149 or 44 as per regulatory domain,
+ else channel 6 (send frequency in MHz).
+ Sometimes depending on country code retrictions, even 149/44 may be restricted
+ in those cases instant channel will be operational only in 2.4GHz.
+ Use wifi_get_usable_channels() API to get supported bands/channels before
+ Instant mode NFC handshake is triggered
+ */
+ u8 config_instant_mode_channel;
+ wifi_channel instant_mode_channel;
} NanEnableRequest;
/*
@@ -1533,6 +1546,17 @@ typedef struct {
*/
u8 config_enable_instant_mode;
u32 enable_instant_mode;
+ /*
+ Config NAN v3.1 instant communication channel selected over NFC/OOB method.
+ If dual band is supported default channel is 149 or 44 as per regulatory domain,
+ else channel 6 (send frequency in MHz).
+ Sometimes depending on country code retrictions, even 149/44 may be restricted
+ in those cases instant channel will be operational only in 2.4GHz.
+ Use wifi_get_usable_channels() API to get supported bands/channels before
+ Instant mode NFC handshake is triggered
+ */
+ u8 config_instant_mode_channel;
+ wifi_channel instant_mode_channel;
} NanConfigRequest;
/*
@@ -2223,6 +2247,18 @@ typedef struct {
is not associated with the NDP (out-of-band discovery).
*/
u8 service_name[NAN_MAX_SERVICE_NAME_LEN];
+
+ /* Security Context Identifiers length */
+ u32 scid_len;
+ /*
+ Security Context Identifier attribute contains PMKID
+ shall be included in NDP setup and response messages.
+ Security Context Identifier, Identifies the Security
+ Context. For NAN Shared Key Cipher Suite, this field
+ contains the 16 octet PMKID identifying the PMK used
+ for setting up the Secure Data Path.
+ */
+ u8 scid[NAN_MAX_SCID_BUF_LEN];
} NanDataPathInitiatorRequest;
/*
@@ -2263,6 +2299,18 @@ typedef struct {
is not associated with the NDP (out-of-band discovery).
*/
u8 service_name[NAN_MAX_SERVICE_NAME_LEN];
+
+ /* Security Context Identifiers length */
+ u32 scid_len;
+ /*
+ Security Context Identifier attribute contains PMKID
+ shall be included in NDP setup and response messages.
+ Security Context Identifier, Identifies the Security
+ Context. For NAN Shared Key Cipher Suite, this field
+ contains the 16 octet PMKID identifying the PMK used
+ for setting up the Secure Data Path.
+ */
+ u8 scid[NAN_MAX_SCID_BUF_LEN];
} NanDataPathIndicationResponse;
/* NDP termination info */
@@ -2298,6 +2346,18 @@ typedef struct {
NanDataPathCfg ndp_cfg;
/* App/Service information of the initiator */
NanDataPathAppInfo app_info;
+
+ /* Security Context Identifiers length */
+ u32 scid_len;
+ /*
+ Security Context Identifier attribute contains PMKID
+ shall be included in NDP setup and response messages.
+ Security Context Identifier, Identifies the Security
+ Context. For NAN Shared Key Cipher Suite, this field
+ contains the 16 octet PMKID identifying the PMK used
+ for setting up the Secure Data Path.
+ */
+ u8 scid[NAN_MAX_SCID_BUF_LEN];
} NanDataPathRequestInd;
/*
diff --git a/power.cpp b/power.cpp
index a39b32b..98ce861 100644
--- a/power.cpp
+++ b/power.cpp
@@ -20,8 +20,10 @@
#include <hardware_legacy/power.h>
#include <wakelock/wakelock.h>
+#include <aidl/android/system/suspend/ISystemSuspend.h>
+#include <aidl/android/system/suspend/IWakeLock.h>
+#include <android/binder_manager.h>
#include <android-base/logging.h>
-#include <android/system/suspend/1.0/ISystemSuspend.h>
#include <utils/Trace.h>
#include <mutex>
@@ -29,37 +31,40 @@
#include <thread>
#include <unordered_map>
-using android::sp;
-using android::system::suspend::V1_0::ISystemSuspend;
-using android::system::suspend::V1_0::IWakeLock;
-using android::system::suspend::V1_0::WakeLockType;
+using aidl::android::system::suspend::ISystemSuspend;
+using aidl::android::system::suspend::IWakeLock;
+using aidl::android::system::suspend::WakeLockType;
static std::mutex gLock;
-static std::unordered_map<std::string, sp<IWakeLock>> gWakeLockMap;
+static std::unordered_map<std::string, std::shared_ptr<IWakeLock>> gWakeLockMap;
-static const sp<ISystemSuspend>& getSystemSuspendServiceOnce() {
- static sp<ISystemSuspend> suspendService = ISystemSuspend::getService();
+static const std::shared_ptr<ISystemSuspend> getSystemSuspendServiceOnce() {
+ static std::shared_ptr<ISystemSuspend> suspendService =
+ ISystemSuspend::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService(
+ (ISystemSuspend::descriptor + std::string("/default")).c_str())));
return suspendService;
}
int acquire_wake_lock(int, const char* id) {
ATRACE_CALL();
- const auto& suspendService = getSystemSuspendServiceOnce();
+ const auto suspendService = getSystemSuspendServiceOnce();
if (!suspendService) {
- LOG(ERROR) << "ISystemSuspend::getService() failed.";
+ LOG(ERROR) << "Failed to get SystemSuspend service";
return -1;
}
std::lock_guard<std::mutex> l{gLock};
if (!gWakeLockMap[id]) {
- auto ret = suspendService->acquireWakeLock(WakeLockType::PARTIAL, id);
- // It's possible that during device shutdown SystemSuspend service has already exited. In
- // these situations HIDL calls to it will result in a DEAD_OBJECT transaction error. We
- // check for DEAD_OBJECT so that libpower clients can shutdown cleanly.
- if (ret.isDeadObject()) {
+ std::shared_ptr<IWakeLock> wl = nullptr;
+ auto status = suspendService->acquireWakeLock(WakeLockType::PARTIAL, id, &wl);
+ // It's possible that during device shutdown SystemSuspend service has already exited.
+ // Check that the wakelock object is not null.
+ if (!wl) {
+ LOG(ERROR) << "ISuspendService::acquireWakeLock() call failed: "
+ << status.getDescription();
return -1;
} else {
- gWakeLockMap[id] = ret;
+ gWakeLockMap[id] = wl;
}
}
return 0;
@@ -70,12 +75,12 @@ int release_wake_lock(const char* id) {
std::lock_guard<std::mutex> l{gLock};
if (gWakeLockMap[id]) {
// Ignore errors on release() call since hwbinder driver will clean up the underlying object
- // once we clear the corresponding strong pointer.
- auto ret = gWakeLockMap[id]->release();
- if (!ret.isOk()) {
- LOG(ERROR) << "IWakeLock::release() call failed: " << ret.description();
+ // once we clear the corresponding shared_ptr.
+ auto status = gWakeLockMap[id]->release();
+ if (!status.isOk()) {
+ LOG(ERROR) << "IWakeLock::release() call failed: " << status.getDescription();
}
- gWakeLockMap[id].clear();
+ gWakeLockMap[id] = nullptr;
return 0;
}
return -1;
@@ -91,7 +96,7 @@ class WakeLock::WakeLockImpl {
bool acquireOk();
private:
- sp<IWakeLock> mWakeLock;
+ std::shared_ptr<IWakeLock> mWakeLock;
};
std::optional<WakeLock> WakeLock::tryGet(const std::string& name) {
@@ -109,14 +114,20 @@ WakeLock::WakeLock(std::unique_ptr<WakeLockImpl> wlImpl) : mImpl(std::move(wlImp
WakeLock::~WakeLock() = default;
WakeLock::WakeLockImpl::WakeLockImpl(const std::string& name) : mWakeLock(nullptr) {
- static sp<ISystemSuspend> suspendService = ISystemSuspend::getService();
- auto ret = suspendService->acquireWakeLock(WakeLockType::PARTIAL, name);
- // It's possible that during device SystemSuspend service is not avaiable. In these
- // situations HIDL calls to it will result in a DEAD_OBJECT transaction error.
- if (ret.isDeadObject()) {
- LOG(ERROR) << "ISuspendService::acquireWakeLock() call failed: " << ret.description();
+ const auto suspendService = getSystemSuspendServiceOnce();
+ if (!suspendService) {
+ LOG(ERROR) << "Failed to get SystemSuspend service";
+ return;
+ }
+
+ std::shared_ptr<IWakeLock> wl = nullptr;
+ auto status = suspendService->acquireWakeLock(WakeLockType::PARTIAL, name, &wl);
+ // It's possible that during device shutdown SystemSuspend service has already exited.
+ // Check that the wakelock object is not null.
+ if (!wl) {
+ LOG(ERROR) << "ISuspendService::acquireWakeLock() call failed: " << status.getDescription();
} else {
- mWakeLock = ret;
+ mWakeLock = wl;
}
}
@@ -124,9 +135,9 @@ WakeLock::WakeLockImpl::~WakeLockImpl() {
if (!acquireOk()) {
return;
}
- auto ret = mWakeLock->release();
- if (!ret.isOk()) {
- LOG(ERROR) << "IWakeLock::release() call failed: " << ret.description();
+ auto status = mWakeLock->release();
+ if (!status.isOk()) {
+ LOG(ERROR) << "IWakeLock::release() call failed: " << status.getDescription();
}
}