Android DPI bug


#1

When I’m trying to retrieve DPI of the main display on Android using Desktop::getInstance().getDisplays().getMainDisplay().dpi I get zero.

I’ve wrote a quick fix of this bug, but I’m not sure it is correct.

JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, setScreenSize, void, (JNIEnv* env, jobject activity,
                                                                          jint screenWidth, jint screenHeight,
                                                                          jint dpi))
{
    android.screenWidth = screenWidth;
    android.screenHeight = screenHeight;
    android.dpi = dpi;
	
    const_cast <Desktop::Displays&> (Desktop::getInstance().getDisplays()).refresh();
    Desktop::Displays::Display& d = 
	const_cast <Desktop::Displays&> (Desktop::getInstance().getDisplays())
	.displays.getReference(0);
    d.dpi = (int) dpi;
	
}

May be the same topic has been created already, but I haven’t found anything about this issue here.

P.S. Sorry for my broken english. I’m russian.


#2

Ah, thanks for the heads-up!

Your fix isn't quite correct, but I've sorted it out now if you want to grab the latest code!


#3

Thanks for your response.
I’m currently developing some kind of organizer application which I plan to use on desktop and android.

Recently I’ve found another couple of bugs on Android.
The first is that if you call DocumentWindow::setUsingNativeTitleBar(true) the application crashes. The same happens when you call setTitleBarButtonsRequired(DocumentWindow::closeButton, false).

Another bug appears when you try to change orientation of device when components with OpenGLContext attached are on the screen. The application simply hangs without writing anything to log.

I’m new to android development, especially to debugging of native libraries, so if you tell me how can I collect required information, I can send it to you.

I also can run adbWireless on my device, so you can debug applications remotely.


#4

Presumably when you call setUsingNativeTitleBar, it's an assertion, not a crash, right? Because obviously there aren't any native title bars on android.

I think hugh had been doing some work with the GL/rotation thing, and I thought that was working now.. Will investigate when I get chance..


#5

As I know, assertions have no effect when Release configuration is selected.

You can just build the JuceDemo project using the Release configuration and see that it crashes when you select “Look-and-feel->Use native window title bar” menu item.

And I’m sure, it’s a crash. Here is the log.

11-05 18:32:15.330: I/InputReader(2300): Touch event's action is 0x1 (deviceType=0) [pCnt=1, s=]
11-05 18:32:15.330: I/InputDispatcher(2300): Delivering touch to current input target: action: 0x1
11-05 18:32:15.330: I/InputDispatcher(2300): Delivering touch to current input target: action: 0x1
11-05 18:32:15.330: I/InputDispatcher(2300): Delivering touch to current input target: action: 0x1
11-05 18:32:15.330: I/InputDispatcher(2300): Delivering touch to current input target: action: 0x1
11-05 18:32:15.440: D/GestureDetector(7822): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 3 mFalseSizeCnt:0
11-05 18:32:15.575: A/libc(7822): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 7822 (com.juce)
11-05 18:32:15.675: I/DEBUG(1918): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
11-05 18:32:15.675: I/DEBUG(1918): Build fingerprint: 'samsung/t03gxx/t03g:4.1.1/JRO03C/N7100XXALJ3:user/release-keys'
11-05 18:32:15.675: I/DEBUG(1918): pid: 7822, tid: 7822, name: com.juce  >>> com.juce <<<
11-05 18:32:15.675: I/DEBUG(1918): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
11-05 18:32:15.825: I/DEBUG(1918):     r0 00000000  r1 40dfa498  r2 00000005  r3 408f2c98
11-05 18:32:15.825: I/DEBUG(1918):     r4 bed3f254  r5 00000000  r6 570c9cb8  r7 00000001
11-05 18:32:15.825: I/DEBUG(1918):     r8 408d8ec5  r9 00000000  sl bed3f2a0  fp bed3f304
11-05 18:32:15.825: I/DEBUG(1918):     ip 408f2ebc  sp bed3f228  lr 40886893  pc 40886896  cpsr 60000030
11-05 18:32:15.825: I/DEBUG(1918):     d0  000000c843480000  d1  0000000043480000
11-05 18:32:15.825: I/DEBUG(1918):     d2  0000000000000000  d3  44a0000000000000
11-05 18:32:15.825: I/DEBUG(1918):     d4  0000003200000000  d5  44a0000044340000
11-05 18:32:15.825: I/DEBUG(1918):     d6  449fe0004433c000  d7  0000000000000000
11-05 18:32:15.825: I/DEBUG(1918):     d8  0000000000000000  d9  0000000000000000
11-05 18:32:15.825: I/DEBUG(1918):     d10 0000000000000000  d11 0000000000000000
11-05 18:32:15.825: I/DEBUG(1918):     d12 0000000000000000  d13 0000000000000000
11-05 18:32:15.825: I/DEBUG(1918):     d14 0000000000000000  d15 0000000000000000
11-05 18:32:15.825: I/DEBUG(1918):     d16 4024000000000000  d17 4024000000000000
11-05 18:32:15.825: I/DEBUG(1918):     d18 00000000027f8000  d19 2000000840070480
11-05 18:32:15.825: I/DEBUG(1918):     d20 ffffffffffffffff  d21 ffffffffffffffff
11-05 18:32:15.825: I/DEBUG(1918):     d22 ffffffffffffffff  d23 ffffffffffffffff
11-05 18:32:15.825: I/DEBUG(1918):     d24 ffffffffffffffff  d25 ffffffffffffffff
11-05 18:32:15.825: I/DEBUG(1918):     d26 ffffffffffffffff  d27 ffffffffffffffff
11-05 18:32:15.825: I/DEBUG(1918):     d28 ffffffffffffffff  d29 ffffffffffffffff
11-05 18:32:15.825: I/DEBUG(1918):     d30 ffffffffffffffff  d31 ffffffffffffffff
11-05 18:32:15.825: I/DEBUG(1918):     scr 60000011
11-05 18:32:15.825: I/DEBUG(1918): backtrace:
11-05 18:32:15.825: I/DEBUG(1918):     #00  pc 00039896  /system/lib/libdvm.so
11-05 18:32:15.825: I/DEBUG(1918):     #01  pc 00040d4f  /system/lib/libdvm.so
11-05 18:32:15.825: I/DEBUG(1918):     #02  pc 0028b2e8  /data/data/com.juce/lib/libjuce_jni.so (juce::GlobalRef::callBooleanMethod(_jmethodID*, ...) const+44)
11-05 18:32:15.825: I/DEBUG(1918):     #03  pc 00376bb0  /data/data/com.juce/lib/libjuce_jni.so (juce::Component::takeKeyboardFocus(juce::Component::FocusChangeType)+68)
11-05 18:32:15.825: I/DEBUG(1918): stack:
11-05 18:32:15.825: I/DEBUG(1918):          bed3f1e8  00000000  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f1ec  00000000  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f1f0  000003e8  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f1f4  00000008  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f1f8  00000000  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f1fc  5ce29064  /dev/binder
11-05 18:32:15.825: I/DEBUG(1918):          bed3f200  5ce2906c  /dev/binder
11-05 18:32:15.825: I/DEBUG(1918):          bed3f204  31945112  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f208  00000000  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f20c  516d76d0  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f210  516d7a50  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f214  31945112  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f218  bed3f254  [stack]
11-05 18:32:15.825: I/DEBUG(1918):          bed3f21c  00000000  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f220  df0027ad  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f224  00000000  
11-05 18:32:15.825: I/DEBUG(1918):     #00  bed3f228  bed3f254  [stack]
11-05 18:32:15.825: I/DEBUG(1918):          bed3f22c  00000000  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f230  570c9cb8  /dev/ashmem/dalvik-LinearAlloc (deleted)
11-05 18:32:15.825: I/DEBUG(1918):          bed3f234  00000000  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f238  00000000  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f23c  570c9cb8  /dev/ashmem/dalvik-LinearAlloc (deleted)
11-05 18:32:15.825: I/DEBUG(1918):          bed3f240  40d81068  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f244  4088dd53  /system/lib/libdvm.so
11-05 18:32:15.825: I/DEBUG(1918):     #01  bed3f248  00000000  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f24c  570c9cb8  /dev/ashmem/dalvik-LinearAlloc (deleted)
11-05 18:32:15.825: I/DEBUG(1918):          bed3f250  40d81068  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f254  40d81068  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f258  408ed9e5  /system/lib/libdvm.so
11-05 18:32:15.825: I/DEBUG(1918):          bed3f25c  00000000  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f260  00000001  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f264  9e29f697  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f268  587ff5dc  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f26c  587ff5a8  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f270  5d794318  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f274  00000002  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f278  00000001  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f27c  56f88bfc  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f280  40ca59b0  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f284  5d3b22ec  /data/data/com.juce/lib/libjuce_jni.so (juce::GlobalRef::callBooleanMethod(_jmethodID*, ...) const+48)
11-05 18:32:15.825: I/DEBUG(1918):     #02  bed3f288  587ff5dc  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f28c  bed3f2a0  [stack]
11-05 18:32:15.825: I/DEBUG(1918):          bed3f290  587ff4fc  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f294  587ff840  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f298  5d49dbb4  /data/data/com.juce/lib/libjuce_jni.so (juce::Component::takeKeyboardFocus(juce::Component::FocusChangeType)+72)
11-05 18:32:15.825: I/DEBUG(1918):          bed3f29c  570c9cb8  /dev/ashmem/dalvik-LinearAlloc (deleted)
11-05 18:32:15.825: I/DEBUG(1918):          bed3f2a0  587ff4fc  
11-05 18:32:15.825: I/DEBUG(1918):          bed3f2a4  5d7940b8  
11-05 18:32:15.830: I/DEBUG(1918): memory near r1:
11-05 18:32:15.830: I/DEBUG(1918):     40dfa478 40dfa3d8 592ca0a8 592ff3b8 0000001a  ...@..,Y../Y....
11-05 18:32:15.830: I/DEBUG(1918):     40dfa488 40e22868 00000000 00000000 00001a2b  h(.@........+...
11-05 18:32:15.830: I/DEBUG(1918):     40dfa498 40dd31e8 00000000 00000000 00000000  .1.@............
11-05 18:32:15.830: I/DEBUG(1918):     40dfa4a8 00000000 00000000 592eb1f3 00000000  ...........Y....
11-05 18:32:15.830: I/DEBUG(1918):     40dfa4b8 00020001 50000184 40cc9000 00000007  .......P...@....
11-05 18:32:15.830: I/DEBUG(1918): memory near r3:
11-05 18:32:15.830: I/DEBUG(1918):     408f2c78 40874dfc 40874e88 40874efc 40874f38  .M.@.N.@.N.@8O.@
11-05 18:32:15.830: I/DEBUG(1918):     408f2c88 4089f061 408a19b5 408b826d 408b4651  a..@...@m..@QF.@
11-05 18:32:15.830: I/DEBUG(1918):     408f2c98 00000000 00000000 00000000 40106111  .............a.@
11-05 18:32:15.830: I/DEBUG(1918):     408f2ca8 400f9828 400f8f24 400f8a98 400f8b74  (..@$..@...@t..@
11-05 18:32:15.830: I/DEBUG(1918):     408f2cb8 400f9c84 400938dc 40093538 400a09f4  ...@.8.@85.@...@
11-05 18:32:15.830: I/DEBUG(1918): memory near r4:
11-05 18:32:15.830: I/DEBUG(1918):     bed3f234 00000000 00000000 570c9cb8 40d81068  ...........Wh..@
11-05 18:32:15.830: I/DEBUG(1918):     bed3f244 4088dd53 00000000 570c9cb8 40d81068  S..@.......Wh..@
11-05 18:32:15.830: I/DEBUG(1918):     bed3f254 40d81068 408ed9e5 00000000 00000001  h..@...@........
11-05 18:32:15.830: I/DEBUG(1918):     bed3f264 9e29f697 587ff5dc 587ff5a8 5d794318  ..)....X...X.Cy]
11-05 18:32:15.830: I/DEBUG(1918):     bed3f274 00000002 00000001 56f88bfc 40ca59b0  ...........V.Y.@
11-05 18:32:15.830: I/DEBUG(1918): memory near r6:
11-05 18:32:15.830: I/DEBUG(1918):     570c9c98 000011fb 5934f4df 58f2ef18 00000000  ......4Y...X....
11-05 18:32:15.830: I/DEBUG(1918):     570c9ca8 00000000 00000000 40081cc8 00000000  ...........@....
11-05 18:32:15.830: I/DEBUG(1918):     570c9cb8 40dfa498 00000011 0002019f 00010002  ...@............
11-05 18:32:15.830: I/DEBUG(1918):     570c9cc8 593ff0d1 40d82928 000021a7 59359171  ..?Y().@.!..q.5Y
11-05 18:32:15.830: I/DEBUG(1918):     570c9cd8 58f2ef3c 00000000 00000000 00000000  <..X............
11-05 18:32:15.830: I/DEBUG(1918): memory near r8:
11-05 18:32:15.830: I/DEBUG(1918):     408d8ea4 00436663 42666345 66634500 6345005a  cfC.EcfB.EcfZ.Ec
11-05 18:32:15.830: I/DEBUG(1918):     408d8eb4 45004c66 44006663 53004600 42004300  fL.Ecf.D.F.S.C.B
11-05 18:32:15.830: I/DEBUG(1918):     408d8ec4 45005a00 00757563 63450066 6d002e6d  .Z.Ecuu.f.Ecm..m
11-05 18:32:15.830: I/DEBUG(1918):     408d8ed4 664c4500 4c450044 45004666 004a664c  .ELfD.ELfF.ELfJ.
11-05 18:32:15.830: I/DEBUG(1918):     408d8ee4 49664c45 664c4500 4c450053 45004366  ELfI.ELfS.ELfC.E
11-05 18:32:15.830: I/DEBUG(1918): memory near sl:
11-05 18:32:15.830: I/DEBUG(1918):     bed3f280 40ca59b0 5d3b22ec 587ff5dc bed3f2a0  .Y.@.";]...X....
11-05 18:32:15.830: I/DEBUG(1918):     bed3f290 587ff4fc 587ff840 5d49dbb4 570c9cb8  ...X@..X..I]...W
11-05 18:32:15.830: I/DEBUG(1918):     bed3f2a0 587ff4fc 5d7940b8 587ff4f8 00000002  ...X.@y]...X....
11-05 18:32:15.830: I/DEBUG(1918):     bed3f2b0 00000001 587ff840 40ca59a0 00000002  ....@..X.Y.@....
11-05 18:32:15.830: I/DEBUG(1918):     bed3f2c0 56f88c08 5d49dcac 587ff840 00000002  ...V..I]@..X....
11-05 18:32:15.830: I/DEBUG(1918): memory near fp:
11-05 18:32:15.830: I/DEBUG(1918):     bed3f2e4 4086ae74 00000001 40895a43 56f88bf8  t..@....CZ.@...V
11-05 18:32:15.830: I/DEBUG(1918):     bed3f2f4 00000001 41e5c860 00000000 00000001  ....`..A........
11-05 18:32:15.830: I/DEBUG(1918):     bed3f304 4089a0c7 56f88bf8 5881dde7 5d49e184  ...@...V...X..I]
11-05 18:32:15.830: I/DEBUG(1918):     bed3f314 40ca59b0 00000000 00000000 4022a307  .Y.@.........."@
11-05 18:32:15.830: I/DEBUG(1918):     bed3f324 4013aa6c 40e0cb28 5881b590 56f88cd4  l..@(..@...X...V
11-05 18:32:15.830: I/DEBUG(1918): memory near ip:
11-05 18:32:15.830: I/DEBUG(1918):     408f2e9c 400f7314 400fd224 400fbbb0 400fd478  .s.@$..@...@x..@
11-05 18:32:15.830: I/DEBUG(1918):     408f2eac 40104e39 400fbef4 400f664c 400fd024  9N.@...@Lf.@$..@
11-05 18:32:15.830: I/DEBUG(1918):     408f2ebc 400fd2d0 400fd0f4 4010380d 400c1971  ...@...@.8.@q..@
11-05 18:32:15.830: I/DEBUG(1918):     408f2ecc 400c1b0d 400f67c0 400fbc9c 400fbce4  ...@.g.@...@...@
11-05 18:32:15.830: I/DEBUG(1918):     408f2edc 401039fd 40103a81 40103ae9 4010422b  .9.@.:.@.:.@+B.@
11-05 18:32:15.830: I/DEBUG(1918): memory near sp:
11-05 18:32:15.830: I/DEBUG(1918):     bed3f208 00000000 516d76d0 516d7a50 31945112  .....vmQPzmQ.Q.1
11-05 18:32:15.830: I/DEBUG(1918):     bed3f218 bed3f254 00000000 df0027ad 00000000  T........'......
11-05 18:32:15.830: I/DEBUG(1918):     bed3f228 bed3f254 00000000 570c9cb8 00000000  T..........W....
11-05 18:32:15.830: I/DEBUG(1918):     bed3f238 00000000 570c9cb8 40d81068 4088dd53  .......Wh..@S..@
11-05 18:32:15.830: I/DEBUG(1918):     bed3f248 00000000 570c9cb8 40d81068 40d81068  .......Wh..@h..@
11-05 18:32:15.830: I/DEBUG(1918): code around pc:
11-05 18:32:15.830: I/DEBUG(1918):     40886874 0005213e 460db57f 21014604 46162000  >!.....F.F.!. .F
11-05 18:32:15.830: I/DEBUG(1918):     40886884 faaef019 46296823 f01068d8 6831fafd  ....#h)F.h....1h
11-05 18:32:15.830: I/DEBUG(1918):     40886894 68004605 d0154288 fce6f031 6930b990  .F.h.B..1.....0i
11-05 18:32:15.830: I/DEBUG(1918):     408868a4 490a6833 68289000 4a094479 447a6980  3h.I..(hyD.J.izD
11-05 18:32:15.830: I/DEBUG(1918):     408868b4 20059001 f7e3699b 4620ee24 fb88f7ff  ... .i..$. F....
11-05 18:32:15.830: I/DEBUG(1918): code around lr:
11-05 18:32:15.830: I/DEBUG(1918):     40886870 0005179c 0005213e 460db57f 21014604  ....>!.....F.F.!
11-05 18:32:15.830: I/DEBUG(1918):     40886880 46162000 faaef019 46296823 f01068d8  . .F....#h)F.h..
11-05 18:32:15.830: I/DEBUG(1918):     40886890 6831fafd 68004605 d0154288 fce6f031  ..1h.F.h.B..1...
11-05 18:32:15.830: I/DEBUG(1918):     408868a0 6930b990 490a6833 68289000 4a094479  ..0i3h.I..(hyD.J
11-05 18:32:15.830: I/DEBUG(1918):     408868b0 447a6980 20059001 f7e3699b 4620ee24  .izD... .i..$. F
11-05 18:32:15.910: I/DEBUG(1918): !@dumpstate -k -t -z -d -o /data/log/dumpstate_app_native -m 7822
11-05 18:32:15.910: I/BootReceiver(2300): Copying /data/tombstones/tombstone_03 to DropBox (SYSTEM_TOMBSTONE)
11-05 18:32:15.920: I/dumpstate(8149): begin

Whan I called setUsingNativeTitleBar() I just wanted to hide the caption of my window to let the application use more screen space. Is there any other way to do this?


#6

I forgot to say, some old JuceDemo versions (about 5 months ago, I don’t remember exactly) haven’t this issue. The title bar just disappeared when you selected those menu item.


#7


#8

Thanks, hugh! Now the application graphics hangs not so frequently. But still there are cases when the problem occurs.
I know, the process does not hang. There are two threads in my application, which write debug strings to log. I see new log messages from these threads even when the graphics is frozen.

Does anyone know how to deal with setUsingNativeTitleBar / setTitleBarHeight(0) / setTitleBarButtonsRequired issue? I just want to hide DocumentWindow’s title bar.


#9

 

Make your app `setFullScreen(true)'.

add,

 

android:theme="@android:style/Theme.NoTitleBar"

 

to your <activity> in AndroidManifest.xml

 


#10

I know how to hide Android activity title but I’m asking how can I hide JUCE window’s title bar with close, maximize and minimize buttons. It is really useless in my case because my application has only one window and the JUCE title bar buttons are too small and it’s difficult to press it with your fingers.


#11

You don't need to hide the titlebar - just don't use a DocumentWindow as your component class, use something else without a titlebar, e.g. ResizableWindow or just a plain old Component.


#12

It really solved my problem! Thanks a lot!
May I ask you another question? Is it possible to handle the press of “back” button on android? I mean using only JUCE, without writing additional Java code.


#13

The back button is definitely on my to-do-list..


#14

Here is my dirty implementation of back button.

======================================================
juce_KeyPress.h

static const int rewindKey;      /**< key-code for a multimedia 'rewind' key, (not all keyboards will have one) */

+++++++++++++
static const int backKey = 4;		/**< key-code for 'back' key if the current device has one */
//As I know, the actual key code value must be defined into platform specific .cpp file.
//I've tried to do this, but I got linker errors

#15

 

here's the java you need and also fixes for other buttons. There would need to be a hook into Juce added for the back button case.



 @Override
        public boolean onKeyDown(int keyCode, KeyEvent event)
        {
            switch (keyCode)
            {
            case KeyEvent.KEYCODE_BACK:
                if (event.getRepeatCount() == 0)
                {
                    // calls `finish' by default
                    onBackPressed();
                }
                break;
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_MENU:
                return super.onKeyDown(keyCode, event);
            default:
                handleKeyDown(host, keyCode, event.getUnicodeChar());
            }
            return true;
        }    

        @Override
        public boolean onKeyUp(int keyCode, KeyEvent event)
        {
            switch (keyCode)
            {
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_MENU:
                return super.onKeyUp(keyCode, event);
            default:
                handleKeyUp(host, keyCode, event.getUnicodeChar());
            }
            return true;
        }