Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MyApplicationVolume/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
versionCode 1
multiDexEnabled true

versionName "2.7.4"
versionName "1.3.3"


testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
7 changes: 4 additions & 3 deletions MyApplicationVolume/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@
android:name=".core.Myapplication"
android:allowBackup="true"
android:exported="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:icon="@mipmap/ic_car_launcher_square"
android:label="@string/app_name_linshi"
android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_config"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/ic_car_launcher_circle"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar"
tools:replace="android:icon, android:label"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity
android:name=".core.game.leaderBoard.LeaderBoardActivity"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import com.penglab.hi5.core.collaboration.basic.ReceiveMsgInterface;
import com.penglab.hi5.core.collaboration.connector.ServerConnector;
import com.penglab.hi5.core.collaboration.service.BasicService;
import com.penglab.hi5.core.collaboration.service.CollaborationService;
import com.penglab.hi5.core.collaboration.service.ManageService;
import com.penglab.hi5.core.ui.collaboration.CollaborationActivity;
import com.penglab.hi5.core.ui.login.LoginActivity;
import com.penglab.hi5.core.ui.home.screens.HomeActivity;
import com.penglab.hi5.data.dataStore.PreferenceLogin;
Expand Down Expand Up @@ -99,12 +101,12 @@ public void run() {
}

customSplash = false;
if (canAutoLogin()) {
onIntent();
} else {
LoginActivity.start(SplashScreenActivity.this);
finish();
}
// if (canAutoLogin()) {
// onIntent();
// } else {
LoginActivity.start(SplashScreenActivity.this);
finish();
// }
}
}
};
Expand Down Expand Up @@ -199,12 +201,12 @@ public void run() {
}

customSplash = false;
if (canAutoLogin()) {
onIntent();
} else {
// if (canAutoLogin()) {
// onIntent();
// } else {
LoginActivity.start(SplashScreenActivity.this);
finish();
}
// }
}
}
};
Expand All @@ -225,12 +227,12 @@ public void run() {
}

customSplash = false;
if (canAutoLogin()) {
onIntent();
} else {
// if (canAutoLogin()) {
// onIntent();
// } else {
LoginActivity.start(SplashScreenActivity.this);
finish();
}
// }
}
};
if (customSplash) {
Expand Down Expand Up @@ -389,8 +391,9 @@ private void showMainActivity(Intent intent) {
InfoCache.setToken(preferenceLogin.getPassword());

// MainActivity.actionStart(SplashScreenActivity.this, account);
HomeActivity.start(SplashScreenActivity.this);
ToastEasy("Welcome, " + account +" !");
// HomeActivity.start(SplashScreenActivity.this);
CollaborationActivity.start(SplashScreenActivity.this);
ToastEasy("Welcome entering in CAR_Mobile !");
finish();
}

Expand Down Expand Up @@ -470,16 +473,16 @@ public void run() {
// ToastEasy("runnable.run()3");

customSplash = false;
if (canAutoLogin()) {
// ToastEasy("runnable.run()4");

onIntent();
} else {
// if (canAutoLogin()) {
//// ToastEasy("runnable.run()4");
//
// onIntent();
// } else {
// ToastEasy("runnable.run()5");

LoginActivity.start(SplashScreenActivity.this);
finish();
}
// }
}
};
if (customSplash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.penglab.hi5.core.MainActivity;
import com.penglab.hi5.core.collaboration.basic.ReconnectionInterface;
import com.penglab.hi5.core.collaboration.connector.ExecutorServiceProvider;

import org.apache.commons.io.IOUtils;

Expand All @@ -23,81 +24,56 @@ public class MsgSender {

private final String TAG = "MsgSender";

private final ExecutorService executorService;
// private final ExecutorService executorService;

public MsgSender(){
executorService = Executors.newFixedThreadPool(4);
}

public boolean sendMsg(Socket socket, String message, boolean waited, boolean resend, ReconnectionInterface reconnectionInterface){

if ((socket == null || !socket.isConnected()) && !resend){
// public MsgSender(){
// executorService = Executors.newFixedThreadPool(4);
// }
public boolean sendMsg(Socket socket, String message, boolean waited, boolean resend, ReconnectionInterface reconnectionInterface) {
if (socket == null || !socket.isConnected()) {
ToastEasy("Fail to Send Message, check the network please !");
return false;
}

Future<Boolean> result = executorService.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try {
OutputStream out = socket.getOutputStream();

String data = message;
if(!message.startsWith("/login"))
data = message + "\n";

int dataLength = data.getBytes(StandardCharsets.UTF_8).length;

/*
msg header = type + dataLength
*/
String header = String.format("DataTypeWithSize:%d %s\n",0, dataLength);

// if (!data.startsWith("HeartBeat")){
// Log.d(TAG,"header: " + header.trim() + ", data: " + data);
//// Logcat.w("sender", data);
// }

String finalMsg = header + data;
out.write(finalMsg.getBytes(StandardCharsets.UTF_8));
out.flush();

/*
* show the progressbar
*/
// if (message.startsWith("/Imgblock:")){
// MainActivity.showDownloadingPopupView();
// }

}catch (Exception e){
Log.d(TAG, "Something wrong when send message to server");
e.printStackTrace();
if (resend){
reconnectionInterface.onReconnection(message);
}
return false;
}
Future<Boolean> result = ExecutorServiceProvider.getExecutorService().submit(() -> {
try {
OutputStream out = socket.getOutputStream();
String data = !message.startsWith("/login") ? message + "\n" : message;
int dataLength = data.getBytes(StandardCharsets.UTF_8).length;
String header = String.format("DataTypeWithSize:%d %s\n", 0, dataLength);
String finalMsg = header + data;
out.write(finalMsg.getBytes(StandardCharsets.UTF_8));
out.flush();
return true;
} catch (Exception e) {
Log.e(TAG, "Error when sending message", e);
if (resend) {
reconnectionInterface.onReconnection(message);
}
return false;
}
});

try {
if (waited){
if (waited) {
try {
return result.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Log.e(TAG, "Thread was interrupted", e);
return false;
} catch (Exception e) {
Log.e(TAG, "Error waiting for result", e);
return false;
}
} catch (Exception e){
e.printStackTrace();
return false;
}

return true;
return true; // Assuming async submission without waiting is considered successful
}



public boolean testConnection(Socket socket){

Future<Boolean> result = executorService.submit(new Callable<Boolean>() {
Future<Boolean> result = ExecutorServiceProvider.getExecutorService().submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try {
Expand Down Expand Up @@ -203,6 +179,6 @@ public byte[] longToBytes(long x) {
}

public void close(){
executorService.shutdown();
ExecutorServiceProvider.shutdownService();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void run() {
*/
if (mSocket.isConnected()) {
Log.e(TAG, "Connect Server Successfully !");

} else {
ToastEasy("Can't Connect Server, Try Again Please!");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.penglab.hi5.core.collaboration.connector;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExecutorServiceProvider {
private static ExecutorService executorService;

private ExecutorServiceProvider () {}

public static synchronized ExecutorService getExecutorService() {
if(executorService == null || executorService.isShutdown()) {
executorService = Executors.newFixedThreadPool(4);

}
return executorService;
}

public static synchronized void shutdownService() {
if(executorService !=null && !executorService.isShutdown()) {
executorService.shutdown();
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class BasicService extends Service {
// private static String TAG = BasicService.class.getSimpleName();
protected String TAG;

private ReceiveMsgInterface receiveMsgInterface;
private volatile ReceiveMsgInterface receiveMsgInterface;

// Binder given to clients
private final IBinder binder = new LocalBinder();
Expand Down Expand Up @@ -136,7 +136,7 @@ public void sendMsg(final String msg) {
* thread for read and process msg
*/
class ReadThread extends Thread {
private Socket mSocket;
private volatile Socket mSocket;
private InputStream is;
private boolean isReconnect = false; /* when the something wrong with the connect, and need to reconnect in the service */
private boolean isReset = false; /* when the connector release the connect, and need to reset connect in this thread */
Expand Down Expand Up @@ -204,6 +204,9 @@ public void resetConnection() {
@Override
public void run() {
super.run();
while(mSocket == null){

}
if (mSocket != null) {
try {
is = mSocket.getInputStream();
Expand Down Expand Up @@ -342,7 +345,9 @@ private void onRead(String tag) {
}
out.close();

while(receiveMsgInterface==null){

}
receiveMsgInterface.onRecMessage("File:" + dataType.filepath + "/" + dataType.filename);


Expand Down Expand Up @@ -465,6 +470,9 @@ private boolean processMsg(final String msg) {
if (msg.endsWith("\n")) {
Log.e(TAG,"ProcessMsg: "+msg);
resetDataType();
while(receiveMsgInterface==null){

}
receiveMsgInterface.onRecMessage(msg.trim());

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void onDestroy() {
// The service is no longer used and is being destroyed
Log.d(TAG, "onDestroy");
super.onDestroy();
isReleased = false;
}


Expand Down Expand Up @@ -81,7 +82,7 @@ public static void resetConnection(){
}

/* when fail to send msg in service, reConnect the socket; use synchronized to avoid the using conflict of socket */
public void reConnection(){
public void reConnection() {
Log.e(TAG,"Start to reConnect");
synchronized (lockForMsgSocket){
if(!mBasicConnector.checkConnection()){
Expand Down
Loading