Android Emulator as `LowRamDevice` - android

There's a method ActivityManagerCompat.isLowRamDevice(), and I'm trying to figure out how to test it. I've tried the following to get it to return true, but it's always false:
Create a new emulator with 128 MB of RAM (Still returns false)
adb shell setprop ro.config.low_ram true (Fails. Doesn't change the property)
add shell setprop debug.force_low_ram true (Sets the property, but need a development build of Android)
Searching online for a "Low Ram Emulator" to test with
How can I test ActivityManagerCompat.isLowRamDevice() without compiling the OS from scratch?

Answer: You need root access on the Emulator
Then you can do: adb shell setprop ro.config.low_ram true
See https://stackoverflow.com/a/45668555 for how to get root access on an emulator.

Related

See app background processes in Android Studio

Maybe I'm just missing it but is there a way to view WHAT is running in the background on-device in android studio?
I'm getting a battery usage alert on my phone (galaxy s8 - OS v8.0), indicating my app is doing something in the background and I'd like to see what it is.
Thank you
Yea, via the terminal function. This is one of options at the bottom of the Android studio.
You need to run ADB to connect to the device. Once connected you can use Unix command lines to see the processes running.
From google dev : https://developer.android.com/studio/command-line/adb
Also, the command I use to connect an emulator to run unix commands is:
adb -s <DEVICE> shell
Normally the ADB is stored :
USER\AppData\Local\Android\Sdk\platform-tools
and then once connected you can use the following to see the running processes :
https://www.howtogeek.com/107217/how-to-manage-processes-from-the-linux-terminal-10-commands-you-need-to-know/
Hope this helps.

create 3 android emulators [phone, tab7, tab10] and start them via commandline for fastlane

I'm working on fastlane and want to start 3 emulators [phone, tab7, tab10] and take screenshots on them.
How do I create a script to create and start emulators via fastlane or commandline
You will need a script which does the following:
Start the emulator
Wait for the emulator to boot
Start screengrab for this emulator
Shut down the emulator
Then you call the script for your three different screen sizes.
Some more details:
To start the emulator use the program emulator which is located under android-sdk/emulator/emulator. I had problems with android-sdk/tools/emulator so be sure to use the right one. The call can look like this:
emulator #'your_emulator_name_variable' &
The & is important when you are using a shell script to continue after the call.
You can call adb shell getprop sys.boot_completed to see if the emulator has booted already. Do this in a loop until it returns 1
Call fastlane screengrab and append the specific type flag:
--specific-type 'device_type_variable'
with 'device_type_variable' equals to phone, sevenInch or tenInch. According to the emulator you started.
Call adb emulator-5554 emu kill to shut down you emulator. If it uses another, non standard port, adjust accordingly.
Now you can call this script with the two variables your_emulator_name_variable and device_type_variable for each of your emulator.
Hope this helps.

Change android time zone on emulator via adb shell

I'm running tests for my app, and I want to validate that it works in various time zones.
I'm trying solutions suggested here running adb shell setprop persist.sys.timezone "Pacific/Honolulu", but the timezone (and time) on emulator is not changing- can this work without restarting the device?
If you mean UI tests, I can not change android Date & Time settings on emulator via adb shell.
The only solution I found is to set the timezone during the creation of the emulator with -timezone option.
For example, you can create android emulator with a command like $ emulator #Nexus_5X_API_23 -timezone Europe/Paris.
See more emulator command line options here

How to TEST Backup in ANDROID (perhaps using bmgr)

So I have implemented all the backup method following official android backup tutorial :http://developer.android.com/guide/topics/data/backup.html
But After I am done with everything, I cannot test it! The Android website says to use bmgr and use commands such as "adb shell bmgr run" etc, but I have no idea what this means...
I am using Eclipse to develop Android apps, and I am using real Samsung Galaxy Devices to test my apps. I am also backing up 1 file from the internal storage.
So how do I force the back up? Where can I write the command line (i can open DDMS)? What and where is this bmgr thing?
And does anyone know how long it takes for devices to actually backup data? Backing up data doesn't seem to happen immediately (if it happens at all) after you call:
BackupManager bm = new BackupManager(this);
bm.dataChanged();
TY
The solution to this problem. You need to find adb.exe file in the Android ADK folder. It is inside platform-tools folder. And then you have to use terminal to go to the folder that has adb so that when you do ls, adb appears. Then you do the command but with ./ in the front
For example:
./adb shell bmgr run
instead of just adb shell bmgr run.
First check whether your device is connected using:
./adb device
From here you can force backup and restore for your app.

Changing the Android emulator locale automatically

For automated testing (using Hudson) I have a script that generates a bunch of emulators for many combinations of Android OS version, screen resolution, screen density and language.
This works fine, except for the language part.
I need to find a way to change the Android system locale automatically. Here's some approaches I can think of, in order of preference:
Extracting/editing/repacking a QEMU image directly before starting the emulator
Running some sort of system-locale-changing APK on the emulator after startup
Changing the locale settings on the emulator filesystem after startup
Changing the locale settings in some SQLite DB on the emulator after startup
Running a key sequence (via the emulator's telnet interface) that would open the settings app and change the locale
Manually starting the emulator for each platform version, changing the locale by hand in the settings, saving it and archiving the images for later deployment
Any ideas whether this can be done, either via the above methods or otherwise?
Do you know where locale settings are persisted to/read from by the system?
Solution:
Thanks to dtmilano's info about the relevant properties, and some further investigation on my part, I came up with a solution even better and simpler than all the ideas above!
I have updated his answer below with the details.
Personally I think the simplest way is to start the emulator, probably a clean instance unless you are running integration tests that depends on other applications and then change locale using adb:
$ adb shell '
setprop persist.sys.language en;
setprop persist.sys.country GB;
stop;
sleep 5;
start'
or whatever locale you want to set.
To verify that your change was successful just use
$ adb shell 'getprop persist.sys.language'
You may also want to run emulators on know ports, check my answer in this thread.
Note that you can also set system properties directly when starting the emulator:
emulator -avd my_avd -prop persist.sys.language=en -prop persist.sys.country=GB
This way, you can create a plain old emulator of any type then start it up immediately using the locale of your choice, without first having to make any modifications to the emulator images.
This locale will persist for future runs of the emulator, though of course you can always change it again at startup or during runtime.
Accepted answer doesn't work anymore. persist.sys.language and persist.sys.country are gone from emulator properties.
My solution is to use preinstalled on android emulator "Custom locale" application. Simply send intent with extra language parameter to it as below:
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE EN
More information here - prepare android emulator for UI test automation.
UPDATE: based on comment from Jonas Alves the following command works on API 28+:
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE "en_US" com.android.customlocale2
Seems that Android emulator now supports setting the locale when starting it:
emulator -avd <avd-name> -change-locale fr-CA
Source - https://androidstudio.googleblog.com/2019/09/emulator-29112-stable.html

Categories

Resources