how to wake up system from sleep using gpio-keys interrupt - android

UPDATE : I changed the keyboard layout file (gpio-keys.kl) to the following:
key 115 POWER WAKE
key 114 POWER WAKE
As seen, I now registered the volume buttons as POWER keys in Android and it wakes up the system. However, I wish to have any generic gpio-key wake up the system. The fact that changing the key layout file as above works tells me that perhaps the issue is on the Android side and not the Linux kernel side. Not sure. Perhaps there are files in Android (policy files, etc.) where I can provide a wake capability to the gpio-key of choice, much the same way as the POWER key has this wake capability.
Please let me know your thoughts.
ORIGINAL :
As for some background, my hardware is a Samsung Galaxy S2-i777, which runs on an Exynos4210 SoC (ARM-based processor). OS is LineageOS 14.1. I'm trying to wake up my system from sleep using a gpio-keys interrupt but I have been unsuccessful.
I've configured gpio-keys in my board file (no device tree as old kernel version). A snippet of where I defined my gpio-keys is below:
struct gpio_keys_button u1_buttons[] = {
{
.code = KEY_VOLUMEUP,
.gpio = GPIO_VOL_UP,
.active_low = 1,
.type = EV_KEY,
.wakeup = 1,
.isr_hook = sec_debug_check_crash_key,
.debounce_interval = 10,
},
};
I omitted registered platform section, etc. but can show if necessary. As seen above, I set the boolean property wakeup to 1 to enable my gpio GPIO_VOL_UP to act as a wakeup source. Also as seen, it is my volume buttons that I want to use as my gpio-keys.
I also modified my key layout file (gpio-keys.kl) as seen below:
key 115 VOLUME_UP WAKE
key 114 VOLUME_DOWN WAKE
When I check my local terminal in LineageOS, I see that my gpio-keys are defined as wakeup_sources and wakeup is enabled. I also see that my volume buttons are generating interrupts (cat /proc/interrupts).
When my system goes to sleep, the volume buttons (gpio-keys) do not wake up my system. Only thing that wakes up my system is the power button (which appears to be a gpio-key as well).
What do you think the issue might be? What are the general steps necessary to waking up the system using gpio-keys interrupts? Even if it is not specific to my hardware, perhaps a general layout of these steps or certain considerations will help me since I might be missing something. Thanks!

First, I would suggest to check the console for any log messages when the Volume button is pressed in the suspend state.
Second, I would like to suggest you to probe the the HW lines to check whether an interrupt is actually generated whenever you press the Volume button when the system is in deep sleep state.
If the interrupts aren't generated, then the HW section might be disabled in the low-power mode and you wouldn't be able to wakeup the system.

Related

What is the modern proper way to modify an android keylayout to wake the system from sleep with a key?

There are plenty of search results explaining that you can modify your android phone to wake up due to a volume key press by modify the keylayout file. You are to simply add WAKE or WAKE_DROPPED to the key in question.
An example to allow the volume up key to wake android:
# /vendor/usr/keylayouts/MyKeyboard.kl
key 115 VOLUME_UP WAKE
This doesn't seem to be applicable any longer. The WAKE flag seems to be ignored. In addition, if I use the validatekeymaps tool with WAKE_DROPPED, you can see it is not even recognized as a valid option any longer.
> validatekeymaps MyKeyboard.kl
Expected key flag label, got 'WAKE_DROPPED'.
If on the other hand, I change the key to be sent to be the POWER key, the system will wake up.
# /vendor/usr/keylayouts/MyKeyboard.kl
key 115 POWER
The system wakes up with or without the WAKE flag is it seems the POWER key has some other attribute set to tell the system to wake up. This of course breaks the volume up functionality and is undesirable.
So my question is, what is the new proper way to set the WAKE attribute on a key? What about WAKE_DROPPED?
You can not set the WAKE attribute on a key now. The wake flags was removed.
The wake key is defined by KeyEvent.isWakeKey

Tapkey Android: How to fetch current status of lock i.e. its locked or open

Thank you for Tapkey Android SDK.
In our application, it's required to show the current status of lock i.e. its locked or open. I have gone through entire documentation at https://developers.tapkey.io/mobile/android/getting_started/, but I cannot find any ways to fetch this status, can you please help here.
The current available locks are technical incapable to detect the bolting state. In the end, the electronics just engage a clutch for a short amount of time. In this time range the mechanical movement is done by hand. Because of this, there is currently no public api for to detecting the bolting state.
For lock manufacturers it is possible to report such a status, which then can be evaluated by the Tapkey Mobile SDK. In this case, please contact Tapkey directly for more information.
The default duration how long a lock is enabled to lock/unlock depends on the lock itself. For the Tapkey-Dom cylinders this is 8 seconds, but this might change in future firmware versions.
Additional to the DefaultTriggerLockCommand there is a TemporaryUnlockTriggerLockCommand which can be created with the TemporaryTriggerUnlockCommandBuilder. With this command it is possible to specify the duration. But be aware that this command might be rejected by older locks.

How can I access the audio 'Priority Mode' on a device running Android 5.0?

Android 5.0 includes a new way to control which apps are allowed to make noise on your device: when you press the volume button, the popup now lets you to choose None (completely silent), Priority (only priority notifications make sound), or All (everything is allowed to make noise.)
I would like my app to be able to query the device to find out which of these three modes is currently active, and also I would like to be able to change these modes (without requiring the device to be rooted). Does anyone know how to do this?
So far, all I can find is a brief reference on this changelog:
Setting the device to RINGER_MODE_SILENT causes the device to enter the new priority mode. The device leaves priority mode if you set it to RINGER_MODE_NORMAL or RINGER_MODE_VIBRATE.
This works as described, which allows me a very limited ability to change "priority mode" by modifying the ringer mode in AudioManager. That's not enough, though, as I need to be able to know exactly which of the three priority mode settings is currently active, and it would also be nice if I could change them more precisely than AudioManager allows.
I've found a solution, but this requires root to change, because this setting is in Settings.Global.
Name of setting is "zen_mode".
Values are:
ZENMODE_ALL = 0;
ZENMODE_PRIORITY = 1;
ZENMODE_NONE = 2;
EDIT: I've found another solution. Check NotificationListenerService.requestInterruptionFilter(int interruptionFilter). https://developer.android.com/reference/android/service/notification/NotificationListenerService.html
Implementation example: https://github.com/kpbird/NotificationListenerService-Example

turn on/off hardware key backlight

Before i ask this question, i've realized it, but it is based on some conditions.
Try1: Change the chmod of file '/sys/class/leds/button-backlight/brightness' to 777, the original file is readable but not writeable, then write '1' to this file to turn on led backlight, '0' to turn off. However, i don't want to change the property of this file.
Try2: something like 'Try 1', that is: Runtime.getRuntime().exec("echo 0 > /sys/class/leds/button-backlight/brightness"); to turn off, Runtime.getRuntime().exec("echo 1 > /sys/class/leds/button-backlight/brightness"); to turn on, but this requires your phone has been rooted or you're a super user when execute the code. So, it isn't the solution that i want.
My thought: i can follow the way that Android System itself turn on/off the led backlight when we touch key like 'Menu', 'Home', 'Back'. But, i don't know how to track or find the ralated code in Android Open Source Code.
I do really appreciate any tip, any thought or any possible way that you provide.

Android ICS/JB, Reboot to Safe Mode Programmatically?

I am making a Utility app for my galaxy nexus. I want to reboot my tablet in safe mode.
I tried to look in PowerManager
PowerManager p = (PowerManager) getSystemService(POWER_SERVICE);
p.reboot(reason);
It seems this will not reboot the device in safe mode. Is it possible to reboot the device programmatically? How?
Basically there are two known ways to enter Safe Mode:
Android detects a problem with a newly installed app and force-closes it while entering into Safe Mode.
A combination of key presses at power application;
I doubt there's yet another way of doing it. If there was, most recoveries and power menus of Custom ROMS would have included that.
The string passed to reboot() is a kernel param, and would have effect only if device's kernel has that option. You can try some options here.
UPDATE:
Safe Mode is toggle is inside PackageManagerService of Android's system server ("package" service):
public void enterSafeMode() {
enforceSystemOrRoot("Only the system can request entering safe mode");
if (!mSystemReady) {
mSafeMode = true;
}
}
and here are some points about using it from any APP :
Process executing this code must be System or have Root previleges
This is an internal service and off-limits to any outside code. Though, some system classes indeed get implementation stubs (IPackageManager) of this service.
The mode change can only be useful when system is yet to be ready.
Let's suppose your app does turn on safe mode some how, due to safe mode being enabled, it won't be around to turn it off. Unless its a system app, built into ROM.
A third way to enter safe mode (available sometime after GingerBread 2.3.5)
With device fully powered up, Press power button, and the LONG press on the power off menu item. An option appears to go into safe mode. Because of this, there may now be a way to programmaticaly enter safe mode. Sure hope so to help troubleshoot. i am going from memory on a lifehacker article which referenced yet another source.

Categories

Resources