1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

AndroidGCS: Get telemetry service working again properly when in multiple

packages.  Have to declare the full service name in AndroidManifest.xml which
seems not ideal.
This commit is contained in:
James Cotton 2012-08-08 11:17:29 -05:00
parent ae36f39f1a
commit ce52b4d199
3 changed files with 24 additions and 5 deletions

View File

@ -46,6 +46,6 @@
android:resource="@xml/telemetry_widget_info" />
</receiver>
<service android:name=".OPTelemetryService"></service>
<service android:name="org.openpilot.androidgcs.telemetry.OPTelemetryService"></service>
</application>
</manifest>

View File

@ -34,6 +34,7 @@ import java.util.ListIterator;
import java.util.Observable;
import java.util.Observer;
import org.openpilot.androidgcs.fragments.ObjectManagerFragment;
import org.openpilot.androidgcs.telemetry.OPTelemetryService;
import org.openpilot.androidgcs.telemetry.OPTelemetryService.LocalBinder;
import org.openpilot.androidgcs.telemetry.OPTelemetryService.TelemTask;
@ -84,7 +85,8 @@ public abstract class ObjectManagerActivity extends Activity {
connectedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Received intent");
if (DEBUG)
Log.d(TAG, "Received intent");
TelemTask task;
if(intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_CONNECTED) == 0) {
if(binder == null)
@ -236,6 +238,10 @@ public abstract class ObjectManagerActivity extends Activity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (!mBound || binder == null) {
Log.e(TAG, "Unable to connect to service");
return super.onOptionsItemSelected(item);
}
switch(item.getItemId()) {
case R.id.menu_connect:
binder.openConnection();
@ -263,7 +269,10 @@ public abstract class ObjectManagerActivity extends Activity {
@Override
public void onStart() {
super.onStart();
Intent intent = new Intent(this, OPTelemetryService.class);
Intent intent = new Intent(getApplicationContext(),
org.openpilot.androidgcs.telemetry.OPTelemetryService.class);
if (DEBUG)
Log.d(TAG, "Attempting to bind: " + intent);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}

View File

@ -54,7 +54,7 @@ import android.widget.Toast;
public class OPTelemetryService extends Service {
// Logging settings
private final String TAG = "OPTelemetryService";
private final String TAG = OPTelemetryService.class.getSimpleName();
public static int LOGLEVEL = 0;
public static boolean WARN = LOGLEVEL > 1;
public static boolean DEBUG = LOGLEVEL > 0;
@ -89,6 +89,8 @@ public class OPTelemetryService extends Service {
}
@Override
public void handleMessage(Message msg) {
if (DEBUG)
Log.d(TAG, "handleMessage: " + msg);
switch(msg.arg1) {
case MSG_START:
stopSelf(msg.arg2);
@ -158,6 +160,9 @@ public class OPTelemetryService extends Service {
public void startup() {
Toast.makeText(getApplicationContext(), "Telemetry service starting", Toast.LENGTH_SHORT).show();
if (DEBUG)
Log.d(TAG, "startup()");
thread = new HandlerThread("TelemetryServiceHandler", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
@ -177,19 +182,24 @@ public class OPTelemetryService extends Service {
@Override
public void onCreate() {
if (DEBUG)
Log.d(TAG, "Telemetry service created");
startup();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Currently only using as bound service
if (DEBUG)
Log.d(TAG, "onStartCommand()");
// If we get killed, after returning from here, restart
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
if (DEBUG)
Log.d(TAG, "onBind()");
return mBinder;
}