[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

@@ -6,10 +6,9 @@ import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.collection.ArrayMap;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.storage.SpStorage;
import com.mogo.commons.storage.SharedPrefsMgr;
import com.mogo.eagle.core.network.Constants;
import com.mogo.eagle.core.network.LocationHelper;
import com.mogo.eagle.core.network.ServerParam;
@@ -41,8 +40,8 @@ public class ParamsUtil {
params.put(ServerParam.CELL_ID, DeviceUtils.getCellId());
// params.put( ServerParam.DISPLAY_ID, DeviceUtil.getSystemVersion() );
params.put(ServerParam.SN, MoGoAiCloudClientConfig.getInstance().getSn());
params.put(ServerParam.TICKET, SpStorage.getTicket());
params.put(ServerParam.SN, SharedPrefsMgr.getInstance().getSn());
params.put(ServerParam.TICKET, SharedPrefsMgr.getInstance().getToken());
return params;
}
@@ -77,7 +76,7 @@ public class ParamsUtil {
map.put("debug", DebugConfig.isDebug() ? 1 : 0);
String fota = DeviceUtils.getFotaVersion();
map.put("systemversion", TextUtils.isEmpty(fota) ? DebugConfig.getProductFlavor() : fota);
map.put("sn", MoGoAiCloudClientConfig.getInstance().getSn());
map.put("sn", SharedPrefsMgr.getInstance().getSn());
return map;
}

View File

@@ -0,0 +1,218 @@
package com.mogo.commons.storage;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;
import java.util.Set;
import androidx.annotation.NonNull;
import com.mogo.cloud.passport.SpStorage;
import com.mogo.commons.AbsMogoApplication;
public class SharedPrefsMgr {
private static final String File_Name = "app_shared_pref";
private static SharedPrefsMgr sInstance;
private static SharedPreferences sSharedPrefs;
private String sn;
private String token;
public synchronized static SharedPrefsMgr getInstance() {
if ( sInstance == null ) {
try {
sInstance = new SharedPrefsMgr(AbsMogoApplication.getApp());
} 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 putSn(String value ) {
try {
sn = value;
SharedPreferences.Editor editor = sSharedPrefs.edit();
editor.putString( "sn", value );
editor.apply();
} catch ( Exception e ) {
}
}
private String getDeviceSn(){
try {
return sSharedPrefs.getString( "sn", "" );
} catch ( Exception e ) {
return "";
}
}
public String getSn() {
if (sn != null && !sn.isEmpty()) {
return sn;
}
if (TextUtils.isEmpty(SpStorage.getSn())) {
Log.e("SharedPrefsMgr", "本地 SN 获取失败……");
}
return getDeviceSn();
}
public void putToken(String value ){
try {
token = value;
SharedPreferences.Editor editor = sSharedPrefs.edit();
editor.putString( "token", value );
editor.apply();
} catch ( Exception e ) {
}
}
public String getToken() {
if (token != null && !token.isEmpty()) {
return token;
}
if (TextUtils.isEmpty(SpStorage.getToken())) {
Log.e("SharedPrefsMgr", "本地 Token 获取失败……");
}
return getDeviceToken();
}
private String getDeviceToken(){
try {
return sSharedPrefs.getString( "token", "" );
} catch ( Exception e ) {
return "";
}
}
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,29 +0,0 @@
package com.mogo.commons.storage;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr;
/**
* @author congtaowang
* @since 2020-01-03
* <p>
* sp 公共缓存区域
*/
public class SpStorage {
public static String getTicket() {
return SharedPrefsMgr.getInstance( AbsMogoApplication.getApp() ).getString( "token" );
}
public static void setTicket( String ticket ) {
SharedPrefsMgr.getInstance( AbsMogoApplication.getApp() ).putString( "token", ticket );
}
public static String getNavigationTarget(){
return SharedPrefsMgr.getInstance( AbsMogoApplication.getApp() ).getString( "naviTarget" );
}
public static void setNavigationTarget( String naviTarget ) {
SharedPrefsMgr.getInstance( AbsMogoApplication.getApp() ).putString( "naviTarget", naviTarget );
}
}

View File

@@ -7,7 +7,7 @@ import com.elegant.analytics.Analytics
import com.elegant.analytics.AnalyticsConfig
import com.elegant.analytics.IAnalyticsParamsProvider
import com.elegant.analytics.UploadMode
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
import com.mogo.commons.storage.SharedPrefsMgr
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.utilcode.util.AppUtils
@@ -56,7 +56,7 @@ object MogoAnalyticUtils {
fun getAnalyticsCustomParams(isDebug: Boolean): Map<String, Any> {
val map: MutableMap<String, Any> = ArrayMap()
map["debug"] = if (isDebug) 1 else 0
map["sn"] = MoGoAiCloudClientConfig.getInstance().sn
map["sn"] = SharedPrefsMgr.getInstance().sn
map["app_version"] = AppUtils.getAppVersionName()
map["app_identity_mode"] = FunctionBuildConfig.appIdentityMode