summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorJason Gerecke <killertofu@gmail.com>2014-01-27 18:30:37 -0800
committerMichael Wright <michaelwr@google.com>2014-03-10 15:54:21 -0700
commitd6396d67201fb2b64d13070324bb115c9c23b08a (patch)
tree1a4e3278bc72fc189cfe8358ed21ad5269ce92c4 /services
parent724cc1f04f117ee27583d015b414a5ba4540d3b1 (diff)
downloadframeworks_base-d6396d67201fb2b64d13070324bb115c9c23b08a.zip
frameworks_base-d6396d67201fb2b64d13070324bb115c9c23b08a.tar.gz
frameworks_base-d6396d67201fb2b64d13070324bb115c9c23b08a.tar.bz2
Allow persistence of input device calibration
This patch extends the PersistentDataStore store to read and write input device calibration data. A new SET_INPUT_CALIBRATION permission grants apps the ability to update this information, and a new TouchCalibration class is used to wrap the raw calibration data. Change-Id: I4daac2b15ef03616ea5b068c1e77bebd0ce7b8c1
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/input/InputManagerService.java35
-rw-r--r--services/core/java/com/android/server/input/PersistentDataStore.java73
2 files changed, 107 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index e49382e..16972f6 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -52,6 +52,7 @@ import android.hardware.input.InputDeviceIdentifier;
import android.hardware.input.InputManager;
import android.hardware.input.InputManagerInternal;
import android.hardware.input.KeyboardLayout;
+import android.hardware.input.TouchCalibration;
import android.os.Binder;
import android.os.Bundle;
import android.os.Environment;
@@ -700,6 +701,40 @@ public class InputManagerService extends IInputManager.Stub
mTempFullKeyboards.clear();
}
+ @Override // Binder call
+ public TouchCalibration getTouchCalibrationForInputDevice(String inputDeviceDescriptor) {
+ if (inputDeviceDescriptor == null) {
+ throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
+ }
+
+ synchronized (mDataStore) {
+ return mDataStore.getTouchCalibration(inputDeviceDescriptor);
+ }
+ }
+
+ @Override // Binder call
+ public void setTouchCalibrationForInputDevice(String inputDeviceDescriptor,
+ TouchCalibration calibration) {
+ if (!checkCallingPermission(android.Manifest.permission.SET_INPUT_CALIBRATION,
+ "setTouchCalibrationForInputDevice()")) {
+ throw new SecurityException("Requires SET_INPUT_CALIBRATION permission");
+ }
+ if (inputDeviceDescriptor == null) {
+ throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
+ }
+ if (calibration == null) {
+ throw new IllegalArgumentException("calibration must not be null");
+ }
+
+ synchronized (mDataStore) {
+ try {
+ mDataStore.setTouchCalibration(inputDeviceDescriptor, calibration);
+ } finally {
+ mDataStore.saveIfNeeded();
+ }
+ }
+ }
+
// Must be called on handler.
private void showMissingKeyboardLayoutNotification() {
if (!mKeyboardLayoutNotificationShown) {
diff --git a/services/core/java/com/android/server/input/PersistentDataStore.java b/services/core/java/com/android/server/input/PersistentDataStore.java
index 71de776..9ea369d 100644
--- a/services/core/java/com/android/server/input/PersistentDataStore.java
+++ b/services/core/java/com/android/server/input/PersistentDataStore.java
@@ -24,6 +24,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
+import android.hardware.input.TouchCalibration;
import android.util.AtomicFile;
import android.util.Slog;
import android.util.Xml;
@@ -82,6 +83,25 @@ final class PersistentDataStore {
}
}
+ public TouchCalibration getTouchCalibration(String inputDeviceDescriptor) {
+ InputDeviceState state = getInputDeviceState(inputDeviceDescriptor, false);
+ if (state == null) {
+ return TouchCalibration.IDENTITY;
+ }
+ else {
+ return state.getTouchCalibration();
+ }
+ }
+
+ public boolean setTouchCalibration(String inputDeviceDescriptor, TouchCalibration calibration) {
+ InputDeviceState state = getInputDeviceState(inputDeviceDescriptor, true);
+ if (state.setTouchCalibration(calibration)) {
+ setDirty();
+ return true;
+ }
+ return false;
+ }
+
public String getCurrentKeyboardLayout(String inputDeviceDescriptor) {
InputDeviceState state = getInputDeviceState(inputDeviceDescriptor, false);
return state != null ? state.getCurrentKeyboardLayout() : null;
@@ -275,9 +295,25 @@ final class PersistentDataStore {
}
private static final class InputDeviceState {
+ private static final String[] CALIBRATION_NAME = { "x_scale",
+ "x_ymix", "x_offset", "y_xmix", "y_scale", "y_offset" };
+
+ private TouchCalibration mTouchCalibration = TouchCalibration.IDENTITY;
private String mCurrentKeyboardLayout;
private ArrayList<String> mKeyboardLayouts = new ArrayList<String>();
+ public TouchCalibration getTouchCalibration() {
+ return mTouchCalibration;
+ }
+
+ public boolean setTouchCalibration(TouchCalibration calibration) {
+ if (calibration.equals(mTouchCalibration)) {
+ return false;
+ }
+ mTouchCalibration = calibration;
+ return true;
+ }
+
public String getCurrentKeyboardLayout() {
return mCurrentKeyboardLayout;
}
@@ -389,6 +425,31 @@ final class PersistentDataStore {
}
mCurrentKeyboardLayout = descriptor;
}
+ } else if (parser.getName().equals("calibration")) {
+ String format = parser.getAttributeValue(null, "format");
+ if (format == null) {
+ throw new XmlPullParserException(
+ "Missing format attribute on calibration.");
+ }
+ if (format.equals("affine")) {
+ float[] matrix = TouchCalibration.IDENTITY.getAffineTransform();
+ int depth = parser.getDepth();
+ while (XmlUtils.nextElementWithin(parser, depth)) {
+ String tag = parser.getName().toLowerCase();
+ String value = parser.nextText();
+
+ for (int i = 0; i < matrix.length && i < CALIBRATION_NAME.length; i++) {
+ if (tag.equals(CALIBRATION_NAME[i])) {
+ matrix[i] = Float.parseFloat(value);
+ break;
+ }
+ }
+ }
+ mTouchCalibration = new TouchCalibration(matrix[0], matrix[1], matrix[2],
+ matrix[3], matrix[4], matrix[5]);
+ } else {
+ throw new XmlPullParserException("Unsupported format for calibration.");
+ }
}
}
@@ -411,6 +472,16 @@ final class PersistentDataStore {
}
serializer.endTag(null, "keyboard-layout");
}
+
+ serializer.startTag(null, "calibration");
+ serializer.attribute(null, "format", "affine");
+ float[] transform = mTouchCalibration.getAffineTransform();
+ for (int i = 0; i < transform.length && i < CALIBRATION_NAME.length; i++) {
+ serializer.startTag(null, CALIBRATION_NAME[i]);
+ serializer.text(Float.toString(transform[i]));
+ serializer.endTag(null, CALIBRATION_NAME[i]);
+ }
+ serializer.endTag(null, "calibration");
}
}
-} \ No newline at end of file
+}