Long standby time for Cyanogenmod 7.1 on ZTE Blade phones

This is a testimonial of the Cyanogenmod 7.1 Android spinoff operating system on the ZTE Blade phone.

I've recently installed Cyanogenmod 7.1 to my ZTE Blade. Prevously I had Cyanogenmod 7.0.3 on it, and the battery life was terrible. It didn't last more than 48 hours in standby (3G, mobile data, wifi, GPS, background synchronization switched off, only receiving a few text messages). But after installing 7.1, the battery lasted for 12 days plus 23 hours in standby mode. Awesome! Finally I have a small and cheap Android phone with long battery life.

The phone user interface also feels much snappier now, and 3D games (e.g. Falldown 3D) which lagged and were unplayable with 7.0.3 are fast and playable now.

Unfortunately I wasn't able to upgrade 7.0.3 to 7.1, but I had to wipe the phone (keeping only the SD card contents) before installing 7.1.


Getting started with IntelliJ to write Android applications on Linux

This blog post gives instructions to get started with Android application development with IntelliJ on Linux.
  1. Install the Java runtime environment (JRE) and the Java compiler (in the JDK). Command to to it on Ubuntu Lucid: sudo apt-get install openjdk-6-jdk . Please note that the JRE without the JDK is not enough, IntelliJ needs the JDK.
  2. You will need about 1.5 GB of free disk space.
  3. Download IntelliJ (either the Ultimate edition or the Community edition; please note that you have to pay for the Ultimate edition after the evaluation period expires) from from. http://www.jetbrains.com/idea/download/ . I've downloaded the file from http://download.jetbrains.com/idea/ideaIU-10.5.2.tar.gz , it was about 160 MB.
  4. Download the Android SDK tools from http://developer.android.com/sdk/ . I've downloaded the file from http://dl.google.com/android/android-sdk_r13-linux_x86.tgz . It was about 160 MB.
  5. If you ever want to connect a real phone via USB, then follow the instructions http://ptspts.blogspot.com/2011/10/how-to-fix-adb-no-permissions-error-on.html do create and install the android.rules udev rule. Please also restart the udev service.
  6. Extract the downloaded archive android-sdk_r13-linux_x86.tgz .
  7. Run the android-sdk-linux_x86/tools/android tool.
  8. On the Available packages tab, find and install the following packages:
    • Android SDK Tools
    • Android SDK Platform-tools
    • Documentation for Android SDK (the latest one)
    • SDK Platform Android 2.2, API 8 (or whichever Android version you are developing for).
    • Samples for SDK API 8 (or whichever Android version you are developing for).
    • Google APIs by Google Inc., Android API 8 (or whichever Android version you are developing for).
    • Android Compatibility package
  9. In the Virtual devices tab, create a virtual device. Use these settings (make sure to enabling snapshots and disabling audio playback and recording):
  10. Start the virtual device, play with it (it's an emulated Android phone), watch how it eats your CPU capacity, and stop it by closing the emulator window.
  11. Please note that the emulator is very slow. It will happily eat 100% even if the virtual device is idle. When you disable sound playback and sound recording, it still eats about 800 MHz (tested on Intel(R) Core(TM)2 Duo CPU P9500 @ 2.53GHz).
  12. A possible bug in the Android emulator: The Launch from snapshot functionality didn't work for me in the emulator, even though the snapshot was present.
  13. In the file ~/Downloads/idea-IU-107.587/bin/idea.sh (the actual filename may depend on where you have downloaded and extracted IntelliJ to), change the line containing OPEN_JDK=$? to OPEN_JDK=1 . This will disable the startup warning.
  14. Start IntelliJ. Enter license data (or choose evaluation), accept the license agreement, just click OK in the Select VCS Integration dialog (or select a superset of the version control systems you are planning to use), unselect all Web/JavaEE plugins (they are not needed for Android development), unselect all the HTML/JavaScript plugins, in the Other plugins dialog select at least these: Android, GenerateToString, Inspection Gadgets, Intention Power Pack, JUnit, Remote Hosts Access, SpellChecker, Structural Search, Task Management, Type Migration; make sure Android is checked; finish the installation.
  15. File / New project. Create project from scratch. Next. Name: afirst. Select type: Android Module. Next. Create source... src. Next. Project JDK / Configure. /usr/lib/jvm/java-6-openjdk . OK. Next. Android SDK: ... . In the top left corner of the window, click +, and select Android SDK. Specify /home/USERNAME/Downloads/android-sdk-linux_x86 (where you have downloaded and extracted the Android SDK to). Select internal JDK: 1.6. OK. Select build target: Android 2.2 (or the Android version of your choice). OK. OK. Now you are back in the Create project wizard, with the Android SDK: selection containing Android 2.2 Platform. Finish.
  16. Wait a few minutes until the project tree afirst appears. Open afirst. Open src. Open com.example. Double click on MyActivity. The MyActivity.java source file appears.
  17. Make sure the virtual device barvirt is running in the Android emulator. Play it safe and restart the emulator.
  18. Stop adb: sudo ~/Downloads/android-sdk-linux_x86/platform-tools/adb kill-server
  19. Restart adb: sudo ~/Downloads/android-sdk-linux_x86/platform-tools/adb devices
  20. In IntelliJ Run / Edit configurations, set up devices and virtual devices like this:
  21. In IntelliJ: Run / Run. Wait a minute. The app should start on the emulator.
  22. Connect your phone with USB debugging enabled (in Settings / Applications / Development). In IntelliJ: Run / Run. Wait a minute. The app should start on the phone.

Typical IntelliJ message for starting the app on the phone:

Waiting for device.
Target device: 1234567890ABCDEF
Uploading file
 local path: /home/pts/IdeaProjects/afirst/out/production/afirst/afirst.apk
 remote path: /data/local/tmp/com.example
Installing com.example
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example"
pkg: /data/local/tmp/com.example

Launching application: com.example/com.example.MyActivity.
DEVICE SHELL COMMAND: am start -n "com.example/com.example.MyActivity"
Starting: Intent { cmp=com.example/.MyActivity }

Typical IntelliJ message for starting the app on the emulator:

Waiting for device.
Target device: emulator-5554 (barvirt)
Uploading file
 local path: /home/pts/IdeaProjects/afirst/out/production/afirst/afirst.apk
 remote path: /data/local/tmp/com.example
Installing com.example
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example"
pkg: /data/local/tmp/com.example

Launching application: com.example/com.example.MyActivity.
DEVICE SHELL COMMAND: am start -n "com.example/com.example.MyActivity"
Starting: Intent { cmp=com.example/.MyActivity }


Named return value optimization in gcc

This blog post demonstrates that GCC 4.1 does Named return value optimization, i.e. it omits creating a temporary object in a function returning an object if all return statements in the function return the same local variable. Example code:

#include <stdio.h>

class C {
  C() { printf("+\n"); }
  ~C() { printf("-\n"); }
  C(const C&) { printf(":\n"); }
  C& operator=(const C&) { printf("=\n"); }

C F(int i) {
  C x;
  if (i > 1) {
    return x;
  } else {
    return x;

C G(int i) {
  if (i > 1) {
    C x;
    return x;
  } else {
    C y;
    return y;

int main(int argc, char**) {
  return 0;

The output, as expected, even without -O... compiler optimization flags:

$ g++ test_return_object.cc && ./a.out


How to initiate and receive voice and video calls from within Gmail?

This blog post explains how to set up Gmail so it will be able to initiate and receive voice and video calls.

  1. Download and install the Google Talk Plugin from here.
  2. Restart your browser, preferably Google Chrome.
  3. Log into gmail in your browser.
  4. In the top right corner click on the cogwheel icon, and then select Mail settings.
  5. In the Chat tab, set up the settings of Voice and video chat.
  6. Click on Verify your settings and make sure it works properly.
  7. Save the settings (Save Changes).
  8. Select a friend in the chat list, open a chat window. In the chat window there will be a phone or camera icon, with which you can start the voice or video chat.


How to fix the adb no permissions error on Ubuntu Lucid

This blog post explains how to fix the no permissions error the Android Debugger displays when running the adb devices command Linux. The solutions presented here have been tested and found working on Ubuntu Lucid, but they should also work on other Ubuntu and Linux versions as well.

This official help center page has many working and non-working answers to the problem, and many comments. The root cause of the problem is that the current user doesn't have sufficient permissions to access the USB device file created when the phone was connected in USB debug mode.

Killing all running adb server instances with sudo killall adb, disconnecting the phone, reconnecting the phone, and then running sudo adb devices instead (so adb gets run as root) fixes the problem.

Alternatively, it is possible to implement a long-term fix which doesn't require sudo, thus it works with e.g. IntelliJ IDE integration:

  • Create a file named /tmp/android.rules with the following contents (hex vendor numbers were taken from the vendor list page):
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0e79", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0502", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="413c", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="091e", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="24e3", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="2116", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0482", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="17ef", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0409", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="2080", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0955", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="2257", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="10a9", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="1d4d", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0471", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="04da", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="05c6", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="1f53", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="04dd", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0930", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="19d2", MODE="0666"
  • Run the following commands (without the leading $):
    $ sudo cp /tmp/android.rules /etc/udev/rules.d/51-android.rules
    $ sudo chmod 644   /etc/udev/rules.d/51-android.rules
    $ sudo chown root. /etc/udev/rules.d/51-android.rules
    $ sudo service udev restart
    $ sudo killall adb
  • Disconnect the USB cable between the phone and the computer.
  • Reconnect the phone.
  • Run adb devices to confirm that now it has permission to access the phone.

Please note that it's possible to use , USER="$LOGINNAME" instead of , MODE="0666" in the .rules file, substituting $LOGINNAME for your login name, i.e. what id -nu prints.