lunedì 22 ottobre 2012

Hide status bar in Android ICS

Most of the Android developers that write applications for ICS should have noticed that it's impossible to run apps in full-screen. So how to remove the damned "status bar"? Let's check the code!

Policies needed to show/hide this bar are handled in this file:

frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Now let's search for "mStatusBarCanHide".

At a certain point there is an explicative comment that says:

// Determine whether the status bar can hide based on the size
// of the screen.  We assume sizes > 600dp are tablets where we
// will use the system bar.

So it seems that the status bar in ICS can't be hidden only in devices that are considered "tablets".

I really don't care about modifying the calculations needed to check if a device is a tablet or no, so I made a really simple mod to switch back to the old fullscreen behaviour.

I added this flag:

boolean mStatusBarForceHide = true;

and then in the code I added a check for that flag:

if (topIsFullscreen) {
    if (mStatusBarCanHide || mStatusBarForceHide ) {
        if (DEBUG_LAYOUT) Log.v(TAG, "** HIDING status bar");
        if (mStatusBar.hideLw(true)) {
            changes |= FINISH_LAYOUT_REDO_LAYOUT;

            mHandler.post(new Runnable() { public void run() {
            if (mStatusBarService != null) {
                try {
                    mStatusBarService.collapse();
                } catch (RemoteException ex) {}
            }
            }});
        }
    } else if (DEBUG_LAYOUT) {
        Log.v(TAG, "Preventing status bar from hiding by policy")     

    }
} else {
    if (DEBUG_LAYOUT) Log.v(TAG, "** SHOWING status bar: top is not fullscreen");
        if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;

}

That's all!

Now the "android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" flag in your AndroidManifest.xml should work like a charm!

domenica 14 ottobre 2012

Adb permissions issues with Ubuntu and Android ICS

If you encounter permissions problems when using the adb utility in Ubuntu with Android 4  ICS (Ice Scream Sandwich), try to follow this guide:
  1. Find your Android device vendor id by using "lsusb".
  2. echo your_vendor_id > ~/.android/adb_usb.ini
  3. adb kill-server
  4. adb start-server
  5. Create or update the /etc/udev/rules.d/51-android.rules file by adding :
    SUBSYSTEM=="usb", ATTR{idVendor}=="your_vendor_id", MODE="0666"
  6. sudo restart udev
  7. Disconnect and reconnect your Android device
  8. adb devices
Now everything should be ok!
Happy debugging!

sabato 13 ottobre 2012

Compiling Android sub-packages

This should be a really obvious question for an Android modder but I think it's better to explain how to compile sub-packages in the android source tree when doing some modifications to them.

This should be done when the whole source tree is already built.

Go in the Android source root dir and launch:

source build/envsetup.sh

Now you are ready to compile sub-packages.
A sub-package can be identified by the presence of an Android.mk file.
Android.mk files are particular makefiles that are interpreted by the Android build system.

If, for example, we want to recompile the SettingsProvider base package we only need to :

  1. cd frameworks/base/packages/SettingsProvider
  2. mm -B

The "-B" option will force the re-compilation of the whole package. If you only need to recompile just only the files you have modified then use simply "mm".

Compiled packages will be placed in the out directory, in this case the SettingsProvider.apk file will be placed in your custom /system/app/ folder.

Android default parameters

There is a really simple way to set default values of Android settings when building a new custom firmware.

Most of those parameters are declared in a resource xml file from the SettingsProvider base package located at:

frameworks/base/packages/SettingsProvider/res/values/defaults.xml

Unfortunately not of all the default parameters can be set here. For some unknown reasons (you must ask Google for this) there are some other configuration items that are set in java code at:

frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

This is true, for example, for the "Stay awake" option.

Another suggestion : always check for specific device source overlay...sometimes there already are customized resource or java files in the "device" directory.