mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Do some parameter checks
This commit is contained in:
parent
93d38843c3
commit
e492e4318b
4 changed files with 12 additions and 4 deletions
|
@ -33,13 +33,12 @@ interface PushersService {
|
||||||
* @param pushkey This is a unique identifier for this pusher. The value you should use for
|
* @param pushkey This is a unique identifier for this pusher. The value you should use for
|
||||||
* this is the routing or destination address information for the notification,
|
* this is the routing or destination address information for the notification,
|
||||||
* for example, the APNS token for APNS or the Registration ID for GCM. If your
|
* for example, the APNS token for APNS or the Registration ID for GCM. If your
|
||||||
* notification client has no such concept, use any unique identifier. Max length, 512 bytes.
|
* notification client has no such concept, use any unique identifier. Max length, 512 chars.
|
||||||
* If the kind is "email", this is the email address to send notifications to.
|
* If the kind is "email", this is the email address to send notifications to.
|
||||||
* @param appId the application id
|
* @param appId the application id
|
||||||
* This is a reverse-DNS style identifier for the application. It is recommended
|
* This is a reverse-DNS style identifier for the application. It is recommended
|
||||||
* that this end with the platform, such that different platform versions get
|
* that this end with the platform, such that different platform versions get
|
||||||
* different app identifiers. Max length, 64 chars.
|
* different app identifiers. Max length, 64 chars.
|
||||||
* If the kind is "email", this is "m.email".
|
|
||||||
* @param profileTag This string determines which set of device specific rules this pusher executes.
|
* @param profileTag This string determines which set of device specific rules this pusher executes.
|
||||||
* @param lang The preferred language for receiving notifications (e.g. "en" or "en-US").
|
* @param lang The preferred language for receiving notifications (e.g. "en" or "en-US").
|
||||||
* @param appDisplayName A human readable string that will allow the user to identify what application owns this pusher.
|
* @param appDisplayName A human readable string that will allow the user to identify what application owns this pusher.
|
||||||
|
@ -52,6 +51,7 @@ interface PushersService {
|
||||||
* Ref: https://matrix.org/docs/spec/push_gateway/r0.1.1#homeserver-behaviour
|
* Ref: https://matrix.org/docs/spec/push_gateway/r0.1.1#homeserver-behaviour
|
||||||
*
|
*
|
||||||
* @return A work request uuid. Can be used to listen to the status
|
* @return A work request uuid. Can be used to listen to the status
|
||||||
|
* @throws [InvalidParameterException] if a parameter is not correct
|
||||||
* (LiveData<WorkInfo> status = workManager.getWorkInfoByIdLiveData(<UUID>))
|
* (LiveData<WorkInfo> status = workManager.getWorkInfoByIdLiveData(<UUID>))
|
||||||
*/
|
*/
|
||||||
fun addHttpPusher(pushkey: String,
|
fun addHttpPusher(pushkey: String,
|
||||||
|
|
|
@ -29,6 +29,7 @@ import im.vector.matrix.android.internal.di.WorkManagerProvider
|
||||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
import im.vector.matrix.android.internal.task.configureWith
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
|
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
|
||||||
|
import java.security.InvalidParameterException
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -58,6 +59,11 @@ internal class DefaultPusherService @Inject constructor(
|
||||||
append: Boolean,
|
append: Boolean,
|
||||||
withEventIdOnly: Boolean)
|
withEventIdOnly: Boolean)
|
||||||
: UUID {
|
: UUID {
|
||||||
|
// Do some parameter checks. It's ok to throw Exception, to inform developer of the problem
|
||||||
|
if (pushkey.length > 512) throw InvalidParameterException("pushkey should not exceed 512 chars")
|
||||||
|
if (appId.length > 64) throw InvalidParameterException("appId should not exceed 64 chars")
|
||||||
|
if ("/_matrix/push/v1/notify" !in url) throw InvalidParameterException("url should contain '/_matrix/push/v1/notify'")
|
||||||
|
|
||||||
val pusher = JsonPusher(
|
val pusher = JsonPusher(
|
||||||
pushKey = pushkey,
|
pushKey = pushkey,
|
||||||
kind = "http",
|
kind = "http",
|
||||||
|
|
|
@ -47,8 +47,8 @@ class PushersManager @Inject constructor(
|
||||||
appNameProvider.getAppName(),
|
appNameProvider.getAppName(),
|
||||||
currentSession.sessionParams.credentials.deviceId ?: "MOBILE",
|
currentSession.sessionParams.credentials.deviceId ?: "MOBILE",
|
||||||
stringProvider.getString(R.string.pusher_http_url),
|
stringProvider.getString(R.string.pusher_http_url),
|
||||||
false,
|
append = false,
|
||||||
true
|
withEventIdOnly = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
https://matrix.org/docs/spec/client_server/r0.4.0#id128
|
https://matrix.org/docs/spec/client_server/r0.4.0#id128
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<!-- Note: pusher_http_url should have path '/_matrix/push/v1/notify' -->
|
||||||
<string name="pusher_http_url" translatable="false">https://matrix.org/_matrix/push/v1/notify</string>
|
<string name="pusher_http_url" translatable="false">https://matrix.org/_matrix/push/v1/notify</string>
|
||||||
|
<!-- Note: pusher_app_id cannot exceed 64 chars -->
|
||||||
<string name="pusher_app_id" translatable="false">im.vector.app.android</string>
|
<string name="pusher_app_id" translatable="false">im.vector.app.android</string>
|
||||||
|
|
||||||
<string-array name="room_directory_servers" translatable="false">
|
<string-array name="room_directory_servers" translatable="false">
|
||||||
|
|
Loading…
Reference in a new issue