mobile: fix boot crash on android

This commit is contained in:
Ammar Ahmed
2025-07-08 14:23:25 +05:00
parent 7789bd145c
commit 258aa77cdd
3 changed files with 114 additions and 76 deletions

View File

@@ -113,7 +113,10 @@ async function onBackgroundSyncStarted() {
useUserStore.getState().setSyncing(false); useUserStore.getState().setSyncing(false);
} }
await Notifications.setupReminders(); await Notifications.setupReminders();
if (SettingsService.get().notifNotes) {
Notifications.pinQuickNote(false);
}
Notifications.restorePinnedNotes();
NotePreviewWidget.updateNotes(); NotePreviewWidget.updateNotes();
deleteDCacheFiles(); deleteDCacheFiles();
DatabaseLogger.info("BACKGROUND SYNC COMPLETE"); DatabaseLogger.info("BACKGROUND SYNC COMPLETE");
@@ -142,6 +145,7 @@ const onBoot = async () => {
Notifications.pinQuickNote(false); Notifications.pinQuickNote(false);
} }
Notifications.restorePinnedNotes(); Notifications.restorePinnedNotes();
NotePreviewWidget.updateNotes();
DatabaseLogger.info("BOOT TASK COMPLETE"); DatabaseLogger.info("BOOT TASK COMPLETE");
} catch (e) { } catch (e) {
DatabaseLogger.error(e as Error); DatabaseLogger.error(e as Error);

View File

@@ -11,57 +11,69 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" /> <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove"/> <uses-permission
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove"/> android:name="android.permission.WRITE_EXTERNAL_STORAGE"
<uses-permission android:name="android.permission.CAMERA"/> tools:node="remove" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <uses-permission
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" tools:node="remove" /> android:name="android.permission.READ_EXTERNAL_STORAGE"
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" /> tools:node="remove" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission
android:name="android.permission.USE_FULL_SCREEN_INTENT"
tools:node="remove" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<queries> <queries>
<intent> <intent>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". --> <!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". -->
<data android:mimeType="application/pdf" /> <data android:mimeType="application/pdf" />
</intent> </intent>
<intent> <intent>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". --> <!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". -->
<data android:mimeType="text/*" /> <data android:mimeType="text/*" />
</intent> </intent>
<intent> <intent>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". --> <!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". -->
<data android:mimeType="image/*" /> <data android:mimeType="image/*" />
</intent> </intent>
<intent> <intent>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". --> <!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". -->
<data android:mimeType="video/*" /> <data android:mimeType="video/*" />
</intent> </intent>
<intent> <intent>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". --> <!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". -->
<data android:mimeType="audio/*" /> <data android:mimeType="audio/*" />
</intent> </intent>
</queries> </queries>
<application <application
android:name=".MainApplication" android:name=".MainApplication"
android:allowBackup="false" android:allowBackup="false"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:theme="@style/BootTheme"
android:largeHeap="true" android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_config"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true" android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"> android:theme="@style/BootTheme">
<receiver android:exported="false" android:label="@string/quick_note" android:name=".NoteWidget"> <receiver
android:name=".NoteWidget"
android:exported="false"
android:label="@string/quick_note">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter> </intent-filter>
@@ -71,7 +83,10 @@
android:resource="@xml/new_note_widget_info" /> android:resource="@xml/new_note_widget_info" />
</receiver> </receiver>
<receiver android:exported="false" android:label="@string/note" android:name=".NotePreviewWidget"> <receiver
android:name=".NotePreviewWidget"
android:exported="false"
android:label="@string/note">
<intent-filter>" <intent-filter>"
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter> </intent-filter>
@@ -81,7 +96,10 @@
android:resource="@xml/note_widget_info" /> android:resource="@xml/note_widget_info" />
</receiver> </receiver>
<receiver android:exported="false" android:label="@string/reminders_title" android:name=".ReminderWidgetProvider"> <receiver
android:name=".ReminderWidgetProvider"
android:exported="false"
android:label="@string/reminders_title">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter> </intent-filter>
@@ -90,33 +108,37 @@
android:resource="@xml/widget_reminders_info" /> android:resource="@xml/widget_reminders_info" />
</receiver> </receiver>
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" <activity
android:name=".NotePreviewConfigureActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:exported="true"
android:label="NotePreviewConfigure" android:label="NotePreviewConfigure"
android:launchMode="singleTask" android:launchMode="singleTask"
android:exported="true"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize" android:name=".NotePreviewConfigureActivity"> android:windowSoftInputMode="adjustResize">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/> <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:exported="true"
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTask" android:launchMode="singleTask"
android:resizeableActivity="true" android:resizeableActivity="true"
android:exported="true"
android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/> <action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter android:label="Notesnook"> <intent-filter android:label="Notesnook">
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
@@ -127,6 +149,7 @@
<intent-filter android:label="Notesnook"> <intent-filter android:label="Notesnook">
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
@@ -134,22 +157,25 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:exported="false" android:name="com.facebook.react.devsupport.DevSettingsActivity" /> <activity
android:name="com.facebook.react.devsupport.DevSettingsActivity"
android:exported="false" />
<activity <activity
android:name=".ShareActivity" android:name=".ShareActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:excludeFromRecents="true"
android:exported="true"
android:label="@string/title_activity_share" android:label="@string/title_activity_share"
android:noHistory="true" android:noHistory="true"
android:screenOrientation="unspecified" android:screenOrientation="unspecified"
android:exported="true"
android:taskAffinity="" android:taskAffinity=""
android:excludeFromRecents="true" android:theme="@style/AppThemeB"
android:windowSoftInputMode="adjustResize" android:windowSoftInputMode="adjustResize">
android:theme="@style/AppThemeB">
<intent-filter android:label="Make Note"> <intent-filter android:label="Make Note">
<action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" /> <data android:mimeType="text/*" />
<data android:mimeType="image/*" /> <data android:mimeType="image/*" />
<data android:mimeType="video/*" /> <data android:mimeType="video/*" />
@@ -160,6 +186,7 @@
<intent-filter android:label="Make Note"> <intent-filter android:label="Make Note">
<action android:name="android.intent.action.SEND_MULTIPLE" /> <action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" /> <data android:mimeType="text/*" />
<data android:mimeType="image/*" /> <data android:mimeType="image/*" />
<data android:mimeType="video/*" /> <data android:mimeType="video/*" />
@@ -179,35 +206,41 @@
android:enabled="true" android:enabled="true"
android:exported="true" android:exported="true"
android:stopWithTask="false" /> android:stopWithTask="false" />
<service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" /> <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" />
<service android:name="com.streetwriters.notesnook.BootTaskService" android:foregroundServiceType="dataSync" /> <service
android:name="com.streetwriters.notesnook.BootTaskService"
android:foregroundServiceType="specialUse">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="The service is required by the app to restore notifications of pinned notes, restore notification with reply input for creating notes and restore data in note preview widgets on device reboot." />
</service>
<service <service
android:name=".NotesnookTileService" android:name=".NotesnookTileService"
android:exported="true"
android:icon="@drawable/add_note" android:icon="@drawable/add_note"
android:label="New note" android:label="New note"
android:exported="true"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"> android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter> <intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/> <action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter> </intent-filter>
</service> </service>
<service <service
android:name=".ReminderViewsService" android:name=".ReminderViewsService"
android:exported="true" android:exported="true"
android:permission="android.permission.BIND_REMOTEVIEWS" /> android:permission="android.permission.BIND_REMOTEVIEWS" />
<provider <provider
android:name="androidx.core.content.FileProvider" android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider" android:authorities="${applicationId}.provider"
android:grantUriPermissions="true" android:exported="false"
android:exported="false"> android:grantUriPermissions="true">
<meta-data <meta-data
android:name="android.support.FILE_PROVIDER_PATHS" android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_viewer_provider_paths" /> android:resource="@xml/file_viewer_provider_paths" />
</provider> </provider>
<provider <provider
android:name="com.vinzscam.reactnativefileviewer.FileProvider" android:name="com.vinzscam.reactnativefileviewer.FileProvider"
@@ -219,12 +252,14 @@
android:resource="@xml/file_viewer_provider_paths" /> android:resource="@xml/file_viewer_provider_paths" />
</provider> </provider>
<receiver android:exported="true" android:name=".BootRecieverService"> <receiver
<intent-filter> android:name=".BootRecieverService"
<action android:name="android.intent.action.BOOT_COMPLETED" /> android:exported="true">
<action android:name="android.intent.action.QUICKBOOT_POWERON" /> <intent-filter>
</intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" />
</receiver> <action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
</application> </application>

View File

@@ -39,7 +39,6 @@ public class BootTaskService extends HeadlessJsTaskService {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("com.streetwriters.notesnook", NotificationChannel channel = new NotificationChannel("com.streetwriters.notesnook",
"Default", "Default",
@@ -55,7 +54,7 @@ public class BootTaskService extends HeadlessJsTaskService {
this.startForeground( this.startForeground(
1, 1,
notification, notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC); ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE);
} else { } else {
this.startForeground( this.startForeground(
1, 1,