Skip to content

Commit

Permalink
Merge pull request #145 from senseobservationsystems/hotfix/implicit_…
Browse files Browse the repository at this point in the history
…intents_lollipop_setpackage

Hotfix/implicit intents lollipop setpackage
  • Loading branch information
Ted Schmidt committed Mar 10, 2015
2 parents 73f0dc4 + a1737a7 commit ade9723
Show file tree
Hide file tree
Showing 42 changed files with 94 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public boolean addDataPoint(String sensorName, String displayName, String descri
intent.putExtra(DataPoint.VALUE, (String) value);
}
intent.putExtra(DataPoint.TIMESTAMP, timestamp);
intent.setPackage(mContext.getPackageName());
ComponentName serviceName = mContext.startService(intent);

if (null != serviceName) {
Expand Down Expand Up @@ -255,6 +256,7 @@ public void close() {
public boolean flushData() throws IllegalStateException {
checkSenseService();
Intent flush = new Intent(mContext.getString(R.string.action_sense_send_data));
flush.setPackage(mContext.getPackageName());
ComponentName started = mContext.startService(flush);
return null != started;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Sense should be alive: poke it");
final Intent serviceIntent = new Intent(
context.getString(R.string.action_sense_service));
serviceIntent.setPackage(context.getPackageName());
if (null == context.startService(serviceIntent)) {
Log.w(TAG, "Could not start Sense service!");
}
Expand Down
1 change: 1 addition & 0 deletions sense-android-library/src/nl/sense_os/service/BootRx.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void onReceive(Context context, Intent intent) {
if (true == autostart) {
Log.i(TAG, "Autostart Sense Platform service");
Intent startService = new Intent(context.getString(R.string.action_sense_service));
startService.setPackage(context.getPackageName());
ComponentName service = context.startService(startService);
if (null == service) {
Log.w(TAG, "Failed to start Sense Platform service");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void stopTransmissions() {
public void transmissionService() {
Log.v(TAG, "Start transmission");
Intent task = new Intent(mContext.getString(R.string.action_sense_send_data));
task.setPackage(mContext.getPackageName());
mLastTxTime = SystemClock.elapsedRealtime();
ComponentName service = mContext.startService(task);
if (null == service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ public void onReceive(final Context context, Intent intent) {

// check that we are not logged in yet before logging in
if (false == state.isLoggedIn()) {
Log.i(TAG, "Regained connectivity! Try to log in");
context.startService(new Intent(context.getString(R.string.action_sense_service)));
Log.i(TAG, "Regained connectivity! Try to log in");
Intent i = new Intent(context.getString(R.string.action_sense_service));
i.setPackage(context.getPackageName());
context.startService(i);


} else {
// still connected, stay logged in
Expand Down
16 changes: 12 additions & 4 deletions sense-android-library/src/nl/sense_os/service/SenseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,12 @@ private void onLogOut() {
transmitter.stopTransmissions();

// completely stop the MsgHandler service
stopService(new Intent(getString(R.string.action_sense_new_data)));
stopService(new Intent(getString(R.string.action_sense_send_data)));
Intent newDataIntent = new Intent(getString(R.string.action_sense_new_data));
newDataIntent.setPackage(getPackageName());
stopService(newDataIntent);
Intent sendDataIntent = new Intent(getString(R.string.action_sense_send_data));
sendDataIntent.setPackage(getPackageName());
stopService(sendDataIntent);
}

void onSampleRateChange() {
Expand Down Expand Up @@ -482,7 +486,9 @@ void onSyncRateChange() {
}

// update any widgets
startService(new Intent(getString(R.string.action_widget_update)));
Intent i = new Intent(getString(R.string.action_widget_update));
i.setPackage(getPackageName());
startService(i);
}

/**
Expand Down Expand Up @@ -1189,7 +1195,9 @@ synchronized void toggleMain(boolean active) {
if (true == active) {
// properly start the service to start sensing
Log.i(TAG, "Start service");
startService(new Intent(getString(R.string.action_sense_service)));
Intent serviceIntent = new Intent(getString(R.string.action_sense_service));
serviceIntent.setPackage(getPackageName());
startService(serviceIntent);

} else {
Log.i(TAG, "Stop service");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,17 @@ public boolean isStarted() {
}

public void setAmbienceActive(boolean active) {
ambienceActive = active;
context.startService(new Intent(context.getString(R.string.action_widget_update)));
ambienceActive = active;
Intent i = new Intent(context.getString(R.string.action_widget_update));
i.setPackage(context.getPackageName());
context.startService(i);
}

public void setDevProxActive(boolean active) {
devProxActive = active;
context.startService(new Intent(context.getString(R.string.action_widget_update)));
Intent i = new Intent(context.getString(R.string.action_widget_update));
i.setPackage(context.getPackageName());
context.startService(i);
}

public void setExternalActive(boolean active) {
Expand All @@ -201,12 +205,16 @@ public void setForeground(boolean foreground) {
// : "Sense Platform Service is in background...");
updateNotification();
}
context.startService(new Intent(context.getString(R.string.action_widget_update)));
Intent i = new Intent(context.getString(R.string.action_widget_update));
i.setPackage(context.getPackageName());
context.startService(i);
}

public void setLocationActive(boolean active) {
locationActive = active;
context.startService(new Intent(context.getString(R.string.action_widget_update)));
Intent i = new Intent(context.getString(R.string.action_widget_update));
i.setPackage(context.getPackageName());
context.startService(i);
}

public void setLoggedIn(boolean loggedIn) {
Expand All @@ -216,17 +224,23 @@ public void setLoggedIn(boolean loggedIn) {
// : "Sense Platform Service logged out...");
updateNotification();
}
context.startService(new Intent(context.getString(R.string.action_widget_update)));
Intent i = new Intent(context.getString(R.string.action_widget_update));
i.setPackage(context.getPackageName());
context.startService(i);
}

public void setMotionActive(boolean active) {
motionActive = active;
context.startService(new Intent(context.getString(R.string.action_widget_update)));
Intent i = new Intent(context.getString(R.string.action_widget_update));
i.setPackage(context.getPackageName());
context.startService(i);
}

public void setPhoneStateActive(boolean active) {
phoneStateActive = active;
context.startService(new Intent(context.getString(R.string.action_widget_update)));
Intent i = new Intent(context.getString(R.string.action_widget_update));
i.setPackage(context.getPackageName());
context.startService(i);
}

public void setQuizActive(boolean active) {
Expand All @@ -241,7 +255,9 @@ public void setStarted(boolean started) {
// : "Sense Platform Service stopped...");
updateNotification();
}
context.startService(new Intent(context.getString(R.string.action_widget_update)));
Intent i = new Intent(context.getString(R.string.action_widget_update));
i.setPackage(context.getPackageName());
context.startService(i);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private void sendSensorValue(double value, long ms) {
sensorData.putExtra(DataPoint.VALUE, (float)value);
sensorData.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.FLOAT);
sensorData.putExtra(DataPoint.TIMESTAMP, ms);
sensorData.setPackage(context.getPackageName());
context.startService(sensorData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void lightValueCallback(float lightValue, int camera_id) {
i.putExtra(DataPoint.SENSOR_DESCRIPTION, sensorDescription);
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setPackage(context.getPackageName());
context.startService(i);
// Log.e(TAG, "Sent new camera licht values, camera: "+camera_id+" value: "+lightValue);
nextUpdate(camera_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void onSensorChanged(SensorEvent event) {
i.putExtra(DataPoint.SENSOR_NAME, sensorName);
i.putExtra(DataPoint.SENSOR_DESCRIPTION, sensor.getName());
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setPackage(mContext.getPackageName());
mContext.startService(i);

// done with sample
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void onSensorChanged(SensorEvent event) {
i.putExtra(DataPoint.SENSOR_DESCRIPTION, sensor.getName());
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
i.putExtra(DataPoint.TIMESTAMP, time);
i.setPackage(context.getPackageName());
this.context.startService(i);

stopSample();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ private void sendSensorValue(double value, long ms) {
sensorData.putExtra(DataPoint.VALUE, (float)value);
sensorData.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.FLOAT);
sensorData.putExtra(DataPoint.TIMESTAMP, ms);
sensorData.setPackage(context.getPackageName());
context.startService(sensorData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public void onSensorChanged(SensorEvent event) {
i.putExtra(DataPoint.DISPLAY_NAME, SENSOR_DISPLAY_NAME);
i.putExtra(DataPoint.SENSOR_DESCRIPTION, sensor.getName());
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setPackage(mContext.getPackageName());
mContext.startService(i);

// sample is successful: unregister the listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ public void run() {
BigDecimal.valueOf(dB).setScale(2, 0).floatValue());
sensorData.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.FLOAT);
sensorData.putExtra(DataPoint.TIMESTAMP, startTimestamp);
sensorData.setPackage(context.getPackageName());
context.startService(sensorData);
}

Expand Down Expand Up @@ -333,6 +334,7 @@ else if (spectrum[i] != Double.NaN && spectrum[i] != Double.NEGATIVE_INFINITY) /
sensorData.putExtra(DataPoint.VALUE, jsonSpectrum.toString());
sensorData.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
sensorData.putExtra(DataPoint.TIMESTAMP, startTimestamp);
sensorData.setPackage(context.getPackageName());
context.startService(sensorData);
}

Expand Down Expand Up @@ -518,6 +520,7 @@ public void sendAudio()
i.putExtra(DataPoint.VALUE, fileName);
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.FILE);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setPackage(context.getPackageName());
context.startService(i);

} catch (Exception e) {
Expand Down Expand Up @@ -599,6 +602,7 @@ public void sendData(JSONObject data, long startTimestamp)
sensorData.putExtra(DataPoint.VALUE, data.toString());
sensorData.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
sensorData.putExtra(DataPoint.TIMESTAMP, startTimestamp);
sensorData.setPackage(context.getPackageName());
context.startService(sensorData);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public void onSensorChanged(SensorEvent event) {
i.putExtra(DataPoint.SENSOR_NAME, sensorName);
i.putExtra(DataPoint.SENSOR_DESCRIPTION, sensor.getName());
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setPackage(mContext.getPackageName());
mContext.startService(i);

// sample is successful: unregister the listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void onSensorChanged(SensorEvent event) {
i.putExtra(DataPoint.SENSOR_NAME, sensorName);
i.putExtra(DataPoint.SENSOR_DESCRIPTION, sensor.getName());
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setPackage(mContext.getPackageName());
mContext.startService(i);

// done with sample
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ private boolean postData(String cookie, JSONObject transmission) throws JSONExce
final Intent serviceIntent = new Intent(ctxRef.get().getString(
R.string.action_sense_service));
serviceIntent.putExtra(SenseService.EXTRA_RELOGIN, true);
serviceIntent.setPackage(ctxRef.get().getPackageName());
ctxRef.get().startService(serviceIntent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void handleMessage(Message msg) {
final Intent serviceIntent = new Intent(ctxRef.get().getString(
R.string.action_sense_service));
serviceIntent.putExtra(SenseService.EXTRA_RELOGIN, true);
serviceIntent.setPackage(ctxRef.get().getPackageName());
ctxRef.get().startService(serviceIntent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,9 @@ else if (syncRate >= 900) // Eco-mode (30 min)
}

// apply change by starting the service
startService(new Intent(getString(R.string.action_sense_service)));
Intent i = new Intent(getString(R.string.action_sense_service));
i.setPackage(getPackageName());
startService(i);

} catch (JSONException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ private void onScanFinished() {
i.putExtra(DataPoint.VALUE, deviceJson.toString());
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setPackage(context.getPackageName());
BluetoothDeviceProximity.this.context.startService(i);
}

Expand All @@ -224,6 +225,7 @@ private void onScanFinished() {
i.putExtra(DataPoint.VALUE, nrBluetoothNeighbours);
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.INT);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setPackage(context.getPackageName());
BluetoothDeviceProximity.this.context.startService(i);
Log.v(TAG, "Found " + nrBluetoothNeighbours + " bluetooth neighbours");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ private void submit() {
dataPoint.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
dataPoint.putExtra(DataPoint.TIMESTAMP, sensorDataPoint.timeStamp);
dataPoint.putExtra(DataPoint.VALUE, value);
dataPoint.setPackage(getPackageName());
startService(dataPoint);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void onReceive(Context context, Intent intent) {
i.putExtra(DataPoint.VALUE, deviceJson.toString());
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setPackage(context.getPackageName());
WIFIDeviceProximity.this.context.startService(i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ private boolean SendDataPoint(String sensorName, String sensorDescription, Objec
Log.w(TAG, "Error sending data point: unexpected data type! '" + dataType + "'");
}
intent.putExtra(DataPoint.TIMESTAMP, SNTP.getInstance().getTime());

intent.setPackage(context.getPackageName());
boolean itemsent = (context.startService(intent) != null);
if (!itemsent)
Log.e(TAG, "Sending of DataPoint: " + sensorName + " " + value + " "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ public void sendIntent(){
i.putExtra(DataPoint.VALUE, getJSON().toString());
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
i.putExtra(DataPoint.TIMESTAMP, SNTP.getInstance().getTime());
i.setPackage(context.getPackageName());
context.startService(i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private void sendDemoDataPoint(String description, Object value,
Log.w(TAG, "Error sending data point: unexpected data type! '" + dataType + "'");
}
intent.putExtra(DataPoint.TIMESTAMP, SNTP.getInstance().getTime());
intent.setPackage(context.getPackageName());
context.startService(intent);
}

Expand Down Expand Up @@ -265,6 +266,7 @@ public void sendIntent(){
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
//TODO: i.putExtra(DataPoint.DEVICE_UUID, )
i.setPackage(context.getPackageName());
context.startService(i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ private void sendDataPoint(String sensorName, String description, Object value,
Log.w(TAG, "Error sending data point: unexpected data type! '" + dataType + "'");
}
intent.putExtra(DataPoint.TIMESTAMP, SNTP.getInstance().getTime());
intent.setPackage(context.getPackageName());
context.startService(intent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ private void sendDataPoint(String sensorName, String description, Object value,
Log.w(TAG, "Error sending data point: unexpected data type! '" + dataType + "'");
}
intent.putExtra(DataPoint.TIMESTAMP, SNTP.getInstance().getTime());
intent.setPackage(context.getPackageName());
context.startService(intent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public void onLocationChanged(Location fix) {
i.putExtra(DataPoint.VALUE, json.toString());
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
i.putExtra(DataPoint.TIMESTAMP, timestamp);
i.setPackage(context.getPackageName());
context.startService(i);

distanceEstimator.addPoint(fix);
Expand Down Expand Up @@ -169,6 +170,7 @@ public void onReceive(Context context, Intent intent) {
i.putExtra(DataPoint.VALUE, (float) distance);
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.FLOAT);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setPackage(context.getPackageName());
context.startService(i);

// start counting again, from the last location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ protected void sendTimeZone()
i.putExtra(DataPoint.SENSOR_DESCRIPTION, dataPoint.sensorDescription);
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setPackage(context.getPackageName());
this.context.startService(i);
}
catch(Exception e)
Expand Down
Loading

0 comments on commit ade9723

Please sign in to comment.