Prevent screen sleeping - android

Android v4.2.2. I'm trying to stop the screen from going to sleep. I've tried a few things like changing the relevant settings in the db:
adb shell "sqlite3 /data/data/com.android.providers.settings/databases/settings.db \"update system set value='-1' where name='screen_off_timeout'\";"
But that didn't work - screen just went to sleep almost immediately. If I go to the settings app there isn't an option to disable it. Instead, it ranges from 15s to 30m.
I have also tried to set the KEEP_SCREEN_ON FLAG in the application but that stops working when I switch to a new activity.
Is there anything else I can try. I was hoping a db setting would do the job. Here is my system db as it stands. Perhaps a setting I am missing and can insert?
1|volume_music|11
2|volume_ring|5
3|volume_system|7
4|volume_voice|4
5|volume_alarm|6
6|volume_notification|5
7|volume_bluetooth_sco|7
8|mode_ringer_streams_affected|174
9|mute_streams_affected|46
10|vibrate_when_ringing|0
11|dim_screen|0
13|dtmf_tone_type|0
14|hearing_aid|0
15|tty_mode|0
16|screen_brightness|102
17|screen_brightness_mode|0
18|window_animation_scale|1.0
19|transition_animation_scale|1.0
20|accelerometer_rotation|1
21|haptic_feedback_enabled|1
22|notification_light_pulse|1
23|dtmf_tone|1
24|sound_effects_enabled|1
26|lockscreen_sounds_enabled|1
27|pointer_speed|0
28|next_alarm_formatted|
29|alarm_alert|content://media/internal/audio/media/5
30|notification_sound|content://media/internal/audio/media/7
31|ringtone|content://media/internal/audio/media/9
32|volume_music_headset|10
33|volume_music_last_audible_headset|10
34|volume_music_headphone|10
35|volume_music_last_audible_headphone|10
36|time_12_24|24
37|date_format|dd-MM-yyyy
39|stay_on_while_plugged_in|1
45|screen_off_timeout|-1

Your setting db contains default time out set by the system which is probably low so the device went to sleep immediately due to low timeout value. You can issue adb shell command to increase screen timeout.
adb shell settings put system screen_off_timeout 60000
Note: 60000 = 1 minute
You can also update setting db with the desired timeout and then push db back to device but it requires root. Above command does not require device to be rooted.

This is related to Activity , There is no impact from DB. Just add android:keepScreenOn="true" to the layout in your xml

Did you try this
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wl.acquire();
For more go through this link http://thiranjith.com/2012/02/22/android-prevent-screen-timeout/

Related

Changing Doze mode parameters programmatically

Question about changing the parameters of the transition to doze mode
I have a non-rooted Android 12 device
There are a number of parameters for changing the transition time in doze mode:
inactive_to
motion_inactive_to
light_after_inactive_to
If you change these parameters through the PC using ADB, then the parameters are set. For instance:
adb shell device_config put device_idle inactive_to 2592000000
The problem is that after a reboot, the settings are reset.
Tried to change them directly in the program
// val command = arrayOf("/system/bin/device_config", "put", "device_idle", "motion_inactive_to", "2592000000")
val command = arrayOf("/system/bin/settings", "put", "global", "device_idle_constants", "light_after_inactive_to", "2592000000")
Log.d("ADB", "Start ${command.joinToString(separator = " ")}")
val process = Runtime.getRuntime().exec(command)
val bufReader = BufferedReader(InputStreamReader(process.errorStream))
val log = StringBuilder()
var line: String?
line = bufReader.readLine()
while (line != null) {
log.append(line + "\n")
line = bufReader.readLine()
}
Log.d("ADB", "Command: $log")
But the first command is answered:
“cmd: Can't find service: "device_config"”
And the second command gives an error:
Permission Denial: getCurrentUser() from pid=28435, uid=10245 requires android.permission.INTERACT_ACROSS_USERS
After searching for information about the INTERACT_ACROSS_USERS permission, I understand that it is necessary for it to make the application system. And for this I need to root the device.
Is there any other way to change the parameters of doze mode or disable it altogether?
It's confusing that you can run a command with adb on a non-rooted device, but you can't directly in the program.
Is there any other way to change the parameters of doze mode or disable it altogether?
No. If there were, it would have been pointless to add Doze mode, as every developer would opt out of it.
It's confusing that you can run a command with adb on a non-rooted device, but you can't directly in the program.
Different users/processes having different privileges has been a common concept in operating systems for at least 30 years.

How to send a 'fake' command to Appium

I'm trying to test my android application with appium and I'm looking for a solution to the following issue:
In my application I have a section that takes time (for image processing) and it sometimes can take one minute, two minute or even more depends on the image size, quality.
In my test case I'm trying to wait for lets say 30 seconds and then I'm checking if the image processing is done.
The problem is if I'm waiting too long, I got the next message:
info: [debug] Didn't get a new command in 60 secs, shutting down...
I don't want to set a 'newCommandTimeout' cause I want to cut the test time and I want to test check if its done every short period.
In addition, I can't use the wait for element or something like that of appium API because I'm using a third party library which tells me when the image processing is done.
My questions is, there is any way to send a 'fake' command to appium so every 30 seconds that my thread is back to work and if I see that the image processing is not done I'll send a fake command and then go back to sleep for 30 seconds without any worry that the appium server will be shut down due to timeout?
Not sure what you are using for wait command. Use this:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
This will wait until it finds the element on screen.
In addition to the comment here:
In order to solve this issue I use the WebDriverWait with a custom ExpectedCondition and it looks like:
new WebDriverWait(mDriver, 30) // 30 is for the time out
.withMessage("You can set any custom error message")
.until(new ExpectedCondition<Boolean>() {
#Override
public Boolean apply(WebDriver d) {
//This function will be called repeatedly until
//the return value will be true
}
});
You can see other implementations of WebDriverWait and actually I think it works with any Object instead of Boolean.

USB Host port disabled when Android screen is locked

I am developing an application that communicates with an Embedded Device via the Android Devices USB Host port. I noticed that when the screen is locked USB Host port is disabled and no communication occurs.
How can I prevent the USB Host port from turning off so that communication can occur when the screen is locked?
------------- USB Host ---------------
| Android | <------------------> | Device |
------------- ---------------
Note: I can have root access on the Android system if necessary.
Thanks for the tip Chris Stratton. Using a PARTIAL_WAKE_LOCK the screen can turn off yet the CPU remains running. This is suitable for my application.
I created a quick app to test this:
public class MainActivity extends Activity {
PowerManager pm;
PowerManager.WakeLock wl;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
}
#Override
protected void onStart() {
super.onStart();
if (wl != null) {
wl.acquire();
}
}
#Override
protected void onDestroy() {
super.onDestroy();
if (wl != null) {
wl.release();
}
}
I tested it by connecting a mouse to the USB Host. When the screen was locked the mouse did not turn off as I would like.
Another option I came across which I have not tried. You may be able to adjust the system resource which controls the power management of the USB device. You probably need root access for this.
Changing the default idle-delay time
------------------------------------
The default autosuspend idle-delay time (in seconds) is controlled by
a module parameter in usbcore. You can specify the value when usbcore
is loaded. For example, to set it to 5 seconds instead of 2 you would
do:
modprobe usbcore autosuspend=5
Equivalently, you could add to a configuration file in /etc/modprobe.d
a line saying:
options usbcore autosuspend=5
Some distributions load the usbcore module very early during the boot
process, by means of a program or script running from an initramfs
image. To alter the parameter value you would have to rebuild that
image.
If usbcore is compiled into the kernel rather than built as a loadable
module, you can add
usbcore.autosuspend=5
to the kernel's boot command line.
Finally, the parameter value can be changed while the system is
running. If you do:
echo 5 >/sys/module/usbcore/parameters/autosuspend
then each new USB device will have its autosuspend idle-delay
initialized to 5. (The idle-delay values for already existing devices
will not be affected.)
Setting the initial default idle-delay to -1 will prevent any
autosuspend of any USB device. This has the benefit of allowing you
then to enable autosuspend for selected devices.
Source:
https://android.googlesource.com/kernel/common/+/android-3.10/Documentation/usb/power-management.txt

Qt/C++: interrupt QProcess arbitrarily with button (simulate ^c)

So I need to make a Qt Application (with GUI) that executes the "adb logcat" command (it's a log that keeps being generated until ^c is pressed).
I need a GUI button to make the process stop and pass the output to a Text Browser.
This is the code I use to get the QProcess output:
QProcess process;
process.start("adb logcat");
process.waitForFinished(-1);
QByteArray logcatOut = process.readAllStandardOutput();
ui->devicesOutput->setText(logcatOut);
Thank you
process.waitForFinished(-1);
would prevent your program of being executed further, till the process "adb" has finished.
So your GUI will be frozen.
You should define QProcess process as a class variable. Use QProcess
*process; instead of creating it on stack. (Best practice for all QObject derivates)
Declare a slot which handles clicked-signal of your button.
call process->terminate() in the slot.
use QProcess::terminate to stop running app

Unlock automatically when android phone booted

I had caught phone boot event.
On boot complete event I am writing following code
KeyguardManager mKeyguardManager = (KeyguardManager) mContext.getSystemService(KEYGUARD_SERVICE);
KeyguardLock mLock = mKeyguardManager.newKeyguardLock("MyApp");
mLock.disableKeyguard();
but what happing I can able to see lock and after that screen is getting unlocked. But requirement is that lock should not be visible at all after booting.
My guess is that I need to make modification in framework somewhere in setting file.
But I don't know where to modify.
but what happing I can able to see lock and after that screen is getting unlocked
You did not lock the screen. Hence, you cannot unlock it. disableKeyguard() is only used to reverse the effects of reenableKeyguard().
My guess is that I need to make modification in framework somewhere in setting file.
If by "setting file" you mean "Java, or possibly C/C++, source code", then yes that is probably the case.
But I don't know where to modify.
StackOverflow is not a great resource for assistance with firmware modifications, sorry.
I have did it by commenting following code in KeyguardViewMediator
private void showLocked() {
/* if (DEBUG) Log.d(TAG, "showLocked");
Message msg = mHandler.obtainMessage(SHOW);
mHandler.sendMessage(msg);*/
}

Categories

Resources