From 8086b8e75dcbb405f95efd95bd433e315e6fc37b Mon Sep 17 00:00:00 2001 From: John S Peterson Date: Tue, 23 Jul 2024 22:12:42 +0000 Subject: [PATCH] Input: list input devices including finger print keyboard! I found this mysterious device that acts a touch key board on that tiny finger print sensor . someone was watching to much telly. must be something from star trek Shanghai edition can't fail the lack of imagination touch in four ways produce for function keys including escape that i still haven't mastered after three months. only master china knows that move. the device is Hisense Unisoc bought in south Africa it incorrectly report no escape key but correctly F keys ~~~ getprop|ack ro.product.locale -C3|copy [ro.product.device]: [HLTE263E] [ro.product.first_api_level]: [33] [ro.product.hardware]: [ums9230_1h10] [ro.product.locale]: [en-ZA] [ro.product.manufacturer]: [Hisense] [ro.product.model]: [Hisense E70 Pro] [ro.product.name]: [HLTE263E] $PREFIX/libexec/termux-api Input { "devices": { "Virtual": { "vendor": 0, "product": 0, "descriptor": "a718a782d34bc767f4689c232d64d527998ea7fd", "sources": "0x301", "on": true }, "gpio-keys": { "vendor": 1, "product": 1, "descriptor": "485d69228e24f5e46da1598745890b214130dbc4", "sources": "0x101", "on": true }, "jadard-touchscreen": { "vendor": 0, "product": 0, "descriptor": "05ab20d8f240ca495f164a09b0b489b3be22e9cc", "sources": "0x1103", "on": true }, "sc27xx:vibrator": { "vendor": 0, "product": 0, "descriptor": "769cc50018f4cb92ff7090463db6ab6573d0a617", "sources": "0x0", "on": true }, "sprdphone-sc2730 Headset Jack": { "vendor": 0, "product": 0, "descriptor": "3b5c5000ad44566db5c2b3a8852c980a48b81674", "sources": "0x80000000", "on": true }, "sprdphone-sc2730 Headset Keyboard": { "vendor": 0, "product": 0, "descriptor": "9c71735ecc867a08d5a051bbb9cf689202c5cd53", "sources": "0x101", "on": true }, "fp-keys": { "vendor": 0, "product": 0, "descriptor": "bc18013244a1dd8fe13c73453267d808c5b3f21e", "sources": "0x101", "on": true, "hasKeys": { "ESCAPE": false, "F1": true, "F2": true, "F3": true, "F4": false } } } } --- .../com/termux/api/TermuxApiReceiver.java | 4 + .../java/com/termux/api/apis/InputAPI.java | 149 ++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 app/src/main/java/com/termux/api/apis/InputAPI.java diff --git a/app/src/main/java/com/termux/api/TermuxApiReceiver.java b/app/src/main/java/com/termux/api/TermuxApiReceiver.java index 6efaafe16..a2443e770 100644 --- a/app/src/main/java/com/termux/api/TermuxApiReceiver.java +++ b/app/src/main/java/com/termux/api/TermuxApiReceiver.java @@ -20,6 +20,7 @@ import com.termux.api.apis.DownloadAPI; import com.termux.api.apis.FingerprintAPI; import com.termux.api.apis.InfraredAPI; +import com.termux.api.apis.InputAPI; import com.termux.api.apis.JobSchedulerAPI; import com.termux.api.apis.KeystoreAPI; import com.termux.api.apis.LocationAPI; @@ -142,6 +143,9 @@ private void doWork(Context context, Intent intent) { InfraredAPI.onReceiveTransmit(this, context, intent); } break; + case "Input": + InputAPI.onReceive(this, context, intent); + break; case "JobScheduler": JobSchedulerAPI.onReceive(this, context, intent); break; diff --git a/app/src/main/java/com/termux/api/apis/InputAPI.java b/app/src/main/java/com/termux/api/apis/InputAPI.java new file mode 100644 index 000000000..d17a999b0 --- /dev/null +++ b/app/src/main/java/com/termux/api/apis/InputAPI.java @@ -0,0 +1,149 @@ +package com.termux.api.apis; + +import android.app.ActivityManager; +import android.app.ActivityManager.MemoryInfo; +import android.app.ApplicationExitInfo; +import android.content.Context; +import android.os.Build; +import android.os.Bundle; +import android.content.Context; +import android.content.Intent; +import android.util.JsonWriter; +import android.view.InputDevice; +import android.view.KeyEvent; + +import androidx.annotation.RequiresPermission; +import androidx.appcompat.app.AppCompatActivity; + +import com.termux.api.TermuxApiReceiver; +import com.termux.api.util.ResultReturner; +import com.termux.shared.logger.Logger; + +import java.util.List; +import java.io.PrintWriter; +import java.io.StringWriter; + +public class InputAPI { + + private static final String LOG_TAG = "InputAPI"; + static Context context; + static TermuxApiReceiver receiver; + static Intent intent; + static StringWriter sw; + static JsonWriter out; + + public static void onReceive(TermuxApiReceiver _receiver, final Context _context, Intent _intent) { + Logger.logDebug(LOG_TAG, "onReceive"); + context = _context; + receiver = _receiver; + intent = _intent; + sw = new StringWriter(); + out = new JsonWriter(sw); + + out.setIndent(" "); + + try { + out.beginObject(); + // jsonTest(); + devices(); + out.endObject(); + write(); + Logger.logInfo(LOG_TAG, sw.toString()); + } catch (Exception e) { + Logger.logError(LOG_TAG, e.getMessage()); + } + } + + static void write() { + ResultReturner.returnData(context.getApplicationContext(), intent, new ResultReturner.WithInput() { + @Override public void writeResult(PrintWriter _out) throws Exception { + try { + _out.print(sw); + } catch (Exception e) { + Logger.logError(LOG_TAG, e.getMessage()); + } + } + }); + } + + static void jsonTest() throws Exception { + // out.beginArray(); + // out.beginObject(); + out.name("devices"); + out.beginObject(); + out.name("123"); + out.beginObject(); + out.name("on").value(0); + // out.endObject(); + out.name("keys"); + out.beginObject(); + out.name("f").value(1); + out.endObject(); + out.endObject(); + // out.endArray(); + } + + static void devices() throws Exception { + + out.name("devices"); + // out.beginArray(); + out.beginObject(); + + for (int id : InputDevice.getDeviceIds()) { + InputDevice dev = InputDevice.getDevice(id); + if (dev == null) continue; + String name = dev.getName(); + int vend = dev.getVendorId(); + int prod = dev.getProductId(); + String desc = dev.getDescriptor(); + int s = dev.getSources(); + String sources = String.format("0x%X", s); + boolean on = dev.isEnabled(); + + // boolean[] keys = dev.hasKeys(ESCAPE, F1); + boolean[] keys = dev.hasKeys( + KeyEvent.KEYCODE_ESCAPE, + KeyEvent.KEYCODE_F1, + KeyEvent.KEYCODE_F2, + KeyEvent.KEYCODE_F3, + KeyEvent.KEYCODE_F4 + ); + + // there Is more internally to perhaps find the files + // String conf = dev.getInputDeviceConfigurationFilePathByDeviceIdentifier(id); + + // out.value(name); + out.name(name); + // out.beginArray(); + out.beginObject(); + // out.beginObject(name); + out.name("vendor").value(vend); + out.name("product").value(prod); + out.name("descriptor").value(desc); + out.name("sources").value(sources); + out.name("on").value(on); + // out.endObject(); + // out.endObject(); + // out.endArray(); + + if (name.equals("fp-keys")) { + out.name("hasKeys"); + out.beginObject(); + out.name("ESCAPE").value(keys[0]); + out.name("F1").value(keys[1]); + out.name("F2").value(keys[2]); + out.name("F3").value(keys[3]); + out.name("F4").value(keys[4]); + out.endObject(); + } + // out.endArray(); + out.endObject(); + + // int sources = inputDevice.getSources(); + + } + out.endObject(); + // out.endArray(); + } + +}