accept local NS data broadcast even when ns_upload_only is selected

This commit is contained in:
Milos Kozak 2018-01-04 09:45:17 +01:00
parent de1475dbba
commit 4643cdc3b9
3 changed files with 10 additions and 4 deletions

View file

@ -96,7 +96,12 @@ public class DataService extends IntentService {
boolean isNSProfile = ConfigBuilderPlugin.getActiveProfileInterface().getClass().equals(NSProfilePlugin.class); boolean isNSProfile = ConfigBuilderPlugin.getActiveProfileInterface().getClass().equals(NSProfilePlugin.class);
boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false); boolean acceptNSData = !SP.getBoolean(R.string.key_ns_upload_only, false);
Bundle bundles = intent.getExtras();
if (bundles != null && bundles.containsKey("islocal")) {
acceptNSData = acceptNSData || bundles.getBoolean("islocal");
}
if (intent != null) { if (intent != null) {
final String action = intent.getAction(); final String action = intent.getAction();
@ -125,7 +130,7 @@ public class DataService extends IntentService {
} else if (isNSProfile && Intents.ACTION_NEW_PROFILE.equals(action) || Intents.ACTION_NEW_DEVICESTATUS.equals(action)) { } else if (isNSProfile && Intents.ACTION_NEW_PROFILE.equals(action) || Intents.ACTION_NEW_DEVICESTATUS.equals(action)) {
// always handle Profile if NSProfile is enabled without looking at nsUploadOnly // always handle Profile if NSProfile is enabled without looking at nsUploadOnly
handleNewDataFromNSClient(intent); handleNewDataFromNSClient(intent);
} else if (!nsUploadOnly && } else if (acceptNSData &&
(Intents.ACTION_NEW_TREATMENT.equals(action) || (Intents.ACTION_NEW_TREATMENT.equals(action) ||
Intents.ACTION_CHANGED_TREATMENT.equals(action) || Intents.ACTION_CHANGED_TREATMENT.equals(action) ||
Intents.ACTION_REMOVED_TREATMENT.equals(action) || Intents.ACTION_REMOVED_TREATMENT.equals(action) ||

View file

@ -24,11 +24,12 @@ import info.nightscout.utils.SP;
public class BroadcastTreatment { public class BroadcastTreatment {
private static Logger log = LoggerFactory.getLogger(BroadcastTreatment.class); private static Logger log = LoggerFactory.getLogger(BroadcastTreatment.class);
public static void handleNewTreatment(JSONObject treatment, boolean isDelta) { public static void handleNewTreatment(JSONObject treatment, boolean isDelta, boolean isLocalBypass) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.toString()); bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
bundle.putBoolean("islocal", isLocalBypass);
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT); Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

View file

@ -110,7 +110,7 @@ public class DBAccessReceiver extends BroadcastReceiver {
JSONObject data = new JSONObject(request.data); JSONObject data = new JSONObject(request.data);
data.put("mills", DateUtil.fromISODateString(data.getString("created_at")).getTime()); data.put("mills", DateUtil.fromISODateString(data.getString("created_at")).getTime());
data.put("_id", data.get("NSCLIENT_ID")); // this is only fake id data.put("_id", data.get("NSCLIENT_ID")); // this is only fake id
BroadcastTreatment.handleNewTreatment(data, false); BroadcastTreatment.handleNewTreatment(data, false, true);
} catch (Exception e) { } catch (Exception e) {
log.error("Unhadled exception", e); log.error("Unhadled exception", e);
} }