Skip to content

TagSpaces is an offline, open source, document manager with tagging support

chore: removing unneeded plugin and reducing the app permissions

Ilian Sapundshievc4225c77adef
diff --git a/capacitor/android/app/capacitor.build.gradle b/capacitor/android/app/capacitor.build.gradle
index b6f137d25..247377f93 100644
--- a/capacitor/android/app/capacitor.build.gradle
+++ b/capacitor/android/app/capacitor.build.gradle
@@ -9,7 +9,6 @@ android {
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
- implementation project(':anuradev-capacitor-background-mode')
implementation project(':capacitor-community-file-opener')
implementation project(':capacitor-app')
implementation project(':capacitor-browser')
diff --git a/capacitor/android/app/src/main/AndroidManifest.xml b/capacitor/android/app/src/main/AndroidManifest.xml
index 346460b86..5c1793293 100644
--- a/capacitor/android/app/src/main/AndroidManifest.xml
+++ b/capacitor/android/app/src/main/AndroidManifest.xml
@@ -21,6 +21,13 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
+ <!-- Keep audio playing while the app is backgrounded (MediaKeepAliveService) -->
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
+
+ <!-- Pro: voice-note recording (WebView getUserMedia) -->
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
+
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
@@ -81,6 +88,13 @@
</activity>
+ <!-- Keeps WebView audio alive in the background (see MediaKeepAlivePlugin) -->
+ <service
+ android:name="org.tagspaces.plugins.MediaKeepAliveService"
+ android:enabled="true"
+ android:exported="false"
+ android:foregroundServiceType="mediaPlayback" />
+
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
diff --git a/capacitor/android/app/src/main/java/org/tagspaces/mobileapp/MainActivity.java b/capacitor/android/app/src/main/java/org/tagspaces/mobileapp/MainActivity.java
index f60eaa365..985ed3bb0 100644
--- a/capacitor/android/app/src/main/java/org/tagspaces/mobileapp/MainActivity.java
+++ b/capacitor/android/app/src/main/java/org/tagspaces/mobileapp/MainActivity.java
@@ -7,6 +7,7 @@ import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.getcapacitor.BridgeActivity;
import org.tagspaces.plugins.IntentHandlerPlugin;
+import org.tagspaces.plugins.MediaKeepAlivePlugin;
import org.tagspaces.plugins.StoragePermissionPlugin;
public class MainActivity extends BridgeActivity {
@@ -14,6 +15,7 @@ public class MainActivity extends BridgeActivity {
public void onCreate(Bundle savedInstanceState) {
registerPlugin(StoragePermissionPlugin.class);
registerPlugin(IntentHandlerPlugin.class);
+ registerPlugin(MediaKeepAlivePlugin.class);
super.onCreate(savedInstanceState);
insetWebViewFromSystemBars();
}
diff --git a/capacitor/android/app/src/main/java/org/tagspaces/plugins/MediaKeepAlivePlugin.java b/capacitor/android/app/src/main/java/org/tagspaces/plugins/MediaKeepAlivePlugin.java
new file mode 100644
index 000000000..f11dd23f4
--- /dev/null
+++ b/capacitor/android/app/src/main/java/org/tagspaces/plugins/MediaKeepAlivePlugin.java
@@ -0,0 +1,33 @@
+package org.tagspaces.plugins;
+
+import android.content.Intent;
+
+import androidx.core.content.ContextCompat;
+
+import com.getcapacitor.Plugin;
+import com.getcapacitor.PluginCall;
+import com.getcapacitor.PluginMethod;
+import com.getcapacitor.annotation.CapacitorPlugin;
+
+/**
+ * Starts/stops {@link MediaKeepAliveService} so WebView audio keeps playing
+ * when the app is in the background. Mirrors the enable()/disable() API
+ * previously provided by @anuradev/capacitor-background-mode.
+ */
+@CapacitorPlugin(name = "MediaKeepAlive")
+public class MediaKeepAlivePlugin extends Plugin {
+
+ @PluginMethod
+ public void enable(PluginCall call) {
+ Intent intent = new Intent(getContext(), MediaKeepAliveService.class);
+ ContextCompat.startForegroundService(getContext(), intent);
+ call.resolve();
+ }
+
+ @PluginMethod
+ public void disable(PluginCall call) {
+ Intent intent = new Intent(getContext(), MediaKeepAliveService.class);
+ getContext().stopService(intent);
+ call.resolve();
+ }
+}
diff --git a/capacitor/android/app/src/main/java/org/tagspaces/plugins/MediaKeepAliveService.java b/capacitor/android/app/src/main/java/org/tagspaces/plugins/MediaKeepAliveService.java
new file mode 100644
index 000000000..f1672c852
--- /dev/null
+++ b/capacitor/android/app/src/main/java/org/tagspaces/plugins/MediaKeepAliveService.java
@@ -0,0 +1,89 @@
+package org.tagspaces.plugins;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ServiceInfo;
+import android.os.Build;
+import android.os.IBinder;
+import android.os.PowerManager;
+
+import androidx.annotation.Nullable;
+import androidx.core.app.NotificationCompat;
+
+/**
+ * Minimal foreground service that keeps the app process alive so HTML5 audio
+ * playing in the WebView continues while the app is in the background.
+ *
+ * Declared with android:foregroundServiceType="mediaPlayback" in the app
+ * manifest. Replaces the third-party @anuradev/capacitor-background-mode
+ * plugin, which declared microphone / special-use foreground-service types
+ * that TagSpaces does not use and that complicate Google Play review.
+ */
+public class MediaKeepAliveService extends Service {
+
+ private static final int NOTIFICATION_ID = 5740;
+ private static final String CHANNEL_ID = "tagspaces_media_playback";
+
+ private PowerManager.WakeLock wakeLock;
+
+ @Nullable
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Notification notification = buildNotification();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
+ startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
+ } else {
+ startForeground(NOTIFICATION_ID, notification);
+ }
+
+ if (wakeLock == null) {
+ PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
+ wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TagSpaces:MediaKeepAlive");
+ }
+ if (!wakeLock.isHeld()) {
+ wakeLock.acquire();
+ }
+
+ // If the process is killed with no pending start commands, stop rather
+ // than restart with a null intent.
+ return START_NOT_STICKY;
+ }
+
+ @Override
+ public void onDestroy() {
+ if (wakeLock != null && wakeLock.isHeld()) {
+ wakeLock.release();
+ }
+ super.onDestroy();
+ }
+
+ private Notification buildNotification() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ NotificationChannel channel = new NotificationChannel(
+ CHANNEL_ID,
+ "Media playback",
+ NotificationManager.IMPORTANCE_LOW
+ );
+ channel.setShowBadge(false);
+ nm.createNotificationChannel(channel);
+ }
+
+ return new NotificationCompat.Builder(this, CHANNEL_ID)
+ .setContentTitle("TagSpaces")
+ .setContentText("Audio playback active")
+ .setSmallIcon(android.R.drawable.ic_media_play)
+ .setOngoing(true)
+ .setPriority(NotificationCompat.PRIORITY_LOW)
+ .build();
+ }
+}
diff --git a/capacitor/android/capacitor.settings.gradle b/capacitor/android/capacitor.settings.gradle
index fbe557b21..6ccabb41f 100644
--- a/capacitor/android/capacitor.settings.gradle
+++ b/capacitor/android/capacitor.settings.gradle
@@ -2,9 +2,6 @@
include ':capacitor-android'
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')
-include ':anuradev-capacitor-background-mode'
-project(':anuradev-capacitor-background-mode').projectDir = new File('../node_modules/@anuradev/capacitor-background-mode/android')
-
include ':capacitor-community-file-opener'
project(':capacitor-community-file-opener').projectDir = new File('../node_modules/@capacitor-community/file-opener/android')
diff --git a/capacitor/package-lock.json b/capacitor/package-lock.json
index 973abc37e..91e280560 100644
--- a/capacitor/package-lock.json
+++ b/capacitor/package-lock.json
@@ -9,31 +9,21 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
- "@anuradev/capacitor-background-mode": "^7.2.1",
- "@capacitor-community/file-opener": "^8.0.0",
- "@capacitor/android": "^8.3.0",
- "@capacitor/app": "^8.1.0",
- "@capacitor/browser": "^8.0.3",
- "@capacitor/camera": "^8.0.2",
- "@capacitor/cli": "^8.3.0",
- "@capacitor/core": "^8.3.0",
- "@capacitor/device": "^8.0.2",
- "@capacitor/filesystem": "^8.1.2",
- "@capacitor/ios": "^8.3.0",
- "@capacitor/share": "^8.0.1",
- "@capacitor/splash-screen": "^8.0.1",
- "@capacitor/status-bar": "^8.0.2",
- "@capawesome/capacitor-file-picker": "^8.0.2",
- "capacitor-plugin-cdv-purchase": "^13.17.1"
- }
- },
- "node_modules/@anuradev/capacitor-background-mode": {
- "version": "7.2.1",
- "resolved": "https://registry.npmjs.org/@anuradev/capacitor-background-mode/-/capacitor-background-mode-7.2.1.tgz",
- "integrity": "sha512-BKTEtYdbUcVCNS9qMLN2cpX/bqUHmVA0TuaAGn6r4KTtwNWeImjpZP6V9/3gHUO6u6UgykM3Wcz6us38NsTVFQ==",
- "license": "MIT",
- "peerDependencies": {
- "@capacitor/core": ">=7.0.0"
+ "@capacitor-community/file-opener": "8.0.0",
+ "@capacitor/android": "8.3.0",
+ "@capacitor/app": "8.1.0",
+ "@capacitor/browser": "8.0.3",
+ "@capacitor/camera": "8.0.2",
+ "@capacitor/cli": "8.3.0",
+ "@capacitor/core": "8.3.0",
+ "@capacitor/device": "8.0.2",
+ "@capacitor/filesystem": "8.1.2",
+ "@capacitor/ios": "8.3.0",
+ "@capacitor/share": "8.0.1",
+ "@capacitor/splash-screen": "8.0.1",
+ "@capacitor/status-bar": "8.0.2",
+ "@capawesome/capacitor-file-picker": "8.0.2",
+ "capacitor-plugin-cdv-purchase": "13.17.1"
}
},
"node_modules/@capacitor-community/file-opener": {
diff --git a/capacitor/package.json b/capacitor/package.json
index e4d631bd6..c9fc81843 100644
--- a/capacitor/package.json
+++ b/capacitor/package.json
@@ -11,7 +11,6 @@
"license": "ISC",
"type": "commonjs",
"dependencies": {
- "@anuradev/capacitor-background-mode": "7.2.1",
"@capacitor-community/file-opener": "8.0.0",
"@capacitor/android": "8.3.0",
"@capacitor/app": "8.1.0",
diff --git a/src/renderer/services/io-capacitor.ts b/src/renderer/services/io-capacitor.ts
index c5aaaf809..7bc11128d 100644
--- a/src/renderer/services/io-capacitor.ts
+++ b/src/renderer/services/io-capacitor.ts
@@ -35,14 +35,6 @@ try {
console.warn('FileOpener plugin not available');
}
-let BackgroundMode;
-try {
- BackgroundMode =
- require('@anuradev/capacitor-background-mode').BackgroundMode;
-} catch (e) {
- console.warn('BackgroundMode plugin not available');
-}
-
let FilePicker;
try {
FilePicker = require('@capawesome/capacitor-file-picker').FilePicker;
@@ -54,6 +46,10 @@ try {
const { registerPlugin } = require('@capacitor/core');
const StoragePermission = registerPlugin('StoragePermission');
const IntentHandler = registerPlugin('IntentHandler');
+// Android-only: foreground service that keeps WebView audio playing in the
+// background (see MediaKeepAlivePlugin.java). On iOS background audio is handled
+// by UIBackgroundModes "audio" in Info.plist.
+const MediaKeepAlive = registerPlugin('MediaKeepAlive');
// iOS-only: bridges FileManager.url(forUbiquityContainerIdentifier:) (see ICloudPlugin.swift)
const ICloud = registerPlugin('ICloud');
@@ -219,12 +215,13 @@ async function onDeviceReady() {
// the iOS in-app browser collapses env(safe-area-inset-top) on return.
setTimeout(captureSafeAreaInset, 1000);
- // Enable background mode
- if (BackgroundMode) {
+ // Keep WebView audio playing while the app is backgrounded. Android starts a
+ // mediaPlayback foreground service; iOS relies on UIBackgroundModes "audio".
+ if (Capacitor.getPlatform() === 'android') {
try {
- BackgroundMode.enable();
+ await MediaKeepAlive.enable();
} catch (e) {
- console.warn('BackgroundMode enable failed:', e);
+ console.warn('MediaKeepAlive enable failed:', e);
}
}