Commit 5c0a770c by Baoxy

fix: 获取网络时间

parent 26dc791d
......@@ -123,38 +123,6 @@
</intent-filter>
</activity>
<activity android:name=".function.setting.AdminSettingActivity"
android:theme="@style/SettingTheme"/>
<activity android:name=".function.setting.SettingActivity"
android:theme="@style/SettingTheme"/>
<activity
android:name=".settings.wifi.WifiWhiteListActivity"
android:excludeFromRecents="true"
android:resizeableActivity="false"
android:theme="@style/AppTheme" />
<activity
android:name=".function.setting.ChangePwdActivity"
android:excludeFromRecents="true"
android:resizeableActivity="false"
android:theme="@style/SettingTheme" />
<activity
android:name=".settings.VerifyPwdProtectionActivity"
android:excludeFromRecents="true"
android:resizeableActivity="false"
android:theme="@style/AppTheme" />
<activity
android:name=".settings.ManagerDisableActivity"
android:excludeFromRecents="true"
android:resizeableActivity="false"
android:theme="@style/AppTheme" />
<activity
android:name=".settings.ProtectionPwdActivity"
android:excludeFromRecents="true"
android:resizeableActivity="false"
android:theme="@style/AppTheme" />
<service
android:priority="1000"
android:name=".settings.wifi.WifiScanService"
......
......@@ -48,7 +48,6 @@
android:supportsRtl="true"
tools:replace="android:label"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".settings.ManagerDisableActivity"></activity>
<activity
android:name=".function.shortcut.ExitShortcut"
......@@ -69,9 +68,8 @@
android:enabled="true"
android:exported="true" />
<activity android:name=".settings.ProtectionPwdActivity" />
<activity android:name=".settings.VerifyPwdProtectionActivity" />
<activity android:name=".function.setting.ChangePwdActivity"
android:excludeFromRecents="true"
android:theme="@style/SettingTheme"/>
<service
......@@ -79,29 +77,37 @@
android:enabled="true"
android:exported="true" />
<activity android:name=".settings.wifi.WifiWhiteListActivity" />
<activity android:name=".settings.wifi.WifiWhiteListActivity"
android:excludeFromRecents="true"/>
<activity android:name=".function.setting.AdminSettingActivity"
android:theme="@style/SettingTheme"/>
android:theme="@style/SettingTheme"
android:excludeFromRecents="true"/>
<activity android:name=".function.setting.SettingActivity"
android:excludeFromRecents="true"
android:theme="@style/SettingTheme"/>
<activity android:name=".function.setting.SettingAboutActivity"
android:excludeFromRecents="true"
android:theme="@style/SettingTheme"/>
<activity android:name=".function.setting.PrivacyPolicyActivity"
android:excludeFromRecents="true"
android:theme="@style/SettingTheme"/>
<activity android:name=".function.setting.SettingPwdActivity"
android:excludeFromRecents="true"
android:theme="@style/SettingTheme"/>
<activity android:name=".function.setting.SettingBuyActivity"
android:excludeFromRecents="true"
android:theme="@style/SettingTheme">
</activity>
<activity android:name=".ManagerAuthActivity"
android:excludeFromRecents="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<activity
......@@ -125,6 +131,7 @@
android:screenOrientation="sensor"
android:stateNotNeeded="true"
android:taskAffinity=""
android:autoRemoveFromRecents="true"
android:windowSoftInputMode="adjustPan|stateUnchanged"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
......@@ -141,6 +148,7 @@
<activity
android:name=".function.pwd.PwdPinSetPwdActivity"
android:excludeFromRecents="true"
android:autoRemoveFromRecents="true"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
......@@ -149,6 +157,7 @@
android:name=".SettingsActivity"
android:autoRemoveFromRecents="true"
android:label="@string/settings_button_text"
android:excludeFromRecents="true"
android:theme="@android:style/Theme.DeviceDefault.Settings">
<intent-filter>
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
......@@ -172,6 +181,7 @@
android:name=".settings.BlankActivity"
android:launchMode="singleInstance"
android:autoRemoveFromRecents="true"
android:excludeFromRecents="true"
android:theme="@style/TransparentTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
......@@ -1198,6 +1198,11 @@ public class Launcher extends BaseActivity
}
ActivationHelper.INSTANCE.active(this, new ActivationHelper.ActivationListener() {
@Override
public void activationFailed() {
}
@Override
public void activated() {
activationNext();
}
......
......@@ -70,6 +70,10 @@ class SettingBuyActivity : BaseActivity() {
override fun activated() {
ToastUtil.showShort(mContext, "该设备已激活")
}
override fun activationFailed() {
}
}, true)
}
}
......
package com.android.launcher3.settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.android.launcher3.R;
import com.secspace.lib.common.utils.ToastUtil;
import com.secspace.mdmengine.api.manager.MdmFactoryManager;
public class ManagerDisableActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
private TextView mTvTitle;
private TextView mTvFinish;
private Switch mSwitchOtg;
private Switch mSwitchUsb;
private Switch mSwitchAdb;
private Switch mSwitchSD;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manager_disable);
initView();
}
private void initView() {
mTvFinish = findViewById(R.id.tv_back);
mTvTitle = findViewById(R.id.tv_title);
mSwitchAdb = findViewById(R.id.switch_adb);
mSwitchOtg = findViewById(R.id.switch_otg);
mSwitchUsb = findViewById(R.id.switch_usb);
mSwitchSD = findViewById(R.id.switch_sd);
mTvFinish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
boolean usbDataDisabled = MdmFactoryManager.getInstance().getDeviceRestrictionManager().isUSBDataDisabled();
boolean adbDisabled = MdmFactoryManager.getInstance().getDeviceRestrictionManager().isAdbDisabled();
boolean usbOtgDisabled = MdmFactoryManager.getInstance().getDeviceRestrictionManager().isUSBOtgDisabled();
boolean externalStorageDisabled = MdmFactoryManager.getInstance().getDeviceRestrictionManager().isExternalStorageDisabled();
mSwitchOtg.setChecked(!usbOtgDisabled);
mSwitchAdb.setChecked(!adbDisabled);
mSwitchUsb.setChecked(!usbDataDisabled);
mSwitchSD.setChecked(!externalStorageDisabled);
mTvTitle.setVisibility(View.VISIBLE);
mTvTitle.setText("功能管控");
mSwitchUsb.setOnCheckedChangeListener(this);
mSwitchOtg.setOnCheckedChangeListener(this);
mSwitchAdb.setOnCheckedChangeListener(this);
mSwitchSD.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView.isPressed()) {
switch (buttonView.getId()) {
case R.id.switch_usb:
MdmFactoryManager.getInstance().getDeviceRestrictionManager().setUSBDataDisabled(!isChecked);
if (!isChecked) {
MdmFactoryManager.getInstance().getDeviceRestrictionManager().setAdbDisabled(true);
mSwitchAdb.setChecked(false);
}
break;
case R.id.switch_otg:
MdmFactoryManager.getInstance().getDeviceRestrictionManager().setUSBOtgDisabled(!isChecked);
break;
case R.id.switch_adb:
boolean usbDataDisabled = MdmFactoryManager.getInstance().getDeviceRestrictionManager().isUSBDataDisabled();
if (usbDataDisabled && isChecked) {
mSwitchAdb.setChecked(false);
ToastUtil.showShort(this, "USB存储被禁用,请先打开USB存储");
return;
}
MdmFactoryManager.getInstance().getDeviceRestrictionManager().setAdbDisabled(!isChecked);
break;
case R.id.switch_sd:
MdmFactoryManager.getInstance().getDeviceRestrictionManager().setExternalStorageDisabled(!isChecked);
break;
}
}
}
}
package com.android.launcher3.settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.android.launcher3.R;
import com.secspace.lib.common.utils.InputUtil;
import com.secspace.lib.common.utils.Prefs;
import com.secspace.lib.common.utils.ToastUtil;
public class ProtectionPwdActivity extends AppCompatActivity implements View.OnClickListener {
EditText mEditQuestion1;
EditText mEditQuestion2;
EditText mEditAnswer1;
EditText mEditAnswer2;
Button mBtnSure;
TextView mTvTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_protection_pwd);
initView();
}
private void initView() {
mEditAnswer1=findViewById(R.id.edit_answer_1);
mEditAnswer2=findViewById(R.id.edit_answer_2);
mEditQuestion1=findViewById(R.id.edit_question_1);
mEditQuestion2=findViewById(R.id.edit_question_2);
mTvTitle=findViewById(R.id.tv_title);
mBtnSure=findViewById(R.id.btn_sure);
findViewById(R.id.tv_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
mTvTitle.setText("设置密保问题");
mBtnSure.setOnClickListener(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public void onClick(View v) {
String question1 = mEditQuestion1.getText().toString();
String question2 = mEditQuestion2.getText().toString();
String answer1 = mEditAnswer1.getText().toString();
String answer2 = mEditAnswer2.getText().toString();
if (TextUtils.isEmpty(question1)||TextUtils.isEmpty(question2)||TextUtils.isEmpty(answer1)||TextUtils.isEmpty(answer2)){
ToastUtil.showShort(this,"不能存在问题或者答案为空的情况,请重新检查输入");
return;
}
Prefs.setPwdProtectionAnswer1(this,answer1);
Prefs.setPwdProtectionQuestion1(this,question1);
Prefs.setPwdProtectionAnswer2(this,answer2);
Prefs.setPwdProtectionQuestion2(this,question2);
finish();
}
}
package com.android.launcher3.settings;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.android.launcher3.R;
import com.android.launcher3.function.setting.ChangePwdActivity;
import com.android.launcher3.function.setting.AdminSettingActivity;
import com.secspace.lib.common.utils.InputUtil;
import com.secspace.lib.common.utils.Prefs;
import com.secspace.lib.common.utils.ToastUtil;
import static com.android.launcher3.settings.Contants.FROM_WHERE;
import static com.android.launcher3.settings.Contants.IS_SHOW_ORIGINAL_PWD;
public class VerifyPwdProtectionActivity extends AppCompatActivity implements View.OnClickListener {
TextView mTvQuestion1;
TextView mTvQuestion2;
EditText mEditAnswer1;
EditText mEditAnswer2;
Button mBtnSure;
private Intent mIntent;
private TextView mTvTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_verify_pwdprotection);
initView();
initData();
}
private void initData() {
mTvQuestion1.setText("密保1: " + Prefs.getPwdProtectionQuestion1(this));
mTvQuestion2.setText("密保2: " + Prefs.getPwdProtectionQuestion2(this));
mIntent = getIntent();
}
private void initView() {
mTvQuestion1 = findViewById(R.id.tv_question_1);
mTvQuestion2 = findViewById(R.id.tv_question_2);
mEditAnswer1 = findViewById(R.id.edit_answer_1);
mEditAnswer2 = findViewById(R.id.edit_answer_2);
mBtnSure = findViewById(R.id.btn_sure);
findViewById(R.id.tv_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InputUtil.closeSoftInput(getApplicationContext(), mEditAnswer1);
finish();
}
});
mBtnSure.setOnClickListener(this);
mTvTitle = findViewById(R.id.tv_title);
mTvTitle.setText("验证密保");
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public void onClick(View v) {
String answer1 = mEditAnswer1.getText().toString();
String answer2 = mEditAnswer2.getText().toString();
if (!ErrorTimeHelper.getInstance(this).canShowDialog()){
ToastUtil.showShort(this,"请在"+ ErrorTimeHelper.getInstance(this).getCountDownTime()+"秒后重试");
return;
}
if (TextUtils.isEmpty(answer1) || TextUtils.isEmpty(answer2)) {
ToastUtil.showShort(this, "密保问题不能为空");
return;
}
if (!TextUtils.equals(answer1, Prefs.getPwdProtectionAnswer1(this)) && !TextUtils.equals(answer2, Prefs.getPwdProtectionAnswer2(this))) {
ToastUtil.showShort(this, "密保问题错误");
ErrorTimeHelper.getInstance(this).canInputPwd();
return;
}
String fromWhere = mIntent.getStringExtra(FROM_WHERE);
Intent intent;
if (!TextUtils.isEmpty(fromWhere) && TextUtils.equals(fromWhere, AdminSettingActivity.class.getSimpleName())) {
intent = new Intent(this, ProtectionPwdActivity.class);
} else {
intent = new Intent(this, ChangePwdActivity.class);
intent.putExtra(IS_SHOW_ORIGINAL_PWD, false);
}
startActivity(intent);
finish();
}
}
......@@ -28,7 +28,8 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".AddDeviceAdminActivity" />
<activity android:name=".AddDeviceAdminActivity"
android:excludeFromRecents="true"/>
<service android:name=".function.ExitService"/>
</application>
......
......@@ -7,9 +7,9 @@ import android.os.Environment
import android.util.Log
import com.secspace.lib.common.utils.ImeiUtil.uniqueId
import com.skr.activation.api.ActivationApi
import com.skr.activation.constant.Constant
import com.skr.activation.constant.Constant.*
import com.skr.activation.network.linstener.CheckLocalActiveStatusListener
import com.skr.activation.network.linstener.GetSystemTimeListener
import com.skr.activation.utils.DesUtil
import com.skr.activation.utils.XmlUtils
import kotlinx.coroutines.Dispatchers
......@@ -21,10 +21,11 @@ import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.net.URL
import java.net.URLConnection
import java.text.SimpleDateFormat
import java.util.*
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
const val PROBATION = "probation"
const val SP_TRIAL_ACTIVE_START_TIME = "trialActiveStartTime"
......@@ -50,45 +51,51 @@ object ActivationHelper {
ActivationApi.getInstance().startActivateActivity(context, context.packageName, false)
return@launch
}
val isProbationCreate = isProbationCreate(context)
if (isProbationCreate) {
val isProbation = isProbationFromLocal(context)
if (isProbation) {
listener.activated()
} else {
DialogManager.getInstance().showBuyCodeDialog(context)
// ActivationApi.getInstance().setUseNormalDialog(true)
// ActivationApi.getInstance().startActivateActivity(context, context.packageName, false)
}
} else {
if (probation(context)) {
listener.activated()
return@launch
}
listener.activationFailed()
}
}
}
override fun onError() {
listener.activationFailed()
}
override fun onError() {}
})
}
private suspend fun getCurrentTimeByNet(): Long {
return withContext(Dispatchers.IO) {
Log.i(TAG, "getCurrentTimeByNet 1")
val url = URL("http://www.bjtime.cn")
Log.i(TAG, "getCurrentTimeByNet 2")
val uc: URLConnection = url.openConnection()
Log.i(TAG, "getCurrentTimeByNet 3")
uc.connect()
Log.i(TAG, "getCurrentTimeByNet 4")
val ld: Long = uc.date
Log.i(TAG, "getCurrentTimeByNet 5 : $ld")
val date = Date(ld)
Log.i(TAG, "getCurrentTimeByNet 6")
Log.e(TAG, "long:$ld, ${date.year}/${date.month}/${date.day} ${date.hours}:${date.minutes}:${date.seconds}")
return@withContext ld
private suspend fun getCurrentTimeByNet(): Long = suspendCoroutine { cont ->
ActivationApi.getInstance().getSystemTime(object : GetSystemTimeListener {
override fun onTime(p0: Long) {
cont.resume(p0)
}
override fun onError(p0: Throwable?) {
cont.resume(-1L)
}
})
}
private fun isProbationCreate(context: Context): Boolean {
return File(FILE_PATH + context.packageName, PROBATION_FILE_NAME).exists()
}
private suspend fun isProbationFromLocal(context: Context): Boolean {
return withContext(Dispatchers.IO) {
val file = File(FILE_PATH + context.packageName, PROBATION_FILE_NAME)
if (!file.exists()) {
probation(context)
return@withContext true
return@withContext false
}
val map: HashMap<String?, *>?
map = try {
......@@ -100,10 +107,13 @@ object ActivationHelper {
Log.e(TAG, "ERROR: ${e.message}")
return@withContext false
}
if (map != null && map.containsKey(Constant.SP_TRIAL_ACTIVE_END_TIME)) {
val endTime: Long = DesUtil.decrypt(map[Constant.SP_TRIAL_ACTIVE_END_TIME].toString()).toLong()
// val currentTime = getCurrentTimeByNet()
val currentTime: Long = System.currentTimeMillis()
if (map != null && map.containsKey(SP_TRIAL_ACTIVE_END_TIME)) {
val endTime: Long = DesUtil.decrypt(map[SP_TRIAL_ACTIVE_END_TIME].toString()).toLong()
val currentTime = getCurrentTimeByNet()
if (currentTime == -1L) {
// 出异常不用处理
return@withContext true
}
if (currentTime > endTime) {
return@withContext false
}
......@@ -113,16 +123,16 @@ object ActivationHelper {
}
}
private suspend fun probation(context: Context) {
private suspend fun probation(context: Context): Boolean {
val map: MutableMap<String?, String?> = HashMap()
Log.i(TAG, "probation before")
// val currentTime = getCurrentTimeByNet()
val currentTime: Long = System.currentTimeMillis()
Log.i(TAG, "probation after")
val currentTime = getCurrentTimeByNet()
if (currentTime == -1L) {
return false
}
val endTime = currentTime + PROBATION_TIME
map[Constant.SP_IS_ACTIVE] = DesUtil.encrypt(PROBATION)
map[Constant.SP_TRIAL_ACTIVE_END_TIME] = DesUtil.encrypt(endTime.toString())
map[Constant.SP_ACTIVE_CODE] = DesUtil.encrypt("无")
map[SP_IS_ACTIVE] = DesUtil.encrypt(PROBATION)
map[SP_TRIAL_ACTIVE_END_TIME] = DesUtil.encrypt(endTime.toString())
map[SP_ACTIVE_CODE] = DesUtil.encrypt("无")
map[SP_TRIAL_ACTIVE_START_TIME] = DesUtil.encrypt(currentTime.toString())
try {
val fileDir = File(FILE_PATH + context.packageName)
......@@ -135,10 +145,11 @@ object ActivationHelper {
}
XmlUtils.writeMapXml(map, FileOutputStream(file))
} catch (e: XmlPullParserException) {
e.printStackTrace()
return false
} catch (e: IOException) {
e.printStackTrace()
return false
}
return true
}
private fun getValueByXmlKey(context: Context, key: String, fileName: String): String {
......@@ -193,7 +204,7 @@ object ActivationHelper {
fun getActivationTimeStart(context: Context): String? {
val time = getValueByXmlKey(context, SP_TRIAL_ACTIVE_START_TIME, PROBATION_FILE_NAME)
if(time.isEmpty()) return "未获取到时间"
if (time.isEmpty()) return "未获取到时间"
val longTime: Long? = time.toLong()
val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US)
return format.format(longTime?.let { Date(it) })
......@@ -205,7 +216,7 @@ object ActivationHelper {
return activationEndTime.replace(" ", " ")
}
val time = getValueByXmlKey(context, SP_TRIAL_ACTIVE_END_TIME, PROBATION_FILE_NAME)
if(time.isEmpty()) return "未获取到时间"
if (time.isEmpty()) return "未获取到时间"
val longTime: Long? = time.toLong()
val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US)
return format.format(longTime?.let { Date(it) })
......@@ -219,5 +230,7 @@ object ActivationHelper {
interface ActivationListener {
fun activated()
fun activationFailed()
}
}
\ No newline at end of file
......@@ -84,10 +84,16 @@ public class BuyCodeDialog implements DialogInterface.OnDismissListener, View.On
ActivationHelper.INSTANCE.active(mActivity, new ActivationHelper.ActivationListener() {
@Override
public void activationFailed() {
}
@Override
public void activated() {
IntentUtil.startEduLauncher(mContext);
}
}, true);
Prefs.setMdmInitializedWhenEnter(mContext, false);
SwitchOutMdm.INSTANCE.exit(mContext);
dismiss();
}
......
......@@ -24,8 +24,7 @@ object WorkManager{
private lateinit var mContext: Context
private val mHandler: Handler = Handler(Looper.getMainLooper(), Handler.Callback { true })
private var mEnterTime: Long = 0
private var isFrstCheckDeviceOwner = true
var isChecksCompleted = false
private var isChecksCompleted = false
fun enter(launcher: Activity?) {
mContext = launcher!!.applicationContext
......
......@@ -55,7 +55,7 @@ public class CheckUpdateCore {
public void init(Context context) {
mAppCtx = context.getApplicationContext();
int[] certificates = new int[]{R.raw.tj_secspace365_cn, R.raw.tomcat_114_215_44_230};
int[] certificates = new int[]{R.raw.tomcat_115_29_115_27};
AppUpdateManager.get().init(context, certificates, new AppUpdateManager.OnAppUpdateListener(){
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment