Check mode/boost index before accessing cached support value
Bug: 174243830 Test: manual Change-Id: I2f81bcd57181791fa95d35ad52e6af2d7d9c8dcf Merged-In: If305a4b694a9d6fcc27da8279f1f53f9fd9cb685 Merged-In: I345d9ff828021da35556f2d51da512840dda8026
This commit is contained in:
@@ -190,19 +190,18 @@ static void setPowerBoostWithHandle(sp<IPowerAidl> handle, Boost boost, int32_t
|
|||||||
static std::array<std::atomic<HalSupport>,
|
static std::array<std::atomic<HalSupport>,
|
||||||
static_cast<int32_t>(Boost::DISPLAY_UPDATE_IMMINENT) + 1>
|
static_cast<int32_t>(Boost::DISPLAY_UPDATE_IMMINENT) + 1>
|
||||||
boostSupportedArray = {HalSupport::UNKNOWN};
|
boostSupportedArray = {HalSupport::UNKNOWN};
|
||||||
|
size_t idx = static_cast<size_t>(boost);
|
||||||
|
|
||||||
// Quick return if boost is not supported by HAL
|
// Quick return if boost is not supported by HAL
|
||||||
if (boost > Boost::DISPLAY_UPDATE_IMMINENT ||
|
if (idx >= boostSupportedArray.size() || boostSupportedArray[idx] == HalSupport::OFF) {
|
||||||
boostSupportedArray[static_cast<int32_t>(boost)] == HalSupport::OFF) {
|
|
||||||
ALOGV("Skipped setPowerBoost %s because HAL doesn't support it", toString(boost).c_str());
|
ALOGV("Skipped setPowerBoost %s because HAL doesn't support it", toString(boost).c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boostSupportedArray[static_cast<int32_t>(boost)] == HalSupport::UNKNOWN) {
|
if (boostSupportedArray[idx] == HalSupport::UNKNOWN) {
|
||||||
bool isSupported = false;
|
bool isSupported = false;
|
||||||
handle->isBoostSupported(boost, &isSupported);
|
handle->isBoostSupported(boost, &isSupported);
|
||||||
boostSupportedArray[static_cast<int32_t>(boost)] =
|
boostSupportedArray[idx] = isSupported ? HalSupport::ON : HalSupport::OFF;
|
||||||
isSupported ? HalSupport::ON : HalSupport::OFF;
|
|
||||||
if (!isSupported) {
|
if (!isSupported) {
|
||||||
ALOGV("Skipped setPowerBoost %s because HAL doesn't support it",
|
ALOGV("Skipped setPowerBoost %s because HAL doesn't support it",
|
||||||
toString(boost).c_str());
|
toString(boost).c_str());
|
||||||
@@ -230,19 +229,18 @@ static bool setPowerModeWithHandle(sp<IPowerAidl> handle, Mode mode, bool enable
|
|||||||
// Need to increase the array if more mode supported.
|
// Need to increase the array if more mode supported.
|
||||||
static std::array<std::atomic<HalSupport>, static_cast<int32_t>(Mode::DISPLAY_INACTIVE) + 1>
|
static std::array<std::atomic<HalSupport>, static_cast<int32_t>(Mode::DISPLAY_INACTIVE) + 1>
|
||||||
modeSupportedArray = {HalSupport::UNKNOWN};
|
modeSupportedArray = {HalSupport::UNKNOWN};
|
||||||
|
size_t idx = static_cast<size_t>(mode);
|
||||||
|
|
||||||
// Quick return if mode is not supported by HAL
|
// Quick return if mode is not supported by HAL
|
||||||
if (mode > Mode::DISPLAY_INACTIVE ||
|
if (idx >= modeSupportedArray.size() || modeSupportedArray[idx] == HalSupport::OFF) {
|
||||||
modeSupportedArray[static_cast<int32_t>(mode)] == HalSupport::OFF) {
|
|
||||||
ALOGV("Skipped setPowerMode %s because HAL doesn't support it", toString(mode).c_str());
|
ALOGV("Skipped setPowerMode %s because HAL doesn't support it", toString(mode).c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modeSupportedArray[static_cast<int32_t>(mode)] == HalSupport::UNKNOWN) {
|
if (modeSupportedArray[idx] == HalSupport::UNKNOWN) {
|
||||||
bool isSupported = false;
|
bool isSupported = false;
|
||||||
handle->isModeSupported(mode, &isSupported);
|
handle->isModeSupported(mode, &isSupported);
|
||||||
modeSupportedArray[static_cast<int32_t>(mode)] =
|
modeSupportedArray[idx] = isSupported ? HalSupport::ON : HalSupport::OFF;
|
||||||
isSupported ? HalSupport::ON : HalSupport::OFF;
|
|
||||||
if (!isSupported) {
|
if (!isSupported) {
|
||||||
ALOGV("Skipped setPowerMode %s because HAL doesn't support it", toString(mode).c_str());
|
ALOGV("Skipped setPowerMode %s because HAL doesn't support it", toString(mode).c_str());
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user