|
|
@ -11,9 +11,14 @@ import android.location.LocationListener;
|
|
|
|
import android.location.LocationManager;
|
|
|
|
import android.location.LocationManager;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Environment;
|
|
|
|
import android.os.Environment;
|
|
|
|
|
|
|
|
import android.os.FileObserver;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Handler;
|
|
|
|
|
|
|
|
import android.os.Looper;
|
|
|
|
|
|
|
|
import android.os.Message;
|
|
|
|
|
|
|
|
import android.os.Messenger;
|
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.os.SystemClock;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
@ -22,6 +27,7 @@ import android.os.Bundle;
|
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
import android.text.method.ScrollingMovementMethod;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.Display;
|
|
|
|
import android.view.Display;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
@ -31,6 +37,7 @@ import android.widget.Toast;
|
|
|
|
import com.dev.devapi.api.SysApi;
|
|
|
|
import com.dev.devapi.api.SysApi;
|
|
|
|
import com.dowse.camera.client.DSCameraManager;
|
|
|
|
import com.dowse.camera.client.DSCameraManager;
|
|
|
|
import com.xypower.mpapp.databinding.ActivityMainBinding;
|
|
|
|
import com.xypower.mpapp.databinding.ActivityMainBinding;
|
|
|
|
|
|
|
|
import com.xypower.mpapp.utils.RandomReader;
|
|
|
|
//import com.xinyingpower.microphoto.request.INettyMessageListener;
|
|
|
|
//import com.xinyingpower.microphoto.request.INettyMessageListener;
|
|
|
|
//import com.xinyingpower.microphoto.request.NettyChatClient;
|
|
|
|
//import com.xinyingpower.microphoto.request.NettyChatClient;
|
|
|
|
|
|
|
|
|
|
|
@ -53,6 +60,8 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
public static final String TAG = "MainActivity";
|
|
|
|
public static final String TAG = "MainActivity";
|
|
|
|
private static int MY_PERMISSIONS_REQUEST_FOREGROUND_SERVICE = 100;
|
|
|
|
private static int MY_PERMISSIONS_REQUEST_FOREGROUND_SERVICE = 100;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int MSG_WHAT_LOG_OBSERVER = MicroPhotoService.MSG_WHAT_MAX + 10;
|
|
|
|
|
|
|
|
|
|
|
|
public final static int DEFAULT_PROTOCOL = 0xFF00;
|
|
|
|
public final static int DEFAULT_PROTOCOL = 0xFF00;
|
|
|
|
|
|
|
|
|
|
|
|
// Used to load the 'microphoto' library on application startup.
|
|
|
|
// Used to load the 'microphoto' library on application startup.
|
|
|
@ -63,8 +72,53 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
private ActivityMainBinding binding;
|
|
|
|
private ActivityMainBinding binding;
|
|
|
|
private int defaultDataSubId;
|
|
|
|
private int defaultDataSubId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Handler mHandler = null;
|
|
|
|
|
|
|
|
private Messenger mMessenger = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private LogFileObserver mLogFileObserver = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class LogFileObserver extends FileObserver {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private long mOffset = 0;
|
|
|
|
|
|
|
|
private String mPath = null;
|
|
|
|
|
|
|
|
public LogFileObserver(String path) {
|
|
|
|
|
|
|
|
super(path, FileObserver.MODIFY | FileObserver.CREATE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mPath = path;
|
|
|
|
|
|
|
|
File file = new File(path);
|
|
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
|
|
mOffset = file.length();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onEvent(int event, String s) {
|
|
|
|
|
|
|
|
int e = event & FileObserver.ALL_EVENTS;
|
|
|
|
|
|
|
|
if (e == FileObserver.MODIFY) {
|
|
|
|
|
|
|
|
File file = new File(mPath);
|
|
|
|
|
|
|
|
long newOffset = file.length();
|
|
|
|
|
|
|
|
if (newOffset > mOffset) {
|
|
|
|
|
|
|
|
RandomReader reader = new RandomReader(mPath, mOffset);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte[] bytes = new byte[(int)(newOffset - mOffset)];
|
|
|
|
|
|
|
|
int bytesRead = reader.read(bytes);
|
|
|
|
|
|
|
|
mOffset += bytesRead;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Message msg = Message.obtain();
|
|
|
|
|
|
|
|
msg.what = MSG_WHAT_LOG_OBSERVER;
|
|
|
|
|
|
|
|
msg.obj = bytes;
|
|
|
|
|
|
|
|
msg.arg1 = bytesRead;
|
|
|
|
|
|
|
|
mHandler.sendMessage(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
|
|
|
if (mLogFileObserver != null) {
|
|
|
|
|
|
|
|
mLogFileObserver.stopWatching();
|
|
|
|
|
|
|
|
}
|
|
|
|
super.onDestroy();
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -88,6 +142,69 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
actionBar.setTitle(actionBar.getTitle().toString() + " " + getVersionName(getApplicationContext()));
|
|
|
|
actionBar.setTitle(actionBar.getTitle().toString() + " " + getVersionName(getApplicationContext()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.logs.setText("");
|
|
|
|
|
|
|
|
binding.logs.setMovementMethod(ScrollingMovementMethod.getInstance());
|
|
|
|
|
|
|
|
binding.logs.setScrollbarFadingEnabled(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mHandler = new Handler(Looper.myLooper()) {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void handleMessage(@NonNull Message msg) {
|
|
|
|
|
|
|
|
switch (msg.what) {
|
|
|
|
|
|
|
|
case MicroPhotoService.MSG_WHAT_LOG: {
|
|
|
|
|
|
|
|
String log = (String) msg.obj;
|
|
|
|
|
|
|
|
binding.logs.append(log);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reply
|
|
|
|
|
|
|
|
// Messenger clientMessenger = msg.replyTo;
|
|
|
|
|
|
|
|
// Message replyMessage = Message.obtain(null, 2);
|
|
|
|
|
|
|
|
// 设置回复消息中的数据
|
|
|
|
|
|
|
|
Bundle replyData = new Bundle();
|
|
|
|
|
|
|
|
replyData.putString("key", "reply value");
|
|
|
|
|
|
|
|
// replyMessage.setData(replyData);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
clientMessenger.send(replyMessage);
|
|
|
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_WHAT_LOG_OBSERVER:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
byte[] bytes = (byte[])msg.obj;
|
|
|
|
|
|
|
|
int bytesRead = msg.arg1;
|
|
|
|
|
|
|
|
String log = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
log = new String(bytes, 0, bytesRead, "UTF-8");
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log != null) {
|
|
|
|
|
|
|
|
binding.logs.append(log);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int line = binding.logs.getLineCount();
|
|
|
|
|
|
|
|
// if (line > 9) {//超出屏幕自动滚动显示(9是当前页面显示的最大行数)
|
|
|
|
|
|
|
|
int offset = line * binding.logs.getLineHeight();
|
|
|
|
|
|
|
|
if (offset > binding.logs.getHeight()) {
|
|
|
|
|
|
|
|
binding.logs.scrollTo(0, offset - binding.logs.getHeight() + binding.logs.getLineHeight());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
mMessenger = new Messenger(new Handler());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String logFilePath = MicroPhotoService.buildAppDir(this.getApplicationContext());
|
|
|
|
|
|
|
|
logFilePath += "logs/log.txt";
|
|
|
|
|
|
|
|
mLogFileObserver = new LogFileObserver(logFilePath);
|
|
|
|
|
|
|
|
mLogFileObserver.startWatching();
|
|
|
|
|
|
|
|
|
|
|
|
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
|
|
|
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
|
|
|
Display defaultDisplay = windowManager.getDefaultDisplay();
|
|
|
|
Display defaultDisplay = windowManager.getDefaultDisplay();
|
|
|
|
int width = defaultDisplay.getWidth();
|
|
|
|
int width = defaultDisplay.getWidth();
|
|
|
@ -159,6 +276,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
intent.putExtra("port", curAppConfig.port);
|
|
|
|
intent.putExtra("port", curAppConfig.port);
|
|
|
|
intent.putExtra("protocol", curAppConfig.protocol);
|
|
|
|
intent.putExtra("protocol", curAppConfig.protocol);
|
|
|
|
intent.putExtra("networkProtocol", curAppConfig.networkProtocol);
|
|
|
|
intent.putExtra("networkProtocol", curAppConfig.networkProtocol);
|
|
|
|
|
|
|
|
intent.putExtra("messenger", mMessenger);
|
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
MainActivity.this.startForegroundService(intent);
|
|
|
|
MainActivity.this.startForegroundService(intent);
|
|
|
@ -400,15 +518,15 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
String appPath = MicroPhotoService.buildAppDir(this.getApplicationContext());
|
|
|
|
String appPath = MicroPhotoService.buildAppDir(this.getApplicationContext());
|
|
|
|
|
|
|
|
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
|
|
|
|
BufferedReader bufferedReader = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
inputStreamReader = new InputStreamReader(new FileInputStream(new File(appPath + "data/App.json")), "UTF-8");
|
|
|
|
inputStreamReader = new InputStreamReader(new FileInputStream(new File(appPath + "data/App.json")), "UTF-8");
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
String line;
|
|
|
|
String line;
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
stringBuilder.append(line);
|
|
|
|
stringBuilder.append(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(stringBuilder.toString());
|
|
|
|
JSONObject jsonObject = new JSONObject(stringBuilder.toString());
|
|
|
|
appConfig.cmdid = jsonObject.getString("CMDID");
|
|
|
|
appConfig.cmdid = jsonObject.getString("CMDID");
|
|
|
@ -427,12 +545,17 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
inputStreamReader.close();
|
|
|
|
inputStreamReader.close();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -443,6 +566,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
String appPath = MicroPhotoService.buildAppDir(this.getApplicationContext());
|
|
|
|
String appPath = MicroPhotoService.buildAppDir(this.getApplicationContext());
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
|
|
|
|
BufferedReader bufferedReader = null;
|
|
|
|
OutputStreamWriter outputStreamWriter = null;
|
|
|
|
OutputStreamWriter outputStreamWriter = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
@ -452,13 +576,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inputStreamReader = new InputStreamReader(new FileInputStream(new File(appPath + "data/App.json")), "UTF-8");
|
|
|
|
inputStreamReader = new InputStreamReader(new FileInputStream(new File(appPath + "data/App.json")), "UTF-8");
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
String line;
|
|
|
|
String line;
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
stringBuilder.append(line);
|
|
|
|
stringBuilder.append(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(stringBuilder.toString());
|
|
|
|
JSONObject jsonObject = new JSONObject(stringBuilder.toString());
|
|
|
|
|
|
|
|
|
|
|
@ -477,6 +600,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
inputStreamReader.close();
|
|
|
|
inputStreamReader.close();
|
|
|
|