Merge pull request #299 from MilosKozak/dev-nsclient-quickfix

NSClient quickfix
This commit is contained in:
Milos Kozak 2017-07-19 18:53:38 +02:00 committed by GitHub
commit 3475b64e1b
15 changed files with 78 additions and 63 deletions

View file

@ -12,6 +12,7 @@ import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm;
import info.nightscout.utils.SP;
/**
* Created by mike on 11.06.2017.
@ -21,6 +22,7 @@ public class BroadcastAckAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastAckAlarm.class);
public static void handleClearAlarm(NSAlarm originalAlarm, Context context, long silenceTimeInMsec) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putInt("level", originalAlarm.getLevel());
bundle.putString("group", originalAlarm.getGroup());
@ -29,9 +31,6 @@ public class BroadcastAckAlarm {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("ACKALARM " + x.size() + " receivers");
}
}

View file

@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP;
/**
* Created by mike on 26.06.2016.
@ -20,14 +21,14 @@ public class BroadcastAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastAlarm.class);
public static void handleAlarm(JSONObject alarm, Context context) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("data", alarm.toString());
Intent intent = new Intent(Intents.ACTION_ALARM);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("ALARM " + x.size() + " receivers");
}
}

View file

@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP;
/**
* Created by mike on 26.06.2016.
@ -21,14 +22,14 @@ public class BroadcastAnnouncement {
private static Logger log = LoggerFactory.getLogger(BroadcastAnnouncement.class);
public static void handleAnnouncement(JSONObject announcement, Context context) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("data", announcement.toString());
Intent intent = new Intent(Intents.ACTION_ANNOUNCEMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("ANNOUNCEMENT " + x.size() + " receivers");
}
}

View file

@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP;
/**
* Created by mike on 26.06.2016.
@ -20,6 +21,9 @@ public class BroadcastCals {
private static Logger log = LoggerFactory.getLogger(BroadcastCals.class);
public static void handleNewCal(JSONArray cals, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("cals", cals.toString());
bundle.putBoolean("delta", isDelta);
@ -27,8 +31,5 @@ public class BroadcastCals {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("CAL " + x.size() + " receivers");
}
}

View file

@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP;
/**
* Created by mike on 26.06.2016.
@ -20,14 +21,14 @@ public class BroadcastClearAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastClearAlarm.class);
public static void handleClearAlarm(JSONObject clearalarm, Context context) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("data", clearalarm.toString());
Intent intent = new Intent(Intents.ACTION_CLEAR_ALARM);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("CLEARALARM " + x.size() + " receivers");
}
}

View file

@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP;
public class BroadcastDeviceStatus {
@ -26,11 +27,13 @@ public class BroadcastDeviceStatus {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("DEVICESTATUS " + x.size() + " receivers");
}
public static void handleNewDeviceStatus(JSONArray statuses, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
List<JSONArray> splitted = BroadcastTreatment.splitArray(statuses);
for (JSONArray part: splitted) {
Bundle bundle = new Bundle();
@ -40,9 +43,6 @@ public class BroadcastDeviceStatus {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("DEVICESTATUS " + part.length() + " records " + x.size() + " receivers");
}
}
}

View file

@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP;
/**
* Created by mike on 26.06.2016.
@ -20,6 +21,9 @@ public class BroadcastMbgs {
private static Logger log = LoggerFactory.getLogger(BroadcastMbgs.class);
public static void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("mbgs", mbgs.toString());
bundle.putBoolean("delta", isDelta);
@ -27,8 +31,5 @@ public class BroadcastMbgs {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("MBG " + x.size() + " receivers");
}
}

View file

@ -12,6 +12,7 @@ import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.utils.SP;
/**
@ -21,6 +22,9 @@ public class BroadcastProfile {
private static Logger log = LoggerFactory.getLogger(BroadcastProfile.class);
public static void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("profile", profile.getData().toString());
bundle.putBoolean("delta", isDelta);
@ -28,9 +32,6 @@ public class BroadcastProfile {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("PROFILE " + x.size() + " receivers");
}
}

View file

@ -6,12 +6,16 @@ import android.os.Bundle;
import android.os.PowerManager;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP;
/**
* Created by mike on 28.02.2016.
*/
public class BroadcastQueueStatus {
public static void handleNewStatus(int size, Context context) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"sendQueue");

View file

@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP;
/**
* Created by mike on 22.02.2016.
@ -21,6 +22,9 @@ public class BroadcastSgvs {
private static Logger log = LoggerFactory.getLogger(BroadcastSgvs.class);
public static void handleNewSgv(JSONObject sgv, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("sgv", sgv.toString());
bundle.putBoolean("delta", isDelta);
@ -28,9 +32,6 @@ public class BroadcastSgvs {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("SGV " + x.size() + " receivers");
}
public static void handleNewSgv(JSONArray sgvs, Context context, boolean isDelta) {
@ -41,9 +42,6 @@ public class BroadcastSgvs {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("SGV " + x.size() + " receivers");
}
}

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
import info.nightscout.utils.SP;
/**
* Created by mike on 24.02.2016.
@ -23,6 +24,9 @@ public class BroadcastStatus {
private static Logger log = LoggerFactory.getLogger(BroadcastStatus.class);
public static void handleNewStatus(NSSettingsStatus status, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
try {
bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName);
@ -38,8 +42,5 @@ public class BroadcastStatus {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("STATUS: " + x.size() + " receivers");
}
}

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.TransactionTooLargeException;
import org.json.JSONArray;
import org.json.JSONException;
@ -16,6 +17,7 @@ import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
import info.nightscout.utils.SP;
/**
* Created by mike on 20.02.2016.
@ -24,6 +26,9 @@ public class BroadcastTreatment {
private static Logger log = LoggerFactory.getLogger(BroadcastTreatment.class);
public static void handleNewTreatment(NSTreatment treatment, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.getData().toString());
bundle.putBoolean("delta", isDelta);
@ -31,12 +36,12 @@ public class BroadcastTreatment {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("TREAT_ADD " + treatment.getEventType() + " " + x.size() + " receivers");
}
public static void handleNewTreatment(JSONArray treatments, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
List<JSONArray> splitted = splitArray(treatments);
for (JSONArray part: splitted) {
Bundle bundle = new Bundle();
@ -46,13 +51,13 @@ public class BroadcastTreatment {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("TREAT_ADD " + part.length() + " " + x.size() + " receivers");
}
}
public void handleChangedTreatment(JSONObject treatment, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta);
@ -60,15 +65,12 @@ public class BroadcastTreatment {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
try {
log.debug("TREAT_CHANGE " + treatment.getString("_id") + " " + x.size() + " receivers");
} catch (JSONException e) {
}
}
public static void handleChangedTreatment(JSONArray treatments, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
List<JSONArray> splitted = splitArray(treatments);
for (JSONArray part: splitted) {
Bundle bundle = new Bundle();
@ -78,13 +80,13 @@ public class BroadcastTreatment {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("TREAT_CHANGE " + part.length() + " " + x.size() + " receivers");
}
}
public static void handleRemovedTreatment(JSONObject treatment, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta);
@ -92,15 +94,12 @@ public class BroadcastTreatment {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
try {
log.debug("TREAT_REMOVE " + treatment.getString("_id") + " " + x.size() + " receivers");
} catch (JSONException e) {
}
}
public static void handleRemovedTreatment(JSONArray treatments, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("treatments", treatments.toString());
bundle.putBoolean("delta", isDelta);
@ -108,9 +107,6 @@ public class BroadcastTreatment {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("TREAT_REMOVE " + treatments.length() + " treatments " + x.size() + " receivers");
}

View file

@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP;
/**
* Created by mike on 26.06.2016.
@ -20,14 +21,14 @@ public class BroadcastUrgentAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastUrgentAlarm.class);
public static void handleUrgentAlarm(JSONObject urgentalarm, Context context) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle();
bundle.putString("data", urgentalarm.toString());
Intent intent = new Intent(Intents.ACTION_URGENT_ALARM);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("URGENTALARM " + x.size() + " receivers");
}
}

View file

@ -580,6 +580,7 @@
<string name="superbolus">Superbolus</string>
<string name="ns_logappstartedevent">Log app start to NS</string>
<string name="key_ns_logappstartedevent" translatable="false">ns_logappstartedevent</string>
<string name="key_ns_localbroadcasts" translatable="false">nsclient_localbroadcasts</string>
<string name="restartingapp">Exiting application to apply settings.</string>
<string name="danarv2pump">DanaRv2</string>
<string name="configbuilder_insulin">Insulin</string>
@ -685,4 +686,6 @@
<string name="cpp_valuesnotstored">Values not stored!</string>
<string name="wear_overviewnotifications">Overview Notifications</string>
<string name="wear_overviewnotifications_summary">Pass the Overview Notifications through as wear confirmation messages.</string>
<string name="ns_localbroadcasts">Enable loacal broadcasts to other apps (like xDrip).</string>
<string name="ns_localbroadcasts_title">Enable local Broadcasts.</string>
</resources>

View file

@ -27,6 +27,13 @@
android:key="@string/key_ns_logappstartedevent"
android:title="@string/ns_logappstartedevent" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/key_ns_localbroadcasts"
android:title="@string/ns_localbroadcasts_title"
android:summary="@string/ns_localbroadcasts"/>
<PreferenceScreen android:title="@string/ns_alarmoptions">
<SwitchPreference