Creating an Android Boot Animation on Mac OS

Been a while since I updated the blog, so here’s a quick one to get back into the swing of things.

I have an HTC Explorer that I rooted a while back, mainly so that I could get rid of some of the OEM installed crap. But once you have your device rooted, chances are you’ll want to do more. So I played around with changing the boot animation on my phone.

I followed the instructions I found on a few different sites, but couldn’t get it to work. The issue, as I discovered, is that the Archive Utility that comes with Mac OS doesn’t create zip files that work with the Android OS. So here are my instructions for creating a replacement boot animation for your Android device.

Short Guide

  1. Create images and desc.txt file
  2. Create bootanimation.zip using zip -r -X -0 bootanimation desc.txt image_folder/
  3. Mount /system as read-write: mount -rw -o remount /dev/block/mtdblock3 /system
  4. Make boot animation location writable by the shell: chmod 777 /system/etc/customer
  5. Copy the bootanimation.zip to device: adb push bootanimation.zip /system/etc/customer
  6. Test that it works: adb shell bootanimation

PRE_REQUISITES:

Root Access
You’ll need to have root access to your device. Instructions will vary according to your device. Here are the instructions for rooting the HTC Explorer.

Android Device Bridge (adb)
You’ll need this to root your device, but if you used another machine to get root, then download adb-fastboot-install

Imaging Editing Software
To create your images. Boot animations are a collection of still images, shown by the device in a slideshow. Must be the same resolution as your device.

Description of bootanimation.zip

Your boot animation is stored in a zipped file that contains a folder with the sequentially numbered images that make up your animation and a desc.txt file that contains the parameters that set up your slideshow.

Location of bootanimation.zip

Depending on your device, bootanimation.zip may be located in several different locations. For the HTC Explorer, the packaged animation is located in /system/customize/resource/hTC_bootanimation.zip

Creating your custom animation

Follow these instructions on creating your custom boot animation file.

Creating the bootanimation.zip file

Once you have your images and desc.txt file completed, you need to create a zip file.

DO NOT USE THE IN-BUILT ARCHIVE UTILITY

Mac OS includes data with compressed files that will cause problems when Android tries to use your boot animation. Instead, open Terminal and use the zipcommand:

zip -r -X -0 bootanimation desc.txt image_folder/

Replace image_folder/ with the name of the directory containing your images.

Copying bootanimation.zip to your device

At this point, you can connect your device to your Mac using the supplied USB cable. Before doing so, make sure that USB Debugging is enabled. (Settings -> Applications -> Development -> USB Debugging). When you connecting your device, you may be prompted for a mode. Select “Charge Only”.

Before you can copy any data to your device, you need to mount the /system directory as read-write. In Terminal type the following commands:

adb shell
su
mount

The mount command should return a list of all the mount points on your device. Look down the list for the /system mount point and make a note of which device is mounted at that point On my phone, it’s /dev/block/mtdblock3, but yours may be different. Once you have the name of the device, run the following command:

mount -rw -o remount /dev/block/mtdblock3 /system

(Don’t forget to substitute the correct device for /dev/block/mtdblock3.)

Aside: I mentioned above that the packaged animation for the HTC Explorer is located in /system/customize/resource/hTC_bootanimation.zip. Normally you would make a backup of this file and replace it with your custom boot animation. However, when troubleshooting problems with my own boot animation I found an entry in the Android logs that suggested that Android would first look in /system/etc/customer for a boot animation. Placing your custom boot animation here has a couple of benefits:

  • You don’t need to make a backup of the OEM boot animation.
  • You won’t lose the original boot animation if you ever decide to go back
  • You won’t mistakenly over-write the original boot animation.

The final step before copying your custom animation to your device is to make sure that the shell can write to the location where your boot animation will reside. Although the /system directory has been mounted as read-write, the permissions on the directory only allow root user to access the data. The method used to push data to your phone uses a different user, so we need to make sure that we have write access. Once again, using the adb shell, we run the following command:

chmod 777 /system/etc/customer

NOTE: If you’re using the same directory as I am in the sample above, you may have to create the customer first. Use mkdir /system/etc/customer to do so.

Exit out of the adb shell by typing Ctrl-D twice. (Once to log out as root, and again to log out completely.) You should now be back at the standard Terminal prompt. At the Terminal prompt, issue the following command:

adb push bootanimation.zip /system/etc/customer

Testing that your boot animation is working

You could always restart your phone to check that the custom animation is working, but there is an easier way. From the Terminal prompt, use:

adb shell bootanimation

This will start the boot animation on your phone, to exit hit Ctrl-C.

Jailbreak 2nd Gen iPod Touch with GreenPois0n

Spent a couple of hours today trying to jailbreak my iPod. After numerous attempts, I was on the point of giving up when I found this forum post with a solution: Run greenpois0n from the command line, rather than from the GUI.

While the forum post refers to RC5_2, I can confirm that it works with RC6 also. Here’s my method.

  1. Make sure that your iPod is connected to your computer.
  2. Shut down iTunes if it’s open.
  3. Turn off your iPod.
  4. Hold the power button and home button for 10 seconds.
  5. Release the power button, keep holding the home button for a further 10 seconds.
  6. Open Terminal.
  7. Change directory to the location of the greenpois0n app.
  8. Type open ./greenpois0n.app/Contents/MacOS/greenpois0n
  9. A new Terminal window will open and greenpois0n should now be able to jailbreak your iPod.
  10. Wait for your iPod to restart.
  11. Find the green Loader icon on your iPod and use it to install Cydia.

And that’s it – you’re good to go!

WordPress and the”filesize() [function.filesize]: stat failed”Error

I’ve been working on a website that includes a download button. When clicked the button would prompt to open or save the file. The prompt appeared on cue and the file downloaded, but for some reason the file was empty.

Checking the php_error.log, showed that this error was being generated:

PHP Warning: filesize() [function.filesize]: stat failed for http://localhost:8888/ringstone/wp-content/uploads/docs/brochure.pdf in /Applications/MAMP/htdocs/ringstone/wp-content/themes/ringstone/frontpage.php on line 26

Normally if the filesize function fails it’s because the directory where the file is stored is not writeable or the file is larger than 2GB.

In this case, the directory was writeable and the file was a lot less than 2GB in size. So I was stumped.

Going over my code, the only thing that I could see that might be causing the problem was the link to the file.

I was using the following code to get the WordPress uploads directory:

$uploads = wp_upload_dir();$url = $uploads['baseurl'];$filename = $url . ‘/docs/brochure.pdf’;

This generated the url for the document as: http://localhost:8888/ringstone/wp-content/uploads/docs/brochure.pdf

According to the PHP manual for filesize, as of PHP 5.0.0 the filesize function supports using some URL wrappers, including HTTP. The version of MAMP that I’m using includes PHP 5.3.2, so this shouldn’t have been a problem. It turns out that I was wrong.

I updated my code to:

$uploads = wp_upload_dir();$path = $uploads['basedir'];$filename = $path . ‘/docs/brochure.pdf’;

And it worked.

The lesson is that if you’re seeing filestat error in your PHP error log, then go through the following checklist:

  1. Pass filestat the directory path to the file, not the URL. (Even though the manual says that it should work.)
  2. Check that the directory is writeable.
  3. Check that the file is smaller than 2GB in size.

Creating A Linux USB Boot Drive on Mac OS X

I recently needed to boot a laptop from Linux, but didn’t have any of my Linux boot disks with me. Luckily I had my USB flash drive, so I decided to install a mini-version of Linux. A quick Google searched led me to Recovery is Possible, or RIPLinuX.

Here’s how to install the .iso onto the flash drive:

Open Terminal under Applications → Utilities.

We’ll be using the diskutil command to write the .iso contents to the flash drive. So the first thing to do is determine the block device associated with our flash drive.

Before inserting the drive typediskutil listand hit enter. Insert your drive and run the diskutil list command again.

You should get something like this:

Results of the diskutil list command

As you can see, the flash drive is connected via /disk/dev1, though this may be different on your system. Before you can start writing the data to the flash drive, you need to unmount the drive.

diskutil unmountDisk /dev/disk1

Unmounting the flash drive using diskutil

Now, you’re ready to start writing the data to the drive.

sudo dd if=/path/to/linux.iso of=/dev/disk1 bs=1m

Data has been successfully written to the drive

Once the data has been written to the drive, all that remains is to eject it.diskutil eject /dev/disk1

Eject the flash drive

And you’re done! Remember that in order to boot from the USB drive, the computer that you’re using must support booting from USB devices and that you need to change the boot order in the BIOS.

PHP Code Snippet

Because of the re-design, there’s a lot of broken links – mainly because the blog used to live under the /whatithink/ folder on the server and now resides in the root folder. So all those Google links now point to a part of the site that no longer exists.

So anyone coming here from Google is going to get a 404 error. Not good.

While I get my head around using .htaccess to automatically rewrite the broken URLs, I’ve created a 404 page that will, (hopefully), correct the URL.

Here’s the PHP:

$requested = $_SERVER['REQUEST_URI'];$parts = explode('/', $requested);foreach ($parts as $part) {switch($part) {case ('whatithink'):break;case (''):break;default:$out .= '/' . $part;}}$out = 'http://' . $_SERVER['HTTP_HOST'] . $out;

Because all my broken URLs have an extra “/whatithink/” section, I can just break the requested URL into parts, and rebuild it without that section.

MyBook World Edition – Time Machine – OSStatus Error 2

If Time Machine is unable to connect to your backup disk with an error message containing “OSStatus Error 2″, then check the permissions on your NAS.

SSH as root into your MBWE and check the permissions for /var and /var/lib.

Use chmod 755 on /var and /var/lib to apply the correct permissions.

Use the Time Machine System Preferences to set your backup disk to your MBWE.

GeekTool

I’ve been playing around with GeekTool for a couple of days and I’ve finally gotten everything I want on my desktop.

Here’s what my desktop looks like at the moment:

My GeekTool Desktop

My GeekTool Desktop

For reference, here’s my list of GeekTool Scripts:

  • Computer Name: hostname -s
  • Login Name: whoami
  • Day: date “+%A”
  • Month: date “+%b”
  • Day (numerical): date “+%e”
  • Time: date +”%I:%M”
  • AM/PM: date +”%p”
  • Mac OS X Version: sw_vers | awk -F’:t’ ‘{print $2}’ | paste -d ‘ ‘ – - – ;
  • Disk Usage: df -H | grep disk0s2 | awk ‘{print “Disk:”, $3, “/”, $2, “-”, $4, “available”}’
  • Uptime: uptime | awk ‘{print “Up: ” $3 ” days”}’
  • Airport Network Name: airport -I | grep -e “bSSID:” | awk ‘{print $2}’
  • Airport Channel: airport -I | grep -e “channel:” | awk ‘{print “Channel: ” $2}’
  • Airport Max Rate: airport -I | grep -e “maxRate:” | awk ‘{print “Max Rate: ” $2}’
  • Airport Link Authorisation: airport -I | grep -e “link auth:” | awk ‘{print “Auth: ” $3}’
  • External IP: echo `curl -s http://checkip.dyndns.org/ | sed ‘s/[a-zA-Z<>/ :]//g’`
  • Running Processes: ps -c -U pmac -o command,%cpu,%mem -r
  • Airport IP: ipconfig getifaddr en1
  • Calendar: cal
  • Network Location: scselect 2>&1 | grep ‘^ *’ | sed -e ‘s:^[^(]*(([^)]*))$:1:g’

Most of these commands were culled from various websites, while I came up with the rest myself.

“custom_domain is null”error message in Firefox

Problem: When opening a “localhost” address using Firefox, a JavaScript error message is displayed with the error message “current_domain is null”.

Description: Using Firefox version 3.0.11. Error message only appears when connecting to a site hosted on the local machine. Disabling all add-ons resolves the problem. Re-enabled add-ons one by one. Re-enabling LongURL Expander causes the problem to re-appear. Error message is known issue with version 2.0.0 of the add-on.

Solution: As per the comments on the the add-on page, edit the longurlmobileexpander.js file to make the requirement for the second part of the domain name optional.

  • On Mac OS X, open home folder and browse to Library/Application Support/Firefox/Profiles/[profile].default/extension/{a7101e54-830c-4d33-a3ed-bedc17ec44da}/content
  • Open longurlmobileexpander.js in TextEdit.
  • Edit line 78 to read:

var current_domain = document.location.href.match(/^https?://(?:www.)?([^.]+(.[^/]+)?)/i);

  • Save changes.

Thanks to Mathias Jansen for the solution.

Disabling Ethernet Prevents Mac OS X From Waking

Problem: When MacBook lid is closed, fan continues to spin and MacBook becomes very hot.

Description: When in use the MacBook fan behaves as expected. On closing the lid to put the MacBook sleep, the fan continues to spin and the base of the machine becomes very hot.

Opening the lid displays a black screen. No mouse or login screen displayed. Fan continues to spin at what seems to be maximum RPM. Closing the lid again does not stop the fan from spinning.

Only available option is to hold the power button to shut down the system.

On pressing the power button to restart the system, the MacBook starts, displays grey start up screen for a second or two and then restarts automatically. MacBook then starts normally.

Once the user logins, the system works as normal again. Putting the system to sleep, causes the problem to reoccur.

Solution: The user deactivated the Ethernet interface within System Preferences -> Network. Reactivating the Ethernet interface and restarting the machine resolved the problem.

(Who’d have thought that disabling the Ethernet interface would prevent the system from sleeping? Certainly not me when I decided to do so.)