mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-05 01:37:03 +01:00
rename IDSenderLookup to LimitedQueue and store Object instead of String
This commit is contained in:
parent
803e58743a
commit
46bbab7df0
@ -29,7 +29,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.IDSenderLookup;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.LimitedQueue;
|
||||
|
||||
//import nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver;
|
||||
|
||||
@ -45,7 +45,7 @@ public class GBApplication extends Application {
|
||||
private static final Lock dbLock = new ReentrantLock();
|
||||
private static DeviceService deviceService;
|
||||
private static SharedPreferences sharedPrefs;
|
||||
private static IDSenderLookup mIDSenderLookup = new IDSenderLookup();
|
||||
private static LimitedQueue mIDSenderLookup = new LimitedQueue(16);
|
||||
|
||||
public static final String ACTION_QUIT
|
||||
= "nodomain.freeyourgadget.gadgetbridge.gbapplication.action.quit";
|
||||
@ -61,10 +61,7 @@ public class GBApplication extends Application {
|
||||
}
|
||||
};
|
||||
|
||||
//private BluetoothConnectReceiver systemBTReceiver = new BluetoothConnectReceiver();
|
||||
|
||||
private void quit() {
|
||||
//unregisterSystemBTReceiver();
|
||||
GB.removeAllNotifications(this);
|
||||
}
|
||||
|
||||
@ -103,25 +100,11 @@ public class GBApplication extends Application {
|
||||
filterLocal.addAction(ACTION_QUIT);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
||||
|
||||
//registerSystemBTReceiver();
|
||||
// for testing DB stuff
|
||||
// SQLiteDatabase db = mActivityDatabaseHandler.getWritableDatabase();
|
||||
// db.close();
|
||||
}
|
||||
|
||||
/*
|
||||
private void registerSystemBTReceiver() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("android.bluetooth.device.action.ACL_CONNECTED");
|
||||
filter.addAction("android.bluetooth.device.action.ACL_CONNECTED");
|
||||
registerReceiver(systemBTReceiver, filter);
|
||||
}
|
||||
|
||||
private void unregisterSystemBTReceiver() {
|
||||
unregisterReceiver(systemBTReceiver);
|
||||
}
|
||||
*/
|
||||
|
||||
private void setupExceptionHandler() {
|
||||
LoggingExceptionHandler handler = new LoggingExceptionHandler(Thread.getDefaultUncaughtExceptionHandler());
|
||||
Thread.setDefaultUncaughtExceptionHandler(handler);
|
||||
@ -259,7 +242,7 @@ public class GBApplication extends Application {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IDSenderLookup getIDSenderLookup() {
|
||||
public static LimitedQueue getIDSenderLookup() {
|
||||
return mIDSenderLookup;
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||
action = NotificationListener.ACTION_MUTE;
|
||||
break;
|
||||
case REPLY:
|
||||
String phoneNumber = GBApplication.getIDSenderLookup().lookup(deviceEvent.handle);
|
||||
String phoneNumber = (String) GBApplication.getIDSenderLookup().lookup(deviceEvent.handle);
|
||||
if (phoneNumber != null) {
|
||||
LOG.info("got notfication reply for " + phoneNumber + " : " + deviceEvent.reply);
|
||||
SmsManager.getDefault().sendTextMessage(phoneNumber, null, deviceEvent.reply, null, null);
|
||||
|
@ -39,7 +39,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.IDSenderLookup;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CALLSTATE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CONNECT;
|
||||
|
@ -1590,7 +1590,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
byte[] reply = new byte[length];
|
||||
buf.get(reply);
|
||||
// FIXME: this does not belong here, but we want at least check if there is no chance at all to send out the SMS later before we report success
|
||||
String phoneNumber = GBApplication.getIDSenderLookup().lookup(id);
|
||||
String phoneNumber = (String) GBApplication.getIDSenderLookup().lookup(id);
|
||||
if (phoneNumber != null) {
|
||||
devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY;
|
||||
devEvtNotificationControl.reply = new String(reply);
|
||||
|
@ -4,21 +4,25 @@ import android.util.Pair;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class IDSenderLookup {
|
||||
private static final int LIMIT = 16;
|
||||
public class LimitedQueue {
|
||||
private final int limit;
|
||||
private LinkedList<Pair> list = new LinkedList<>();
|
||||
|
||||
public void add(int id, String sender) {
|
||||
if (list.size() > LIMIT - 1) {
|
||||
public LimitedQueue(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public void add(int id, Object sender) {
|
||||
if (list.size() > limit - 1) {
|
||||
list.removeFirst();
|
||||
}
|
||||
list.add(new Pair<>(id, sender));
|
||||
}
|
||||
|
||||
public String lookup(int id) {
|
||||
public Object lookup(int id) {
|
||||
for (Pair entry : list) {
|
||||
if (id == (Integer) entry.first) {
|
||||
return (String) entry.second;
|
||||
return entry.second;
|
||||
}
|
||||
}
|
||||
return null;
|
Loading…
Reference in New Issue
Block a user