5,604,292 Members 48,997 Now Online
XDA Developers Android and Mobile Development Forum

[MOD][HOWTO] 4 Way Reboot / Clock / Battery / ART-Dalvik ADB Toggle

Tip us?
(Last edited by EddyOS; 13th December 2013 at 11:01 AM.)
EddyOS's Avatar
Recognized Contributor
Thanks Meter 2640
Posts: 12,469
Join Date: Jan 2010
Location: Liverpool, Merseyside
OK, got the stuff decompiled. Just wanna ask if the % will be the same size as the numbers, e.g. 100%, or whether it will be like 100%

Also, do you have to re-odex on a phone or can you do it on a computer?
Google Nexus 5 (LG-D821) 32GB
ROM: Android 4.4.2 (KOT49H) | Bootloader: HHZ11d | Recovery: Stock | Baseband: M8974A- | Kernel: Stock

If you have a question, great - but DO NOT PM ME WITH IT!!!
EddyOS's Avatar
Recognized Contributor
Thanks Meter 2640
Posts: 12,469
Join Date: Jan 2010
Location: Liverpool, Merseyside
Could someone knock me up the mod exactly like this?

I reckon I can get most of it done but I'm going away this weekend so won't have the time...
Google Nexus 5 (LG-D821) 32GB
ROM: Android 4.4.2 (KOT49H) | Bootloader: HHZ11d | Recovery: Stock | Baseband: M8974A- | Kernel: Stock

If you have a question, great - but DO NOT PM ME WITH IT!!!
chopper the dog
chopper the dog's Avatar
Senior Member
Thanks Meter 732
Posts: 2,034
Join Date: Oct 2008
Location: The blood bath known as Chicago IL.
@twistedumbrella Some other fun edits to add to the guide. No credit needed android is fun.


good day.
$3 charging dock for the galaxy nexus. SEE HERE.
If I annoyed you. Hit the thanks button.
Junior Member
Thanks Meter 0
Posts: 8
Join Date: Aug 2010
Location: Singapore
Thumbs up THANK YOU!!!

Man, you saved my life! I received a prototype phone from our client to test our app. I wanted to find out if our app will work on ART so I changed the VM to ART. The handset then got stuck in a bootloop!!!

Thankfully, I found your post. And thankfully, the steps to switch between VMs through ADB couldn't have been easier!!! I thought I was a gonner.

Thanks again, a million times!

Note to self: Do not do anything else apart from what you've been told to do. Do not experiment on a client's device, especially, if it's a prototype device.

Originally Posted by twistedumbrella View Post
Important tools to have handy that will be used in these guides:
Baksmali / Smali

Example Builds for Stock Odex KOT49H:
Advanced Power Menu
Statusbar Modifications

Advanced Power Menu:

First you will want to copy the entire framework folder from the build you plan to use to a working folder.
After that is done, make sure you have baksmali, smali.jar, and baksmali.jar in the same working folder.

Copy the odex file for the item you want to modify, in this case android.policy.odex into the root of the working folder.
Open up a command prompt or terminal and cd to the working directory then run:
./baksmali -a 19 -x android.policy.odex -d framework -o policy
Now open up the policy folder that was just created and open all the folders until you get to:

In this folder, you will want to open GlobalActions.smali
Search for:
invoke-direct {v1, p0, v2, v3}, Lcom/android/internal/policy/impl/GlobalActions$2;->(Lcom/android/internal/policy/impl/GlobalActions;II)V
Right below that, you will want to make sure you have:

    invoke-virtual {v0, v1}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z

    new-instance v1, Lcom/android/internal/policy/impl/GlobalActions$99;

    const v2, 0x108007c

    const v3, 0x1040361

    invoke-direct {v1, p0, v2, v3}, Lcom/android/internal/policy/impl/GlobalActions$99;->(Lcom/android/internal/policy/impl/GlobalActions;II)V

    invoke-virtual {v0, v1}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z
the next code after this group should now be .line 264

Close and save this file, then open GlobalActions$SinglePressAction.smali

You will see a section that reads:
# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/android/internal/policy/impl/GlobalActions;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x40a
    name = "SinglePressAction"
.end annotation
Below that, you will want to add:

# static fields
.field protected static rebootMode:I

.field protected static final rebootOptions:[Ljava/lang/String;
Now skip past the next section:

# instance fields
.field private final mIcon:Landroid/graphics/drawable/Drawable;

.field private final mIconResId:I

.field private final mMessage:Ljava/lang/CharSequence;

.field private final mMessageResId:I
and add the following section directly under # direct methods:

.method static constructor ()V
    .registers 3

    const/4 v0, 0x4

    new-array v0, v0, [Ljava/lang/String;

    const/4 v1, 0x0

    const-string v2, "Reboot"

    aput-object v2, v0, v1

    const/4 v1, 0x1

    const-string v2, "Restart"

    aput-object v2, v0, v1

    const/4 v1, 0x2

    const-string v2, "Bootloader"

    aput-object v2, v0, v1

    const/4 v1, 0x3

    const-string v2, "Recovery"

    aput-object v2, v0, v1

    sput-object v0, Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;->rebootOptions:[Ljava/lang/String;

.end method
You can now save and close this file. There are three additional files (attached to the post as GlobalActions.zip) that should also be added to the folder you are currently working in.

You are now ready to package the modification back into a file. Make sure you are still in the working directory in your command prompt or terminal and run:
java -Xmx1024m -jar smali.jar policy -o classes.dex
Now it is time to use winrar, 7zip, or whatever archive program you have handy to add the new classes.dex to android.policy.jar
Once this has been done, move the file to the device and follow the section for how to odex a file.

Statusbar Modifications:

For this one, you will be modifying the SystemUI.apk directly with apktool. Copy that to the working directory and run:
./apktool if framework/framework-res.apk
./apktool decode SystemUI.apk
First, open up the SystemUI/smali/com folder and add the contents of percentage.zip (attached to post), so the new percentage folder is in the same directory as android already was.

Now return to the SystemUI folder and open SystemUI/res/layout/status_bar.xml and search for:
<com.android.systemui.BatteryMeterView android:id="@id/battery" android:layout_width="10.5dip" android:layout_height="16.0dip" android:layout_marginBottom="0.33000004dip" android:layout_marginStart="4.0dip" />
This is the battery icon. You can keep it or remove it. The placement from the top to the bottom of this file goes from left to right on screen. If you place a battery percentage before the icon in the file, it will be on the left of the icon on your screen. Same as placing it after would be on the right of the icon on screen.

Depending where you decide you want the percentage, paste this code:
            <com.percentage.BatteryText android:textSize="14.0dip" android:gravity="center" android:layout_width="wrap_content" android:layout_height="fill_parent" />
If you want to change the size of the text, replace 14.0dip with the value you want, such as 16.0dip to match the battery height.

To center the clock, first remove the current com.android.systemui.statusbar.policy.Clock line and search for:
            <com.android.systemui.statusbar.phone.IconMerger android:gravity="center_vertical" android:orientation="horizontal" android:id="@id/notificationIcons" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentStart="true" />
Directly below the </LinearLayout> add:
        <LinearLayout android:gravity="center" android:orientation="horizontal" android:id="@id/clock" android:layout_width="wrap_content" android:layout_height="fill_parent">
            <com.android.systemui.statusbar.policy.Clock android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:gravity="center" android:layout_width="wrap_content" android:layout_height="fill_parent" android:singleLine="true" />
This will create a centered layout in the middle of the statusbar that contains the clock.
Now you can close and save this file and return to the command prompt or terminal window and run:
./apktool build SystemUI
You will find your new SystemUI.apk in the SystemUI/dist directory that was just created.
Don't forget to create an odex file if you came from an odex build, which is the next guide below.

How to Odex a File:

Copy dexopt-wrapper to /system/xbin/ ( One can be found at the Original Tutorial )
chmod 755 /system/xbin/dexopt-wrapper
dexopt-wrapper MODIFIED-FILE.*** TEMPORARY-ODEX-FILE.odex /system/framework/core.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/framework2.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/webviewchromium.jar
(The long string of files at the end is everything after export BOOTCLASSPATH in init.rc / init.environ.rc)

busybox dd if=ORIGINAL-ODEX-FILE.odex of=TEMPORARY-ODEX-FILE.odex bs=1 count=20 skip=52 seek=52 conv=notrunc
Now place the modified file and new odex file in a flashable zip or directly into the target directory replacing the originals.

Toggling ART and Dalvik from ADB:

adb pull /data/property/persist.sys.dalvik.vm.lib
open the file and replace the "libart.so" with "libdvm.so" (no quotes) to switch from ART to Dalvik
open the file and replace the "libdvm.so" with "libart.so" (no quotes) to switch from Dalvik to ART
adb push persist.sys.dalvik.vm.lib /data/property/
adb shell reboot
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes