Skip to content

Commit 1d65745

Browse files
committed
startForeground updates
1 parent 5cee79f commit 1d65745

File tree

6 files changed

+62
-5
lines changed

6 files changed

+62
-5
lines changed

android-refimpl-app/app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,19 +341,31 @@
341341
<service
342342
android:name=".ConfGroupAudioService"
343343
android:enabled="true"
344+
android:foregroundServiceType="specialUse"
344345
android:exported="false">
346+
<property
347+
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
348+
android:value="watchdog service" />
345349
</service>
346350

347351
<service
348352
android:name=".GroupGroupAudioService"
349353
android:enabled="true"
354+
android:foregroundServiceType="specialUse"
350355
android:exported="false">
356+
<property
357+
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
358+
android:value="watchdog service" />
351359
</service>
352360

353361
<service
354362
android:name=".CallAudioService"
355363
android:enabled="true"
364+
android:foregroundServiceType="specialUse"
356365
android:exported="false">
366+
<property
367+
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
368+
android:value="watchdog service" />
357369
</service>
358370

359371
<receiver android:name=".ConfGroupAudioService$ButtonReceiver" android:enabled="true">

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/CallAudioService.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
import android.content.Context;
2828
import android.content.Intent;
2929
import android.content.ServiceConnection;
30+
import android.content.pm.ServiceInfo;
3031
import android.graphics.Bitmap;
3132
import android.graphics.Color;
3233
import android.graphics.drawable.Drawable;
34+
import android.os.Build;
3335
import android.os.IBinder;
3436
import android.os.SystemClock;
3537
import android.util.Log;
@@ -40,6 +42,7 @@
4042
import com.zoffcc.applications.nativeaudio.NativeAudio;
4143

4244
import androidx.core.app.NotificationCompat;
45+
import androidx.core.app.ServiceCompat;
4346

4447
import static com.zoffcc.applications.trifa.CallingActivity.callactivity_handler_s;
4548
import static com.zoffcc.applications.trifa.CallingActivity.mute_button;
@@ -115,7 +118,15 @@ public void onCreate()
115118

116119
nm3 = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
117120
noti_and_builder = buildNotification(global_gas_status);
118-
startForeground(ONGOING_CALL_AUDIO_NOTIFICATION_ID, noti_and_builder.n);
121+
int type = 0;
122+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
123+
{
124+
type = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE;
125+
}
126+
ServiceCompat.startForeground(this,
127+
ONGOING_CALL_AUDIO_NOTIFICATION_ID,
128+
noti_and_builder.n,
129+
type);
119130

120131
Log.i(TAG, "onCreate:thread:1");
121132

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/ConfGroupAudioService.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
import android.content.Context;
2828
import android.content.Intent;
2929
import android.content.ServiceConnection;
30+
import android.content.pm.ServiceInfo;
3031
import android.graphics.Bitmap;
3132
import android.graphics.Color;
3233
import android.graphics.drawable.Drawable;
3334
import android.media.AudioManager;
35+
import android.os.Build;
3436
import android.os.IBinder;
3537
import android.os.SystemClock;
3638
import android.util.Log;
@@ -41,6 +43,7 @@
4143
import com.zoffcc.applications.nativeaudio.NativeAudio;
4244

4345
import androidx.core.app.NotificationCompat;
46+
import androidx.core.app.ServiceCompat;
4447

4548
import static com.zoffcc.applications.trifa.CallingActivity.audio_receiver_thread;
4649
import static com.zoffcc.applications.trifa.CallingActivity.audio_thread;
@@ -130,7 +133,15 @@ public void onCreate()
130133

131134
nm3 = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
132135
noti_and_builder = buildNotification(global_gas_status);
133-
startForeground(ONGOING_GROUP_AUDIO_NOTIFICATION_ID, noti_and_builder.n);
136+
int type = 0;
137+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
138+
{
139+
type = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE;
140+
}
141+
ServiceCompat.startForeground(this,
142+
ONGOING_GROUP_AUDIO_NOTIFICATION_ID,
143+
noti_and_builder.n,
144+
type);
134145

135146
Log.i(TAG, "onCreate:thread:1");
136147

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/GroupGroupAudioService.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
import android.content.Context;
2828
import android.content.Intent;
2929
import android.content.ServiceConnection;
30+
import android.content.pm.ServiceInfo;
3031
import android.graphics.Bitmap;
3132
import android.graphics.Color;
3233
import android.graphics.drawable.Drawable;
3334
import android.media.AudioManager;
35+
import android.os.Build;
3436
import android.os.IBinder;
3537
import android.os.SystemClock;
3638
import android.util.Log;
@@ -41,6 +43,7 @@
4143
import com.zoffcc.applications.nativeaudio.NativeAudio;
4244

4345
import androidx.core.app.NotificationCompat;
46+
import androidx.core.app.ServiceCompat;
4447

4548
import static com.zoffcc.applications.nativeaudio.NativeAudio.n_audio_in_buffer_max_count;
4649
import static com.zoffcc.applications.trifa.CallingActivity.audio_receiver_thread;
@@ -53,6 +56,7 @@
5356
import static com.zoffcc.applications.trifa.HelperGeneric.reset_audio_mode;
5457
import static com.zoffcc.applications.trifa.HelperGeneric.set_audio_to_headset;
5558
import static com.zoffcc.applications.trifa.HelperGeneric.stop_ngc_audio_system;
59+
import static com.zoffcc.applications.trifa.MainActivity.WATCHDOG_NOTIFICATION_ID;
5660

5761
public class GroupGroupAudioService extends Service
5862
{
@@ -114,7 +118,15 @@ public void onCreate()
114118

115119
ngc_nm3 = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
116120
ngc_noti_and_builder = buildNotification(global_ngc_gas_status);
117-
startForeground(ONGOING_NGC_AUDIO_NOTIFICATION_ID, ngc_noti_and_builder.n);
121+
int type = 0;
122+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
123+
{
124+
type = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE;
125+
}
126+
ServiceCompat.startForeground(this,
127+
ONGOING_NGC_AUDIO_NOTIFICATION_ID,
128+
ngc_noti_and_builder.n,
129+
type);
118130

119131
Log.i(TAG, "onCreate:thread:1");
120132

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/TrifaToxService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.content.Intent;
2929
import android.content.ServiceConnection;
3030
import android.content.SharedPreferences;
31+
import android.content.pm.ServiceInfo;
3132
import android.os.Build;
3233
import android.os.IBinder;
3334
import android.os.Process;
@@ -44,6 +45,7 @@
4445
import java.util.Iterator;
4546
import java.util.List;
4647

48+
import androidx.core.app.ServiceCompat;
4749
import info.guardianproject.iocipher.VirtualFileSystem;
4850

4951
import static com.zoffcc.applications.nativeaudio.NativeAudio.set_aec_active;
@@ -1874,7 +1876,15 @@ void start_me()
18741876
{
18751877
Log.i(TAG, "start_me");
18761878
notification2 = tox_notification_setup(this, nmn2);
1877-
startForeground(HelperToxNotification.ONGOING_NOTIFICATION_ID, notification2);
1879+
int type = 0;
1880+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
1881+
{
1882+
type = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE;
1883+
}
1884+
ServiceCompat.startForeground(this,
1885+
HelperToxNotification.ONGOING_NOTIFICATION_ID,
1886+
notification2,
1887+
type);
18781888
}
18791889

18801890
static void bootstap_from_custom_nodes()

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/WatchdogService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public int onStartCommand(Intent intent, int flags, int startId)
8383
try {
8484
Notification notification = new NotificationCompat.Builder(this, channelId_toxservice).build();
8585
int type = 0;
86-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
86+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
87+
{
8788
type = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE;
8889
}
8990
ServiceCompat.startForeground(this,

0 commit comments

Comments
 (0)