正在查看: Tasker v6.5.11 应用的 PreferencesConfigurationManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Tasker v6.5.11 应用的 PreferencesConfigurationManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package chip.platform;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import java.util.Base64;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
public class PreferencesConfigurationManager implements ConfigurationManager {
private SharedPreferences preferences;
private final String TAG = KeyValueStoreManager.class.getSimpleName();
private final String PREFERENCE_FILE_KEY = "chip.platform.ConfigurationManager";
public PreferencesConfigurationManager(Context context) {
this.preferences = context.getSharedPreferences("chip.platform.ConfigurationManager", 0);
try {
String key = getKey(ConfigurationManager.kConfigNamespace_ChipFactory, ConfigurationManager.kConfigKey_UniqueId);
if (this.preferences.contains(key)) {
return;
}
this.preferences.edit().putString(key, UUID.randomUUID().toString().replaceAll("-", "")).apply();
} catch (AndroidChipPlatformException e) {
e.printStackTrace();
}
}
private String getKey(String str, String str2) throws AndroidChipPlatformException {
if (str != null && str2 != null) {
return str + ":" + str2;
}
if (str == null || str2 != null) {
throw new AndroidChipPlatformException();
}
return str + ":";
}
@Override
public void clearConfigValue(String str, String str2) throws AndroidChipPlatformException {
if (str != null && str2 != null) {
this.preferences.edit().remove(getKey(str, str2)).apply();
return;
}
if (str == null || str2 != null) {
if (str == null && str2 == null) {
this.preferences.edit().clear().apply();
return;
}
return;
}
String key = getKey(str, null);
SharedPreferences.Editor edit = this.preferences.edit();
Iterator<Map.Entry<String, ?>> it = this.preferences.getAll().entrySet().iterator();
while (it.hasNext()) {
String key2 = it.next().getKey();
if (key2.startsWith(key)) {
edit.remove(key2);
}
}
edit.apply();
}
@Override
public boolean configValueExists(String str, String str2) throws AndroidChipPlatformException {
return this.preferences.contains(getKey(str, str2));
}
@Override
public byte[] readConfigValueBin(String str, String str2) throws AndroidChipPlatformException {
Base64.Decoder decoder;
byte[] decode;
String key = getKey(str, str2);
if (this.preferences.contains(key)) {
String string = this.preferences.getString(key, null);
decoder = Base64.getDecoder();
decode = decoder.decode(string);
return decode;
}
Log.d(this.TAG, "Key '" + key + "' not found in shared preferences");
throw new AndroidChipPlatformException();
}
@Override
public long readConfigValueLong(String str, String str2) throws AndroidChipPlatformException {
String key;
key = getKey(str, str2);
key.hashCode();
switch (key) {
case "chip-factory:hardware-ver":
return 1L;
case "chip-factory:product-id":
return 32771L;
case "chip-factory:software-version":
return 1L;
default:
if (this.preferences.contains(key)) {
return this.preferences.getLong(key, Long.MAX_VALUE);
}
Log.d(this.TAG, "Key '" + key + "' not found in shared preferences");
throw new AndroidChipPlatformException();
}
}
@Override
public String readConfigValueStr(String str, String str2) throws AndroidChipPlatformException {
String key;
key = getKey(str, str2);
key.hashCode();
switch (key) {
case "chip-factory:product-url":
return "https://buildwithmatter.com/";
case "chip-factory:mfg-date":
return "2021-12-06";
case "chip-factory:product-name":
return "TEST_ANDROID_PRODUCT";
case "chip-factory:part-number":
return "TEST_ANDROID_PRODUCT_BLUE";
case "chip-factory:hardware-ver-str":
return "TEST_ANDROID_VERSION";
case "chip-factory:serial-num":
return "TEST_ANDROID_SN";
case "chip-factory:product-label":
return "X10";
case "chip-factory:software-version-str":
return "prerelease(android)";
default:
if (this.preferences.contains(key)) {
return this.preferences.getString(key, null);
}
Log.d(this.TAG, "Key '" + key + "' not found in shared preferences");
throw new AndroidChipPlatformException();
}
}
@Override
public void writeConfigValueBin(String str, String str2, byte[] bArr) throws AndroidChipPlatformException {
Base64.Encoder encoder;
String encodeToString;
String key = getKey(str, str2);
if (bArr == null) {
this.preferences.edit().remove(key).apply();
return;
}
encoder = Base64.getEncoder();
encodeToString = encoder.encodeToString(bArr);
this.preferences.edit().putString(key, encodeToString).apply();
}
@Override
public void writeConfigValueLong(String str, String str2, long j) throws AndroidChipPlatformException {
this.preferences.edit().putLong(getKey(str, str2), j).apply();
}
@Override
public void writeConfigValueStr(String str, String str2, String str3) throws AndroidChipPlatformException {
this.preferences.edit().putString(getKey(str, str2), str3).apply();
}
}