Skip to content

Commit

Permalink
Fixed the implicit intent warning/error when starting a service by re…
Browse files Browse the repository at this point in the history
…stricting the scope to the package.
  • Loading branch information
ted committed Mar 6, 2015
1 parent 704a66e commit a1737a7
Show file tree
Hide file tree
Showing 41 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public boolean addDataPoint(String sensorName, String displayName, String descri
intent.putExtra(DataPoint.VALUE, (String) value);
}
intent.putExtra(DataPoint.TIMESTAMP, timestamp);
intent.setClass(mContext, nl.sense_os.service.MsgHandler.class);
intent.setPackage(mContext.getPackageName());
ComponentName serviceName = mContext.startService(intent);

if (null != serviceName) {
Expand Down Expand Up @@ -256,7 +256,7 @@ public void close() {
public boolean flushData() throws IllegalStateException {
checkSenseService();
Intent flush = new Intent(mContext.getString(R.string.action_sense_send_data));
flush.setClass(mContext, nl.sense_os.service.MsgHandler.class);
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,7 +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.setClass(context, nl.sense_os.service.SenseService.class);
serviceIntent.setPackage(context.getPackageName());
if (null == context.startService(serviceIntent)) {
Log.w(TAG, "Could not start Sense service!");
}
Expand Down
2 changes: 1 addition & 1 deletion sense-android-library/src/nl/sense_os/service/BootRx.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +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.setClass(context, nl.sense_os.service.SenseService.class);
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,7 +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.setClass(mContext, nl.sense_os.service.MsgHandler.class);
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 @@ -37,7 +37,7 @@ public void onReceive(final Context context, Intent intent) {
if (false == state.isLoggedIn()) {
Log.i(TAG, "Regained connectivity! Try to log in");
Intent i = new Intent(context.getString(R.string.action_sense_service));
i.setClass(context, nl.sense_os.service.SenseService.class);
i.setPackage(context.getPackageName());
context.startService(i);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@ private void onLogOut() {

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

Expand Down Expand Up @@ -1196,7 +1196,7 @@ synchronized void toggleMain(boolean active) {
// properly start the service to start sensing
Log.i(TAG, "Start service");
Intent serviceIntent = new Intent(getString(R.string.action_sense_service));
serviceIntent.setClass(this, nl.sense_os.service.SenseService.class);
serviceIntent.setPackage(getPackageName());
startService(serviceIntent);

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
sensorData.setPackage(context.getPackageName());
context.startService(sensorData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
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,7 +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.setClass(mContext, nl.sense_os.service.MsgHandler.class);
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,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
this.context.startService(i);

stopSample();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
sensorData.setPackage(context.getPackageName());
context.startService(sensorData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +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.setClass(mContext, nl.sense_os.service.MsgHandler.class);
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,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
sensorData.setPackage(context.getPackageName());
context.startService(sensorData);
}

Expand Down Expand Up @@ -334,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
sensorData.setPackage(context.getPackageName());
context.startService(sensorData);
}

Expand Down Expand Up @@ -520,7 +520,7 @@ public void sendAudio()
i.putExtra(DataPoint.VALUE, fileName);
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.FILE);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
context.startService(i);

} catch (Exception e) {
Expand Down Expand Up @@ -602,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
sensorData.setPackage(context.getPackageName());
context.startService(sensorData);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +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.setClass(mContext, nl.sense_os.service.MsgHandler.class);
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,7 +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.setClass(mContext, nl.sense_os.service.MsgHandler.class);
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,7 +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.setClass(ctxRef.get(), nl.sense_os.service.SenseService.class);
serviceIntent.setPackage(ctxRef.get().getPackageName());
ctxRef.get().startService(serviceIntent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +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.setClass(ctxRef.get(), nl.sense_os.service.SenseService.class);
serviceIntent.setPackage(ctxRef.get().getPackageName());
ctxRef.get().startService(serviceIntent);
}

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

// apply change by starting the service
Intent i = new Intent(getString(R.string.action_sense_service));
i.setClass(this, nl.sense_os.service.SenseService.class);
i.setPackage(getPackageName());
startService(i);

} catch (JSONException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
BluetoothDeviceProximity.this.context.startService(i);
}

Expand All @@ -225,7 +225,7 @@ private void onScanFinished() {
i.putExtra(DataPoint.VALUE, nrBluetoothNeighbours);
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.INT);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setClass(context, nl.sense_os.service.MsgHandler.class);
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,7 +348,7 @@ private void submit() {
dataPoint.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
dataPoint.putExtra(DataPoint.TIMESTAMP, sensorDataPoint.timeStamp);
dataPoint.putExtra(DataPoint.VALUE, value);
dataPoint.setClass(this, nl.sense_os.service.MsgHandler.class);
dataPoint.setPackage(getPackageName());
startService(dataPoint);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
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.setClass(context, nl.sense_os.service.MsgHandler.class);
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,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
context.startService(i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
intent.setPackage(context.getPackageName());
context.startService(intent);
}

Expand Down Expand Up @@ -266,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
context.startService(i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
intent.setPackage(context.getPackageName());
context.startService(intent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
intent.setPackage(context.getPackageName());
context.startService(intent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
context.startService(i);

distanceEstimator.addPoint(fix);
Expand Down Expand Up @@ -170,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
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,7 +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.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
this.context.startService(i);
}
catch(Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void sendData(Sensor sensor) {
i.putExtra(DataPoint.VALUE, value);
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON_TIME_SERIES);
i.putExtra(DataPoint.TIMESTAMP, SNTP.getInstance().getTime() - LOCAL_BUFFER_TIME);
i.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
context.startService(i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void sendFallMessage(boolean fall) {
i.putExtra(DataPoint.VALUE, fall);
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.BOOL);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
context.startService(i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void sendData(Sensor sensor) {
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON_TIME_SERIES);
i.putExtra(DataPoint.TIMESTAMP, SNTP.getInstance().getTime()
- burstDuration);
i.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
context.startService(i);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void sendData() {
i.putExtra(DataPoint.VALUE, value);
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.FLOAT);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
context.startService(i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void sendData(String description, String sensorName, JSONObject json) {
i.putExtra(DataPoint.VALUE, json.toString());
i.putExtra(DataPoint.DATA_TYPE, SenseDataTypes.JSON);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
context.startService(i);
}
catch(Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void sendAppInfo() {
i.putExtra(DataPoint.VALUE, json.toString());
i.putExtra(DataPoint.SENSOR_NAME, SensorNames.APP_INFO_SENSOR);
i.putExtra(DataPoint.TIMESTAMP, dataPoint.timeStamp);
i.setClass(context, nl.sense_os.service.MsgHandler.class);
i.setPackage(context.getPackageName());
context.startService(i);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public abstract class AppInfoVersion {

public final static String SENSE_LIBRARY_VERSION = "v3.3.2-4-g73f0dc4-dirty";
public final static String CORTEX_VERSION = "v1.4.2-coaching_v3.0";
public final static String SENSE_LIBRARY_VERSION = "v3.3.2-5-g704a66e-dirty";
public final static String CORTEX_VERSION = "v1.4.2-coaching_v3.0-dirty";
}
Loading

0 comments on commit a1737a7

Please sign in to comment.