|
|
|
@ -60,6 +60,7 @@ import android.util.Log;
|
|
|
|
|
import android.widget.RemoteViews;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import com.dev.api.XyDev;
|
|
|
|
|
import com.dev.devapi.api.SysApi;
|
|
|
|
|
import com.xypower.common.FileDownloader;
|
|
|
|
|
import com.xypower.common.FilesUtils;
|
|
|
|
@ -250,6 +251,23 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
public void onCreate() {
|
|
|
|
|
super.onCreate();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (usingEthernet()) {
|
|
|
|
|
mConnectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
|
|
|
|
|
|
Network[] nws = mConnectivityManager.getAllNetworks();
|
|
|
|
|
for (Network nw : nws) {
|
|
|
|
|
NetworkInfo ni = mConnectivityManager.getNetworkInfo(nw);
|
|
|
|
|
if (ni.getType() == ConnectivityManager.TYPE_ETHERNET) {
|
|
|
|
|
updateEhernet(mNativeHandle, nw.getNetworkHandle(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
final String appPath = MicroPhotoContext.buildMpAppDir(this);
|
|
|
|
|
|
|
|
|
@ -373,6 +391,12 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
getApplicationContext().unregisterReceiver(mScreenaAtionReceiver);
|
|
|
|
|
getApplicationContext().unregisterReceiver(mNetworkChangedReceiver);
|
|
|
|
|
|
|
|
|
|
if (mConnectivityManager != null) {
|
|
|
|
|
if (mNetworkCallback != null) {
|
|
|
|
|
mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LocalBroadcastManager.getInstance(getApplicationContext()).unregisterReceiver(mLocalMsgReceiver);
|
|
|
|
|
|
|
|
|
|
for(Map.Entry<String, PowerManager.WakeLock> entry : mWakeLocks.entrySet()) {
|
|
|
|
@ -929,6 +953,23 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
return START_NOT_STICKY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long getDefaultNetworkHandle() {
|
|
|
|
|
long defaultNetHandle = 0;
|
|
|
|
|
if (mConnectivityManager != null) {
|
|
|
|
|
Network network = mConnectivityManager.getActiveNetwork();
|
|
|
|
|
if (network != null) {
|
|
|
|
|
NetworkInfo networkInfo = mConnectivityManager.getNetworkInfo(network);
|
|
|
|
|
int type = networkInfo.getType();
|
|
|
|
|
if (type == ConnectivityManager.TYPE_MOBILE || type == ConnectivityManager.TYPE_VPN ||
|
|
|
|
|
type == ConnectivityManager.TYPE_MOBILE_DUN || type == ConnectivityManager.TYPE_MOBILE_HIPRI) {
|
|
|
|
|
defaultNetHandle = network.getNetworkHandle();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return defaultNetHandle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void startTerminalService(Intent intent) {
|
|
|
|
|
|
|
|
|
|
if (MicroPhotoService.this.mNativeHandle != 0) {
|
|
|
|
@ -982,8 +1023,9 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long defaultNetHandle = service.getDefaultNetworkHandle();
|
|
|
|
|
service.mNativeHandle = init(appPath, server, port, cmdid, protocol, networkProtocol,
|
|
|
|
|
encryptData, 0, service.getSignalLevel(), versionCode,
|
|
|
|
|
encryptData, defaultNetHandle, service.getSignalLevel(), versionCode,
|
|
|
|
|
BuildConfig.BUILD_TIMESTAMP, simcard, tfCardPath, nativeLibraryDir);
|
|
|
|
|
|
|
|
|
|
if (service.mNativeHandle != 0) {
|
|
|
|
@ -994,6 +1036,70 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
long startTime = (date.getTime() + 999) / 1000;
|
|
|
|
|
service.updateCaptureSchedule(startTime);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (usingEthernet()) {
|
|
|
|
|
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onLost(Network network) {
|
|
|
|
|
infoLog("Network Lost " + network.toString());
|
|
|
|
|
updateEhernet(mNativeHandle, network.getNetworkHandle(), false);
|
|
|
|
|
updateDefaultNetwork();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void onAvailable(final Network network) {
|
|
|
|
|
String ip = "";
|
|
|
|
|
try {
|
|
|
|
|
NetworkInfo ni = mConnectivityManager.getNetworkInfo(network);
|
|
|
|
|
LinkProperties lp = mConnectivityManager.getLinkProperties(network);
|
|
|
|
|
if (lp != null) {
|
|
|
|
|
List<LinkAddress> addresses = lp.getLinkAddresses();
|
|
|
|
|
if (addresses != null && addresses.size() > 0) {
|
|
|
|
|
for (LinkAddress linkAddress : addresses) {
|
|
|
|
|
InetAddress inetAddress = linkAddress.getAddress();
|
|
|
|
|
if (inetAddress != null && inetAddress instanceof Inet4Address) {
|
|
|
|
|
ip = inetAddress.getHostAddress();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
infoLog("Network Available " + network.toString() + " IP=" + ip + " Handle=" + Long.toString(network.getNetworkHandle()));
|
|
|
|
|
updateEhernet(mNativeHandle, network.getNetworkHandle(), true);
|
|
|
|
|
updateDefaultNetwork();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateDefaultNetwork() {
|
|
|
|
|
MicroPhotoService thisService = MicroPhotoService.this;
|
|
|
|
|
long defaultNetHandle = thisService.getDefaultNetworkHandle();
|
|
|
|
|
if (defaultNetHandle != 0) {
|
|
|
|
|
thisService.updateActiveNetwork(thisService.mNativeHandle, defaultNetHandle, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NetworkRequest request = new NetworkRequest.Builder()
|
|
|
|
|
.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
mConnectivityManager.registerNetworkCallback(request, mNetworkCallback);
|
|
|
|
|
|
|
|
|
|
Network[] nws = mConnectivityManager.getAllNetworks();
|
|
|
|
|
for (Network nw : nws) {
|
|
|
|
|
NetworkInfo ni = mConnectivityManager.getNetworkInfo(nw);
|
|
|
|
|
if (ni.getType() == ConnectivityManager.TYPE_ETHERNET) {
|
|
|
|
|
updateEhernet(mNativeHandle, nw.getNetworkHandle(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mPreviousLocation != null) {
|
|
|
|
|
service.updatePosition(mNativeHandle, mPreviousLocation.getLongitude(), mPreviousLocation.getLatitude(),
|
|
|
|
|
mPreviousLocation.getAccuracy(), mPreviousLocation.getTime() / 1000);
|
|
|
|
@ -1390,6 +1496,27 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
public static void restartApp(Context context, String packageName, String reason) {
|
|
|
|
|
|
|
|
|
|
// "com.xypower.mpmaster.ACT_REQ_RST_APP"
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.setAction("com.xypower.mpmaster.ACT_REQ_RST_APP");
|
|
|
|
|
intent.setPackage(MicroPhotoContext.PACKAGE_NAME_MPMASTER);
|
|
|
|
|
intent.putExtra("noDelay", 1);
|
|
|
|
|
intent.putExtra("reason", reason);
|
|
|
|
|
intent.putExtra("packageName", context.getPackageName());
|
|
|
|
|
context.sendBroadcast(intent);
|
|
|
|
|
System.exit(0);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if (TextUtils.equals(packageName, MicroPhotoContext.PACKAGE_NAME_MPAPP)) {
|
|
|
|
|
MicroPhotoContext.restartMpApp(context, reason, 0);
|
|
|
|
|
System.exit(0);
|
|
|
|
|
} else {
|
|
|
|
|
MicroPhotoContext.restartApp(context, packageName, reason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Intent intent = new Intent(context, MainActivity.class);
|
|
|
|
|
int noDelay = 1;
|
|
|
|
|
intent.putExtra("noDelay", noDelay);
|
|
|
|
@ -1397,11 +1524,10 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
intent.putExtra("reason", reason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
System.exit(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
|
|
|
int noDelay = 1;
|
|
|
|
@ -1505,58 +1631,6 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
public void setStaticNetwork(String iface, String ip, String netmask, String gateway)
|
|
|
|
|
{
|
|
|
|
|
if (mConnectivityManager == null || mNetworkCallback == null) {
|
|
|
|
|
mConnectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
|
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLost(Network network) {
|
|
|
|
|
infoLog("Network Lost " + network.toString());
|
|
|
|
|
updateEhernet(mNativeHandle, network.getNetworkHandle(), false);
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void onAvailable(final Network network) {
|
|
|
|
|
String ip = "";
|
|
|
|
|
try {
|
|
|
|
|
NetworkInfo ni = mConnectivityManager.getNetworkInfo(network);
|
|
|
|
|
LinkProperties lp = mConnectivityManager.getLinkProperties(network);
|
|
|
|
|
if (lp != null) {
|
|
|
|
|
List<LinkAddress> addresses = lp.getLinkAddresses();
|
|
|
|
|
if (addresses != null && addresses.size() > 0) {
|
|
|
|
|
for (LinkAddress linkAddress : addresses) {
|
|
|
|
|
InetAddress inetAddress = linkAddress.getAddress();
|
|
|
|
|
if (inetAddress != null && inetAddress instanceof Inet4Address) {
|
|
|
|
|
ip = inetAddress.getHostAddress();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
infoLog("Network Available " + network.toString() + " IP=" + ip);
|
|
|
|
|
updateEhernet(mNativeHandle, network.getNetworkHandle(), true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NetworkRequest request = new NetworkRequest.Builder()
|
|
|
|
|
.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
mConnectivityManager.registerNetworkCallback(request, mNetworkCallback);
|
|
|
|
|
|
|
|
|
|
Network[] nws = mConnectivityManager.getAllNetworks();
|
|
|
|
|
for (Network nw : nws) {
|
|
|
|
|
NetworkInfo ni = mConnectivityManager.getNetworkInfo(nw);
|
|
|
|
|
if (ni.getType() == ConnectivityManager.TYPE_ETHERNET) {
|
|
|
|
|
updateEhernet(mNativeHandle, nw.getNetworkHandle(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!TextUtils.equals("0.0.0.0", ip)) {
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.putExtra("cmd", "setnet");
|
|
|
|
@ -1602,6 +1676,7 @@ cellSignalStrengthGsm.getDbm();
|
|
|
|
|
protected native boolean reloadConfigs(long handler);
|
|
|
|
|
protected native void updatePosition(long handler, double lon, double lat, double radius, long ts);
|
|
|
|
|
protected native boolean updateEhernet(long handler, long nativeNetworkHandle, boolean available);
|
|
|
|
|
protected native boolean updateActiveNetwork(long handler, long nativeNetworkHandle, boolean available);
|
|
|
|
|
protected native boolean uninit(long handler);
|
|
|
|
|
protected native void recordingFinished(long handler, boolean photoOrVideo, boolean result, String path, long videoId);
|
|
|
|
|
protected native void captureFinished(long handler, boolean photoOrVideo, boolean result, Bitmap bm, long videoId);
|
|
|
|
@ -1612,6 +1687,8 @@ cellSignalStrengthGsm.getDbm();
|
|
|
|
|
public static native boolean sendExternalPhoto(long deviceHandle, String path, long photoInfo);
|
|
|
|
|
public static native void infoLog(String log);
|
|
|
|
|
|
|
|
|
|
public static native boolean usingEthernet();
|
|
|
|
|
|
|
|
|
|
public static native void setOtgState(boolean enabled);
|
|
|
|
|
public static native void setCam3V3Enable(boolean enabled);
|
|
|
|
|
public static native String getSerialNumber();
|
|
|
|
|