altosdroid: Deal with Google requiring API version 31
[fw/altos] / altosdroid / app / src / main / java / org / altusmetrum / AltosDroid / TelemetryService.java
index 2c2095df68186847225e4480993754123be524a2..e58906ea425d952fee6804fc5f32846c3ae92788 100644 (file)
@@ -20,6 +20,7 @@ package org.altusmetrum.AltosDroid;
 
 import java.lang.ref.WeakReference;
 import java.util.concurrent.TimeoutException;
+import java.io.*;
 import java.util.*;
 
 import android.app.*;
@@ -30,6 +31,7 @@ import android.hardware.usb.*;
 import android.content.Intent;
 import android.content.Context;
 import android.os.*;
+import android.os.Build.*;
 import android.widget.Toast;
 import androidx.core.app.NotificationCompat;
 
@@ -340,6 +342,21 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
                        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);
@@ -646,10 +663,16 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
        @Override
        public int onStartCommand(Intent intent, int flags, int startId) {
                AltosDebug.debug("Received start id %d: %s", startId, intent);
+               int             flag;
+
+               if (android.os.Build.VERSION.SDK_INT >= 31) // android.os.Build.VERSION_CODES.S
+                       flag = 33554432; // PendingIntent.FLAG_MUTABLE
+               else
+                       flag = 0;
 
                // The PendingIntent to launch our activity if the user selects this notification
                PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
-                               new Intent(this, AltosDroid.class), 0);
+                               new Intent(this, AltosDroid.class), flag);
 
                String channelId =
                                (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)