version:1.0.0
fix: update:更换为荣耀mdm
This commit is contained in:
@@ -13,11 +13,12 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.xwad.os"
|
||||
//There are no CERT files because If the mini sdk version is 23+, the AGP will ignore the V1 scheme signature.
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 29
|
||||
|
||||
versionCode 24
|
||||
versionName "1.2.3"
|
||||
versionCode 1
|
||||
versionName "1.0.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
@@ -131,8 +132,9 @@ android {
|
||||
|
||||
dependencies {
|
||||
// implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation files('libs/CSDK_TBY11_AiYouDu_250312.jar')
|
||||
compileOnly files('libs/framework.jar')
|
||||
// compileOnly files('libs/framework.jar')
|
||||
compileOnly files('libs/magic-android-31.35.6.300.jar')
|
||||
|
||||
implementation project(path: ':niceimageview')
|
||||
implementation project(path: ':FlycoTabLayoutZ_Lib')
|
||||
implementation project(path: ':verification-view')
|
||||
|
||||
Binary file not shown.
BIN
app/libs/magic-android-31.35.6.300.jar
Normal file
BIN
app/libs/magic-android-31.35.6.300.jar
Normal file
Binary file not shown.
@@ -280,6 +280,19 @@
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
|
||||
<receiver
|
||||
android:name=".receiver.AoleDeviceAdminReceiver"
|
||||
android:description="@string/sample_device_admin_description"
|
||||
android:label="@string/sample_device_admin"
|
||||
android:permission="android.permission.BIND_DEVICE_ADMIN">
|
||||
<meta-data
|
||||
android:name="android.app.device_admin"
|
||||
android:resource="@xml/device_admin_sample" />
|
||||
<intent-filter>
|
||||
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name=".alarm.AlarmService"
|
||||
android:enabled="true"
|
||||
|
||||
@@ -14,9 +14,7 @@ import com.xwad.os.base.mvvm.BaseMvvmActivity;
|
||||
import com.xwad.os.config.CommonConfig;
|
||||
import com.xwad.os.databinding.ActivityEditBinding;
|
||||
import com.xwad.os.manager.DeviceSNManager;
|
||||
import com.xwad.os.manager.RemoteManager;
|
||||
import com.xwad.os.utils.ActivationUtil;
|
||||
import com.xwad.os.utils.LenovoCsdkUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -45,9 +45,7 @@ import com.xwad.os.jxw.JxwPackageConfig;
|
||||
import com.xwad.os.manager.AmapManager;
|
||||
import com.xwad.os.manager.DeviceSNManager;
|
||||
import com.xwad.os.manager.RemoteManager;
|
||||
import com.xwad.os.service.SocketService;
|
||||
import com.xwad.os.utils.ApkUtils;
|
||||
import com.xwad.os.utils.LenovoCsdkUtil;
|
||||
import com.xwad.os.utils.OpenApkUtils;
|
||||
import com.xwad.os.utils.Utils;
|
||||
import com.xwad.os.view.viewpager.BaseFragmentPagerAdapter;
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
import com.hjq.toast.Toaster;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xwad.os.R;
|
||||
import com.xwad.os.base.mvvm.BaseMvvmActivity;
|
||||
@@ -16,10 +15,7 @@ import com.xwad.os.databinding.ActivitySelecteGradeBinding;
|
||||
import com.xwad.os.jxw.SPUtils;
|
||||
import com.xwad.os.jxw.event.UpdateGradeEvent;
|
||||
import com.xwad.os.manager.DeviceSNManager;
|
||||
import com.xwad.os.manager.RemoteManager;
|
||||
import com.xwad.os.utils.ActivationUtil;
|
||||
import com.xwad.os.utils.LenovoCsdkUtil;
|
||||
import com.xwad.os.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ import com.xwad.os.utils.ActivationUtil;
|
||||
import com.xwad.os.utils.ApkUtils;
|
||||
import com.xwad.os.utils.FileUtil;
|
||||
import com.xwad.os.utils.GlideLoadUtils;
|
||||
import com.xwad.os.utils.LenovoCsdkUtil;
|
||||
import com.xwad.os.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -25,12 +25,13 @@ import com.xwad.os.manager.AppManager;
|
||||
import com.xwad.os.manager.ConnectManager;
|
||||
import com.xwad.os.manager.DeviceSNManager;
|
||||
import com.xwad.os.manager.RemoteManager;
|
||||
import com.xwad.os.mdm.AdminManager;
|
||||
import com.xwad.os.network.NetInterfaceManager;
|
||||
import com.xwad.os.push.PushManager;
|
||||
import com.xwad.os.receiver.ApkInstallReceiver;
|
||||
import com.xwad.os.utils.ActivationUtil;
|
||||
import com.xwad.os.utils.AppUsedTimeUtils;
|
||||
import com.xwad.os.utils.LenovoCsdkUtil;
|
||||
import com.xwad.os.utils.JgyUtils;
|
||||
import com.xwad.os.utils.OpenApkUtils;
|
||||
import com.xwad.os.utils.SystemUtils;
|
||||
|
||||
@@ -83,7 +84,8 @@ public class BaseApplication extends Application {
|
||||
|
||||
ActivationUtil.init(this);
|
||||
RemoteManager.init(this);
|
||||
LenovoCsdkUtil.init(this);
|
||||
JgyUtils.init(this);
|
||||
AdminManager.init(this);
|
||||
|
||||
CrashReport.initCrashReport(getApplicationContext(), "4efcaad4c9", false);
|
||||
CrashReport.setDeviceId(BaseApplication.this, DeviceSNManager.getDeviceSN());
|
||||
|
||||
@@ -41,6 +41,8 @@ public class CommonConfig {
|
||||
/*保存激活码*/
|
||||
public static final String ACTIVATIONBEAN_CODE_KEY = "UIUI_ACTIVATIONBEAN_CODE";
|
||||
|
||||
public static final String INSTALL_SD_APKS = "install_sd_apks";
|
||||
|
||||
/*是否显示返回Android按钮*/
|
||||
public static final String UIUI_RETURN_ANDROID_KEY = "iflytek_uiui_is_return_android";
|
||||
|
||||
@@ -80,4 +82,22 @@ public class CommonConfig {
|
||||
/*是否为管理员app*/
|
||||
public static final String APP_ADMIN = "iflytek_setting_admin_app";
|
||||
|
||||
|
||||
/*禁止联网应用*/
|
||||
public final static String AOLE_ACTION_NETWORK_DISALLOW = "aole_network_disallow";
|
||||
|
||||
|
||||
/*通话白名单开关*/
|
||||
public final static String STRANGE_PHONE_DENY = "strange_phone_deny";
|
||||
/*通话白名单*/
|
||||
public static final String NUMBER_BLACK_WHITE_LIST = "mdm_call_black_and_white_list";
|
||||
|
||||
/*app安装白名单开关*/
|
||||
public static final String APP_WHITELIST_CONTROL = "app_whitelist_control";
|
||||
|
||||
/*通知栏常驻*/
|
||||
public static final String NOTI_BAR_PERMANENT_KEY = "notification_bar_permanent";
|
||||
public static final String NOTI_BAR_PERMANENT_ACTION = "notification_bar_permanent_action";
|
||||
/*是否允许通知*/
|
||||
public static final String ALLOW_NOTIFICATION = "allow_notification";
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.xwad.os.fragment.user;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
@@ -11,10 +10,8 @@ import com.google.gson.reflect.TypeToken;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.FragmentEvent;
|
||||
import com.xwad.os.BuildConfig;
|
||||
import com.xwad.os.R;
|
||||
import com.xwad.os.base.mvvm.BaseViewModel;
|
||||
import com.xwad.os.bean.AppUsed;
|
||||
import com.xwad.os.bean.BaseResponse;
|
||||
import com.xwad.os.bean.DesktopIcon;
|
||||
import com.xwad.os.bean.HomeworkBean;
|
||||
@@ -25,13 +22,11 @@ import com.xwad.os.config.CommonConfig;
|
||||
import com.xwad.os.databinding.FragmentUserBinding;
|
||||
import com.xwad.os.manager.AppManager;
|
||||
import com.xwad.os.manager.DeviceSNManager;
|
||||
import com.xwad.os.manager.RemoteManager;
|
||||
import com.xwad.os.network.NetInterfaceManager;
|
||||
import com.xwad.os.network.UrlAddress;
|
||||
import com.xwad.os.utils.ActivationUtil;
|
||||
import com.xwad.os.utils.ApkUtils;
|
||||
import com.xwad.os.utils.CXAESUtil;
|
||||
import com.xwad.os.utils.LenovoCsdkUtil;
|
||||
import com.xwad.os.utils.TimeUtils;
|
||||
import com.xwad.os.utils.Utils;
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import androidx.lifecycle.Observer;
|
||||
import com.hjq.toast.Toaster;
|
||||
import com.xwad.os.BuildConfig;
|
||||
import com.xwad.os.R;
|
||||
import com.xwad.os.activity.home.HomeActivity;
|
||||
import com.xwad.os.activity.permission.PermissionActivity;
|
||||
import com.xwad.os.activity.service.ServiceActivity;
|
||||
import com.xwad.os.activity.update.UpdateActivity;
|
||||
@@ -19,9 +18,7 @@ import com.xwad.os.base.mvvm.fragment.BaseMvvmFragment;
|
||||
import com.xwad.os.bean.AppUpdateInfo;
|
||||
import com.xwad.os.databinding.FragmentDeviceBinding;
|
||||
import com.xwad.os.manager.DeviceSNManager;
|
||||
import com.xwad.os.manager.RemoteManager;
|
||||
import com.xwad.os.utils.ApkUtils;
|
||||
import com.xwad.os.utils.LenovoCsdkUtil;
|
||||
|
||||
public class DeviceFragment extends BaseMvvmFragment<DeviceViewModel, FragmentDeviceBinding> {
|
||||
|
||||
|
||||
@@ -19,9 +19,7 @@ import com.xwad.os.bean.SnInfo;
|
||||
import com.xwad.os.config.CommonConfig;
|
||||
import com.xwad.os.databinding.FragmentInfoBinding;
|
||||
import com.xwad.os.manager.DeviceSNManager;
|
||||
import com.xwad.os.manager.RemoteManager;
|
||||
import com.xwad.os.utils.ActivationUtil;
|
||||
import com.xwad.os.utils.LenovoCsdkUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
2031
app/src/main/java/com/xwad/os/mdm/AdminManager.java
Normal file
2031
app/src/main/java/com/xwad/os/mdm/AdminManager.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
package com.xwad.os.receiver;
|
||||
|
||||
import android.app.admin.DeviceAdminReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.xwad.os.R;
|
||||
|
||||
public class AoleDeviceAdminReceiver extends DeviceAdminReceiver {
|
||||
|
||||
@Override
|
||||
public CharSequence onDisableRequested(Context context, Intent intent) {
|
||||
return context.getString(R.string.disable_warning);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(Context context, Intent intent) {
|
||||
super.onEnabled(context, intent);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import android.util.Log;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import com.hjq.toast.Toaster;
|
||||
import com.xwad.os.BuildConfig;
|
||||
import com.xwad.os.R;
|
||||
import com.xwad.os.bean.AppUpdateInfo;
|
||||
@@ -27,7 +28,12 @@ import com.xwad.os.bean.DesktopIcon;
|
||||
import com.xwad.os.manager.RemoteManager;
|
||||
import com.xwad.os.receiver.InstallResultReceiver;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.Collator;
|
||||
@@ -512,6 +518,141 @@ public class ApkUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过路径安装APK,兼容Android 9以上
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param filePath apk文件路径
|
||||
*/
|
||||
public static void installApp(Context context, String filePath) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
installAppatPie(context, filePath);
|
||||
} else {
|
||||
installApps(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean installApps(String apkPath) {
|
||||
Toaster.showShort("正在安装应用");
|
||||
Process process = null;
|
||||
BufferedReader successResult = null;
|
||||
BufferedReader errorResult = null;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder errorMsg = new StringBuilder();
|
||||
try {
|
||||
process = new ProcessBuilder("pm", "install", "-i", BuildConfig.APPLICATION_ID, "--user", "0", apkPath).start();
|
||||
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
String s;
|
||||
while ((s = successResult.readLine()) != null) {
|
||||
successMsg.append(s);
|
||||
}
|
||||
while ((s = errorResult.readLine()) != null) {
|
||||
errorMsg.append(s);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("installApps1", e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
if (successResult != null) {
|
||||
successResult.close();
|
||||
}
|
||||
if (errorResult != null) {
|
||||
errorResult.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("installApps2", e.getMessage());
|
||||
}
|
||||
if (process != null) {
|
||||
process.destroy();
|
||||
}
|
||||
}
|
||||
Log.e("result", "" + errorMsg.toString());
|
||||
//如果含有“success”认为安装成功
|
||||
Log.e("installApp", successMsg.toString());
|
||||
// if (!successMsg.toString().equalsIgnoreCase("success")) {
|
||||
// install(context, new File(apkPath));
|
||||
// }
|
||||
return successMsg.toString().equalsIgnoreCase("success");
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public static void installAppatPie(Context context, String apkFilePath) {
|
||||
File file = new File(apkFilePath);
|
||||
PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
|
||||
PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstaller
|
||||
.SessionParams.MODE_FULL_INSTALL);
|
||||
sessionParams.setSize(file.length());
|
||||
int sessionId = createSession(packageInstaller, sessionParams);
|
||||
if (sessionId != -1) {
|
||||
boolean copySuccess = copyApkFile(packageInstaller, sessionId, apkFilePath);
|
||||
if (copySuccess) {
|
||||
install(packageInstaller, sessionId, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
private static boolean copyApkFile(PackageInstaller pi, int sessionId, String apkFilePath) {
|
||||
boolean success = false;
|
||||
File apkFile = new File(apkFilePath);
|
||||
PackageInstaller.Session session = null;
|
||||
try {
|
||||
session = pi.openSession(sessionId);
|
||||
OutputStream out = session.openWrite("app.apk", 0, apkFile.length());
|
||||
FileInputStream input = new FileInputStream(apkFile);
|
||||
int read = 0;
|
||||
byte[] buffer = new byte[65536];
|
||||
// while (read != -1) {
|
||||
// read = input.read(buffer);
|
||||
// out.write(buffer, 0, read);
|
||||
// }
|
||||
while (true) {
|
||||
read = input.read(buffer);
|
||||
if (read == -1) {
|
||||
session.fsync(out);
|
||||
success = true;
|
||||
out.close();
|
||||
input.close();
|
||||
break;
|
||||
}
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("fht", "copyApkFile" + e.getMessage());
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
private static void install(PackageInstaller packageInstaller, int sessionId, Context context) {
|
||||
try {
|
||||
PackageInstaller.Session session = packageInstaller.openSession(sessionId);
|
||||
Intent intent = new Intent(context, InstallResultReceiver.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
1, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
);
|
||||
session.commit(pendingIntent.getIntentSender());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "install: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
private static int createSession(PackageInstaller packageInstaller, PackageInstaller.SessionParams sessionParams) {
|
||||
int sessionId = -1;
|
||||
try {
|
||||
sessionId = packageInstaller.createSession(sessionParams);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 静默卸载应用
|
||||
*
|
||||
|
||||
1322
app/src/main/java/com/xwad/os/utils/JgyUtils.java
Normal file
1322
app/src/main/java/com/xwad/os/utils/JgyUtils.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,83 +0,0 @@
|
||||
package com.xwad.os.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.csdk.CSDKManager;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xwad.os.BuildConfig;
|
||||
import com.xwad.os.config.CommonConfig;
|
||||
|
||||
public class LenovoCsdkUtil {
|
||||
private static final String TAG = "LenovoCsdkUtil";
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static LenovoCsdkUtil sInstance;
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
private Context mContext;
|
||||
private CSDKManager mCSDKManager;
|
||||
|
||||
|
||||
private LenovoCsdkUtil(Context context) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("Context is NULL");
|
||||
}
|
||||
this.mContext = context;
|
||||
try {
|
||||
this.mCSDKManager = new CSDKManager(context);
|
||||
if (mCSDKManager.isLicenseKeyEnabled(BuildConfig.APPLICATION_ID)) {
|
||||
Log.e(TAG, "LenovoCsdkUtil: devices activated");
|
||||
} else {
|
||||
Log.e(TAG, "LenovoCsdkUtil: devices not activated");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "LenovoCsdkUtil: " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
Log.e(TAG, "init: ");
|
||||
sInstance = new LenovoCsdkUtil(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static LenovoCsdkUtil getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init LenovoCsdkUtil first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* int: 1 MAC
|
||||
* int: 2 SN
|
||||
* int: 3 Model
|
||||
* int: 4 IMEI
|
||||
*/
|
||||
public String getDeviceMac() {
|
||||
String mac = mCSDKManager.getDeviceInfo(1);
|
||||
return mac;
|
||||
}
|
||||
|
||||
// public String getSerial() {
|
||||
// if (BuildConfig.DEBUG) {
|
||||
// return "T811MN128GB23529041363";
|
||||
// }
|
||||
// String sn = mCSDKManager.getDeviceInfo(2);
|
||||
// return sn;
|
||||
// }
|
||||
|
||||
public String getDeviceModel() {
|
||||
String model = mCSDKManager.getDeviceInfo(3);
|
||||
return model;
|
||||
}
|
||||
|
||||
public String getDeviceIMEI() {
|
||||
String imei = mCSDKManager.getDeviceInfo(4);
|
||||
return imei;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xwad.os.utils;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@@ -13,14 +14,18 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.PowerManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
@@ -33,8 +38,10 @@ import com.xwad.os.BuildConfig;
|
||||
import com.xwad.os.R;
|
||||
import com.xwad.os.manager.RemoteManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Reader;
|
||||
@@ -43,11 +50,58 @@ import java.net.NetworkInterface;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class Utils {
|
||||
private static final String TAG = "Utils";
|
||||
|
||||
/**
|
||||
* 判断MagicOS 版本
|
||||
* https://developer.honor.com/cn/docs/adaptation_guide/guides/general_adaptation_guide
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getMagicOsVersion() {
|
||||
if (!isHonorDevice()) {
|
||||
// 非荣耀设备,暂不支持
|
||||
return -1;
|
||||
}
|
||||
// Android S及以上版本取用MAGIC_SDK_INT值
|
||||
if (Build.VERSION.SDK_INT >= 31) {
|
||||
return com.hihonor.android.os.Build.VERSION.MAGIC_SDK_INT;
|
||||
}
|
||||
// Android R版本对应MagicUI 5.0
|
||||
if (Build.VERSION.SDK_INT == 30) {
|
||||
return 31;
|
||||
}
|
||||
// Android Q版本对应MagicUI 4.0
|
||||
if (Build.VERSION.SDK_INT == 29) {
|
||||
return 26;
|
||||
}
|
||||
// Android Q以下版本返回-1
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 判定荣耀折叠屏设备
|
||||
*/
|
||||
public static boolean isHonorFoldableDevice(Context context) {
|
||||
if (Build.MANUFACTURER.equalsIgnoreCase("HONOR")
|
||||
&& context.getPackageManager() != null
|
||||
&& context.getPackageManager().hasSystemFeature("com.hihonor.hardware.sensor.posture")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 判定荣耀设备
|
||||
*/
|
||||
public static boolean isHonorDevice() {
|
||||
return "HONOR".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备序列号
|
||||
* <p>
|
||||
@@ -76,6 +130,8 @@ public class Utils {
|
||||
// }
|
||||
// return serial;
|
||||
// }
|
||||
|
||||
|
||||
public static String getAndroiodScreenProperty(Context context) {
|
||||
Log.e("getAndroiodScreenProperty", "heightPixels:" + context.getResources().getDisplayMetrics().heightPixels);
|
||||
Log.e("getAndroiodScreenProperty", "widthPixels:" + context.getResources().getDisplayMetrics().widthPixels);
|
||||
@@ -102,16 +158,179 @@ public class Utils {
|
||||
return width + "×" + height;
|
||||
}
|
||||
|
||||
public static String getDeviceSN() {
|
||||
String serial = null;
|
||||
/**
|
||||
* @return 序列号
|
||||
*/
|
||||
public static String getSerial(Context context) {
|
||||
String serialNumber = "unknow";
|
||||
try {
|
||||
Class<?> c = Class.forName("android.os.SystemProperties");
|
||||
Method get = c.getMethod("get", String.class);
|
||||
serial = (String) get.invoke(c, "persist.sys.hrSerial");
|
||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {//9.0+
|
||||
serialNumber = Build.getSerial();
|
||||
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {//8.0+
|
||||
serialNumber = Build.SERIAL;
|
||||
} else {//8.0-
|
||||
Class<?> c = Class.forName("android.os.SystemProperties");
|
||||
Method get = c.getMethod("get", String.class);
|
||||
serialNumber = (String) get.invoke(c, "ro.serialno");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("getSerial", "读取设备序列号异常:" + e.toString());
|
||||
}
|
||||
return serialNumber;
|
||||
}
|
||||
|
||||
public static String getSerial() {
|
||||
String serialNumber = "unknow";
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {//9.0+
|
||||
serialNumber = Build.getSerial();
|
||||
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {//8.0+
|
||||
serialNumber = Build.SERIAL;
|
||||
} else {//8.0-
|
||||
Class<?> c = Class.forName("android.os.SystemProperties");
|
||||
Method get = c.getMethod("get", String.class);
|
||||
serialNumber = (String) get.invoke(c, "ro.serialno");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("getSerial", "读取设备序列号异常:" + e.toString());
|
||||
}
|
||||
return serialNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context 获取真实的MAC地址
|
||||
* @return
|
||||
*/
|
||||
public static String getAndroid10MAC(Context context) {
|
||||
// if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
|
||||
// return getMacAddress(context);
|
||||
// } else {
|
||||
// return getAndroid7MAC();
|
||||
// }
|
||||
return getAllMacAddress(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取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();
|
||||
}
|
||||
return serial;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容7.0获取不到的问题
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getAndroid7MAC() {
|
||||
try {
|
||||
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
|
||||
for (NetworkInterface nif : all) {
|
||||
if (!nif.getName().equalsIgnoreCase("wlan0"))
|
||||
continue;
|
||||
byte[] macBytes = nif.getHardwareAddress();
|
||||
if (macBytes == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder res1 = new StringBuilder();
|
||||
for (byte b : macBytes) {
|
||||
res1.append(String.format("%02X:", b));
|
||||
}
|
||||
if (res1.length() > 0) {
|
||||
res1.deleteCharAt(res1.length() - 1);
|
||||
}
|
||||
return res1.toString();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历循环所有的网络接口,找到接口是 wlan0
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String getMacFromHardware() {
|
||||
try {
|
||||
List<NetworkInterface> 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地址";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,36 +571,6 @@ public class Utils {
|
||||
return macSerial;
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容7.0获取不到的问题
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getAndroid7MAC() {
|
||||
try {
|
||||
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
|
||||
for (NetworkInterface nif : all) {
|
||||
if (!"wlan0".equalsIgnoreCase(nif.getName()))
|
||||
continue;
|
||||
byte[] macBytes = nif.getHardwareAddress();
|
||||
if (macBytes == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder res1 = new StringBuilder();
|
||||
for (byte b : macBytes) {
|
||||
res1.append(String.format("%02X:", b));
|
||||
}
|
||||
if (res1.length() > 0) {
|
||||
res1.deleteCharAt(res1.length() - 1);
|
||||
}
|
||||
return res1.toString();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Log.e(TAG, "getAndroid7MAC: " + ex.getMessage());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String loadFileAsString(String fileName) throws Exception {
|
||||
FileReader reader = new FileReader(fileName);
|
||||
String text = loadReaderAsString(reader);
|
||||
|
||||
@@ -25,4 +25,46 @@
|
||||
<string name="license_verification_successful">许可证验证成功,本账户已可长期使用,\n点击开启学习之旅!</string>
|
||||
<string name="validity_period">有效期:%d年</string>
|
||||
<string name="qrcode_expiration_time">二维码过期时间%s</string>
|
||||
|
||||
<!--MagicOS-->
|
||||
<string name="current_state_wifi">"当前状态:"</string>
|
||||
<string name="current_state_keep_alive">"当前状态:"</string>
|
||||
<string name="current_state_screen_capture">"当前状态:"</string>
|
||||
<string name="state_restricted">已禁用</string>
|
||||
<string name="state_nomal">未禁用</string>
|
||||
<string name="state_keep_alive">已保活</string>
|
||||
<string name="state_cancel_alive">未保活</string>
|
||||
<string name="disable_wifi">禁用WiFi</string>
|
||||
<string name="enable_wifi">启用WiFi</string>
|
||||
<string name="keep_alive">将该应用保活</string>
|
||||
<string name="cancel_alive">取消该应用保活</string>
|
||||
<string name="enable_screen_capture">启用截屏</string>
|
||||
<string name="disable_screen_capture">禁用截屏</string>
|
||||
<string name="enable_data_conn">启用数据连接</string>
|
||||
<string name="state_not_actived">该应用未激活</string>
|
||||
<string name="no_permission">无操作权限</string>
|
||||
<string name="not_support">本应用只支持MAGIC4及以上的版本</string>
|
||||
<string name="disable_warning">取消激活后将导致本软件的部分功能无法正常工作,您确定要取消激活么?</string>
|
||||
<string name="accept_btn">同意</string>
|
||||
<string name="exit_btn">退出</string>
|
||||
<string name="know">已阅读</string>
|
||||
<string name="not_show_anymore">不再提示</string>
|
||||
<string name="title_license">免责声明与软件许可协议</string>
|
||||
<string name="title_permissions">权限使用声明</string>
|
||||
<string name="read_statement">若您点击同意并开始使用本软件,代表您已阅读并接受<a href="http://www.hihonor.mdm.com">《免责声明与软件许可协议》</a>。</string>
|
||||
<string name="title_activemode">请选择以下模式中的一种进行设备管理器的激活。</string>
|
||||
<string name="user_active_description">用户确认激活模式即普通的激活方式,激活后用户可随时解除激活。</string>
|
||||
<string name="force_active_description">强制激活模式只在企业定制版本(通过荣耀商城企业定制服务进行定制的终端版本)上生效,用户只能点击激活,激活成功后无法手动解除激活。</string>
|
||||
<string name="delay_active_description">延时解除激活模式请先输入延迟时间(范围在1~72的数字),激活成功后用户在设定的延迟时间(单位:小时)过后才能解除激活设备管理器。</string>
|
||||
<string name="user_activemode">用户确认激活模式</string>
|
||||
<string name="force_activemode">强制激活模式</string>
|
||||
<string name="delay_activemode">延时解除激活模式</string>
|
||||
<string name="delay_hint">请输入延迟时间,范围:1~72</string>
|
||||
<string name="remove_active_admin">解除激活设备管理器</string>
|
||||
<string name="force_active_error">setForcedActiveDeviceAdmin error</string>
|
||||
<string name="delay_deactive_error">setDelayDeactiveDeviceAdmin error</string>
|
||||
|
||||
<string name="sample_device_admin">为关怀系统提供管控功能,请激活后使用</string>
|
||||
<string name="sample_device_admin_description">开启我吧</string>
|
||||
|
||||
</resources>
|
||||
|
||||
14
app/src/main/res/xml/device_admin_sample.xml
Normal file
14
app/src/main/res/xml/device_admin_sample.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<device-admin>
|
||||
<uses-policies>
|
||||
<limit-password />
|
||||
<watch-login />
|
||||
<reset-password />
|
||||
<force-lock />
|
||||
<wipe-data />
|
||||
<expire-password />
|
||||
<encrypted-storage />
|
||||
<disable-camera />
|
||||
<disable-keyguard-features />
|
||||
</uses-policies>
|
||||
</device-admin>
|
||||
Reference in New Issue
Block a user