[change] 添加后台权限相关代码,测试程序格式化时间
This commit is contained in:
1
libraries/mogo-adas-backgrounder-permission/.gitignore
vendored
Normal file
1
libraries/mogo-adas-backgrounder-permission/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
463
libraries/mogo-adas-backgrounder-permission/README.md
Normal file
463
libraries/mogo-adas-backgrounder-permission/README.md
Normal 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);
|
||||
~~~
|
||||
36
libraries/mogo-adas-backgrounder-permission/build.gradle
Normal file
36
libraries/mogo-adas-backgrounder-permission/build.gradle
Normal 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
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
GROUP=com.mogo.adas
|
||||
POM_ARTIFACT_ID=mogo-adas
|
||||
VERSION_CODE=1
|
||||
26
libraries/mogo-adas-backgrounder-permission/proguard-rules.pro
vendored
Normal file
26
libraries/mogo-adas-backgrounder-permission/proguard-rules.pro
vendored
Normal 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>();
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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 user’s 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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#FAFFFFFF" />
|
||||
<stroke
|
||||
android:width="0.8dp"
|
||||
android:color="#81666666" />
|
||||
<!-- 圆角 -->
|
||||
<corners android:radius="6dp" />
|
||||
</shape>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">adas-backgrounder-permission</string>
|
||||
</resources>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user