android check heap memory in run time - android

I have an android app, this application connect to server to download images, but this images has more than one copy, first copy 1600 * 1080 pixel and the second is 800 * 540 ...
so the device should send tag to server to download the good images for this device
I used many ways to check the device memory or density but the results was not clear enough to make a decision, here some code I used:
float density = getResources().getDisplayMetrics().density;
long mem = Runtime.getRuntime().freeMemory();
long heap = Debug.getNativeHeapAllocatedSize();
the results was for 3 devices like this:
samsumg tab 10 inch = 1.0 , 745464 , 3249552 byte
china tab 7 inch = 1.0 , 559944 , 2789016 byte
htc moble 3.4 inch = 1.5 , 1760904 , 8942736 byte
as the result showed the htc is the better but it was not because I can't view the highest resolution on it, but on the other devices it was very good
the error msg:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget(Heap Size=7687KB, Allocated=3356KB, Bitmap Size=25092KB)
Any help in this issue ?

Your decision should depend on two factors:
Screen density.
Screen Size.
In your case you had received hdpi drawables on htc, but it's small device, so it's not required to show large image with more details on small device.
for more information for loading large bitmaps efficiently:
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

Related

How init.rc setprop works

I have android 8 from nxp and using it on sabresd board.
I am trying to change dpi settings through setprop settings
So I have put this iside init.${hardware}.rc on boot event
# Set the density to 160dpi, default 128dpi is not good
# Set the density to 128 dpi for 480x800, 7 inch.
setprop ro.sf.lcd_density 128
The device works fine and if I do this
wm density
Physical density:128
Now I put this dpi setting in kernel command line
androidboot.sf.lcd_density=128
but I do not see device to be in 128 dpi setting. Also
wm density
Physical density:160
Now this baffles me.Who gave 160dpi settings?
How putting setprop in init.$hardware.rc affects the display but not in kernel command line.
Who really processes setprop.
I tried putting prints like this
on boot
exec /system/bin/echo "Trigger test E"
I saw nothing, so does that mean boot event never happened?
In android framework there is a file called
display file
that contains default dpi if none is specified.
This file have this setting,
public static final int DENSITY_MEDIUM = 160;
Which is used if no dpi is specified.

3.5 Inch SPI TFT LCD Display goes black for Android Things

I have a KeDei 3.5 ich SPI TFT LCD Display. I attached to Raspberry Pi with Android Things Image. When I boot the RPi, nothing is shown, only displays a black screen. The display is getting powered up, and I can differentiate between it's on and off state. But when I try remote display (followed steps from this post), I can see the display properly.
Logcat output which I think is related to display:
mBaseDisplayInfo=DisplayInfo{"Built-in Screen", uniqueId "local:0", app 640 x 480, real 640 x 480, largest app 640 x 480, smallest app 640 x 480,mode 1, defaultMode 1, modes [{id=1, width=640, height=480,fps=60.000004}], colorMode 0, supportedColorModes [0], hdrCapabilities android.view.Display$HdrCapabilities#1d6308, rotation 0, density 240 (0.0 x 0.0) dpi, layerStack 0, appVsyncOff 1000000, presDeadline 16666666, type BUILT_IN, state ON, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS, removeMode 0}
I tried latest Raspbian Image and dev preview 0.4.1 as mentioned here. Tried with HDMI config given in the same link. Nothing works except the rpi_35_v6.3_ubuntu_mate_15_kedei image from KeDei vendor.
Display Specs:
480x320 16bit/18bit
version 6.3 2016/11/1
Android Things:
OS: 0.6.1-devpreview
Build: OIM1.171126.016
Empty Bundle
According Hardware Platforms description, Raspberry Pi with Android Things support Display only via HDMI or DSI interfaces, not via SPI, and there is no built in drivers for it - your KeDei 3.5 ich SPI TFTLCD Display will not work. You can use that display only from your application via SPI commands (something like custom driver), but not from Android Things system.

out of memory exception android in android?

i am making an application and on the start of application i want to display a picture but i get this out of memory exception. i used a lot of shared Preferences in the code that is not yet executed. so this rises 2 questions -
is memory for shared Preferences allocated at the beginning itself ?
and is the memory for shared Preferences allocated in the apps heap memory ?
should i clear the shared preferences and use database instead . will that solve the problem ?
Android hardware must at least support 2048x2048.
For OpenGL I used:
int[] maxSize = new int[1];
gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxSize, 0);
For Nexus 4 it equals to 4096
For Sansung 2 it equals to 4096
You can calculate [(Height in pixels) x (length in pixels) x (bit depth)] / 8 / 1024 = image size in kilobytes (KB)
So be sure that you have proper image size.
Hope it will help,

Why max size of SurfaceView(Android) for play video is 1024x1024?

I use SurfaceView for play video. I use Samsung Galaxy Tab to test. I set size:
LinearLayout.LayoutParams videoViewParams = new LinearLayout.LayoutParams(m_mainView.getPictureWidth(), m_mainView.getPictureHeight());
mPreview = (SurfaceView) videoView.findViewById(R.id.surface);
mPreview.setLayoutParams(videoViewParams);
When mainView.getPictureWidth() or mainView.getPictureHeight() is higer then 1024 - i get message in logcat:
01-12 11:49:15.839: ERROR/SurfaceFlinger(2491): LayerBuffer init temp buff failed with w=1210, h=922, exp max=1024x1024 on 0
and i see only black screen.
Why?
In my application I use video scaling, and sometimes I need to get a video of a size greater than 1024.
It is suspected that this restriction only on Samsung. Checked on emulators - all ok!Found a single theme -
a similar problemt where people asked him to test the media player (and he says that for all its devices, the application works correctly). One user is the same problem on Samsung Galaxy S. Only he exp max = 800x800. Ie obtained here is taken the maximum value of screen sizes and forms the limit.
Any ideas?
I still have 2 ideas:
1)Make a zoom limit for all devices (Set the maximum size of video as a maximum size of one side of the screen). But in this case sometimes zoom in general will not or he will be very small.
2)Catch this log about error and show the user a dialogue that in such a zoom video to play will not work. But how to catch this log?
What do you think about this?

How to measure VRAM consumption on Android?

I want to acquire怀Android Device VRAM size.
Is there a method for acquisition from the program?
Let's do some calculation using Nexus One:
Screen resolution is 480x800. So minimum required video memory size would be:
400 * 800 * 4 bytes = 1536000 bytes
Assuming that driver may (and normally should) use several buffers, we should also expect values like:
1536000 * 2 bytes = 3072000 bytes
1536000 * 3 bytes = 4608000 bytes
etc...
It would be weird to have values that are not multiple of 1536000 (or W x H x 4 in general).
After some searches on Android internals I've found this documentation :
...Android makes two requirements of the driver: a linear address space of mappable memory that it can write to directly...accessing the driver by calling open on /dev/fb0...
So I tried and take size of /dev/graphics/fb0 file (on my device there is no /dev/fb0).
But a direct approach doesn't work:
File file = new File("/dev/graphics/fb0");
file.length(); // ==0, doesn't work, no read access
Using next trick you can get actual size of fb0:
>adb pull /dev/graphics/fb0
1659 KB/s (4608000 bytes in 2.712s)
Video memory is ~4mb (Nexus One). Let's check if this is multiple of Nexus screen size:
4608000/1536000 = 3
It looks like a right value. And we also can say that driver uses three screen buffers.
So, as a conclusion, you can detect video memory size using adb, but you can't use this approach from your android application in runtime due to file access restrictions.
You typically do not have a dedicated "VRAM" on mobile devices. At least you don't have it with PowerVR architectures (wich totally dominate the market with their MBX and SGX cores).
That is, the OpenGL driver allocates normal RAM until you run out of it, and the more you allocate the less you have left for your application.
The Android/OpenGL APIs don't offer explicit methods to read the VRAM size from a given device.
Poor man solution:
You could try to infer the VRAM size in an empiric way adding 1MB texture until you get an out of memory error from gl.glGetError().
From your "dmesg" output u can read off the VRAM, so for my Tablet:
> [ 0.000000] Machine: TDM3730 [ 0.000000] Reserving 12582912
> bytes SDRAM for VRAM
>
> 7>[ 3.929962] VRAM: checking region 9f400000 3072
> <4>[ 3.929992] Failed. Allocating 4194304 bytes for fb 0
> <7>[ 3.935333] VRAM: alloc mem type 0 size 4194304 paddr dec2bd4c
> <7>[ 3.935485] VRAM: checking region 9f400000 3072
> <7>[ 3.935485] VRAM: found 9f400000, end a0000000
> <6>[ 3.936584] android_usb gadget: high speed config #1: android
> <4>[ 3.960113] allocating 4194304 bytes for fb 1
or details at:
http://pastebin.com/jQSXQqHh
Is simple just count how many Mb ram that from usable to real capacity of the ram, example for my lenovo a369i has 512 RAM Module, but in setting app only showing 471 Mb usable so the 41Mb left is reserved for the GPU, so the conclusion is my a369i has 41Mb vram
This method is based from shared graphics memory (wiki)
I suspect that android.os.StatFs is what you're looking for:
http://developer.android.com/reference/android/os/StatFs.html

Categories

Resources