[change] 添加后台权限相关代码,测试程序格式化时间

This commit is contained in:
xinfengkun
2022-06-09 13:41:16 +08:00
parent 9bf94a9765
commit f9441a3a5c
46 changed files with 1171 additions and 99 deletions

View File

@@ -69,6 +69,7 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation rootProject.ext.dependencies.gson
implementation project(':libraries:mogo-adas')
implementation project(':libraries:mogo-adas-backgrounder-permission')
// implementation 'com.zhidao.support.adas:high:2.6.6.0'
// implementation 'com.zhjt.mogo.adas.data:adas-data:2.6.6.0'
compileOnly project(':core:mogo-core-data')

View File

@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.zhidao.adas.client">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.DEVICE_POWER"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@@ -61,6 +63,40 @@
android:theme="@style/AppTheme.NoActionBar">
</activity>
<!-- 开机启动 -->
<receiver
android:name="BootCompletedReceive"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
android:process=":daemon">
<intent-filter android:priority="1000">
<action
android:name="android.net.conn.CONNECTIVITY_CHANGE"
tools:ignore="BatteryLife" />
<action android:name="android.net.ethernet.ETH_STATE_CHANGED" />
<action android:name="mitv.network.ethernet.action.ETHERNET_STATE_CHANGED" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
<action android:name="com.duokan.duokanplayer.BOOT_COMPLETED" />
<action android:name="android.intent.action.LETV_SCREENON" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.android.server.action.NETWORK_STATS_UPDATED" />
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<action android:name="android.intent.action.MEDIA_UNMOUNTED" />
<action android:name="android.intent.action.MEDIA_EJECT" />
<data android:scheme="file" />
</intent-filter>
</receiver>
</application>
</manifest>

View File

@@ -0,0 +1,13 @@
package com.zhidao.adas.client;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootCompletedReceive extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("开机", "启动");
}
}

View File

@@ -2,13 +2,15 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
public class ArrivalNotification extends BaseInfo {
public final MessagePad.ArrivalNotification bean;
public ArrivalNotification(MessagePad.Header header, MessagePad.ArrivalNotification bean) {
super("接收", bean.getSerializedSize(), header);
public ArrivalNotification(MessagePad.Header header, MessagePad.ArrivalNotification bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,13 +2,15 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
public class AutopilotState extends BaseInfo {
public final MessagePad.AutopilotState bean;
public AutopilotState(MessagePad.Header header, MessagePad.AutopilotState bean) {
super("接收", bean.getSerializedSize(), header);
public AutopilotState(MessagePad.Header header, MessagePad.AutopilotState bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -1,7 +1,8 @@
package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import mogo.telematics.pad.MessagePad;
@@ -10,12 +11,14 @@ public abstract class BaseInfo {
public final long nowTime;
public final MessagePad.Header header;
public final int len;
private SimpleDateFormat sdf;
public BaseInfo(String action, int len, MessagePad.Header header) {
public BaseInfo(String action, int len, MessagePad.Header header, SimpleDateFormat sdf) {
this.action = action;
nowTime = System.currentTimeMillis();
this.len = 8 + header.getSerializedSize() + len;
this.header = header;
this.sdf = sdf;
}
public BaseInfo(String action, int len) {
@@ -27,6 +30,8 @@ public abstract class BaseInfo {
@Override
public String toString() {
return "原始数据长度:"+len + "\nHeader:[" + TextFormat.printer().escapingNonAscii(false).shortDebugString(header) + "]\n";
return "原始数据长度:" + len + "\nHeader:[" + "MessageID:" + header.getMsgID() +
" MessageType:" + header.getMsgType() + " 发送时间:" + sdf.format(new Date((long) (header.getTimestamp() * 1000)))
+ " 数据源时间:" + sdf.format(new Date((long) (header.getSourceTimestamp() * 1000))) + "]\n";
}
}

View File

@@ -2,13 +2,15 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
public class BasicInfoReq extends BaseInfo {
public final MessagePad.BasicInfoReq bean;
public BasicInfoReq(MessagePad.Header header, MessagePad.BasicInfoReq bean) {
super("接收", bean.getSerializedSize(), header);
public BasicInfoReq(MessagePad.Header header, MessagePad.BasicInfoReq bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,13 +2,15 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
public class CarConfigResp extends BaseInfo {
public final MessagePad.CarConfigResp bean;
public CarConfigResp(MessagePad.Header header, MessagePad.CarConfigResp bean) {
super("接收", bean.getSerializedSize(), header);
public CarConfigResp(MessagePad.Header header, MessagePad.CarConfigResp bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,13 +2,15 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
public class GlobalPathResp extends BaseInfo {
public final MessagePad.GlobalPathResp bean;
public GlobalPathResp(MessagePad.Header header, MessagePad.GlobalPathResp bean) {
super("接收", bean.getSerializedSize(), header);
public GlobalPathResp(MessagePad.Header header, MessagePad.GlobalPathResp bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,13 +2,15 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
public class GnssInfo extends BaseInfo {
public final MessagePad.GnssInfo bean;
public GnssInfo(MessagePad.Header header, MessagePad.GnssInfo bean) {
super("接收", bean.getSerializedSize(), header);
public GnssInfo(MessagePad.Header header, MessagePad.GnssInfo bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,14 +2,16 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
import mogo_msg.MogoReportMsg;
public class MogoReportMessage extends BaseInfo {
public final MogoReportMsg.MogoReportMessage bean;
public MogoReportMessage(MessagePad.Header header, MogoReportMsg.MogoReportMessage bean) {
super("接收", bean.getSerializedSize(), header);
public MogoReportMessage(MessagePad.Header header, MogoReportMsg.MogoReportMessage bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,14 +2,16 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
import rule_segement.MogoPointCloudOuterClass;
public class MyPointCloud extends BaseInfo {
public final MogoPointCloudOuterClass.MogoPointCloud bean;
public MyPointCloud(MessagePad.Header header, MogoPointCloudOuterClass.MogoPointCloud bean) {
super("接收", bean.getSerializedSize(), header);
public MyPointCloud(MessagePad.Header header, MogoPointCloudOuterClass.MogoPointCloud bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,14 +2,16 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
import perception.TrafficLightOuterClass;
public class PerceptionTrafficLight extends BaseInfo {
public final TrafficLightOuterClass.TrafficLights bean;
public PerceptionTrafficLight(MessagePad.Header header, TrafficLightOuterClass.TrafficLights bean) {
super("接收", bean.getSerializedSize(), header);
public PerceptionTrafficLight(MessagePad.Header header, TrafficLightOuterClass.TrafficLights bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,13 +2,15 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
public class PlanningObjects extends BaseInfo {
public final MessagePad.PlanningObjects bean;
public PlanningObjects(MessagePad.Header header, MessagePad.PlanningObjects bean) {
super("接收", bean.getSerializedSize(), header);
public PlanningObjects(MessagePad.Header header, MessagePad.PlanningObjects bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,14 +2,16 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
import prediction.Prediction;
public class PredictionObstacleTrajectory extends BaseInfo {
public final Prediction.mPredictionObjects bean;
public PredictionObstacleTrajectory(MessagePad.Header header, Prediction.mPredictionObjects bean) {
super("接收", bean.getSerializedSize(), header);
public PredictionObstacleTrajectory(MessagePad.Header header, Prediction.mPredictionObjects bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,14 +2,16 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
import record_cache.RecordPanelOuterClass;
public class RecordPanel extends BaseInfo {
public final RecordPanelOuterClass.RecordPanel bean;
public RecordPanel(MessagePad.Header header, RecordPanelOuterClass.RecordPanel bean) {
super("接收", bean.getSerializedSize(), header);
public RecordPanel(MessagePad.Header header, RecordPanelOuterClass.RecordPanel bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,14 +2,16 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
import system_master.SystemStatusInfo;
public class StatusInfo extends BaseInfo {
public final SystemStatusInfo.StatusInfo bean;
public StatusInfo(MessagePad.Header header, SystemStatusInfo.StatusInfo bean) {
super("接收", bean.getSerializedSize(), header);
public StatusInfo(MessagePad.Header header, SystemStatusInfo.StatusInfo bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,13 +2,15 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
public class TrackedObjects extends BaseInfo {
private MessagePad.TrackedObjects bean;
public TrackedObjects(MessagePad.Header header, MessagePad.TrackedObjects bean) {
super("接收", bean.getSerializedSize(), header);
public TrackedObjects(MessagePad.Header header, MessagePad.TrackedObjects bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,13 +2,15 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
public class Trajectory extends BaseInfo {
public final MessagePad.Trajectory bean;
public Trajectory(MessagePad.Header header, MessagePad.Trajectory bean) {
super("接收", bean.getSerializedSize(), header);
public Trajectory(MessagePad.Header header, MessagePad.Trajectory bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}
@Override

View File

@@ -2,14 +2,16 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import chassis.VehicleStateOuterClass;
import mogo.telematics.pad.MessagePad;
public class VehicleState extends BaseInfo {
public final VehicleStateOuterClass.VehicleState bean;
public VehicleState(MessagePad.Header header, VehicleStateOuterClass.VehicleState bean) {
super("接收", bean.getSerializedSize(), header);
public VehicleState(MessagePad.Header header, VehicleStateOuterClass.VehicleState bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -2,13 +2,15 @@ package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
public class Warn extends BaseInfo {
public final MessagePad.Warn bean;
public Warn(MessagePad.Header header, MessagePad.Warn bean) {
super("接收", bean.getSerializedSize(), header);
public Warn(MessagePad.Header header, MessagePad.Warn bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}

View File

@@ -0,0 +1,150 @@
package com.zhidao.adas.client.log;
import android.os.Environment;
import android.text.TextUtils;
import com.zhidao.adas.client.utils.Constants;
import com.zhidao.support.adas.high.common.ThreadPoolManager;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
/**
* 与服务器交互日志管理任务
*/
public class ConnectStatusSave {
private static final String TAG = ConnectStatusSave.class.getSimpleName();
private static final String LOG_FILE_NAME = "ConnectStatus-%s.log";//文件名称
private volatile static ConnectStatusSave INSTANCE;
private static final long MAX_CAPACITY = 20 * 1024 * 1024L;//单文件最大存储容量 kb
private final LinkedBlockingQueue<String> queue;
private BufferedWriter buff = null;
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS", Locale.getDefault());
private File file;
private volatile long capacity = MAX_CAPACITY;
private Future future;
private ConnectStatusSave() {
queue = new LinkedBlockingQueue<>();
}
public static ConnectStatusSave getInstance() {
if (INSTANCE == null) {
synchronized (ConnectStatusSave.class) {
if (INSTANCE == null) {
INSTANCE = new ConnectStatusSave();
}
}
}
return INSTANCE;
}
public boolean isSdcardUse() {
boolean bl = false;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
bl = true;
}
return bl;
}
private synchronized void getFile() throws IOException {
if (isSdcardUse()) {
String time = sdf.format(new Date());
String childPath = time.split("_")[0] + File.separator;
file = new File(Constants.ROOT_PATH + childPath + String.format(LOG_FILE_NAME, time));
if (!file.exists()) {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
file.createNewFile();
}
FileWriter fw = new FileWriter(file, true);
buff = new BufferedWriter(fw);
}
}
public void saveLog(String info) {
if (isStart()) {
queue.add(info);
}
}
public boolean isStart() {
return future != null;
}
public void start() {
if (future == null) {
future = ThreadPoolManager.getsInstance().submit(new WriteThread());
}
}
public void stop() {
if (future != null) {
Runnable runnable = new Runnable() {
@Override
public void run() {
queue.clear();
if (!future.isCancelled()) {
future.cancel(true);
}
future = null;
closeBufferedWriter();
}
};
ThreadPoolManager.getsInstance().execute(runnable);
}
}
private void closeBufferedWriter() {
if (buff != null) {
try {
buff.flush();
buff.close();
} catch (IOException e) {
e.printStackTrace();
}
buff = null;
}
}
private class WriteThread implements Runnable {
@Override
public void run() {
synchronized (this) {
while (!Thread.currentThread().isInterrupted()) {
try {
long size = 0;
if (file != null) {
size = file.length();
}
if (size > capacity || file == null || !file.exists() || buff == null) {
closeBufferedWriter();
getFile();
}
String data = queue.take();
if (buff != null && !TextUtils.isEmpty(data)) {
buff.write(data);
buff.newLine();
buff.flush();
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
}

View File

@@ -3,6 +3,7 @@ package com.zhidao.adas.client.log;
import android.os.Environment;
import android.text.TextUtils;
import com.zhidao.adas.client.utils.Constants;
import com.zhidao.support.adas.high.common.ThreadPoolManager;
import java.io.BufferedWriter;
@@ -20,7 +21,6 @@ import java.util.concurrent.LinkedBlockingQueue;
*/
public class LogSave {
private static final String TAG = LogSave.class.getSimpleName();
private static final String ROOT_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "IPCMonitoring" + File.separator;//程序外部存储跟目录
private static final String LOG_FILE_NAME = "%s.log";//文件名称
private volatile static LogSave INSTANCE;
private static final long MAX_CAPACITY = 20 * 1024 * 1024L;//单文件最大存储容量 kb
@@ -59,7 +59,7 @@ public class LogSave {
if (isSdcardUse()) {
String time = sdf.format(new Date());
String childPath = time.split("_")[0] + File.separator;
file = new File(ROOT_PATH + childPath + String.format(LOG_FILE_NAME, time));
file = new File(Constants.ROOT_PATH + childPath + String.format(LOG_FILE_NAME, time));
if (!file.exists()) {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();

View File

@@ -7,11 +7,14 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.os.PowerManager;
import android.provider.Settings;
import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
@@ -71,6 +74,7 @@ import com.zhidao.adas.client.bean.TrackedObjects;
import com.zhidao.adas.client.bean.Trajectory;
import com.zhidao.adas.client.bean.VehicleState;
import com.zhidao.adas.client.bean.Warn;
import com.zhidao.adas.client.log.ConnectStatusSave;
import com.zhidao.adas.client.log.LogSave;
import com.zhidao.adas.client.utils.Constants;
import com.zhidao.support.adas.high.AdasManager;
@@ -88,10 +92,13 @@ import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
@@ -107,6 +114,7 @@ import system_master.SystemStatusInfo;
public class MainActivity extends BaseActivity implements OnAdasListener, OnAdasConnectStatusListener, BaseAdapter.OnItemClickListener<String> {
private final static String TAG = MainActivity.class.getSimpleName();
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault());
private static final int WHAT_IPC_IP = 0x00;
private static final int WHAT_DRIVER_IP = 0x01;
private static final int WHAT_IPC_CONNECT_STATE = 0x02;
@@ -115,6 +123,7 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
private ImageView tvIp;
private TextView title;
private TextView ipcIp;
private TextView background;
private TextView localIp;
private View line;
private View line1;
@@ -161,12 +170,15 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
// LogSave.getInstance().stop();
// }
PowerManager.WakeLock wakeLock;
WifiManager.WifiLock wifiLock;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initHandler();
ConnectStatusSave.getInstance().start();
isPad = isPad(this);
if (!isPad)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
@@ -177,6 +189,40 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
onUpdateConnectStateView();
showIPCIP();
canDrawOverlays();
// PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
// wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
// wakeLock.acquire();
// int wifiLockType = WifiManager.WIFI_MODE_FULL;
// try {
// wifiLockType = WifiManager.class.getField("WIFI_MODE_FULL_HIGH_PERF").getInt(null);
// } catch (Exception e) {
// // 我们必须运行在一个pre-Honeycomb设备上。
// Log.w(TAG, "无法获得高性能wifi锁.");
// }
// WifiManager wifiManager = WifiManager.class.cast(getApplicationContext().getSystemService(WIFI_SERVICE));
// wifiLock = wifiManager.createWifiLock(wifiLockType, TAG);
// wifiLock.acquire();
}
@Override
protected void onDestroy() {
super.onDestroy();
AdasManager.getInstance().setOnAdasListener(null);
AdasManager.getInstance().disconnect();
if (mExecutorServiceConfigTimer != null) {
mExecutorServiceConfigTimer.shutdownNow();
}
DataDistribution.getInstance().stop();
if (floatWindow != null) {
floatWindow.hideFloatWindow();
floatWindow = null;
}
ConnectStatusSave.getInstance().stop();
// 释放唤醒锁, 如果没有其它唤醒锁存在, 设备会很快进入休眠状态
if (wakeLock != null)
wakeLock.release();
if (wifiLock != null)
wifiLock.release();
}
private void canDrawOverlays() {
@@ -214,6 +260,7 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
private void initView() {
include_title = findViewById(R.id.include_title);
etIp = findViewById(R.id.et_ip);
background = findViewById(R.id.background);
role = findViewById(R.id.role);
line = findViewById(R.id.line);
line1 = findViewById(R.id.line1);
@@ -477,6 +524,22 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
}
}
});
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// String str = "后台运行:" + (AdasManager.getInstance().isPermissionLongBackgroundRunning(this) ? "<font color='red'>已优化</font>" : "<font color='red'>未优化</font>");
// background.setText(Html.fromHtml(str, Html.FROM_HTML_MODE_LEGACY));
// background.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//
//// Permission.requestAddDataSaverWhite(MainActivity.this);
//// AdasManager.getInstance().requestIgnoreBatteryOptimizations(MainActivity.this);
// AdasManager.getInstance().showPermissionLongBackgroundRunningDialog(MainActivity.this);
// }
// });
// } else {
// background.setVisibility(View.GONE);
// }
}
private void showListPopupWindow() {
@@ -690,56 +753,56 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
@Override
public void onTrajectory(MessagePad.Header header, MessagePad.Trajectory trajectory) {
Trajectory base = new Trajectory(header, trajectory);
Trajectory base = new Trajectory(header, trajectory, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onTrackedObjects(MessagePad.Header header, MessagePad.TrackedObjects trackedObjects) {
TrackedObjects base = new TrackedObjects(header, trackedObjects);
TrackedObjects base = new TrackedObjects(header, trackedObjects, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onGnssInfo(MessagePad.Header header, MessagePad.GnssInfo gnssInfo) {
GnssInfo base = new GnssInfo(header, gnssInfo);
GnssInfo base = new GnssInfo(header, gnssInfo, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onVehicleState(MessagePad.Header header, VehicleStateOuterClass.VehicleState vehicleState) {
VehicleState base = new VehicleState(header, vehicleState);
VehicleState base = new VehicleState(header, vehicleState, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onAutopilotState(MessagePad.Header header, MessagePad.AutopilotState autopilotState) {
AutopilotState base = new AutopilotState(header, autopilotState);
AutopilotState base = new AutopilotState(header, autopilotState, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onReportMessage(MessagePad.Header header, MogoReportMsg.MogoReportMessage mogoReportMessage) {
MogoReportMessage base = new MogoReportMessage(header, mogoReportMessage);
MogoReportMessage base = new MogoReportMessage(header, mogoReportMessage, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onPerceptionTrafficLight(MessagePad.Header header, TrafficLightOuterClass.TrafficLights trafficLights) {
PerceptionTrafficLight base = new PerceptionTrafficLight(header, trafficLights);
PerceptionTrafficLight base = new PerceptionTrafficLight(header, trafficLights, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onPredictionObstacleTrajectory(MessagePad.Header header, Prediction.mPredictionObjects predictionObjects) {
PredictionObstacleTrajectory base = new PredictionObstacleTrajectory(header, predictionObjects);
PredictionObstacleTrajectory base = new PredictionObstacleTrajectory(header, predictionObjects, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onPointCloud(MessagePad.Header header, MogoPointCloudOuterClass.MogoPointCloud pointCloud) {
MyPointCloud base = new MyPointCloud(header, pointCloud);
MyPointCloud base = new MyPointCloud(header, pointCloud, sdf);
DataDistribution.getInstance().addData(base);
// String data = PointCloudDecoder.decode(header, pointCloud);
// Log.i("dddd", "data==" + data.length());
@@ -749,13 +812,13 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
@Override
public void onPlanningObjects(MessagePad.Header header, MessagePad.PlanningObjects planningObjects) {
PlanningObjects base = new PlanningObjects(header, planningObjects);
PlanningObjects base = new PlanningObjects(header, planningObjects, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onBasicInfoReq(MessagePad.Header header, MessagePad.BasicInfoReq basicInfoReq) {
BasicInfoReq info = new BasicInfoReq(header, basicInfoReq);
BasicInfoReq info = new BasicInfoReq(header, basicInfoReq, sdf);
DataDistribution.getInstance().addData(info);
AdasManager.getInstance().sendBasicInfoResp("X202021111192N41VY", 0);
showToastCenter("收到车机基础信息请求:" + info.toString());
@@ -763,13 +826,13 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
@Override
public void onCarConfigResp(MessagePad.Header header, MessagePad.CarConfigResp carConfigResp) {
CarConfigResp base = new CarConfigResp(header, carConfigResp);
CarConfigResp base = new CarConfigResp(header, carConfigResp, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onRecordResult(MessagePad.Header header, RecordPanelOuterClass.RecordPanel recordPanel) {
RecordPanel base = new RecordPanel(header, recordPanel);
RecordPanel base = new RecordPanel(header, recordPanel, sdf);
DataDistribution.getInstance().addData(base);
recordKey = recordPanel.getKey();
recordFileName = recordPanel.getFilename();
@@ -777,25 +840,25 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
@Override
public void onGlobalPathResp(MessagePad.Header header, MessagePad.GlobalPathResp globalPathResp) {
GlobalPathResp base = new GlobalPathResp(header, globalPathResp);
GlobalPathResp base = new GlobalPathResp(header, globalPathResp, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onWarn(MessagePad.Header header, MessagePad.Warn warn) {
Warn base = new Warn(header, warn);
Warn base = new Warn(header, warn, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onArrivalNotification(MessagePad.Header header, MessagePad.ArrivalNotification arrivalNotification) {
ArrivalNotification base = new ArrivalNotification(header, arrivalNotification);
ArrivalNotification base = new ArrivalNotification(header, arrivalNotification, sdf);
DataDistribution.getInstance().addData(base);
}
@Override
public void onStatusQueryResp(MessagePad.Header header, SystemStatusInfo.StatusInfo statusInfo) {
StatusInfo base = new StatusInfo(header, statusInfo);
StatusInfo base = new StatusInfo(header, statusInfo, sdf);
DataDistribution.getInstance().addData(base);
}
@@ -892,21 +955,11 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
}
@Override
protected void onDestroy() {
super.onDestroy();
AdasManager.getInstance().setOnAdasListener(null);
AdasManager.getInstance().disconnect();
if (mExecutorServiceConfigTimer != null) {
mExecutorServiceConfigTimer.shutdownNow();
}
DataDistribution.getInstance().stop();
}
@Override
public void onConnectionIPCStatus(int ipcConnectionStatus, String reason) {
Log.i(TAG, "连接状态=" + (reason == null ? "主动断开连接" : reason));
// Log.i(TAG, "连接状态=" + (reason == null ? "主动断开连接" : reason));
String time = sdf.format(new Date());
ConnectStatusSave.getInstance().saveLog(time + " ipcConnectionStatus=" + ipcConnectionStatus + " reason=" + reason);
connectStatusList.add(0, new IPCConnectState(reason == null ? "主动断开连接" : reason, getStatusColor(ipcConnectionStatus)));
if (connectStatusList.size() > 100) {
connectStatusList.remove(connectStatusList.size() - 1);
@@ -924,12 +977,12 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
getHandler().sendEmptyMessage(WHAT_IPC_IP);
}
// LogSave.getInstance().saveLog("连接状态", status);
CupidLogUtils.i(TAG, "connectStatus=" + status);
// CupidLogUtils.i(TAG, "connectStatus=" + status);
}
@Override
public void onCompatibility(VersionCompatibility versionCompatibility) {
showToastCenter("所连工控机:\n" + versionCompatibility.toString(), Toast.LENGTH_LONG);
showToastCenter("所连工控机:\n" + (versionCompatibility == null ? "未连接" : versionCompatibility.toString()), Toast.LENGTH_LONG);
}
private void showLocalIP() {
@@ -1023,7 +1076,7 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
break;
case 2:
//发送sn
AdasManager.getInstance().sendBasicInfoResp("X202021111192N41VY", 1);
AdasManager.getInstance().sendBasicInfoResp("X202021111192N41VY", 0);
break;
case 3:
//数据采集5秒

View File

@@ -1,6 +1,7 @@
package com.zhidao.adas.client.utils;
import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;
import com.google.gson.reflect.TypeToken;
@@ -8,8 +9,11 @@ import com.zhidao.adas.client.bean.AutoPilotMode;
import com.zhidao.support.adas.high.common.JsonUtil;
import com.zhidao.support.adas.high.common.MessageType;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* @author song kenan
@@ -17,6 +21,9 @@ import java.util.List;
* @date 2021/10/8
*/
public class Constants {
public static final String ROOT_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "IPCMonitoring" + File.separator;//程序外部存储跟目录
public static final String FILE_PATH = ROOT_PATH + "Crash" + File.separator;
private static final String ALL_PATH = "all_path";//所有路线
private static final String DEFAULT_PATH = "[{\"endLatLon\":{\"latitude\":40.19774,\"longitude\":116.72704},\"endName\":\"汇源果汁\",\"name\":\"北京市顺义区北小营镇\",\"speedLimit\":20.0,\"startLatLon\":{\"latitude\":40.20047,\"longitude\":116.73512},\"startName\":\"13号路口西\"},{\"endLatLon\":{\"latitude\":40.19996,\"longitude\":116.73584},\"endName\":\"13号路口主路\",\"name\":\"北京市顺义区北小营镇\",\"speedLimit\":20.0,\"startLatLon\":{\"latitude\":40.19763,\"longitude\":116.72686},\"startName\":\"汇源果汁\"}]";

View File

@@ -23,7 +23,6 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
@@ -40,7 +39,7 @@ import java.util.Objects;
* @since Ver 1.0 I used to be a programmer like you, then I took an arrow in the knee
*/
public class CrashHandler implements UncaughtExceptionHandler {
private static final String FILE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "IPCMonitoring" + File.separator + "Crash" + File.separator;//程序外部存储跟目录
/**
* Log日志的tag
* String : TAG
@@ -75,7 +74,7 @@ public class CrashHandler implements UncaughtExceptionHandler {
*
* @since 2013-3-21下午8:46:15
*/
private final Map<String, String> mLogInfo = new HashMap<String, String>();
private Map<String, String> mLogInfo = new HashMap<String, String>();
/**
* 用于格式化日期,作为日志文件名的一部分(FIXME 注意在windows下文件名无法使用等符号)
* SimpleDateFormat : mSimpleDateFormat
@@ -219,8 +218,11 @@ public class CrashHandler implements UncaughtExceptionHandler {
for (Field field : mFields) {
try {
field.setAccessible(true);
mLogInfo.put(field.getName(), Objects.requireNonNull(field.get("")).toString());
} catch (IllegalArgumentException | IllegalAccessException e) {
mLogInfo.put(field.getName(), field.get("").toString());
Log.d(TAG, field.getName() + ":" + field.get(""));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
@@ -270,8 +272,8 @@ public class CrashHandler implements UncaughtExceptionHandler {
String mFileName = mContext.getPackageName() + "_Exception-" + mTime + ".log";
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
try {
File mDirectory = new File(FILE_PATH);
Log.v(TAG, mDirectory.toString());
File mDirectory = new File(Constants.FILE_PATH);
Log.d(TAG, mDirectory.toString());
if (!mDirectory.exists())
mDirectory.mkdirs();
FileOutputStream mFileOutputStream = new FileOutputStream(mDirectory + File.separator + mFileName);

View File

@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
<stroke
android:width="0.8dp"
android:color="#ffffff" />
<!-- 圆角 -->
<corners android:radius="6dp" />
</shape>

View File

@@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_dialog">
android:background="@drawable/bg_adas_dialog">
<TextView
android:id="@+id/title"

View File

@@ -6,23 +6,42 @@
android:focusable="true"
android:focusableInTouchMode="true">
<TextView
android:id="@+id/title"
<LinearLayout
android:id="@+id/title_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:gravity="center_vertical"
android:text="@string/app_name"
android:textColor="@color/colorWhile"
android:textSize="18dp"
android:textStyle="bold" />
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/app_name"
android:textColor="@color/colorWhile"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="后台运行:"
android:textColor="@color/colorWhile"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="@+id/role"
android:layout_width="22dp"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_toEndOf="@id/title"
android:layout_toEndOf="@id/title_layout"
android:scaleType="centerInside"
android:src="@drawable/selector_role" />

View File

@@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_float"
android:background="@drawable/bg_adas_dialog"
android:orientation="vertical">

View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,463 @@
#### 说明
# ADAS LIB
## 与工控机交互LIB
# 使用方法参见【app_ipc_monitoring】中的代码
## 可用接口
~~~java
/**
* 设置多设备监听
*
* @param l 监听
*/
AdasManager.getInstance().setOnMultiDeviceListener(OnMultiDeviceListener l);
~~~
~~~java
/**
* 设置工控机数据监听
*
* @param l 监听
*/
AdasManager.getInstance().setOnAdasListener(OnAdasListener l);
~~~
~~~java
/**
* 创建一个连接
*
* @param options 连接参数
* @param onAdasConnectStatusListener 连接状态监听
*/
AdasManager.getInstance().create(AdasOptions options, OnAdasConnectStatusListener onAdasConnectStatusListener);
~~~
~~~java
/**
* ADAS LIB 版本
*
* @return 版本
*/
AdasManager.getInstance().getAdasVersion();
~~~
~~~java
/**
* 获取协议版本
*
* @return 版本
*/
AdasManager.getInstance().getProtocolVersion();
~~~
~~~java
/**
* 获取工控机配置信息
*
* @return 配置信息 未连接为null 断开连接会清空
*/
AdasManager.getInstance().getCarConfig();
~~~
~~~java
/**
* 连接工控机
*/
AdasManager.getInstance().connect();
~~~
~~~java
/**
* 与工控机断开连接
*/
AdasManager.getInstance().disconnect();
~~~
~~~java
/**
* 获取当前工控机的链接状态
*
* @return {@link Constants.IPC_CONNECTION_STATUS}
*/
AdasManager.getInstance().getIpcConnectionStatus();
~~~
~~~java
/**
* Log是否开启打印
*/
AdasManager.getInstance().setEnableLog(boolean isEnableLog);
~~~
~~~java
/**
* 系统命令请求, 比如系统重启,启用新镜像
*
* @param type SystemCmdType。SYSTEMCMD_REBOOT 重启所有节点
* SystemCmdType。SYSTEMCMD_EMPLOY_NEW_IMAGE 使用新镜像(推镜像)
* SystemCmdType。SYSTEMCMD_SHUT_DOWN 关机
* @return boolean
*/
AdasManager.getInstance().sendSystemCmdReq(@NonNull MessagePad.SystemCmdType type);
~~~
~~~java
/**
* 解析工控机发送过来的数据
* 多设备时使用
*
* @param bytes 数据
*/
AdasManager.getInstance().parseIPCData(byte[] bytes);
~~~
~~~java
/**
* 获取工控机链接配置
*
* @return 工控机链接参数
*/
AdasManager.getInstance().getAdasOptions();
~~~
~~~java
/**
* 获取已经链接成功的工控机IP 未连接为null
*
* @return ip null:表示未连接
*/
AdasManager.getInstance().getIpcConnectedIp();
~~~
~~~java
/**
* 获取已经链接成功的工控机端口
*
* @return 端口 未连接为默认端口
*/
AdasManager.getInstance().getIpcConnectedPort();
~~~
~~~java
/**
* 自动驾驶设备基础信息应答
*
* @param sn SN
* @param environment 1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
* @return
*/
AdasManager.getInstance().sendBasicInfoResp(@NonNull String sn, int environment);
~~~
~~~java
/**
* 设置自动驾驶模式 启动自动驾驶
*
* @param mode 1: enter autopilot mode, 0: quit autopilot mode
* @param source 命令来源: 0: pad模拟(模拟时routeInfo传null), 1: AICloud业务
* @param routeInfo 自动驾驶路径信息
* @return
*/
AdasManager.getInstance().sendAutoPilotModeReq(int mode, int source, MessagePad.RouteInfo routeInfo);
~~~
~~~java
/**
* 设置演示模式
*
* @param enable 1: enable, 0: disable
* @return
*/
AdasManager.getInstance().sendDemoModeReq(int enable);
~~~
~~~java
/**
* 车机基础信息请求
*
* @return
*/
AdasManager.getInstance().sendCarConfigReq();
~~~
~~~java
/**
* 记录人工接管原因
*
* @param key bag key 唯一标识
* @param filename 文件路径
* @param reasonID 接管原因id
* @param reason 接管原因
* @return
*/
AdasManager.getInstance().sendRecordCause(long key, @NonNull String filename, @NonNull String reasonID, @NonNull String reason);
~~~
~~~java
/**
* 同下
*
* @param id
* @param type
* @return
*/
AdasManager.getInstance().startRecordPackage(int id, int type);
~~~
~~~java
/**
* 同下
*
* @param id
* @param type
* @return
*/
AdasManager.getInstance().startRecordPackage(int id, int duration, int type);
~~~
~~~java
/**
* 同下
*
* @param id
* @param type
* @return
*/
AdasManager.getInstance().stopRecordPackage(int id, int type);
~~~
~~~java
/**
* 数据采集请求 主动录制Bag包
*
* @param id 采集id
* @param duration 采集时间长
* @param type 采集类型, 1:badcase, 2: map; 3: rests
* @param isRecord 采集指令, true: 采集, false: 停止采集
* @param sustain 是否持续采集
* @return
*/
AdasManager.getInstance().sendRecordData(int id, int duration, int type, boolean isRecord);
~~~
~~~java
/**
* 设置自动驾驶最大速度
*
* @param speedLimit 最大车辆速度 m/s
* @return
*/
AdasManager.getInstance().sendAutopilotSpeedReq(double speedLimit);
~~~
~~~java
/**
* 发送红绿灯数据到工控机
*
* @param crossID roadID
* @param latitude
* @param longitude
* @param heading 红绿灯方向
* @param direction 路的航向角
* @param lightId 红绿灯ID
* @param laneNo 车道号
* @param arrowNo 当前车道对应地面要素转向
* @param flashYellow 黄灯总时间
* @param laneDetail 灯态具体信息
* @return
*/
AdasManager.getInstance().sendTrafficLightData(@NonNull String crossID, double latitude, double longitude, @NonNull String heading, @NonNull String direction, int lightId, int laneNo, int arrowNo, int flashYellow, MessagePad.TrafficLightDetail laneDetail);
~~~
~~~java
/**
* 自动驾驶路径请求
*
* @return
*/
AdasManager.getInstance().sendGlobalPathReq();
~~~
~~~java
/**
* 获取工控机固定IP列表
*
* @return 返回默认工控机IP列表
*/
AdasManager.getInstance().getIPCFixationIPList(Context context);
~~~
~~~java
/**
* 增加工控机固定IP
*
* @param ipcIP IP
*/
AdasManager.getInstance().addIPCFixationIP(Context context, String ipcIP);
~~~
~~~java
/**
* 删除指定的工控机固定IP
*
* @param ipcIP IP
*/
AdasManager.getInstance().delIPCFixationIP(Context context, String ipcIP);
~~~
~~~java
/**
* 删除所有工控机固定IP
*/
AdasManager.getInstance().delIPCFixationIP(Context context);
~~~
## OnAdasListener
### 工控机数据回调
#### 回调中对象的字段详情参见各个proto文件
~~~java
/**
* 自动驾驶局部轨迹 前车引导线
*
* @param header 头
* @param trajectory 数据
*/
void onTrajectory(MessagePad.Header header, MessagePad.Trajectory trajectory);
~~~
~~~java
/**
* 障碍物 他车数据
*
* @param header 头
* @param trackedObjects 数据
*/
void onTrackedObjects(MessagePad.Header header, MessagePad.TrackedObjects trackedObjects);
~~~
~~~java
/**
* 惯导信息
*
* @param header 头
* @param gnssInfo 数据
*/
void onGnssInfo(MessagePad.Header header, MessagePad.GnssInfo gnssInfo);
~~~
~~~java
/**
* 底盘信息, 透传底盘状态pb参考底盘
*
* @param header 头
* @param vehicleState 数据
*/
void onVehicleState(MessagePad.Header header, VehicleStateOuterClass.VehicleState vehicleState);
~~~
~~~java
/**
* 自动驾驶状态
*
* @param header 头
* @param autopilotState 数据
*/
void onAutopilotState(MessagePad.Header header, MessagePad.AutopilotState autopilotState);
~~~
~~~java
/**
* 监控事件报告
*
* @param header 头
* @param mogoReportMessage 数据
*/
void onReportMessage(MessagePad.Header header, MogoReportMsg.MogoReportMessage mogoReportMessage);
~~~
~~~java
/**
* 感知红绿灯
*
* @param header 头
* @param trafficLights 感知红绿灯
*/
void onPerceptionTrafficLight(MessagePad.Header header, TrafficLightOuterClass.TrafficLights trafficLights);
~~~
~~~java
/**
* 他车轨迹预测
*
* @param header 头
* @param predictionObjects 他车轨迹预测数据
*/
void onPredictionObstacleTrajectory(MessagePad.Header header, Prediction.mPredictionObjects predictionObjects);
~~~
~~~java
/**
* 自动驾驶设备基础信息请求
*
* @param header 头
* @param basicInfoReq 数据 目前没有任何参数
*/
void onBasicInfoReq(MessagePad.Header header, MessagePad.BasicInfoReq basicInfoReq);
~~~
~~~java
/**
* 车机基础信息应答
*
* @param header 头
* @param carConfigResp 数据
*/
void onCarConfigResp(MessagePad.Header header, MessagePad.CarConfigResp carConfigResp);
~~~
~~~java
/**
* 数据采集结果
*
* @param header 头
* @param recordPanel 数据
*/
void onRecordResult(MessagePad.Header header, RecordPanelOuterClass.RecordPanel recordPanel);
~~~
~~~java
/**
* 自动驾驶路径应答
*
* @param header 头
* @param globalPathResp 数据
*/
void onGlobalPathResp(MessagePad.Header header, MessagePad.GlobalPathResp globalPathResp);
~~~
~~~java
/**
* 报警信息
* 暂时保留,目前没有使用
*
* @param header 头
* @param warn 数据
*/
@Deprecated
void onWarn(MessagePad.Header header, MessagePad.Warn warn);
~~~
~~~java
/**
* 到站提醒 自动驾驶站点
*
* @param header 头
* @param arrivalNotification 数据
*/
void onArrivalNotification(MessagePad.Header header, MessagePad.ArrivalNotification arrivalNotification);
~~~
~~~java
/**
* 向IPC发送命令返回结果
*
* @param info
*/
void onSSHResult(SSHResult info);
~~~
~~~java
/**
* 数据错误
*
* @param status 错误原因
* @param bytes 原始数据
*/
void onError(ProtocolStatus status, byte[] bytes);
~~~
## OnAdasConnectStatusListener
### 连接状态监听
~~~java
/**
* 与工控机链接状态变化
*
* @param ipcConnectionStatus {@link Constants.IPC_CONNECTION_STATUS}
* @param reason 连接信息 需要判null
* 如果ipcConnectionStatus==Constants.IPC_CONNECTION_STATUS.DISCONNECTED&&reason==null 表示主动断开连接
*/
void onConnectionIPCStatus(@Define.IPCConnectionStatus int ipcConnectionStatus, @Nullable String reason);
~~~
## OnMultiDeviceListener
### 多设备链接监听
~~~java
/**
* 转发工控机消息
* 如果是客户端此回调不会被调用
*
* @param bytes 数据
*/
void onForwardingIPCMessage(byte[] bytes);
~~~

View File

@@ -0,0 +1,36 @@
plugins {
id 'com.android.library'
}
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
// buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
minSdkVersion 21
targetSdkVersion rootProject.ext.android.targetSdkVersion
// versionCode Integer.valueOf(VERSION_CODE)
// versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION")
//
// buildConfigField "String", "AP_VERSION", "\"${AP_VERSION}\""
versionCode rootProject.versionCode as int
versionName rootProject.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation rootProject.ext.dependencies.androidxappcompat
}

View File

@@ -0,0 +1,3 @@
GROUP=com.mogo.adas
POM_ARTIFACT_ID=mogo-adas
VERSION_CODE=1

View File

@@ -0,0 +1,26 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-----MogoMap-----
-keep class com.mogo.map.MogoNavi{
private <init>();
}

View File

@@ -0,0 +1,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zhidao.support.adas.high.permission">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<application>
<activity
android:name=".dialog.PermissionLongBackgroundRunningDialog"
android:theme="@style/PermissionLongBackgroundRunningDialogStyle" />
</application>
</manifest>

View File

@@ -0,0 +1,111 @@
package com.zhidao.support.adas.high.permission;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.PowerManager;
import android.provider.Settings;
import android.util.Log;
import com.zhidao.support.adas.high.permission.dialog.PermissionLongBackgroundRunningDialog;
/**
* 长时间后台运行权限检查
*/
public class BackgrounderPermission {
public void showPermissionLongBackgroundRunningDialog(Context context) {
Intent intent = new Intent(context, PermissionLongBackgroundRunningDialog.class);
context.startActivity(intent);
}
/**
* 获取当前是否开启电池优化
*
* @param context 上下文
* @return 否在设备的电源白名单上 true 表示未优化
*/
public boolean isIgnoringBatteryOptimizations(Context context) {
boolean isIgnoring = false;
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (powerManager != null) {
isIgnoring = powerManager.isIgnoringBatteryOptimizations(context.getPackageName());
}
return isIgnoring;
}
/**
* 申请 关闭电池优化权限
*
* @param context
*/
public void requestIgnoreBatteryOptimizations(Context context) {
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + context.getPackageName()));
context.startActivity(intent);
}
/**
* 是否忽略计费网络限制
* 后台运行时网络限制
*
* @param context
* @return
*/
public boolean isIgnoringMeteredNetworkRestrictions(Context context) {
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
// 检查设备是否在计费网络
// if (connMgr.isActiveNetworkMetered()) {
// Checks users Data Saver settings.
switch (connMgr.getRestrictBackgroundStatus()) {
case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED:
// 用户已为此应用启用流量节省程序。应用应努力限制前台流量消耗,并妥善处理后台流量消耗限制。
Log.i("Permission", "用户已为此应用启用流量节省程序。应用应努力限制前台流量消耗,并妥善处理后台流量消耗限制。");
return false;
case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_WHITELISTED:
// 用户已启用流量节省程序,但应用在白名单中。应用应努力限制前台和后台流量消耗。
Log.i("Permission", "用户已启用流量节省程序,但应用在白名单中。应用应努力限制前台和后台流量消耗。");
return false;
case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_DISABLED:
// 流量节省程序已停用。
Log.i("Permission", "流量节省程序已停用。");
return true;
}
// } else {
// // 设备不在计费网络,为所欲为
// Log.i("Permission","设备不在计费网络,为所欲为");
// return true;
// }
Log.i("dddd", "其他");
return false;
}
/**
* 除非应用的核心功能受到不利影响,否则 Google Play 政策禁止应用请求直接豁免 Android 6.0+ 中的电源管理功能(低电耗模式和应用待机模式)
*/
public static void requestAddDataSaverWhite(Context context) {
// ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
// if (connMgr != null && connMgr.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED) {
Intent intent = new Intent(Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS);
intent.setData(Uri.parse("package:" + context.getPackageName()));
context.startActivity(intent);
// }
}
/**
* 是否允许长时间后台运行
*
* @param context 上下文
* @return
*/
public boolean isPermissionLongBackgroundRunning(Context context) {
return isIgnoringBatteryOptimizations(context) && isIgnoringMeteredNetworkRestrictions(context);
}
}

View File

@@ -0,0 +1,41 @@
package com.zhidao.support.adas.high.permission.dialog;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.zhidao.support.adas.high.permission.R;
/**
* 数据用量及电池优化 权限申请
* 高版本Android系统会针对熄屏、休眠或后台 对电池WiFi等进行优化长时间网络可能会断开连接
*/
public class PermissionLongBackgroundRunningDialog extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.dialog_in, R.anim.dialog_out);
setContentView(R.layout.dialog_adas_permission_long_background_running);
// //设置弹出窗口与屏幕对齐
// Window win = this.getWindow();
// int density = (int) (getResources().getDisplayMetrics().density + 0.5f);
////设置内边距这里设置为10dp
// win.getDecorView().setPadding(10 * density, 10 * density, 10 * density, 10 * density);
// WindowManager.LayoutParams lp = win.getAttributes();
////设置窗口宽度
// lp.width = WindowManager.LayoutParams.MATCH_PARENT;
////设置窗口高度
// lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
////设置Dialog位置
// lp.gravity = Gravity.TOP;
// win.setAttributes(lp);
}
@Override
public void finish() {
super.finish();
//在此时设置转场动画
overridePendingTransition(R.anim.dialog_out, R.anim.dialog_in);
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="50%"
android:toYDelta="100%" />
<alpha
android:duration="300"
android:fromAlpha="0"
android:toAlpha="1" />
</set>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="50%"
android:toYDelta="0" />
<alpha
android:duration="300"
android:fromAlpha="0"
android:toAlpha="1" />
</set>

View File

@@ -3,7 +3,7 @@
<solid android:color="#FAFFFFFF" />
<stroke
android:width="0.8dp"
android:color="#A140E0D0" />
android:color="#81666666" />
<!-- 圆角 -->
<corners android:radius="6dp" />
</shape>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_adas_dialog"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="由于系统默认启动了电池优化功能,此功会影响熄屏或休眠后网络连接"
android:textColor="#000000" />
</LinearLayout>

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">adas-backgrounder-permission</string>
</resources>

View File

@@ -0,0 +1,21 @@
<resources>
<style name="PermissionLongBackgroundRunningDialogStyle" parent="Theme.AppCompat.Dialog">
<!--设置dialog的背景-->
<item name="android:windowBackground">@android:color/transparent</item>
<!--设置Dialog的windowFrame框为无-->
<item name="android:windowFrame">@null</item>
<!--设置无标题-->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!--是否浮现在activity之上-->
<item name="android:windowIsFloating">true</item>
<!--是否半透明-->
<item name="android:windowIsTranslucent">true</item>
<!--设置窗口内容不覆盖-->
<item name="android:windowContentOverlay">@null</item>
<!--背景是否模糊显示-->
<item name="android:backgroundDimEnabled">true</item>
</style>
</resources>

View File

@@ -62,6 +62,7 @@ include ':libraries:mogo-map-api'
include ':libraries:mogo-map'
include ':libraries:mogo-adas'
include ':libraries:mogo-adas-data'
include ':libraries:mogo-adas-backgrounder-permission'
// OLD业务模块
include ':modules:mogo-module-common'