Skip to content

Commit

Permalink
Defined foreground service type, bumped androidx compat for >=1.12 re…
Browse files Browse the repository at this point in the history
…quirement, specified SMS_SENT receiver export state. Bumped version to 3.0.1
  • Loading branch information
lukeaschenbrenner committed Mar 2, 2025
1 parent a3f4fbf commit a2bdebd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.txtnet.txtnetbrowser"
//minSdk 19
targetSdk 35
versionCode 300
versionName "3.0.0"
versionCode 301
versionName "3.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.debug
Expand Down Expand Up @@ -87,7 +87,7 @@ dependencies {
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.core:core-ktx:1.13.1' //last version to support minSdkVersion<21
implementation 'androidx.navigation:navigation-fragment:2.5.3'
implementation 'androidx.navigation:navigation-ui:2.5.3'
testImplementation 'junit:junit:4.13.2'
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
tools:ignore="ProtectedPermissions" /> Even though it says only system apps can get this permission, that isn't true. -->
<!-- It turns out, we do not need WRITE_SETTINGS since we already have WRITE_SECURE_SETTINGS -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<!-- Below permissions are only needed for Android >= 14 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application
android:allowBackup="true"
Expand Down Expand Up @@ -165,6 +168,7 @@
</activity> <!-- Service that delivers messages from the phone "quick response" -->
<service
android:name=".SMSActivities$HeadlessSmsSendService"
android:foregroundServiceType="remoteMessaging"
android:exported="true"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
<intent-filter>
Expand All @@ -183,7 +187,10 @@
android:description="@string/server_description"
android:icon="@drawable/ic_launcher_monochrome"
android:label="TxtNet Server"
android:permission="android.permission.INTERNET" />
android:permission="android.permission.INTERNET"
android:foregroundServiceType="remoteMessaging|dataSync"
android:exported="false"
/>

<provider
android:name="rikka.shizuku.ShizukuProvider"
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/com/txtnet/txtnetbrowser/server/SmsSocket.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.txtnet.txtnetbrowser.server;

import static android.app.PendingIntent.FLAG_IMMUTABLE;
import static androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED;
import static com.txtnet.txtnetbrowser.basest.Base10Conversions.SYMBOL_TABLE;
import static com.txtnet.txtnetbrowser.basest.Base10Conversions.v2r;

Expand All @@ -14,6 +15,8 @@
import android.telephony.SmsManager;
import android.util.Log;

import androidx.core.content.ContextCompat;

import com.google.i18n.phonenumbers.Phonenumber;
import com.txtnet.brotli4droid.Brotli4jLoader;
import com.txtnet.brotli4droid.encoder.BrotliOutputStream;
Expand Down Expand Up @@ -211,12 +214,11 @@ public void sendHTML(String html, String pageTitle) {
isSending = true;

try{
service.getApplication().getApplicationContext().registerReceiver(SmsSentReceiver.class.newInstance(), new IntentFilter("SMS_SENT"));

}catch(IllegalAccessException e){

}catch( InstantiationException e){
ContextCompat.registerReceiver(service.getApplication().getApplicationContext(),
SmsSentReceiver.class.newInstance(), new IntentFilter("SMS_SENT"), RECEIVER_NOT_EXPORTED);

}catch(IllegalAccessException | InstantiationException e){
Log.e(this.TAG, e.toString());
}

sendMessagesSynchronously(smsQueue, outputNumber, shouldSend, SMS_SERVER_SEND_INTERVAL_MS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ServiceInfo;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
import android.net.Uri;
Expand Down Expand Up @@ -97,6 +98,7 @@
import org.jsoup.select.Elements;
import org.jsoup.select.NodeTraversor;
import org.jsoup.select.NodeVisitor;
import androidx.core.app.ServiceCompat;


public class TxtNetServerService extends Service {
Expand Down Expand Up @@ -240,7 +242,12 @@ else if (intent.getAction().equals(Constants.ACTION.STOPFOREGROUND_ACTION)) {
notificationManager = NotificationManagerCompat.from(context.getApplicationContext());
Notification notif = builder.build();
notificationManager.notify(NOTIFICATION_ID, builder.build());
startForeground(NOTIFICATION_ID, notif);

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE){ // Service types mandatory beginning API 34 (Android 14)
ServiceCompat.startForeground(this, NOTIFICATION_ID, notif, ServiceInfo.FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING | ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
}else{
startForeground(NOTIFICATION_ID, notif);
}



Expand Down

0 comments on commit a2bdebd

Please sign in to comment.