很多手拿Android手机的人不明白这个软件是干啥的,其实,就是Market Updater,我也不明白为什么中文会叫成这样。在Broncho的时候,反编译过这个MarketUpdater.apk,以后我也不干这坏事了,把成果贴出来吧: https://github.com/lytsing/MarketUpdater
就30多行代码,它干的事情很少,监听 “com.android.vending.UPDATE_MARKET”, intent把下载后的apk url传过来,调用静默安装apk的方法。
那么,谁发 “com.android.vending.UPDATE_MARKET” 这个intent action? 当然是电子市场了:
<receiver
android:name=".InitializeMarketAction$DownloadBroadcastReceiver"
android:permission="android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS"
android:exported="true">
<receiver />
大致的InitializeMarketAction.java代码:
// From Vending.apk
package com.android.vending;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
public class InitializeMarketAction {
public class DownloadBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final Uri contentUri = intent.getData();
int status = DownloadManagerUtil.getStatus(context, contentUri);
if (DownloadManagerUtil.isStatusAuthFailure(status)) {
new Thread() {
public void run() {
VendingApplication.getVendingApplication().invalidateAuthTokenBlocking(
AuthService.ANDROID_SECURE);
}
}.start();
} else if (DownloadManagerUtil.isStatusSuccess(status)) {
setBackgroundRunnable(new Runnable() {
@Override
public void run() {
ServiceLocator.getCacheManager().clear();
Context app = VendingApplication.getVendingApplication();
app.sendBroadcast(new Intent("com.android.vending.UPDATE_MARKET",
contentUri));
}
});
}
}
}
}
那电子市场是如何自我更新的呢? 这个问题问得好。待续。。。
If you enjoyed this post, make sure you subscribe to my RSS feed!