save. didn't find a way to hook set state yet

This commit is contained in:
vanous 2022-05-22 21:10:41 +02:00
parent cc28879ecc
commit 179b483dce
5 changed files with 128 additions and 0 deletions

View File

@ -420,6 +420,14 @@
android:name=".database.PeriodicExporter"
android:enabled="true"
android:exported="false" />
<receiver
android:name=".service.receivers.GBDeviceSystemEventReceiver"
android:exported="false">
<intent-filter>
<action android:name="nodomain.freeyourgadget.gadgetbridge.systemeventcontrol" />
</intent-filter>
</receiver>
<!--
forcing the DebugActivity to portrait mode avoids crashes with the progress
dialog when changing orientation

View File

@ -0,0 +1,29 @@
/* Copyright (C) 2015-2021 Andreas Shimokawa
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/>. */
package nodomain.freeyourgadget.gadgetbridge.deviceevents;
public class GBDeviceEventDeviceSystemEvent extends GBDeviceEvent {
public Event event = Event.UNKNOWN;
public enum Event {
UNKNOWN,
BATTERY_FULL,
CONNECTED,
DISCONNECTED
}
}

View File

@ -38,6 +38,7 @@ import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventDeviceSystemEvent;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;

View File

@ -58,6 +58,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventDeviceSystemEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventDisplayMessage;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFmFrequency;
@ -76,6 +77,7 @@ import nodomain.freeyourgadget.gadgetbridge.externalevents.NotificationListener;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBCallControlReceiver;
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBDeviceSystemEventReceiver;
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBMusicControlReceiver;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -183,6 +185,8 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
handleGBDeviceEvent((GBDeviceEventUpdateDeviceState) deviceEvent);
} else if (deviceEvent instanceof GBDeviceEventFmFrequency) {
handleGBDeviceEvent((GBDeviceEventFmFrequency) deviceEvent);
} else if (deviceEvent instanceof GBDeviceEventDeviceSystemEvent) {
handleGBDeviceEvent((GBDeviceEventDeviceSystemEvent) deviceEvent);
}
}
@ -241,6 +245,22 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
}
}
private void handleGBDeviceEvent(GBDeviceEventDeviceSystemEvent systemEvent) {
Context context = getContext();
LOG.info("Got event for DEVICE SYSTEM EVENT");
Intent systemEventIntent = new Intent(GBDeviceSystemEventReceiver.ACTION_SYSTEM_EVENT_CONTROL);
systemEventIntent.putExtra("event", systemEvent.event.ordinal());
systemEventIntent.putExtra(GBDevice.EXTRA_DEVICE, gbDevice);
systemEventIntent.setPackage(context.getPackageName());
context.sendBroadcast(systemEventIntent);
// LOG.debug("petr setting state");
// if (updateDeviceState.state == GBDevice.State.INITIALIZED ){
// GBDeviceEventDeviceSystemEvent connectEvent = null;
// connectEvent.event=GBDeviceEventDeviceSystemEvent.Event.CONNECTED;
// evaluateGBDeviceEvent(connectEvent);
// }
}
private void handleGBDeviceEvent(GBDeviceEventMusicControl musicEvent) {
Context context = getContext();

View File

@ -0,0 +1,70 @@
/* Copyright (C) 2015-2021 Andreas Shimokawa, Carsten Pfeiffer, Daniele
Gobbetti, Gabe Schrecker, Petr Vaněk
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/>. */
package nodomain.freeyourgadget.gadgetbridge.service.receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventDeviceSystemEvent;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class GBDeviceSystemEventReceiver extends BroadcastReceiver {
private static final Logger LOG = LoggerFactory.getLogger(GBDeviceSystemEventReceiver.class);
public static final String ACTION_SYSTEM_EVENT_CONTROL = "nodomain.freeyourgadget.gadgetbridge.systemeventcontrol";
@Override
public void onReceive(Context context, Intent intent) {
GBDeviceEventDeviceSystemEvent.Event systemEvent = GBDeviceEventDeviceSystemEvent.Event.values()[intent.getIntExtra("event", 0)];
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
switch (systemEvent) {
case CONNECTED:
GB.createNotification("oh mine... connected!", context);
LOG.debug("petr connected");
try {
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
} catch (SecurityException e) {
LOG.error("SecurityException when trying to set ringer (no permission granted :/ ?), not setting it then.");
}
break;
case DISCONNECTED:
LOG.debug("petr disconnected");
GB.createNotification("oh mine... disconnected!", context);
try {
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
} catch (SecurityException e) {
LOG.error("SecurityException when trying to set ringer (no permission granted :/ ?), not setting it then.");
}
break;
case BATTERY_FULL:
GB.createNotification("battery full!", context);
break;
default:
return;
}
}
}