2017-03-10 14:53:19 +01:00
|
|
|
/* Copyright (C) 2015-2017 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
|
|
|
Gobbetti
|
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
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-24 11:07:49 +01:00
|
|
|
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
|
|
|
|
2017-01-24 11:07:49 +01:00
|
|
|
JSONObject getAppKeys() throws IOException, JSONException {
|
2017-01-20 19:17:00 +01:00
|
|
|
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
|
|
|
}
|