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.
Related
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.
My issue is Android goes to sleep mode, i can avoid this by selecting from settings but that is not what i want.
I would like to change the stay awake option from firmware level and/or ??(smarter way) so that i can have my new build with the stay awake selected by default permanent and forever, but i do not find the source files.
-is the power manager (http://developer.android.com/reference/android/os/PowerManager.html#FULL_WAKE_LOCK) really the only option? any other solutions?
Edit: wake_lock.c and .h files are handling the topic, so is that where the stay awake mechanism handled?
Regards, Archer
The stay awake option from developers option is changed in defaults.xml:
- false
+ true
-Index: android/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
Once the flag is changed to "true" the system does not go to sleep.
Cheers,
Archer
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
I trying some stuffs with android as i am learning android development, now i have a scenario here.
I want to change the android phone's system date through my application( first i would like to know is this doable? )
Layout is as below
Now what i want is when the user clicks the button the date should increase by say 20 days
how can i do this.
i am unable to start...please help
As I already said that's impossible. You need the SET_TIME permission and that permission is granted by system only to applications that are in the Android system image. If You are able to gain that privilege you can easily change with the AlarmManager. SystemClock.setCurrentTimeMillis write the /dev/allarm file
adb shell ls -l /dev/alarm
crw-rw-r-- system radio 10, 46 2013-06-12 10:46 alarm
c stays for Character special file (stored in /dev).
system is the owner of the file
radio is the group
system and radio have read and write permissions (rw-, tree bits, int value 6), the others have only the read permission (r, int value 4). So the file permission is 664. If you can get root user (running su), you can change the permission of this file and wrote in it a new value. A bug report has been filled in order to ask google to allow apps to modify programmatically the mobile date but it has been declied. Here the reference
On Android, the only way for an application do have write access to the time&date is to get the SET_TIME permission, which is only possible for "applications that are in the Android system image or that are signed with the same certificate as the application that declared the permission." (see signatureOrSystem protection level).
The only way for your application to reach this protection level is to run on a rooted device, or build and sign your own android rom.
If this is your case, you can easily use the AlarmManager or simply the Calendar instance.
Good luck!
Normal user applications does not have permission to change the device time. Read the answer by cashbash in the following post for the alternate option.
Unfortunately, blackbelt is right; android lets us do a lot of cool things, but changing system time programmatically is not one of them.
Since I see that you are looking for more credible/official sources, I suggest you check out this open ticket with Google, which suggests this is an open problem--it ought to work, but doesn't, and it doesn't seem Google is going to fix it anytime soon. The gist of it is that the SET_TIME protection level is set higher than it ought to be. (for more information on permissions, see here)
Although this is not quite the same as changing the time programmatically, you can still make the user change the system time for you if for some reason you do need system time to be changed. This thread will explain how to go about implementing that if you want to go that route.
Hope this was helpful information!
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.