1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +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" /> android:resource="@xml/telemetry_widget_info" />
</receiver> </receiver>
<service android:name=".OPTelemetryService"></service> <service android:name="org.openpilot.androidgcs.telemetry.OPTelemetryService"></service>
</application> </application>
</manifest> </manifest>

View File

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

View File

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