Files
device_motorola_rtwo/touch/TouchscreenGesture.cpp

61 lines
1.8 KiB
C++
Raw Normal View History

2020-08-24 17:11:05 +02:00
/*
* Copyright (C) 2019 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "TouchscreenGestureService"
#include <fstream>
#include <android-base/file.h>
#include <android-base/logging.h>
#include "TouchscreenGesture.h"
namespace vendor {
namespace lineage {
namespace touch {
namespace V1_0 {
namespace implementation {
Return<void> TouchscreenGesture::getSupportedGestures(getSupportedGestures_cb resultCb) {
std::vector<Gesture> gestures;
for (int32_t i = 0; i < std::size(kGestureNodes); ++i) {
gestures.push_back({i, kGestureNodes[i].name, kGestureNodes[i].keycode});
}
resultCb(gestures);
return Void();
}
Return<bool> TouchscreenGesture::setGestureEnabled(
const ::vendor::lineage::touch::V1_0::Gesture& gesture, bool enable) {
if (gesture.id >= std::size(kGestureNodes)) {
return false;
}
if (!android::base::WriteStringToFile(enable ? kGestureNodes[gesture.id].enable : kGestureNodes[gesture.id].disable,
kGestureNodes[gesture.id].path)) {
LOG(ERROR) << "Writing to file " << kGestureNodes[gesture.id].path << " failed";
return false;
}
return true;
}
} // namespace implementation
} // namespace V1_0
} // namespace touch
} // namespace lineage
} // namespace vendor