Use optional for nullable types
AIDL generates optional<T> for nullable T types for C++, which is more efficient and idomatic and easy to use. Bug: 144773267 Test: build/flash/boot Change-Id: Iac0c34e10bc09f1230d0a941b05618671cbcbb5e
This commit is contained in:
parent
067e1194a3
commit
78ac2cc2b4
48
server.cpp
48
server.cpp
|
@ -39,6 +39,7 @@ using android::net::wifi::nl80211::DeviceWiphyCapabilities;
|
|||
using android::wifi_system::InterfaceTool;
|
||||
|
||||
using std::endl;
|
||||
using std::optional;
|
||||
using std::placeholders::_1;
|
||||
using std::string;
|
||||
using std::stringstream;
|
||||
|
@ -241,7 +242,7 @@ void Server::MarkDownAllInterfaces() {
|
|||
}
|
||||
|
||||
Status Server::getAvailable2gChannels(
|
||||
std::unique_ptr<vector<int32_t>>* out_frequencies) {
|
||||
std::optional<vector<int32_t>>* out_frequencies) {
|
||||
BandInfo band_info;
|
||||
ScanCapabilities scan_capabilities_ignored;
|
||||
WiphyFeatures wiphy_features_ignored;
|
||||
|
@ -250,17 +251,16 @@ Status Server::getAvailable2gChannels(
|
|||
&scan_capabilities_ignored,
|
||||
&wiphy_features_ignored)) {
|
||||
LOG(ERROR) << "Failed to get wiphy info from kernel";
|
||||
out_frequencies->reset(nullptr);
|
||||
out_frequencies->reset();
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
out_frequencies->reset(
|
||||
new vector<int32_t>(band_info.band_2g.begin(), band_info.band_2g.end()));
|
||||
out_frequencies->emplace(band_info.band_2g.begin(), band_info.band_2g.end());
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status Server::getAvailable5gNonDFSChannels(
|
||||
std::unique_ptr<vector<int32_t>>* out_frequencies) {
|
||||
std::optional<vector<int32_t>>* out_frequencies) {
|
||||
BandInfo band_info;
|
||||
ScanCapabilities scan_capabilities_ignored;
|
||||
WiphyFeatures wiphy_features_ignored;
|
||||
|
@ -269,17 +269,16 @@ Status Server::getAvailable5gNonDFSChannels(
|
|||
&scan_capabilities_ignored,
|
||||
&wiphy_features_ignored)) {
|
||||
LOG(ERROR) << "Failed to get wiphy info from kernel";
|
||||
out_frequencies->reset(nullptr);
|
||||
out_frequencies->reset();
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
out_frequencies->reset(
|
||||
new vector<int32_t>(band_info.band_5g.begin(), band_info.band_5g.end()));
|
||||
out_frequencies->emplace(band_info.band_5g.begin(), band_info.band_5g.end());
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status Server::getAvailableDFSChannels(
|
||||
std::unique_ptr<vector<int32_t>>* out_frequencies) {
|
||||
std::optional<vector<int32_t>>* out_frequencies) {
|
||||
BandInfo band_info;
|
||||
ScanCapabilities scan_capabilities_ignored;
|
||||
WiphyFeatures wiphy_features_ignored;
|
||||
|
@ -288,17 +287,17 @@ Status Server::getAvailableDFSChannels(
|
|||
&scan_capabilities_ignored,
|
||||
&wiphy_features_ignored)) {
|
||||
LOG(ERROR) << "Failed to get wiphy info from kernel";
|
||||
out_frequencies->reset(nullptr);
|
||||
out_frequencies->reset();
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
out_frequencies->reset(new vector<int32_t>(band_info.band_dfs.begin(),
|
||||
band_info.band_dfs.end()));
|
||||
out_frequencies->emplace(band_info.band_dfs.begin(),
|
||||
band_info.band_dfs.end());
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status Server::getAvailable6gChannels(
|
||||
std::unique_ptr<vector<int32_t>>* out_frequencies) {
|
||||
std::optional<vector<int32_t>>* out_frequencies) {
|
||||
BandInfo band_info;
|
||||
ScanCapabilities scan_capabilities_ignored;
|
||||
WiphyFeatures wiphy_features_ignored;
|
||||
|
@ -307,18 +306,17 @@ Status Server::getAvailable6gChannels(
|
|||
&scan_capabilities_ignored,
|
||||
&wiphy_features_ignored)) {
|
||||
LOG(ERROR) << "Failed to get wiphy info from kernel";
|
||||
out_frequencies->reset(nullptr);
|
||||
out_frequencies->reset();
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
out_frequencies->reset(
|
||||
new vector<int32_t>(band_info.band_6g.begin(), band_info.band_6g.end()));
|
||||
out_frequencies->emplace(band_info.band_6g.begin(), band_info.band_6g.end());
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status Server::getDeviceWiphyCapabilities(
|
||||
const std::string& iface_name,
|
||||
std::unique_ptr<DeviceWiphyCapabilities>* capabilities) {
|
||||
std::optional<DeviceWiphyCapabilities>* capabilities) {
|
||||
if (!RefreshWiphyIndex(iface_name)) {
|
||||
capabilities = nullptr;
|
||||
return Status::ok();
|
||||
|
@ -336,15 +334,15 @@ Status Server::getDeviceWiphyCapabilities(
|
|||
return Status::ok();
|
||||
}
|
||||
|
||||
capabilities->reset(new DeviceWiphyCapabilities());
|
||||
capabilities->emplace();
|
||||
|
||||
capabilities->get()->is80211nSupported_ = band_info.is_80211n_supported;
|
||||
capabilities->get()->is80211acSupported_ = band_info.is_80211ac_supported;
|
||||
capabilities->get()->is80211axSupported_ = band_info.is_80211ax_supported;
|
||||
capabilities->get()->is160MhzSupported_ = band_info.is_160_mhz_supported;
|
||||
capabilities->get()->is80p80MhzSupported_ = band_info.is_80p80_mhz_supported;
|
||||
capabilities->get()->maxTxStreams_ = band_info.max_tx_streams;
|
||||
capabilities->get()->maxRxStreams_ = band_info.max_rx_streams;
|
||||
capabilities->value().is80211nSupported_ = band_info.is_80211n_supported;
|
||||
capabilities->value().is80211acSupported_ = band_info.is_80211ac_supported;
|
||||
capabilities->value().is80211axSupported_ = band_info.is_80211ax_supported;
|
||||
capabilities->value().is160MhzSupported_ = band_info.is_160_mhz_supported;
|
||||
capabilities->value().is80p80MhzSupported_ = band_info.is_80p80_mhz_supported;
|
||||
capabilities->value().maxTxStreams_ = band_info.max_tx_streams;
|
||||
capabilities->value().maxRxStreams_ = band_info.max_rx_streams;
|
||||
|
||||
return Status::ok();
|
||||
}
|
||||
|
|
10
server.h
10
server.h
|
@ -56,16 +56,16 @@ class Server : public android::net::wifi::nl80211::BnWificond {
|
|||
callback) override;
|
||||
// Returns a vector of available frequencies for 2.4GHz channels.
|
||||
android::binder::Status getAvailable2gChannels(
|
||||
::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
|
||||
::std::optional<::std::vector<int32_t>>* out_frequencies) override;
|
||||
// Returns a vector of available frequencies for 5GHz non-DFS channels.
|
||||
android::binder::Status getAvailable5gNonDFSChannels(
|
||||
::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
|
||||
::std::optional<::std::vector<int32_t>>* out_frequencies) override;
|
||||
// Returns a vector of available frequencies for DFS channels.
|
||||
android::binder::Status getAvailableDFSChannels(
|
||||
::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
|
||||
::std::optional<::std::vector<int32_t>>* out_frequencies) override;
|
||||
// Returns a vector of available frequencies for 6GHz channels.
|
||||
android::binder::Status getAvailable6gChannels(
|
||||
::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
|
||||
::std::optional<::std::vector<int32_t>>* out_frequencies) override;
|
||||
|
||||
android::binder::Status createApInterface(
|
||||
const std::string& iface_name,
|
||||
|
@ -96,7 +96,7 @@ class Server : public android::net::wifi::nl80211::BnWificond {
|
|||
// Returns device wiphy capabilities for an interface
|
||||
android::binder::Status getDeviceWiphyCapabilities(
|
||||
const std::string& iface_name,
|
||||
::std::unique_ptr<net::wifi::nl80211::DeviceWiphyCapabilities>* capabilities) override;
|
||||
::std::optional<net::wifi::nl80211::DeviceWiphyCapabilities>* capabilities) override;
|
||||
|
||||
private:
|
||||
// Request interface information from kernel and setup local interface object.
|
||||
|
|
Loading…
Reference in New Issue