|
| 1 | +/*! |
| 2 | +@class QtDataSync::AndroidBackgroundService |
| 3 | + |
| 4 | +This service can be used as Android service to create a background synchronizations service |
| 5 | +without much effort. However, a few additional setup steps are needed. This class only extends |
| 6 | +the QtService implementation of an android service to add the synchronization aspect. |
| 7 | + |
| 8 | +@warning This class alone is **not** sufficient to make synchronization possible. Have a look at |
| 9 | +the @ref android_sync_guide to learn how to add background synchronization to your project. |
| 10 | + |
| 11 | +@sa AndroidSyncControl, QtService::Service, @ref qtservice_backends_android |
| 12 | +*/ |
| 13 | + |
| 14 | +/*! |
| 15 | +@property QtDataSync::AndroidBackgroundService::waitFullSync |
| 16 | + |
| 17 | +@default{`true`} |
| 18 | + |
| 19 | +If set to true, the serivce will internally call SyncManager::runOnSynchronized() with the |
| 20 | +onSyncCompleted() as handler. If disable, SyncManager::runOnDownloaded() is used instead. Check |
| 21 | +the documentation of these two methods. |
| 22 | + |
| 23 | +@accessors{ |
| 24 | + @readAc{waitFullSync()} |
| 25 | + @writeAc{setWaitFullSync()} |
| 26 | + @notifyAc{waitFullSyncChanged()} |
| 27 | +} |
| 28 | + |
| 29 | +@sa AndroidBackgroundService::onSyncCompleted, SyncManager::runOnSynchronized, |
| 30 | +SyncManager::runOnDownloaded |
| 31 | +*/ |
| 32 | + |
| 33 | +/*! |
| 34 | +@fn QtDataSync::AndroidBackgroundService::setupName |
| 35 | + |
| 36 | +@returns The name of the setup |
| 37 | + |
| 38 | +The default implementation returns `QtDataSync::DefaultSetup`. You can override the method if you |
| 39 | +need the service to create the setup under a different name. |
| 40 | + |
| 41 | +@sa QtDataSync::DefaultSetup, AndroidBackgroundService::prepareSetup |
| 42 | +*/ |
| 43 | + |
| 44 | +/*! |
| 45 | +@fn QtDataSync::AndroidBackgroundService::prepareSetup |
| 46 | + |
| 47 | +@param setup The setup to be prepared |
| 48 | + |
| 49 | +You should override this method to configure the setup before creation (i.e. set properties on it). |
| 50 | +The default implementation does nothing. |
| 51 | + |
| 52 | +@sa QtDataSync::Setup, AndroidBackgroundService::setupName |
| 53 | +*/ |
| 54 | + |
| 55 | +/*! |
| 56 | +@fn QtDataSync::AndroidBackgroundService::onSyncCompleted |
| 57 | + |
| 58 | +@param state The state in which the synchronization finished |
| 59 | + |
| 60 | +This method is called as soon as the datasync instance has finished the data synchronization. You |
| 61 | +can override it to perform additional operations with the data before quitting the service. |
| 62 | + |
| 63 | +The default implementation only calls exitAfterSync() to quit the service gracefully. You must |
| 64 | +do the same in your implementation. You do not have to call it from within the method, but must |
| 65 | +call it eventually. Otherwise it will keep running indefinitely |
| 66 | + |
| 67 | +Possible states can be: |
| 68 | +- Uploading (only if waitFullSync is set to false) |
| 69 | +- Synchronized |
| 70 | +- Error |
| 71 | +- Disconnected |
| 72 | + |
| 73 | +@sa AndroidBackgroundService::waitFullSync, AndroidBackgroundService::exitAfterSync |
| 74 | +*/ |
| 75 | + |
| 76 | +/*! |
| 77 | +@fn QtDataSync::AndroidBackgroundService::exitAfterSync |
| 78 | + |
| 79 | +Call this method if you reimplement onSyncCompleted(). It will quit the service gracefully, |
| 80 | +honoring the order of start commands, if multiple have been used. Internally, this method calls |
| 81 | +stopSelf() with the most recently used startId of a BackgroundSyncAction. |
| 82 | + |
| 83 | +@sa AndroidBackgroundService::onSyncCompleted, AndroidBackgroundService::stopSelf, |
| 84 | +AndroidBackgroundService::BackgroundSyncAction |
| 85 | +*/ |
| 86 | + |
| 87 | +/*! |
| 88 | +@fn QtDataSync::AndroidBackgroundService::onStartCommand |
| 89 | + |
| 90 | +@param intent The intent that was used to start the service |
| 91 | +@param flags The flags that were used to start the service |
| 92 | +@param startId The id of this start request |
| 93 | +@returns A value allowed by android to indicate the servies state |
| 94 | + |
| 95 | +This method is registered within QtService via QtService::Service::addCallback. Check |
| 96 | +@ref qtservice_backends_android documentation for details on the method itself. Its bascially just |
| 97 | +a forwarding of the Android Service method. |
| 98 | + |
| 99 | +Only implement this if you need to do custom stuff here. You should always call this base |
| 100 | +implementation in your overload, as this method internally handles the synchronization intents. |
| 101 | + |
| 102 | +@attention This method is called synchronously on the android thread. This means you should not |
| 103 | +interact with service class at all. Only use queued invokes to schedule things to be done on |
| 104 | +the actual main thread. |
| 105 | + |
| 106 | +@sa @ref qtservice_backends_android, QtService::Service::addCallback, |
| 107 | +AndroidBackgroundService::stopSelf, |
| 108 | +[android.app.Service.onStartCommand](https://developer.android.com/reference/android/app/Service.html#onStartCommand(android.content.Intent,%20int,%20int)) |
| 109 | +*/ |
| 110 | + |
| 111 | +/*! |
| 112 | +@fn QtDataSync::AndroidBackgroundService::createForegroundNotification |
| 113 | + |
| 114 | +@returns An Android |
| 115 | +[Notification](https://developer.android.com/reference/android/app/Notification) object, ready to |
| 116 | +be presented as foreground notification |
| 117 | + |
| 118 | +You must implement this method to create a working service, as since Android 8, all services that |
| 119 | +want to run must show a foreground notification while running in order to not be killed by the |
| 120 | +system. A basic sample could be the following. |
| 121 | + |
| 122 | +The code to create the notification was first written in java: |
| 123 | +@snippet SvcHelper.java create_notification |
| 124 | +And that method is then simply called from the implementation: |
| 125 | +@snippet syncservice.cpp jni_create_notification |
| 126 | + |
| 127 | +@sa [android.app.Notification](https://developer.android.com/reference/android/app/Notification) |
| 128 | +*/ |
| 129 | + |
| 130 | +/*! |
| 131 | +@fn QtDataSync::AndroidBackgroundService::stopSelf |
| 132 | + |
| 133 | +@param startId The id of the start command that was finished and thus is beeing stopped |
| 134 | +@returns true if the service stop was accepted, false if not |
| 135 | + |
| 136 | +Internally this method simply calls stopSelfResult on the android service. You can reimplement |
| 137 | +it if you want to customize how to quit the service. |
| 138 | + |
| 139 | +@sa AndroidBackgroundService::exitAfterSync, AndroidBackgroundService::onStartCommand, |
| 140 | +android.app.Service.stopSelfResult](https://developer.android.com/reference/android/app/Service.html#stopSelfResult(int)) |
| 141 | +*/ |
0 commit comments