Skip to content

Commit 6c798c6

Browse files
committed
Make it possible to target sdk 34
1 parent eef5ac4 commit 6c798c6

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
3737
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
3838
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" />
39+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
3940

4041
<application
4142
android:name=".app.TermuxApplication"
@@ -196,11 +197,13 @@
196197

197198
<service
198199
android:name=".app.TermuxService"
200+
android:foregroundServiceType="specialUse"
199201
android:exported="false" />
200202

201203
<service
202204
android:name=".app.RunCommandService"
203205
android:exported="true"
206+
android:foregroundServiceType="specialUse"
204207
android:permission="${TERMUX_PACKAGE_NAME}.permission.RUN_COMMAND">
205208
<intent-filter>
206209
<action android:name="${TERMUX_PACKAGE_NAME}.RUN_COMMAND" />

app/src/main/java/com/termux/app/TermuxActivity.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,11 @@ public void onCreate(Bundle savedInstanceState) {
259259
try {
260260
// Start the {@link TermuxService} and make it run regardless of who is bound to it
261261
Intent serviceIntent = new Intent(this, TermuxService.class);
262-
startService(serviceIntent);
262+
if (Build.VERSION.SDK_INT >= 26) {
263+
startForegroundService(serviceIntent);
264+
} else {
265+
startService(serviceIntent);
266+
};
263267

264268
// Attempt to bind to the service, this will call the {@link #onServiceConnected(ComponentName, IBinder)}
265269
// callback if it succeeds.
@@ -932,7 +936,11 @@ private void registerTermuxActivityBroadcastReceiver() {
932936
intentFilter.addAction(TERMUX_ACTIVITY.ACTION_RELOAD_STYLE);
933937
intentFilter.addAction(TERMUX_ACTIVITY.ACTION_REQUEST_PERMISSIONS);
934938

935-
registerReceiver(mTermuxActivityBroadcastReceiver, intentFilter);
939+
if (Build.VERSION.SDK_INT >= 28 ) {
940+
registerReceiver(mTermuxActivityBroadcastReceiver, intentFilter, Context.RECEIVER_NOT_EXPORTED);
941+
} else {
942+
registerReceiver(mTermuxActivityBroadcastReceiver, intentFilter);
943+
}
936944
}
937945

938946
private void unregisterTermuxActivityBroadcastReceiver() {

app/src/main/java/com/termux/app/TermuxService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ private Notification buildNotification() {
784784

785785
// Set pending intent to be launched when notification is clicked
786786
Intent notificationIntent = TermuxActivity.newInstance(this);
787-
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
787+
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
788788

789789

790790
// Set notification text
@@ -827,15 +827,15 @@ private Notification buildNotification() {
827827

828828
// Set Exit button action
829829
Intent exitIntent = new Intent(this, TermuxService.class).setAction(TERMUX_SERVICE.ACTION_STOP_SERVICE);
830-
builder.addAction(android.R.drawable.ic_delete, res.getString(R.string.notification_action_exit), PendingIntent.getService(this, 0, exitIntent, 0));
830+
builder.addAction(android.R.drawable.ic_delete, res.getString(R.string.notification_action_exit), PendingIntent.getService(this, 0, exitIntent, PendingIntent.FLAG_IMMUTABLE));
831831

832832

833833
// Set Wakelock button actions
834834
String newWakeAction = wakeLockHeld ? TERMUX_SERVICE.ACTION_WAKE_UNLOCK : TERMUX_SERVICE.ACTION_WAKE_LOCK;
835835
Intent toggleWakeLockIntent = new Intent(this, TermuxService.class).setAction(newWakeAction);
836836
String actionTitle = res.getString(wakeLockHeld ? R.string.notification_action_wake_unlock : R.string.notification_action_wake_lock);
837837
int actionIcon = wakeLockHeld ? android.R.drawable.ic_lock_idle_lock : android.R.drawable.ic_lock_lock;
838-
builder.addAction(actionIcon, actionTitle, PendingIntent.getService(this, 0, toggleWakeLockIntent, 0));
838+
builder.addAction(actionIcon, actionTitle, PendingIntent.getService(this, 0, toggleWakeLockIntent, PendingIntent.FLAG_IMMUTABLE));
839839

840840

841841
return builder.build();

termux-shared/src/main/java/com/termux/shared/termux/crash/TermuxCrashUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public static void sendCrashReportNotification(final Context currentPackageConte
342342
// Must ensure result code for PendingIntents and id for notification are unique otherwise will override previous
343343
int nextNotificationId = TermuxNotificationUtils.getNextNotificationId(termuxPackageContext);
344344

345-
PendingIntent contentIntent = PendingIntent.getActivity(termuxPackageContext, nextNotificationId, result.contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
345+
PendingIntent contentIntent = PendingIntent.getActivity(termuxPackageContext, nextNotificationId, result.contentIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
346346

347347
PendingIntent deleteIntent = null;
348348
if (result.deleteIntent != null)

0 commit comments

Comments
 (0)