Merge "Allow light HAL to exit if it's a lazy HAL"
This commit is contained in:
@@ -39,37 +39,7 @@ using Type = ::android::hardware::light::V2_0::Type;
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
using Return = ::android::hardware::Return<T>;
|
using Return = ::android::hardware::Return<T>;
|
||||||
|
|
||||||
class LightHal {
|
static bool sLightSupported = true;
|
||||||
private:
|
|
||||||
static sp<ILight> sLight;
|
|
||||||
static bool sLightInit;
|
|
||||||
|
|
||||||
LightHal() {}
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void disassociate() {
|
|
||||||
sLightInit = false;
|
|
||||||
sLight = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static sp<ILight> associate() {
|
|
||||||
if ((sLight == nullptr && !sLightInit) ||
|
|
||||||
(sLight != nullptr && !sLight->ping().isOk())) {
|
|
||||||
// will return the hal if it exists the first time.
|
|
||||||
sLight = ILight::getService();
|
|
||||||
sLightInit = true;
|
|
||||||
|
|
||||||
if (sLight == nullptr) {
|
|
||||||
ALOGE("Unable to get ILight interface.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sLight;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
sp<ILight> LightHal::sLight = nullptr;
|
|
||||||
bool LightHal::sLightInit = false;
|
|
||||||
|
|
||||||
static bool validate(jint light, jint flash, jint brightness) {
|
static bool validate(jint light, jint flash, jint brightness) {
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
@@ -134,7 +104,6 @@ static void processReturn(
|
|||||||
const LightState &state) {
|
const LightState &state) {
|
||||||
if (!ret.isOk()) {
|
if (!ret.isOk()) {
|
||||||
ALOGE("Failed to issue set light command.");
|
ALOGE("Failed to issue set light command.");
|
||||||
LightHal::disassociate();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,13 +133,11 @@ static void setLight_native(
|
|||||||
jint offMS,
|
jint offMS,
|
||||||
jint brightnessMode) {
|
jint brightnessMode) {
|
||||||
|
|
||||||
if (!validate(light, flashMode, brightnessMode)) {
|
if (!sLightSupported) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sp<ILight> hal = LightHal::associate();
|
if (!validate(light, flashMode, brightnessMode)) {
|
||||||
|
|
||||||
if (hal == nullptr) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,6 +147,11 @@ static void setLight_native(
|
|||||||
|
|
||||||
{
|
{
|
||||||
android::base::Timer t;
|
android::base::Timer t;
|
||||||
|
sp<ILight> hal = ILight::getService();
|
||||||
|
if (hal == nullptr) {
|
||||||
|
sLightSupported = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
Return<Status> ret = hal->setLight(type, state);
|
Return<Status> ret = hal->setLight(type, state);
|
||||||
processReturn(ret, type, state);
|
processReturn(ret, type, state);
|
||||||
if (t.duration() > 50ms) ALOGD("Excessive delay setting light");
|
if (t.duration() > 50ms) ALOGD("Excessive delay setting light");
|
||||||
|
|||||||
Reference in New Issue
Block a user