diff --git a/app/build.gradle b/app/build.gradle index 917dde1..bdde5c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,6 +41,17 @@ android { abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86' // 还可以添加 'armeabi' , 'x86', 'x86_64', 'mips', 'mips64' } + + manifestPlaceholders = [ + XG_ACCESS_ID : "1500026372", + XG_ACCESS_KEY: "AR7A1L5M0LPH", + ] + + buildConfigField "String", "ROOT_URL", '"https://led.aoleyun.cn/api/"' + buildConfigField "String", "SCREEN_BASE_URL", '"https://led.aoleyun.cn:2018/"' + buildConfigField "String", "SCREEN_URL", '"https://led.aoleyun.cn:2018/wm/is_online"' + buildConfigField "String", "WebsocketURL", '"wss://led.aoleyun.cn:2018"' + } lintOptions { @@ -56,64 +67,52 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } - //多版本 + //多渠道 productFlavors { //新平台正式 + newly { + flavorDimensions "default" + versionCode 20 + versionName "2.9" + buildConfigField "String", "platform", '"ZhanRui"' + manifestPlaceholders = [ + AMAP_KEY: "6e339305206eeb43f2b4cc1f31751f89" + ] + } + + //酷比魔方 cube { flavorDimensions "default" versionCode 36 versionName "4.5" - /*********************************极光推送************************************/ + buildConfigField "String", "platform", '"ZhanRuiCube"' manifestPlaceholders = [ - XG_ACCESS_ID : "1500026372", - XG_ACCESS_KEY: "AR7A1L5M0LPH", - -// JPUSH_PKGNAME: "com.aoleyun.sn", -// JPUSH_APPKEY : "79c64ef41b8728ad6aa29af1", //JPush上注册的包名对应的appkey. -// JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可. -// channel_value: "newly", - + AMAP_KEY: "6e339305206eeb43f2b4cc1f31751f89" ] - /*********************************极光推送end************************************/ - buildConfigField "String", "ROOT_URL", '"https://led.aoleyun.cn/api/"' - buildConfigField "String", "SCREEN_BASE_URL", '"https://led.aoleyun.cn:2018/"' - buildConfigField "String", "SCREEN_URL", '"https://led.aoleyun.cn:2018/wm/is_online"' - buildConfigField "String", "WebsocketURL", '"wss://led.aoleyun.cn:2018"' } - //新平台测试 - beta { - versionNameSuffix "-beta" + //MTK + MTKnewly { flavorDimensions "default" - versionCode 1 - versionName "1.0" - /*********************************极光推送************************************/ + versionCode 12 + versionName "2.1" + buildConfigField "String", "platform", '"MTK"' manifestPlaceholders = [ - XG_ACCESS_ID : "1500026372", - XG_ACCESS_KEY: "AR7A1L5M0LPH", -// JPUSH_PKGNAME: "com.aoleyun.sn", -// JPUSH_APPKEY : "79c64ef41b8728ad6aa29af1", //JPush上注册的包名对应的appkey. -// JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可. -// channel_value: "beta", + AMAP_KEY: "1af68e0a7edcaac82678b1cbb7643408" ] - /*********************************极光推送end************************************/ - buildConfigField "String", "ROOT_URL", '"https://led.aoleyun.cn/api/"' - buildConfigField "String", "SCREEN_BASE_URL", '"https://led.aoleyun.cn:2018/"' - buildConfigField "String", "SCREEN_URL", '"https://led.aoleyun.cn:2018/wm/is_online"' - buildConfigField "String", "WebsocketURL", '"wss://led.aoleyun.cn:2018"' } } sourceSets { //测试版的图标 - beta.res.srcDirs = ['src/beta/res'] +// beta.res.srcDirs = ['src/beta/res'] // newly.res.srcDirs = ['src/beta/res'] } //签名 signingConfigs { - alldocube { + zhanRui { storeFile file("keystore/zhanxun.keystore") storePassword "123456" keyAlias "zhanxun" @@ -122,7 +121,7 @@ android { v2SigningEnabled false } - alldocubeDebug { + zhanRuiUserdebug { storeFile file("keystore/zhanxunUserdebug.keystore") storePassword "123456" keyAlias "zhanxunUserdebug" @@ -130,36 +129,74 @@ android { v1SigningEnabled true v2SigningEnabled false } + + mtk { + storeFile file("keystore/xueshibaoos.jks") + storePassword "123456" + keyAlias "xueshibaoos" + keyPassword "123456" + v1SigningEnabled true + v2SigningEnabled true + } } // Disable release builds for now -// android.variantFilter { variant -> -// if (variant.buildType.name.endsWith('zhanRuiRelease')) { -// variant.setIgnore(variant.getFlavors().get(0).name.equals('official') || variant.getFlavors().get(0).name.equals('zhongyou')) + android.variantFilter { variant -> + if (variant.buildType.name.endsWith('zhanRuiRelease')) { + variant.setIgnore(variant.getFlavors().get(0).name.equals('official') || variant.getFlavors().get(0).name.equals('zhongyou')) + } + if (name.startsWith('newly')) { + variant.setIgnore(name.endsWith("newlyDebug") + || name.endsWith('newlyRelease')) + } + if (name.startsWith('cube')) { + variant.setIgnore(name.endsWith("cubeDebug") + || name.endsWith('cubeRelease')) + } + if (name.contains("MTKnewly")) { + variant.setIgnore(variant.buildType.name.endsWith("zhanRuiRelease") + || variant.buildType.name.endsWith("zhanRuiDebug") + || variant.buildType.name.endsWith("zhanRuiUserdebug") + || variant.buildType.name.endsWith("zhanRuiUserdebugReleas") + || variant.buildType.name.endsWith("alldocubeDebug") + || variant.buildType.name.endsWith("alldocubeDebugRelease") + ) + } + +// // Icon recents is Go only +// if (name.contains("WithQuickstepIconRecents") && !name.contains("l3go")) { +// variant.setIgnore(true) // } -// if (variant.buildType.name.endsWith('zhanRuiDebug')) { -// variant.setIgnore(variant.getFlavors().get(0).name.equals('official') || variant.getFlavors().get(0).name.equals('zhongyou')) -// } -// if (name.contains("MTKnewly")) { -// variant.setIgnore(variant.buildType.name.endsWith("zhanRuiRelease") || variant.buildType.name.endsWith("zhanRuiDebug") || variant.buildType.name.endsWith("zhanRuiUserdebug") -// || variant.buildType.name.endsWith("zhanRuiUserdebugReleas")) -// } -// if (name.endsWith("newlyDebug") || name.endsWith("newlyRelease")) { -// variant.setIgnore(!name.contains("MTK")) -// } -// -//// // Icon recents is Go only -//// if (name.contains("WithQuickstepIconRecents") && !name.contains("l3go")) { -//// variant.setIgnore(true) -//// } -// } + } buildTypes { + zhanRuiDebug.initWith(debug) + zhanRuiDebug { + debuggable true + versionNameSuffix "-debug" + signingConfig signingConfigs.zhanRui + } + + zhanRuiRelease.initWith(release) + zhanRuiRelease { + signingConfig signingConfigs.zhanRui + } + + //userdebug rom使用这个版本 + zhanRuiUserdebug.initWith(zhanRuiDebug) + zhanRuiUserdebug { + debuggable true + versionNameSuffix "-debug" + signingConfig signingConfigs.zhanRuiUserdebug + } + + zhanRuiUserdebugReleas.initWith(release) + zhanRuiUserdebugReleas { + debuggable true + signingConfig signingConfigs.zhanRuiUserdebug + } + debug { - buildConfigField "String", "platform", '"ZhanRui"' - manifestPlaceholders = [ - AMAP_KEY: "6e339305206eeb43f2b4cc1f31751f89" - ] debuggable true versionNameSuffix "-debug" minifyEnabled false @@ -175,14 +212,10 @@ android { } } } - signingConfig signingConfigs.alldocube + signingConfig signingConfigs.mtk } release { - buildConfigField "String", "platform", '"ZhanRui"' - manifestPlaceholders = [ - AMAP_KEY: "6e339305206eeb43f2b4cc1f31751f89" - ] //混淆 minifyEnabled false //前一部分代表系统默认的android程序的混淆文件,该文件已经包含了基本的混淆声明,后一个文件是自己的定义混淆文件 @@ -198,28 +231,7 @@ android { } } } - signingConfig signingConfigs.alldocube - } - - //userdebug rom使用这个版本 - alldocubeDebug.initWith(debug) - alldocubeDebug { - buildConfigField "String", "platform", '"ZhanRui"' - manifestPlaceholders = [ - AMAP_KEY: "6e339305206eeb43f2b4cc1f31751f89" - ] - debuggable true - versionNameSuffix "-debug" - signingConfig signingConfigs.alldocubeDebug - } - - alldocubeDebugReleas.initWith(release) - alldocubeDebugReleas { - buildConfigField "String", "platform", '"ZhanRui"' - manifestPlaceholders = [ - AMAP_KEY: "6e339305206eeb43f2b4cc1f31751f89" - ] - signingConfig signingConfigs.alldocubeDebug + signingConfig signingConfigs.mtk } } diff --git a/app/keystore/xueshibaoos.jks b/app/keystore/xueshibaoos.jks new file mode 100644 index 0000000..b94a626 Binary files /dev/null and b/app/keystore/xueshibaoos.jks differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ab0638f..1a6fb07 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -145,6 +145,7 @@ android:excludeFromRecents="true" android:launchMode="singleTop" /> + @@ -452,6 +453,7 @@ + { + + public MainHandler(MainActivity1 owner) { + super(owner); + } + + @Override + public void handleMessage(Message msg) { + MainActivity1 activity = getOwner(); + if (activity == null) + return; + + if (msg.what == MSG_UPDATE_UI) { + activity.updateUI(); + } + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main1); + startBroadCast(); + + initView(); + } + + private void initView() { + tv_show = findViewById(R.id.tv_show); + } + + private void updateUI() { + tv_show.setText(result); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + stopBroadCast(); + } + + private void startBroadCast() { + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_BATTERY_CHANGED); + registerReceiver(mBroadcastReceiver, filter); + } + + private void stopBroadCast() { + unregisterReceiver(mBroadcastReceiver); + } + + private BroadcastReceiver mBroadcastReceiver = new 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 status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN); + int plugged = intent.getIntExtra(EXTRA_PLUGGED, BATTERY_PLUGGED_ANY); + int level = intent.getIntExtra(EXTRA_LEVEL, 0); + int scale = intent.getIntExtra(EXTRA_SCALE, 0); + int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN); + + int maxChargingMicroAmp = intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1); + int maxChargingMicroVolt = intent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE, -1); + int batteryVolt = intent.getIntExtra(EXTRA_VOLTAGE, -1); + int temperature = intent.getIntExtra(EXTRA_TEMPERATURE, -1); + String batteryTechnologyDescript = intent.getStringExtra(EXTRA_TECHNOLOGY); + + final int maxChargingMicroWatt; + + if (maxChargingMicroVolt <= 0) { + maxChargingMicroVolt = DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT; + } + if (maxChargingMicroAmp > 0) { + // Calculating muW = muA * muV / (10^6 mu^2 / mu); splitting up the divisor + // to maintain precision equally on both factors. + maxChargingMicroWatt = (maxChargingMicroAmp / 1000) + * (maxChargingMicroVolt / 1000); + } else { + maxChargingMicroWatt = -1; + } + + + String statusStr = getStatus(status); + String healthStr = getHealth(health); + String pluggedStr = getPlugged(plugged); + String levelStr = getLevel(level); + String scaleStr = getLevel(scale); + String temperatureStr = getTemperature(temperature); + String batteryVoltStr = getBatteryVolt(batteryVolt); + String maxChargingMicroAmpStr = getMaxChargingMicroAmp(maxChargingMicroAmp); + String maxChargingMicroVoltStr = getMaxChargingMicroVolt(maxChargingMicroVolt); + + int currentChargingCurrent = getCurrentChargingCurrent(); + String currentChargingCurrentStr = getCurrentChargingCurrentStr(currentChargingCurrent); + int currentChargingVoltage = getCurrentChargingVoltage(); + String currentChargingVoltageStr = getCurrentChargingVoltageStr(currentChargingVoltage); + + + result = MainActivity1.this.getString(R.string.adb_shell_help) + + "\n" + MainActivity1.this.getString(R.string.battery_current_level) + levelStr + + "\n" + MainActivity1.this.getString(R.string.battery_current_temperature) + temperatureStr + + "\n" + MainActivity1.this.getString(R.string.battery_current_volt) + batteryVoltStr + + "\n" + MainActivity1.this.getString(R.string.battery_current_charging_current) + currentChargingCurrentStr + + "\n" + MainActivity1.this.getString(R.string.battery_current_charging_voltage) + currentChargingVoltageStr + + "\n" + MainActivity1.this.getString(R.string.battery_status_titls) + statusStr + + "\n" + MainActivity1.this.getString(R.string.battery_plugged_titls) + pluggedStr + + "\n" + MainActivity1.this.getString(R.string.battery_max_charging_current) + maxChargingMicroAmpStr + + "\n" + MainActivity1.this.getString(R.string.battery_max_charging_voltage) + maxChargingMicroVoltStr + + "\n" + MainActivity1.this.getString(R.string.battery_health_titls) + healthStr + + "\n" + MainActivity1.this.getString(R.string.battery_max_level) + scaleStr + + "\n" + MainActivity1.this.getString(R.string.battery_technology_describing) + batteryTechnologyDescript + +"\n充电速度 = " + maxChargingMicroWatt; + mHandler.sendEmptyMessage(MSG_UPDATE_UI); + + } + } + + + }; + + private String getCurrentChargingVoltageStr(int currentChargingVoltage) { + return String.format("%.3f V", currentChargingVoltage / 1000000.0); + } + + private String getCurrentChargingCurrentStr(int currentChargingCurrent) { + return String.format("%.3f A", currentChargingCurrent / 1000.0); + } + + /** + * 当前充电电流 mA + * + * adb shell "cat /sys/class/power_supply/battery/BatteryAverageCurrent" + */ + private int getCurrentChargingCurrent() { + int result = 0; + BufferedReader br = null; + try { + String line; + br = new BufferedReader(new FileReader("/sys/class/power_supply/battery/BatteryAverageCurrent")); + if ((line = br.readLine()) != null) { + result = Integer.parseInt(line); + } + + br.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + return result; + } + + /** + * 当前充电电压 uV + * + * adb shell "cat /sys/class/power_supply/battery/batt_vol" + */ + private int getCurrentChargingVoltage() { + int result = 0; + BufferedReader br = null; + try { + String line; + br = new BufferedReader(new FileReader("/sys/class/power_supply/battery/batt_vol")); + if ((line = br.readLine()) != null) { + result = Integer.parseInt(line); + } + + br.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + return result; + } + + private String getMaxChargingMicroVolt(int maxChargingMicroVolt) { + return String.format("%.1f V", maxChargingMicroVolt / 1000000.0); + } + + private String getMaxChargingMicroAmp(int maxChargingMicroAmp) { + return String.format("%.1f A", maxChargingMicroAmp / 1000000.0); + } + + private String getBatteryVolt(int batteryVolt) { + return String.format("%.3f V", batteryVolt / 1000.0); + } + + + private String getTemperature(int temperature) { + return String.format("%.1f ℃", temperature / 10.0); + } + + private String getLevel(int level) { + return String.format("%d %%", level); + } + + private String getPlugged(int plugged) { + String result = getString(R.string.battery_plugged_any); + + switch (plugged) { + case BATTERY_PLUGGED_ANY: + break; + case BATTERY_PLUGGED_AC: + result = getString(R.string.battery_plugged_ac); + break; + case BATTERY_PLUGGED_USB: + result = getString(R.string.battery_plugged_usb); + break; + case BATTERY_PLUGGED_WIRELESS: + result = getString(R.string.battery_plugged_wireless); + break; + } + + return result; + } + + + private String getHealth(int health) { + String result = getString(R.string.battery_health_unknow); + + switch (health) { + case BATTERY_HEALTH_UNKNOWN: + break; + case BATTERY_HEALTH_GOOD: + result = getString(R.string.battery_health_good); + break; + case BATTERY_HEALTH_OVERHEAT: + result = getString(R.string.battery_health_overheat); + break; + case BATTERY_HEALTH_DEAD: + result = getString(R.string.battery_health_dead); + break; + case BATTERY_HEALTH_UNSPECIFIED_FAILURE: + result = getString(R.string.battery_health_unspecified_failure); + break; + case BATTERY_HEALTH_OVER_VOLTAGE: + result = getString(R.string.battery_health_over_voltage); + break; + case BATTERY_HEALTH_COLD: + result = getString(R.string.battery_health_cold); + break; + } + + return result; + } + + + private String getStatus(int status) { + String result = getString(R.string.battery_status_unknown); + + switch (status) { + case BATTERY_STATUS_FULL: + result = getString(R.string.battery_status_full); + break; + case BATTERY_STATUS_NOT_CHARGING: + result = getString(R.string.battery_status_not_charging); + break; + case BATTERY_STATUS_DISCHARGING: + result = getString(R.string.battery_status_discharging); + break; + case BATTERY_STATUS_CHARGING: + result = getString(R.string.battery_status_charging); + break; + case BATTERY_STATUS_UNKNOWN: + break; + } + + return result; + } +} diff --git a/app/src/main/java/com/aoleyun/sn/activity/SplashActivity.java b/app/src/main/java/com/aoleyun/sn/activity/SplashActivity.java index c49f980..0e2e669 100644 --- a/app/src/main/java/com/aoleyun/sn/activity/SplashActivity.java +++ b/app/src/main/java/com/aoleyun/sn/activity/SplashActivity.java @@ -33,7 +33,9 @@ import com.aoleyun.sn.comm.PackageNames; import com.aoleyun.sn.network.NetInterfaceManager; import com.aoleyun.sn.service.LogcatService; import com.aoleyun.sn.utils.ApkUtils; +import com.aoleyun.sn.utils.FlowInfo; import com.aoleyun.sn.utils.ForegroundAppUtil; +import com.aoleyun.sn.utils.GetFlowUtil; import com.aoleyun.sn.utils.JGYUtils; import com.aoleyun.sn.utils.NetworkUtils; import com.aoleyun.sn.utils.SPUtils; @@ -89,15 +91,19 @@ public class SplashActivity extends AppCompatActivity { private void initView() { if (BuildConfig.DEBUG) { -// Log.e(TAG, "initView: " + Utils.getIMEI(this)); -// Log.e(TAG, "initView: " + Utils.getIMEI(this, 0)); -// Log.e(TAG, "initView: " + Utils.getIMEI(this, 1)); + JGYUtils.getModel(); Log.e(TAG, "getOperators: " + NetworkUtils.getOperators(this)); Log.e(TAG, "PublicIP: " + MMKV.defaultMMKV().decodeString(NetInterfaceManager.PublicIP, "")); NetInterfaceManager.GetWhois(); Log.e(TAG, "initView: " + NetworkUtils.getPhoneNumber(this)); -// String jsonString = ApkUtils.getRunningAppInfo(this); -// Log.e(TAG, "initView: " + jsonString); + FlowInfo flowInfo1 = GetFlowUtil.getAppFlowInfo(BuildConfig.APPLICATION_ID, this); + Log.e(TAG, "initView: " + GetFlowUtil.byteToMB(flowInfo1.getUpKb())); + Log.e(TAG, "initView: " + GetFlowUtil.byteToMB(flowInfo1.getDownKb())); + FlowInfo flowInfo2 = GetFlowUtil.getAppFlowInfo("com.aoleyun.appstore", this); + Log.e(TAG, "initView: " + GetFlowUtil.byteToMB(flowInfo2.getUpKb())); + Log.e(TAG, "initView: " + GetFlowUtil.byteToMB(flowInfo2.getDownKb())); + Log.e(TAG, "initView: " + Utils.getCurrentChargingCurrent()); + Log.e(TAG, "initView: " + Utils.getCurrentChargingVoltage()); ApkUtils.showAllAPP(this); // JGYUtils.getInstance().cleanBackgroundMemory(); // NetInterfaceManager.getInstance().uploadLogFile(); @@ -155,7 +161,8 @@ public class SplashActivity extends AppCompatActivity { Log.i(TAG, "debugTest: " + Utils.getAndroid10MAC(this)); // Log.i(TAG, "debugTest: " + JPushInterface.getRegistrationID(this)); - Log.i(TAG, "debugTest: " + Utils.getCustomVersion()); + Log.e(TAG, "getCustomVersion: " + Utils.getCustomVersion()); + Log.e(TAG, "getRomVersion: " + Utils.getRomVersion()); Log.i(TAG, "debugTest: " + BuildConfig.VERSION_NAME); Log.i(TAG, "debugTest: " + Utils.getAPPVersionName(PackageNames.APPSTORE, this)); Log.i(TAG, "debugTest: " + Utils.getAndroid7MAC()); 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 7f52df6..d5a62ec 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 @@ -28,7 +28,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers; import io.reactivex.rxjava3.subjects.BehaviorSubject; /** - * MainActivity 的 Presenter + * MainActivity1 的 Presenter * * @author jgy */ @@ -83,7 +83,7 @@ public class MainAPresenter implements MainAContact.Presenter { */ @Override public void getStudesInfo(boolean refresh) { - NetInterfaceManager.getInstance().getStudesInfo(false, getLifecycle(), new NetInterfaceManager.StudesInfoListener() { + NetInterfaceManager.getInstance().getStudesInfo(true, getLifecycle(), new NetInterfaceManager.StudesInfoListener() { @Override public void setStudentsInfo(StudentsInfo studentsInfo) { mView.setStudesInfo(studentsInfo); diff --git a/app/src/main/java/com/aoleyun/sn/activity/utils/WeakHandler.java b/app/src/main/java/com/aoleyun/sn/activity/utils/WeakHandler.java new file mode 100644 index 0000000..0ff230a --- /dev/null +++ b/app/src/main/java/com/aoleyun/sn/activity/utils/WeakHandler.java @@ -0,0 +1,37 @@ +/***************************************************************************** + * WeakHandler.java + ***************************************************************************** + * Copyright © 2012 VLC authors and VideoLAN + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +package com.aoleyun.sn.activity.utils; + +import android.os.Handler; + +import java.lang.ref.WeakReference; + +public abstract class WeakHandler extends Handler { + private WeakReference mOwner; + + public WeakHandler(T owner) { + mOwner = new WeakReference(owner); + } + + public T getOwner() { + return mOwner.get(); + } +} diff --git a/app/src/main/java/com/aoleyun/sn/bean/ForceDownloadData.java b/app/src/main/java/com/aoleyun/sn/bean/ForceDownloadData.java index 3a7c748..b769d2f 100644 --- a/app/src/main/java/com/aoleyun/sn/bean/ForceDownloadData.java +++ b/app/src/main/java/com/aoleyun/sn/bean/ForceDownloadData.java @@ -6,7 +6,6 @@ import com.google.gson.JsonParser; import java.io.Serializable; public class ForceDownloadData implements Serializable { - private static final long serialVersionUID = 2965901905485481437L; private String 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 ea01eb2..791ece6 100644 --- a/app/src/main/java/com/aoleyun/sn/comm/CommonConfig.java +++ b/app/src/main/java/com/aoleyun/sn/comm/CommonConfig.java @@ -47,4 +47,10 @@ public class CommonConfig { /*上次获取标签的时间*/ public final static String GET_DEVICES_TAG_LASTTIME = "Aoleyun_devices_tag_last_time"; + + /** + * 管控系统指令 + */ + + public final static String aole_action_usb_usb_charge = "aole_action_usb_usb_charge"; } diff --git a/app/src/main/java/com/aoleyun/sn/jpush/MyReceiver.java b/app/src/main/java/com/aoleyun/sn/jpush/MyReceiver.java index b163f2a..fc74c06 100644 --- a/app/src/main/java/com/aoleyun/sn/jpush/MyReceiver.java +++ b/app/src/main/java/com/aoleyun/sn/jpush/MyReceiver.java @@ -91,18 +91,18 @@ package com.aoleyun.sn.jpush; // return sb.toString(); // } // -// //send msg to MainActivity +// //send msg to MainActivity1 // private void processCustomMessage(Context context, Bundle bundle) { -// if (MainActivity.isForeground) { +// if (MainActivity1.isForeground) { // String message = bundle.getString(JPushInterface.EXTRA_MESSAGE); // String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); -// Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION); -// msgIntent.putExtra(MainActivity.KEY_MESSAGE, message); +// Intent msgIntent = new Intent(MainActivity1.MESSAGE_RECEIVED_ACTION); +// msgIntent.putExtra(MainActivity1.KEY_MESSAGE, message); // if (!ExampleUtil.isEmpty(extras)) { // try { // JSONObject extraJson = new JSONObject(extras); // if (extraJson.length() > 0) { -// msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras); +// msgIntent.putExtra(MainActivity1.KEY_EXTRAS, extras); // } // } catch (JSONException e) { // diff --git a/app/src/main/java/com/aoleyun/sn/jpush/invalid/MainActivity.java b/app/src/main/java/com/aoleyun/sn/jpush/invalid/MainActivity.java index 6e40d8b..c6b8ed5 100644 --- a/app/src/main/java/com/aoleyun/sn/jpush/invalid/MainActivity.java +++ b/app/src/main/java/com/aoleyun/sn/jpush/invalid/MainActivity.java @@ -1,7 +1,7 @@ package com.aoleyun.sn.jpush.invalid; -//public class MainActivity extends InstrumentedActivity implements OnClickListener{ +//public class MainActivity1 extends InstrumentedActivity implements OnClickListener{ // // private Button mInit; // private Button mSetting; @@ -71,7 +71,7 @@ package com.aoleyun.sn.jpush.invalid; // init(); // break; // case R.id.setting: -// Intent intent = new Intent(MainActivity.this, PushSetActivity.class); +// Intent intent = new Intent(MainActivity1.this, PushSetActivity.class); // startActivity(intent); // break; // case R.id.stopPush: 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 ca3bfc1..5a925d6 100644 --- a/app/src/main/java/com/aoleyun/sn/network/NetInterfaceManager.java +++ b/app/src/main/java/com/aoleyun/sn/network/NetInterfaceManager.java @@ -424,7 +424,7 @@ public class NetInterfaceManager { .observeOn(AndroidSchedulers.mainThread()); } - public Observable getDesktopObservable() { + public Observable> getDesktopObservable() { return mRetrofit.create(GetDesktopApi.class) .getDesktop(Utils.getSerial(mContext)) .subscribeOn(Schedulers.io()) @@ -893,24 +893,27 @@ public class NetInterfaceManager { public void getDefaultDesktop(BehaviorSubject lifecycle, onCompleteCallback callback) { getDesktopObservable() .compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY)) - .subscribe(new Observer() { + .subscribe(new Observer>() { @Override public void onSubscribe(@NonNull Disposable d) { Log.e("getDefaultDesktop", "onSubscribe: "); } @Override - public void onNext(@NonNull BaseResponse baseResponse) { + public void onNext(@NonNull BaseResponse baseResponse) { Log.e("getDefaultDesktop", "onNext: " + baseResponse); if (baseResponse.code == OK) { - String jsonString = GsonUtils.toJsonString(baseResponse.data); + ForceDownloadData desktopInfo = baseResponse.data; + String jsonString = GsonUtils.toJsonString(desktopInfo); JSONObject data = JSON.parseObject(jsonString); cacheHelper.put(UrlAddress.GET_DESKTOP, jsonString); JGYUtils.getInstance().installDesktop(data); + SPUtils.put(mContext, "default_launcher", desktopInfo.getApp_package()); } else { Log.e("getDefaultDesktop", "onNext: " + "删除定制桌面"); cacheHelper.put(UrlAddress.GET_DESKTOP, ""); String whiteList = Settings.System.getString(mContext.getContentResolver(), JGYActions.ACTION_JGY_SHORTCUTLIST); + Log.e("getDefaultDesktop", "onNext: " + whiteList); if (!TextUtils.isEmpty(whiteList)) { if (!whiteList.contains(ApkUtils.desktopAPP.get(0))) { ApkUtils.UninstallAPP(mContext, ApkUtils.desktopAPP.get(0)); @@ -920,6 +923,9 @@ public class NetInterfaceManager { ApkUtils.UninstallAPP(mContext, ApkUtils.desktopAPP.get(1)); Log.e("getDefaultDesktop", "skip: " + ApkUtils.desktopAPP.get(1)); } + }else { + ApkUtils.UninstallAPP(mContext, ApkUtils.desktopAPP.get(0)); + ApkUtils.UninstallAPP(mContext, ApkUtils.desktopAPP.get(1)); } } } @@ -1839,6 +1845,8 @@ public class NetInterfaceManager { set.add(JGYUtils.MTKTag); } else if (platform == JGYUtils.ZhanruiPlatform) { set.add(JGYUtils.ZhanruiTag); + } else if (platform == JGYUtils.CubePlatform) { + set.add(JGYUtils.CubeTag); } } }); diff --git a/app/src/main/java/com/aoleyun/sn/network/api/get/GetDesktopApi.java b/app/src/main/java/com/aoleyun/sn/network/api/get/GetDesktopApi.java index 239eafa..ddd7dee 100644 --- a/app/src/main/java/com/aoleyun/sn/network/api/get/GetDesktopApi.java +++ b/app/src/main/java/com/aoleyun/sn/network/api/get/GetDesktopApi.java @@ -1,6 +1,7 @@ package com.aoleyun.sn.network.api.get; import com.aoleyun.sn.bean.BaseResponse; +import com.aoleyun.sn.bean.ForceDownloadData; import com.aoleyun.sn.network.UrlAddress; import io.reactivex.rxjava3.core.Observable; @@ -10,7 +11,7 @@ import retrofit2.http.Query; public interface GetDesktopApi { @GET(UrlAddress.GET_DESKTOP) - Observable getDesktop( + Observable> getDesktop( @Query("sn") String sn ); } 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 8d634ba..587ab2c 100644 --- a/app/src/main/java/com/aoleyun/sn/receiver/NewAppReceiver.java +++ b/app/src/main/java/com/aoleyun/sn/receiver/NewAppReceiver.java @@ -63,6 +63,7 @@ public class NewAppReceiver extends BroadcastReceiver { break; } Log.e(TAG, "sendAppInfo: " + state + packageName); + JGYUtils.getInstance().checkDefaultDesktop(packageName); JGYUtils.getInstance().checkForceDownload(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (!PackageNames.APPSTORE.equals(packageName) || !PackageNames.DEVICE_INFO.equals(packageName)) { 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 0e81cd9..1f344f5 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 @@ -242,7 +242,7 @@ public class MainSPresenter implements MainSContact.Presenter { @Override public void getDefaultDesktop() { - if (JGYUtils.isOfficialVersion() || JGYUtils.getInstance().getDeviceIsLocked()) { + if (JGYUtils.isOfficialVersion() || !JGYUtils.getInstance().getDeviceIsLocked()) { mView.getDefaultDesktopFinish(); } else { NetInterfaceManager.getInstance() 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 5e4b157..c2ce32b 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/ApkUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/ApkUtils.java @@ -738,10 +738,10 @@ public class ApkUtils { //桌面app public static List desktopAPP = new ArrayList() {{ + this.add("com.aoleyunos.dop1"); + this.add("com.aoleyunos.dop2"); this.add("com.uiuios.jgy1"); this.add("com.uiuios.jgy2"); -// this.add("com.aoleyunos.dop1"); -// this.add("com.aoleyunos.dop2"); this.add("com.android.uiuios"); }}; diff --git a/app/src/main/java/com/aoleyun/sn/utils/FlowInfo.java b/app/src/main/java/com/aoleyun/sn/utils/FlowInfo.java new file mode 100644 index 0000000..dc5ea89 --- /dev/null +++ b/app/src/main/java/com/aoleyun/sn/utils/FlowInfo.java @@ -0,0 +1,69 @@ +package com.aoleyun.sn.utils; + +import android.graphics.drawable.Drawable; + +import androidx.annotation.NonNull; + +import com.google.gson.Gson; +import com.google.gson.JsonParser; + +import java.io.Serializable; + +public class FlowInfo implements Serializable { + private static final long serialVersionUID = 4948079364302374385L; + + String packname; + Drawable icon; + String appname; + long upKb; + long downKb; + long[] stat; + + public String getPackname() { + return packname; + } + + public void setPackname(String packname) { + this.packname = packname; + } + + public Drawable getIcon() { + return icon; + } + + public void setIcon(Drawable icon) { + this.icon = icon; + } + + public String getAppname() { + return appname; + } + + public void setAppname(String appname) { + this.appname = appname; + } + + public long getUpKb() { + return upKb; + } + + public void setUpKb(long upKb) { + this.upKb = upKb; + } + + public long getDownKb() { + return downKb; + } + + public void setDownKb(long downKb) { + this.downKb = downKb; + } + + public long[] getStat() { + return stat; + } + + public void setStat(long[] stat) { + this.stat = stat; + } +} diff --git a/app/src/main/java/com/aoleyun/sn/utils/GetFlowUtil.java b/app/src/main/java/com/aoleyun/sn/utils/GetFlowUtil.java new file mode 100644 index 0000000..dae74ff --- /dev/null +++ b/app/src/main/java/com/aoleyun/sn/utils/GetFlowUtil.java @@ -0,0 +1,84 @@ +package com.aoleyun.sn.utils; + +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.net.TrafficStats; +import android.text.TextUtils; +import android.util.Log; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.List; + +public class GetFlowUtil { + public static FlowInfo getAppFlowInfo(String pakageName, Context context) { + //获取到配置权限信息的应用程序 + PackageManager pms = context.getPackageManager(); + List packinfos = pms + .getInstalledPackages(PackageManager.GET_PERMISSIONS); + //存放具有Internet权限信息的应用 + FlowInfo flowInfo = new FlowInfo(); + for (PackageInfo packinfo : packinfos) { + String appName = packinfo.packageName; + if (!TextUtils.isEmpty(appName)) { + if (appName.equals(pakageName)) { + //用于封装具有Internet权限的应用程序信息 + //封装应用信息 + flowInfo.setPackname(packinfo.packageName); + flowInfo.setIcon(packinfo.applicationInfo.loadIcon(pms)); + flowInfo.setAppname(packinfo.applicationInfo.loadLabel(pms).toString()); + //获取到应用的uid(user id) + int uid = packinfo.applicationInfo.uid; + //TrafficStats对象通过应用的uid来获取应用的下载、上传流量信息 + //发送的 上传的流量byte + flowInfo.setUpKb(TrafficStats.getUidRxBytes(uid)); + //下载的流量 byte + flowInfo.setDownKb(TrafficStats.getUidTxBytes(uid)); + break; + } + } + } + return flowInfo; + } + + private static long[] getStat(int uid) { + String line, line2; + long[] stats = new long[2]; + try { + File fileSnd = new File("/proc/uid_stat/" + uid + "/tcp_snd"); + File fileRcv = new File("/proc/uid_stat/" + uid + "/tcp_rcv"); + BufferedReader br1 = new BufferedReader(new FileReader(fileSnd)); + BufferedReader br2 = new BufferedReader(new FileReader(fileRcv)); + while ((line = br1.readLine()) != null && (line2 = br2.readLine()) != null) { + stats[0] = Long.parseLong(line); + stats[1] = Long.parseLong(line2); + } + br1.close(); + br2.close(); + } catch (Exception e) { + e.printStackTrace(); + Log.e("getStat: ", e.getMessage()); + } + return stats; + } + + //将字节数转化为MB + public static String byteToMB(long size) { + long kb = 1024; + long mb = kb * 1024; + long gb = mb * 1024; + if (size >= gb) { + return String.format("%.1f GB", (float) size / gb); + } else if (size >= mb) { + float f = (float) size / mb; + return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f); + } else if (size > kb) { + float f = (float) size / kb; + return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f); + } else { + return String.format("%d B", size); + } + } +} 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 9f9df8f..4369000 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/JGYUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/JGYUtils.java @@ -53,7 +53,6 @@ import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.aoleyun.sn.BuildConfig; -import com.aoleyun.sn.base.BaseApplication; import com.aoleyun.sn.bean.AppListInfo; import com.aoleyun.sn.bean.Appground; import com.aoleyun.sn.bean.BaseResponse; @@ -108,16 +107,21 @@ public class JGYUtils { private Context mContext; private ContentResolver crv; - public static int MTKPlatform = 1; - public static int ZhanruiPlatform = 2; public static int UnknowPlatform = 0; - public static String MTKTag = "MTK"; - public static String ZhanruiTag = "展锐cube"; + public static int MTKPlatform = 1; + // TODO: 2022/4/23 标签替换未完成 + public static int CubePlatform = 2; + public static int ZhanruiPlatform = 3; + + public static String Other = "其他"; + public static String MTKTag = "MTK"; + // TODO: 2022/4/23 标签替换未完成 + public static String CubeTag = "展锐cube"; + public static String ZhanruiTag = "展锐"; private CacheHelper cacheHelper; - static { System.loadLibrary("jgy"); } @@ -147,6 +151,74 @@ public class JGYUtils { public static native String getAuthorization(); + public int checkSNPlatform(String sn) { + String secondChars = sn.substring(1, 2); + if ("N".equalsIgnoreCase(secondChars)) {//MTK平台 + return MTKPlatform; + } else if ("R".equalsIgnoreCase(secondChars)) {//展锐平台 + return ZhanruiPlatform; + } else { + Log.e(TAG, "checkSNPlatform: " + "sn: " + sn + "没有对应平台"); + return UnknowPlatform; + } + } + + public int checkAppPlatform() { + String platform = BuildConfig.platform; + if ("MTK".equalsIgnoreCase(platform)) { + Log.i(TAG, "checkAppPlatform: " + "MTK平台"); + return MTKPlatform; + } else if ("ZhanRui".equalsIgnoreCase(platform)) { + Log.i(TAG, "checkAppPlatform: " + "展锐平台"); + return ZhanruiPlatform; + } else if ("ZhanRuiCube".equalsIgnoreCase(platform)) { + Log.i(TAG, "checkAppPlatform: " + "酷比平台"); + return CubePlatform; + } else { + Log.i(TAG, "checkAppPlatform: " + "没有数据"); + return UnknowPlatform; + } + } + + public boolean isSamePlatform(String platform) { + String AppPlatform = BuildConfig.platform; + if ("ZhanRui".equals(AppPlatform)) { + return ZhanruiTag.equals(platform); + } else { + return AppPlatform.equals(platform); + } + } + + public interface GetAppPlatformCallback { + void AppPlatform(int platform); + } + + public void getAppPlatform(GetAppPlatformCallback getAppPlatformCallback) { + String platform = BuildConfig.platform; + if ("MTK".equalsIgnoreCase(platform)) { + getAppPlatformCallback.AppPlatform(MTKPlatform); + } else if ("ZhanRui".equalsIgnoreCase(platform)) { + getAppPlatformCallback.AppPlatform(ZhanruiPlatform); + } else if ("ZhanRuiCube".equalsIgnoreCase(platform)) { + getAppPlatformCallback.AppPlatform(CubePlatform); + } else { + getAppPlatformCallback.AppPlatform(UnknowPlatform); + } + } + + public String getAppPlatform() { + String platform = BuildConfig.platform; + if ("MTK".equalsIgnoreCase(platform)) { + return MTKTag; + } else if ("ZhanRui".equalsIgnoreCase(platform)) { + return ZhanruiTag; + } else if ("ZhanRuiCube".equalsIgnoreCase(platform)) { + return CubeTag; + } else { + return Other; + } + } + public static boolean isOfficialVersion() { String channelValue = JGYUtils.getInstance().getStringMetaData(); return "official".equals(channelValue); @@ -1591,67 +1663,6 @@ public class JGYUtils { } } - public int checkSNPlatform(String sn) { - String secondChars = sn.substring(1, 2); - if ("N".equalsIgnoreCase(secondChars)) {//MTK平台 - return MTKPlatform; - } else if ("R".equalsIgnoreCase(secondChars)) {//展锐平台 - return ZhanruiPlatform; - } else { - Log.e(TAG, "checkSNPlatform: " + "sn: " + sn + "没有对应平台"); - return UnknowPlatform; - } - } - - public int checkAppPlatform() { - String platform = BuildConfig.platform; - if ("MTK".equalsIgnoreCase(platform)) { - Log.i(TAG, "checkAppPlatform: " + "MTK平台"); - return MTKPlatform; - } else if ("ZhanRui".equalsIgnoreCase(platform)) { - Log.i(TAG, "checkAppPlatform: " + "展锐平台"); - return ZhanruiPlatform; - } else { - Log.i(TAG, "checkAppPlatform: " + "没有数据"); - return UnknowPlatform; - } - } - - public boolean isSamePlatform(String platform) { - String AppPlatform = BuildConfig.platform; - if ("ZhanRui".equals(AppPlatform)) { - return ZhanruiTag.equals(platform); - } else { - return AppPlatform.equals(platform); - } - } - - public interface GetAppPlatformCallback { - void AppPlatform(int platform); - } - - public void getAppPlatform(GetAppPlatformCallback getAppPlatformCallback) { - String platform = BuildConfig.platform; - if ("MTK".equalsIgnoreCase(platform)) { - getAppPlatformCallback.AppPlatform(MTKPlatform); - } else if ("ZhanRui".equalsIgnoreCase(platform)) { - getAppPlatformCallback.AppPlatform(ZhanruiPlatform); - } else { - getAppPlatformCallback.AppPlatform(UnknowPlatform); - } - } - - public String getAppPlatform() { - String platform = BuildConfig.platform; - if ("MTK".equalsIgnoreCase(platform)) { - return MTKTag; - } else if ("ZhanRui".equalsIgnoreCase(platform)) { - return ZhanruiTag; - } else { - return Other; - } - } - @RequiresApi(api = Build.VERSION_CODES.M) public void cleanBackgroundMemory() { ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); @@ -1885,8 +1896,16 @@ public class JGYUtils { private String Launcher3 = "com.android.launcher3"; private String Launcher3Class = "com.android.launcher3.Launcher"; + public void checkDefaultDesktop(String pkg) { + String desktopPkg = (String) SPUtils.get(mContext, "default_launcher", ""); + if (desktopPkg.equalsIgnoreCase(pkg)) { + setDefaultDesktop(pkg); + } + } + //设置默认桌面 public void setDefaultDesktop(String pkg) { + Log.e(TAG, "setDefaultDesktop: " + pkg); if (TextUtils.isEmpty(pkg)) { openLauncher3(); } else { @@ -2069,4 +2088,47 @@ public class JGYUtils { wakeUpAppstore(); wakeUpNotify(); } + + public static String getModel() { + Log.e(TAG, "MANUFACTURER=" + Build.MANUFACTURER); + Log.e(TAG, "BRAND=" + Build.BRAND); + Log.e(TAG, "MODEL=" + Build.MODEL); + Log.e(TAG, "VERSION.RELEASE=" + Build.VERSION.RELEASE); + Log.e(TAG, "VERSION.SDK_INT=" + Build.VERSION.SDK_INT); + Log.e(TAG, "DEVICE=" + Build.DEVICE); + Log.e(TAG, "HOST=" + Build.HOST); + Log.e(TAG, "ID=" + Build.ID); + Log.e(TAG, "TIME=" + Build.TIME); + Log.e(TAG, "TYPE=" + Build.TYPE); + Log.e(TAG, "PRODUCT=" + Build.PRODUCT); + Log.e(TAG, "BOARD=" + Build.BOARD); + Log.e(TAG, "DISPLAY=" + Build.DISPLAY); + Log.e(TAG, "FINGERPRINT=" + Build.FINGERPRINT); + Log.e(TAG, "HARDWARE=" + Build.HARDWARE); + Log.e(TAG, "BOOTLOADER=" + Build.BOOTLOADER); + Log.e(TAG, "TAGS=" + Build.TAGS); + Log.e(TAG, "UNKNOWN=" + Build.UNKNOWN); + Log.e(TAG, "USER=" + Build.USER); + return Build.MODEL; + } + + private static String MTK_HARDWARE = "mtk"; + private static String UNISOC_HARDWARE = "ums"; + + private static String AIHUA_BRAND = "AS"; + private static String CUBE_BRAND = "ALLDOCUBE"; + + public static String getHardware() { + return Build.HARDWARE; + } + + public static boolean isAihuaDevice() { + return getHardware().startsWith(MTK_HARDWARE) && Build.BRAND.startsWith(AIHUA_BRAND); + } + + public static boolean isCubeDevice() { + return getHardware().startsWith(UNISOC_HARDWARE) && Build.BRAND.equalsIgnoreCase(CUBE_BRAND); + } + + } diff --git a/app/src/main/java/com/aoleyun/sn/utils/SysSettingUtils.java b/app/src/main/java/com/aoleyun/sn/utils/SysSettingUtils.java index 2448238..a16196a 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/SysSettingUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/SysSettingUtils.java @@ -115,8 +115,8 @@ public class SysSettingUtils { // ToastTool.show("qch_call_forbid::"+setting_call+"----setting_phones::"+setting_phones+"----"+qch_white_list_Array+"---"+qch_call_forbid); Log.e(TAG, "qch_white_list_Array:" + qch_white_list_Array + "---" + qch_white_list_Array); - boolean qch_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_sdcard_forbid_on", state); - Log.e(TAG, "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); + boolean aole_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "aole_sdcard_forbid_on", state); + Log.e(TAG, "aole_sdcard_forbid_on:" + aole_sdcard_forbid_on); } catch (Exception e) { Log.e(TAG, "setPhoneList: " + e.getMessage()); } @@ -146,8 +146,8 @@ public class SysSettingUtils { } //存储卡 int setting_memory = changeNum(jsonObject.getInteger("setting_memory")); - boolean qch_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_sdcard_forbid_on", setting_memory); - Log.e(TAG, "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); + boolean aole_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "aole_sdcard_forbid_on", setting_memory); + Log.e(TAG, "aole_sdcard_forbid_on:" + aole_sdcard_forbid_on); } catch (Exception e) { Log.e(TAG, "setPhoneList: " + e.getMessage()); } @@ -180,26 +180,36 @@ public class SysSettingUtils { //Midi模式:usb_midi String setting_usb = jsonObject.getString("setting_usb"); if (!BuildConfig.DEBUG) { - SuperPower mService = (SuperPower) context.getSystemService("mdm"); - boolean aole_usb_choose = Settings.System.putString(context.getContentResolver(), "aole_usb_choose", setting_usb); - Log.e("setUSBstate", "aole_usb_choose---------" + aole_usb_choose); - String usbStatus = ""; - switch (setting_usb) { - case "usb_charge": - mService.setUSBDataDisabled(true); - usbStatus = "aole_action_usb_usb_charge"; - break; - case "usb_mtp": - mService.setUSBDataDisabled(false); - usbStatus = "aole_action_usb_usb_mtp"; - break; - case "usb_midi": - usbStatus = "aole_action_usb_usb_midi"; - break; - + if (JGYUtils.isCubeDevice()) { + SuperPower mService = (SuperPower) context.getSystemService("mdm"); + switch (setting_usb) { + case "usb_charge": + mService.setUSBDataDisabled(true); + break; + case "usb_mtp": + mService.setUSBDataDisabled(false); + break; + default: + } + } else { + boolean aole_usb_choose = Settings.System.putString(context.getContentResolver(), "aole_usb_choose", setting_usb); + Log.e("setUSBstate", "aole_usb_choose---------" + aole_usb_choose); + String usbStatus = "aole_action_usb_usb_charge"; + switch (setting_usb) { + case "usb_charge": + usbStatus = "aole_action_usb_usb_charge"; + break; + case "usb_mtp": + usbStatus = "aole_action_usb_usb_mtp"; + break; + case "usb_midi": + usbStatus = "aole_action_usb_usb_midi"; + break; + default: + } + Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); + context.sendBroadcast(usbIntent); } - Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); - context.sendBroadcast(usbIntent); } } @@ -597,21 +607,21 @@ public class SysSettingUtils { } private static void setCanReset(Context context, int state) { - boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 0); - Log.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on); + boolean aole_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "aole_restore_forbid_on", 0); + Log.e(TAG, "aole_restore_forbid_on:" + aole_restore_forbid_on); //默认打开 } - //qch_restore_forbid_on=1,禁止恢复出厂设置 - //qch_restore_forbid_on=0,允许恢复出厂设置 + //aole_restore_forbid_on=1,禁止恢复出厂设置 + //aole_restore_forbid_on=0,允许恢复出厂设置 private static void setCanReset(Context context, JSONObject jsonObject) { int mode = jsonObject.getInteger("qch_restore"); if (mode == 1) { - boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 0); - Log.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on); + boolean aole_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "aole_restore_forbid_on", 0); + Log.e(TAG, "aole_restore_forbid_on:" + aole_restore_forbid_on); } else { - boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 1); - Log.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on); + boolean aole_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "aole_restore_forbid_on", 1); + Log.e(TAG, "aole_restore_forbid_on:" + aole_restore_forbid_on); } } 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 9db9b13..08842df 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/Utils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/Utils.java @@ -172,11 +172,12 @@ public class Utils { } public static String getAndroid10MAC(Context context) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) { - return getMacAddress(context); - } else { - return getAndroid7MAC(); - } +// if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) { +// return getMacAddress(context); +// } else { +// return getAndroid7MAC(); +// } + return getAllMacAddress(context); } /** @@ -284,6 +285,95 @@ public class Utils { return builder.toString(); } + /** + * 获取MAC地址 + * + * @param context + * @return + */ + public static String getAllMacAddress(Context context) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + return getMacDefault(context); + } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + return getMacAddressM(); + } else { + return getMacFromHardware(); + } + } + + /** + * Android 6.0 之前(不包括6.0) + * + * @param context + * @return + */ + private static String getMacDefault(Context context) { + String mac = "未获取到设备Mac地址"; + if (context == null) { + return mac; + } + WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiInfo info = null; + try { + info = wifi.getConnectionInfo(); + } catch (Exception e) { + e.printStackTrace(); + } + if (info == null) { + return mac; + } + mac = info.getMacAddress(); + if (!TextUtils.isEmpty(mac)) { + mac = mac.toUpperCase(Locale.ENGLISH); + } + + return mac; + } + + /** + * Android 6.0(包括) - Android 7.0(不包括) + * + * @return + */ + private static String getMacAddressM() { + String mac = "未获取到设备Mac地址"; + + try { + mac = new BufferedReader(new FileReader("/sys/class/net/wlan0/address")).readLine(); + } catch (IOException e) { + e.printStackTrace(); + } + return mac; + } + + /** + * 遍历循环所有的网络接口,找到接口是 wlan0 + * + * @return + */ + private static String getMacFromHardware() { + try { + List all = Collections.list(NetworkInterface.getNetworkInterfaces()); + + for (NetworkInterface nif : all) { + if (!nif.getName().equalsIgnoreCase("wlan0")) { + continue; + } + byte[] macBytes = nif.getHardwareAddress(); + StringBuilder res1 = new StringBuilder(); + for (byte b : macBytes) { + res1.append(String.format("%02X:", b)); + } + if (res1 != null) { + res1.deleteCharAt(res1.length() - 1); + } + return res1.toString(); + } + } catch (Exception e) { + e.printStackTrace(); + } + return "未获取到设备Mac地址"; + } // MD5 设备地址标识 public static String getMD5(Context context) { @@ -1593,17 +1683,33 @@ public class Utils { return Formatter.formatFileSize(context, availableSize); } + /** + * 获取自定义版本号 或者版本号 + * @return + */ public static String getCustomVersion() { if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) { return Utils.getProperty("ro.build.display.id", "获取失败"); + } else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.CubePlatform) { + return Utils.getProperty("ro.build.display.id", "获取失败"); + } else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.MTKPlatform) { + return Utils.getProperty("ro.build.display.id", "获取失败"); } else { return Utils.getProperty("ro.custom.build.version", "获取失败"); } } + /** + * 获取系统版本号 + * @return + */ public static String getRomVersion() { if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) { return getProperty("ro.build.id", "获取失败"); + }else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.CubePlatform) { + return Utils.getProperty("ro.build.id", "获取失败"); + } else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.MTKPlatform) { + return Utils.getProperty("ro.build.id", "获取失败"); } else { return getProperty("ro.build.display.id", "获取失败"); } @@ -1719,6 +1825,69 @@ public class Utils { } } + /** + * 当前充电电流 mA + *

+ * adb shell "cat /sys/class/power_supply/battery/BatteryAverageCurrent" + */ + public static int getCurrentChargingCurrent() { + int result = 0; + BufferedReader br = null; + try { + String line; + br = new BufferedReader(new FileReader("/sys/class/power_supply/battery/BatteryAverageCurrent")); + if ((line = br.readLine()) != null) { + result = Integer.parseInt(line); + } + br.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + return result; + } + + /** + * 当前充电电压 uV + *

+ * adb shell "cat /sys/class/power_supply/battery/batt_vol" + */ + public static int getCurrentChargingVoltage() { + int result = 0; + BufferedReader br = null; + try { + String line; + br = new BufferedReader(new FileReader("/sys/class/power_supply/battery/batt_vol")); + if ((line = br.readLine()) != null) { + result = Integer.parseInt(line); + } + + br.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return result; + } } diff --git a/app/src/main/res/layout/activity_main1.xml b/app/src/main/res/layout/activity_main1.xml new file mode 100644 index 0000000..1daf68a --- /dev/null +++ b/app/src/main/res/layout/activity_main1.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index f026464..00c48d4 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -4,6 +4,9 @@ @dimen/dp_15 + 16dp + 16dp + -60dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8e26ba6..77ed9ea 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -76,4 +76,41 @@ www.jiaoguanyi.com\n http://shouji.360tpcdn.com/170917/af50b75c9980cd6cba079052f4aa4e63/com.jingdong.app.mall_52563.apk http://shouji.360tpcdn.com/170919/1a4d1a0ca1255ae315c36394dd2b0865/com.mt.mtxx.mtxx_6860.apk + + + + 电池状态: + 未知 + 充电中 + 放电中 + 未充电 + 电池满 + + 电池健康情况: + 未知 + 良好 + 过热 + 没电 + 未知错误 + 过电压 + 温度过低 + + 充电类型: + 充电器 + USB + 其他 + 无线充电 + + 当前电量: + 电量最大值: + 当前电池温度: + 当前电池电压: + 电池技术描述: + + 当前充电电流: + 最大充电电流: + + 当前充电电压: + 最大充电电压: + 发送命令: adb shell dumpsys battery \n \ No newline at end of file