universal7885: parts-aidl: Implement new interface

This commit is contained in:
roynatech2544 2022-11-25 20:09:56 +09:00
commit e8bbe8517f
4 changed files with 102 additions and 12 deletions

View file

@ -14,6 +14,7 @@ cc_binary {
"libfileio", "libfileio",
"vendor.eureka.hardware.parts-V1-ndk", "vendor.eureka.hardware.parts-V1-ndk",
], ],
header_libs: ["logformat"],
init_rc: ["vendor.eureka.hardware.parts-service.rc"], init_rc: ["vendor.eureka.hardware.parts-service.rc"],
vintf_fragments: ["vendor.eureka.hardware.parts.xml"], vintf_fragments: ["vendor.eureka.hardware.parts.xml"],
} }

View file

@ -12,31 +12,118 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#define LOG_TAG "PartsHAL-Display"
#include "Display.h" #include "Display.h"
#include <functional>
#include <sstream>
#include <string> #include <string>
#include <FileIO.h> #include <FileIO.h>
#include <LogFormat.h>
namespace aidl::vendor::eureka::hardware::parts { namespace aidl::vendor::eureka::hardware::parts {
constexpr const char *SEC_TSP_CMD = "/sys/class/sec/tsp/cmd"; constexpr const char *SEC_TSP_CMD = "/sys/class/sec/tsp/cmd";
constexpr const char *SEC_TSP_CMD_RESULT = "/sys/class/sec/tsp/cmd_result";
static std::string DisplayStrBuilder(bool enable, DisplaySys type) {
std::stringstream builder;
switch (type) {
case DisplaySys::DOUBLE_TAP:
builder << "aot_enable";
break;
case DisplaySys::GLOVE_MODE:
builder << "glove_mode";
break;
};
builder << ",";
builder << enable; // Implicit conversion
return builder.str();
}
enum DisplayResult {
OK,
NOOP,
INVALID,
};
constexpr const char *OK_STR = "OK";
constexpr const char *NOOP_STR = "NOOP";
static DisplayResult parseResult(std::string *result, DisplaySys from) {
std::stringstream ss;
std::string parsed;
const std::function<void(std::string *)> addEmpty = [](std::string *str) {
if (str->empty())
*str = std::string("(empty)");
};
ss << DisplayStrBuilder(true, from);
ss << ":";
if (result->find(ss.str()) == std::string::npos) {
LOG_E("Unexpected: Failed to find built string in result string");
goto error;
}
parsed = result->substr(result->find(ss.str()) + 1);
if (parsed == OK_STR) {
return DisplayResult::OK;
} else if (parsed == NOOP_STR) {
return DisplayResult::NOOP;
}
addEmpty(&parsed);
LOG_E("Unexpected: Failed to parse by matching parsed result string");
LOG_E("Parsed string was %s", parsed.c_str());
error:
LOG_W("Falling back to find");
if (result->find(OK_STR) != std::string::npos)
return DisplayResult::OK;
else if (result->find(NOOP_STR) != std::string::npos)
return DisplayResult::NOOP;
else {
addEmpty(result);
LOG_E("Failed to find result string in result string");
LOG_E("Resulting string was: %s", result->c_str());
return DisplayResult::INVALID;
}
}
::ndk::ScopedAStatus DisplayConfigs::writeDisplay(bool enable, ::ndk::ScopedAStatus DisplayConfigs::writeDisplay(bool enable,
DisplaySys type) { DisplaySys type) {
std::string writevalue; FileIO::writeline(SEC_TSP_CMD, DisplayStrBuilder(enable, type));
if (type == DisplaySys::DOUBLE_TAP) { return ::ndk::ScopedAStatus::ok();
writevalue = "aot_enable"; }
} else if (type == DisplaySys::GLOVE_MODE) {
writevalue = "glove_mode"; ::ndk::ScopedAStatus DisplayConfigs::readDisplay(DisplaySys type,
bool *_aidl_return) {
std::string res;
writeDisplay(true, type);
res = FileIO::readline(SEC_TSP_CMD_RESULT);
switch (parseResult(&res, type)) {
case DisplayResult::NOOP: {
*_aidl_return = true;
break;
} }
writevalue += ","; case DisplayResult::OK: {
if (enable) { writeDisplay(true, type);
writevalue += "1"; res = FileIO::readline(SEC_TSP_CMD_RESULT);
} else { switch (parseResult(&res, type)) {
writevalue += "0"; case DisplayResult::NOOP: {
} *_aidl_return = false;
FileIO::writeline(SEC_TSP_CMD, writevalue); writeDisplay(false, type);
break;
}
case DisplayResult::OK: {
LOG_W("Double enable returns OK: function not implemented.");
return ::ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
case DisplayResult::INVALID:
return ::ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
};
} break;
case DisplayResult::INVALID:
return ::ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
};
return ::ndk::ScopedAStatus::ok(); return ::ndk::ScopedAStatus::ok();
} }
} // namespace aidl::vendor::eureka::hardware::parts } // namespace aidl::vendor::eureka::hardware::parts

View file

@ -22,5 +22,6 @@ struct DisplayConfigs : public BnDisplayConfigs {
// Methods from ::aidl::vendor::eureka::hardware::parts::IDisplayConfigs // Methods from ::aidl::vendor::eureka::hardware::parts::IDisplayConfigs
// follow. // follow.
::ndk::ScopedAStatus writeDisplay(bool enable, DisplaySys type); ::ndk::ScopedAStatus writeDisplay(bool enable, DisplaySys type);
::ndk::ScopedAStatus readDisplay(DisplaySys type, bool *_aidl_return);
}; };
} // namespace aidl::vendor::eureka::hardware::parts } // namespace aidl::vendor::eureka::hardware::parts

View file

@ -21,3 +21,4 @@ interface IDisplayConfigs {
oneway void writeDisplay(in boolean enable, in DisplaySys type); oneway void writeDisplay(in boolean enable, in DisplaySys type);
boolean readDisplay(in DisplaySys type); boolean readDisplay(in DisplaySys type);
} }