mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-01 05:25:50 +01:00
removed DeviceSupportService hack
This commit is contained in:
parent
e1d2ba32da
commit
0b572505b3
@ -48,15 +48,18 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
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.model.ItemWithDetails;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
|
||||
|
||||
public class ConfigActivity extends AbstractGBActivity implements ServiceConnection {
|
||||
public class ConfigActivity extends AbstractGBActivity {
|
||||
PackageAdapter adapter;
|
||||
ArrayList<PackageConfig> list;
|
||||
PackageConfigHelper helper;
|
||||
@ -73,8 +76,8 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_qhybrid_settings);
|
||||
|
||||
findViewById(R.id.buttonOverwriteButtons).setOnClickListener(new View.OnClickListener() {
|
||||
@ -129,8 +132,6 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
|
||||
});
|
||||
updateTimeOffset();
|
||||
|
||||
bindService(new Intent(getApplicationContext(), DeviceCommunicationService.class), this, 0);
|
||||
|
||||
setTitle(R.string.preferences_qhybrid_settings);
|
||||
|
||||
ListView appList = findViewById(R.id.qhybrid_appList);
|
||||
@ -222,6 +223,13 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
|
||||
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent);
|
||||
}
|
||||
});
|
||||
|
||||
device = GBApplication.app().getDeviceManager().getSelectedDevice();
|
||||
if(device == null || device.getType() != DeviceType.FOSSILQHYBRID){
|
||||
setSettingsError("Watch not connected");
|
||||
}else{
|
||||
updateSettings();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTimeOffset() {
|
||||
@ -310,7 +318,6 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unbindService(this);
|
||||
helper.close();
|
||||
}
|
||||
|
||||
@ -336,29 +343,6 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||
Log.d("Config", "service connected");
|
||||
DeviceCommunicationService.CommunicationServiceBinder binder = (DeviceCommunicationService.CommunicationServiceBinder) iBinder;
|
||||
if (binder == null) {
|
||||
Log.d("Config", "Service not running");
|
||||
setSettingsError("Service not running");
|
||||
return;
|
||||
}
|
||||
DeviceSupport support = ((DeviceCommunicationService.CommunicationServiceBinder) iBinder).getDeviceSupport();
|
||||
if (!(support instanceof QHybridSupport)) {
|
||||
Log.d("Config", "Watch not connected");
|
||||
setSettingsError("Watch not connected");
|
||||
return;
|
||||
}
|
||||
this.device = support.getDevice();
|
||||
updateSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName componentName) {
|
||||
|
||||
}
|
||||
|
||||
private void setSettingsError(final String error) {
|
||||
runOnUiThread(new Runnable() {
|
||||
|
@ -32,7 +32,6 @@ import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.widget.Toast;
|
||||
@ -814,16 +813,9 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
}
|
||||
}
|
||||
|
||||
public class CommunicationServiceBinder extends Binder{
|
||||
public DeviceSupport getDeviceSupport(){
|
||||
if(mDeviceSupport == null) return null;
|
||||
return ((ServiceDeviceSupport)DeviceCommunicationService.this.mDeviceSupport).getDelegate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return new CommunicationServiceBinder();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,13 +32,16 @@ import java.util.UUID;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfig;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfigHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.ActivityPointGetRequest;
|
||||
@ -101,15 +104,10 @@ public class QHybridSupport extends QHybridBaseSupport {
|
||||
|
||||
private Request fileRequest = null;
|
||||
|
||||
private boolean dumpInited = false;
|
||||
|
||||
private long timeOffset;
|
||||
|
||||
private UploadFileRequest uploadFileRequest;
|
||||
|
||||
private PendingIntent dumpIntent;
|
||||
private PendingIntent stepIntent;
|
||||
|
||||
private Queue<Request> requestQueue = new ArrayDeque<>();
|
||||
|
||||
|
||||
@ -170,39 +168,11 @@ public class QHybridSupport extends QHybridBaseSupport {
|
||||
timeOffset = getContext().getSharedPreferences(getContext().getPackageName(), Context.MODE_PRIVATE).getInt("QHYBRID_TIME_OFFSET", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(commandReceiver);
|
||||
if (dumpInited) {
|
||||
getContext().unregisterReceiver(dumpReceiver);
|
||||
((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).cancel(dumpIntent);
|
||||
getContext().unregisterReceiver(stepReceiver);
|
||||
((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).cancel(stepIntent);
|
||||
dumpInited = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void queueWrite(Request request) {
|
||||
new TransactionBuilder(request.getClass().getSimpleName()).write(getCharacteristic(request.getRequestUUID()), request.getRequestData()).queue(getQueue());
|
||||
if (request instanceof FileRequest) this.fileRequest = request;
|
||||
}
|
||||
|
||||
private final BroadcastReceiver stepReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
queueWrite(new GetCurrentStepCountRequest());
|
||||
}
|
||||
};
|
||||
|
||||
private final BroadcastReceiver dumpReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d("Dump", "dumping...");
|
||||
downloadActivityFiles();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
|
||||
@ -225,16 +195,6 @@ public class QHybridSupport extends QHybridBaseSupport {
|
||||
.write(getCharacteristic(initialRequest.getRequestUUID()), initialRequest.getRequestData());
|
||||
|
||||
helper = new PackageConfigHelper(getContext());
|
||||
|
||||
// if (!dumpInited) {
|
||||
// getContext().registerReceiver(dumpReceiver, new IntentFilter("dumpReceiver2"));
|
||||
// getContext().registerReceiver(stepReceiver, new IntentFilter("stepDumpReceiver"));
|
||||
// dumpIntent = PendingIntent.getBroadcast(getContext(), 0, new Intent("dumpReceiver2"), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
// stepIntent = PendingIntent.getBroadcast(getContext(), 0, new Intent("stepDumpReceiver"), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
// ((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, AlarmManager.INTERVAL_HOUR, dumpIntent);
|
||||
// ((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, AlarmManager.INTERVAL_HOUR / 60, stepIntent);
|
||||
// dumpInited = true;
|
||||
// }
|
||||
getTimeOffset();
|
||||
|
||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
||||
@ -242,6 +202,16 @@ public class QHybridSupport extends QHybridBaseSupport {
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchRecordedData(int dataTypes) {
|
||||
if((dataTypes & RecordedDataTypes.TYPE_ACTIVITY) != 0){
|
||||
requestQueue.add(new BatteryLevelRequest());
|
||||
requestQueue.add(new GetCurrentStepCountRequest());
|
||||
requestQueue.add(new ListFilesRequest());
|
||||
queueWrite(new ActivityPointGetRequest());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotification(NotificationSpec notificationSpec) {
|
||||
Log.d("Service", "notif from " + notificationSpec.sourceAppId + " " + notificationSpec.sender + " " + notificationSpec.phoneNumber);
|
||||
@ -337,10 +307,6 @@ public class QHybridSupport extends QHybridBaseSupport {
|
||||
queueWrite(uploadFileRequest);
|
||||
}
|
||||
|
||||
private void downloadActivityFiles() {
|
||||
queueWrite(new ListFilesRequest());
|
||||
}
|
||||
|
||||
private void backupFile(DownloadFileRequest request) {
|
||||
try {
|
||||
File f = new File("/sdcard/qFiles/");
|
||||
@ -517,20 +483,18 @@ public class QHybridSupport extends QHybridBaseSupport {
|
||||
|
||||
if (request instanceof BatteryLevelRequest) {
|
||||
gbDevice.setBatteryLevel(((BatteryLevelRequest) request).level);
|
||||
|
||||
gbDevice.setBatteryThresholdPercent((short) 25);
|
||||
|
||||
GBDeviceEventBatteryInfo batteryInfo = new GBDeviceEventBatteryInfo();
|
||||
batteryInfo.level = gbDevice.getBatteryLevel();
|
||||
batteryInfo.state = BatteryState.BATTERY_NORMAL;
|
||||
handleGBDeviceEvent(batteryInfo);
|
||||
} else if (request instanceof GetStepGoalRequest) {
|
||||
gbDevice.addDeviceInfo(new GenericItem(ITEM_STEP_GOAL, String.valueOf(((GetStepGoalRequest) request).stepGoal)));
|
||||
} else if (request instanceof GetVibrationStrengthRequest) {
|
||||
int strength = ((GetVibrationStrengthRequest) request).strength;
|
||||
gbDevice.addDeviceInfo(new GenericItem(ITEM_VIBRATION_STRENGTH, String.valueOf(strength)));
|
||||
} else if (fileRequest instanceof ListFilesRequest) {
|
||||
ListFilesRequest r = (ListFilesRequest) fileRequest;
|
||||
//if(r.fileCount != -1){
|
||||
if (r.completed) {
|
||||
Log.d("Service", "FileCount: " + r.fileCount);
|
||||
this.fileRequest = null;
|
||||
}
|
||||
//}
|
||||
} else if (request instanceof GetCurrentStepCountRequest) {
|
||||
int steps = ((GetCurrentStepCountRequest) request).steps;
|
||||
logger.debug("get current steps: " + steps);
|
||||
@ -575,7 +539,7 @@ public class QHybridSupport extends QHybridBaseSupport {
|
||||
if (((ListFilesRequest) request).completed) {
|
||||
logger.debug("File count: " + ((ListFilesRequest) request).fileCount + " size: " + ((ListFilesRequest) request).size);
|
||||
if (((ListFilesRequest) request).fileCount == 0) return true;
|
||||
queueWrite(new DownloadFileRequest((short) (256 + ((ListFilesRequest) request).fileCount)));
|
||||
// queueWrite(new DownloadFileRequest((short) (256 + ((ListFilesRequest) request).fileCount)));
|
||||
}
|
||||
} else if (request instanceof DownloadFileRequest) {
|
||||
if (((FileRequest) request).completed) {
|
||||
|
Loading…
Reference in New Issue
Block a user