version:1.2.4
fix: update:增加时间管控
This commit is contained in:
@@ -16,8 +16,8 @@ android {
|
|||||||
minSdkVersion 23
|
minSdkVersion 23
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
|
|
||||||
versionCode 24
|
versionCode 25
|
||||||
versionName "1.2.3"
|
versionName "1.2.4"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
</queries>
|
</queries>
|
||||||
|
|
||||||
<!-- 清单文件中, 申明监听通话精确状态权限,该权限需要android:sharedUserId="android.uid.system" -->
|
<!-- 清单文件中, 申明监听通话精确状态权限,该权限需要android:sharedUserId="android.uid.system" -->
|
||||||
|
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
||||||
<uses-permission android:name="android.permission.READ_PRECISE_PHONE_STATE" />
|
<uses-permission android:name="android.permission.READ_PRECISE_PHONE_STATE" />
|
||||||
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
|
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
|
||||||
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
|
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.xwad.os.bean.UserInfo;
|
|||||||
import com.xwad.os.config.CommonConfig;
|
import com.xwad.os.config.CommonConfig;
|
||||||
import com.xwad.os.databinding.ActivityHomeBinding;
|
import com.xwad.os.databinding.ActivityHomeBinding;
|
||||||
import com.xwad.os.jxw.SPUtils;
|
import com.xwad.os.jxw.SPUtils;
|
||||||
|
import com.xwad.os.manager.ControlManager;
|
||||||
import com.xwad.os.manager.DeviceSNManager;
|
import com.xwad.os.manager.DeviceSNManager;
|
||||||
import com.xwad.os.network.NetInterfaceManager;
|
import com.xwad.os.network.NetInterfaceManager;
|
||||||
import com.xwad.os.utils.ActivationUtil;
|
import com.xwad.os.utils.ActivationUtil;
|
||||||
@@ -108,8 +109,11 @@ public class HomeViewModel extends BaseViewModel<ActivityHomeBinding, ActivityEv
|
|||||||
Log.e("getSystemSettings", "onNext: " + systemSettingsBaseResponse);
|
Log.e("getSystemSettings", "onNext: " + systemSettingsBaseResponse);
|
||||||
if (systemSettingsBaseResponse.code == 200) {
|
if (systemSettingsBaseResponse.code == 200) {
|
||||||
SystemSettings systemSettings = systemSettingsBaseResponse.data;
|
SystemSettings systemSettings = systemSettingsBaseResponse.data;
|
||||||
|
ControlManager.getInstance().setSystemSetting(systemSettings);
|
||||||
mMMKV.encode(CommonConfig.APP_INSTALLATION, systemSettings.getSetting_other_appInstaller());
|
mMMKV.encode(CommonConfig.APP_INSTALLATION, systemSettings.getSetting_other_appInstaller());
|
||||||
mSystemSettingsMutableLiveData.setValue(systemSettings);
|
mSystemSettingsMutableLiveData.setValue(systemSettings);
|
||||||
|
}else {
|
||||||
|
ControlManager.getInstance().setDisableSetting();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,12 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.AppHolder> {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Log.e(TAG, "onClick: " + pkg);
|
Log.e(TAG, "onClick: " + pkg);
|
||||||
|
|
||||||
|
if (OpenApkUtils.getInstance().getDisallowedRunningAppSet().contains(pkg)) {
|
||||||
|
Toaster.show("应用已禁止打开");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (TextUtils.isEmpty(pkg)) {
|
if (TextUtils.isEmpty(pkg)) {
|
||||||
Toaster.show("应用未安装");
|
Toaster.show("应用未安装");
|
||||||
OpenApkUtils.getInstance().showDownloadDialog(mContext, pkg, lable);
|
OpenApkUtils.getInstance().showDownloadDialog(mContext, pkg, lable);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.xwad.os.alarm.AlarmUtils;
|
|||||||
import com.xwad.os.manager.AmapManager;
|
import com.xwad.os.manager.AmapManager;
|
||||||
import com.xwad.os.manager.AppManager;
|
import com.xwad.os.manager.AppManager;
|
||||||
import com.xwad.os.manager.ConnectManager;
|
import com.xwad.os.manager.ConnectManager;
|
||||||
|
import com.xwad.os.manager.ControlManager;
|
||||||
import com.xwad.os.manager.DeviceSNManager;
|
import com.xwad.os.manager.DeviceSNManager;
|
||||||
import com.xwad.os.manager.RemoteManager;
|
import com.xwad.os.manager.RemoteManager;
|
||||||
import com.xwad.os.network.NetInterfaceManager;
|
import com.xwad.os.network.NetInterfaceManager;
|
||||||
@@ -96,6 +97,7 @@ public class BaseApplication extends Application {
|
|||||||
AppUsedTimeUtils.init(this);
|
AppUsedTimeUtils.init(this);
|
||||||
OpenApkUtils.init(this);
|
OpenApkUtils.init(this);
|
||||||
ConnectManager.init(this);
|
ConnectManager.init(this);
|
||||||
|
ControlManager.init(this);
|
||||||
NetInterfaceManager.init(this);
|
NetInterfaceManager.init(this);
|
||||||
// startService(new Intent(this, MainService.class));
|
// startService(new Intent(this, MainService.class));
|
||||||
registAppReceive();
|
registAppReceive();
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.xwad.os.bean;
|
package com.xwad.os.bean;
|
||||||
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
@@ -70,32 +69,13 @@ public class SystemSettings implements Serializable {
|
|||||||
int is_top_notify;
|
int is_top_notify;
|
||||||
int is_bottom_bar;
|
int is_bottom_bar;
|
||||||
int is_notify_bar_show;
|
int is_notify_bar_show;
|
||||||
|
int browser_down;
|
||||||
int voice_assistant;
|
int voice_assistant;
|
||||||
|
int is_browser_network;
|
||||||
public int getQch_restore() {
|
int photo_answer_display;
|
||||||
return qch_restore;
|
int ai_teacher;
|
||||||
}
|
int photo_search_questions;
|
||||||
|
int ai_question_test;
|
||||||
public void setQch_restore(int qch_restore) {
|
|
||||||
this.qch_restore = qch_restore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSetting_browserInput() {
|
|
||||||
return setting_browserInput;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSetting_browserInput(int setting_browserInput) {
|
|
||||||
this.setting_browserInput = setting_browserInput;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDev_mode() {
|
|
||||||
return dev_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDev_mode(int dev_mode) {
|
|
||||||
this.dev_mode = dev_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getSetting_call() {
|
public int getSetting_call() {
|
||||||
return setting_call;
|
return setting_call;
|
||||||
@@ -273,6 +253,30 @@ public class SystemSettings implements Serializable {
|
|||||||
this.setting_hotspot = setting_hotspot;
|
this.setting_hotspot = setting_hotspot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getQch_restore() {
|
||||||
|
return qch_restore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQch_restore(int qch_restore) {
|
||||||
|
this.qch_restore = qch_restore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSetting_browserInput() {
|
||||||
|
return setting_browserInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSetting_browserInput(int setting_browserInput) {
|
||||||
|
this.setting_browserInput = setting_browserInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDev_mode() {
|
||||||
|
return dev_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDev_mode(int dev_mode) {
|
||||||
|
this.dev_mode = dev_mode;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSetting_sos() {
|
public String getSetting_sos() {
|
||||||
return setting_sos;
|
return setting_sos;
|
||||||
}
|
}
|
||||||
@@ -513,6 +517,14 @@ public class SystemSettings implements Serializable {
|
|||||||
this.is_notify_bar_show = is_notify_bar_show;
|
this.is_notify_bar_show = is_notify_bar_show;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getBrowser_down() {
|
||||||
|
return browser_down;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBrowser_down(int browser_down) {
|
||||||
|
this.browser_down = browser_down;
|
||||||
|
}
|
||||||
|
|
||||||
public int getVoice_assistant() {
|
public int getVoice_assistant() {
|
||||||
return voice_assistant;
|
return voice_assistant;
|
||||||
}
|
}
|
||||||
@@ -521,6 +533,46 @@ public class SystemSettings implements Serializable {
|
|||||||
this.voice_assistant = voice_assistant;
|
this.voice_assistant = voice_assistant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getIs_browser_network() {
|
||||||
|
return is_browser_network;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIs_browser_network(int is_browser_network) {
|
||||||
|
this.is_browser_network = is_browser_network;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPhoto_answer_display() {
|
||||||
|
return photo_answer_display;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhoto_answer_display(int photo_answer_display) {
|
||||||
|
this.photo_answer_display = photo_answer_display;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAi_teacher() {
|
||||||
|
return ai_teacher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAi_teacher(int ai_teacher) {
|
||||||
|
this.ai_teacher = ai_teacher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPhoto_search_questions() {
|
||||||
|
return photo_search_questions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhoto_search_questions(int photo_search_questions) {
|
||||||
|
this.photo_search_questions = photo_search_questions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAi_question_test() {
|
||||||
|
return ai_question_test;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAi_question_test(int ai_question_test) {
|
||||||
|
this.ai_question_test = ai_question_test;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
53
app/src/main/java/com/xwad/os/bean/TimeControl.java
Normal file
53
app/src/main/java/com/xwad/os/bean/TimeControl.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package com.xwad.os.bean;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class TimeControl implements Serializable {
|
||||||
|
private static final long serialVersionUID = 8400702243953866327L;
|
||||||
|
|
||||||
|
int id;
|
||||||
|
int user_id;
|
||||||
|
String sn;
|
||||||
|
String start_time;
|
||||||
|
String end_time;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUser_id() {
|
||||||
|
return user_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser_id(int user_id) {
|
||||||
|
this.user_id = user_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSn() {
|
||||||
|
return sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSn(String sn) {
|
||||||
|
this.sn = sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStart_time() {
|
||||||
|
return start_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStart_time(String start_time) {
|
||||||
|
this.start_time = start_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEnd_time() {
|
||||||
|
return end_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnd_time(String end_time) {
|
||||||
|
this.end_time = end_time;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,9 @@ public class CommonConfig {
|
|||||||
public static final String MMKV_ID = "InterProcessKV";
|
public static final String MMKV_ID = "InterProcessKV";
|
||||||
|
|
||||||
public static final String CLOUD_LESSON_SETTINGS_KEY = "cloud_lesson_settings_key";
|
public static final String CLOUD_LESSON_SETTINGS_KEY = "cloud_lesson_settings_key";
|
||||||
|
public static final String DISALLOWED_RUNNING_APP_KEY = "disallowed_running_app";
|
||||||
|
|
||||||
|
public static final String ALIYUN_PUSH_ID = "aliyun_push_id_key";
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static final String isLogined = "isLogined";
|
public static final String isLogined = "isLogined";
|
||||||
@@ -12,6 +15,9 @@ public class CommonConfig {
|
|||||||
public static final String LOCK_SCREEN_PASSWORD ="Iflytek_lockScreenPasswordKey";
|
public static final String LOCK_SCREEN_PASSWORD ="Iflytek_lockScreenPasswordKey";
|
||||||
public static final String DEFAULT_PASSWORD = "666666";
|
public static final String DEFAULT_PASSWORD = "666666";
|
||||||
|
|
||||||
|
public static final String SCREEN_LOCK_PWD = "screen_lock_passwd";
|
||||||
|
public static final String SUPER_PASSWORD = "0728";
|
||||||
|
|
||||||
/*保存个人基本信息*/
|
/*保存个人基本信息*/
|
||||||
/*性别*/
|
/*性别*/
|
||||||
public static final String UIUI_USER_GENDER_KEY = "USER_INFO_GENDER";
|
public static final String UIUI_USER_GENDER_KEY = "USER_INFO_GENDER";
|
||||||
@@ -41,6 +47,10 @@ public class CommonConfig {
|
|||||||
/*保存激活码*/
|
/*保存激活码*/
|
||||||
public static final String ACTIVATIONBEAN_CODE_KEY = "UIUI_ACTIVATIONBEAN_CODE";
|
public static final String ACTIVATIONBEAN_CODE_KEY = "UIUI_ACTIVATIONBEAN_CODE";
|
||||||
|
|
||||||
|
public static final String INSTALL_SD_APKS = "install_sd_apks";
|
||||||
|
/*是否显示通知栏,以及增强模式*/
|
||||||
|
public static final String NOTIFY_BAR_SHOW_KEY = "is_notify_bar_show_key";
|
||||||
|
|
||||||
/*是否显示返回Android按钮*/
|
/*是否显示返回Android按钮*/
|
||||||
public static final String UIUI_RETURN_ANDROID_KEY = "iflytek_uiui_is_return_android";
|
public static final String UIUI_RETURN_ANDROID_KEY = "iflytek_uiui_is_return_android";
|
||||||
|
|
||||||
@@ -51,8 +61,18 @@ public class CommonConfig {
|
|||||||
public static final String MAP_LONGITUDE_KEY = "map_longitude_key";
|
public static final String MAP_LONGITUDE_KEY = "map_longitude_key";
|
||||||
public static final String MAP_LATITUDE_KEY = "map_latitude_key";
|
public static final String MAP_LATITUDE_KEY = "map_latitude_key";
|
||||||
public static final String MAP_ADDRESS_KEY = "map_address_key";
|
public static final String MAP_ADDRESS_KEY = "map_address_key";
|
||||||
|
public static final String MAP_PROVINCE_KEY = "map_province_key";
|
||||||
|
public static final String MAP_CITY_KEY = "map_city_key";
|
||||||
|
public static final String MAP_DISTRICT_KEY = "map_district_key";
|
||||||
|
public static final String MAP_STREET_KEY = "map_street_key";
|
||||||
|
public static final String MAP_LOCATION_DESCRIBE_KEY = "map_locationDescribe_key";
|
||||||
public static final String MAP_ERROR_KEY = "map_error_key";
|
public static final String MAP_ERROR_KEY = "map_error_key";
|
||||||
|
|
||||||
|
public static final String MAP_onLocationChanged_time_KEY = "map_onLocationChanged_time_key";
|
||||||
|
|
||||||
|
public static final String MAP_BEAN = "MapBean";
|
||||||
|
|
||||||
|
|
||||||
public static final String SETTING_OTHER_APPINSTALLER_KEY = "iflytek_setting_other_appInstaller";
|
public static final String SETTING_OTHER_APPINSTALLER_KEY = "iflytek_setting_other_appInstaller";
|
||||||
/*应用市场的app列表*/
|
/*应用市场的app列表*/
|
||||||
public final static String ADMIN_APP_LIST = "only_admin_app_list";
|
public final static String ADMIN_APP_LIST = "only_admin_app_list";
|
||||||
@@ -80,4 +100,50 @@ public class CommonConfig {
|
|||||||
/*是否为管理员app*/
|
/*是否为管理员app*/
|
||||||
public static final String APP_ADMIN = "iflytek_setting_admin_app";
|
public static final String APP_ADMIN = "iflytek_setting_admin_app";
|
||||||
|
|
||||||
|
|
||||||
|
/*禁止联网应用*/
|
||||||
|
public final static String AOLE_ACTION_NETWORK_DISALLOW = "aole_network_disallow";
|
||||||
|
|
||||||
|
|
||||||
|
/*通话白名单开关*/
|
||||||
|
public final static String STRANGE_PHONE_DENY = "strange_phone_deny";
|
||||||
|
/*通话白名单*/
|
||||||
|
public static final String NUMBER_BLACK_WHITE_LIST = "mdm_call_black_and_white_list";
|
||||||
|
|
||||||
|
/*app安装白名单开关*/
|
||||||
|
public static final String APP_WHITELIST_CONTROL = "app_whitelist_control";
|
||||||
|
|
||||||
|
/*通知栏常驻*/
|
||||||
|
public static final String NOTI_BAR_PERMANENT_KEY = "notification_bar_permanent";
|
||||||
|
public static final String NOTI_BAR_PERMANENT_ACTION = "notification_bar_permanent_action";
|
||||||
|
/*是否允许通知*/
|
||||||
|
public static final String ALLOW_NOTIFICATION = "allow_notification";
|
||||||
|
|
||||||
|
/*默认桌面key*/
|
||||||
|
public final static String DESKTOP_APP_KEY = "desktop_app_key";
|
||||||
|
public final static String BROWSER_APP_KEY = "browser_app_key";
|
||||||
|
public final static String TYPEWRITING_APP_KEY = "typewriting_app_key";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管控系统指令
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*USB模式-充电*/
|
||||||
|
public final static String AOLE_ACTION_USB_USB_CHARGE = "aole_action_usb_usb_charge";
|
||||||
|
/*USB模式-MTP*/
|
||||||
|
public final static String AOLE_ACTION_USB_USB_MTP = "aole_action_usb_usb_mtp";
|
||||||
|
/*USB模式-MIDI*/
|
||||||
|
public final static String AOLE_ACTION_USB_USB_MIDI = "aole_action_usb_usb_midi";
|
||||||
|
|
||||||
|
/*应用安装白名单总开关*/
|
||||||
|
public final static String AOLE_APP_ALLOW_INSTALL = "aole_app_allow_install";
|
||||||
|
/*应用安装白名单*/
|
||||||
|
public final static String AOLE_ACTION_APP_FORBID = "aole_app_forbid";
|
||||||
|
/*强制安装应用,禁止卸载*/
|
||||||
|
public final static String AOLE_ACTION_FORCE_APP = "aole_force_app";
|
||||||
|
|
||||||
|
/*应用ID管控*/
|
||||||
|
public final static String AOLE_ACTION_APP_FORBID_ID = "aole_app_forbid_id";
|
||||||
|
/*应用ID管控*/
|
||||||
|
public final static String AOLE_ACTION_APP_FORBID_ARRAY = "DeselectViewArray";
|
||||||
}
|
}
|
||||||
|
|||||||
871
app/src/main/java/com/xwad/os/manager/ControlManager.java
Normal file
871
app/src/main/java/com/xwad/os/manager/ControlManager.java
Normal file
@@ -0,0 +1,871 @@
|
|||||||
|
package com.xwad.os.manager;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.hjq.toast.Toaster;
|
||||||
|
import com.tencent.mmkv.MMKV;
|
||||||
|
import com.xwad.os.BuildConfig;
|
||||||
|
import com.xwad.os.bean.SystemSettings;
|
||||||
|
import com.xwad.os.config.CommonConfig;
|
||||||
|
import com.xwad.os.gson.GsonUtils;
|
||||||
|
import com.xwad.os.utils.OpenApkUtils;
|
||||||
|
import com.xwad.os.utils.TimeUtils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统管理处理
|
||||||
|
* 所有数据 后台1是0否,底层0是1否
|
||||||
|
*
|
||||||
|
* @author jgy02
|
||||||
|
*/
|
||||||
|
public class ControlManager {
|
||||||
|
private static final String TAG = "ControlManager";
|
||||||
|
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
private static ControlManager sInstance;
|
||||||
|
private Context mContext;
|
||||||
|
private ContentResolver mResolver;
|
||||||
|
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||||
|
|
||||||
|
private ControlManager(Context context) {
|
||||||
|
if (context == null) {
|
||||||
|
throw new RuntimeException("Context is NULL");
|
||||||
|
}
|
||||||
|
this.mContext = context;
|
||||||
|
this.mResolver = context.getContentResolver();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init(Context context) {
|
||||||
|
if (sInstance == null) {
|
||||||
|
sInstance = new ControlManager(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ControlManager getInstance() {
|
||||||
|
if (sInstance == null) {
|
||||||
|
throw new IllegalStateException("You must be init ControlManager first");
|
||||||
|
}
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// private int changeNum(int status) {
|
||||||
|
// return status == 0 ? 1 : 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
private boolean isDebugMode() {
|
||||||
|
return BuildConfig.DEBUG;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSystemSetting(String jsonString) {
|
||||||
|
if (TextUtils.isEmpty(jsonString)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SystemSettings systemSettings = GsonUtils.toJavaObject(jsonString, SystemSettings.class);
|
||||||
|
if (null != systemSettings) {
|
||||||
|
setUSBstate(systemSettings);
|
||||||
|
// setPhoneList(systemSettings);
|
||||||
|
// setBluetooth(systemSettings);
|
||||||
|
// setHotspot(systemSettings);
|
||||||
|
setBar(systemSettings);
|
||||||
|
setCamera(systemSettings);
|
||||||
|
// setTF(systemSettings);
|
||||||
|
setIcon(systemSettings);
|
||||||
|
setCanReset(systemSettings);
|
||||||
|
setDeveloperOptions(systemSettings);
|
||||||
|
// setSearchTopic(systemSettings);
|
||||||
|
setSOSNumber(systemSettings);
|
||||||
|
setAppstoreAdmin(systemSettings);
|
||||||
|
setDefaultApp(systemSettings);
|
||||||
|
setIsControl(systemSettings);
|
||||||
|
setOtherAppInstaller(systemSettings);
|
||||||
|
setQuickApp(systemSettings);
|
||||||
|
setTimeControl(systemSettings);
|
||||||
|
setBrowserInput(systemSettings);
|
||||||
|
|
||||||
|
setZhuangyuanSetting(systemSettings);
|
||||||
|
setDisallowedRunningApp(systemSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSystemSetting(SystemSettings systemSettings) {
|
||||||
|
if (null != systemSettings) {
|
||||||
|
setUSBstate(systemSettings);
|
||||||
|
// setPhoneList(systemSettings);
|
||||||
|
// setBluetooth(systemSettings);
|
||||||
|
// setHotspot(systemSettings);
|
||||||
|
setBar(systemSettings);
|
||||||
|
setCamera(systemSettings);
|
||||||
|
// setTF(systemSettings);
|
||||||
|
setIcon(systemSettings);
|
||||||
|
setCanReset(systemSettings);
|
||||||
|
setDeveloperOptions(systemSettings);
|
||||||
|
// setSearchTopic(systemSettings);
|
||||||
|
setSOSNumber(systemSettings);
|
||||||
|
setAppstoreAdmin(systemSettings);
|
||||||
|
setDefaultApp(systemSettings);
|
||||||
|
setIsControl(systemSettings);
|
||||||
|
setOtherAppInstaller(systemSettings);
|
||||||
|
setQuickApp(systemSettings);
|
||||||
|
setTimeControl(systemSettings);
|
||||||
|
setBrowserInput(systemSettings);
|
||||||
|
|
||||||
|
setZhuangyuanSetting(systemSettings);
|
||||||
|
setDisallowedRunningApp(systemSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭所有功能
|
||||||
|
*/
|
||||||
|
public void setDisableSetting() {
|
||||||
|
Log.e("setDisableSetting", "Close all settings: ");
|
||||||
|
// setUSBstate(1);
|
||||||
|
// setPhoneList(1);
|
||||||
|
// setBluetooth(0);
|
||||||
|
// setHotspot(0);
|
||||||
|
setCamera(1);
|
||||||
|
// setTF(1);
|
||||||
|
setIcon(1);
|
||||||
|
setWallpaper(0);
|
||||||
|
setCanReset(1);
|
||||||
|
setBrowserInput(1);
|
||||||
|
if (!isDebugMode()) {
|
||||||
|
// setDeveloperOptions(1);
|
||||||
|
}
|
||||||
|
// setSearchTopic(0);
|
||||||
|
setTimeControlClose();
|
||||||
|
setDisallowedRunningApp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* usb连接模式管控
|
||||||
|
*
|
||||||
|
* @param settings
|
||||||
|
*/
|
||||||
|
private void setUSBstate(SystemSettings settings) {
|
||||||
|
//USB数据功能管控
|
||||||
|
//仅充电:usb_charge
|
||||||
|
//MTP模式:usb_mtp
|
||||||
|
//Midi模式:usb_midi
|
||||||
|
String setting_usb = settings.getSetting_usb();
|
||||||
|
Log.e("SystemSetting", "setting_usb:" + setting_usb);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* usb连接模式管控
|
||||||
|
*
|
||||||
|
* @param state
|
||||||
|
*/
|
||||||
|
public void setUSBstate(int state) {
|
||||||
|
//USB数据功能管控
|
||||||
|
//仅充电:usb_charge
|
||||||
|
//MTP模式:usb_mtp
|
||||||
|
//Midi模式:usb_midi
|
||||||
|
if (!isDebugMode()) {
|
||||||
|
try {
|
||||||
|
// boolean qch_usb_choose = Settings.System.putString(mResolver, "qch_usb_choose", "usb_charge");
|
||||||
|
// Log.e(TAG, "qch_usb_choose:" + qch_usb_choose);
|
||||||
|
String usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE;
|
||||||
|
Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings");
|
||||||
|
mContext.sendBroadcast(usbIntent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setUSBstate: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* usb连接模式管控
|
||||||
|
*/
|
||||||
|
public void setUSBstate(String action) {
|
||||||
|
//USB数据功能管控
|
||||||
|
//仅充电:usb_charge
|
||||||
|
//MTP模式:usb_mtp
|
||||||
|
//Midi模式:usb_midi
|
||||||
|
if (!isDebugMode()) {
|
||||||
|
Log.e(TAG, "qch_usb_choose:" + action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPhoneList(SystemSettings settings) {
|
||||||
|
//设置电话功能,电话白名单
|
||||||
|
// int setting_call = changeNum(settings.getSetting_call());
|
||||||
|
// boolean qch_call_forbid = Settings.System.putInt(mResolver, "qch_call_forbid", setting_call);
|
||||||
|
// Log.e("SystemSetting", "qch_call_forbid: " + setting_call);
|
||||||
|
|
||||||
|
// int setting_phone = changeNum(settings.getSetting_phone());
|
||||||
|
// boolean aole_white_list_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_WHITE_LIST_ON, setting_phone);
|
||||||
|
// Log.e("SystemSetting", "aole_white_list_on: " + setting_phone);
|
||||||
|
|
||||||
|
// String setting_phones = settings.getSetting_phones();
|
||||||
|
// boolean aole_white_list_Array = Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_WHITE_LIST_ARRAY, setting_phones);
|
||||||
|
// Log.e("SystemSetting", "aole_white_list_Array: " + aole_white_list_Array + "=" + setting_phones);
|
||||||
|
|
||||||
|
// int setting_memory = changeNum(settings.getSetting_memory());
|
||||||
|
// boolean aole_sdcard_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, setting_memory);
|
||||||
|
// Log.e("SystemSetting", "aole_sdcard_forbid_on: " + setting_memory);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPhoneList(int state) {
|
||||||
|
try {
|
||||||
|
//设置电话功能,电话白名单
|
||||||
|
// boolean qch_call_forbid = Settings.System.putInt(mResolver, "qch_call_forbid", state);
|
||||||
|
// Log.e(TAG, "qch_call_forbid:" + qch_call_forbid);
|
||||||
|
|
||||||
|
// boolean aole_white_list_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_WHITE_LIST_ON, state);
|
||||||
|
// Log.e(TAG, "aole_white_list_on:" + aole_white_list_on);
|
||||||
|
|
||||||
|
// boolean aole_white_list_Array = Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_WHITE_LIST_ARRAY, "");
|
||||||
|
// ToastTool.show("qch_call_forbid::"+setting_call+"----setting_phones::"+setting_phones+"----"+aole_white_list_Array+"---"+qch_call_forbid);
|
||||||
|
// Log.e(TAG, "aole_white_list_Array:" + aole_white_list_Array + "---" + aole_white_list_Array);
|
||||||
|
|
||||||
|
// boolean aole_sdcard_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, state);
|
||||||
|
// Log.e(TAG, "aole_sdcard_forbid_on:" + aole_sdcard_forbid_on);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setPhoneList: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setBluetooth(SystemSettings settings) {
|
||||||
|
try {
|
||||||
|
//蓝牙开关
|
||||||
|
// int setting_bht = changeNum(settings.getSetting_bht());
|
||||||
|
//总开关
|
||||||
|
// int setting_bhtvideo = changeNum(settings.getSetting_bhtvideo());
|
||||||
|
//蓝牙音频开关
|
||||||
|
// int setting_bluetooth = changeNum(settings.getSetting_bluetooth());
|
||||||
|
//蓝牙传输开关
|
||||||
|
// boolean aole_bht_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_BHT_FORBID_ON, setting_bht);
|
||||||
|
//写入系统数据库
|
||||||
|
// Log.e("SystemSetting", "aole_bht_forbid_on:" + aole_bht_forbid_on);
|
||||||
|
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
// if (aole_bht_forbid_on) {
|
||||||
|
// //成功
|
||||||
|
// if (null == mBluetoothAdapter) {
|
||||||
|
// mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
// //获取默认蓝牙适配器
|
||||||
|
// }
|
||||||
|
// if (setting_bht == 0) {
|
||||||
|
// //蓝牙总开关开启
|
||||||
|
// String setting_context = settings.getSetting_context();
|
||||||
|
// if (setting_bhtvideo == 0) {
|
||||||
|
// if (null != setting_context && !"".equals(setting_context) && !" ".equals(setting_context) && !"null".equals(setting_context)) {
|
||||||
|
// Log.e("SystemSetting", "setting_context:" + setting_context);
|
||||||
|
//// Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, setting_context);
|
||||||
|
// } else {
|
||||||
|
//// Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty");
|
||||||
|
// }
|
||||||
|
// } else if (setting_bhtvideo == 1) {
|
||||||
|
//// Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty");
|
||||||
|
// }
|
||||||
|
//// Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_BT_FORBID_ON, setting_bluetooth);
|
||||||
|
// } else {
|
||||||
|
// mBluetoothAdapter.disable();
|
||||||
|
// //设置关闭时关闭蓝牙
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setBluetooth: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setBluetooth(int state) {
|
||||||
|
try {
|
||||||
|
// boolean aole_bht_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_BHT_FORBID_ON, state);
|
||||||
|
//写入系统数据库
|
||||||
|
// Log.e(TAG, "aole_bht_forbid_on:" + aole_bht_forbid_on);
|
||||||
|
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
// if (aole_bht_forbid_on) {
|
||||||
|
// //成功
|
||||||
|
// if (null == mBluetoothAdapter) {
|
||||||
|
// mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
// //获取默认蓝牙适配器
|
||||||
|
// }
|
||||||
|
// //蓝牙总开关开启
|
||||||
|
//// Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty");
|
||||||
|
//// Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_BT_FORBID_ON, state);
|
||||||
|
// mBluetoothAdapter.disable();
|
||||||
|
// //设置关闭时关闭蓝牙
|
||||||
|
// }
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setBluetooth: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setHotspot(SystemSettings settings) {
|
||||||
|
try {
|
||||||
|
// int setting_hotspot = changeNum(settings.getSetting_hotspot());//热点
|
||||||
|
// if (setting_hotspot == 1) {
|
||||||
|
// Intent intent = new Intent();
|
||||||
|
// intent.setAction("qch_hotspot_close");
|
||||||
|
// intent.setPackage("com.android.settings");
|
||||||
|
// mContext.sendStickyBroadcast(intent);
|
||||||
|
// }
|
||||||
|
// boolean aole_hotspot_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_HOTSPOT_FORBID_ON, setting_hotspot);//写入系统数据库
|
||||||
|
// Log.e("SystemSetting", "aole_hotspot_forbid_on:" + setting_hotspot);
|
||||||
|
// Log.e("SystemSetting", "aole_hotspot_forbid_on:" + aole_hotspot_forbid_on);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setHotspot: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setHotspot(int state) {
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setAction("qch_hotspot_close");
|
||||||
|
intent.setPackage("com.android.settings");
|
||||||
|
mContext.sendStickyBroadcast(intent);
|
||||||
|
// boolean aole_hotspot_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_HOTSPOT_FORBID_ON, state);
|
||||||
|
// Log.e(TAG, "aole_hotspot_forbid_on:" + aole_hotspot_forbid_on);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setHotspot: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setBar(SystemSettings settings) {
|
||||||
|
//系统导航条显示开关
|
||||||
|
int setting_navigation = settings.getSetting_navigation();
|
||||||
|
Log.e(TAG, "setBar: setting_navigation = " + setting_navigation);
|
||||||
|
|
||||||
|
//状态栏显示开关
|
||||||
|
int setting_statusbar = settings.getSetting_statusbar();
|
||||||
|
Log.e(TAG, "setBar: setting_statusbar = " + setting_statusbar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private void setCamera(SystemSettings settings) {
|
||||||
|
try {
|
||||||
|
//摄像头开关
|
||||||
|
int setting_camera = (settings.getSetting_camera());
|
||||||
|
// Settings.System.putInt(mResolver, "qch_app_camera", setting_camera);
|
||||||
|
// ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.camera");
|
||||||
|
Log.e("SystemSetting", "setting_camera:" + setting_camera);
|
||||||
|
String cameraStatus = "";
|
||||||
|
switch (setting_camera) {
|
||||||
|
case 0:
|
||||||
|
cameraStatus = "qch_camera_open";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
cameraStatus = "qch_camera_forbid";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setCamera: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private void setCamera(int state) {
|
||||||
|
try {
|
||||||
|
//摄像头开关
|
||||||
|
// boolean qch_app_camera = Settings.System.putInt(mResolver, "qch_app_camera", state);
|
||||||
|
Log.e(TAG, "qch_app_camera1:" + state);
|
||||||
|
// ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.camera");
|
||||||
|
// Log.e(TAG, "setting_camera---------" + qch_app_camera);
|
||||||
|
String cameraStatus = "qch_camera_forbid";
|
||||||
|
switch (state) {
|
||||||
|
case 0:
|
||||||
|
cameraStatus = "qch_camera_open";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
cameraStatus = "qch_camera_forbid";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings");
|
||||||
|
mContext.sendBroadcast(cameraIntent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setCamera: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
private void setTF(SystemSettings settings) {
|
||||||
|
//tfmedia开关
|
||||||
|
int setting_tfmedia = (settings.getSetting_tfmedia());
|
||||||
|
// boolean qch_tfmedia_forbid = Settings.System.putInt(mResolver, "qch_tfmedia_forbid", setting_tfmedia);
|
||||||
|
// Log.e("SystemSetting", "setting_tfmedia:" + qch_tfmedia_forbid);
|
||||||
|
String tfmediaStatus = "";
|
||||||
|
switch (setting_tfmedia) {
|
||||||
|
case 0:
|
||||||
|
tfmediaStatus = "qch_tfmedia_open";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
tfmediaStatus = "qch_tfmedia_forbid";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Intent tfmediaIntent = new Intent(tfmediaStatus).setPackage("com.android.settings");
|
||||||
|
mContext.sendBroadcast(tfmediaIntent);
|
||||||
|
if (setting_tfmedia == 1) {
|
||||||
|
String qch_tfmedia_filetypes = settings.getSetting_tfmedia_format();
|
||||||
|
if (TextUtils.isEmpty(qch_tfmedia_filetypes)) {
|
||||||
|
// Settings.System.putString(mResolver, "qch_tfmedia_filetypes", "");//影音管控
|
||||||
|
} else {
|
||||||
|
HashSet<String> types = new HashSet<>(Arrays.asList(qch_tfmedia_filetypes.split(",")));
|
||||||
|
types.removeIf(new Predicate<String>() {
|
||||||
|
@Override
|
||||||
|
public boolean test(String s) {
|
||||||
|
return TextUtils.isEmpty(s);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
String typesString = String.join(",", types);
|
||||||
|
// Settings.System.putString(mResolver, "qch_tfmedia_filetypes", typesString);//影音管控
|
||||||
|
Log.e("SystemSetting", "qch_tfmedia_filetypes :" + typesString);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Settings.System.putInt(mResolver, "qch_tfmedia_forbid", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTF(int state) {
|
||||||
|
try {
|
||||||
|
//tfmedia开关
|
||||||
|
// int setting_tfmedia = 1;
|
||||||
|
// boolean qch_tfmedia_forbid = Settings.System.putInt(mResolver, "qch_tfmedia_forbid", state);
|
||||||
|
// Log.e(TAG, "setting_tfmedia---------" + qch_tfmedia_forbid);
|
||||||
|
String tfmediaStatus = "";
|
||||||
|
switch (state) {
|
||||||
|
case 0:
|
||||||
|
tfmediaStatus = "qch_tfmedia_open";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
tfmediaStatus = "qch_tfmedia_forbid";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Intent tfmediaIntent = new Intent(tfmediaStatus).setPackage("com.android.settings");
|
||||||
|
mContext.sendBroadcast(tfmediaIntent);
|
||||||
|
if (state == 1) {
|
||||||
|
// boolean qch_tfmedia_filetypes = Settings.System.putString(mResolver, "qch_tfmedia_filetypes", "Empty");//影音管控
|
||||||
|
// Log.e(TAG, "qch_tfmedia_filetypes:" + qch_tfmedia_filetypes);
|
||||||
|
} else {
|
||||||
|
// Settings.System.putInt(mResolver, "qch_tfmedia_forbid", 0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setTF: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private void setIcon(SystemSettings settings) {
|
||||||
|
try {
|
||||||
|
int deskclock = (settings.getSetting_clock());
|
||||||
|
Log.e("SystemSetting", "qch_app_deskclock:" + deskclock);
|
||||||
|
//录音机
|
||||||
|
int soundrecorder = (settings.getSetting_recording());
|
||||||
|
Log.e("SystemSetting", "qch_app_soundrecorder:" + soundrecorder);
|
||||||
|
//音乐
|
||||||
|
int music = (settings.getSetting_music());
|
||||||
|
Log.e("SystemSetting", "qch_app_music:" + music);
|
||||||
|
//图库
|
||||||
|
int gallery = (settings.getSetting_picture());
|
||||||
|
Log.e("SystemSetting", "qch_app_gallery:" + gallery);
|
||||||
|
//壁纸
|
||||||
|
int wallpaper = (settings.getSetting_wallpaper());
|
||||||
|
Log.e("SystemSetting", "qch_app_wallpaper:" + wallpaper);
|
||||||
|
//文件管理器
|
||||||
|
int filemanager = (settings.getSetting_file());
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||||
|
// ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.filemanager");
|
||||||
|
} else {
|
||||||
|
// ApkUtils.hideSystemSettingAPP(mContext, "com.android.documentsui");
|
||||||
|
}
|
||||||
|
Log.e("SystemSetting", "qch_app_filemanager:" + filemanager);
|
||||||
|
//浏览器
|
||||||
|
int browser = (settings.getSetting_browser());
|
||||||
|
Log.e(TAG, "qch_app_browser" + browser);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setIcon: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private void setIcon(int state) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
//时钟
|
||||||
|
// int deskclock = 1;
|
||||||
|
// ApkUtils.hideSystemSettingAPP(mContext, "com.android.deskclock");
|
||||||
|
Log.e(TAG, "qch_app_deskclock" + state);
|
||||||
|
//录音机
|
||||||
|
// int soundrecorder = 1;
|
||||||
|
// ApkUtils.hideSystemSettingAPP(mContext, "com.android.soundrecorder");
|
||||||
|
Log.e(TAG, "qch_app_soundrecorder" + state);
|
||||||
|
//音乐
|
||||||
|
// int music = 1;
|
||||||
|
// ApkUtils.hideSystemSettingAPP(mContext, "com.android.music");
|
||||||
|
Log.e(TAG, "qch_app_music" + state);
|
||||||
|
//图库
|
||||||
|
// int gallery = 1;
|
||||||
|
// ApkUtils.hideSystemSettingAPP(mContext, "com.android.gallery3d");
|
||||||
|
Log.e(TAG, "qch_app_gallery" + state);
|
||||||
|
//文件管理器
|
||||||
|
// int filemanager = 1;
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||||
|
// ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.filemanager");
|
||||||
|
} else {
|
||||||
|
// ApkUtils.hideSystemSettingAPP(mContext, "com.android.documentsui");
|
||||||
|
}
|
||||||
|
Log.e(TAG, "qch_app_filemanager" + state);
|
||||||
|
//浏览器
|
||||||
|
Log.e(TAG, "qch_app_browser" + state);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setIcon: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setWallpaper(int state) {
|
||||||
|
//壁纸
|
||||||
|
// int wallpaper = 1;
|
||||||
|
// Settings.System.putInt(mResolver, "qch_app_wallpaper", state);
|
||||||
|
Log.e(TAG, "qch_app_wallpaper" + state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCanReset(SystemSettings settings) {
|
||||||
|
int qch_restore = settings.getQch_restore();
|
||||||
|
Log.e(TAG, "setCanReset: qch_restore = " + qch_restore);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCanReset(int state) {
|
||||||
|
Log.e(TAG, "setCanReset: state = " + state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 置浏览器禁止输入,默认打开
|
||||||
|
*
|
||||||
|
* @param state
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
private void setBrowserInput(int state) {
|
||||||
|
// Settings.System.putInt(mResolver, "qch_Browser_input", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private void setBrowserInput(SystemSettings systemSettings) {
|
||||||
|
int setting_browserInput = (systemSettings.getSetting_browserInput());
|
||||||
|
// Settings.System.putInt(mResolver, "qch_Browser_input", setting_browserInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeveloperOptions(SystemSettings systemSettings) {
|
||||||
|
int dev_mode = systemSettings.getDev_mode();
|
||||||
|
Log.e(TAG, "setDeveloperOptions: " + dev_mode);
|
||||||
|
if (!isDebugMode()) {
|
||||||
|
setDeveloperMode(dev_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeveloperOptions(String jsonString) {
|
||||||
|
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
|
||||||
|
int dev_mode = (jsonObject.get("dev_mode").getAsInt());
|
||||||
|
Log.e(TAG, "setDeveloperOptions: " + dev_mode);
|
||||||
|
if (!isDebugMode()) {
|
||||||
|
// Settings.System.putInt(mResolver, "qch_Developeroptions", dev_mode);
|
||||||
|
int old_dev_enabled = Settings.Global.getInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
|
||||||
|
Log.e(TAG, "setDeveloperOptions: " + old_dev_enabled);
|
||||||
|
int new_state = (dev_mode == 1 ? 0 : 1);
|
||||||
|
if (old_dev_enabled != new_state) {
|
||||||
|
// Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, new_state);
|
||||||
|
// Settings.Global.putInt(mResolver, Settings.Global.ADB_ENABLED, new_state);
|
||||||
|
}
|
||||||
|
// Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, dev_mode);
|
||||||
|
if (dev_mode == 1) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setAction("qch_developeroptions_close");
|
||||||
|
intent.setPackage("com.android.settings");
|
||||||
|
mContext.sendBroadcast(intent);
|
||||||
|
Log.e(TAG, "setDeveloperOptions: " + "关闭开发者模式");
|
||||||
|
Toaster.debugShow("关闭开发者模式");
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "setDeveloperOptions: " + "打开开发者模式");
|
||||||
|
Toaster.debugShow("打开开发者模式");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeveloperOptions(int state) {
|
||||||
|
Log.e(TAG, "setDeveloperOptions: " + state);
|
||||||
|
if (!isDebugMode()) {
|
||||||
|
// Settings.System.putInt(mResolver, "qch_Developeroptions", state);
|
||||||
|
int old_dev_enabled = Settings.Global.getInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
|
||||||
|
Log.e(TAG, "setDeveloperOptions: " + old_dev_enabled);
|
||||||
|
int new_state = (state == 1 ? 0 : 1);
|
||||||
|
if (old_dev_enabled != new_state) {
|
||||||
|
// Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, new_state);
|
||||||
|
// Settings.Global.putInt(mResolver, Settings.Global.ADB_ENABLED, new_state);
|
||||||
|
}
|
||||||
|
// Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, state);
|
||||||
|
if (state == 1) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setAction("qch_developeroptions_close");
|
||||||
|
intent.setPackage("com.android.settings");
|
||||||
|
mContext.sendBroadcast(intent);
|
||||||
|
Log.e(TAG, "setDeveloperOptions: " + "关闭开发者模式");
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "setDeveloperOptions: " + "打开开发者模式");
|
||||||
|
// Toaster.show("打开开发者模式");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearchTopic(String jsonString) {
|
||||||
|
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
|
||||||
|
if (jsonObject.get("search_topic") == null) return;
|
||||||
|
int mode = jsonObject.get("search_topic").getAsInt();
|
||||||
|
mMMKV.encode("search_topic", mode);
|
||||||
|
Log.e(TAG, "setSearchTopic:" + mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearchTopic(int state) {
|
||||||
|
mMMKV.encode("search_topic", state);
|
||||||
|
Log.e(TAG, "setSearchTopic:" + state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开机管控usb
|
||||||
|
*/
|
||||||
|
public void setDefaultUSBstate() {
|
||||||
|
//USB数据功能管控
|
||||||
|
//仅充电:usb_charge
|
||||||
|
//MTP模式:usb_mtp
|
||||||
|
//Midi模式:usb_midi
|
||||||
|
String setting_usb = Settings.System.getString(mResolver, "qch_usb_choose");
|
||||||
|
Log.e("SystemSetting", "setting_usb:" + setting_usb);
|
||||||
|
String usbStatus = "";
|
||||||
|
if (TextUtils.isEmpty(setting_usb)) {
|
||||||
|
usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE;
|
||||||
|
} else {
|
||||||
|
if (!isDebugMode()) {
|
||||||
|
switch (setting_usb) {
|
||||||
|
case "usb_charge":
|
||||||
|
usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE;
|
||||||
|
break;
|
||||||
|
case "usb_mtp":
|
||||||
|
usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MTP;
|
||||||
|
break;
|
||||||
|
// case "usb_midi":
|
||||||
|
// usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MIDI;
|
||||||
|
// break;
|
||||||
|
default:
|
||||||
|
usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings");
|
||||||
|
mContext.sendBroadcast(usbIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private void setSOSNumber(SystemSettings settings) {
|
||||||
|
String setting_sos = settings.getSetting_sos();
|
||||||
|
Log.e(TAG, "setSOSNumber: setting_sos = " + setting_sos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private void setAppstoreAdmin(SystemSettings settings) {
|
||||||
|
int setting_admin_app = settings.getSetting_admin_app();
|
||||||
|
mMMKV.encode(CommonConfig.APP_ADMIN, setting_admin_app);
|
||||||
|
int isReturnAndroid = settings.getIs_return_android();
|
||||||
|
mMMKV.encode(CommonConfig.UIUI_RETURN_ANDROID_KEY, isReturnAndroid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSetting(SystemSettings settings) {
|
||||||
|
String setting_volume = settings.getSetting_volume();
|
||||||
|
String setting_luminance = settings.getSetting_luminance();
|
||||||
|
String setting_typeface = settings.getSetting_typeface();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setScreenShared(SystemSettings settings) {
|
||||||
|
int projection_screen = settings.getProjection_screen();
|
||||||
|
setScreenShared(projection_screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setScreenShared(int state) {
|
||||||
|
// Settings.System.putInt(mResolver, "projection_screen", state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setHotPoint(SystemSettings settings) {
|
||||||
|
int hot_point = settings.getHot_point();
|
||||||
|
setScreenShared(hot_point);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setHotPoint(int state) {
|
||||||
|
// Settings.System.putInt(mResolver, "hot_point", state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDefaultApp(SystemSettings settings) {
|
||||||
|
String desktop_app = settings.getDesktop_app();
|
||||||
|
Log.e(TAG, "setDefaultApp: desktop_app = " + desktop_app);
|
||||||
|
if (!TextUtils.isEmpty(desktop_app)) {
|
||||||
|
mMMKV.encode(CommonConfig.DESKTOP_APP_KEY, desktop_app);
|
||||||
|
} else {
|
||||||
|
mMMKV.encode(CommonConfig.DESKTOP_APP_KEY, "");
|
||||||
|
}
|
||||||
|
String browser_app = settings.getBrowser_app();
|
||||||
|
Log.e(TAG, "setDefaultApp: browser_app = " + browser_app);
|
||||||
|
if (!TextUtils.isEmpty(browser_app)) {
|
||||||
|
mMMKV.encode(CommonConfig.BROWSER_APP_KEY, browser_app);
|
||||||
|
} else {
|
||||||
|
mMMKV.encode(CommonConfig.BROWSER_APP_KEY, "");
|
||||||
|
}
|
||||||
|
String typewriting_app = settings.getTypewriting_app();
|
||||||
|
Log.e(TAG, "setDefaultApp: typewriting_app = " + typewriting_app);
|
||||||
|
if (!TextUtils.isEmpty(typewriting_app)) {
|
||||||
|
mMMKV.encode(CommonConfig.TYPEWRITING_APP_KEY, typewriting_app);
|
||||||
|
} else {
|
||||||
|
mMMKV.encode(CommonConfig.TYPEWRITING_APP_KEY, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用安装之后重新设置
|
||||||
|
*/
|
||||||
|
public void setDefaultApp() {
|
||||||
|
String desktop_app = mMMKV.decodeString(CommonConfig.DESKTOP_APP_KEY, "");
|
||||||
|
Log.e(TAG, "setDefaultApp: desktop_app = " + desktop_app);
|
||||||
|
if (!TextUtils.isEmpty(desktop_app)) {
|
||||||
|
}
|
||||||
|
String browser_app = mMMKV.decodeString(CommonConfig.BROWSER_APP_KEY, "");
|
||||||
|
Log.e(TAG, "setDefaultApp: browser_app = " + browser_app);
|
||||||
|
if (!TextUtils.isEmpty(browser_app)) {
|
||||||
|
}
|
||||||
|
String typewriting_app = mMMKV.decodeString(CommonConfig.TYPEWRITING_APP_KEY, "");
|
||||||
|
Log.e(TAG, "setDefaultApp: typewriting_app = " + typewriting_app);
|
||||||
|
if (!TextUtils.isEmpty(typewriting_app)) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setIsControl(SystemSettings settings) {
|
||||||
|
int is_control = settings.getIs_control();
|
||||||
|
setIsControl(is_control);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setIsControl(int state) {
|
||||||
|
// Settings.System.putInt(mResolver, CommonConfig.KEY_IS_CONTROL, state);
|
||||||
|
//关闭
|
||||||
|
if (state == 0) {
|
||||||
|
// setBluetooth(0);
|
||||||
|
// setHotspot(0);
|
||||||
|
setUSBstate(CommonConfig.AOLE_ACTION_USB_USB_MTP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private void setOtherAppInstaller(SystemSettings settings) {
|
||||||
|
int is_storeinstall = settings.getIs_storeinstall();
|
||||||
|
mMMKV.encode(CommonConfig.APP_STORE_INSTALL, is_storeinstall);
|
||||||
|
int setting_other_appInstaller = settings.getSetting_other_appInstaller();
|
||||||
|
mMMKV.encode(CommonConfig.APP_INSTALLATION, setting_other_appInstaller);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void setOtherAppInstaller(int status) {
|
||||||
|
mMMKV.encode(CommonConfig.APP_STORE_INSTALL, status);
|
||||||
|
mMMKV.encode(CommonConfig.APP_INSTALLATION, status);
|
||||||
|
mMMKV.encode(CommonConfig.AOLE_APP_ALLOW_INSTALL, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static final String QUICK_APP_KEY = "QuickAppPackageKey";
|
||||||
|
public static final String QUICK_APP_REFRESH_KEY = "QuickAppRefreshKey";
|
||||||
|
public static final String QUICK_APP_ENABLED_KEY = "QuickAppEnabledKey";
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private void setQuickApp(SystemSettings settings) {
|
||||||
|
if (settings.getIs_quickapp() == 1) {
|
||||||
|
String pkg = settings.getQuickapp();
|
||||||
|
// Settings.Global.putString(mContext.getContentResolver(), QUICK_APP_KEY, pkg);
|
||||||
|
// Settings.Global.putInt(mContext.getContentResolver(), QUICK_APP_ENABLED_KEY, 1);
|
||||||
|
} else {
|
||||||
|
// Settings.Global.putInt(mContext.getContentResolver(), QUICK_APP_ENABLED_KEY, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTimeControl(SystemSettings settings) {
|
||||||
|
int is_timecontrol = settings.getIs_timecontrol();
|
||||||
|
mMMKV.encode(TimeUtils.AOLELEARN_TIME_CONTROL_KEY, is_timecontrol);
|
||||||
|
|
||||||
|
// String timecontrol_start = settings.getTimecontrol_start();
|
||||||
|
// mMMKV.encode(TimeUtils.AOLELEARN_TTIMECONTROL_START_KEY, timecontrol_start);
|
||||||
|
// String timecontrol_end = settings.getTimecontrol_start();
|
||||||
|
// mMMKV.encode(TimeUtils.AOLELEARN_TTIMECONTROL_END_KEY, timecontrol_end);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTimeControlClose() {
|
||||||
|
mMMKV.encode(TimeUtils.AOLELEARN_TIME_CONTROL_KEY, 0);
|
||||||
|
// mMMKV.encode(TimeUtils.AOLELEARN_TTIMECONTROL_START_KEY, "");
|
||||||
|
// mMMKV.encode(TimeUtils.AOLELEARN_TTIMECONTROL_END_KEY, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setZhuangyuanSetting(SystemSettings setting) {
|
||||||
|
setBluetoothShare((setting.getIs_bluetooth_share()));
|
||||||
|
setDeveloperMode((setting.getIs_developer_mode()));
|
||||||
|
setDeviceRecover((setting.getIs_device_recover()));
|
||||||
|
setTopNotify(setting.getIs_top_notify());
|
||||||
|
setBottomBar(setting.getIs_bottom_bar());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBluetoothShare(int status) {
|
||||||
|
Log.e(TAG, "setBluetoothShare: " + status);
|
||||||
|
// AdminManager.getInstance().setBluetoothDataTransferDisable(status == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeveloperMode(int status) {
|
||||||
|
Log.e(TAG, "setDeveloperMode: " + status);
|
||||||
|
// AdminManager.getInstance().turnOnUsbDebugMode(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceRecover(int status) {
|
||||||
|
Log.e(TAG, "setDeviceRecover: " + status);
|
||||||
|
// AdminManager.getInstance().setRestoreFactoryDisabled(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTopNotify(int status) {
|
||||||
|
Log.e(TAG, "setTopNotify: " + status);
|
||||||
|
// AdminManager.getInstance().setStatusBarExpandPanelDisabled(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBottomBar(int status) {
|
||||||
|
Log.e(TAG, "setBottomBar: " + status);
|
||||||
|
// AdminManager.getInstance().setNavigationBarDisabled(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisallowedRunningApp(SystemSettings setting) {
|
||||||
|
if (setting.getAi_teacher() == 0) {
|
||||||
|
OpenApkUtils.getInstance().addDisallowedRunningApp("com.jxw.aijtjs");
|
||||||
|
} else {
|
||||||
|
OpenApkUtils.getInstance().removeDisallowedRunningApp("com.jxw.aijtjs");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setting.getPhoto_search_questions() == 0) {
|
||||||
|
OpenApkUtils.getInstance().addDisallowedRunningApp("com.jxw.souti");
|
||||||
|
} else {
|
||||||
|
OpenApkUtils.getInstance().removeDisallowedRunningApp("com.jxw.souti");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setting.getAi_question_test() == 0) {
|
||||||
|
OpenApkUtils.getInstance().addDisallowedRunningApp("com.jxw.aizndy");
|
||||||
|
} else {
|
||||||
|
OpenApkUtils.getInstance().removeDisallowedRunningApp("com.jxw.aizndy");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisallowedRunningApp() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,12 +4,17 @@ import android.annotation.SuppressLint;
|
|||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import com.xwad.os.activity.home.HomeActivity;
|
import com.xwad.os.activity.home.HomeActivity;
|
||||||
import com.xwad.os.disklrucache.CacheHelper;
|
import com.xwad.os.disklrucache.CacheHelper;
|
||||||
import com.xwad.os.fragment.user.UserFragment;
|
import com.xwad.os.fragment.user.UserFragment;
|
||||||
|
import com.xwad.os.gson.GsonUtils;
|
||||||
import com.xwad.os.network.NetInterfaceManager;
|
import com.xwad.os.network.NetInterfaceManager;
|
||||||
import com.hjq.toast.Toaster;
|
import com.hjq.toast.Toaster;
|
||||||
|
import com.xwad.os.utils.OpenApkUtils;
|
||||||
|
|
||||||
public class PushManager {
|
public class PushManager {
|
||||||
private static final String TAG = "PushManager";
|
private static final String TAG = "PushManager";
|
||||||
@@ -56,6 +61,13 @@ public class PushManager {
|
|||||||
/*爱的鼓励*/
|
/*爱的鼓励*/
|
||||||
private static final String LOVE_ENCOURAGEMENT = "121";
|
private static final String LOVE_ENCOURAGEMENT = "121";
|
||||||
|
|
||||||
|
/*AI家庭教师开关*/
|
||||||
|
private static final String AI_Tutor = "123";
|
||||||
|
/*拍照搜题*/
|
||||||
|
private static final String PHOTO_SEARCH_QUESTIONS = "124";
|
||||||
|
/*AI答疑测试*/
|
||||||
|
private static final String AI_QA_TEST = "125";
|
||||||
|
|
||||||
|
|
||||||
public void setPushContent(String title, String extras) {
|
public void setPushContent(String title, String extras) {
|
||||||
switch (title) {
|
switch (title) {
|
||||||
@@ -76,10 +88,65 @@ public class PushManager {
|
|||||||
case LOVE_ENCOURAGEMENT:
|
case LOVE_ENCOURAGEMENT:
|
||||||
Toaster.debugShow("收到推送消息: 爱的鼓励");
|
Toaster.debugShow("收到推送消息: 爱的鼓励");
|
||||||
sendEncouragement(extras);
|
sendEncouragement(extras);
|
||||||
|
break;
|
||||||
|
case AI_Tutor:
|
||||||
|
setAiTeacher(extras);
|
||||||
|
break;
|
||||||
|
case PHOTO_SEARCH_QUESTIONS:
|
||||||
|
setPhotoSearchQuestions(extras);
|
||||||
|
break;
|
||||||
|
case AI_QA_TEST:
|
||||||
|
setAiQuestionTest(extras);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setAiTeacher(String extras) {
|
||||||
|
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
|
||||||
|
JsonElement jsonElement = jsonObject.get("ai_teacher");
|
||||||
|
if (jsonElement == null || jsonElement.isJsonNull()) {
|
||||||
|
Log.e(TAG, "setAiTeacher: jsonElement is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int ai_teacher = jsonElement.getAsInt();
|
||||||
|
if (ai_teacher == 0) {
|
||||||
|
OpenApkUtils.getInstance().addDisallowedRunningApp("com.jxw.aijtjs");
|
||||||
|
} else {
|
||||||
|
OpenApkUtils.getInstance().removeDisallowedRunningApp("com.jxw.aijtjs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPhotoSearchQuestions(String extras) {
|
||||||
|
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
|
||||||
|
JsonElement jsonElement = jsonObject.get("photo_search_questions");
|
||||||
|
if (jsonElement == null || jsonElement.isJsonNull()) {
|
||||||
|
Log.e(TAG, "setPhotoSearchQuestions: jsonElement is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int photo_search_questions = jsonElement.getAsInt();
|
||||||
|
if (photo_search_questions == 0) {
|
||||||
|
OpenApkUtils.getInstance().addDisallowedRunningApp("com.jxw.souti");
|
||||||
|
} else {
|
||||||
|
OpenApkUtils.getInstance().removeDisallowedRunningApp("com.jxw.souti");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setAiQuestionTest(String extras) {
|
||||||
|
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
|
||||||
|
JsonElement jsonElement = jsonObject.get("ai_question_test");
|
||||||
|
if (jsonElement == null || jsonElement.isJsonNull()) {
|
||||||
|
Log.e(TAG, "setAiQuestionTest: jsonElement is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int ai_question_test = jsonElement.getAsInt();
|
||||||
|
if (ai_question_test == 0) {
|
||||||
|
OpenApkUtils.getInstance().addDisallowedRunningApp("com.jxw.aizndy");
|
||||||
|
} else {
|
||||||
|
OpenApkUtils.getInstance().removeDisallowedRunningApp("com.jxw.aizndy");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void startHome() {
|
private void startHome() {
|
||||||
Intent intent = new Intent(mContext, HomeActivity.class);
|
Intent intent = new Intent(mContext, HomeActivity.class);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.hjq.toast.Toaster;
|
import com.hjq.toast.Toaster;
|
||||||
import com.tencent.mmkv.MMKV;
|
import com.tencent.mmkv.MMKV;
|
||||||
import com.xwad.os.BuildConfig;
|
|
||||||
import com.xwad.os.R;
|
import com.xwad.os.R;
|
||||||
import com.xwad.os.activity.activation.ActivationActivity;
|
import com.xwad.os.activity.activation.ActivationActivity;
|
||||||
import com.xwad.os.activity.login.LoginActivity;
|
import com.xwad.os.activity.login.LoginActivity;
|
||||||
@@ -65,12 +64,15 @@ public class OpenApkUtils {
|
|||||||
private LessonJson mLessonJson;
|
private LessonJson mLessonJson;
|
||||||
private TimeUtils.ContralTime mContralTime;
|
private TimeUtils.ContralTime mContralTime;
|
||||||
|
|
||||||
|
private Set<String> mDisallowedRunningAppSet;
|
||||||
|
|
||||||
private OpenApkUtils(Context context) {
|
private OpenApkUtils(Context context) {
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
throw new RuntimeException("Context is NULL");
|
throw new RuntimeException("Context is NULL");
|
||||||
}
|
}
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
this.mResolver = context.getContentResolver();
|
this.mResolver = context.getContentResolver();
|
||||||
|
mDisallowedRunningAppSet = mMMKV.decodeStringSet(CommonConfig.DISALLOWED_RUNNING_APP_KEY, new HashSet<>());
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +89,31 @@ public class OpenApkUtils {
|
|||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<String> getDisallowedRunningAppSet() {
|
||||||
|
if (mDisallowedRunningAppSet == null) {
|
||||||
|
mDisallowedRunningAppSet = new HashSet<>();
|
||||||
|
}
|
||||||
|
return mDisallowedRunningAppSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDisallowedRunningApp(String pkg) {
|
||||||
|
Log.e(TAG, "addDisallowedRunningApp: " + pkg);
|
||||||
|
if (mDisallowedRunningAppSet == null) {
|
||||||
|
mDisallowedRunningAppSet = new HashSet<>();
|
||||||
|
}
|
||||||
|
mDisallowedRunningAppSet.add(pkg);
|
||||||
|
mMMKV.encode(CommonConfig.DISALLOWED_RUNNING_APP_KEY, mDisallowedRunningAppSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeDisallowedRunningApp(String pkg) {
|
||||||
|
Log.e(TAG, "removeDisallowedRunningApp: " + pkg);
|
||||||
|
if (mDisallowedRunningAppSet == null) {
|
||||||
|
mDisallowedRunningAppSet = new HashSet<>();
|
||||||
|
}
|
||||||
|
mDisallowedRunningAppSet.remove(pkg);
|
||||||
|
mMMKV.encode(CommonConfig.DISALLOWED_RUNNING_APP_KEY, mDisallowedRunningAppSet);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean checkActivation() {
|
private boolean checkActivation() {
|
||||||
if (!ApkUtils.isAvailable(mContext, "com.uiui.zy")) {
|
if (!ApkUtils.isAvailable(mContext, "com.uiui.zy")) {
|
||||||
return true;
|
return true;
|
||||||
@@ -716,6 +743,13 @@ public class OpenApkUtils {
|
|||||||
Log.d(TAG, "包名:" + packageName + "\n类名:" + className
|
Log.d(TAG, "包名:" + packageName + "\n类名:" + className
|
||||||
+ "\n第四项:" + fourthParam + "\n应用名:" + appName);
|
+ "\n第四项:" + fourthParam + "\n应用名:" + appName);
|
||||||
|
|
||||||
|
Log.e(TAG, "openJxwApp: " + getDisallowedRunningAppSet());
|
||||||
|
|
||||||
|
if (mDisallowedRunningAppSet.contains(packageName)) {
|
||||||
|
Toaster.show("应用已禁止打开");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ApkUtils.isAvailable(mContext, packageName)) {
|
if (!ApkUtils.isAvailable(mContext, packageName)) {
|
||||||
showDownloadDialog(activity, packageName, appName);
|
showDownloadDialog(activity, packageName, appName);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,44 +1,85 @@
|
|||||||
package com.xwad.os.utils;
|
package com.xwad.os.utils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.tencent.mmkv.MMKV;
|
||||||
|
import com.xwad.os.bean.TimeControl;
|
||||||
|
import com.xwad.os.config.CommonConfig;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TimeUtils {
|
public class TimeUtils {
|
||||||
private static final String TAG = "TimeUtils";
|
private static final String TAG = "TimeUtils";
|
||||||
|
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||||
|
|
||||||
private static DateFormat df = new SimpleDateFormat("HH:mm", Locale.getDefault());
|
private static DateFormat df = new SimpleDateFormat("HH:mm", Locale.CHINA);
|
||||||
|
|
||||||
public static final long DAY_TIME = 60 * 60 * 24 * 1000;
|
public static final long DAY_TIME = 60 * 60 * 24 * 1000;
|
||||||
public static final long MINUTE_TIME = 60 * 1000;
|
public static final long MINUTE_TIME = 60 * 1000;
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
public static final String START_TIME_KEY = "START_TIME";
|
||||||
public static boolean isTodayTime(long timeStamp) {
|
public static final String END_TIME_KEY = "END_TIME";
|
||||||
String time = transferLongToDate(timeStamp);
|
public static final String WEEK_START_TIME_KEY = "WEEK_START_TIME";
|
||||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
public static final String WEEK_END_TIME_KEY = "WEEK_END_TIME";
|
||||||
LocalDateTime localTime = LocalDateTime.parse(time, dtf);
|
|
||||||
LocalDateTime startTime = LocalDate.now().atTime(0, 0, 0);
|
/*新增 时间控制开关*/
|
||||||
LocalDateTime endTime = LocalDate.now().atTime(23, 59, 59);
|
public static final String AOLELEARN_TIME_CONTROL_KEY = "aolelearn_time_control";
|
||||||
return localTime.isAfter(startTime) && localTime.isBefore(endTime);
|
/*多个时间段*/
|
||||||
|
public static final String AOLELEARN_TTIMECONTROL_LIST_KEY = "aolelearn_timecontrol_list";
|
||||||
|
|
||||||
|
/*可以使用时间开始*/
|
||||||
|
@Deprecated
|
||||||
|
public static final String AOLELEARN_TTIMECONTROL_START_KEY = "aolelearn_timecontrol_start";
|
||||||
|
/*可以使用时间结束*/
|
||||||
|
@Deprecated
|
||||||
|
public static final String AOLELEARN_TTIMECONTROL_END_KEY = "aolelearn_timecontrol_end";
|
||||||
|
|
||||||
|
|
||||||
|
public static String getNowTime() {
|
||||||
|
long nowTime = System.currentTimeMillis();
|
||||||
|
DateFormat df = ContralTime.getDf();
|
||||||
|
return df.format(nowTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String transferLongToDate(Long millisecond) {
|
// public static boolean CurrentInTimeScope(ContralTime contralTime) {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
// boolean result = true;
|
||||||
Date date = new Date(millisecond);
|
// final long aDayInMillis = 1000 * 60 * 60 * 24;
|
||||||
|
// long currentTimeMillis = System.currentTimeMillis();
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
public static String transferLongToDate(Long millSec) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||||
|
Date date = new Date(millSec);
|
||||||
return sdf.format(date);
|
return sdf.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +96,28 @@ public class TimeUtils {
|
|||||||
return dateString + "\t" + getWeek();
|
return dateString + "\t" + getWeek();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String transferSecondToDate(long second) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
||||||
|
|
||||||
|
Date date = new Date(second * 1000);
|
||||||
|
return sdf.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String transferSecond(long second) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
||||||
|
Date date = new Date(second * 1000);
|
||||||
|
return sdf.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getPhotoDate() {
|
||||||
|
long millisecond = System.currentTimeMillis();
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||||||
|
Date date = new Date(millisecond);
|
||||||
|
return sdf.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getHomeworkTime(String timeString) {
|
public static String getHomeworkTime(String timeString) {
|
||||||
SimpleDateFormat old = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
SimpleDateFormat old = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
@@ -168,6 +231,244 @@ public class TimeUtils {
|
|||||||
return String.format("%d小时%d分", hour, min);
|
return String.format("%d小时%d分", hour, min);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final long ONE_DAY_TIME_OF_SECOND = 24 * 60 * 60;
|
||||||
|
|
||||||
|
public static long timestampInterval(long nowTime, long expireTime) {
|
||||||
|
long num = expireTime - nowTime;//时间戳相差的毫秒数
|
||||||
|
long day = num / ONE_DAY_TIME_OF_SECOND;
|
||||||
|
return day;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
|
public static boolean isTodayTime(long timeStamp) {
|
||||||
|
String time = transferLongToDate(timeStamp);
|
||||||
|
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
LocalDateTime localTime = LocalDateTime.parse(time, dtf);
|
||||||
|
LocalDateTime startTime = LocalDate.now().atTime(0, 0, 0);
|
||||||
|
LocalDateTime endTime = LocalDate.now().atTime(23, 59, 59);
|
||||||
|
return localTime.isAfter(startTime) && localTime.isBefore(endTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ContralTime String2WorkingTime(Context context, @NonNull String timeText) {
|
||||||
|
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||||
|
DateFormat df = ContralTime.getDf();
|
||||||
|
String[] time = timeText.trim().split("-");
|
||||||
|
if (time.length != 2) {
|
||||||
|
// return null;
|
||||||
|
throw new RuntimeException("Time format error!" + Arrays.toString(time));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mmkv.encode(START_TIME_KEY, time[0].trim());
|
||||||
|
mmkv.encode(END_TIME_KEY, time[1].trim());
|
||||||
|
Date startDate = df.parse(time[0].trim());
|
||||||
|
Date endDate = df.parse(time[1].trim());
|
||||||
|
ContralTime contralTime = new ContralTime();
|
||||||
|
// if (date1.getTime() < date2.getTime()) {
|
||||||
|
contralTime.setStartTime(df.format(startDate));
|
||||||
|
contralTime.setEndTime(df.format(endDate));
|
||||||
|
// } else {
|
||||||
|
// contralTime.setStartTime(df.format(date2));
|
||||||
|
// contralTime.setEndTime(df.format(date1));
|
||||||
|
// }
|
||||||
|
return contralTime;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param context
|
||||||
|
* @param timeText HH:mm-HH:mm 格式转化为ContralTime
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ContralTime string2WeekTime(Context context, @NonNull String timeText) {
|
||||||
|
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||||
|
DateFormat df = ContralTime.getDf();
|
||||||
|
String[] time = timeText.trim().split("-");
|
||||||
|
if (time.length != 2) {
|
||||||
|
// return null;
|
||||||
|
throw new RuntimeException("Time format error!" + Arrays.toString(time));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mmkv.encode(WEEK_START_TIME_KEY, time[0].trim());
|
||||||
|
mmkv.encode(WEEK_END_TIME_KEY, time[1].trim());
|
||||||
|
Date startDate = df.parse(time[0].trim());
|
||||||
|
Date endDate = df.parse(time[1].trim());
|
||||||
|
ContralTime contralTime = new ContralTime();
|
||||||
|
// if (date1.getTime() < date2.getTime()) {
|
||||||
|
contralTime.setStartTime(df.format(startDate));
|
||||||
|
contralTime.setEndTime(df.format(endDate));
|
||||||
|
// } else {
|
||||||
|
// contralTime.setStartTime(df.format(date2));
|
||||||
|
// contralTime.setEndTime(df.format(date1));
|
||||||
|
// }
|
||||||
|
return contralTime;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取工作日时间控制
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static ContralTime getWorkingDayContralTime(Context context) {
|
||||||
|
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||||
|
String startTime = mmkv.decodeString(START_TIME_KEY, "00:00");
|
||||||
|
String endTime = mmkv.decodeString(END_TIME_KEY, "00:00");
|
||||||
|
return getContralTime(context, startTime, endTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取休息日时间控制
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static ContralTime getWeekDayContralTime(Context context) {
|
||||||
|
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||||
|
String startTime = mmkv.decodeString(WEEK_START_TIME_KEY, "00:00");
|
||||||
|
String endTime = mmkv.decodeString(WEEK_END_TIME_KEY, "00:00");
|
||||||
|
return getContralTime(context, startTime, endTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否在管控时间内
|
||||||
|
*
|
||||||
|
* @param workingTime
|
||||||
|
* @param weekTime
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static boolean inContralTime(ContralTime workingTime, ContralTime weekTime) {
|
||||||
|
if (inWeekDay()) {
|
||||||
|
if (weekTime == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return weekTime.inControlTime();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (workingTime == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return workingTime.inControlTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取新的时间管控
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static ContralTime getDayContralTime(Context context) {
|
||||||
|
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||||
|
String timecontrol_start = mmkv.decodeString(AOLELEARN_TTIMECONTROL_START_KEY, "00:00");
|
||||||
|
String timecontrol_end = mmkv.decodeString(AOLELEARN_TTIMECONTROL_END_KEY, "00:00");
|
||||||
|
return getContralTime(context, timecontrol_start, timecontrol_end);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static boolean inDayContralTime(ContralTime contralTime) {
|
||||||
|
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||||
|
int is_timecontrol = mmkv.decodeInt(TimeUtils.AOLELEARN_TIME_CONTROL_KEY, 0);
|
||||||
|
if (is_timecontrol == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (contralTime == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ("00:00".equals(contralTime.getStartTime()) && "00:00".equals(contralTime.getEndTime())
|
||||||
|
|| "00:00".equals(contralTime.getStartTime()) && "24:00".equals(contralTime.getEndTime())
|
||||||
|
|| "24:00".equals(contralTime.getStartTime()) && "00:00".equals(contralTime.getEndTime())
|
||||||
|
|| Objects.equals(contralTime.getStartTime(), contralTime.getEndTime())
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return contralTime.inControlTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ContralTime> getDayContralTimeList(Context context) {
|
||||||
|
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||||
|
String listJsonString = mmkv.decodeString(AOLELEARN_TTIMECONTROL_LIST_KEY, "");
|
||||||
|
if (!TextUtils.isEmpty(listJsonString)) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
Type listType = new TypeToken<List<TimeControl>>() {
|
||||||
|
}.getType();
|
||||||
|
try {
|
||||||
|
List<TimeControl> timeControls = gson.fromJson(listJsonString, listType);
|
||||||
|
List<ContralTime> contralTimes = timeControls.stream().map(new Function<TimeControl, ContralTime>() {
|
||||||
|
@Override
|
||||||
|
public ContralTime apply(TimeControl timeControl) {
|
||||||
|
return getContralTime(context, timeControl.getStart_time(), timeControl.getEnd_time());
|
||||||
|
}
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return contralTimes;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "getDayContralTimeList: " + e.getMessage());
|
||||||
|
mmkv.remove(AOLELEARN_TTIMECONTROL_LIST_KEY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean inDayContralTime(List<ContralTime> contralTimes) {
|
||||||
|
Log.e(TAG, "inDayContralTime: " + contralTimes);
|
||||||
|
if (contralTimes == null || contralTimes.isEmpty()) {
|
||||||
|
Log.e(TAG, "inDayContralTime: isEmpty");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||||
|
int is_timecontrol = mmkv.decodeInt(TimeUtils.AOLELEARN_TIME_CONTROL_KEY, 0);
|
||||||
|
if (is_timecontrol == 0) {
|
||||||
|
Log.e(TAG, "inDayContralTime: false");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
List<Boolean> booleans = new ArrayList<>();
|
||||||
|
for (ContralTime contralTime : contralTimes) {
|
||||||
|
if (contralTime == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ("00:00".equals(contralTime.getStartTime()) && "00:00".equals(contralTime.getEndTime())
|
||||||
|
|| "00:00".equals(contralTime.getStartTime()) && "24:00".equals(contralTime.getEndTime())
|
||||||
|
|| "24:00".equals(contralTime.getStartTime()) && "00:00".equals(contralTime.getEndTime())
|
||||||
|
|| Objects.equals(contralTime.getStartTime(), contralTime.getEndTime())
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
booleans.add(contralTime.inControlTime());
|
||||||
|
// if (!contralTime.inControlTime()) {
|
||||||
|
// Log.e(TAG, "inDayContralTime: " + contralTime + " true");
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
Log.e(TAG, "inDayContralTime: " + booleans);
|
||||||
|
return !booleans.contains(false);
|
||||||
|
// Log.e(TAG, "inDayContralTime: false");
|
||||||
|
// return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDayTimeString(Context context) {
|
||||||
|
// ContralTime contralTime = getDayContralTime(context);
|
||||||
|
List<ContralTime> contralTimes = TimeUtils.getDayContralTimeList(context);
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
if (contralTimes != null) {
|
||||||
|
for (ContralTime contralTime : contralTimes) {
|
||||||
|
stringBuilder.append(contralTime).append("\t");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否在管控时间内
|
* 是否在管控时间内
|
||||||
*
|
*
|
||||||
@@ -194,7 +495,6 @@ public class TimeUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 根据日期取得星期几
|
* @return 根据日期取得星期几
|
||||||
*/
|
*/
|
||||||
@@ -210,6 +510,141 @@ public class TimeUtils {
|
|||||||
return weeks[weekIndex];
|
return weeks[weekIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取控制时间文本
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static String getNowTimeString(Context context) {
|
||||||
|
ContralTime work = getWorkingDayContralTime(context);
|
||||||
|
ContralTime week = getWeekDayContralTime(context);
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
if (work != null) {
|
||||||
|
stringBuilder.append("周一至周五:").append(work).append("\n");
|
||||||
|
}
|
||||||
|
if (week != null) {
|
||||||
|
stringBuilder.append("周末:").append(week);
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置为空
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
public static void setEmpty(Context context) {
|
||||||
|
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||||
|
mmkv.encode(START_TIME_KEY, "00:00");
|
||||||
|
mmkv.encode(END_TIME_KEY, "00:00");
|
||||||
|
mmkv.encode(WEEK_START_TIME_KEY, "00:00");
|
||||||
|
mmkv.encode(WEEK_END_TIME_KEY, "00:00");
|
||||||
|
|
||||||
|
// Intent intent = new Intent();
|
||||||
|
// intent.setAction(ManagerService.ACTION_UPDATE);
|
||||||
|
// context.sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取格式化后的时间
|
||||||
|
*
|
||||||
|
* @param time 时间戳
|
||||||
|
* @return 时间戳格式化文本
|
||||||
|
*/
|
||||||
|
public static String getDate(long time) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String finaWayDate = sdf.format(time);
|
||||||
|
Log.e(TAG, "getDate: " + finaWayDate);
|
||||||
|
return finaWayDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取周几
|
||||||
|
*
|
||||||
|
* @return 周几的数字
|
||||||
|
*/
|
||||||
|
public static int getWeekDay() {
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
Log.e(TAG, "getWeekDay: " + time);
|
||||||
|
return getWeekDay(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取周几
|
||||||
|
*
|
||||||
|
* @param time 时间戳
|
||||||
|
* @return 周几的数字 1-7
|
||||||
|
*/
|
||||||
|
public static int getWeekDay(long time) {
|
||||||
|
getDate(time);
|
||||||
|
Calendar now = Calendar.getInstance();
|
||||||
|
now.setTimeInMillis(time);
|
||||||
|
//一周第一天是否为星期天
|
||||||
|
boolean isFirstSunday = (now.getFirstDayOfWeek() == Calendar.SUNDAY);
|
||||||
|
//获取周几
|
||||||
|
int weekDay = now.get(Calendar.DAY_OF_WEEK);
|
||||||
|
//若一周第一天为星期天,则-1
|
||||||
|
if (isFirstSunday) {
|
||||||
|
weekDay = weekDay - 1;
|
||||||
|
if (weekDay == 0) {
|
||||||
|
weekDay = 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return weekDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] weekDays = {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取星期几
|
||||||
|
*
|
||||||
|
* @return 星期的文本
|
||||||
|
*/
|
||||||
|
public String getWeekDayString() {
|
||||||
|
return weekDays[getWeekDay() - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取星期几
|
||||||
|
*
|
||||||
|
* @param time 时间戳
|
||||||
|
* @return 星期的文本
|
||||||
|
*/
|
||||||
|
public String getWeekDayString(long time) {
|
||||||
|
return weekDays[getWeekDay(time) - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否未周末
|
||||||
|
*
|
||||||
|
* @return 周末返回ture 工作日返回false
|
||||||
|
*/
|
||||||
|
public static boolean inWeekDay() {
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
return inWeekDay(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否未周末
|
||||||
|
*
|
||||||
|
* @param time 时间戳
|
||||||
|
* @return 周末返回ture 工作日返回false
|
||||||
|
*/
|
||||||
|
public static boolean inWeekDay(long time) {
|
||||||
|
int weekDay = getWeekDay(time);
|
||||||
|
if (weekDay > 5) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSystemTime(long time) {
|
||||||
|
SystemClock.setCurrentTimeMillis(time);
|
||||||
|
}
|
||||||
|
|
||||||
public static class ContralTime {
|
public static class ContralTime {
|
||||||
//format HH:mm
|
//format HH:mm
|
||||||
String startTime;
|
String startTime;
|
||||||
@@ -253,13 +688,16 @@ public class TimeUtils {
|
|||||||
return df.format(new Date(time));
|
return df.format(new Date(time));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean inControlTime() {
|
public boolean inControlTime() {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
return inControlTime(time);
|
return inControlTime(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean inControlTime(long time) {
|
public boolean inControlTime(long time) {
|
||||||
return inControlTime(df.format(new Date(time)));
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
||||||
|
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
||||||
|
return inControlTime(sdf.format(new Date(time)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean inControlTime(String time) {
|
public boolean inControlTime(String time) {
|
||||||
@@ -280,8 +718,7 @@ public class TimeUtils {
|
|||||||
}
|
}
|
||||||
Log.e(TAG, "inControlTime: " + (startDate.getTime() - MINUTE_TIME));
|
Log.e(TAG, "inControlTime: " + (startDate.getTime() - MINUTE_TIME));
|
||||||
assert nowDate != null;
|
assert nowDate != null;
|
||||||
// if (nowDate.getTime() <= startDate.getTime() - MINUTE_TIME || nowDate.getTime() >= endDate.getTime()) {
|
if (nowDate.getTime() <= startDate.getTime() - MINUTE_TIME || nowDate.getTime() >= endDate.getTime()) {
|
||||||
if (nowDate.getTime() >= startDate.getTime() && nowDate.getTime() <= endDate.getTime()) {
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -295,8 +732,221 @@ public class TimeUtils {
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return startTime + "\t-\t" + endTime;
|
return startTime + " - " + endTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static SntpClient mNtpClient;
|
||||||
|
|
||||||
|
public static long getTimeFromNtpServer(String hostAddress) {
|
||||||
|
Log.d(TAG, "getTimeFromNtpServer()");
|
||||||
|
if (TextUtils.isEmpty(hostAddress)) {
|
||||||
|
Log.e(TAG, "Ntp host is null.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (mNtpClient == null) {
|
||||||
|
mNtpClient = new SntpClient();
|
||||||
|
}
|
||||||
|
boolean isSuccessful = mNtpClient.requestTime(hostAddress, 20000);
|
||||||
|
Log.e(TAG, "requestTime:" + isSuccessful);
|
||||||
|
if (isSuccessful) {
|
||||||
|
long now = mNtpClient.getNtpTime();//now就是获取的时间
|
||||||
|
return now;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SntpClient {
|
||||||
|
private static final String TAG = "SntpClient";
|
||||||
|
|
||||||
|
private static final int REFERENCE_TIME_OFFSET = 16;
|
||||||
|
private static final int ORIGINATE_TIME_OFFSET = 24;
|
||||||
|
private static final int RECEIVE_TIME_OFFSET = 32;
|
||||||
|
private static final int TRANSMIT_TIME_OFFSET = 40;
|
||||||
|
private static final int NTP_PACKET_SIZE = 48;
|
||||||
|
|
||||||
|
private static final int NTP_PORT = 123;
|
||||||
|
private static final int NTP_MODE_CLIENT = 3;
|
||||||
|
private static final int NTP_VERSION = 3;
|
||||||
|
|
||||||
|
// Number of seconds between Jan 1, 1900 and Jan 1, 1970
|
||||||
|
// 70 years plus 17 leap days
|
||||||
|
private static final long OFFSET_1900_TO_1970 = ((365L * 70L) + 17L) * 24L * 60L * 60L;
|
||||||
|
|
||||||
|
// system time computed from NTP server response
|
||||||
|
private long mNtpTime;
|
||||||
|
|
||||||
|
// value of SystemClock.elapsedRealtime() corresponding to mNtpTime
|
||||||
|
private long mNtpTimeReference;
|
||||||
|
|
||||||
|
// round trip time in milliseconds
|
||||||
|
private long mRoundTripTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an SNTP request to the given host and processes the response.
|
||||||
|
*
|
||||||
|
* @param host host name of the server.
|
||||||
|
* @param timeout network timeout in milliseconds.
|
||||||
|
* @return true if the transaction was successful.
|
||||||
|
*/
|
||||||
|
public boolean requestTime(String host, int timeout) {
|
||||||
|
DatagramSocket socket = null;
|
||||||
|
try {
|
||||||
|
socket = new DatagramSocket();
|
||||||
|
socket.setSoTimeout(timeout);
|
||||||
|
InetAddress address = InetAddress.getByName(host);
|
||||||
|
byte[] buffer = new byte[NTP_PACKET_SIZE];
|
||||||
|
DatagramPacket request = new DatagramPacket(buffer,
|
||||||
|
buffer.length, address, NTP_PORT);
|
||||||
|
|
||||||
|
// set mode = 3 (client) and version = 3
|
||||||
|
// mode is in low 3 bits of first byte
|
||||||
|
// version is in bits 3-5 of first byte
|
||||||
|
buffer[0] = NTP_MODE_CLIENT | (NTP_VERSION << 3);
|
||||||
|
|
||||||
|
// get current time and write it to the request packet
|
||||||
|
long requestTime = System.currentTimeMillis();
|
||||||
|
Log.d(TAG, "RequestTime:" + new Date(requestTime));
|
||||||
|
long requestTicks = SystemClock.elapsedRealtime();
|
||||||
|
writeTimeStamp(buffer, TRANSMIT_TIME_OFFSET, requestTime);
|
||||||
|
|
||||||
|
socket.send(request);
|
||||||
|
|
||||||
|
// read the response
|
||||||
|
DatagramPacket response = new DatagramPacket(buffer,
|
||||||
|
buffer.length);
|
||||||
|
socket.receive(response);
|
||||||
|
long responseTicks = SystemClock.elapsedRealtime();
|
||||||
|
long responseTime = requestTime
|
||||||
|
+ (responseTicks - requestTicks);
|
||||||
|
|
||||||
|
// extract the results
|
||||||
|
long originateTime = readTimeStamp(buffer,
|
||||||
|
ORIGINATE_TIME_OFFSET);
|
||||||
|
long receiveTime = readTimeStamp(buffer, RECEIVE_TIME_OFFSET);
|
||||||
|
long transmitTime = readTimeStamp(buffer, TRANSMIT_TIME_OFFSET);
|
||||||
|
long roundTripTime = responseTicks - requestTicks
|
||||||
|
- (transmitTime - receiveTime);
|
||||||
|
// receiveTime = originateTime + transit + skew
|
||||||
|
// responseTime = transmitTime + transit - skew
|
||||||
|
// clockOffset = ((receiveTime - originateTime) + (transmitTime
|
||||||
|
// - responseTime))/2
|
||||||
|
// = ((originateTime + transit + skew - originateTime) +
|
||||||
|
// (transmitTime - (transmitTime + transit - skew)))/2
|
||||||
|
// = ((transit + skew) + (transmitTime - transmitTime - transit
|
||||||
|
// + skew))/2
|
||||||
|
// = (transit + skew - transit + skew)/2
|
||||||
|
// = (2 * skew)/2 = skew
|
||||||
|
long clockOffset = ((receiveTime - requestTime) + (transmitTime - System.currentTimeMillis())) / 2;
|
||||||
|
// if (false) Log.d(TAG, "round trip: " + roundTripTime +
|
||||||
|
// " ms");
|
||||||
|
// if (false) Log.d(TAG, "clock offset: " + clockOffset +
|
||||||
|
// " ms");
|
||||||
|
|
||||||
|
// save our results - use the times on this side of the network
|
||||||
|
// latency
|
||||||
|
// (response rather than request time)
|
||||||
|
mNtpTime = System.currentTimeMillis() + clockOffset;
|
||||||
|
// mNtpTime = transmitTime;
|
||||||
|
mNtpTimeReference = responseTicks;
|
||||||
|
mRoundTripTime = roundTripTime;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (false)
|
||||||
|
Log.e(TAG, "request time failed:" + e);
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
if (socket != null) {
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the time computed from the NTP transaction.
|
||||||
|
*
|
||||||
|
* @return time value computed from NTP server response.
|
||||||
|
*/
|
||||||
|
public long getNtpTime() {
|
||||||
|
return mNtpTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the reference clock value (value of
|
||||||
|
* SystemClock.elapsedRealtime()) corresponding to the NTP time.
|
||||||
|
*
|
||||||
|
* @return reference clock corresponding to the NTP time.
|
||||||
|
*/
|
||||||
|
public long getNtpTimeReference() {
|
||||||
|
return mNtpTimeReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the round trip time of the NTP transaction
|
||||||
|
*
|
||||||
|
* @return round trip time in milliseconds.
|
||||||
|
*/
|
||||||
|
public long getRoundTripTime() {
|
||||||
|
return mRoundTripTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads an unsigned 32 bit big endian number from the given offset in
|
||||||
|
* the buffer.
|
||||||
|
*/
|
||||||
|
private long read32(byte[] buffer, int offset) {
|
||||||
|
byte b0 = buffer[offset];
|
||||||
|
byte b1 = buffer[offset + 1];
|
||||||
|
byte b2 = buffer[offset + 2];
|
||||||
|
byte b3 = buffer[offset + 3];
|
||||||
|
|
||||||
|
// convert signed bytes to unsigned values
|
||||||
|
int i0 = ((b0 & 0x80) == 0x80 ? (b0 & 0x7F) + 0x80 : b0);
|
||||||
|
int i1 = ((b1 & 0x80) == 0x80 ? (b1 & 0x7F) + 0x80 : b1);
|
||||||
|
int i2 = ((b2 & 0x80) == 0x80 ? (b2 & 0x7F) + 0x80 : b2);
|
||||||
|
int i3 = ((b3 & 0x80) == 0x80 ? (b3 & 0x7F) + 0x80 : b3);
|
||||||
|
|
||||||
|
return ((long) i0 << 24) + ((long) i1 << 16) + ((long) i2 << 8)
|
||||||
|
+ (long) i3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the NTP time stamp at the given offset in the buffer and
|
||||||
|
* returns it as a system time (milliseconds since January 1, 1970).
|
||||||
|
*/
|
||||||
|
private long readTimeStamp(byte[] buffer, int offset) {
|
||||||
|
long seconds = read32(buffer, offset);
|
||||||
|
long fraction = read32(buffer, offset + 4);
|
||||||
|
return ((seconds - OFFSET_1900_TO_1970) * 1000)
|
||||||
|
+ ((fraction * 1000L) / 0x100000000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes system time (milliseconds since January 1, 1970) as an NTP
|
||||||
|
* time stamp at the given offset in the buffer.
|
||||||
|
*/
|
||||||
|
private void writeTimeStamp(byte[] buffer, int offset, long time) {
|
||||||
|
long seconds = time / 1000L;
|
||||||
|
long milliseconds = time - seconds * 1000L;
|
||||||
|
seconds += OFFSET_1900_TO_1970;
|
||||||
|
|
||||||
|
// write seconds in big endian format
|
||||||
|
buffer[offset++] = (byte) (seconds >> 24);
|
||||||
|
buffer[offset++] = (byte) (seconds >> 16);
|
||||||
|
buffer[offset++] = (byte) (seconds >> 8);
|
||||||
|
buffer[offset++] = (byte) (seconds >> 0);
|
||||||
|
|
||||||
|
long fraction = milliseconds * 0x100000000L / 1000L;
|
||||||
|
// write fraction in big endian format
|
||||||
|
buffer[offset++] = (byte) (fraction >> 24);
|
||||||
|
buffer[offset++] = (byte) (fraction >> 16);
|
||||||
|
buffer[offset++] = (byte) (fraction >> 8);
|
||||||
|
// low order bits should be random data
|
||||||
|
buffer[offset++] = (byte) (Math.random() * 255.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user