diff --git a/app/build.gradle b/app/build.gradle index 970f35b..2ce8c91 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -82,16 +82,16 @@ android { //酷比魔方 cube { flavorDimensions "default" - versionCode 73 - versionName "6.3.3" + versionCode 78 + versionName "6.3.8" buildConfigField "String", "platform", '"ZhanRuiCube"' } //MTK MTKnewly { flavorDimensions "default" - versionCode 43 - versionName "2.3.3" + versionCode 48 + versionName "2.3.8" buildConfigField "String", "platform", '"MTK"' } } @@ -278,7 +278,7 @@ dependencies { implementation 'com.squareup.moshi:moshi:1.9.3' //OkHttp - implementation 'com.squareup.okhttp3:okhttp:4.9.0' + implementation 'com.squareup.okhttp3:okhttp:4.8.0' //Retrofit implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' diff --git a/app/src/main/java/com/aoleyun/sn/activity/checknet/CheckNetPresenter.java b/app/src/main/java/com/aoleyun/sn/activity/checknet/CheckNetPresenter.java index c7e010e..ec3b0c2 100644 --- a/app/src/main/java/com/aoleyun/sn/activity/checknet/CheckNetPresenter.java +++ b/app/src/main/java/com/aoleyun/sn/activity/checknet/CheckNetPresenter.java @@ -154,9 +154,9 @@ public class CheckNetPresenter implements CheckNetContact.Presenter { @Override public void setPushTags() { - mNetInterfaceManager.setPushTags(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() { + mNetInterfaceManager.setPushTags(true, getLifecycle(), new NetInterfaceManager.PushTagCallback() { @Override - public void onComplete() { + public void setPushTag(String tag) { Log.e("setPushTags", "onComplete: "); mView.setTagsFinish(false); } diff --git a/app/src/main/java/com/aoleyun/sn/activity/main/MainAContact.java b/app/src/main/java/com/aoleyun/sn/activity/main/MainAContact.java index f894ccb..18ac20d 100644 --- a/app/src/main/java/com/aoleyun/sn/activity/main/MainAContact.java +++ b/app/src/main/java/com/aoleyun/sn/activity/main/MainAContact.java @@ -13,21 +13,33 @@ public class MainAContact { /*获取设备锁定状态*/ void getLockedState(); /*获取设备二维码*/ - void getQRCode(boolean loocked); + void getQrCode(boolean loocked); /*获取学生信息*/ - void getStudesInfo(boolean refresh); + void getStudesInfo(); + /*获取公网ip*/ + void getPublicIp(); /*手动获取设备信息更新*/ void buttonCheckUpdate(View view); + /*获取设备信息更新*/ + void checkAoleyunUpdate(); + /*获取测试应用更新*/ + void checkTestUpdate(); } public interface MainView extends BaseView { /*获取设备锁定状态*/ void setLockedState(boolean loocked); /*获取设备二维码*/ - void setQRCode(Bitmap qrcode); + void setQrCode(Bitmap qrcode); /*获取学生信息*/ void setStudesInfo(StudentsInfo studesInfo); + /*获取公网ip*/ + void setPublicIp(String ip); /*手动获取设备信息更新*/ void buttonCheckUpdateFinish(boolean update, JsonObject jsonObject); + /*获取设备信息更新*/ + void checkAoleyunUpdateFinish(); + /*获取测试应用更新*/ + void checkTestUpdateFinish(); } } diff --git a/app/src/main/java/com/aoleyun/sn/activity/main/MainAPresenter.java b/app/src/main/java/com/aoleyun/sn/activity/main/MainAPresenter.java index 44018d8..5c4cf86 100644 --- a/app/src/main/java/com/aoleyun/sn/activity/main/MainAPresenter.java +++ b/app/src/main/java/com/aoleyun/sn/activity/main/MainAPresenter.java @@ -84,18 +84,18 @@ public class MainAPresenter implements MainAContact.Presenter { } @Override - public void getQRCode(boolean loocked) { + public void getQrCode(boolean loocked) { String encryptString = CXAESUtil.encrypt(CommonConfig.AES_KEY, Utils.getSerial()); Log.e("getQRCode", "setImageAndText: " + encryptString); Bitmap bitmap = Utils.createQRImage(encryptString, 400, 400); - mView.setQRCode(bitmap); + mView.setQrCode(bitmap); } /** * 通过sn获取用户信息 */ @Override - public void getStudesInfo(boolean refresh) { + public void getStudesInfo() { NetInterfaceManager.getInstance().getStudesInfo(true, getLifecycle(), new NetInterfaceManager.StudesInfoListener() { @Override public void setStudentsInfo(StudentsInfo studentsInfo) { @@ -109,12 +109,41 @@ public class MainAPresenter implements MainAContact.Presenter { }); } + @Override + public void getPublicIp() { + NetInterfaceManager.getInstance().getPublicIp(lifecycle, ip -> mView.setPublicIp(ip)); + } + @Override public void buttonCheckUpdate(View view) { checkUpdateInfo(); } + @Override + public void checkAoleyunUpdate() { + checkUpdateInfo(); + NetInterfaceManager.getInstance() + .checkAoleyunUpdate(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() { + @Override + public void onComplete() { + mView.checkAoleyunUpdateFinish(); + } + }); +// mView.checkAoleyunUpdateFinish(); + } + + @Override + public void checkTestUpdate() { + NetInterfaceManager.getInstance() + .checkTestUpdate(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() { + @Override + public void onComplete() { + mView.checkTestUpdateFinish(); + } + }); + } + private void checkUpdateInfo() { NetInterfaceManager.getInstance() .getUpdateApi() diff --git a/app/src/main/java/com/aoleyun/sn/activity/main/MainActivity.java b/app/src/main/java/com/aoleyun/sn/activity/main/MainActivity.java index 2949227..3871e21 100644 --- a/app/src/main/java/com/aoleyun/sn/activity/main/MainActivity.java +++ b/app/src/main/java/com/aoleyun/sn/activity/main/MainActivity.java @@ -5,19 +5,25 @@ import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.graphics.Bitmap; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.Build; import android.os.IBinder; import android.os.SystemClock; import android.provider.Settings; import android.text.TextUtils; +import android.text.format.Formatter; import android.util.Log; +import android.view.Gravity; import android.view.KeyEvent; import android.view.View; -import android.widget.Button; +import android.view.WindowManager; import android.widget.ImageView; import android.widget.TextView; @@ -30,6 +36,7 @@ import com.aoleyun.sn.base.BaseActivity; import com.aoleyun.sn.bean.StudentsInfo; import com.aoleyun.sn.comm.CommonConfig; import com.aoleyun.sn.comm.JGYActions; +import com.aoleyun.sn.dialog.UpdateDialog; import com.aoleyun.sn.service.main.MainService; import com.aoleyun.sn.utils.JGYUtils; import com.aoleyun.sn.utils.SPUtils; @@ -53,57 +60,83 @@ import io.reactivex.rxjava3.core.ObservableOnSubscribe; import io.reactivex.rxjava3.core.Observer; import io.reactivex.rxjava3.disposables.Disposable; +import static android.os.BatteryManager.EXTRA_LEVEL; +import static android.os.BatteryManager.EXTRA_VOLTAGE; + public class MainActivity extends BaseActivity implements MainAContact.MainView, NetworkUtils.OnNetworkStatusChangedListener { private static final String TAG = MainActivity.class.getSimpleName(); public static final String UPDATE_LOCKED_STATUS = "UPDATE_LOCKED_STATUS"; - @BindView(R.id.iv_head) - ImageView head; - @BindView(R.id.tv_devsn) - TextView tv_devsn; - @BindView(R.id.tv_imei2) - TextView tv_imei2; - @BindView(R.id.tv_devmac) - TextView tv_devmac; - @BindView(R.id.version) - TextView tv_version; - @BindView(R.id.tv_batch) - TextView tv_batch; - @BindView(R.id.tv_class_name) - TextView tv_class_name; - @BindView(R.id.tv_class) - TextView tv_class; - @BindView(R.id.tv_number_name) - TextView tv_number_name; - @BindView(R.id.tv_number) - TextView tv_number; - @BindView(R.id.tv_name) - TextView tv_name; - @BindView(R.id.tv_wifi) - TextView tv_wifi; - @BindView(R.id.chkupd) - Button bt_checkupdate; - // @BindView(R.id.checkupdate) -// ConstraintLayout checkupdate; @BindView(R.id.iv_back) ImageView back; - @BindView(R.id.iv_locked) - ImageView iv_locked; - @BindView(R.id.layout_class) - ConstraintLayout layout_class; - @BindView(R.id.layout_number) - ConstraintLayout layout_number; - @BindView(R.id.layout_name) - ConstraintLayout layout_name; - @BindView(R.id.cl_imei) - ConstraintLayout cl_imei; - @BindView(R.id.tv_customversion) - TextView tv_customversion; + @BindView(R.id.tv_version) + TextView tv_version; + @BindView(R.id.iv_head) + ImageView iv_head; + @BindView(R.id.tv_name) + TextView tv_name; + @BindView(R.id.tv_batch) + TextView tv_batch; + @BindView(R.id.tv_number) + TextView tv_number; + @BindView(R.id.tv_class) + TextView tv_class; + @BindView(R.id.tv_model) + TextView tv_model; + @BindView(R.id.cl_ota) + ConstraintLayout cl_ota; + @BindView(R.id.tv_system_version) + TextView tv_system_version; + + @BindView(R.id.tv_battery) + TextView tv_battery; + @BindView(R.id.tv_voltage) + TextView tv_voltage; + @BindView(R.id.tv_wifi) + TextView tv_wifi; + @BindView(R.id.tv_signal) + TextView tv_signal; + @BindView(R.id.tv_ip) + TextView tv_ip; + @BindView(R.id.tv_public_ip) + TextView tv_public_ip; + + @BindView(R.id.tv_serial) + TextView tv_serial; + @BindView(R.id.tv_imei) + TextView tv_imei; + @BindView(R.id.tv_mac) + TextView tv_mac; + + @BindView(R.id.tv_bind_statu) + TextView tv_bind_statu; @BindView(R.id.iv_qrcode) ImageView iv_qrcode; + @BindView(R.id.tv_bind_time) + TextView tv_bind_time; - @OnClick({R.id.iv_back, R.id.tv_title, R.id.chkupd}) +// @BindView(R.id.tv_class_name) +// TextView tv_class_name; +// @BindView(R.id.tv_number_name) +// TextView tv_number_name; +// @BindView(R.id.chkupd) +// Button bt_checkupdate; + // @BindView(R.id.checkupdate) +// ConstraintLayout checkupdate; +// @BindView(R.id.iv_locked) +// ImageView iv_locked; +// @BindView(R.id.layout_class) +// ConstraintLayout layout_class; +// @BindView(R.id.layout_number) +// ConstraintLayout layout_number; +// @BindView(R.id.layout_name) +// ConstraintLayout layout_name; +// @BindView(R.id.cl_imei) +// ConstraintLayout cl_imei; + + + @OnClick({R.id.iv_back, R.id.tv_title}) public void onClick(View view) { switch (view.getId()) { case R.id.iv_back: @@ -144,7 +177,6 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, @Override public void onConnected(NetworkUtils.NetworkType networkType) { Log.e("OnNetworkStatusChanged", "onConnected: "); - Utils.getPublicIP(this); } @Override @@ -161,11 +193,12 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, JGYUtils.startServices(MainActivity.this); getDevicesInfo(); if (Utils.isWifiAvailable(MainActivity.this)) { - tv_wifi.setText(Utils.obtainWifiInfo(MainActivity.this) + "dbm"); - }else { - tv_wifi.setText("未连接"); + tv_signal.setText(Utils.obtainWifiInfo(MainActivity.this) + "dbm"); + } else { + tv_signal.setText("未连接"); } - setStoreUpdateListener(bt_checkupdate); +// setStoreUpdateListener(bt_checkupdate); + registerReceiver(); } private void setStoreUpdateListener(View view) { @@ -194,7 +227,7 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, public void onNext(@NonNull View view) { Log.e("mObserver", "onNext"); ToastUtil.show("正在检查更新"); - mMainAPresenter.buttonCheckUpdate(bt_checkupdate); +// mMainAPresenter.buttonCheckUpdate(bt_checkupdate); } @Override @@ -216,34 +249,39 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, } private void getDevicesInfo() { + tv_model.setText(Build.MODEL); String sn = Utils.getSerial(this); - tv_devsn.setText(sn); + tv_serial.setText(sn); getIMEI(); - checkSNError(sn); - String macaddr = Utils.getAndroid10MAC(this); - if (TextUtils.isEmpty(macaddr)) { - tv_devmac.setText("获取失败"); - } else { - tv_devmac.setText(macaddr); - } + setMac(); + checkSnError(sn); tv_version.setText(BuildConfig.VERSION_NAME); //获取自定义版本号 Log.e(TAG, "getDevicesInfo: CustomVersion: " + Utils.getCustomVersion()); Log.e(TAG, "getDevicesInfo: RomVersion: " + Utils.getRomVersion()); - tv_customversion.setText(Utils.getCustomVersion()); + tv_system_version.setText(Utils.getCustomVersion()); } private void getIMEI() { if (!Utils.NOSN.equalsIgnoreCase(Utils.getSerial())) { - tv_imei2.setText(Utils.getIMEI(this, 1)); + tv_imei.setText(Utils.getIMEI(this, 1)); } else { if (!TextUtils.isEmpty(Utils.getIMEI(this, 1))) { - tv_imei2.setText(Utils.getIMEI(this, 1)); + tv_imei.setText(Utils.getIMEI(this, 1)); } } } - private void checkSNError(String sn) { + private void setMac() { + String macaddr = Utils.getAndroid10MAC(this); + if (TextUtils.isEmpty(macaddr)) { + tv_mac.setText("获取失败"); + } else { + tv_mac.setText(macaddr); + } + } + + private void checkSnError(String sn) { //sn长度最长30位 if (sn.length() > 30) { showSNErrorDialog("设备SN号码格式错误!"); @@ -302,23 +340,23 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, public void setLockedState(boolean loocked) { Log.e(TAG, "setLockedState: " + loocked); if (loocked) { - iv_locked.setVisibility(View.VISIBLE); - iv_locked.setImageDrawable(getDrawable(R.drawable.locked)); - mMainAPresenter.getStudesInfo(false); +// iv_locked.setVisibility(View.VISIBLE); +// iv_locked.setImageDrawable(getDrawable(R.drawable.locked)); + mMainAPresenter.getStudesInfo(); } else { - iv_locked.setVisibility(View.VISIBLE); - iv_locked.setImageDrawable(getDrawable(R.drawable.unlock)); +// iv_locked.setVisibility(View.VISIBLE); +// iv_locked.setImageDrawable(getDrawable(R.drawable.unlock)); setNumberText("", View.GONE); setNameText("", View.GONE); setClassText("", View.GONE); setBatchText("", View.GONE); SysSettingUtils.setEnableSetting(this); } - mMainAPresenter.getQRCode(loocked); + mMainAPresenter.getQrCode(loocked); } @Override - public void setQRCode(Bitmap qrcode) { + public void setQrCode(Bitmap qrcode) { iv_qrcode.setImageBitmap(qrcode); } @@ -357,21 +395,28 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, setBatchText(batch, View.VISIBLE); } if (TextUtils.isEmpty(head_img)) { - setHead(""); + setIv_head(""); } else { - setHead(head_img); + setIv_head(head_img); } SPUtils.put(this, CommonConfig.ADMIN_ID, studesInfo.getAdmin_id()); } + @Override + public void setPublicIp(String ip) { + Log.e(TAG, "setPublicIp: " + ip); + tv_public_ip.setText(ip); + mMainAPresenter.checkAoleyunUpdate(); + } + public void settradeType(int tradeType) { - if (tradeType == 1) { - tv_class_name.setText("班级"); - tv_number_name.setText("学号"); - } else if (tradeType == 2) { - tv_class_name.setText("部门"); - tv_number_name.setText("工号"); - } +// if (tradeType == 1) { +// tv_class_name.setText("班级"); +// tv_number_name.setText("学号"); +// } else if (tradeType == 2) { +// tv_class_name.setText("部门"); +// tv_number_name.setText("工号"); +// } } public void setBatchText(String text, int visibility) { @@ -394,11 +439,11 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, // layout_name.setVisibility(visibility); } - public void setHead(String url) { + public void setIv_head(String url) { if (TextUtils.isEmpty(url)) { - Glide.with(head).load(getDrawable(R.drawable.head)).into(head); + Glide.with(iv_head).load(getDrawable(R.drawable.default_head)).into(iv_head); } else { - Glide.with(head).load(url).into(head); + Glide.with(iv_head).load(url).error(R.drawable.default_head).into(iv_head); } } @@ -407,7 +452,7 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, public void buttonCheckUpdateFinish(boolean update, JsonObject jsonObject) { this.updateApp = !update; if (update) { - showDialog(jsonObject); + showUpdateDialog(jsonObject); } else { Observable.timer(5000, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) @@ -415,30 +460,66 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, } } - private void showDialog(JsonObject jsonObject) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("更新:"); - builder.setMessage("检测到有新版本,是否更新?"); - builder.setIcon(R.mipmap.ic_launcher); - builder.setCancelable(true); - //设置正面按钮 - builder.setPositiveButton("更新", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - JGYUtils.getInstance().installAPK(jsonObject); - dialog.dismiss(); - } - }); - //设置反面按钮 - builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); - builder.show(); + @Override + public void checkAoleyunUpdateFinish() { + mMainAPresenter.checkTestUpdate(); } + @Override + public void checkTestUpdateFinish() { + + } + + private void showUpdateDialog(JsonObject jsonObject) { + UpdateDialog dialog = new UpdateDialog(this); + dialog.setMessage(String.format(getString(R.string.upgrade_app), jsonObject.get("version_name").getAsString())) + .setTitle("版本更新") + .setPositive("确定") + .setSingle(true) + .setOnClickBottomListener(new UpdateDialog.OnClickBottomListener() { + @Override + public void onPositiveClick() { + JGYUtils.getInstance().installAPK(jsonObject); + dialog.dismiss(); + } + + @Override + public void onNegtiveClick() { + dialog.dismiss(); + } + }); + dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + dialog.show(); + dialog.getWindow().setGravity(Gravity.CENTER); + dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); + dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + dialog.setCancelable(false); + } + +// private void showDialog(JsonObject jsonObject) { +// AlertDialog.Builder builder = new AlertDialog.Builder(this); +// builder.setTitle("版本更新"); +// builder.setMessage(String.format(getString(R.string.upgrade_app),jsonObject.get("version_code").getAsString())); +// builder.setIcon(R.mipmap.ic_launcher); +// builder.setCancelable(true); +// //设置正面按钮 +// builder.setPositiveButton("更新", new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// JGYUtils.getInstance().installAPK(jsonObject); +// dialog.dismiss(); +// } +// }); +// //设置反面按钮 +// builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// dialog.dismiss(); +// } +// }); +// builder.show(); +// } + @Override protected void onStop() { super.onStop(); @@ -465,6 +546,7 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, super.onDestroy(); mMainAPresenter.detachView(); mMainAPresenter = null; + unregister(); JGYUtils.startServices(MainActivity.this); } @@ -488,6 +570,20 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, } } + private void registerReceiver() { + registerWiFiReceiver(); + registerBatteryReceiver(); + } + + private void unregister() { + if (mWifiReceiver != null) { + unregisterReceiver(mWifiReceiver); + } + if (mBatteryReceiver != null) { + unregisterReceiver(mBatteryReceiver); + } + } + private UpdateReceiver mUpdateReceiver; private void registerUpdateReceiver() { @@ -505,19 +601,124 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, if (UPDATE_LOCKED_STATUS.equals(intent.getAction())) { int locked = Settings.System.getInt(getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, JGYActions.FRAME_CODE_LOCKED); if (locked == JGYActions.FRAME_CODE_LOCKED) { - iv_locked.setVisibility(View.VISIBLE); - iv_locked.setImageDrawable(getDrawable(R.drawable.locked)); +// iv_locked.setVisibility(View.VISIBLE); +// iv_locked.setImageDrawable(getDrawable(R.drawable.locked)); } else { - iv_locked.setVisibility(View.VISIBLE); - iv_locked.setImageDrawable(getDrawable(R.drawable.unlock)); +// iv_locked.setVisibility(View.VISIBLE); +// iv_locked.setImageDrawable(getDrawable(R.drawable.unlock)); setNumberText("", View.GONE); setNameText("", View.GONE); setClassText("", View.GONE); setBatchText("", View.GONE); - Glide.with(head).load(getDrawable(R.drawable.head)).into(head); + Glide.with(iv_head).load(getDrawable(R.drawable.default_head)).error(R.drawable.default_head).into(iv_head); SysSettingUtils.setEnableSetting(MainActivity.this); } } } } + + private WifiReceiver mWifiReceiver; + + private void registerWiFiReceiver() { + if (mWifiReceiver == null) { + mWifiReceiver = new WifiReceiver(); + } + IntentFilter filter = new IntentFilter(); + filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); + filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); + filter.addAction(WifiManager.RSSI_CHANGED_ACTION); + filter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION); + filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); + filter.addAction(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION); + filter.addAction(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION); + filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); + filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); + registerReceiver(mWifiReceiver, filter); + } + + public class WifiReceiver extends BroadcastReceiver { + private static final String TAG = "wifiReceiver"; + + @Override + public void onReceive(Context context, Intent intent) { + switch (intent.getAction()) { + case WifiManager.RSSI_CHANGED_ACTION: + int rssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -1); + tv_signal.setText(rssi + "dBm"); + //这函数可以计算出信号的等级 + int strength = WifiManager.calculateSignalLevel(rssi, 5); + Log.e(TAG, "wifi信号强度变化"); + break; + //wifi连接上与否 + case WifiManager.NETWORK_STATE_CHANGED_ACTION: + NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); + if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) { + Log.e(TAG, getString(R.string.wifi_disconnected)); + tv_wifi.setText(getString(R.string.wifi_disconnected)); + tv_signal.setText(""); + tv_ip.setText(getString(R.string.unknown)); + } else if (info.getState().equals(NetworkInfo.State.CONNECTED)) { + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + //获取当前wifi名称 + String newSSID = wifiInfo.getSSID(); + tv_wifi.setText(newSSID); + tv_ip.setText(Formatter.formatIpAddress(wifiInfo.getIpAddress())); + setMac(); + Log.e(TAG, "连接到网络 " + newSSID); + } + break; + //wifi打开与否 + case WifiManager.WIFI_STATE_CHANGED_ACTION: + int wifistate = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED); + if (wifistate == WifiManager.WIFI_STATE_DISABLED) { +// tv_wifi.setText(getString(R.string.turn_off_wifi)); + Log.e(TAG, getString(R.string.turn_off_wifi)); + } else if (wifistate == WifiManager.WIFI_STATE_ENABLED) { +// tv_wifi.setText(getString(R.string.turn_on_wifi)); + Log.e(TAG, getString(R.string.turn_on_wifi)); + mMainAPresenter.getPublicIp(); + } + break; + default: + } + } + } + + private BatteryReceiver mBatteryReceiver; + + private void registerBatteryReceiver() { + if (mBatteryReceiver == null) { + mBatteryReceiver = new BatteryReceiver(); + } + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_BATTERY_CHANGED); + registerReceiver(mBatteryReceiver, filter); + } + + private class BatteryReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (null == intent) { + return; + } + String action = intent.getAction(); + if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { + int level = intent.getIntExtra(EXTRA_LEVEL, 0); + int batteryVolt = intent.getIntExtra(EXTRA_VOLTAGE, -1); + String levelStr = getLevel(level); + tv_battery.setText("电量:" + levelStr); + String batteryVoltStr = getBatteryVolt(batteryVolt); + tv_voltage.setText("电压:" + batteryVoltStr); + } + } + } + + private String getLevel(int level) { + return String.format("%d %%", level); + } + + private String getBatteryVolt(int batteryVolt) { + return String.format("%.3f V", batteryVolt / 1000.0); + } } diff --git a/app/src/main/java/com/aoleyun/sn/base/BaseApplication.java b/app/src/main/java/com/aoleyun/sn/base/BaseApplication.java index 178a5da..f619d55 100644 --- a/app/src/main/java/com/aoleyun/sn/base/BaseApplication.java +++ b/app/src/main/java/com/aoleyun/sn/base/BaseApplication.java @@ -9,8 +9,6 @@ import android.util.Log; import androidx.multidex.MultiDexApplication; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; import com.aoleyun.sn.BuildConfig; import com.aoleyun.sn.bean.BaseResponse; import com.aoleyun.sn.manager.MapManager; diff --git a/app/src/main/java/com/aoleyun/sn/bean/AppUpdateInfo.java b/app/src/main/java/com/aoleyun/sn/bean/AppUpdateInfo.java index e64802f..4bfbd7e 100644 --- a/app/src/main/java/com/aoleyun/sn/bean/AppUpdateInfo.java +++ b/app/src/main/java/com/aoleyun/sn/bean/AppUpdateInfo.java @@ -12,6 +12,7 @@ public class AppUpdateInfo implements Serializable { int id; String url; long version_code; + String version_name; String app_name; @SerializedName("package") String packages; @@ -41,6 +42,14 @@ public class AppUpdateInfo implements Serializable { this.version_code = version_code; } + public String getVersion_name() { + return version_name; + } + + public void setVersion_name(String version_name) { + this.version_name = version_name; + } + public String getApp_name() { return app_name; } diff --git a/app/src/main/java/com/aoleyun/sn/comm/CommonConfig.java b/app/src/main/java/com/aoleyun/sn/comm/CommonConfig.java index 2dbddca..0f59d13 100644 --- a/app/src/main/java/com/aoleyun/sn/comm/CommonConfig.java +++ b/app/src/main/java/com/aoleyun/sn/comm/CommonConfig.java @@ -48,7 +48,7 @@ public class CommonConfig { /*上次检查更新时间*/ public final static String LAST_CHECK_ALL_UPDATE_TIME = "lastCheckAllUpdateTime"; /*获取设备的标签*/ - public final static String DEVICES_TAG = "Aoleyun_devices_tag"; + public final static String DEVICES_TAG = "Aoleyun_devices_tpush_tag"; /*上次获取标签的时间*/ public final static String GET_DEVICES_TAG_LASTTIME = "Aoleyun_devices_tag_last_time"; diff --git a/app/src/main/java/com/aoleyun/sn/dialog/UpdateDialog.java b/app/src/main/java/com/aoleyun/sn/dialog/UpdateDialog.java new file mode 100644 index 0000000..fa1b6a2 --- /dev/null +++ b/app/src/main/java/com/aoleyun/sn/dialog/UpdateDialog.java @@ -0,0 +1,197 @@ +package com.aoleyun.sn.dialog; + + +import android.content.Context; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.appcompat.app.AlertDialog; + +import com.aoleyun.sn.R; + + +/** + * description:自定义dialog + */ + +public class UpdateDialog extends AlertDialog { + /** + * 显示的标题 + */ + private TextView titleTv; + + /** + * 显示的消息 + */ + private TextView messageTv; + + /** + * 确认和取消按钮 + */ + private TextView positiveBn; + + /** + * 按钮之间的分割线 + */ +// private View columnLineView; + + private Context mContext; + + public UpdateDialog(Context context) { + super(context, R.style.CustomDialog); + this.mContext = context; + } + + /** + * 都是内容数据 + */ + private String message; + private String title; + private String positive; + private int imageResId = -1; + + /** + * 底部是否只有一个按钮 + */ + private boolean isSingle = false; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.update_dialog); + //按空白处不能取消动画 + setCanceledOnTouchOutside(false); + //初始化界面控件 + initView(); + //初始化界面数据 + refreshView(); + //初始化界面控件的事件 + initEvent(); + } + + /** + * 初始化界面的确定和取消监听器 + */ + private void initEvent() { + //设置确定按钮被点击后,向外界提供监听 + positiveBn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (onClickBottomListener != null) { + onClickBottomListener.onPositiveClick(); + } + } + }); + } + + /** + * 初始化界面控件的显示数据 + */ + private void refreshView() { + //如果用户自定了title和message + if (!TextUtils.isEmpty(title)) { + titleTv.setText(title); + titleTv.setVisibility(View.VISIBLE); + } else { + titleTv.setVisibility(View.GONE); + } + if (!TextUtils.isEmpty(message)) { + messageTv.setText(message); + } + //如果设置按钮的文字 + if (!TextUtils.isEmpty(positive)) { + positiveBn.setText(positive); + } else { + positiveBn.setText("确定"); + } + } + + @Override + public void show() { + super.show(); + refreshView(); + } + + /** + * 初始化界面控件 + */ + private void initView() { + positiveBn = findViewById(R.id.positive); + titleTv = findViewById(R.id.title); + messageTv = findViewById(R.id.message); + } + + /** + * 设置确定取消按钮的回调 + */ + private OnClickBottomListener onClickBottomListener; + + public void setOnClickBottomListener(OnClickBottomListener onClickBottomListener) { + this.onClickBottomListener = onClickBottomListener; + } + + public interface OnClickBottomListener { + /** + * 点击确定按钮事件 + */ + void onPositiveClick(); + + /** + * 点击取消按钮事件 + */ + void onNegtiveClick(); + } + + public String getMessage() { + return message; + } + + public UpdateDialog setMessage(String message) { + this.message = message; + return this; + } + + public String getTitle() { + return title; + } + + public UpdateDialog setTitle(String title) { + this.title = title; + return this; + } + + public String getPositive() { + return positive; + } + + public UpdateDialog setPositive(String positive) { + this.positive = positive; + return this; + } + + public int getImageResId() { + return imageResId; + } + + public boolean isSingle() { + return isSingle; + } + + public UpdateDialog setSingle(boolean single) { + isSingle = single; + return this; + } + + public UpdateDialog setImageResId(int imageResId) { + this.imageResId = imageResId; + return this; + } + + @Override + public void dismiss() { + super.dismiss(); + } +} diff --git a/app/src/main/java/com/aoleyun/sn/network/NetInterfaceManager.java b/app/src/main/java/com/aoleyun/sn/network/NetInterfaceManager.java index 9aba943..334d860 100644 --- a/app/src/main/java/com/aoleyun/sn/network/NetInterfaceManager.java +++ b/app/src/main/java/com/aoleyun/sn/network/NetInterfaceManager.java @@ -49,7 +49,6 @@ import com.aoleyun.sn.gson.GsonUtils; import com.aoleyun.sn.gson.NullStringToEmptyAdapterFactory; import com.aoleyun.sn.manager.ConnectManager; import com.aoleyun.sn.manager.ConnectMode; -import com.aoleyun.sn.network.api.GetPublicIPApi; import com.aoleyun.sn.network.api.GetWhoisApi; import com.aoleyun.sn.network.api.get.CheckTestUpdateApi; import com.aoleyun.sn.network.api.get.DefaultAppApi; @@ -590,9 +589,9 @@ public class NetInterfaceManager { .observeOn(AndroidSchedulers.mainThread()); } - public Observable GetNetworkConnectControl() { + public Observable GetNetworkConnectControl(String time) { return mRetrofit.create(NetworkConnectApi.class) - .sendNetwork(Utils.getSerial(mContext)) + .sendNetwork(Utils.getSerial(mContext), time) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); } @@ -1594,6 +1593,9 @@ public class NetInterfaceManager { @Override public void onComplete() { Log.e("getSnAppAttr", "onComplete: "); + if (onCompleteCallback != null) { + onCompleteCallback.onComplete(); + } } }; } @@ -1826,9 +1828,9 @@ public class NetInterfaceManager { * @param studesInfoListener */ public void getStudesInfo(boolean refresh, BehaviorSubject lifecycle, StudesInfoListener studesInfoListener) { - ConnectMode connectMode = ConnectMode.FIFTEEN_MINUTES; + ConnectMode connectMode = ConnectMode.ONE_MINUTE; if (refresh) { - connectMode = ConnectMode.ONE_MINUTE; + connectMode = ConnectMode.DEFAULT; } if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_STUDENTS_INFO, connectMode)) { getInfo(lifecycle, studesInfoListener); @@ -1903,23 +1905,23 @@ public class NetInterfaceManager { .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { - Log.e(TAG + ":" + "getLockedState", "onSubscribe: "); + Log.e("getLockedState", "onSubscribe: "); } @Override public void onNext(@NonNull BaseResponse response) { - Log.e(TAG + ":" + "getLockedState", "onNext: " + response); + Log.e("getLockedState", "onNext: " + response); if (response.code == OK) { JsonObject jsonObject = JsonParser.parseString(new Gson().toJson(response.data)).getAsJsonObject(); int locked = jsonObject.get("lock").getAsInt(); - Log.e(TAG + ":" + "getLockedState", "locked: " + locked); + Log.e("getLockedState", "locked: " + locked); // int oldState = Settings.System.getInt(mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, JGYActions.FRAME_CODE_LOCKED); -// Log.e(TAG + ":" + "getLockedState", "qch_unlock_ipad: " + oldState); +// Log.e( "getLockedState", "qch_unlock_ipad: " + oldState); //后台1是锁定,底层0是锁定 SPUtils.put(mContext, CommonConfig.JGY_FIRST_CONNECT, 1); if (locked == JGYActions.NET_CODE_LOCKED) { // if (oldState == JGYActions.FRAME_CODE_UNLOCKED) { -// Log.e(TAG + ":" + "getLockedState", "onNext: " + "state changed , reset devices"); +// Log.e( "getLockedState", "onNext: " + "state changed , reset devices"); // Utils.doMasterClear(mContext); // } Settings.System.putInt(mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, JGYActions.FRAME_CODE_LOCKED); @@ -1929,19 +1931,19 @@ public class NetInterfaceManager { } } else if (response.code == NOTFOUND) { Settings.System.putInt(mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, JGYActions.FRAME_CODE_LOCKED); - Log.e(TAG + ":" + "getLockedState", "locked: " + false); + Log.e("getLockedState", "locked: " + false); } } @Override public void onError(@NonNull Throwable e) { - Log.e(TAG + ":" + "getLockedState", "onError: " + e.getMessage()); + Log.e("getLockedState", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - Log.e(TAG + ":" + "getLockedState", "onComplete: "); + Log.e("getLockedState", "onComplete: "); callback.onComplete(); } }); @@ -2018,91 +2020,82 @@ public class NetInterfaceManager { }); } + public interface PushTagCallback { + void setPushTag(String tag); + } - synchronized public void setPushTags(boolean refresh, BehaviorSubject lifecycle, onCompleteCallback callback) { - ConnectMode connectMode = ConnectMode.ONCE; + public void setPushTags(boolean refresh, BehaviorSubject lifecycle, PushTagCallback callback) { + ConnectMode connectMode = ConnectMode.ONE_DAY; if (refresh) { - connectMode = ConnectMode.ONE_DAY; + connectMode = ConnectMode.SIX_HOUR; } if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_DEVICES_TAGS, connectMode)) { setPushTags(lifecycle, callback); } else { - String jsonString = cacheHelper.getAsString(UrlAddress.GET_DEVICES_TAGS); + String batch = mMMKV.decodeString(CommonConfig.DEVICES_TAG, ""); //为 "" 是已经请求成功的 - if (jsonString == null) { + if (TextUtils.isEmpty(batch)) { setPushTags(lifecycle, callback); } else { - Set tagSets = mMMKV.decodeStringSet(CommonConfig.DEVICES_TAG + "pushset"); - Log.e("setPushTags", "tagSets: " + tagSets); - clearAndAppendTags(tagSets); - callback.onComplete(); + Log.e("setPushTags", "tagSets: " + batch); + callback.setPushTag(batch); } } } + /** * 设置推送的标签 * * @param lifecycle * @param callback */ - synchronized public void setPushTags(BehaviorSubject lifecycle, onCompleteCallback callback) { - Set set = new HashSet<>(); - JGYUtils.getInstance().getAppPlatform(new JGYUtils.GetAppPlatformCallback() { - @Override - public void AppPlatform(int platform) { - if (platform == JGYUtils.MTKPlatform) { - set.add(JGYUtils.MTKTag); - } else if (platform == JGYUtils.ZhanruiPlatform) { - set.add(JGYUtils.ZhanruiTag); - } else if (platform == JGYUtils.CubePlatform) { - set.add(JGYUtils.CubeTag); - } - } - }); + public void setPushTags(BehaviorSubject lifecycle, PushTagCallback callback) { getPushTagsObservable() .compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY)) .subscribe(new Observer>() { @Override public void onSubscribe(@NonNull Disposable d) { - Log.e(TAG + ":" + "setPushTags", "onSubscribe: "); + Log.e("setPushTags", "onSubscribe: "); } @Override public void onNext(@NonNull BaseResponse response) { if (response.code == OK) { - String batch = response.data.getBatch(); cacheHelper.put(UrlAddress.GET_DEVICES_TAGS, GsonUtils.toJSONString(response.data)); - Log.e(TAG + ":" + "setPushTags", "onNext: " + batch); - if (!TextUtils.isEmpty(batch)) { - set.add(batch); + String batch = response.data.getBatch(); + Log.e("setPushTags", "onNext: " + batch); + if (TextUtils.isEmpty(batch)) { + Log.e("setPushTags", "onNext: " + "batch empty"); + callback.setPushTag(""); } else { - Log.e(TAG + ":" + "setPushTags", "onNext: " + "batch empty"); + callback.setPushTag(batch); + mMMKV.encode(CommonConfig.DEVICES_TAG, batch); } } else { cacheHelper.put(UrlAddress.GET_DEVICES_TAGS, ""); - Log.e(TAG + ":" + "setPushTags", "onNext: " + response.toString()); + callback.setPushTag(""); + Log.e("setPushTags", "onNext: " + response.toString()); } - mMMKV.encode(CommonConfig.DEVICES_TAG + "pushset", set); } @Override public void onError(@NonNull Throwable e) { - Log.e(TAG + ":" + "setPushTags", "onError: " + e.getMessage()); + Log.e("setPushTags", "onError: " + e.getMessage()); + String batch = mMMKV.decodeString(CommonConfig.DEVICES_TAG, ""); + Log.e("setPushTags", "tagSets: " + batch); + callback.setPushTag(batch); onComplete(); } @Override public void onComplete() { - Log.e(TAG + ":" + "setPushTags", "onComplete: "); - Log.e("setPushTags", "tagSets: " + set); - clearAndAppendTags(set); - callback.onComplete(); + Log.e("setPushTags", "onComplete: "); } }); } - synchronized private void clearAndAppendTags(Set tagSets) { + public void clearAndAppendTags(Set tagSets) { XGPushManager.clearAndAppendTags(mContext, "clearAndAppendTags :" + System.currentTimeMillis(), tagSets, new XGIOperateCallback() { @Override public void onSuccess(Object o, int i) { @@ -2118,7 +2111,7 @@ public class NetInterfaceManager { public void updateDeviceInfo(boolean refresh, BehaviorSubject lifecycle, onCompleteCallback callback) { - ConnectMode connectMode = ConnectMode.SIX_HOUR; + ConnectMode connectMode = ConnectMode.ONE_MINUTE; if (refresh) { connectMode = ConnectMode.DEFAULT; } @@ -2328,7 +2321,7 @@ public class NetInterfaceManager { } public void getBookMarkBlackWhiteList(boolean refresh, BehaviorSubject lifecycle, onCompleteCallback callback) { - ConnectMode connectMode = ConnectMode.ONE_HOUR; + ConnectMode connectMode = ConnectMode.ONE_MINUTE; if (refresh) { connectMode = ConnectMode.DEFAULT; } @@ -2585,9 +2578,9 @@ public class NetInterfaceManager { listener.setScreenLockState(false, ""); return; } - ConnectMode connectMode = ConnectMode.SIX_HOUR; + ConnectMode connectMode = ConnectMode.ONE_MINUTE; if (refresh) { - connectMode = ConnectMode.ONE_HOUR; + connectMode = ConnectMode.DEFAULT; } if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_LOCK_SCREEN_STATE, connectMode)) { getScreenLock(lifecycle, listener); @@ -2646,9 +2639,9 @@ public class NetInterfaceManager { } public void getAppLimit(boolean refresh, BehaviorSubject lifecycle, onCompleteCallback callback) { - ConnectMode connectMode = ConnectMode.HALF_DAY; + ConnectMode connectMode = ConnectMode.ONE_MINUTE; if (refresh) { - connectMode = ConnectMode.SIX_HOUR; + connectMode = ConnectMode.DEFAULT; } if (ConnectManager.getInstance().isNeedConnect(UrlAddress.SET_WHITE_PACKAGE_LIST, connectMode)) { getAppLimit(lifecycle, callback); @@ -2732,9 +2725,9 @@ public class NetInterfaceManager { * 获取所有app详细信息 */ public void getAllAppList(boolean refresh, BehaviorSubject lifecycle, onCompleteCallback callback) { - ConnectMode connectMode = ConnectMode.ONE_HOUR; + ConnectMode connectMode = ConnectMode.ONE_MINUTE; if (refresh) { - connectMode = ConnectMode.HALF_HOUR; + connectMode = ConnectMode.DEFAULT; } if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_ALL_APP, connectMode)) { getAllAppList(lifecycle, callback); @@ -2807,9 +2800,9 @@ public class NetInterfaceManager { public void getSnTimeControl(boolean refresh, BehaviorSubject lifecycle, onCompleteCallback callback) { - ConnectMode connectMode = ConnectMode.SIX_HOUR; + ConnectMode connectMode = ConnectMode.ONE_MINUTE; if (refresh) { - connectMode = ConnectMode.ONE_HOUR; + connectMode = ConnectMode.DEFAULT; } if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_SN_TIME_CONTROL, connectMode)) { getSnTimeControl(lifecycle, callback); @@ -2960,9 +2953,9 @@ public class NetInterfaceManager { } public void getTopApp(boolean refresh, BehaviorSubject lifecycle, onCompleteCallback callback) { - ConnectMode connectMode = ConnectMode.HALF_DAY; + ConnectMode connectMode = ConnectMode.ONE_MINUTE; if (refresh) { - connectMode = ConnectMode.SIX_HOUR; + connectMode = ConnectMode.DEFAULT; } if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_TOP_APP_CONTROL, connectMode)) { getTopApp(lifecycle, callback); @@ -3099,7 +3092,7 @@ public class NetInterfaceManager { } public void getPoweroffTime(boolean refresh, BehaviorSubject lifecycle, onCompleteCallback callback) { - ConnectMode connectMode = ConnectMode.ONE_HOUR; + ConnectMode connectMode = ConnectMode.ONE_MINUTE; if (refresh) { connectMode = ConnectMode.DEFAULT; } @@ -3176,7 +3169,7 @@ public class NetInterfaceManager { public void getWiFiPasswd(boolean refresh, BehaviorSubject lifecycle, onCompleteCallback callback) { - ConnectMode connectMode = ConnectMode.ONE_HOUR; + ConnectMode connectMode = ConnectMode.ONE_MINUTE; if (refresh) { connectMode = ConnectMode.DEFAULT; } @@ -3198,21 +3191,18 @@ public class NetInterfaceManager { } public void getWiFiPasswd(BehaviorSubject lifecycle, onCompleteCallback callback) { - NetInterfaceManager.getInstance() - .getWiFiControl() + getWiFiControl() .compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY)) .subscribe(getWiFiPasswdObserver(callback)); } public void getWiFiPasswd(onCompleteCallback callback) { - NetInterfaceManager.getInstance() - .getWiFiControl() + getWiFiControl() .subscribe(getWiFiPasswdObserver(callback)); } public void getWiFiPasswd() { - NetInterfaceManager.getInstance() - .getWiFiControl() + getWiFiControl() .subscribe(getWiFiPasswdObserver(null)); } @@ -3308,73 +3298,8 @@ public class NetInterfaceManager { }); } - - public interface PublicIP { - void set(String ip); - } - public static final String PublicIP = "PublicIP"; - /** - * 获取设备公网IP - * - * @param publicIP - */ - private static String IpAddr = ""; - - public static void getPublicIP(PublicIP publicIP) { - Retrofit retrofit = new Retrofit.Builder() - .client(NetInterfaceManager.getInstance().getOkHttpClient()) - .baseUrl(UrlAddress.SHOUHU_CITYJSON) - .addConverterFactory(GsonConverterFactory.create()) - .addCallAdapterFactory(RxJava3CallAdapterFactory.create()) - .build(); - retrofit.create(GetPublicIPApi.class) - .getPublicIP() - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - Log.e("getPublicIP", "onSubscribe: "); - } - - @Override - public void onNext(ResponseBody responseBody) { - try { - String s = responseBody.string(); - Log.e("getPublicIP", "onNext: " + s); - if (!TextUtils.isEmpty(s)) { - //var returnCitySN = {"cip": "183.11.74.141", "cid": "440300", "cname": "广东省深圳市"}; - if (s.contains("{")) { - String jsonString = s.substring(s.indexOf("{"), s.lastIndexOf("}") + 1); - JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject(); - String ip = jsonObject.get("cip").getAsString(); - if (!TextUtils.isEmpty(ip)) { - IpAddr = ip; - } - } - } - } catch (IOException e) { - e.printStackTrace(); - Log.e("getPublicIP", "IOException: " + e.getMessage()); - } - } - - @Override - public void onError(Throwable e) { - Log.e("getPublicIP", "onError: " + e.getMessage()); - } - - @Override - public void onComplete() { - Log.e("getPublicIP", "onComplete: "); - MMKV.defaultMMKV().encode(NetInterfaceManager.PublicIP, IpAddr); - publicIP.set(IpAddr); - } - }); - } - public static final String WHOIS_ADDR = "whois_ip_addr"; public static void GetWhois() { @@ -3565,4 +3490,53 @@ public class NetInterfaceManager { } }); } + + public static final String WHOIS_IP = "whois_ip_addr"; + + public interface PublicIpCallbak { + void getPublicIp(String ip); + } + + public void getPublicIp(BehaviorSubject lifecycle, PublicIpCallbak callbak) { + Retrofit retrofit = new Retrofit.Builder() + .client(NetInterfaceManager.getInstance().getOkHttpClient()) + .baseUrl(UrlAddress.PCONLINE_WHOIS) + .addConverterFactory(GsonConverterFactory.create()) + .addCallAdapterFactory(RxJava3CallAdapterFactory.create()) + .build(); + retrofit.create(GetWhoisApi.class) + .getWhois(true) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY)) + .subscribe(new Observer() { + @Override + public void onSubscribe(@NonNull Disposable d) { + Log.e("getPublicIp", "onSubscribe: "); + } + + @Override + public void onNext(@NonNull WhoisBean whoisBean) { + Log.e("getPublicIp", "onNext: " + whoisBean); + if (whoisBean != null && !TextUtils.isEmpty(whoisBean.getIp())) { + callbak.getPublicIp(whoisBean.getIp()); + MMKV.defaultMMKV().encode(NetInterfaceManager.WHOIS_IP, whoisBean.getIp()); + } else { + callbak.getPublicIp("unknown"); + } + } + + @Override + public void onError(@NonNull Throwable e) { + Log.e("getPublicIp", "onError: "); + callbak.getPublicIp("unknown"); + onComplete(); + } + + @Override + public void onComplete() { + Log.e("getPublicIp", "onComplete: "); + } + }); + } } diff --git a/app/src/main/java/com/aoleyun/sn/network/UrlAddress.java b/app/src/main/java/com/aoleyun/sn/network/UrlAddress.java index ad9b1be..c435a5b 100644 --- a/app/src/main/java/com/aoleyun/sn/network/UrlAddress.java +++ b/app/src/main/java/com/aoleyun/sn/network/UrlAddress.java @@ -4,6 +4,20 @@ package com.aoleyun.sn.network; * @author Administrator */ public class UrlAddress { + + /** + * 设备管控信息 + */ + + /*获取设备锁定状态*/ + public static final String GET_DEVICES_LOCKED = "lock/index"; + /*获取设备标签*/ + public static final String GET_DEVICES_TAGS = "Sn/getSnTag"; + + /*获取批次*/ + @Deprecated + public static final String GET_BATCH = "log/getBatch"; + /** * 应用策略相关 */ @@ -37,16 +51,8 @@ public class UrlAddress { /*下载接口 根据包名匹配 请求后更新下载次数*/ public static final String SEND_DOWNLOAD_TIMES = "count/index"; - /** - * 设备相关 - */ - /*获取设备锁定状态*/ - public static final String GET_DEVICES_LOCKED = "lock/index"; - /*获取设备标签*/ - public static final String GET_DEVICES_TAGS = "Sn/getSnTag"; - /*获取批次*/ - public static final String GET_BATCH = "log/getBatch"; + /*上传安装的应用信息*/ public static final String UPLOAD_APPINFO = "log/index"; @@ -70,6 +76,7 @@ public class UrlAddress { public static final String GET_LOCK_SCREEN_STATE = "Sn/getSnScreen"; /*上传电池信息*/ public static final String SEND_BATTERY_INFO = "And/sn/updateBatteryInfo"; + /*上传联网时间*/ public static final String NETWORK_CONNECT = "And/network"; @@ -115,6 +122,11 @@ public class UrlAddress { /*开发人员选项开关*/ public static final String GET_DEVELOPER = "Sn/getDeveloper"; + + /** + * log相关 + */ + /*获取log任务*/ public static final String GET_LOG_ORDER = "And/getSnRunLog"; /*上传log文件*/ @@ -123,8 +135,7 @@ public class UrlAddress { public static final String UPLOAD_IS_LOG_FILE = "And/sn/uploadIsLogFile"; - /*获取公网IP*/ - public static final String SHOUHU_CITYJSON = "http://pv.sohu.com/cityjson/"; + /*通过ip获取信息*/ public static final String PCONLINE_WHOIS = "http://whois.pconline.com.cn/"; public static final String WHOIS = "ipJson.jsp"; diff --git a/app/src/main/java/com/aoleyun/sn/network/api/GetPublicIPApi.java b/app/src/main/java/com/aoleyun/sn/network/api/GetPublicIPApi.java deleted file mode 100644 index 4d23ac3..0000000 --- a/app/src/main/java/com/aoleyun/sn/network/api/GetPublicIPApi.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.aoleyun.sn.network.api; - -import com.aoleyun.sn.network.UrlAddress; - -import io.reactivex.rxjava3.core.Observable; -import okhttp3.ResponseBody; -import retrofit2.http.GET; - -/** - * @author : fanhuitong - * e-mail : - * @date : 2021/10/1814:39 - * desc : - * version: 1.0 - */ -public interface GetPublicIPApi { - @GET(UrlAddress.SHOUHU_CITYJSON) - Observable getPublicIP(); -} diff --git a/app/src/main/java/com/aoleyun/sn/network/api/post/NetworkConnectApi.java b/app/src/main/java/com/aoleyun/sn/network/api/post/NetworkConnectApi.java index e59d020..a39d20a 100644 --- a/app/src/main/java/com/aoleyun/sn/network/api/post/NetworkConnectApi.java +++ b/app/src/main/java/com/aoleyun/sn/network/api/post/NetworkConnectApi.java @@ -3,6 +3,8 @@ package com.aoleyun.sn.network.api.post; import com.aoleyun.sn.bean.BaseResponse; import com.aoleyun.sn.network.UrlAddress; +import java.util.List; + import io.reactivex.rxjava3.core.Observable; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; @@ -12,6 +14,7 @@ public interface NetworkConnectApi { @FormUrlEncoded @POST(UrlAddress.NETWORK_CONNECT) Observable sendNetwork( - @Field("sn") String sn + @Field("sn") String sn, + @Field("time") String time ); } diff --git a/app/src/main/java/com/aoleyun/sn/network/interceptor/RepeatRequestInterceptor.java b/app/src/main/java/com/aoleyun/sn/network/interceptor/RepeatRequestInterceptor.java index 76c919e..0b4a1af 100644 --- a/app/src/main/java/com/aoleyun/sn/network/interceptor/RepeatRequestInterceptor.java +++ b/app/src/main/java/com/aoleyun/sn/network/interceptor/RepeatRequestInterceptor.java @@ -39,7 +39,11 @@ public class RepeatRequestInterceptor implements Interceptor { // Response copy = response.newBuilder().body(responseBody).build(); ResponseBody copy = ResponseBody.create(responseBody.contentType(), content); if (BuildConfig.DEBUG) { - Log.e(TAG, "请求体返回:| Response: " + request.url().encodedPath() + "\t body: " + content); + if (content.length() < 1024) { + Log.e(TAG, "请求体返回:| Response: " + request.url() + "\t body: " + content); + }else { + Log.e(TAG, "请求体返回:| Response: " + request.url() + "\t body: too long" ); + } } //相同的请求 String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString() + requestBodyToString(request.body())); @@ -83,7 +87,7 @@ public class RepeatRequestInterceptor implements Interceptor { final Request copy = request.newBuilder().build(); final Buffer buffer = new Buffer(); copy.body().writeTo(buffer); - if (buffer.size() > 4096) { + if (buffer.size() > 1024) { return "-too long"; } return buffer.readUtf8(); @@ -96,7 +100,7 @@ public class RepeatRequestInterceptor implements Interceptor { try { final Buffer buffer = new Buffer(); body.writeTo(buffer); - if (buffer.size() > 4096) { + if (buffer.size() > 1024) { return "-too long"; } return buffer.readUtf8(); diff --git a/app/src/main/java/com/aoleyun/sn/receiver/NewAppReceiver.java b/app/src/main/java/com/aoleyun/sn/receiver/NewAppReceiver.java index 53d6df2..e6ba966 100644 --- a/app/src/main/java/com/aoleyun/sn/receiver/NewAppReceiver.java +++ b/app/src/main/java/com/aoleyun/sn/receiver/NewAppReceiver.java @@ -96,6 +96,7 @@ public class NewAppReceiver extends BroadcastReceiver { public void onNext(@NonNull String s) { Log.e(TAG, "sendAppInfo: onNext: " + s); JGYUtils.getInstance().checkForceDownload(); + NetInterfaceManager.getInstance().getAppLimit(); NetInterfaceManager.getInstance().getDefaultDesktop(); NetInterfaceManager.getInstance().sendInstalledAppInfo(new NetInterfaceManager.onCompleteCallback() { @Override diff --git a/app/src/main/java/com/aoleyun/sn/service/StepService.java b/app/src/main/java/com/aoleyun/sn/service/StepService.java index b79fe6f..53794e8 100644 --- a/app/src/main/java/com/aoleyun/sn/service/StepService.java +++ b/app/src/main/java/com/aoleyun/sn/service/StepService.java @@ -18,6 +18,7 @@ import androidx.annotation.Nullable; import com.alibaba.fastjson.JSONObject; import com.aoleyun.sn.BuildConfig; +import com.aoleyun.sn.utils.JGYUtils; import com.blankj.utilcode.util.NetworkUtils; import com.aoleyun.sn.KeepAliveConnection; import com.aoleyun.sn.utils.ServiceAliveUtils; @@ -46,7 +47,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus @Override public void onConnected(NetworkUtils.NetworkType networkType) { - connect(); +// connect(); } //用于Activity和service通讯 @@ -134,6 +135,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus case Intent.ACTION_BOOT_COMPLETED: case Intent.ACTION_USER_PRESENT: case Intent.ACTION_SCREEN_ON: + mHandler.post(heartBeatRunnable);//开启心跳检测 sendMsg(1); break; case Intent.ACTION_SCREEN_OFF: @@ -185,8 +187,9 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus Log.i("JWebSocketClientService", "websocket连接关闭"); // client.close(); // initSocketClient(); - mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 - + if (JGYUtils.getInstance().isScreenOn()) { + mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 + } } @Override @@ -195,8 +198,11 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus Log.i("JWebSocketClientService", "websocket连接错误:" + ex.getMessage()); // client.close(); // initSocketClient(); - mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 - + if (JGYUtils.getInstance().isScreenOn()) { + mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 + } else { + Log.i("JWebSocketClientService", "postDelayed off"); + } } }; connect(); @@ -219,7 +225,6 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus } } }.start(); - } /** @@ -285,7 +290,11 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus sendMsg(); } else if (client.isClosed()) { Log.i("JWebSocketClientService", "websocket重连中"); - reconnectWs(); + if (JGYUtils.getInstance().isScreenOn()) { + reconnectWs(); + } else { + Log.i("JWebSocketClientService", "reconnectWs off"); + } } } else { //如果client已为空,重新初始化连接 @@ -293,7 +302,11 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus initSocketClient(); } //每隔一定的时间,对长连接进行一次心跳检测 - mHandler.postDelayed(this, HEART_BEAT_RATE); + if (JGYUtils.getInstance().isScreenOn()) { + mHandler.postDelayed(this, HEART_BEAT_RATE); + } else { + Log.i("JWebSocketClientService", "websocket息屏不重连"); + } } }; @@ -314,4 +327,4 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus } }.start(); } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/aoleyun/sn/service/main/MainSContact.java b/app/src/main/java/com/aoleyun/sn/service/main/MainSContact.java index de5299c..cb073af 100644 --- a/app/src/main/java/com/aoleyun/sn/service/main/MainSContact.java +++ b/app/src/main/java/com/aoleyun/sn/service/main/MainSContact.java @@ -3,37 +3,49 @@ package com.aoleyun.sn.service.main; import com.aoleyun.sn.base.BasePresenter; import com.aoleyun.sn.base.BaseView; +import java.util.List; + public class MainSContact { public interface Presenter extends BasePresenter { - void sendNetwork(); /*分支1*/ /*获取设备锁定状态*/ - void getLockedState(String key); + void getLockedState(); /*设置极光推送标签*/ void setPushTags(); - /*获取设备批次*/ - void getDeviceBatch(); /*分支2 基本信息*/ /*是否第一次联网*/ void getFirstConnect(); /*获取学生信息*/ - void getStudesInfo(boolean refresh); + void getStudesInfo(); /*分支3 上传信息*/ + /*上传联网时间*/ + void sendNetwork(List time); /*发送mac地址*/ - void sendMACAddress(); + void sendMacAddress(); /*更新设备信息*/ void updateDeviceInfo(); /*上传安装的应用列表*/ void sendInstalled(); - - /*分支4 获取应用*/ /*获取设备信息更新*/ void checkAoleyunUpdate(); /*获取测试应用更新*/ void checkTestUpdate(); + + /*分支4 根据SN获取*/ + /*获取开发者选项*/ + void getDeveloper(); + /*获取自定义内置app*/ + void getRomApp(); + /*获取屏幕锁状态*/ + void getScreenLockState(); + + + /*分支5 根据批次获取*/ + /*获取设备后台设置*/ + void getSystemSettingBegin(); /*获取可被写入的安装包名*/ void getAppLimit(); /*获取强制下载apk*/ @@ -42,16 +54,8 @@ public class MainSContact { void getDefaultDesktop(); /*设置开机动画*/ void setLogoImg(); - - /*分支5 获取管控*/ - /*获取开发者选项*/ - void getDeveloper(); - /*获取设备后台设置*/ - void getSystemSettingBegin(); /*获取所有app详细信息*/ void getAllAppList(); - /*获取自定义内置app*/ - void getROMApp(); /*获取浏览器书签设置管控*/ void getBrowserBookmarks(); /*设置白名单的url 单独*/ @@ -63,11 +67,11 @@ public class MainSContact { /*获取禁用app*/ void getSnAppAttr(); /*获取第三方应用子页面ID连网限制*/ - void getAppIDControl(); + void getAppIdControl(); /*获取第三方应用内部网页跳转屏蔽*/ void setAppinsideWeb(); /*获取系统其他管控设置*/ - void setSystemSetting(); + void getSystemSetting(); /*获取系统默认程序设置*/ void getDefaultApp(); /*应用霸屏*/ @@ -77,23 +81,16 @@ public class MainSContact { /*获取时间管控*/ void getSnTimeControl(); /*获取电子书包激活码*/ - void getEBagCode(); + void getEbagCode(); /*获取wifi密码*/ void getWiFiPasswd(); - - /*获取屏幕锁状态*/ - void getScreenLockState(); } public interface MainView extends BaseView { - void sendNetworkFinish(); - /*获取设备锁定状态*/ void setLockedState(boolean loocked); /*设置极光推送标签*/ void setTagsFinish(boolean noTag); - /*获取设备批次结束*/ - void getDeviceBatchFinish(); /*是否第一次联网*/ @@ -101,8 +98,10 @@ public class MainSContact { /*获取学生信息*/ void setStudesInfo(); + /*上传联网时间*/ + void sendNetworkFinish(); /*发送mac地址*/ - void sendMACFinish(); + void sendMacFinish(); /*更新设备信息*/ void updateDeviceInfoFinish(); /*上传安装的应用列表*/ @@ -112,6 +111,15 @@ public class MainSContact { void checkAoleyunUpdateFinish(); /*获取测试应用更新*/ void checkTestUpdateFinish(); + /*获取开发者选项结束*/ + void getDeveloperFinish(); + /*获取自定义内置app*/ + void getRomAppFinish(); + /*设置屏幕锁状态结束*/ + void setScreenLockStateFinish(boolean locked, String tips); + + /*设置设备后台设置*/ + void setSystemSetting(); /*获取可被写入的安装包名结束*/ void getAppLimitFinish(); /*获取强制下载apk结束*/ @@ -120,15 +128,8 @@ public class MainSContact { void getDefaultDesktopFinish(); /*设置开机动画*/ void setLogoImgFinish(); - - /*获取开发者选项结束*/ - void getDeveloperFinish(); - /*设置设备后台设置*/ - void setSystemSetting(); /*获取所有app详细信息*/ void getAllAppListFinish(); - /*获取自定义内置app*/ - void getROMAppFinish(); /*获取浏览器书签设置管控结束*/ void getBrowserBookmarksFinish(); /*设置白名单的url 单独*/ @@ -140,11 +141,11 @@ public class MainSContact { /*获取禁用app*/ void getSnAppAttrFinish(); /*获取第三方应用子页面ID连网限制结束*/ - void getAppIDControlFinish(); + void getAppIdControlFinish(); /*获取第三方应用内部网页跳转屏蔽结束*/ void setAppinsideWebFinish(); /*获取系统其他管控设置结束*/ - void setSystemSettingFinish(); + void getSystemSettingFinish(); /*获取系统默认程序设置*/ void setDefaultAppFinish(); /*获取应用霸屏结束*/ @@ -154,11 +155,9 @@ public class MainSContact { /*获取时间管控*/ void getSnTimeControlFinish(); /*获取电子书包激活码*/ - void getEBagCodeFinish(); + void getEbagCodeFinish(); /*获取wifi密码结束*/ void setWiFiPasswd(); - /*设置屏幕锁状态结束*/ - void setScreenLockStateFinish(boolean locked, String tips); } } diff --git a/app/src/main/java/com/aoleyun/sn/service/main/MainSPresenter.java b/app/src/main/java/com/aoleyun/sn/service/main/MainSPresenter.java index 6f591a6..fd63ab4 100644 --- a/app/src/main/java/com/aoleyun/sn/service/main/MainSPresenter.java +++ b/app/src/main/java/com/aoleyun/sn/service/main/MainSPresenter.java @@ -3,6 +3,7 @@ package com.aoleyun.sn.service.main; import android.content.ContentResolver; import android.content.Context; import android.provider.Settings; +import android.text.TextUtils; import android.util.Log; import com.aoleyun.sn.bean.BaseResponse; @@ -11,17 +12,17 @@ import com.aoleyun.sn.comm.CommonConfig; import com.aoleyun.sn.comm.JGYActions; import com.aoleyun.sn.disklrucache.CacheHelper; import com.aoleyun.sn.network.NetInterfaceManager; +import com.aoleyun.sn.network.UrlAddress; import com.aoleyun.sn.utils.JGYUtils; import com.aoleyun.sn.utils.SPUtils; import com.aoleyun.sn.utils.ToastUtil; import com.aoleyun.sn.utils.URLUtils; import com.aoleyun.sn.utils.Utils; -import com.arialyy.aria.orm.annotation.Ignore; import com.tencent.mmkv.MMKV; import com.trello.rxlifecycle4.RxLifecycle; import com.trello.rxlifecycle4.android.ActivityEvent; -import java.util.Set; +import java.util.List; import io.reactivex.rxjava3.annotations.NonNull; import io.reactivex.rxjava3.core.Observer; @@ -69,59 +70,18 @@ public class MainSPresenter implements MainSContact.Presenter { this.mView = null; } - private boolean requesting = false; - - public boolean isRequesting() { - return requesting; - } - - public void setRequesting(boolean requesting) { - this.requesting = requesting; - } - - public long responseTime; - - @Override - public void sendNetwork() { - NetInterfaceManager.getInstance().GetNetworkConnectControl() - .compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY)) - .subscribe(new Observer() { - @Override - public void onSubscribe(@NonNull Disposable d) { - Log.e("sendNetwork", "onSubscribe: "); - } - - @Override - public void onNext(@NonNull BaseResponse baseResponse) { - Log.e("sendNetwork", "onNext: " + baseResponse); - } - - @Override - public void onError(@NonNull Throwable e) { - Log.e("sendNetwork", "onError: "); - } - - @Override - public void onComplete() { - Log.e("sendNetwork", "onComplete: "); - } - }); - } - /** * 1 */ @Override - public void getLockedState(String key) { - Log.e(TAG, "getLockedState: " + key); + public void getLockedState() { + Log.e(TAG, "getLockedState: "); if (JGYUtils.getInstance().isAihuaFramwwork()) { int aihuaUnlock = Settings.System.getInt(mContext.getContentResolver(), CommonConfig.AIHUA_UNLOCK, 0); if (aihuaUnlock == 1) { return; } } - requesting = true; - responseTime = System.currentTimeMillis(); NetInterfaceManager.getInstance() .getLockedState(getLifecycle(), new NetInterfaceManager.onCompleteCallback() { @Override @@ -129,30 +89,31 @@ public class MainSPresenter implements MainSContact.Presenter { Log.e("getLockedState", "onComplete: "); int locked = Settings.System.getInt(crv, JGYActions.ACTION_QCH_UNLOCK_IPAD, JGYActions.FRAME_CODE_LOCKED); Log.e("getLockedState", "locked: " + locked); + if (locked == 0) { + JGYUtils.getInstance().deleteOtherApp(); + } mView.setLockedState(locked == JGYActions.FRAME_CODE_LOCKED); } }); } - @Override public void setPushTags() { - Set tagSets = mMMKV.decodeStringSet(CommonConfig.DEVICES_TAG + "pushset"); + NetInterfaceManager.getInstance().setPushTags(false, getLifecycle(), new NetInterfaceManager.PushTagCallback() { + @Override + public void setPushTag(String tag) { + mView.setTagsFinish(TextUtils.isEmpty(tag)); + } + }); + String tagSets = mMMKV.decodeString(CommonConfig.DEVICES_TAG); Log.e("setPushTags", "onComplete: tagSets =" + tagSets); - String tags = cacheHelper.getAsString(CommonConfig.DEVICES_TAG); + String tags = cacheHelper.getAsString(UrlAddress.GET_DEVICES_TAGS); Log.e("setPushTags", "onComplete: tags = " + tags); - mView.setTagsFinish(tagSets == null || tagSets.size() < 2); } - @Override - public void getDeviceBatch() { - int locked = Settings.System.getInt(mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, 0); - Log.e(TAG, "getDeviceBatch: " + locked); - if (locked == 0) { - JGYUtils.getInstance().deleteOtherApp(); - mView.getDeviceBatchFinish(); - } - } + /* + * 2 + */ /** * 第一次连接 @@ -164,15 +125,11 @@ public class MainSPresenter implements MainSContact.Presenter { mView.setFirstConnect(first == 0); } - /** - * 2 - */ - /** * 通过sn获取用户信息 */ @Override - public void getStudesInfo(boolean refresh) { + public void getStudesInfo() { NetInterfaceManager.getInstance().getStudesInfo(false, getLifecycle(), new NetInterfaceManager.StudesInfoListener() { @Override public void setStudentsInfo(StudentsInfo studentsInfo) { @@ -186,16 +143,54 @@ public class MainSPresenter implements MainSContact.Presenter { }); } + @Override + public void sendNetwork(List time) { + if (time == null || time.size() == 0) { + Log.e(TAG, "sendNetwork: " + "time empty"); + return; + } + NetInterfaceManager.getInstance().GetNetworkConnectControl(time.toString()) + .compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY)) + .subscribe(new Observer() { + @Override + public void onSubscribe(@NonNull Disposable d) { + Log.e("sendNetwork", "onSubscribe: "); + } + + @Override + public void onNext(@NonNull BaseResponse baseResponse) { + Log.e("sendNetwork", "onNext: " + baseResponse); + if (baseResponse.code == 200) { + JGYUtils.getInstance().removeNetworkConnectedTime(time); + } else { + + } + } + + @Override + public void onError(@NonNull Throwable e) { + Log.e("sendNetwork", "onError: "); + onComplete(); + } + + @Override + public void onComplete() { + Log.e("sendNetwork", "onComplete: "); + mView.sendNetworkFinish(); + } + }); + } + /** * 3 */ @Override - public void sendMACAddress() { + public void sendMacAddress() { NetInterfaceManager.getInstance().sendMACAddress(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() { @Override public void onComplete() { - mView.sendMACFinish(); + mView.sendMacFinish(); } }); } @@ -226,7 +221,6 @@ public class MainSPresenter implements MainSContact.Presenter { }); } - /** * 4 */ @@ -240,9 +234,9 @@ public class MainSPresenter implements MainSContact.Presenter { mView.checkAoleyunUpdateFinish(); } }); +// mView.checkAoleyunUpdateFinish(); } - @Override public void checkTestUpdate() { NetInterfaceManager.getInstance() @@ -254,6 +248,51 @@ public class MainSPresenter implements MainSContact.Presenter { }); } + /** + * 5 + */ + @Override + public void getDeveloper() { + NetInterfaceManager.getInstance() + .getDeveloper(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() { + @Override + public void onComplete() { + mView.getDeveloperFinish(); + } + }); + } + + @Override + public void getRomApp() { + String customVersion = Utils.getCustomVersion(); + Log.e(TAG, "getROMApp: " + customVersion); + NetInterfaceManager.getInstance() + .getCustomROMApp(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() { + @Override + public void onComplete() { + mView.getRomAppFinish(); + } + }); + } + + @Override + public void getScreenLockState() { + NetInterfaceManager.getInstance().getScreenLockState(true, getLifecycle(), new NetInterfaceManager.ScreenLockStateListener() { + @Override + public void setScreenLockState(boolean locked, String tips) { + mView.setScreenLockStateFinish(locked, tips); + } + }); + } + + @Override + public void getSystemSettingBegin() { + //重置设备 + JGYUtils.getInstance().resetDevice(); + ToastUtil.betaShow("开始获取管控"); + mView.setSystemSetting(); + } + @Override public void getAppLimit() { NetInterfaceManager.getInstance() @@ -312,29 +351,6 @@ public class MainSPresenter implements MainSContact.Presenter { } } - - /** - * 5 - */ - @Override - public void getDeveloper() { - NetInterfaceManager.getInstance() - .getDeveloper(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() { - @Override - public void onComplete() { - mView.getDeveloperFinish(); - } - }); - } - - @Override - public void getSystemSettingBegin() { - //重置设备 - JGYUtils.getInstance().resetDevice(); - ToastUtil.betaShow("开始获取管控"); - mView.setSystemSetting(); - } - @Override public void getAllAppList() { NetInterfaceManager.getInstance() @@ -346,19 +362,6 @@ public class MainSPresenter implements MainSContact.Presenter { }); } - @Override - public void getROMApp() { - String customVersion = Utils.getCustomVersion(); - Log.e(TAG, "getROMApp: " + customVersion); - NetInterfaceManager.getInstance() - .getCustomROMApp(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() { - @Override - public void onComplete() { - mView.getROMAppFinish(); - } - }); - } - @Override public void getBrowserBookmarks() { NetInterfaceManager.getInstance() @@ -411,12 +414,12 @@ public class MainSPresenter implements MainSContact.Presenter { } @Override - public void getAppIDControl() { + public void getAppIdControl() { NetInterfaceManager.getInstance() .getAppIDControl(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() { @Override public void onComplete() { - mView.getAppIDControlFinish(); + mView.getAppIdControlFinish(); } }); } @@ -436,12 +439,12 @@ public class MainSPresenter implements MainSContact.Presenter { } @Override - public void setSystemSetting() { + public void getSystemSetting() { NetInterfaceManager.getInstance() .setSystemSetting(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() { @Override public void onComplete() { - mView.setSystemSettingFinish(); + mView.getSystemSettingFinish(); } }); } @@ -499,17 +502,16 @@ public class MainSPresenter implements MainSContact.Presenter { } @Override - public void getEBagCode() { + public void getEbagCode() { NetInterfaceManager.getInstance() .getEBagCode(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() { @Override public void onComplete() { - mView.getEBagCodeFinish(); + mView.getEbagCodeFinish(); } }); } - @Override public void getWiFiPasswd() { NetInterfaceManager.getInstance() @@ -520,14 +522,4 @@ public class MainSPresenter implements MainSContact.Presenter { } }); } - - @Override - public void getScreenLockState() { - NetInterfaceManager.getInstance().getScreenLockState(true, getLifecycle(), new NetInterfaceManager.ScreenLockStateListener() { - @Override - public void setScreenLockState(boolean locked, String tips) { - mView.setScreenLockStateFinish(locked, tips); - } - }); - } } diff --git a/app/src/main/java/com/aoleyun/sn/service/main/MainService.java b/app/src/main/java/com/aoleyun/sn/service/main/MainService.java index 431859a..b026472 100644 --- a/app/src/main/java/com/aoleyun/sn/service/main/MainService.java +++ b/app/src/main/java/com/aoleyun/sn/service/main/MainService.java @@ -43,7 +43,6 @@ import com.aoleyun.sn.bean.PoweroffBean; import com.aoleyun.sn.comm.CommonConfig; import com.aoleyun.sn.comm.JGYActions; import com.aoleyun.sn.comm.PackageNames; -import com.aoleyun.sn.manager.ConnectManager; import com.aoleyun.sn.network.NetInterfaceManager; import com.aoleyun.sn.rlog.LogDBManager; import com.aoleyun.sn.utils.ApkUtils; @@ -76,6 +75,7 @@ import java.util.Arrays; import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; import io.reactivex.rxjava3.core.Observable; @@ -103,23 +103,15 @@ public class MainService extends Service implements MainSContact.MainView, Netwo Aria.download(this).resumeAllTask(); String WiFiAlias = Utils.getWifiAlias(this); Log.e("OnNetworkStatusChanged", "onConnected: " + WiFiAlias); - - if (!checkAoleyunApp()) { - mPresenter.checkAoleyunUpdate(); - } - Utils.getPublicIP(this); - TimeTask task = new TimeTask(); - task.execute("ntp.aliyun.com"); - mPresenter.sendNetwork(); + JGYUtils.getInstance().addNetworkConnectedTime(System.currentTimeMillis() / 1000); if (JGYUtils.getInstance().isScreenOn()) { - mPresenter.getLockedState("onConnected"); + TimeTask task = new TimeTask(); + task.execute("ntp.aliyun.com"); + if (!checkAoleyunApp()) { + mPresenter.checkAoleyunUpdate(); + } + mPresenter.getLockedState(); } -// if (mMMKV.decodeInt(CommonConfig.DEVICES_FRIST_START, 1) == 1) { -// Intent intent = new Intent(this, CheckNetActivity.class); -// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); -// startActivity(intent); -// } - } private class TimeTask extends AsyncTask { @@ -150,18 +142,13 @@ public class MainService extends Service implements MainSContact.MainView, Netwo public void onSuccess(Object data, int flag) { //token在设备卸载重装的时候有可能会变 Log.e("TPush", "注册成功,设备token为:" + data); + List accountInfoList = new ArrayList<>(); accountInfoList.add(new XGPushManager.AccountInfo(XGPushManager.AccountType.CUSTOM.getValue(), Utils.getSerial(MainService.this))); XGPushManager.upsertAccounts(MainService.this, accountInfoList, new XGIOperateCallback() { @Override public void onSuccess(Object data, int flag) { Log.e("TPush", "onSuccess, data:" + data + ", flag:" + flag); - NetInterfaceManager.getInstance().setPushTags(false, lifecycleSubject, new NetInterfaceManager.onCompleteCallback() { - @Override - public void onComplete() { - Log.e("TimeTask", "onComplete: "); - } - }); } @Override @@ -169,6 +156,28 @@ public class MainService extends Service implements MainSContact.MainView, Netwo Log.e("TPush", "onFail, data:" + data + ", code:" + errCode + ", msg:" + msg); } }); + NetInterfaceManager.getInstance().setPushTags(false, lifecycleSubject, new NetInterfaceManager.PushTagCallback() { + @Override + public void setPushTag(String tag) { + Set tagSets = new HashSet<>(); + if (!TextUtils.isEmpty(tag)) { + tagSets.add(tag); + } + JGYUtils.getInstance().getAppPlatform(new JGYUtils.GetAppPlatformCallback() { + @Override + public void AppPlatform(int platform) { + if (platform == JGYUtils.MTKPlatform) { + tagSets.add(JGYUtils.MTKTag); + } else if (platform == JGYUtils.ZhanruiPlatform) { + tagSets.add(JGYUtils.ZhanruiTag); + } else if (platform == JGYUtils.CubePlatform) { + tagSets.add(JGYUtils.CubeTag); + } + } + }); + NetInterfaceManager.getInstance().clearAndAppendTags(tagSets); + } + }); } @Override @@ -282,7 +291,41 @@ public class MainService extends Service implements MainSContact.MainView, Netwo String action = intent.getAction(); Log.e("RefreshReceiver", "onReceive: " + action); if (!TextUtils.isEmpty(action)) { - mPresenter.getLockedState("refresh"); + mPresenter.getLockedState(); + } + } + } + + private ScreenLockReceiver screenLockReceiver; + + private void registerScreenLockReceiver() { + if (null == screenLockReceiver) { + screenLockReceiver = new ScreenLockReceiver(); + } + IntentFilter filter = new IntentFilter(); + filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); + filter.addAction(Intent.ACTION_SCREEN_ON); + filter.addAction(Intent.ACTION_SCREEN_OFF); + registerReceiver(screenLockReceiver, filter); + } + + private class ScreenLockReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + Log.e(TAG, "onReceive:" + action); + if (TextUtils.isEmpty(action)) { + Log.e(TAG, "onReceive: is NULL"); + return; + } + switch (action) { + case Intent.ACTION_SCREEN_ON: + mPresenter.sendNetwork(JGYUtils.getInstance().getNetworkConnectedTime()); + break; + case Intent.ACTION_SCREEN_OFF: + break; + default: + break; } } } @@ -312,10 +355,9 @@ public class MainService extends Service implements MainSContact.MainView, Netwo mPresenter = new MainSPresenter(this); mPresenter.attachView(this); mPresenter.setLifecycle(lifecycleSubject); - TimeTask task = new TimeTask(); task.execute("ntp.aliyun.com"); - mPresenter.getLockedState("onCreate"); + mPresenter.getLockedState(); //根据要求卸载这两个应用 if (!JGYUtils.getInstance().getDeviceIsLocked()) { @@ -454,6 +496,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo registerTimeReceiver(); registerInstallReceiver(); registerRefreshReceiver(); + registerScreenLockReceiver(); } private void unRegisterReceivers() { @@ -472,6 +515,9 @@ public class MainService extends Service implements MainSContact.MainView, Netwo if (null != mRefreshReceiver) { unregisterReceiver(mRefreshReceiver); } + if (null != screenLockReceiver) { + unregisterReceiver(screenLockReceiver); + } } private static WindowManager windowManager; @@ -506,7 +552,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo TextView textView = topView.findViewById(R.id.textView); textView.setText(name); } else { - if (topView.getTag().equals("added")) { + if ("added".equals(topView.getTag())) { TextView textView = topView.findViewById(R.id.textView); textView.setText(name); return; @@ -665,7 +711,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo setFloatingWindow(); } else if (ACTION_UPDATE.equals(intent.getAction())) { setFloatingWindow(); - mPresenter.getScreenLockState(); +// mPresenter.getScreenLockState(); Log.e("TimeChangedReceiver", "onReceive:" + "date update"); } timeChangedStart.onstar(System.currentTimeMillis()); @@ -712,6 +758,40 @@ public class MainService extends Service implements MainSContact.MainView, Netwo } } + synchronized private void setFloatingWindow() { + Log.e(TAG, "setFloatingWindow: "); + long nowTime = System.currentTimeMillis(); + mTopApp.open(nowTime); +// ForegroundAppUtil.openTopApp(MainService.this); + TimeUtils.ContralTime contralTime = TimeUtils.getDefaltContralTime(this); + Log.e(TAG, "setFloatingWindow: " + contralTime); + Log.e(TAG, "setFloatingWindow: screenlocked: " + screenlocked); + if (null != contralTime) { + if (contralTime.inControlTime(nowTime)) { + Log.e(TAG, "setFloatingWindow: " + "inControlTime is true"); + if (!screenlocked) { + showFloatingWindow("设备可用时间:" + contralTime.toString()); + } else { + TextView textView = topView.findViewById(R.id.textView); + textView.setText("设备可用时间:" + contralTime.toString()); + } + timelocked = true; + } else { + Log.e(TAG, "setFloatingWindow: " + "inControlTime is false"); + if (!screenlocked) { + hideFloatingWindow(); + } + timelocked = false; + } + } else { + Log.e(TAG, "setFloatingWindow: " + "inControlTime is null"); + if (!screenlocked) { + hideFloatingWindow(); + } + timelocked = false; + } + } + private interface TopApp { void open(Long time); } @@ -748,39 +828,6 @@ public class MainService extends Service implements MainSContact.MainView, Netwo } }; - synchronized private void setFloatingWindow() { - Log.e(TAG, "setFloatingWindow: "); - long nowTime = System.currentTimeMillis(); - mTopApp.open(nowTime); -// ForegroundAppUtil.openTopApp(MainService.this); - TimeUtils.ContralTime contralTime = TimeUtils.getDefaltContralTime(this); - Log.e(TAG, "setFloatingWindow: " + contralTime); - Log.e(TAG, "setFloatingWindow: screenlocked: " + screenlocked); - if (null != contralTime) { - if (contralTime.inControlTime(nowTime)) { - Log.e(TAG, "setFloatingWindow: " + "inControlTime is true"); - if (!screenlocked) { - showFloatingWindow("设备可用时间:" + contralTime.toString()); - } else { - TextView textView = topView.findViewById(R.id.textView); - textView.setText("设备可用时间:" + contralTime.toString()); - } - timelocked = true; - } else { - Log.e(TAG, "setFloatingWindow: " + "inControlTime is false"); - if (!screenlocked) { - hideFloatingWindow(); - } - timelocked = false; - } - } else { - Log.e(TAG, "setFloatingWindow: " + "inControlTime is null"); - if (!screenlocked) { - hideFloatingWindow(); - } - timelocked = false; - } - } private void registerInstallReceiver() { if (mInstallReceiver == null) { @@ -790,12 +837,13 @@ public class MainService extends Service implements MainSContact.MainView, Netwo registerReceiver(mInstallReceiver, intentFilter, INSTALLAPK_PREMISSIONS, null); } - private String INSTALLAPK_ACTION = "JGY_INSTALLAPK_ACTION"; - private String INSTALLAPK_PREMISSIONS = "com.aoleyun.sn.permissions.INSTALL_APK"; + private static final String INSTALLAPK_ACTION = "JGY_INSTALLAPK_ACTION"; + private static final String INSTALLAPK_PREMISSIONS = "com.aoleyun.sn.permissions.INSTALL_APK"; private InstallReceiver mInstallReceiver; /** + * 安装第三方的应用 * https://blog.csdn.net/jdsjlzx/article/details/82630113 */ class InstallReceiver extends BroadcastReceiver { @@ -843,11 +891,6 @@ public class MainService extends Service implements MainSContact.MainView, Netwo } } - @Override - public void sendNetworkFinish() { - - } - @Override public void setLockedState(boolean loocked) { Log.e(TAG, "setLockedState: " + loocked); @@ -855,15 +898,16 @@ public class MainService extends Service implements MainSContact.MainView, Netwo ToastUtil.betaShow("设备已上锁"); // sendSimpleNotification(); mPresenter.setPushTags(); - mPresenter.getDeveloper(); ApkUtils.UninstallAPP(this, "com.joytv.live"); ApkUtils.UninstallAPP(this, "com.tencent.android.qqdownloader"); } else { ToastUtil.betaShow("设备已解锁"); - notificationManager.cancel(NotificationID); +// notificationManager.cancel(NotificationID); SysSettingUtils.setEnableSetting(this); - mPresenter.checkAoleyunUpdate(); } + mPresenter.sendMacAddress(); + + //更新主页锁定状态 Intent intent = new Intent(MainActivity.UPDATE_LOCKED_STATUS); sendBroadcast(intent); } @@ -875,13 +919,10 @@ public class MainService extends Service implements MainSContact.MainView, Netwo Log.e(TAG, "setTagsFinish: " + "not set tag"); // mPresenter.getStudesInfo(true); } else { - mPresenter.getDeviceBatch(); + mPresenter.getFirstConnect(); } - } - - @Override - public void getDeviceBatchFinish() { - mPresenter.getFirstConnect(); + mPresenter.getStudesInfo(); + mPresenter.getDeveloper(); } /** @@ -896,20 +937,22 @@ public class MainService extends Service implements MainSContact.MainView, Netwo Log.e(TAG, "setDisableSetting: "); //设置系统管控 SysSettingUtils.setDisableSetting(this); - } else { - } - mPresenter.getStudesInfo(true); + mPresenter.getSystemSettingBegin(); } @Override public void setStudesInfo() { Log.e(TAG, "setStudesInfo: " + "基本信息获取完毕"); - mPresenter.sendMACAddress(); } @Override - public void sendMACFinish() { + public void sendNetworkFinish() { + Log.e(TAG, "sendNetworkFinish: " ); + } + + @Override + public void sendMacFinish() { mPresenter.updateDeviceInfo(); } @@ -931,6 +974,40 @@ public class MainService extends Service implements MainSContact.MainView, Netwo @Override public void checkTestUpdateFinish() { + Log.e(TAG, "checkTestUpdateFinish: "); + } + + @Override + public void getDeveloperFinish() { + mPresenter.getRomApp(); + } + + @Override + public void getRomAppFinish() { + mPresenter.getScreenLockState(); + } + + @Override + public void setScreenLockStateFinish(boolean locked, String tips) { + if (locked) { + if (!timelocked) { + showFloatingWindow(tips); + } + screenlocked = true; + SPUtils.put(this, "is_screen_lock", true); + SPUtils.put(this, "screen_tips", tips); + } else { + if (!timelocked) { + hideFloatingWindow(); + } + screenlocked = false; + SPUtils.put(this, "is_screen_lock", false); + SPUtils.put(this, "screen_tips", ""); + } + } + + @Override + public void setSystemSetting() { mPresenter.getAppLimit(); } @@ -951,28 +1028,11 @@ public class MainService extends Service implements MainSContact.MainView, Netwo @Override public void setLogoImgFinish() { - mPresenter.setRequesting(false); - Log.e(TAG, "setLogoImgFinish: "); - Log.e(TAG, "SettingFinish: " + (System.currentTimeMillis() - mPresenter.responseTime) + " ms"); - } - - @Override - public void getDeveloperFinish() { - mPresenter.getSystemSettingBegin(); - } - - @Override - public void setSystemSetting() { mPresenter.getAllAppList(); } @Override public void getAllAppListFinish() { - mPresenter.getROMApp(); - } - - @Override - public void getROMAppFinish() { mPresenter.getBrowserBookmarks(); } @@ -998,21 +1058,21 @@ public class MainService extends Service implements MainSContact.MainView, Netwo @Override public void getSnAppAttrFinish() { - mPresenter.getAppIDControl(); + mPresenter.getAppIdControl(); } @Override - public void getAppIDControlFinish() { + public void getAppIdControlFinish() { mPresenter.setAppinsideWeb(); } @Override public void setAppinsideWebFinish() { - mPresenter.setSystemSetting(); + mPresenter.getSystemSetting(); } @Override - public void setSystemSettingFinish() { + public void getSystemSettingFinish() { mPresenter.getDefaultApp(); } @@ -1033,37 +1093,16 @@ public class MainService extends Service implements MainSContact.MainView, Netwo @Override public void getSnTimeControlFinish() { - mPresenter.getEBagCode(); + mPresenter.getEbagCode(); } @Override - public void getEBagCodeFinish() { + public void getEbagCodeFinish() { mPresenter.getWiFiPasswd(); } @Override public void setWiFiPasswd() { - mPresenter.setRequesting(false); Log.e(TAG, "setWiFiPasswd: "); - Log.e(TAG, "SettingFinish: " + (System.currentTimeMillis() - mPresenter.responseTime) + " ms"); - } - - @Override - public void setScreenLockStateFinish(boolean locked, String tips) { - if (locked) { - if (!timelocked) { - showFloatingWindow(tips); - } - screenlocked = true; - SPUtils.put(this, "is_screen_lock", true); - SPUtils.put(this, "screen_tips", tips); - } else { - if (!timelocked) { - hideFloatingWindow(); - } - screenlocked = false; - SPUtils.put(this, "is_screen_lock", false); - SPUtils.put(this, "screen_tips", ""); - } } } diff --git a/app/src/main/java/com/aoleyun/sn/utils/AES/AesCbcWithIntegrity.java b/app/src/main/java/com/aoleyun/sn/utils/AES/AesCbcWithIntegrity.java index cf607b4..101adb1 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/AES/AesCbcWithIntegrity.java +++ b/app/src/main/java/com/aoleyun/sn/utils/AES/AesCbcWithIntegrity.java @@ -282,7 +282,7 @@ public class AesCbcWithIntegrity { aesCipherForEncryption.init(Cipher.ENCRYPT_MODE, secretKeys.getConfidentialityKey(), new IvParameterSpec(iv)); /* - * Now we get back the IV that will actually be used. Some Android + * Now we get bt_return the IV that will actually be used. Some Android * versions do funny stuff w/ the IV, so this is to work around bugs: */ iv = aesCipherForEncryption.getIV(); diff --git a/app/src/main/java/com/aoleyun/sn/utils/ApkUtils.java b/app/src/main/java/com/aoleyun/sn/utils/ApkUtils.java index cadf5ba..23c4f51 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/ApkUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/ApkUtils.java @@ -427,7 +427,6 @@ public class ApkUtils { ToastUtil.show("正在安装应用"); install(packageInstaller, sessionId, context); } - } } @@ -447,7 +446,6 @@ public class ApkUtils { } } - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private static int createSession(PackageInstaller packageInstaller, PackageInstaller.SessionParams sessionParams) { int sessionId = -1; diff --git a/app/src/main/java/com/aoleyun/sn/utils/JGYUtils.java b/app/src/main/java/com/aoleyun/sn/utils/JGYUtils.java index faba1ca..8e6e349 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/JGYUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/JGYUtils.java @@ -51,6 +51,7 @@ import com.aoleyun.sn.comm.CommonConfig; import com.aoleyun.sn.comm.JGYActions; import com.aoleyun.sn.comm.PackageNames; import com.aoleyun.sn.disklrucache.CacheHelper; +import com.aoleyun.sn.gson.GsonUtils; import com.aoleyun.sn.network.NetInterfaceManager; import com.aoleyun.sn.network.UrlAddress; import com.aoleyun.sn.receiver.BootReceiver; @@ -94,6 +95,7 @@ import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.Executor; import java.util.function.Consumer; import java.util.function.Predicate; @@ -107,6 +109,7 @@ public class JGYUtils { @SuppressLint("StaticFieldLeak") private static JGYUtils sInstance; + private MMKV mMMKV = MMKV.defaultMMKV(); private Context mContext; private ContentResolver crv; @@ -136,6 +139,7 @@ public class JGYUtils { this.mContext = context; this.crv = context.getContentResolver(); this.cacheHelper = new CacheHelper(context); + initConnectedTimeCache(); } public static void init(Context context) { @@ -2165,7 +2169,7 @@ public class JGYUtils { jsonObject.addProperty("desktop_version", Utils.getAPPVersionName("com.aoleyun.os", mContext)); jsonObject.addProperty("local_mac", Utils.getAndroid7MAC()); // jsonObject.addProperty("wifi_status", Utils.obtainWifiInfo(mContext)); - jsonObject.addProperty("PN_ip", MMKV.defaultMMKV().decodeString(NetInterfaceManager.PublicIP, "")); + jsonObject.addProperty("PN_ip", mMMKV.decodeString(NetInterfaceManager.PublicIP, "")); jsonObject.addProperty("LAN_ip", Utils.getIPAddress(mContext)); jsonObject.addProperty("bluetooth", Utils.getBluetoothList()); jsonObject.addProperty("wifi_name", Utils.getWifiAlias(mContext)); @@ -2370,4 +2374,43 @@ public class JGYUtils { //true为打开,false为关闭 return powerManager.isInteractive(); } + + private static final String CONNECTED_TIME_KEY = "connectedTimeKey"; + + private List connectedTime; + + private void initConnectedTimeCache() { + String jsonString = cacheHelper.getAsString(CONNECTED_TIME_KEY); + Gson gson = new Gson(); + Type listType = new TypeToken>() { + }.getType(); + List longList = gson.fromJson(jsonString, listType); + if (longList == null) { + connectedTime = new ArrayList<>(); + } else { + connectedTime = longList; + } + } + + public List getNetworkConnectedTime() { + Log.e(TAG, "getNetworkConnectedTime: " + connectedTime); + return connectedTime; + } + + public void addNetworkConnectedTime(Long time) { + Log.e(TAG, "addNetworkConnectedTime: " + time); + connectedTime.add(time); + cacheHelper.put(CONNECTED_TIME_KEY, GsonUtils.toJSONString(connectedTime)); + } + + public void removeNetworkConnectedTime(List time) { + if (time == null || time.size() == 0) { + return; + } + List copy = new ArrayList<>(time); + for (Long l : copy) { + connectedTime.remove(l); + } + cacheHelper.put(CONNECTED_TIME_KEY, GsonUtils.toJSONString(connectedTime)); + } } diff --git a/app/src/main/java/com/aoleyun/sn/utils/StatusBarUtil.java b/app/src/main/java/com/aoleyun/sn/utils/StatusBarUtil.java index 285acbb..75ac728 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/StatusBarUtil.java +++ b/app/src/main/java/com/aoleyun/sn/utils/StatusBarUtil.java @@ -271,7 +271,7 @@ public class StatusBarUtil { decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } else { // We want to change tint color to white again. - // You can also record the flags in advance so that you can turn UI back completely if + // You can also record the flags in advance so that you can turn UI bt_return completely if // you have set other flags before, such as translucent or full screen. decor.setSystemUiVisibility(0); } diff --git a/app/src/main/java/com/aoleyun/sn/utils/Utils.java b/app/src/main/java/com/aoleyun/sn/utils/Utils.java index 3d3d3c0..e747ff3 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/Utils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/Utils.java @@ -1755,20 +1755,6 @@ public class Utils { return "获取失败"; } - /** - * 获取公网IP并保存 - * - * @param context - */ - public static void getPublicIP(Context context) { - NetInterfaceManager.getPublicIP(new NetInterfaceManager.PublicIP() { - @Override - public void set(String ip) { - Log.e("getPublicIP", "set: " + ip); - } - }); - } - /** * 获取WiFi信号强度 * diff --git a/app/src/main/res/drawable-hdpi/back.png b/app/src/main/res/drawable-hdpi/back.png deleted file mode 100644 index 3bb1c10..0000000 Binary files a/app/src/main/res/drawable-hdpi/back.png and /dev/null differ diff --git a/app/src/main/res/drawable-hdpi/bt_return.png b/app/src/main/res/drawable-hdpi/bt_return.png new file mode 100644 index 0000000..df53546 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/bt_return.png differ diff --git a/app/src/main/res/drawable-hdpi/default_head.png b/app/src/main/res/drawable-hdpi/default_head.png new file mode 100644 index 0000000..4dc3c83 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/default_head.png differ diff --git a/app/src/main/res/drawable-hdpi/delimiter.png b/app/src/main/res/drawable-hdpi/delimiter.png new file mode 100644 index 0000000..5b40328 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/delimiter.png differ diff --git a/app/src/main/res/drawable-hdpi/head.png b/app/src/main/res/drawable-hdpi/head.png deleted file mode 100644 index 3e60ede..0000000 Binary files a/app/src/main/res/drawable-hdpi/head.png and /dev/null differ diff --git a/app/src/main/res/drawable-hdpi/icon_battery.png b/app/src/main/res/drawable-hdpi/icon_battery.png new file mode 100644 index 0000000..9817cfd Binary files /dev/null and b/app/src/main/res/drawable-hdpi/icon_battery.png differ diff --git a/app/src/main/res/drawable-hdpi/icon_ipaddress.png b/app/src/main/res/drawable-hdpi/icon_ipaddress.png new file mode 100644 index 0000000..d21913b Binary files /dev/null and b/app/src/main/res/drawable-hdpi/icon_ipaddress.png differ diff --git a/app/src/main/res/drawable-hdpi/icon_wifi.png b/app/src/main/res/drawable-hdpi/icon_wifi.png new file mode 100644 index 0000000..f7cb889 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/icon_wifi.png differ diff --git a/app/src/main/res/drawable-hdpi/more.png b/app/src/main/res/drawable-hdpi/more.png new file mode 100644 index 0000000..7174552 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/more.png differ diff --git a/app/src/main/res/drawable/bg_dialog.xml b/app/src/main/res/drawable/bg_dialog.xml new file mode 100644 index 0000000..64427cc --- /dev/null +++ b/app/src/main/res/drawable/bg_dialog.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/app/src/main/res/drawable/bt_activation_normnl.xml b/app/src/main/res/drawable/bt_activation_normnl.xml new file mode 100644 index 0000000..9cfee8e --- /dev/null +++ b/app/src/main/res/drawable/bt_activation_normnl.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bt_activation_pressed.xml b/app/src/main/res/drawable/bt_activation_pressed.xml new file mode 100644 index 0000000..8551266 --- /dev/null +++ b/app/src/main/res/drawable/bt_activation_pressed.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bt_activation_selector.xml b/app/src/main/res/drawable/bt_activation_selector.xml new file mode 100644 index 0000000..3b50ee2 --- /dev/null +++ b/app/src/main/res/drawable/bt_activation_selector.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bt_trial.xml b/app/src/main/res/drawable/bt_trial.xml new file mode 100644 index 0000000..70d5bee --- /dev/null +++ b/app/src/main/res/drawable/bt_trial.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bt_vip.xml b/app/src/main/res/drawable/bt_vip.xml new file mode 100644 index 0000000..c22d1db --- /dev/null +++ b/app/src/main/res/drawable/bt_vip.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/card_background.xml b/app/src/main/res/drawable/card_background.xml new file mode 100644 index 0000000..039758e --- /dev/null +++ b/app/src/main/res/drawable/card_background.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/join_background.xml b/app/src/main/res/drawable/join_background.xml new file mode 100644 index 0000000..75ac08f --- /dev/null +++ b/app/src/main/res/drawable/join_background.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/joined_background.xml b/app/src/main/res/drawable/joined_background.xml new file mode 100644 index 0000000..5e209a7 --- /dev/null +++ b/app/src/main/res/drawable/joined_background.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml index 9525238..8e205fd 100644 --- a/app/src/main/res/layout-land/activity_main.xml +++ b/app/src/main/res/layout-land/activity_main.xml @@ -8,434 +8,434 @@ android:fitsSystemWindows="true" tools:context=".activity.main.MainActivity"> - + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + + + - - + + + + + + + + + + + + + - + + + + + + + + - + + + + - - + + + + + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + + + + - + + + - + + + + + + + + + + + - + + + + + + + + + + + - - + + + + + + + + + + + - + + + + - + + + + + + + + + + + - + + + + + + + + + + + - - + + + + + + + + + + + - + + + - + + + + + + + + + + + - + + + + + + + + + + + - - + + + + + + + + + + + - + + + + + - + + + + + + + + + + + - + + + + + + + + + + + - - + + + + + + + + + + + - + + + + + - + + + + + + + + + + + - + + + + + + + + + + + - - + + + + + + + + + + + - + + + + + - + + + + + + + + + + + - + + + + + + + + + + - - + + + + + + + + + + + - + + + + - + + + + + + + + + + + - + + + + + + + + + + - - + + + + + + + + + + + -