1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 13:26:50 +01:00

added capability to push config via intents

This commit is contained in:
Daniel Dakhno 2021-11-09 22:48:30 +01:00 committed by Arjan Schrijver
parent faec433b95
commit bc60b66abf
4 changed files with 54 additions and 35 deletions

View File

@ -97,6 +97,7 @@ public class QHybridSupport extends QHybridBaseSupport {
public static final String QHYBRID_COMMAND_SET_WIDGET_CONTENT = "nodomain.freeyourgadget.gadgetbridge.Q_SET_WIDGET_CONTENT";
public static final String QHYBRID_COMMAND_SET_BACKGROUND_IMAGE = "nodomain.freeyourgadget.gadgetbridge.Q_SET_BACKGROUND_IMAGE";
public static final String QHYBRID_COMMAND_UNINSTALL_APP = "nodomain.freeyourgadget.gadgetbridge.Q_UNINSTALL_APP";
public static final String QHYBRID_COMMAND_PUSH_CONFIG = "nodomain.freeyourgadget.gadgetbridge.Q_PUSH_CONFIG";
public static final String QHYBRID_COMMAND_DOWNLOAD_FILE = "nodomain.freeyourgadget.gadgetbridge.Q_DOWNLOAD_FILE";
public static final String QHYBRID_COMMAND_UPLOAD_FILE = "nodomain.freeyourgadget.gadgetbridge.Q_UPLOAD_FILE";
@ -304,6 +305,7 @@ public class QHybridSupport extends QHybridBaseSupport {
globalFilter.addAction(QHYBRID_COMMAND_SET_MENU_MESSAGE);
globalFilter.addAction(QHYBRID_COMMAND_SET_WIDGET_CONTENT);
globalFilter.addAction(QHYBRID_COMMAND_UPLOAD_FILE);
globalFilter.addAction(QHYBRID_COMMAND_PUSH_CONFIG);
globalCommandReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@ -367,9 +369,13 @@ public class QHybridSupport extends QHybridBaseSupport {
break;
}
case QHYBRID_COMMAND_UPLOAD_FILE:{
if (GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREF_HYBRID_HR_DANGEROUS_EXTERNAL_INTENTS, true)) {
handleFileUploadIntent(intent);
}
if(!externalAccessAllowed()) break;
handleFileUploadIntent(intent);
break;
}
case QHYBRID_COMMAND_PUSH_CONFIG:{
if(!externalAccessAllowed()) break;
handleConfigSetIntent(intent);
break;
}
}
@ -378,6 +384,15 @@ public class QHybridSupport extends QHybridBaseSupport {
GBApplication.getContext().registerReceiver(globalCommandReceiver, globalFilter);
}
private void handleConfigSetIntent(Intent intent) {
String configJson = intent.getExtras().getString("EXTRA_CONFIG_JSON", "{}");
watchAdapter.pushConfigJson(configJson);
}
private boolean externalAccessAllowed(){
return GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREF_HYBRID_HR_DANGEROUS_EXTERNAL_INTENTS, true);
}
private void handleFileUploadIntent(Intent intent){
boolean generateHeader = intent.getBooleanExtra("EXTRA_GENERATE_FILE_HEADER", false);
String filePath = intent.getStringExtra("EXTRA_PATH");

View File

@ -156,4 +156,8 @@ public abstract class WatchAdapter {
public void uninstallApp(String appName) {
}
public void pushConfigJson(String configJson){
}
}

View File

@ -1224,39 +1224,29 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
@Override
public void onTestNewFunction() {
/*queueWrite(new ButtonConfigurationPutRequest(
new String[]{"test"},
new ButtonConfiguration[]{
new ButtonConfiguration(
"short_press_release", "stopwatchApp"
)
},
this
));*/
/*queueWrite(new FileLookupAndGetRequest(FileHandle.APP_CODE, this) {
@Override
public void handleFileData(byte[] fileData) {
log("test");
}
@Override
public void handleFileLookupError(FILE_LOOKUP_ERROR error) {
try{
JSONObject data = new JSONObject()
.put("push", new JSONObject()
.put("set", new JSONObject()
.put("widgetCustom0._.config.upper_text", "0 up")
.put("widgetCustom0._.config.lower_text", "0 low")
}
});*/
/*queueWrite(new TranslationsGetRequest(this){
@Override
public void handleTranslations(TranslationData translationData) {
translationData.replaceByOriginal("ON", "oi m8");
translationData.replaceByOriginal("OFF", "nah go away");
translationData.replaceByOriginal("Device is about to reset.", "oh frick no no no");
translationData.replaceByOriginal("Release button to stop reset.", "please don't let me die like that");
translationData.replaceByOriginal("Serial number", "Gadgetbridge :)");
translationData.replaceByOriginal("Dial Info", "Widgets");
TranslationsPutRequest request = new TranslationsPutRequest(translationData, FossilHRWatchAdapter.this);
queueWrite(request);
}
});*/
.put("widgetCustom1._.config.upper_text", "1 up")
.put("widgetCustom1._.config.lower_text", "1 low")
.put("widgetCustom2._.config.upper_text", "2 up")
.put("widgetCustom2._.config.lower_text", "2 low")
.put("widgetCustom3._.config.upper_text", "3 up")
.put("widgetCustom3._.config.lower_text", "3 low")
)
);
queueWrite(new JsonPutRequest(data, this));
}catch (Exception e) {
e.printStackTrace();
}
}
public byte[] getSecretKey() throws IllegalAccessException {
@ -1279,6 +1269,12 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
return authKeyBytes;
}
@Override
public void pushConfigJson(String configJson){
configJson = configJson.replace("\n", "");
queueWrite(new JsonPutRequest(configJson, this));
}
public void setPhoneRandomNumber(byte[] phoneRandomNumber) {
this.phoneRandomNumber = phoneRandomNumber;
}

View File

@ -23,6 +23,10 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
public class JsonPutRequest extends FilePutRawRequest {
public JsonPutRequest(JSONObject object, FossilHRWatchAdapter adapter) {
super((short)(0x0500 | (adapter.getJsonIndex() & 0xFF)), object.toString().getBytes(), adapter);
this(object.toString(), adapter);
}
public JsonPutRequest(String json, FossilHRWatchAdapter adapter) {
super((short)(0x0500 | (adapter.getJsonIndex() & 0xFF)), json.getBytes(), adapter);
}
}