1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-28 03:25:49 +01:00

updated some requests, still dunno why some files time out...

This commit is contained in:
Daniel Dakhno 2019-10-30 02:50:00 +01:00
parent 06d7568249
commit 25a67b2ebb
16 changed files with 289 additions and 74 deletions

View File

@ -47,12 +47,14 @@ import androidx.annotation.Nullable;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class ConfigActivity extends AbstractGBActivity {
PackageAdapter adapter;
@ -131,8 +133,14 @@ public class ConfigActivity extends AbstractGBActivity {
ListView appList = findViewById(R.id.qhybrid_appList);
try {
helper = new PackageConfigHelper(getApplicationContext());
list = helper.getSettings();
list = helper.getNotificationConfigurations();
} catch (GBException e) {
e.printStackTrace();
GB.toast("error getting configurations", Toast.LENGTH_SHORT, GB.ERROR, e);
list = new ArrayList<>();
}
list.add(null);
appList.setAdapter(adapter = new PackageAdapter(this, R.layout.qhybrid_package_settings_item, list));
appList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@ -152,7 +160,13 @@ public class ConfigActivity extends AbstractGBActivity {
public void onFinish(boolean success, NotificationConfiguration config) {
setControl(false, null);
if (success) {
helper.saveConfig(config);
try {
helper.saveNotificationConfiguration(config);
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED));
} catch (GBException e) {
e.printStackTrace();
GB.toast("error saving notification", Toast.LENGTH_SHORT, GB.ERROR, e);
}
refreshList();
}
}
@ -173,7 +187,13 @@ public class ConfigActivity extends AbstractGBActivity {
break;
}
case "delete": {
helper.deleteConfig((NotificationConfiguration) adapterView.getItemAtPosition(i));
try {
helper.deleteNotificationConfiguration((NotificationConfiguration) adapterView.getItemAtPosition(i));
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED));
} catch (GBException e) {
e.printStackTrace();
GB.toast("error deleting setting", Toast.LENGTH_SHORT, GB.ERROR, e);
}
refreshList();
break;
}
@ -331,7 +351,12 @@ public class ConfigActivity extends AbstractGBActivity {
private void refreshList() {
list.clear();
list.addAll(helper.getSettings());
try {
list.addAll(helper.getNotificationConfigurations());
} catch (GBException e) {
e.printStackTrace();
GB.toast("error getting configurations", Toast.LENGTH_SHORT, GB.ERROR, e);
}
list.add(null);
adapter.notifyDataSetChanged();
}
@ -339,7 +364,6 @@ public class ConfigActivity extends AbstractGBActivity {
@Override
protected void onDestroy() {
super.onDestroy();
helper.close();
}
@Override

View File

@ -29,7 +29,7 @@ public class NotificationConfiguration implements Serializable {
this.vibration = vibration;
}
NotificationConfiguration(short min, short hour, String packageName, String appName, boolean respectSilentMode, PlayNotificationRequest.VibrationType vibration, long id) {
public NotificationConfiguration(short min, short hour, String packageName, String appName, boolean respectSilentMode, PlayNotificationRequest.VibrationType vibration, long id) {
this.min = min;
this.hour = hour;
this.packageName = packageName;

View File

@ -8,10 +8,14 @@ import android.util.Log;
import java.util.ArrayList;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.database.DBOpenHelper;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.PlayNotificationRequest;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class PackageConfigHelper extends DBOpenHelper {
public class PackageConfigHelper {
public static final String DB_NAME = "qhybridNotifications.db";
public static final String DB_ID = "id";
public static final String DB_TABLE = "notifications";
@ -22,16 +26,12 @@ public class PackageConfigHelper extends DBOpenHelper {
public static final String DB_HOUR = "hourDegrees";
public static final String DB_RESPECT_SILENT = "respectSilent";
SQLiteDatabase database;
public PackageConfigHelper(Context context) {
super(context, DB_NAME, null);
this.database = getWritableDatabase();
public PackageConfigHelper(Context context) throws GBException {
initDB();
}
public void saveConfig(NotificationConfiguration settings){
public void saveNotificationConfiguration(NotificationConfiguration settings) throws GBException {
ContentValues values = new ContentValues(6);
values.put(DB_PACKAGE, settings.getPackageName());
values.put(DB_APPNAME, settings.getAppName());
@ -40,16 +40,25 @@ public class PackageConfigHelper extends DBOpenHelper {
values.put(DB_VIBRATION, settings.getVibration().getValue());
values.put(DB_RESPECT_SILENT, settings.getRespectSilentMode());
SQLiteDatabase database = GBApplication.acquireDB().getDatabase();
if(settings.getId() == -1) {
settings.setId(database.insert(DB_TABLE, null, values));
}else{
database.update(DB_TABLE, values, DB_ID + "=?", new String[]{String.valueOf(settings.getId())});
}
GBApplication.releaseDB();
//LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent());
}
public ArrayList<NotificationConfiguration> getSettings(){
public ArrayList<NotificationConfiguration> getNotificationConfigurations() throws GBException {
SQLiteDatabase database = GBApplication.acquireDB().getDatabase();
Cursor cursor = database.query(DB_TABLE, new String[]{"*"}, null, null, null, null, null);
GBApplication.releaseDB();
int size = cursor.getCount();
ArrayList<NotificationConfiguration> list = new ArrayList<>(size);
if(size > 0){
@ -78,9 +87,15 @@ public class PackageConfigHelper extends DBOpenHelper {
return list;
}
public NotificationConfiguration getSetting(String appName){
public NotificationConfiguration getNotificationConfiguration(String appName) throws GBException {
if(appName == null) return null;
SQLiteDatabase database = GBApplication.acquireDB().getDatabase();
Cursor c = database.query(DB_TABLE, new String[]{"*"}, DB_APPNAME + "=?", new String[]{appName}, null, null, null);
GBApplication.releaseDB();
if(c.getCount() == 0){
c.close();
return null;
@ -99,7 +114,9 @@ public class PackageConfigHelper extends DBOpenHelper {
return settings;
}
private void initDB(){
private void initDB() throws GBException {
SQLiteDatabase database = GBApplication.acquireDB().getDatabase();
database.execSQL("CREATE TABLE IF NOT EXISTS notifications(" +
DB_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
DB_PACKAGE + " TEXT, " +
@ -108,17 +125,18 @@ public class PackageConfigHelper extends DBOpenHelper {
DB_APPNAME + " TEXT," +
DB_RESPECT_SILENT + " INTEGER," +
DB_HOUR + " INTEGER DEFAULT -1);");
GBApplication.releaseDB();
}
@Override
public void close(){
super.close();
database.close();
}
public void deleteConfig(NotificationConfiguration packageSettings) {
public void deleteNotificationConfiguration(NotificationConfiguration packageSettings) throws GBException {
Log.d("DB", "deleting id " + packageSettings.getId());
if(packageSettings.getId() == -1) return;
this.database.delete(DB_TABLE, DB_ID + "=?", new String[]{String.valueOf(packageSettings.getId())});
SQLiteDatabase database = GBApplication.acquireDB().getDatabase();
database.delete(DB_TABLE, DB_ID + "=?", new String[]{String.valueOf(packageSettings.getId())});
GBApplication.releaseDB();
}
}

View File

@ -15,6 +15,7 @@ import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Collections;
import java.util.Comparator;
@ -23,9 +24,12 @@ import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import static android.view.View.GONE;
@ -39,7 +43,14 @@ public class QHybridAppChoserActivity extends AbstractGBActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qhybrid_app_choser);
try {
helper = new PackageConfigHelper(getApplicationContext());
} catch (GBException e) {
e.printStackTrace();
GB.toast("error getting database helper", Toast.LENGTH_SHORT, GB.ERROR, e);
finish();
return;
}
final ListView appList = findViewById(R.id.qhybrid_appChooserList);
final PackageManager manager = getPackageManager();
@ -78,7 +89,6 @@ public class QHybridAppChoserActivity extends AbstractGBActivity {
@Override
protected void onDestroy() {
super.onDestroy();
helper.close();
}
private void setControl(boolean control) {
@ -111,7 +121,12 @@ public class QHybridAppChoserActivity extends AbstractGBActivity {
public void onFinish(boolean success, NotificationConfiguration config) {
setControl(false);
if(success){
helper.saveConfig(config);
try {
helper.saveNotificationConfiguration(config);
} catch (GBException e) {
e.printStackTrace();
GB.toast("error saving configuration", Toast.LENGTH_SHORT, GB.ERROR, e);
}
finish();
}
}

View File

@ -22,6 +22,7 @@ import java.util.UUID;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationConfiguration;
@ -54,6 +55,7 @@ public class QHybridSupport extends QHybridBaseSupport {
public static final String QHYBRID_EVENT_SETTINGS_UPDATED = "nodomain.freeyourgadget.gadgetbridge.Q_SETTINGS_UPDATED";
public static final String QHYBRID_EVENT_FILE_UPLOADED = "nodomain.freeyourgadget.gadgetbridge.Q_FILE_UPLOADED";
public static final String QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED = "nodomain.freeyourgadget.gadgetbridge.Q_NOTIFICATION_CONFIG_CHANGED";
public static final String QHYBRID_EVENT_BUTTON_PRESS = "nodomain.freeyourgadget.gadgetbridge.Q_BUTTON_PRESSED";
@ -93,9 +95,20 @@ public class QHybridSupport extends QHybridBaseSupport {
commandFilter.addAction(QHYBRID_COMMAND_NOTIFICATION);
commandFilter.addAction(QHYBRID_COMMAND_UPDATE_SETTINGS);
commandFilter.addAction(QHYBRID_COMMAND_OVERWRITE_BUTTONS);
commandFilter.addAction(QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED);
LocalBroadcastManager.getInstance(getContext()).registerReceiver(commandReceiver, commandFilter);
try {
helper = new PackageConfigHelper(GBApplication.getContext());
} catch (GBException e) {
e.printStackTrace();
GB.toast("erroe getting database", Toast.LENGTH_SHORT, GB.ERROR, e);
try {
throw e;
} catch (GBException ex) {
ex.printStackTrace();
}
}
IntentFilter globalFilter = new IntentFilter();
globalFilter.addAction(QHYBRID_ACTION_SET_ACTIVITY_HAND);
@ -130,8 +143,6 @@ public class QHybridSupport extends QHybridBaseSupport {
loadTimeOffset();
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
return builder;
}
@ -148,7 +159,13 @@ public class QHybridSupport extends QHybridBaseSupport {
//new Exception().printStackTrace();
String packageName = notificationSpec.sourceName;
NotificationConfiguration config = helper.getSetting(packageName);
NotificationConfiguration config = null;
try {
config = helper.getNotificationConfiguration(packageName);
} catch (GBException e) {
e.printStackTrace();
GB.toast("error getting notification configuration", Toast.LENGTH_SHORT, GB.ERROR, e);
}
if (config == null) return;
Log.d("Service", "handling notification");
@ -160,9 +177,9 @@ public class QHybridSupport extends QHybridBaseSupport {
boolean enforceActivityHandNotification = config.getHour() == -1 && config.getMin() == -1;
// showNotificationsByAllActive(enforceActivityHandNotification);
playNotification(config);
showNotificationsByAllActive(enforceActivityHandNotification);
}
@Override
@ -173,7 +190,7 @@ public class QHybridSupport extends QHybridBaseSupport {
}
private void showNotificationsByAllActive(boolean enforceByNotification) {
if (!this.useActivityHand) ;
if (!this.useActivityHand);
double progress = calculateNotificationProgress();
showNotificationCountOnActivityHand(progress);
@ -190,9 +207,14 @@ public class QHybridSupport extends QHybridBaseSupport {
public double calculateNotificationProgress() {
HashMap<NotificationConfiguration, Boolean> configs = new HashMap<>(0);
for (NotificationConfiguration config : helper.getSettings()) {
try {
for (NotificationConfiguration config : helper.getNotificationConfigurations()) {
configs.put(config, false);
}
} catch (GBException e) {
e.printStackTrace();
GB.toast("error getting notification configs", Toast.LENGTH_SHORT, GB.ERROR, e);
}
double notificationProgress = 0;
@ -353,8 +375,8 @@ public class QHybridSupport extends QHybridBaseSupport {
switch (intent.getAction()) {
case QHYBRID_ACTION_SET_ACTIVITY_HAND: {
try {
Object extra = intent.getExtras().get("EXTRA_PROGRESS");
float progress = (float) extra;
String extra = String.valueOf(intent.getExtras().get("EXTRA_PROGRESS"));
float progress = Float.parseFloat(extra);
watchAdapter.setActivityHand(progress);
watchAdapter.playNotification(new NotificationConfiguration(
@ -437,6 +459,10 @@ public class QHybridSupport extends QHybridBaseSupport {
watchAdapter.overwriteButtons();
break;
}
case QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED: {
watchAdapter.syncNotificationSettings();
break;
}
}
}
};

View File

@ -19,7 +19,7 @@ public abstract class WatchAdapter {
return this.deviceSupport;
}
protected Context getContext(){
public Context getContext(){
return getDeviceSupport().getContext();
}
@ -37,6 +37,7 @@ public abstract class WatchAdapter {
public abstract void releaseHandsControl();
public abstract void setStepGoal(int stepGoal);
public abstract void setVibrationStrength(short strength);
public abstract void syncNotificationSettings();
public abstract void onTestNewFunction();
public abstract boolean supportsExtendedVibration();

View File

@ -5,13 +5,17 @@ import android.bluetooth.BluetoothGattCharacteristic;
import android.util.Log;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.TimeZone;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationConfiguration;
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfigHelper;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.WatchAdapter;
@ -23,8 +27,10 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FilePutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.NotificationFilterPutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.PlayNotificationRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.PrepareFilesRequestOrWhatever;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.AnimationRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.MoveHandsRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.ReleaseHandsControlRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.RequestHandControlRequest;
public class FossilWatchAdapter extends WatchAdapter {
private Queue<Request> requestQueue = new ArrayDeque<>();
@ -41,8 +47,44 @@ public class FossilWatchAdapter extends WatchAdapter {
@Override
public void initialize() {
playPairingAnimation();
queueWrite(new PrepareFilesRequestOrWhatever());
// queueWrite(new PrepareFilesRequestOrWhatever());
queueWrite(new ConfigurationGetRequest(this));
/*queueWrite(new Request() {
@Override
public byte[] getStartSequence() {
return new byte[]{0x01, (byte)0xF1, 0x28};
}
});
queueWrite(new Request() {
@Override
public byte[] getStartSequence() {
return new byte[]{0x09, (byte) 0xFF, (byte) 0xFF};
}
@Override
public UUID getRequestUUID() {
return UUID.fromString("3dda0003-957f-7d4a-34a6-74696673696d");
}
});
queueWrite(new Request() {
@Override
public byte[] getStartSequence() {
return new byte[]{(byte) 0x02, (byte) 0x09 , (byte) 0x0C , (byte) 0x00 , (byte) 0x0C , (byte) 0x00 , (byte) 0x2D , (byte) 0x00 , (byte) 0x58 , (byte) 0x02};
}
});*/
/*queueWrite(new Request() {
@Override
public byte[] getStartSequence() {
return new byte[]{0x02, 0x17, 0x01};
}
});*/
syncNotificationSettings();
getDeviceSupport().getDevice().setState(GBDevice.State.INITIALIZED);
getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
}
@Override
@ -52,6 +94,10 @@ public class FossilWatchAdapter extends WatchAdapter {
@Override
public void playNotification(NotificationConfiguration config) {
if(config.getPackageName() == null){
log("package name in notification not set");
return;
}
queueWrite(new PlayNotificationRequest(config.getPackageName(), this));
}
@ -86,12 +132,13 @@ public class FossilWatchAdapter extends WatchAdapter {
@Override
public void setHands(short hour, short minute) {
queueWrite(new MoveHandsRequest(false, minute, hour, (short) -1));
}
@Override
public void vibrate(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.PlayNotificationRequest.VibrationType vibration) {
public void vibrate(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.PlayNotificationRequest.VibrationType vibration) {
// queueWrite(new nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.PlayNotificationRequest(vibration, -1, -1));
}
@Override
@ -99,14 +146,15 @@ public class FossilWatchAdapter extends WatchAdapter {
}
@Override
public void requestHandsControl() {
queueWrite(new RequestHandControlRequest());
}
@Override
public void releaseHandsControl() {
queueWrite(new ReleaseHandsControlRequest());
}
@Override
@ -126,19 +174,27 @@ public class FossilWatchAdapter extends WatchAdapter {
);
}
@Override
public void syncNotificationSettings() {
log("syncing notification settings...");
try {
PackageConfigHelper helper = new PackageConfigHelper(getContext());
ArrayList<NotificationConfiguration> configurations = helper.getNotificationConfigurations();
if(configurations.size() == 1) configurations.add(configurations.get(0));
queueWrite(new NotificationFilterPutRequest(configurations, this));
} catch (GBException e) {
e.printStackTrace();
}
}
@Override
public void onTestNewFunction() {
NotificationConfiguration c = new NotificationConfiguration(
(short) 0x77,
(short) 0x77,
(short) 0xFF,
nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.PlayNotificationRequest.VibrationType.WHATEVER
);
c.setPackageName("com.whatsapp");
queueWrite(new NotificationFilterPutRequest(
new NotificationConfiguration[]{c, c},
this
));
try {
queueWrite(new NotificationFilterPutRequest(new PackageConfigHelper(getContext()).getNotificationConfigurations() ,this));
} catch (GBException e) {
e.printStackTrace();
}
}
@Override
@ -179,12 +235,25 @@ public class FossilWatchAdapter extends WatchAdapter {
@Override
public void onFetchActivityData() {
queueWrite(new ConfigurationGetRequest(this));
NotificationConfiguration config = new NotificationConfiguration((short) 0, (short) 0, (short) 0, null);
config.setPackageName("org.telegram.messenger");
playNotification(config);
// queueWrite(new ConfigurationGetRequest(this));
}
@Override
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
switch (characteristic.getUuid().toString()) {
case "3dda0002-957f-7d4a-34a6-74696673696d": {
if(fileGetRequest == null && fileLookupRequest == null && filePutRequest == null){
try {
queueWrite(requestQueue.remove());
} catch (NoSuchElementException e) {
log("requestsQueue empty");
}
}
break;
}
case "3dda0004-957f-7d4a-34a6-74696673696d":
case "3dda0003-957f-7d4a-34a6-74696673696d": {
if (filePutRequest != null) {
@ -192,10 +261,12 @@ public class FossilWatchAdapter extends WatchAdapter {
filePutRequest.handleResponse(characteristic);
if (filePutRequest.isFinished()) {
log("filePutRequets finished");
filePutRequest = null;
try {
queueWrite(requestQueue.remove());
} catch (NoSuchElementException e) {
log("requestsQueue empty");
}
}
} else if (fileGetRequest != null) {
@ -209,10 +280,12 @@ public class FossilWatchAdapter extends WatchAdapter {
}
if (requestFinished) {
log("fileGetRequest finished");
fileGetRequest = null;
try {
queueWrite(requestQueue.remove());
} catch (NoSuchElementException e) {
log("requestsQueue empty");
}
}
} else if (fileLookupRequest != null) {
@ -226,29 +299,48 @@ public class FossilWatchAdapter extends WatchAdapter {
}
if (requestFinished) {
log("fileLookupRequest finished");
fileLookupRequest = null;
try {
queueWrite(requestQueue.remove());
} catch (NoSuchElementException e) {
log("requestsQueue empty");
}
}
} else {
try {
queueWrite(requestQueue.remove());
} catch (NoSuchElementException e) {
log("requestsQueue empty");
}
}
}
}
return true;
}
private void log(String message){
Log.d("FossilWatchAdapter", message);
}
public void queueWrite(Request request) {
if(request.isBasicRequest()){
try {
queueWrite(requestQueue.remove());
}catch (NoSuchElementException e){}
}else {
if (filePutRequest != null || fileGetRequest != null || fileLookupRequest != null) {
Log.d("FossilWatchAdapter", "queing request");
Log.d("FossilWatchAdapter", "queing request: " + request.getName());
requestQueue.add(request);
return;
}
log("executing request directly: " + request.getName());
if (request instanceof FilePutRequest) filePutRequest = (FilePutRequest) request;
else if (request instanceof FileGetRequest) fileGetRequest = (FileGetRequest) request;
else if (request instanceof FileLookupRequest)
fileLookupRequest = (FileLookupRequest) request;
}
new TransactionBuilder(request.getClass().getSimpleName()).write(getDeviceSupport().getCharacteristic(request.getRequestUUID()), request.getRequestData()).queue(getDeviceSupport().getQueue());
}

View File

@ -89,6 +89,9 @@ public class MisfitWatchAdapter extends WatchAdapter {
requestQueue.add(new SetCurrentStepCountRequest((int) (999999 * getDeviceSupport().calculateNotificationProgress())));
queueWrite(new GetCurrentStepCountRequest());
getDeviceSupport().getDevice().setState(GBDevice.State.INITIALIZED);
getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
}
@ -384,6 +387,11 @@ public class MisfitWatchAdapter extends WatchAdapter {
queueWrite(new SetVibrationStrengthRequest(strength));
}
@Override
public void syncNotificationSettings() {
}
@Override
public void onTestNewFunction() {

View File

@ -49,6 +49,10 @@ public abstract class Request {
Log.d(getName(), message);
}
public boolean isBasicRequest(){
return this.getRequestUUID().toString().equals("3dda0002-957f-7d4a-34a6-74696673696d");
}
public boolean expectsResponse(){
return this.data[0] == 1;
}

View File

@ -30,5 +30,7 @@ public class ConfigurationGetRequest extends FileLookupAndGetRequest {
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_STEP_COUNT, String.valueOf(((ConfigurationPutRequest.CurrentStepCountConfigItem) item).getValue())));
}
}
device.sendDeviceUpdateIntent(getAdapter().getContext());
}
}

View File

@ -107,7 +107,7 @@ public class ConfigurationPutRequest extends FilePutRequest {
@Override
public short getId() {
return 0;
return this.configId;
}
@Override

View File

@ -22,7 +22,7 @@ public class FileLookupRequest extends Request {
private byte[] fileData;
private boolean finished = false;
protected boolean finished = false;
public FileLookupRequest(byte fileType, FossilWatchAdapter adapter) {
this.fileType = fileType;

View File

@ -1,6 +1,7 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil;
import android.bluetooth.BluetoothGattCharacteristic;
import android.widget.Toast;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@ -12,6 +13,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.CRC32C;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public abstract class FilePutRequest extends Request {
public enum UploadState{INITIALIZED, UPLOADING, CLOSING, UPLOADED, ERROR}
@ -165,6 +167,24 @@ public abstract class FilePutRequest extends Request {
break;
}
case 9: {
GB.toast("timeout writing file", Toast.LENGTH_SHORT, GB.ERROR);
ByteBuffer buffer2 = ByteBuffer.allocate(3);
buffer2.order(ByteOrder.LITTLE_ENDIAN);
buffer2.put((byte) 4);
buffer2.putShort(this.handle);
new TransactionBuilder("file close")
.write(
adapter.getDeviceSupport().getCharacteristic(UUID.fromString("3dda0003-957f-7d4a-34a6-74696673696d")),
buffer2.array()
)
.queue(adapter.getDeviceSupport().getQueue());
this.state = UploadState.CLOSING;
break;
}
}
}
}

View File

@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fo
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.zip.CRC32;
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationConfiguration;
@ -12,6 +13,11 @@ public class NotificationFilterPutRequest extends FilePutRequest {
super((short) 0x0C00, createFile(configs), adapter);
}
public NotificationFilterPutRequest(ArrayList<NotificationConfiguration> configs, FossilWatchAdapter adapter) {
super((short) 0x0C00, createFile(configs.toArray(new NotificationConfiguration[0])), adapter);
}
private static byte[] createFile(NotificationConfiguration[] configs){
ByteBuffer buffer = ByteBuffer.allocate(configs.length * 27);
buffer.order(ByteOrder.LITTLE_ENDIAN);
@ -39,7 +45,7 @@ public class NotificationFilterPutRequest extends FilePutRequest {
buffer.putShort(config.getHour())
.putShort(config.getMin())
.putShort(config.getSubEye())
.putShort((short) 1000);
.putShort((short) 5000);
buffer.put(PacketID.VIBRATION.id);
buffer.put((byte) 1);

View File

@ -17,7 +17,7 @@ public class PlayNotificationRequest extends FilePutRequest {
private static byte[] createFile(String packageName){
CRC32 crc = new CRC32();
crc.update(packageName.getBytes());
return createFile("", "", "", (int)crc.getValue());
return createFile(packageName, packageName, packageName, (int)crc.getValue());
}
private static byte[] createFile(String title, String sender, String message, int packageCrc) {

View File

@ -8,7 +8,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Req
public class PlayNotificationRequest extends Request {
public enum VibrationType{
WHATEVER(4),
SINGLE_SHORT(3),
DOUBLE_SHORT(2),
TRIPLE_SHORT(1),