[6.2.6] sp opt , update aicloud upload loc thread

This commit is contained in:
EmArrow
2024-01-03 16:31:29 +08:00
parent 74824c1eba
commit 6729fe50af
135 changed files with 649 additions and 792 deletions

View File

@@ -1,154 +0,0 @@
package com.mogo.eagle.core.utilcode.mogo.storage;
import android.content.Context;
import android.content.SharedPreferences;
import java.util.Set;
import androidx.annotation.NonNull;
public class SharedPrefsMgr {
private static final String File_Name = "app_shared_pref";
private static SharedPrefsMgr sInstance;
private static SharedPreferences sSharedPrefs;
public synchronized static SharedPrefsMgr getInstance( @NonNull Context context ) {
if ( sInstance == null ) {
try {
sInstance = new SharedPrefsMgr( context.getApplicationContext() );
} catch ( Exception e ) {
sInstance = new SharedPrefsMgr();
}
}
return sInstance;
}
private SharedPrefsMgr() {
}
private SharedPrefsMgr( Context context ) {
try {
sSharedPrefs = context.getSharedPreferences( File_Name, Context.MODE_PRIVATE );
} catch ( Exception e ) {
e.printStackTrace();
}
}
public void putString( String key, String value ) {
try {
SharedPreferences.Editor editor = sSharedPrefs.edit();
editor.putString( key, value );
editor.apply();
} catch ( Exception e ) {
}
}
public String getString( String tag ) {
try {
return sSharedPrefs.getString( tag, "" );
} catch ( Exception e ) {
return "";
}
}
public String getString( String tag, String defVal ) {
try {
return sSharedPrefs.getString( tag, defVal );
} catch ( Exception e ) {
return "";
}
}
public boolean getBoolean( String key, boolean defaultValue ) {
try {
return sSharedPrefs.getBoolean( key, defaultValue );
} catch ( Exception e ) {
return defaultValue;
}
}
public long getLong( String key, long defaultValue ) {
try {
return sSharedPrefs.getLong( key, defaultValue );
} catch ( Exception e ) {
return defaultValue;
}
}
public float getFloat( String key, float defaultValue ) {
try {
return sSharedPrefs.getFloat( key, defaultValue );
} catch ( Exception e ) {
return defaultValue;
}
}
public int getInt( String key, int value ) {
try {
return sSharedPrefs.getInt( key, value );
} catch ( Exception e ) {
return value;
}
}
public void putBoolean( String key, boolean value ) {
try {
SharedPreferences.Editor editor = sSharedPrefs.edit();
editor.putBoolean( key, value );
editor.apply();
} catch ( Exception e ) {
}
}
public void putLong( String key, long value ) {
try {
SharedPreferences.Editor editor = sSharedPrefs.edit();
editor.putLong( key, value );
editor.apply();
} catch ( Exception e ) {
}
}
public void putInt( String key, int value ) {
try {
SharedPreferences.Editor editor = sSharedPrefs.edit();
editor.putInt( key, value );
editor.apply();
} catch ( Exception e ) {
}
}
public void putFloat( String key, float value ) {
try {
SharedPreferences.Editor editor = sSharedPrefs.edit();
editor.putFloat( key, value );
editor.apply();
} catch ( Exception e ) {
}
}
public void remove( String key ) {
try {
SharedPreferences.Editor editor = sSharedPrefs.edit();
editor.remove( key );
editor.apply();
} catch ( Exception e ) {
}
}
public void putStringSet( String key, Set< String > values ) {
try {
SharedPreferences.Editor editor = sSharedPrefs.edit();
editor.putStringSet( key, values );
editor.apply();
} catch ( Exception e ) {
}
}
public Set<String> getStringSet( String key ) {
return sSharedPrefs.getStringSet( key, null );
}
}

View File

@@ -1,149 +0,0 @@
package com.mogo.eagle.core.utilcode.util;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.media.MediaDrm;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import androidx.core.content.ContextCompat;
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.UUID;
public final class DeviceIdUtils {
public static final String KEY_DEVICE_ID = "deviceId";
private DeviceIdUtils() {
}
private static void saveDeviceId(Context context, String deviceId) {
SharedPrefsMgr.getInstance(context).putString(KEY_DEVICE_ID, deviceId);
}
public static String getDeviceId(Context context) {
if (context == null) {
throw new NullPointerException("context must not be null.");
}
final Context appContext = context.getApplicationContext();
String deviceId = SharedPrefsMgr.getInstance(context).getString(KEY_DEVICE_ID);
if (TextUtils.isEmpty(deviceId)) {
deviceId = getDeviceIdInternal(appContext);
if (TextUtils.isEmpty(deviceId)) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
deviceId = ((TelephonyManager) appContext.getSystemService(Context.TELEPHONY_SERVICE)).getSimSerialNumber();
}
if (TextUtils.isEmpty(deviceId)) {
deviceId = getDeviceSerial();
if (TextUtils.isEmpty(deviceId) || deviceId.equalsIgnoreCase("unknown")) {
deviceId = getAndroidId(appContext);
if (TextUtils.isEmpty(deviceId)) {
deviceId = String.valueOf(System.currentTimeMillis());
}
}
}
}
saveDeviceId(appContext, deviceId);
}
return deviceId;
}
private static String getDeviceIdInternal(Context context) {
String id = "";
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
return id;
}
TelephonyManager telephonymanager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonymanager != null) {
id = telephonymanager.getDeviceId();
if (TextUtils.isEmpty(id)) {
id = "";
}
}
return id;
}
private static String getAndroidId(Context context) {
String s = "";
s = Settings.Secure.getString(context.getContentResolver(), "android_id");
if (TextUtils.isEmpty(s)) {
s = "";
}
return s;
}
private static String getDeviceSerial() {
String serial = "unknown";
try {
Class clazz = Class.forName("android.os.Build");
Class paraTypes = Class.forName("java.lang.String");
Method method = clazz.getDeclaredMethod("getString", paraTypes);
if (!method.isAccessible()) {
method.setAccessible(true);
}
serial = (String) method.invoke(new Build(), "ro.serialno");
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
return serial;
}
/**
* 获取数字版权管理设备ID
*
* @return WidevineID可能为空
*/
public static String getWidevineID(Context context) {
try {
//See https://stackoverflow.com/questions/16369818/how-to-get-crypto-scheme-uuid
//You can find some UUIDs in the https://github.com/google/ExoPlayer source code
final UUID WIDEVINE_UUID = new UUID(0xEDEF8BA979D64ACEL, 0xA3C827DCD51D21EDL);
MediaDrm mediaDrm = new MediaDrm(WIDEVINE_UUID);
byte[] widevineId = mediaDrm.getPropertyByteArray(MediaDrm.PROPERTY_DEVICE_UNIQUE_ID);
if (widevineId == null) {
return "";
}
StringBuilder sb = new StringBuilder();
for (byte aByte : widevineId) {
sb.append(String.format("%02x", aByte));
}
return sb.toString();
} catch (Exception | Error e) {
e.printStackTrace();
}
return "";
}
/**
* 获取数字版权管理设备ID,进行MD5加密获取32位的唯一标记给后台生成SN
*
* @return WidevineID可能为空
*/
public static String getWidevineIDWithMd5(Context context) {
try {
String widevineId = getWidevineID(context);
if (!TextUtils.isEmpty(widevineId)) {
widevineId = EncryptUtils.encryptHmacMD5ToString(widevineId, "MoGoAuto");
return widevineId;
} else {
return getDeviceId(context);
}
} catch (Exception | Error e) {
e.printStackTrace();
}
return getDeviceId(context);
}
}

View File

@@ -1,7 +1,6 @@
package com.mogo.eagle.core.utilcode
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
import com.zhidao.thirdlogin.utils.Aes
import org.junit.Assert.*
import org.junit.Test