Does anyone have any experience with contenteditable and keycodes in an (Android) WebView?
I'm writing an Android app using a WebView and need to monitor key events. I'm using jQuery, so I'm using $(document).on('keydown').
Problem is, the event received only contains useful information if it's keyCode 13/'Enter'. Things like backspace, delete, or regular characters (all of which I need to be able to monitor) return a value of 229 and 'Unidentified'.
My debugging output looks like this:
e = {"originalEvent":{"isTrusted":true},"type":"keydown","target":{"sizzle1500307408528":{"undefined":{"parentNode":[5,3,true]}}},"currentTarget":{"sizzle1500307408528":{"undefined":{"parentNode":[5,3,true]}}},"timeStamp":5361.655000000001,"jQuery310027283423097243387":true,"delegateTarget":{"location":{"ancestorOrigins":{},"origin":"file://","protocol":"file:","host":"","hostname":"","port":"","search":"","hash":""},"jQuery3100272834230972433871":{"events":{"touchend":[{"type":"touchend","origType":"touchend","guid":1,"selector":".script p","needsContext":false,"namespace":""}],"touchstart":[{"type":"touchstart","origType":"touchstart","guid":2,"selector":".script p","needsContext":false,"namespace":""}],"touchmove":[{"type":"touchmove","origType":"touchmove","guid":3,"selector":".script p","needsContext":false,"namespace":""}],"focusin":[{"type":"focusin","origType":"focus","guid":4,"selector":".script","needsContext":false,"namespace":""}],"focusout":[{"type":"focusout","origType":"blur","guid":5,"selector":".script","needsContext":false,"namespace":""}],"paste":[{"type":"paste","origType":"paste","guid":6,"selector":".script","needsContext":false,"namespace":""}],"selectionchange":[{"type":"selectionchange","origType":"selectionchange","guid":7,"namespace":""}],"input":[{"type":"input","origType":"input","guid":8,"selector":".script","needsContext":false,"namespace":""}],"keydown":[{"type":"keydown","origType":"keydown","guid":9,"selector":".script","needsContext":false,"namespace":""}]},"focusin":1,"focusout":1}},"handleObj":{"type":"keydown","origType":"keydown","guid":9,"selector":".script","needsContext":false,"namespace":""}}
e.keyCode = 229
e.key = Unidentified
My presumption is that 229 (or 0xe5) is getting returned because that's the 'Process' keyCode related to IME input (as per MDN). But regardless I don't see any way to get the key value.
(I'm also curious as to why e.KeyCode and e.keyEvent are values when there is no keyCode or keyEvent in that dump of e. But a question for another day, maybe.)
Related
Edit 10 Apr 2020
I may have misnamed what we are looking for. It may actually be the linux user name of the installed app, rather than its UID. So how should we get that programmatically?
Original question below
When we use adb shell ps even on a non rooted android device, it returns process info where the UID comes in the form u0_xxxx where x represents some arbitrary digits in hex (except for system/root processes).
For example
u0_a464 31481 894 5015336 69200 0 0 S com.example.app_uid_checker
In this example app_uid_checker is my app in user space. When trying to obtain the UID programmatically, though, I get 10464 (the decimal representation of a464), and without the u0 prefix.
I tried
package manager's getApplicationInfo()
activity manager's getAllRunningProcess()
android.os.Process.myUid()
(following suggestions in this post on SO. They all return 10464. How can I get the "full" UID? (for want of a better term, I'm not sure what the u0_a464 version of the UID should be called, as compared to the 10464 version)).
Even if we can programmatically use adb shell ps I think it may not be a good way, as adb needs developer mode to be enabled.
You need to use the geteuid(2) and getpwuid(3) to retrieve the data, as the JVM does not expose it.
extern "C" JNIEXPORT jstring JNICALL Java_com_example_GetUser_getUser(JNIEnv* env) {
uid_t uid = geteuid();
struct passwd *user;
if (uid == -1)
return NULL;
user = getpwuid(uid);
return env->NewStringUTF(user->pw_name);
}
Full working project: https://gitlab.com/hackintosh5/getuser
I am newbie to Linux kernel and just started to know how zram works. Initial testing, I am seeing that READ is issued before WRITE just after the zram is being initialized. But I am just eager to know, why this is so ?
As an activity I took the dump_stack() and followed the path form where to how this zram read is being performed.
zram get to know this info whether it has to do READ or WRITE operation on issued bio->bi_rw. Code flow is like that zram_make_request API is being called from create_device in zram driver. And zram_make_request internally called __zram_make_request which called the zram_bvec_rw API.
In zram_bvec_rw API check the available info of bio->bi_rw and correspondingly issued the READ and WRITE call.
Now, in this case what is happening: READ is being encapsulated inside bio struct itself. As triage I found that submit_bh fills all the entry of bio and issued the submit_bio.
I was wondering who is actually sets the bio->bi_rw as READ. By enabling the few prints I found that ll_rw_block API is being called by __block_write_begin with READ, later ll_rw_block calls the submit_bh API where rest of bio struct entries are filled.
But I am still not getting the answer why READ is issued for ll_rw_block from __block_write_begin ?
zram driver:
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/block/zram/zram_drv.c?id=refs/tags/v3.18.14
in file: https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/fs/buffer.c?id=refs/tags/v3.18.14
if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
!buffer_unwritten(bh) &&
(block_start < from || block_end > to)) {
ll_rw_block(READ, 1, &bh);
*wait_bh++=bh;
}
buffer_uptodate(bh), /* Contains valid data */
buffer_delay(bh), /* Buffer is not yet allocated on disk */
buffer_unwritten(bh), /* Buffer is allocated on disk but not written */
Please can someone give an explaination/answer to my question ?
How I am concluding that read is perfomed before write ??
I just check the num_reads and num_writes count. And num_reads count is set to 1 while num_writes is found 0 when we do mkswap /dev/block/zram0 and after calling the swapon /dev/block/zram0 the final counts are num_reads = 2 and num_writes=1.
NOTE: This is the case when we don't performing any additional zram activity. We got this behavior in case as explained above.
Because of this as far as i can see: block_start < from || block_end > to (respecting other conditions of course, buffer_uptodate() etc.) .
i.e. bio will write a whole block so if a region to be updated smaller than submited block you obviously need a fresh copy.
I am trying to type in a search box within my app and tap/click on search button(magnifying glass) on keyboard. But I am unable to click/tap on it. I have tried below things:
driver.sendKeyEvent(84);
Appium says it successfully sent in the command but 'search' does not get tapped. Cursor remains in text box and results do not filter.
HashMap swipeObject = new HashMap();
swipeObject.put("keycode", 84);
((JavascriptExecutor ) driver).executeScript("mobile: keyevent", swipeObject);
Appium says not yet implemented.
JavascriptExecutor jse = (JavascriptExecutor) driver1; jse.executeScript("UIATarget.localTarget().frontMostApp().keyboard().buttons()['Done'].tap();");
Appium says not yet implemented.
driver.sendKeyEvent(AndroidKeyCode.ENTER, AndroidKeyMetastate.META_FUNCTION_ON);
Appium says it successfully sent in the command but 'search' does not get tapped. Cursor remains in text box and results do not filter.
driver.sendKeyEvent(AndroidKeyCode.ENTER);
Nothing happens
All other send key events works except ENTER, Search. I can use sendKeyEvent for alphabets, numbers, space etc.
I am using Ecllipse, AndroidDriver, AppiumDriver, TestNG, Appium(1.2.4.1), Samsung Galaxy Note 3.
Any help on this would be really helpful. I went through lot of Googling but till not successful tapping search key.
I'm trying to get my game working on Android. I've ported it with the free version of Apportable and it works quite well, but I haven't been able to implement the gyroscope feature.
CMMotionManager gets initialized but the motion updates never start (or at least handleDeviceMotion: never gets called). The motion manager's isAccelerometerActive property is always NO, but isAccelerometerAvailable is YES.
Using [NSOperationQueue mainQueue] doesn't help either.
This is how I initialize the motion manager:
self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.gyroUpdateInterval = .2;
[self.motionManager startDeviceMotionUpdatesToQueue:[[NSOperationQueue alloc] init]
withHandler:^(CMDeviceMotion *motion, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self handleDeviceMotion:motion];
});
}];
It produces the following message to logcat:
E/Sensors ( 507): HAL:ERR open file /sys/bus/iio/devices/iio:device0/dmp_event_int_on to write with error 2
E/Sensors ( 507): HAL:ERR can't disable DMP event interrupt
I have no idea what this means...
I'm testing the app on Asus Nexus 7.
Is there something special I need to do to use CoreMotion with Apportable?
Edit:
Here's a simple test project I created to demonstrate the issue.
CoreMotion should work with apportable. Here is a simplified initialization and usage paradigm that I've tested on a Nexus 7 (2012).
self.motionManager = [[CMMotionManager alloc] init];
[self.motionManager startDeviceMotionUpdates];
self.motionTimer = [NSTimer scheduledTimerWithTimeInterval:0.2
target:self
selector:#selector(handleDeviceMotion)
userInfo:nil
repeats:YES];
Instead of using startDeviceMotionUpdatesToQueue: withHandler: to process the motion events, try explicitly accessing the deviceMotion property in a handleDeviceMotion method which will be called by the repeating timer.
-(void) handleDeviceMotion {
CMDeviceMotion *motion = [self.motionManager deviceMotion];
// use motion data accordingly
}
And don't forget to stop updates when you're done!
[self.motionManager stopDeviceMotionUpdates];
For this sort of device motion in particular, we had a fairly layered series of issues that I've (hopefully) resolved with the next SDK update. I've implemented yaw, pitch, and roll, and they seem to give relatively sane values. If you're still having issues, email sdk(#)apportable.com (delete the parens obviously) and mention me.
I'm trying to control Android by writing data into /dev/uinput. For example, if I enter 'A' on my desktop, the codes will write something according to key_code into uinput and Android should behave like I input an 'A' on the phone. I am following the codes in RemoteInput. I tested on Nexus 4 with JB 4.2 system. All the ioctls return positive results, which means it should work. However, when I put in an 'A', the Android only seems to refresh the virtual keyboard and does not input anything.
First, you need to "register" the supported keys using ioctl(m_fd, UI_SET_KEYBIT, key). For A, you should use KEY_A, which is defined in linux/input.h (#define KEY_A 30) and not KEYCODE_A, which is a different code. In my experience, /dev/uinput on Android works with Linux key codes.
You should:
open /dev/uinput
ioctl(m_fd, UI_SET_EVBIT, EV_KEY) - support EV_KEY event
ioctl(m_fd, UI_SET_EVBIT, EV_SYN) - support EV_SYN event
ioctl(m_fd, UI_SET_KEYBIT, key) - support key - for each keycode that you want to support
create uinput_user_dev structure and populate it, then write that structure to /dev/uinput file descriptor (see below)
call ioctl(m_fd, UI_DEV_CREATE) to create this device; the m_fd will now point to newly created device.
Do monitor logcat output and check if the device will be created successfully. It will take a generic keychar map and key layout, since no keymap is defined. If you want to define it, look into /system/usr/keychars and /system/usr/keylayout.
Create uinput device
uinput_user_dev uidev;
memset(&uidev, 0, sizeof(uidev));
snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "uinput-test");
uidev.id.bustype = BUS_USB;
uidev.id.vendor = 0x1212;
uidev.id.product = 0xabab;
uidev.id.version = 3;
write(m_fd, &uidev, sizeof(uidev)