解决donut Gtalk、Market登录不了的问题

拿到一个开发板,研究一下为什么gtak,market都登录不了的问题。折腾了许久,很纠结,试过几个ROM的包都不行。今天再搞不定,明天还计划准备对market进行反编译。

Gtalk界面提示:无法连接到服务器。请稍后重试。
logcat是:
1050 GTalkService W [GTalkConnection.12] doConnect: caught java.lang.IllegalStateException: empty JID resource

market界面出现这样的提示:出现服务器错误,请重试,或者取消并返回上一屏幕。
后台logcat是:

1190 vending D com.android.vending.BaseActivity$BaseAction.run(): ApiException:
1190 vending D com.android.vending.api.FatalCommunicationException: Sent a bad request.
1190 vending D at com.android.vending.api.RequestDispatcher.throwException(RequestDispatcher.java:371)
1190 vending D at com.android.vending.api.RequestDispatcher.performRequestsOverNetwork(RequestDispatcher.java
212)
1190 vending D at com.android.vending.api.RequestDispatcher.performRequests(RequestDispatcher.java:174)
1190 vending D at com.android.vending.api.RequestManager.doRequestsOverNetwork(RequestManager.java:244)
1190 vending D at com.android.vending.api.RequestManager.doRequests(RequestManager.java:230)
1190 vending D at com.android.vending.BaseActivity$BaseAction.run(BaseActivity.java:1476)
1190 vending D at com.android.vending.BaseActivity$BaseAction$BackgroundThread$1.run(BaseActivity.java:1556)
1190 vending D at java.lang.Thread.run(Thread.java:1060)
1190 vending I om.android.vending.BaseActivity$BaseAction.displayErrorUi(): General error in com.android.vend
ng.AssetBrowserActivity$NetworkDataLoadAction
1190 vending I om.android.vending.api.FatalCommunicationException: Sent a bad request.
1190 vending I at com.android.vending.api.RequestDispatcher.throwException(RequestDispatcher.java:371)
1190 vending I at com.android.vending.api.RequestDispatcher.performRequestsOverNetwork(RequestDispatcher.java
212)
1190 vending I at com.android.vending.api.RequestDispatcher.performRequests(RequestDispatcher.java:174)
1190 vending I at com.android.vending.api.RequestManager.doRequestsOverNetwork(RequestManager.java:244)
1190 vending I at com.android.vending.api.RequestManager.doRequests(RequestManager.java:230)
1190 vending I at com.android.vending.BaseActivity$BaseAction.run(BaseActivity.java:1476)
1190 vending I at com.android.vending.BaseActivity$BaseAction$BackgroundThread$1.run(BaseActivity.java:1556)
1190 vending I at java.lang.Thread.run(Thread.java:1060)
1024 GTalkSerice E createAccountFromSettings caughtjava.lang.NumberFormatException: unable to parse 'null' as integer, use default port 5228

首先tcpdump获取数据包,然后用wireshark分析,发现

POST /market/api/ApiRequest HTTP/1.1\r\n
version=2&request=ClIxxxxxxxxxxxxxxxxxxxxxxxxAggBFA (中间有个人信息,用xxx替代)

总是返回 404错误,肯定是参数问题。request的参数,是经过base64加密过的,一直琢磨不出到底是哪个参数错了。

到了下午,痛定思痛,整理一下思路:

1. market与gtalk都登录不了,而gmail可以正常使用,从wireshark分析的数据包来看,DNS解析正常,没有被盾。
2. market与gtalk都登录不了,两者共有的东西是什么?是gtalkservice。
3. 同样的包,在模拟上,gtalk 可以登录使用,market却不行。

好,再仔细分析log:

[GTalkConnection.9] doConnect: caught java.lang.IllegalStateException: empty JID resource

开始也注意到这条log,但上面说的第三点因素,加上 Google这条错误信息,没有搜索记录,别人没遇到这问题,所以就没在意。

GTalkConnection是不是在gtalkservice里面? 用apktoo 反编译 gtalkservice.apk,搜索”empty JID resource” 字符串,还真在这个文件GTalkConnection.smali,代码大概是:

String resource = Settings.getJidResource();

if (TextUtils.isEmpty(resource )) {
    throw new IllegalStateException("empty JID resource");
}

搜索一下getJidResource, 文档写:

public static String getJidResource()

Returns the GTalk JID resource associated with this device.

Returns:
String the JID resource of the device. It uses the device IMEI in the computation of the JID resource. If IMEI is not ready (i.e. telephony module not ready), we’ll return an empty string.

哈哈哈,太明显了,IMEI!!! 在设置里,查看手机的IMEI,显示是未知,90%应该是这个问题了,先做个假的测试一下。

frameworks/base/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java

 897     public String getDeviceId() {
 898         return mImei;
 899     }
 

用模拟器上的值,改为:

 897     public String getDeviceId() {
 898         /*return mImei;*/
 899         return "000000000000000";
 900     }
 

到 frameworks/base目录下,mm -B , 重新生成frameworks.jar, push 到手机,重启,ok,market, gtalk可正常使用 :)

总结一下,给我一杯凉水,我需要冷静,log很重要,搞php我每次都先看apache error log, 搞C/C++, gdb无敌,一到android,没能潜移默化,可能是最初对Java的抵触,反感。现在发现用Java写程式也是蛮是享受的事。

If you enjoyed this post, make sure you subscribe to my RSS feed!

5 thoughts on “解决donut Gtalk、Market登录不了的问题

  1. Pingback: Android Emulator 大戰 « 阿喵就像家

  2. fitonrenza

    看到你的文章,很专业哦.不知可不可以把你的frameworks.jar发送给我,谢谢
    gtalk实在是很讨厌

    Reply
    1. deli Post author

      hi, 编译一下代码就行了。frameworks.jar 这个包我们是有修改过的,在你那不一定能跑。

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *