号簿助手 v4.6.31版本的 MD5 值为:9d7ff98a6bb5cc178eac2df4d1b2f0e0
以下内容为反编译后的 YXApiImplementation.java 源代码,内容仅作参考
package im.yixin.sdk.api;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;
import im.yixin.sdk.api.SendMessageToYX;
import im.yixin.sdk.channel.YXMessageActivityChannel;
import im.yixin.sdk.channel.YXMessageChannel;
import im.yixin.sdk.channel.YXMessageProtocol;
import im.yixin.sdk.channel.YXMessageUtil;
import im.yixin.sdk.util.SDKLogger;
import im.yixin.sdk.util.YixinConstants;
final class YXApiImplementation implements IYXAPI {
private String appId;
private Context applicationContext;
public YXApiImplementation(Context context, String str) {
this.applicationContext = context.getApplicationContext();
this.appId = str;
}
private PackageInfo getYixinAppPackageInfo() {
try {
return this.applicationContext.getPackageManager().getPackageInfo(YixinConstants.YIXIN_APP_PACKAGE_NAME, 64);
} catch (PackageManager.NameNotFoundException e) {
return null;
}
}
public void showYixinDownloadPage() {
SDKLogger.i(YXApiImplementation.class, "showYixinDownloadPage:http://yixin.im/");
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setData(Uri.parse("http://yixin.im/"));
intent.addFlags(268435456);
this.applicationContext.startActivity(intent);
}
private boolean validateYixinAppSignature() {
SDKLogger.i(YXApiImplementation.class, "validateYixinSignature");
try {
PackageInfo yixinAppPackageInfo = getYixinAppPackageInfo();
if (yixinAppPackageInfo == null) {
return false;
}
return validateYixinAppSignature(yixinAppPackageInfo.signatures);
} catch (Exception e) {
return false;
}
}
private boolean validateYixinAppSignature(Signature[] signatureArr) {
if (signatureArr == null) {
return false;
}
for (Signature signature : signatureArr) {
String charsString = signature.toCharsString();
if (charsString.equals(YixinConstants.YIXIN_SIGNATURE_STRING) || charsString.equals(YixinConstants.YIXIN_TEST_SIGNATURE_STRING)) {
return true;
}
}
return false;
}
private boolean validateYixinAppVersion(PackageInfo packageInfo) {
SDKLogger.e(YXApiImplementation.class, "(packageInfo != null)=" + (packageInfo != null) + ",packageInfo.versionCode=" + packageInfo.versionCode);
return packageInfo != null && packageInfo.versionCode > 146;
}
@Override
public String getAppId() {
return this.appId;
}
@Override
public boolean handleIntent(Intent intent, IYXAPICallbackEventHandler iYXAPICallbackEventHandler) {
YXMessageProtocol parseProtocol = YXMessageProtocol.parseProtocol(intent);
if (parseProtocol == null || !parseProtocol.isValid()) {
SDKLogger.e(YXApiImplementation.class, "handleIntent failed because !protocol.isValid()");
return false;
}
if ("onReq".equalsIgnoreCase(parseProtocol.getCommand())) {
switch (intent.getIntExtra(YixinConstants.INTENT_EXTRA_KEY_REQ_CMD_TYPE, 0)) {
case 1:
iYXAPICallbackEventHandler.onReq(new SendMessageToYX.Req(intent.getExtras()));
return true;
default:
return true;
}
}
if (!"onResp".equalsIgnoreCase(parseProtocol.getCommand())) {
SDKLogger.e(YXApiImplementation.class, "handleIntent error command passed from Yixin " + parseProtocol.getCommand());
return true;
}
switch (intent.getIntExtra(YixinConstants.INTENT_EXTRA_KEY_REQ_CMD_TYPE, 0)) {
case 1:
iYXAPICallbackEventHandler.onResp(new SendMessageToYX.Resp(intent.getExtras()));
return true;
default:
return true;
}
}
@Override
public boolean isYXAppInstalled() {
SDKLogger.i(YXApiImplementation.class, "isYXAppInstalled");
return validateYixinAppSignature();
}
@Override
public boolean registerApp() {
SDKLogger.i(YXApiImplementation.class, "registerApp");
if (!validateYixinAppSignature() || YXMessageUtil.isBlank(this.appId)) {
SDKLogger.i(YXApiImplementation.class, "registerApp: validateYixinSignature - false or isBlank(this.appId)!");
return false;
}
YXMessageChannel.sendData2Yixin(this.applicationContext, YixinConstants.YIXIN_APP_PACKAGE_NAME, YixinConstants.INTENT_ACTION_REGISTER, "yixin://registerapp?appid=" + this.appId);
return true;
}
public void sendMsg(BaseReq baseReq) {
PackageInfo yixinAppPackageInfo = getYixinAppPackageInfo();
if (yixinAppPackageInfo == null || !validateYixinAppSignature(yixinAppPackageInfo.signatures)) {
showYixinDownloadPage();
return;
}
if (!validateYixinAppVersion(yixinAppPackageInfo)) {
new Handler().post(new Runnable() {
@Override
public void run() {
Toast.makeText(YXApiImplementation.this.applicationContext, "您的易信版本过低,请先升级!", 0).show();
YXApiImplementation.this.showYixinDownloadPage();
}
});
return;
}
if (baseReq == null) {
SDKLogger.i(YXApiImplementation.class, "sendMsg error param paramBaseReq is null");
return;
}
SDKLogger.i(YXApiImplementation.class, "sendMsg: transaction=" + baseReq.transaction);
Bundle bundle = new Bundle();
if (!baseReq.checkArgs()) {
SDKLogger.i(YXApiImplementation.class, "sendMsg: transaction=" + baseReq.transaction + ",checkArgs fail");
} else {
baseReq.toBundle(bundle);
YXMessageChannel.sendData2Yixin(this.applicationContext, YixinConstants.YIXIN_APP_PACKAGE_NAME, YixinConstants.INTENT_ACTION_MESSAGE, "yixin://sendmsg?appid=" + this.appId, bundle);
}
}
@Override
public boolean sendRequest(BaseReq baseReq) {
PackageInfo yixinAppPackageInfo = getYixinAppPackageInfo();
if (yixinAppPackageInfo == null || !validateYixinAppSignature(yixinAppPackageInfo.signatures)) {
showYixinDownloadPage();
return false;
}
if (!validateYixinAppVersion(yixinAppPackageInfo)) {
new Handler().post(new Runnable() {
@Override
public void run() {
Toast.makeText(YXApiImplementation.this.applicationContext.getApplicationContext(), "您的易信版本过低,请先升级!", 0).show();
YXApiImplementation.this.showYixinDownloadPage();
}
});
return false;
}
if (baseReq == null) {
SDKLogger.i(YXApiImplementation.class, "sendReq error parameter paramBaseReq is null.");
return false;
}
SDKLogger.i(YXApiImplementation.class, "sendReq: transaction=" + baseReq.transaction);
if (!baseReq.checkArgs()) {
SDKLogger.i(YXApiImplementation.class, "sendReq: transaction=" + baseReq.transaction + ", checkArgs fail.");
return false;
}
Bundle bundle = new Bundle();
baseReq.toBundle(bundle);
return YXMessageActivityChannel.sendData2Yixin(this.applicationContext, YixinConstants.YIXIN_APP_PACKAGE_NAME, YixinConstants.INTENT_ACTION_SHARE_CONTENT, "yixin://sendreq?appid=" + this.appId, bundle);
}
@Override
public void unRegisterApp() {
SDKLogger.i(YXApiImplementation.class, "unregisterApp");
if (!validateYixinAppSignature() || YXMessageUtil.isBlank(this.appId)) {
SDKLogger.i(YXApiImplementation.class, "unregisterApp: validateYixinSignature - false or isBlank(this.appId)!");
} else {
YXMessageChannel.sendData2Yixin(this.applicationContext, YixinConstants.YIXIN_APP_PACKAGE_NAME, YixinConstants.INTENT_ACTION_UNREGISTER, "yixin://unregisterapp?appid=" + this.appId);
}
}
}