Page : 2/2

First Page     Prev. Page     Next Page     Last Page


Sunday, 17 Apr 2011 (Only #Android)

I was experiencing routine disconnects (after around 7 minutes) from the Internet on my computer while using Android 2.2's USB tethering on my HTC Wildfire until I turned off the setting in Winamp for Android marked :

"Enable auto-mount
Automatically set device to USB drive mode when connected via USB"

It would appear running programs on Android are able to cause tethering to disconnect.

Tuesday, 22 Feb 2011 (Only #Android)

1. EditText not re-drawing correctly when the on-screen keyboard is activated.

For a simple app such as:

Bug.java:
package com.matthew1471.bugtest;

import android.app.Activity;
import android.os.Bundle;

public class bug extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}


Main.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <EditText android:id="@+id/example" android:layout_width="200.0dip" android:layout_height="wrap_content"/>
    <EditText android:layout_width="200.0dip" android:layout_height="wrap_content"/>
    <EditText android:layout_width="200.0dip" android:layout_height="wrap_content"/>
    <EditText android:layout_width="200.0dip" android:layout_height="wrap_content"/>
    <EditText android:layout_width="200.0dip" android:layout_height="wrap_content"/>
    <EditText android:layout_width="200.0dip" android:layout_height="wrap_content"/>
    <EditText android:layout_width="200.0dip" android:layout_height="wrap_content" />
</LinearLayout>


Manifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.matthew1471.bugtest"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="BugTest">
        <activity android:name=".bug"
                  android:label="BugTest">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

While this shows in the console:

[2011-02-22 01:25:02 - BugTest] WARNING: Application does not specify an API level requirement!
[2011-02-22 01:25:02 - BugTest] Device API version is 8 (Android 2.2.1)
[2011-02-22 01:25:02 - BugTest] Uploading BugTest.apk onto device 'HT<<REMOVED>>'
[2011-02-22 01:25:02 - BugTest] Installing BugTest.apk...

The 5th EditText and onwards when selected and text is entered do not redraw to include the text until the on screen keyboard is closed. For some reason specifying :

    <uses-sdk android:minSdkVersion="4"></uses-sdk>

Just before the <application.. tag fixes it. In my application I specified minSdkVersion 8, though anything 4 (Android 1.6, http://developer.android.com/guide/appendix/api-levels.html) and above fixes the redraw issue. By default the Android system defaults to 1 if not specified (http://developer.android.com/guide/topics/manifest/uses-sdk-element.html). There must have been something released in Android 1.6 that causes the screen to properly redraw when the on-screen keyboard is activated. The full API change list is documented on the developer site (http://developer.android.com/sdk/api_diff/4/changes.html)

2. SetText to an integer causes a misleading force close.

Adding
EditText text = ((EditText)(this.findViewById(R.id.example)));
text.setText(text.getHeight());
to the main part of the above program results in a non-descriptive force close.

02-22 01:48:02.107: WARN/dalvikvm(6248): threadid=1: thread exiting with uncaught exception (group=0x40028a00)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): FATAL EXCEPTION: main
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.matthew1471.bugtest/com.matthew1471.bugtest.bug}: android.content.res.Resources$NotFoundException: String resource ID #0x0
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.os.Looper.loop(Looper.java:143)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread.main(ActivityThread.java:4914)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at java.lang.reflect.Method.invokeNative(Native Method)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at java.lang.reflect.Method.invoke(Method.java:521)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at dalvik.system.NativeStart.main(Native Method)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.content.res.Resources.getText(Resources.java:201)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.widget.TextView.setText(TextView.java:2828)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at com.matthew1471.bugtest.bug.onCreate(bug.java:15)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): ... 11 more
02-22 01:48:02.127: WARN/ActivityManager(102): Force finishing activity com.matthew1471.bugtest/.bug


Which would make you think it cannot find the example EditText in the layout. However changing the second line to :
text.setText("" + text.getHeight());
resolves all the issues. setText is not happy casting an int to a string because usually when an int is specified it corresponds to a program's string in the strings.xml file unless tricked into dealing with strings. There is also seemingly no .tostring() method on an int but there is one for Integer.toString();

The same force close exists with:
int five = 5;
text.setText(five);

Thursday, 23 Dec 2010 (Only #Android)

Froyo for HTC Wildfire Asia has now been released as of a few hours ago.

Taking me from 1.25.707.1 CL227575 release-keys to 2.24.707.1.

"Update: Android 2.2 update 59.56 MB

You can now download the latest software update for new features and improved performance. It won't delete any of your content and we'd recommend using a Wi-Fi connection as this is a large update. If not, standard data connection charges may apply. Any questions? Contact us via www.htc.com"

Your phone should auto update soon, to ask it to check earlier go to your home screen, tap menu, go to "Settings" select "About Phone" then "System software updates" then select "Check now".

Europe users (including the UK) would have already received this update a few days ago, however a lot of phones bought on-line may have the phone's software (firmware) from another region.

Manual download link (I believe this would need to be saved to the SD Card as update.zip) : http://fotadl.htc.com/OTA_Buzz_Froyo_hTC_Asia_WWE_2.24.707.1-1.25.707.1_release_161166pv4uxzm3rnr4swsl.zip

More information: http://www.htc.com/sea/support.aspx

Friday, 17 Dec 2010 (Only #Android)

These are the settings I have found to definitely work for pay as you go:

Name: O2
APN: payandgo.o2.co.uk
Proxy: <Not set>
Port: <Not set>
Username: <Not set>
Password: <Not set>
Server: <Not set>
MMSC: http://mmsc.mms.o2.co.uk:8002
MMS Proxy: 193.113.200.195
MMS port: 8080
MMS protocol: WAP 2.0
MCC: 234
MNC: 10
Authentication type: None
APN type: <Not set>


From what I have observed, the usernames and passwords are completely ignored, however I have included a few below just in-case it turns out they are checked.

More importantly while searching online I found multiple APNs. APNs are what choose your route to the Internet, contract customers have access to faster APNs that give them a faster connection:

APN (Contract): mobile.o2.co.uk
Username: mobileweb or faster or o2web
Password: password

APN (Contact): mobile.o2.co.uk
UserName: web
Password: web

APN (Contract): wap.o2.co.uk
Username: o2wap
Password: password

APN (Pay and go): payandgo.o2.co.uk
Username: payandgo or vertigo
Password: password

I have also seen the authentication type set to PAP but again do not believe this makes a difference.

I have also seen the proxy address: 193.113.200.195 and port 8080 but I do not want to route my traffic through a proxy.

That proxy IP works on ports 8080, 9200 and 9201. According to the WAP specs:
9200 connectionless (temporary)
9201 connection oriented (permanent)

8080 is typically used by devices that support HTTP (which the android does).

For those wondering what the differences in mobile internet connection types are, I found this on a forum:
The different modes are:
G - GPRS (32-40kbps)
E - EDGE (~96kbps)
3G - 3rd Generation (128-320kbps)
H - HSDPA (1.2Mbps-7.2Mbps)


Though there is speculation that O2 limit HSDPA connection speeds.

Thanks to http://forum.o2.co.uk/viewtopic.php?f=2&t=24802

I have also managed to find settings for the exceptionally similar HTC Desire on O2's website, they show you both settings with proxy and without proxy.

Saturday, 13 Nov 2010 (Only #Android)

This explains what an APK file is, how to get it from the Android Market Place and options on how to decompile it.

Introduction To Android Programming

Android relies on the Dalvik Virtual Machine which uses Dalvik bytecode (named after the fishing village of Dalvík in Eyjafjörður, Iceland where some of the creators' ancestors lived according to Wikipedia). Developers write their programs in Java and the Android SDK converts it into Dalvik machine code. The main reasons for using Java as an intermediate language (and why it does not run as Java bytecode on the device) are obvious, developers do not have to learn yet another programming language, Android requires no permission from Sun Microsystems (or Oracle) and a lot of the bloat in the Java VM can be removed. Dalvik is also based on registers rather than a stack like the Java VM.

.dex is the file extension of a Dalvik Executable, this would normally sit inside a .apk file (Android PacKage). APK files typically include other details such as the AndroidManifest.xml which lists how the program appear's on the launcher and what permissions the program requires. If a program tries to call a method which needs a permission not listed in the manifest it will generate a SecurityException which if not correctly handled will lead to a "Force Quit".

Acquiring the APK

I am currently aware of 5 methods of acquiring APK files.

  1. Running an Android emulator on your computer with a ROM that contains the Android Market Place.
  2. Plugging in a Wireless Router to a wireless Windows computer and using Internet Connection Sharing while running Wireshark on your computer capturing traffic on the ethernet port.
  3. ARP Spoof your router using Cain & Abel and then capturing the traffic using Wireshark.
  4. Downloading it on your phone and then using the ASTRO File Manager to save the files to the SD Card, then copying them to the PC.
  5. Writing a program to pretend to be a phone and connecting to the market place directly and an article such as "REVERSING ANDROID MARKET PROTOCOL" may provide further help as well as a Wordpress plugin for displaying application details and its source.

Decompilation to Dalvik bytecode

Now to extract the Dalvik bytecode from the DEX file one can use the decompiler that is built into the SDK, but this ultimately does not produce output that is easy to read, so there is also Baksmali which with this tool you could even convert it back to a Dalvik Executable using Smali.

This produces output like this.

I have seen examples of people doing this to extend the functionality of existing applications such as Howto enable Gmail notifications for all new mail with smali/baksmali.

Another alternative is DeDexer, though this does not have an assembler.

There is also a tool to decode the manifest and other resources contained within the APK such as XMLs and PNGs called APKTool.

ODEX?

From Google Groups:
""Normal" apps have an APK with a manifest, resources, and a
"classes.dex" inside. The classes.dex is optimized by the package
manager on first use, and ends up in /data/dalvik-cache/.

"System" apps have the DEX optimization performed ahead of time. The
resulting ".odex" file is stored next to the APK, the classes.dex is
removed from the APK, and the whole thing works without having to put
more stuff in your /data partition.

The optimized DEX files cannot easily be converted back to unoptimized
DEX, and I'm not sure there's any benefit in doing so. Both kinds of
DEX files can be examined with "dexdump".

More detail can be found in dalvik/docs/dexopt.html in the source
tree, or on the web at:
http://android.git.kernel.org/?p=platform/dalvik.git;a=blob_plain;f=d... "

Both DeDexer and baksmali have limited support for ODEX files.

Decompilation to Java bytecode

Given Java code converts to Dalvik machine code it did not take very long for someone to write a Dalvik machine code to Java bytecode converter. In fact there are 2.

UNDX (lack of download link, developer notified) and Dex2Jar.

The UNDX decompiler appeared to be missing some support for some of the Dalvik op(eration) codes so there is an unofficial fork at GitHub.

Decompilation to Java source code

Once you have Java bytecode you can convert it to Java source by using a Java disassembler such as JD-GUI.

Summary

Finally applications can be decompiled to a variety of formats right up to the original Java source code. Generally the less processing done on the file the more success you will have in trying to decompile it (i.e. it is easier to go to Dalvik bytecode than to go back to source code as you are relying on less processes going wrong).

Sources & Further Reading:
http://aquarium.72pines.com/2010/02/24/using-undx-to-decompile-android-dex-bytecode/
http://jack-mannino.blogspot.com/2010/09/reversing-android-apps-101.html
http://intrepidusgroup.com/insight/2010/10/decompiling-android-apps-undx-dex2jar-and-smali/
http://pallergabor.uw.hu/common/understandingdalvikbytecode.pdf
http://www.slideshare.net/paller/dedexer
http://mylifewithandroid.blogspot.com/2009/02/optimized-dex-files.html
http://groups.google.com/group/android-developers/browse_thread/thread/952ef48bfa1350d8/567d69603d2ef3f4