2 * Copyright © 2021 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.AltosDroid;
22 import org.altusmetrum.altoslib_14.*;
24 import android.content.BroadcastReceiver;
25 import android.content.Context;
26 import android.content.Intent;
27 import android.content.IntentFilter;
28 import android.os.Environment;
30 public class TelemetryLogger implements AltosLogTrace {
31 private TelemetryService service = null;
32 private AltosLink link = null;
33 private AltosLog logger = null;
35 private BroadcastReceiver mExternalStorageReceiver;
37 /* AltosLogTrace interface */
38 public void trace(String format, Object ... arguments) {
39 AltosDebug.debug(format, arguments);
42 public void open_failed(File file) {
43 service.send_file_failed_to_clients(file);
46 public TelemetryLogger(TelemetryService in_service, AltosLink in_link) {
50 startWatchingExternalStorage();
54 stopWatchingExternalStorage();
58 private void close() {
60 AltosDebug.debug("Shutting down Telemetry Logging");
66 void handleExternalStorageState() {
67 String state = Environment.getExternalStorageState();
68 if (Environment.MEDIA_MOUNTED.equals(state)) {
70 AltosDebug.debug("Starting up Telemetry Logging");
71 logger = new AltosLog(link,this);
74 AltosDebug.debug("External Storage not present - stopping");
79 void startWatchingExternalStorage() {
80 mExternalStorageReceiver = new BroadcastReceiver() {
82 public void onReceive(Context context, Intent intent) {
83 handleExternalStorageState();
86 IntentFilter filter = new IntentFilter();
87 filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
88 filter.addAction(Intent.ACTION_MEDIA_REMOVED);
89 service.registerReceiver(mExternalStorageReceiver, filter);
90 handleExternalStorageState();
93 void stopWatchingExternalStorage() {
94 service.unregisterReceiver(mExternalStorageReceiver);