Compdigitec Labs

Fixing IllegalStateException: The content of the adapter has changed but ListView did not receive a notification

By admin | November 16, 2013

Recently while working with a custom BaseAdapter in ListView, I came across this error:

E/InputEventReceiver(30380): Exception dispatching input event.
E/MessageQueue-JNI(30380): Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI(30380): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131230721, class android.widget.ListView) with Adapter(class com.compdigitec.libvlcandroidsample.DirectoryAdapter)]
E/MessageQueue-JNI(30380): 	at android.widget.ListView.layoutChildren(ListView.java:1544)
E/MessageQueue-JNI(30380): 	at android.widget.AbsListView.onTouchEvent(AbsListView.java:3403)
E/MessageQueue-JNI(30380): 	at android.view.View.dispatchTouchEvent(View.java:7239)
E/MessageQueue-JNI(30380): 	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
E/MessageQueue-JNI(30380): 	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
E/MessageQueue-JNI(30380): 	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
E/MessageQueue-JNI(30380): 	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
E/MessageQueue-JNI(30380): 	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
E/MessageQueue-JNI(30380): 	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
E/MessageQueue-JNI(30380): 	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
E/MessageQueue-JNI(30380): 	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
E/MessageQueue-JNI(30380): 	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
E/MessageQueue-JNI(30380): 	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
E/MessageQueue-JNI(30380): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
E/MessageQueue-JNI(30380): 	at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
E/MessageQueue-JNI(30380): 	at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
E/MessageQueue-JNI(30380): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
E/MessageQueue-JNI(30380): 	at android.view.View.dispatchPointerEvent(View.java:7419)
E/MessageQueue-JNI(30380): 	at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
E/MessageQueue-JNI(30380): 	at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
E/MessageQueue-JNI(30380): 	at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
E/MessageQueue-JNI(30380): 	at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
E/MessageQueue-JNI(30380): 	at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
E/MessageQueue-JNI(30380): 	at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
E/MessageQueue-JNI(30380): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MessageQueue-JNI(30380): 	at android.os.MessageQueue.next(MessageQueue.java:125)
E/MessageQueue-JNI(30380): 	at android.os.Looper.loop(Looper.java:124)
E/MessageQueue-JNI(30380): 	at android.app.ActivityThread.main(ActivityThread.java:5191)
E/MessageQueue-JNI(30380): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/MessageQueue-JNI(30380): 	at java.lang.reflect.Method.invoke(Method.java:511)
E/MessageQueue-JNI(30380): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
E/MessageQueue-JNI(30380): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
E/MessageQueue-JNI(30380): 	at dalvik.system.NativeStart.main(Native Method)

this.notifyDataSetChanged() was already being called, so that couldn’t have been the problem.

The solution?
If registerDataSetObserver() and unregisterDataSetObserver() are going to be overridden, ensure that the superclass’ methods are being called too. If you forget to call them, then when Android registers the ListView dataset observer, nothing is going to happen.

    @Override
    public void registerDataSetObserver(DataSetObserver arg0) {
        // ...stuff
        super.registerDataSetObserver(arg0);
    }

    @Override
    public void unregisterDataSetObserver(DataSetObserver arg0) {
        // ...stuff
        super.unregisterDataSetObserver(arg0);
    }

Topics: Mobile | No Comments »

Importing upstream tarballs in Debian with gbp import-orig

By admin | October 6, 2013

gbp import-orig --pristine-tar --upstream-branch=upstream ../programname-0.9.9.tar.xz

To build it:

gbp buildpackage --git-ignore-new --git-export-dir=../build-area/ --git-no-purge

Topics: Linux | No Comments »

Apache Active Directory authentication

By admin | September 15, 2013

Add this to /etc/ldap/ldap.conf:

REFERRALS off

Then add this to a block:

 AuthLDAPBindDN "ApacheUser@example.com"
 AuthLDAPBindPassword "the password used for apache lookups"
 AuthLDAPURL "ldap://192.168.88.2:389/dc=example,dc=com?sAMAccountName?sub?(objectClass=user)" NONE

 AuthzLDAPAuthoritative off
 AuthBasicProvider ldap
 AuthType Basic
 AuthName "Please enter your computer logon (Active Directory) to enter."
 # Important, otherwise you get "(9)Bad file descriptor: Could not open password file: (null)"
 AuthUserFile /dev/null
 Require ldap-group cn=Users
 Require valid-user

Topics: Linux | No Comments »

Reverse proxy HTTPS with Apache

By admin | August 23, 2013

The procedure is mostly similar to the procedure with regular HTTP, but there are a few gimmicks involved here:

  1. Generate a self-signed one or purchase a SSL certificate (*.crt) for the server in question.
  2. Make sure you run ‘sudo a2enmod ssl‘ to enable SSL.
  3. Make sure you have enable the proxy module with ‘sudo a2enmod proxy‘ as well.

Below is a sample reverse HTTPS proxy configuration.

<VirtualHost *:443>
    <Proxy *>
     Order Deny,Allow
     Allow from all
    </Proxy>

 SSLEngine On
 SSLProxyEngine On
 SSLCertificateFile /etc/apache2/cert/server.crt <!-- path to your certifcate and key -->
 SSLCertificateKeyFile /etc/apache2/cert/server.key
 SSLProxyCheckPeerCN off
 SSLProxyCheckPeerExpire off
 SSLProxyCheckPeerName off

 ProxyRequests Off
 ProxyPass / https://192.168.42.3/
 ProxyPassReverse / https://192.168.42.3/
 ProxyPreserveHost On
</VirtualHost>

Replace 192.168.42.3 with the internal IP address of your server, as before (keep the http(s):// portion).

Topics: Linux | No Comments »

CUPS web interface not working

By admin | August 17, 2013

CUPS seems to be working fine – documents can be printed and everything seems to work fine, but the web interface at http://localhost:631/ doesn’t work, returning something like:

Firefox can’t establish a connection to the server at localhost:631.

Solution:

Open /etc/cups/cupsd.conf as root and ensure that the line:

Listen 631

Exists somewhere in the file. Then save it and close it. Finally, restart CUPS:

sudo /etc/init.d/cups restart

Then fire up your web browser and head to http://localhost:631/ and enjoy the CUPS web interface.

Topics: Linux | No Comments »

OpenGL acceleration in Debian/Ubuntu

By admin | June 20, 2013

Getting “Error:  couldn’t get an RGB, Double-buffered visual“?

1) Install video driver

Example:

sudo apt-get install xserver-xorg-video-intel # or whatever nvidia package for your card

2) Install OpenGL and related libraries/tools:

sudo apt-get install libgl1-mesa-dri libgl1-mesa-glx mesa-utils

3) Restart X server or restart computer:

sudo shutdown now -r

4) Test acceleration:

glxgears
glxinfo

Sample working output:

name of display: :0
display: :0  screen: 0
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4
server glx extensions:
    GLX_ARB_multisample, GLX_EXT_import_context, GLX_EXT_texture_from_pixmap,
    GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_MESA_copy_sub_buffer,
    GLX_OML_swap_method, GLX_SGI_swap_control, GLX_SGIS_multisample,
    GLX_SGIX_fbconfig, GLX_SGIX_pbuffer, GLX_SGIX_visual_select_group,
    GLX_INTEL_swap_event
client glx vendor string: Mesa Project and SGI
client glx version string: 1.4
client glx extensions:
    GLX_ARB_create_context, GLX_ARB_create_context_profile,
    GLX_ARB_create_context_robustness, GLX_ARB_framebuffer_sRGB,
    GLX_ARB_get_proc_address, GLX_ARB_multisample, GLX_EXT_import_context,
    GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_EXT_framebuffer_sRGB,
    GLX_EXT_create_context_es2_profile, GLX_MESA_copy_sub_buffer,
    GLX_MESA_multithread_makecurrent, GLX_MESA_swap_control,
    GLX_OML_swap_method, GLX_OML_sync_control, GLX_SGI_make_current_read,
    GLX_SGI_swap_control, GLX_SGI_video_sync, GLX_SGIS_multisample,
    GLX_SGIX_fbconfig, GLX_SGIX_pbuffer, GLX_SGIX_visual_select_group,
    GLX_EXT_texture_from_pixmap, GLX_INTEL_swap_event
GLX version: 1.4
GLX extensions:
    GLX_ARB_get_proc_address, GLX_ARB_multisample, GLX_EXT_import_context,
    GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_MESA_copy_sub_buffer,
    GLX_MESA_multithread_makecurrent, GLX_MESA_swap_control,
    GLX_OML_swap_method, GLX_OML_sync_control, GLX_SGI_make_current_read,
    GLX_SGI_swap_control, GLX_SGI_video_sync, GLX_SGIS_multisample,
    GLX_SGIX_fbconfig, GLX_SGIX_pbuffer, GLX_SGIX_visual_select_group,
    GLX_EXT_texture_from_pixmap, GLX_INTEL_swap_event
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) 915GM x86/MMX/SSE2
OpenGL version string: 1.4 Mesa 9.1.3
OpenGL extensions:
    GL_ARB_multisample, GL_EXT_abgr, GL_EXT_bgra, GL_EXT_blend_color,
    GL_EXT_blend_minmax, GL_EXT_blend_subtract, GL_EXT_copy_texture,
    GL_EXT_polygon_offset, GL_EXT_subtexture, GL_EXT_texture_object,
    GL_EXT_vertex_array, GL_EXT_compiled_vertex_array, GL_EXT_texture,
    GL_EXT_texture3D, GL_IBM_rasterpos_clip, GL_ARB_point_parameters,
    GL_EXT_draw_range_elements, GL_EXT_packed_pixels, GL_EXT_point_parameters,
    GL_EXT_rescale_normal, GL_EXT_separate_specular_color,
    GL_EXT_texture_edge_clamp, GL_SGIS_generate_mipmap,
    GL_SGIS_texture_border_clamp, GL_SGIS_texture_edge_clamp,
    GL_SGIS_texture_lod, GL_ARB_multitexture, GL_IBM_multimode_draw_arrays,
    GL_IBM_texture_mirrored_repeat, GL_3DFX_texture_compression_FXT1,
    GL_ARB_texture_cube_map, GL_ARB_texture_env_add, GL_ARB_transpose_matrix,
    GL_EXT_blend_func_separate, GL_EXT_fog_coord, GL_EXT_multi_draw_arrays,
    GL_EXT_secondary_color, GL_EXT_texture_env_add,
    GL_EXT_texture_filter_anisotropic, GL_EXT_texture_lod_bias,
    GL_INGR_blend_func_separate, GL_NV_blend_square, GL_NV_light_max_exponent,
    GL_NV_texgen_reflection, GL_NV_texture_env_combine4, GL_S3_s3tc,
    GL_SUN_multi_draw_arrays, GL_ARB_texture_border_clamp,
    GL_ARB_texture_compression, GL_EXT_framebuffer_object,
    GL_EXT_texture_compression_s3tc, GL_EXT_texture_env_combine,
    GL_EXT_texture_env_dot3, GL_MESA_window_pos, GL_NV_packed_depth_stencil,
    GL_NV_texture_rectangle, GL_ARB_depth_texture, GL_ARB_shadow,
    GL_ARB_texture_env_combine, GL_ARB_texture_env_crossbar,
    GL_ARB_texture_env_dot3, GL_ARB_texture_mirrored_repeat,
    GL_ARB_window_pos, GL_EXT_stencil_two_side, GL_EXT_texture_cube_map,
    GL_APPLE_packed_pixels, GL_APPLE_vertex_array_object, GL_ARB_draw_buffers,
    GL_ARB_fragment_program, GL_ARB_fragment_shader, GL_ARB_shader_objects,
    GL_ARB_vertex_program, GL_ARB_vertex_shader, GL_ATI_draw_buffers,
    GL_ATI_texture_env_combine3, GL_EXT_shadow_funcs, GL_EXT_stencil_wrap,
    GL_MESA_pack_invert, GL_MESA_ycbcr_texture, GL_ARB_half_float_pixel,
    GL_ARB_point_sprite, GL_ARB_shading_language_100, GL_ARB_sync,
    GL_ARB_texture_non_power_of_two, GL_ARB_vertex_buffer_object,
    GL_ATI_blend_equation_separate, GL_EXT_blend_equation_separate,
    GL_OES_read_format, GL_ARB_pixel_buffer_object, GL_ARB_texture_rectangle,
    GL_EXT_pixel_buffer_object, GL_EXT_texture_compression_dxt1,
    GL_EXT_texture_rectangle, GL_ARB_framebuffer_object,
    GL_EXT_framebuffer_blit, GL_EXT_framebuffer_multisample,
    GL_EXT_packed_depth_stencil, GL_APPLE_object_purgeable,
    GL_ARB_vertex_array_object, GL_ATI_separate_stencil,
    GL_EXT_gpu_program_parameters, GL_OES_EGL_image, GL_ARB_copy_buffer,
    GL_ARB_map_buffer_range, GL_EXT_separate_shader_objects,
    GL_ARB_ES2_compatibility, GL_ARB_debug_output,
    GL_ARB_draw_elements_base_vertex, GL_ARB_explicit_attrib_location,
    GL_ARB_provoking_vertex, GL_ARB_sampler_objects, GL_EXT_provoking_vertex,
    GL_ARB_get_program_binary, GL_ARB_robustness,
    GL_ANGLE_texture_compression_dxt3, GL_ANGLE_texture_compression_dxt5,
    GL_ARB_internalformat_query, GL_ARB_texture_storage,
    GL_ARB_invalidate_subdata

Topics: Linux | No Comments »

Check if an Intent can be used in Android

By admin | June 15, 2013

Intent intent = new Intent("org.openintents.action.PICK_FILE"); // or any other intent
// add other intent options here

if(context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
    // we can use this intent
} else {
    // we can't use this intent
}

From: http://www.curious-creature.org/2008/12/15/android-can-i-use-this-intent/ [Romain Guy]

Topics: Mobile | No Comments »

Generating slope fields / direction fields with python and gnuplot

By admin | April 21, 2013

Slope field of (dy/dx) = x/y

Slope field of (dy/dx) = x/y

slopefields.py (1.9 KB)

Now you can generate your own slope field / vector field / direction field of a differential equation using open source python and gnuplot!

Topics: Linux | No Comments »

Techniques for testing Android fragments

By admin | March 4, 2013

How to test a fragment-based Android application:

Preferably test in the “don’t keep activities” mode, as this will root out a ton of bugs related to the Android lifecycle – i.e. when Android decides to kill an old activity of yours.

Case Study:

User complaint: http://forum.videolan.org/viewtopic.php?f=35&t=108743

The story so far… old versions of the VLC for Android beta, up to 0.0.10, suffer from a bug, where trying to delete something in another fragment causes the other (non-visible) fragment to receive the onContextItemSelected() call. After setting user visibility hints for that bug, a series of fragment related bugs appeared, mostly involving IllegalStateException in android.support.v4.app.FragmentManager because of duplicate fragments being added.

The problems were caused when Android decided to kill unused background activities. The interface code would try to recreate and re-add() fragments, even though Android had automatically recreated them via “android.support.fragments” in the onCreate() bundle. This would manifest after opening another activity, shutting the screen off, or having a system popup appear.

The solution was to keep better track of currently-added fragments, as member variables of the main activity may not necessarily be kept after the activity was hidden. To solve the problem, a check was implemented in onRestoreFragments() to ‘recall’ fragments that were already added. This fixed the problem permanently.

The moral of the story: watch and manage fragments very carefully in order to prevent problems.

Topics: Mobile | No Comments »

Compiling mingw-w64 with GCC 4.8

By admin | February 7, 2013

You need at least mingw-w64 rev 5579, build-essential, and a working compiler. Be sure to have installed flex and bison.

Replace the demo prefix /usr/i686-w64-mingw32 with whatever you feel like, if you want to.

Extract the gcc tarball, and pull in mpfr, mpc, and and gmp tarballs under the extracted gcc root.

sudo mkdir /usr/i686-w64-mingw32

../binutils-2.22/configure --disable-multilib --target=i686-w64-mingw32 --with-sysroot=/usr/i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32
make -j4
sudo make install

ln -s /usr/i686-w64-mingw32/i686-w64-mingw32 /usr/i686-w64-mingw32/mingw

../mingw-w64/mingw-w64-headers/configure --build=i686-linux-gnu --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32/i686-w64-mingw32 # notice the extra i686-w64-mingw32
make
sudo make install

../gcc-4.8-20130120/configure --target=i686-w64-mingw32 --disable-multilib --enable-languages=c,c++  --with-system-zlib --enable-shared --prefix=/usr/i686-w64-mingw32 --with-sysroot=/usr/i686-w64-mingw32
make all-gcc -j4
sudo make install-gcc

../mingw-w64/configure --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32 --with-sysroot=/usr/i686-w64-mingw32
make -j4
sudo su
export PATH=/usr/i686-w64-mingw32/bin:$PATH
make install
exit

cd ../gcc-4.8-20130120-build
make -j4
# /usr/i686-w64-mingw32/i686-w64-mingw32/bin/ld: cannot find dllcrt2.o: No such file or directory
sudo ln -s /usr/i686-w64-mingw32/lib/dllcrt2.o /usr/i686-w64-mingw32/mingw/lib/
make
# checking for ld that supports -Wl,--gc-sections... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
# dig into i686-w64-mingw32/libstdc++-v3/config.log, you find this:
# /usr/i686-w64-mingw32/i686-w64-mingw32/bin/ld: cannot find crt2.o: No such file or directory
# solution:
sudo ln -s /usr/i686-w64-mingw32/lib/crt2.o /usr/i686-w64-mingw32/mingw/lib/
make
sudo make install

../../../mingw-w64/mingw-w64-libraries/winstorecompat/configure --prefix=/usr/i686-w64-mingw32 --host=i686-w64-mingw32
make
sudo su
export PATH=/usr/i686-w64-mingw32/bin:$PATH
make install
exit

And just for fun, let’s test it:

i686-w64-mingw32-gcc --version
# i686-w64-mingw32-gcc (GCC) 4.8.0 20130120 (experimental)
# Copyright (C) 2013 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions.  There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

i686-w64-mingw32-gcc ~/c/hello.c

file a.exe
# a.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit

wine a.exe
# Hello, World!

Bibliography:

Topics: Linux | No Comments »

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles! « Older Entries Newer Entries »