2015-10-04 15:53:11 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
|
|
|
|
|
|
|
|
|
|
|
|
import android.util.Pair;
|
|
|
|
|
2017-01-20 19:17:00 +01:00
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2015-10-04 15:53:11 +02:00
|
|
|
import java.util.ArrayList;
|
2017-01-20 19:17:00 +01:00
|
|
|
import java.util.Map;
|
2015-10-04 15:53:11 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
2017-01-08 17:17:29 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
|
2016-05-16 23:00:04 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2016-12-31 18:56:24 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
2017-01-20 19:17:00 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
2015-10-04 15:53:11 +02:00
|
|
|
|
2017-01-01 16:24:46 +01:00
|
|
|
class AppMessageHandler {
|
2016-12-31 18:56:24 +01:00
|
|
|
final PebbleProtocol mPebbleProtocol;
|
|
|
|
final UUID mUUID;
|
2017-01-20 19:17:00 +01:00
|
|
|
protected Map<String, Integer> messageKeys;
|
2015-10-04 15:53:11 +02:00
|
|
|
|
|
|
|
AppMessageHandler(UUID uuid, PebbleProtocol pebbleProtocol) {
|
|
|
|
mUUID = uuid;
|
|
|
|
mPebbleProtocol = pebbleProtocol;
|
|
|
|
}
|
|
|
|
|
2016-06-04 21:50:26 +02:00
|
|
|
public boolean isEnabled() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-04 15:53:11 +02:00
|
|
|
public UUID getUUID() {
|
|
|
|
return mUUID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
|
2017-01-08 17:17:29 +01:00
|
|
|
// Just ACK
|
|
|
|
GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
|
|
|
|
sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
|
|
|
|
return new GBDeviceEvent[]{sendBytesAck};
|
2015-10-04 15:53:11 +02:00
|
|
|
}
|
|
|
|
|
2016-12-31 19:04:05 +01:00
|
|
|
public GBDeviceEvent[] onAppStart() {
|
2015-12-23 14:22:28 +01:00
|
|
|
return null;
|
|
|
|
}
|
2016-05-13 23:47:47 +02:00
|
|
|
|
2016-12-31 18:56:24 +01:00
|
|
|
public byte[] encodeUpdateWeather(WeatherSpec weatherSpec) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-05-16 23:00:04 +02:00
|
|
|
protected GBDevice getDevice() {
|
|
|
|
return mPebbleProtocol.getDevice();
|
2016-05-13 23:47:47 +02:00
|
|
|
}
|
2017-01-20 19:17:00 +01:00
|
|
|
|
|
|
|
protected JSONObject getAppKeys() throws IOException, JSONException {
|
|
|
|
File destDir = new File(FileUtils.getExternalFilesDir() + "/pbw-cache");
|
|
|
|
File configurationFile = new File(destDir, mUUID.toString() + ".json");
|
|
|
|
if (configurationFile.exists()) {
|
|
|
|
String jsonstring = FileUtils.getStringFromFile(configurationFile);
|
|
|
|
JSONObject json = new JSONObject(jsonstring);
|
|
|
|
return json.getJSONObject("appKeys");
|
|
|
|
}
|
|
|
|
throw new IOException();
|
|
|
|
}
|
2015-10-04 15:53:11 +02:00
|
|
|
}
|