import java.lang.ref.WeakReference;
import java.util.*;
+import java.io.*;
import android.Manifest;
import android.app.Activity;
public static final int MSG_UPDATE_AGE = 2;
public static final int MSG_IDLE_MODE = 3;
public static final int MSG_IGNITER_STATUS = 4;
+ public static final int MSG_FILE_FAILED = 5;
// Intent request codes
public static final int REQUEST_CONNECT_DEVICE = 1;
ad.idle_mode = (Boolean) msg.obj;
ad.update_state(null);
break;
+ case MSG_FILE_FAILED:
+ ad.file_failed((File) msg.obj);
+ break;
}
}
};
}
}
+ boolean fail_shown;
+
+ private void file_failed(File file) {
+ if (!fail_shown) {
+ fail_shown = true;
+ AlertDialog fail = new AlertDialog.Builder(this).create();
+ fail.setTitle("Failed to Create Log File");
+ fail.setMessage(file.getPath());
+ fail.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ }
+ });
+ fail.show();
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
+/*
+ * Copyright © 2021 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
package org.altusmetrum.AltosDroid;
+import java.io.*;
+
import org.altusmetrum.altoslib_14.*;
import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.os.Environment;
-public class TelemetryLogger {
- private Context context = null;
+public class TelemetryLogger implements AltosLogTrace {
+ private TelemetryService service = null;
private AltosLink link = null;
private AltosLog logger = null;
private BroadcastReceiver mExternalStorageReceiver;
- public TelemetryLogger(Context in_context, AltosLink in_link) {
- context = in_context;
+ /* AltosLogTrace interface */
+ public void trace(String format, Object ... arguments) {
+ AltosDebug.debug(format, arguments);
+ }
+
+ public void open_failed(File file) {
+ service.send_file_failed_to_clients(file);
+ }
+
+ public TelemetryLogger(TelemetryService in_service, AltosLink in_link) {
+ service = in_service;
link = in_link;
startWatchingExternalStorage();
if (Environment.MEDIA_MOUNTED.equals(state)) {
if (logger == null) {
AltosDebug.debug("Starting up Telemetry Logging");
- logger = new AltosLog(link);
+ logger = new AltosLog(link,this);
}
} else {
AltosDebug.debug("External Storage not present - stopping");
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
filter.addAction(Intent.ACTION_MEDIA_REMOVED);
- context.registerReceiver(mExternalStorageReceiver, filter);
+ service.registerReceiver(mExternalStorageReceiver, filter);
handleExternalStorageState();
}
void stopWatchingExternalStorage() {
- context.unregisterReceiver(mExternalStorageReceiver);
+ service.unregisterReceiver(mExternalStorageReceiver);
}
}
import java.lang.ref.WeakReference;
import java.util.concurrent.TimeoutException;
+import java.io.*;
import java.util.*;
import android.app.*;
send_idle_mode_to_client(client);
}
+ private void send_file_failed_to_client(Messenger client, File f) {
+ Message m = Message.obtain(null, AltosDroid.MSG_FILE_FAILED, f);
+ try {
+ client.send(m);
+ } catch (RemoteException e) {
+ AltosDebug.error("Client %s disappeared", client.toString());
+ remove_client(client);
+ }
+ }
+
+ public void send_file_failed_to_clients(File f) {
+ for (Messenger client : clients)
+ send_file_failed_to_client(client, f);
+ }
+
private void telemetry_start() {
if (telemetry_reader == null && idle_monitor == null && !ignite_running) {
telemetry_reader = new TelemetryReader(altos_link, handler);