Aqara Home v2.4.1版本的 MD5 值为:529779ac2bc0131db52a1fc3098d2b35
以下内容为反编译后的 TestAddGateway.java 源代码,内容仅作参考
package com.lumiunited.aqara.architecture.ui.testpage;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkRequest;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.alibaba.fastjson.JSON;
import com.lumiunited.aqara.application.base.BaseActivity;
import com.lumiunited.aqara.architecture.ui.testpage.TestAddGateway;
import com.lumiunited.aqara.device.adddevicepage.bean.BindGatewayResult;
import com.lumiunited.aqara.device.adddevicepage.bean.BindUserWithHomeKit;
import com.lumiunited.aqara.device.adddevicepage.bean.HomeKitDeviceInfo;
import com.lumiunited.aqara.device.adddevicepage.bean.HomeKitGatewayResult;
import com.lumiunited.aqara.login.bean.UserInfo;
import com.lumiunited.aqarahome.R;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import k.u.c.d.d.m0;
import k.u.c.d.d.n0;
import k.u.c.d.j.i0;
import k.u.c.d.j.j0;
import k.u.c.d.j.n;
import k.u.c.d.j.o;
import k.u.c.d.j.r;
import k.u.c.e.d.f.d0;
import k.u.c.i.j3.z;
import k.u.c.i.m1;
import p.a.b0;
import p.a.k0;
import p.a.x0.g;
import pub.devrel.easypermissions.EasyPermissions;
public class TestAddGateway extends BaseActivity implements EasyPermissions.PermissionCallbacks {
public static final int j7 = -1;
public static final int k7 = 0;
public static final int l7 = 1;
public static final int m7 = 2;
public static final int n7 = 3;
public static final int o7 = 4;
public static final int p7 = 5;
public static final int q7 = 6;
public ConnectivityManager I;
public WifiManager J;
public ConnectivityChangeReceiver K;
public String R;
public HomeKitDeviceInfo S;
public BindUserWithHomeKit T;
public int U;
public int a7;
public int b7;
@BindView(R.id.btn_get_device_info)
public Button btnDeviceInfo;
@BindView(R.id.btn_retry)
public TextView btnRetry;
public int c7;
public int d7;
public int e7;
public int f7;
public p.a.u0.c g7;
public int h7;
@BindView(R.id.et_wifi_ssid)
public EditText mWIFISSID;
@BindView(R.id.et_wifi_pwd)
public EditText mWifiPWD;
public boolean H = false;
public String L = "App-Work";
public String M = "buzhidao";
public int N = -1;
public p.a.u0.b i7 = new p.a.u0.b();
public class ConnectivityChangeReceiver extends BroadcastReceiver {
public ConnectivityChangeReceiver() {
}
private void a(Context context, Intent intent) {
if (TextUtils.isEmpty(TestAddGateway.this.R)) {
return;
}
String format = String.format("\"%s\"", TestAddGateway.this.R);
if (intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE")) {
Bundle extras = intent.getExtras();
if (extras.getBoolean("noConnectivity", false) || extras.getInt("networkType") != 1) {
return;
}
String string = extras.getString("extraInfo");
if (format.equals(string)) {
TestAddGateway.this.a(context);
TestAddGateway.this.j1();
TestAddGateway.this.h1();
} else if (TextUtils.isEmpty(string) || string.equals("<unknown ssid>")) {
} else {
if (TestAddGateway.this.f7 > 0) {
TestAddGateway.o(TestAddGateway.this);
TestAddGateway.this.switchGatewayWifi();
return;
}
TestAddGateway testAddGateway = TestAddGateway.this;
testAddGateway.j0("切换到网关的WIFI:" + TestAddGateway.this.R + " 失败,点我手动切换");
}
}
}
private void b(Context context, Intent intent) {
if (TextUtils.isEmpty(TestAddGateway.this.L)) {
return;
}
String format = String.format("\"%s\"", TestAddGateway.this.L);
if (intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE")) {
Bundle extras = intent.getExtras();
if (extras.getBoolean("noConnectivity", false) || extras.getInt("networkType") != 1) {
return;
}
String string = extras.getString("extraInfo");
if (format.equals(string)) {
TestAddGateway.this.a(context);
TestAddGateway.this.f1();
TestAddGateway.this.j1();
} else if (TextUtils.isEmpty(string) || string.equals("<unknown ssid>")) {
} else {
if (TestAddGateway.this.a7 > 0) {
TestAddGateway.q(TestAddGateway.this);
TestAddGateway.this.checkWifi();
return;
}
TestAddGateway testAddGateway = TestAddGateway.this;
testAddGateway.j0("切换到网关待入网WIFI:s" + TestAddGateway.this.L + " 失败,点我手动切换");
}
}
}
@Override
public void onReceive(Context context, Intent intent) {
int i2 = TestAddGateway.this.N;
if (i2 == 0) {
b(context, intent);
} else if (i2 == 2) {
a(context, intent);
} else if (i2 != 5) {
} else {
TestAddGateway.this.a(context, intent);
}
}
}
public class b extends ConnectivityManager.NetworkCallback {
public b() {
}
@Override
public void onAvailable(Network network) {
super.onAvailable(network);
if (Build.VERSION.SDK_INT >= 23) {
TestAddGateway.this.I.bindProcessToNetwork(network);
} else {
ConnectivityManager.setProcessDefaultNetwork(network);
}
if (TestAddGateway.this.N == 2) {
TestAddGateway testAddGateway = TestAddGateway.this;
if (testAddGateway.i0(testAddGateway.R)) {
TestAddGateway.this.o1();
}
}
}
}
public class c extends o<String> {
public class a implements n<String> {
public a() {
}
@Override
public void onSuccess(String str) {
if (TestAddGateway.this.N == -1) {
return;
}
TestAddGateway.this.switchNetWifi();
}
@Override
public void onFailed(int i2, String str) {
if (TestAddGateway.this.N == -1) {
return;
}
TestAddGateway.this.switchNetWifi();
}
}
public c() {
}
@Override
public void a(int i2, String str) {
if (TestAddGateway.this.b7 > 0) {
TestAddGateway.w(TestAddGateway.this);
n0.a(new Runnable() {
@Override
public final void run() {
TestAddGateway.c.this.a();
}
}, 1000L);
return;
}
TestAddGateway.this.j0("发送入网信息到网关失败,确认在网关WIFI后,点我重试");
}
public void a() {
TestAddGateway.this.o1();
}
@Override
public void a(String str) {
TestAddGateway.this.N = 4;
if (TextUtils.isEmpty(str)) {
return;
}
k.d.a.f(str);
TestAddGateway.this.S = null;
List<HomeKitDeviceInfo> device_list = ((HomeKitGatewayResult) JSON.parseObject(str, HomeKitGatewayResult.class)).getDevice_list();
if (device_list != null && !device_list.isEmpty()) {
Iterator<HomeKitDeviceInfo> it = device_list.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
HomeKitDeviceInfo next = it.next();
String model = next.getModel();
if (!TextUtils.isEmpty(model) && model.contains("lumi.gateway")) {
TestAddGateway.this.S = next;
break;
}
}
}
m1.d().b(new a());
if (TestAddGateway.this.S != null) {
if (!z.a(TestAddGateway.this.S.getModel())) {
TestAddGateway.this.N = -1;
TestAddGateway.this.g0("请选择与设备一致的地区");
return;
}
TestAddGateway testAddGateway = TestAddGateway.this;
testAddGateway.T = testAddGateway.g1();
return;
}
TestAddGateway.this.g0("发送信息到网关成功,但是未获取到正确的设备信息");
}
}
public class d extends o<String> {
public d() {
}
@Override
public void a(int i2, String str) {
if (TestAddGateway.this.d7 > 0) {
TestAddGateway.g(TestAddGateway.this);
n0.a(new Runnable() {
@Override
public final void run() {
TestAddGateway.d.this.a();
}
}, 1000L);
}
}
public void a() {
TestAddGateway.this.i1();
}
@Override
public void a(String str) {
if (TextUtils.isEmpty(str)) {
TestAddGateway.this.N = -1;
return;
}
List parseArray = JSON.parseArray(str, BindGatewayResult.class);
if (parseArray.isEmpty()) {
return;
}
int code = ((BindGatewayResult) parseArray.get(0)).getCode();
if (626 == code) {
TestAddGateway.this.t1();
} else if (code == 0) {
TestAddGateway.this.N = -1;
TestAddGateway.this.l1();
TestAddGateway.this.h7 = 60;
}
}
}
public class e extends o<String> {
public e() {
}
@Override
public void a(int i2, String str) {
if (TestAddGateway.this.d7 > 0) {
TestAddGateway.g(TestAddGateway.this);
TestAddGateway.this.t1();
}
}
@Override
public void a(String str) {
TestAddGateway.this.d7 = 10;
TestAddGateway.this.i1();
}
}
public static int d(TestAddGateway testAddGateway) {
int i2 = testAddGateway.U;
testAddGateway.U = i2 - 1;
return i2;
}
private void f(boolean z2, String str) {
}
public static int g(TestAddGateway testAddGateway) {
int i2 = testAddGateway.d7;
testAddGateway.d7 = i2 - 1;
return i2;
}
public BindUserWithHomeKit g1() {
String str;
BindUserWithHomeKit bindUserWithHomeKit = new BindUserWithHomeKit();
BindUserWithHomeKit.DeviceInfo deviceInfo = new BindUserWithHomeKit.DeviceInfo();
deviceInfo.setClientId(k.u.c.y.a.e().a());
deviceInfo.setDid(this.S.getId());
deviceInfo.setLang(getResources().getConfiguration().locale.getLanguage());
Location d2 = k.u.c.r.l.d.d(getApplicationContext());
String str2 = "";
if (d2 != null) {
str = d2.getLatitude() + "";
} else {
str = "";
}
deviceInfo.setLatitude(str);
if (d2 != null) {
str2 = d2.getLongitude() + "";
}
deviceInfo.setLongitude(str2);
deviceInfo.setPositionId("room.491045792870563840");
deviceInfo.setPositionType("room");
deviceInfo.setTimeZone(r.b());
ArrayList arrayList = new ArrayList();
arrayList.add(deviceInfo);
bindUserWithHomeKit.setDids(arrayList);
return bindUserWithHomeKit;
}
public void h1() {
NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addTransportType(1);
this.I.requestNetwork(builder.build(), new b());
}
public boolean i0(String str) {
return this.I.getActiveNetworkInfo() != null && String.format("\"%s\"", str).equals(this.I.getActiveNetworkInfo().getExtraInfo());
}
public void i1() {
this.N = 6;
if (this.d7 <= 0) {
return;
}
m1.d().a(this.T, new d());
}
public void j0(String str) {
if (TextUtils.isEmpty(str)) {
this.btnRetry.setText("");
this.btnRetry.setVisibility(8);
r1();
return;
}
l1();
this.btnRetry.setVisibility(0);
this.btnRetry.setText(str);
}
public void j1() {
j0("");
}
private void k1() {
d0.d().a(getApplicationContext());
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.net.wifi.STATE_CHANGE");
intentFilter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
intentFilter.addAction("android.net.wifi.SCAN_RESULTS");
ConnectivityChangeReceiver connectivityChangeReceiver = new ConnectivityChangeReceiver();
this.K = connectivityChangeReceiver;
registerReceiver(connectivityChangeReceiver, intentFilter);
this.R = "Aqara Hub-A714";
m1();
}
public void l1() {
p.a.u0.c cVar = this.g7;
if (cVar == null || cVar.isDisposed()) {
return;
}
this.g7.dispose();
this.i7.a(this.g7);
}
private void m1() {
this.U = 3;
this.a7 = 2;
this.b7 = 5;
this.c7 = 2;
this.d7 = 5;
this.e7 = 2;
this.f7 = 1;
}
private void n1() {
}
public static int o(TestAddGateway testAddGateway) {
int i2 = testAddGateway.f7;
testAddGateway.f7 = i2 - 1;
return i2;
}
public void o1() {
this.N = 3;
if (!TextUtils.isEmpty(this.L) && !TextUtils.isEmpty(this.M)) {
m1.d().b(this.L, this.M, (String) null, new c());
} else {
g0("wifi 为空的");
}
}
private void p1() {
startActivity(new Intent("android.settings.WIRELESS_SETTINGS"));
}
public static int q(TestAddGateway testAddGateway) {
int i2 = testAddGateway.a7;
testAddGateway.a7 = i2 - 1;
return i2;
}
private void q1() {
startActivity(new Intent("android.settings.WIFI_SETTINGS"));
}
private void r1() {
p.a.u0.c cVar = this.g7;
if (cVar != null && !cVar.isDisposed()) {
this.g7.dispose();
this.i7.a(this.g7);
}
p.a.u0.c subscribe = b0.interval(0L, 1L, TimeUnit.SECONDS).onTerminateDetach().observeOn(p.a.s0.d.a.a()).subscribe(new g() {
@Override
public final void accept(Object obj) {
TestAddGateway.this.c((Long) obj);
}
}, new g() {
@Override
public final void accept(Object obj) {
k.d.a.c(((Throwable) obj).getMessage());
}
});
this.g7 = subscribe;
this.i7.b(subscribe);
}
private void s1() {
if (Build.VERSION.SDK_INT >= 23) {
this.I.bindProcessToNetwork(null);
} else {
ConnectivityManager.setProcessDefaultNetwork(null);
}
}
public void t1() {
if (this.e7 <= 0) {
return;
}
m1.d().r(this.S.getId(), new e());
}
public static int w(TestAddGateway testAddGateway) {
int i2 = testAddGateway.b7;
testAddGateway.b7 = i2 - 1;
return i2;
}
@Override
public void a(int i2, @NonNull List<String> list) {
}
@Override
public void b(int i2, @NonNull List<String> list) {
}
@OnClick({R.id.btn_check_send_result})
public void checkSendResult() {
}
@OnClick({R.id.btn_check_wifi})
public void checkWifi() {
this.h7 = 60;
r1();
m1();
this.N = 0;
if (j0.b((Activity) this)) {
if (this.J.isWifiEnabled()) {
if (i0(this.L)) {
f1();
return;
} else if (d0.d().a(this.L, this.M)) {
return;
} else {
j0("切换WIFI失败,需要手动切换. 点击我");
return;
}
}
this.J.setWifiEnabled(true);
}
}
@SuppressLint({"CheckResult"})
public void f1() {
if (this.N != 0 || this.H) {
return;
}
this.H = true;
m0.b("13342761749", "123456a").b((k0<UserInfo>) new a());
}
@OnClick({R.id.btn_get_device_info})
public void getDeviceInfo() {
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_test_add_gateway);
ButterKnife.a(this);
this.I = (ConnectivityManager) getApplicationContext().getSystemService("connectivity");
this.J = (WifiManager) getApplicationContext().getSystemService("wifi");
k1();
}
@Override
public void onDestroy() {
super.onDestroy();
s1();
unregisterReceiver(this.K);
}
@OnClick({R.id.btn_retry})
public void retry() {
int i2 = this.N;
if (i2 != 0 && i2 != 2) {
if (i2 == 3) {
o1();
return;
} else if (i2 != 5) {
if (i2 != 6) {
return;
}
i1();
return;
}
}
q1();
}
@OnClick({R.id.btn_scan_gateway})
public void scanGateway() {
if (this.J.startScan()) {
return;
}
n1();
}
@OnClick({R.id.btn_send_msg})
public void sendMsg() {
h1();
}
@OnClick({R.id.btn_switch_wifi})
public void switchGatewayWifi() {
this.N = 2;
if (i0(this.R)) {
h1();
} else if (d0.d().a(this.R, null)) {
} else {
j0("切换WIFI失败,需要手动切换. 点击我");
}
}
@OnClick({R.id.btn_swich_net_wifi})
public void switchNetWifi() {
this.N = 5;
if (i0(this.L)) {
i1();
} else if (d0.d().a(this.L, this.M)) {
} else {
j0("切换WIFI失败,需要手动切换. 点击我");
}
}
public class a extends k.u.c.v.a.b<UserInfo> {
public a() {
}
@Override
public void onSuccess(UserInfo userInfo) {
TestAddGateway testAddGateway = TestAddGateway.this;
testAddGateway.H = false;
if (testAddGateway.N == 0) {
TestAddGateway.this.switchGatewayWifi();
}
}
public void b() {
TestAddGateway.this.f1();
}
@Override
public void onSubscribe(p.a.u0.c cVar) {
TestAddGateway.this.i7.b(cVar);
}
@Override
public void a(int i2, String str) {
TestAddGateway testAddGateway = TestAddGateway.this;
testAddGateway.H = false;
if (testAddGateway.U > 0) {
TestAddGateway.d(TestAddGateway.this);
n0.a(new Runnable() {
@Override
public final void run() {
TestAddGateway.a.this.b();
}
}, 1000L);
return;
}
TextView textView = TestAddGateway.this.btnRetry;
textView.setText(TestAddGateway.this.L + "网络不通请检测网络状态");
}
}
public void c(Long l2) throws Exception {
if (this.h7 < 0) {
if (this.g7.isDisposed()) {
return;
}
this.g7.dispose();
return;
}
Button button = this.btnDeviceInfo;
button.setText(this.h7 + "秒");
this.h7 = this.h7 + (-1);
}
public void a(Context context, Intent intent) {
if (TextUtils.isEmpty(this.L)) {
this.N = -1;
return;
}
String format = String.format("\"%s\"", this.L);
if (intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE")) {
Bundle extras = intent.getExtras();
if (extras.getBoolean("noConnectivity", false) || extras.getInt("networkType") != 1) {
return;
}
String string = extras.getString("extraInfo");
if (format.equals(string)) {
a(context);
j1();
i1();
} else if (TextUtils.isEmpty(string) || string.equals("<unknown ssid>")) {
} else {
int i2 = this.c7;
if (i2 > 0) {
this.c7 = i2 - 1;
switchNetWifi();
return;
}
j0("biu biu 连接到了非指定WIFI,请手动切换到WIFI:" + this.L);
}
}
}
public void a(Context context) {
if (BaseActivity.f8941z) {
i0.a(context, new Intent(context, TestAddGateway.class));
}
}
}