Skip to content

Commit 035d570

Browse files
committed
修改接受返回数据包的数组大小
1 parent 26a9246 commit 035d570

File tree

2 files changed

+20
-40
lines changed

2 files changed

+20
-40
lines changed

app/src/main/java/com/guang/drcomandroid/MainActivity.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,6 @@ protected void onCreate(Bundle savedInstanceState) {
2828
btnLogin = (Button)this.findViewById(R.id.button1);
2929
btnLogout = (Button)this.findViewById(R.id.button2);
3030

31-
32-
// NotificationManager mNotifyMgr =
33-
// (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
34-
// PendingIntent contentIntent = PendingIntent.getActivity(
35-
// this, 1, new Intent(this, MainActivity.class), 0);
36-
//
37-
// NotificationCompat.Builder mBuilder =
38-
// new NotificationCompat.Builder(this)
39-
// .setSmallIcon(R.mipmap.ic_launcher)
40-
// .setContentTitle("Drcom正常运行中")
41-
// .setContentText("测试")
42-
// .setTicker("测试通知来啦")
43-
// .setDefaults(Notification.DEFAULT_VIBRATE)
44-
// .setWhen(System.currentTimeMillis())
45-
// .setContentIntent(contentIntent);
46-
//
47-
// mNotifyMgr.notify(1, mBuilder.build());
48-
4931
btnLogin.setOnClickListener(new View.OnClickListener() {
5032

5133
public void onClick(View v){
@@ -56,25 +38,13 @@ public void onClick(View v){
5638
Intent startIntent = new Intent(MainActivity.this, DrcomService.class);
5739
startIntent.putExtra("info",info);
5840
startService(startIntent);
59-
// HostInfo info = new HostInfo(mAccount,mPassword,"74-AC-5F-87-F3-ED");
60-
// mDrcomTask = new DrcomTask();
61-
// mDrcomTask.setOnMsgReceivedListener(new DrcomTask.MsgListener() {
62-
// @Override
63-
// public void onMsgReceived(String msg) {
64-
// Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
65-
// }
66-
// });
67-
// mDrcomTask.execute(info);
6841
}
6942
});
7043

7144
btnLogout.setOnClickListener(new View.OnClickListener() {
7245

7346
@Override
7447
public void onClick(View arg0) {
75-
// if (mDrcomTask != null) {
76-
// mDrcomTask.notifyLogout();
77-
// }
7848
stopService(new Intent(getBaseContext(), DrcomService.class));
7949
}
8050
});

app/src/main/java/com/guang/drcomandroid/drcom/DrcomService.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ public void run(){
8383
public void onCreate() {
8484
super.onCreate();
8585
LogUtils.e("oncreate:"+isNotificationEnabled(this));
86+
if(!isNotificationEnabled(this)){
87+
Toast.makeText(this, "Dr.com没有通知栏权限,记得去设置里开启喔", Toast.LENGTH_SHORT).show();
88+
}
89+
}
90+
91+
@Override
92+
public void onDestroy() {
93+
super.onDestroy();
94+
hideNotification();
8695
}
8796

8897
private void showNotification() {
@@ -93,10 +102,11 @@ private void showNotification() {
93102
NotificationCompat.Builder mBuilder =
94103
new NotificationCompat.Builder(this)
95104
.setSmallIcon(R.mipmap.ic_launcher)
96-
.setContentTitle("Drcom正常运行中")
97-
.setContentText("测试")
98-
.setTicker("测试通知来啦")
105+
.setContentTitle("Dr.com正常运行中")
106+
.setContentText("能看到我就说明有网络")
107+
.setTicker("Dr.com运行中")
99108
.setWhen(System.currentTimeMillis())
109+
.setOngoing(false) //用户无法滑动删除通知栏
100110
.setContentIntent(contentIntent);
101111
mNotifyMgr.notify(FOREGROUND_ID, mBuilder.build());
102112
}
@@ -105,9 +115,7 @@ private void hideNotification(){
105115
notificationManager.cancel(FOREGROUND_ID);
106116
}
107117

108-
109118
private boolean isNotificationEnabled(Context context) {
110-
111119
AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
112120
ApplicationInfo appInfo = context.getApplicationInfo();
113121
String pkg = context.getApplicationContext().getPackageName();
@@ -222,7 +230,7 @@ private void mainRun() {
222230
//重置端口 继续发alive包,若超过则可能是UDP丢包导致
223231
init();
224232
if(reconnectTimes >= 2){
225-
//第一次只重发alive失败后之后选择重新登陆
233+
//第一次只重发alive,失败后之后第二三次选择重新登陆
226234
if (!challenge(challengeTimes++)||!login()) {
227235
performMsgCall("自动重新登陆失败,准备断网");
228236
break;
@@ -240,7 +248,7 @@ private void mainRun() {
240248
} catch (SocketTimeoutException e) {
241249
e.printStackTrace();
242250
performMsgCall("通信超时:"+e.getMessage());
243-
// exception = true;
251+
exception = true;
244252
} catch (IOException e) {
245253
performMsgCall("IO 异常"+e.getMessage());
246254
exception = true;
@@ -486,7 +494,7 @@ private boolean alive() throws IOException {
486494
performLogCall("[rand="+ByteUtil.toHexString(packet38[36])+"|"+ByteUtil.toHexString(packet38[37])+"]"
487495
+"send keep38.:"+ByteUtil.toHexString(packet38));
488496

489-
byte[] recv = new byte[128];
497+
byte[] recv = new byte[64];
490498
client.receive(new DatagramPacket(recv, recv.length));
491499
String logStr = String.format("[rand={%s}|{%s}]recv Keep38. [{%s}.{%s}.{%s}.{%s}] 【{%s}】",
492500
ByteUtil.toHexString(recv[6]), ByteUtil.toHexString(recv[7]),
@@ -496,6 +504,7 @@ private boolean alive() throws IOException {
496504
keepAliveVer[0] = recv[28];//收到keepAliveVer//通常不会变
497505
keepAliveVer[1] = recv[29];
498506

507+
needExtra = false; //不发送keep40_extra貌似不影响广财的上网
499508
if (needExtra) {//每十次keep38都要发一个 keep40_extra
500509
performLogCall("Keep40_extra...");
501510
//--------------keep40_extra--------------------------------------------
@@ -509,7 +518,7 @@ private boolean alive() throws IOException {
509518
ByteUtil.toHexString(packet40extra[8]), ByteUtil.toHexString(packet40extra[9]),
510519
ByteUtil.toHexString(packet40extra));
511520
performLogCall(logStr);
512-
recv = new byte[512];
521+
recv = new byte[40];
513522
client.receive(new DatagramPacket(recv, recv.length));
514523
logStr = String.format("[seq={%s}|type={%s}][rand={%s}|{%s}]recv Keep40_extra. 【{%s}】",
515524
recv[1], recv[5], ByteUtil.toHexString(recv[8]), ByteUtil.toHexString(recv[9]), ByteUtil.toHexString(recv));
@@ -527,7 +536,7 @@ private boolean alive() throws IOException {
527536
ByteUtil.toHexString(packet40_1[8]), ByteUtil.toHexString(packet40_1[9]),
528537
ByteUtil.toHexString(packet40_1));
529538
performLogCall(logStr);
530-
recv = new byte[64];//40
539+
recv = new byte[40];//40
531540
client.receive(new DatagramPacket(recv, recv.length));
532541
logStr = String.format("[seq={%s}|type={%s}][rand={%s}|{%s}]send Keep40_1. 【{%s}】",
533542
recv[1], recv[5],
@@ -547,6 +556,7 @@ private boolean alive() throws IOException {
547556
ByteUtil.toHexString(packet40_2[8]), ByteUtil.toHexString(packet40_2[9]),
548557
ByteUtil.toHexString(packet40_2));
549558
performLogCall(logStr);
559+
recv = new byte[40];
550560
client.receive(new DatagramPacket(recv, recv.length));
551561
// performLogCall("[seq={%s}|type={%s}][rand={%s}|{%s}]recv Keep40_2. 【{%s}】", recv[1], recv[5],
552562
// ByteUtil.toHexString(recv[8]), ByteUtil.toHexString(recv[9]), ByteUtil.toHexString(recv));

0 commit comments

Comments
 (0)