From 9e7d4c901e040943c81ed12ea9260eb3ba760abb Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 11 Mar 2021 16:47:21 +0300 Subject: [PATCH 1/8] Api interceptor implementation to allow app developers to peek responses. --- .../java/org/matrix/android/sdk/api/Matrix.kt | 7 + .../android/sdk/api/network/ApiInterceptor.kt | 90 +++++++++ .../matrix/android/sdk/api/network/ApiPath.kt | 183 ++++++++++++++++++ .../android/sdk/internal/di/NetworkModule.kt | 12 +- 4 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiInterceptor.kt create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiPath.kt diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt index a5d457222f..90bfbe3de6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt @@ -25,6 +25,8 @@ import org.matrix.android.sdk.BuildConfig import org.matrix.android.sdk.api.auth.AuthenticationService import org.matrix.android.sdk.api.auth.HomeServerHistoryService import org.matrix.android.sdk.api.legacy.LegacySessionImporter +import org.matrix.android.sdk.api.network.ApiInterceptor +import org.matrix.android.sdk.api.network.ApiPath import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.internal.SessionManager import org.matrix.android.sdk.internal.di.DaggerMatrixComponent @@ -49,6 +51,7 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo @Inject internal lateinit var olmManager: OlmManager @Inject internal lateinit var sessionManager: SessionManager @Inject internal lateinit var homeServerHistoryService: HomeServerHistoryService + @Inject internal lateinit var apiInterceptor: ApiInterceptor init { Monarchy.init(context) @@ -73,6 +76,10 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo return legacySessionImporter } + fun registerApiInterceptorListener(path: ApiPath, listener: ApiInterceptor.Listener) { + apiInterceptor.addListener(path, listener) + } + companion object { private lateinit var instance: Matrix diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiInterceptor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiInterceptor.kt new file mode 100644 index 0000000000..2b259a9797 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiInterceptor.kt @@ -0,0 +1,90 @@ +/* + * Copyright 2020 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.api.network + +import okhttp3.Interceptor +import okhttp3.Response +import timber.log.Timber +import javax.inject.Inject +import javax.inject.Singleton + +/** + * Interceptor class for provided api paths. + */ +@Singleton +class ApiInterceptor @Inject constructor() : Interceptor { + + interface Listener { + fun onApiResponse(path: ApiPath, response: String) + } + + init { + Timber.d("ApiInterceptor.init") + } + + private val apiResponseListenersMap = mutableMapOf>() + + override fun intercept(chain: Interceptor.Chain): Response { + val request = chain.request() + val path = request.url.encodedPath.replaceFirst("/", "") + val method = request.method + + val response = chain.proceed(request) + + findApiPath(path, method)?.let { apiPath -> + response.peekBody(Long.MAX_VALUE).string().let { + apiResponseListenersMap[apiPath]?.forEach { listener -> + listener.onApiResponse(apiPath, it) + } + } + } + + return response + } + + private fun findApiPath(path: String, method: String): ApiPath? { + return apiResponseListenersMap + .keys + .find { apiPath -> + apiPath.method === method && isTheSamePath(apiPath.path, path) + } + } + + private fun isTheSamePath(pattern: String, path: String): Boolean { + val patternSegments = pattern.split("/") + val pathSegments = path.split("/") + + if (patternSegments.size != pathSegments.size) return false + + for (i in patternSegments.indices) { + if (patternSegments[i] != pathSegments[i] && !patternSegments[i].startsWith("{")) { + return false + } + } + return true + } + + /** + * Adds listener to send intercepted api responses through. + */ + fun addListener(path: ApiPath, listener: Listener) { + if (!apiResponseListenersMap.contains(path)) { + apiResponseListenersMap[path] = mutableListOf() + } + apiResponseListenersMap[path]?.add(listener) + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiPath.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiPath.kt new file mode 100644 index 0000000000..4de8d49cf4 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiPath.kt @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.api.network + +import org.matrix.android.sdk.internal.network.NetworkConstants + +enum class ApiPath(val path: String, val method: String) { + // AuthApi + VERSIONS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "versions", "GET"), + REGISTER(NetworkConstants.URI_API_PREFIX_PATH_R0 + "register", "POST"), + ADD_3PID(NetworkConstants.URI_API_PREFIX_PATH_R0 + "register/{threePid}/requestToken", "POST"), + LOGIN_FLOWS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login", "GET"), + LOGIN(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login", "POST"), + RESET_PASSWORD(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password/email/requestToken", "POST"), + RESET_PASSWORD_MAIL_CONFIRMED(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password", "POST"), + + // DirectoryApi + ROOM_ID_BY_ALIAS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}", "GET"), + ROOM_DIRECTORY_VISIBILITY(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/list/room/{roomId}", "GET"), + SET_ROOM_DIRECTORY_VISIBILITY(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/list/room/{roomId}", "PUT"), + ADD_ROOM_ALIAS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}", "PUT"), + DELETE_ROOM_ALIAS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}", "DELETE"), + + // CryptoApi + GET_DEVICES(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices", "GET"), + GET_DEVICE_INFO(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{deviceId}", "GET"), + UPLOAD_KEYS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/upload", "POST"), + DOWNLOAD_KEYS_FOR_USERS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/query", "POST"), + UPLOAD_SIGNING_KEYS(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "keys/device_signing/upload", "POST"), + UPLOAD_SIGNATURES(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "keys/signatures/upload", "POST"), + CLAIM_ONE_TIME_KEYS_FOR_USERS_DEVICES(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/claim", "POST"), + SEND_TO_DEVICE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "sendToDevice/{eventType}/{txnId}", "PUT"), + DELETE_DEVICE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{device_id}", "DELETE"), + UPDATE_DEVICE_INFO(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{device_id}", "PUT"), + GET_KEY_CHANGES(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/changes", "GET"), + + // RoomKeysApi + CREATE_KEYS_BACKUP_VERSION(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version", "POST"), + GET_KEYS_BACKUP_LAST_VERSION(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version", "GET"), + GET_KEYS_BACKUP_VERSION(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}", "GET"), + UPDATE_KEYS_BACKUP_VERSION(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}", "PUT"), + STORE_ROOM_SESSION_DATA(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}", "PUT"), + STORE_ROOM_SESSIONS_DATA(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}", "PUT"), + STORE_SESSIONS_DATA(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys", "PUT"), + GET_ROOM_SESSION_DATA(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}", "GET"), + GET_ROOM_SESSIONS_DATA(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}", "GET"), + GET_SESSIONS_DATA(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys", "GET"), + DELETE_ROOM_SESSION_DATA(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}", "DELETE"), + DELETE_ROOM_SESSIONS_DATA(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}", "DELETE"), + DELETE_SESSIONS_DATA(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys", "DELETE"), + DELETE_BACKUP(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}", "DELETE"), + + // AccountApi + CHANGE_PASSWORD(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password", "POST"), + DEACTIVATE_ACCOUNT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/deactivate", "POST"), + + // SearchApi + SEARCH(NetworkConstants.URI_API_PREFIX_PATH_R0 + "search", "POST"), + + // FederationApi + GET_FEDERATION_VERSION(NetworkConstants.URI_FEDERATION_PATH + "version", "GET"), + + // VoipApi + GET_TURN_SERVER(NetworkConstants.URI_API_PREFIX_PATH_R0 + "voip/turnServer", "GET"), + + // PushGatewayApi + NOTIFY_PUSH_GATEWAY(NetworkConstants.URI_PUSH_GATEWAY_PREFIX_PATH + "notify", "POST"), + + // GroupApi + GET_GROUP_SUMMARY(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/summary", "GET"), + GET_GROUP_ROOMS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/rooms", "GET"), + GET_GROUP_USERS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/users", "GET"), + + // CapabilitiesApi + GET_CAPABILITIES(NetworkConstants.URI_API_PREFIX_PATH_R0 + "capabilities", "GET"), + GET_VERSIONS(NetworkConstants.URI_API_PREFIX_PATH_ + "versions", "GET"), + PING(NetworkConstants.URI_API_PREFIX_PATH_ + "versions", "GET"), + + // IdentityApi + GET_ACCOUNT(NetworkConstants.URI_IDENTITY_PATH_V2 + "account", "GET"), + LOGOUT(NetworkConstants.URI_IDENTITY_PATH_V2 + "account/logout", "POST"), + IDENTITY_HAS_DETAILS(NetworkConstants.URI_IDENTITY_PATH_V2 + "hash_details", "GET"), + LOOKUP(NetworkConstants.URI_IDENTITY_PATH_V2 + "lookup", "POST"), + REQUEST_TOKEN_TO_BIND_EMAIL(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/email/requestToken", "POST"), + REQUEST_TOKEN_TO_BIND_MSISDN(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/msisdn/requestToken", "POST"), + SUBMIT_TOKEN(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/{medium}/submitToken", "POST"), + + // FilterApi + UPLOAD_FILTER(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/filter", "POST"), + GET_FILTER_BY_ID(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/filter/{filterId}", "GET"), + + // IndentityAuthApi + IDENTITY_REGISTER(NetworkConstants.URI_IDENTITY_PATH_V2 + "account/register", "POST"), + + // MediaApi + GET_MEDIA_CONFIG(NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "config", "GET"), + GET_PREVIEW_URL_DATA(NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "preview_url", "GET"), + + // OpenIdApi + OPEN_ID_TOKEN(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/openid/request_token", "POST"), + + // ProfileApi + GET_PROFILE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}", "GET"), + GET_THREE_PIDS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid", "GET"), + SET_DISPLAY_NAME(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}/displayname", "PUT"), + SET_AVATAR_URL(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}/avatar_url", "PUT"), + BIND_THREE_PID(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "account/3pid/bind", "POST"), + UNBIND_THREE_PID(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "account/3pid/unbind", "POST"), + ADD_EMAIL(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/email/requestToken", "POST"), + ADD_MSISDN(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/msisdn/requestToken", "POST"), + FINALIZE_ADD_THREE_PID(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/add", "POST"), + DELETE_THREE_PID(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/delete", "POST"), + + // PusherRulesApi + GET_ALL_PUSHER_RULES(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/", "GET"), + UPDATE_ENABLE_PUSH_RULE_STATUS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/enabled", "PUT"), + UPDATE_PUSH_RULE_ACTIONS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/actions", "PUT"), + DELETE_PUSH_RULE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}", "DELETE"), + ADD_PUSH_RULE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}", "PUT"), + + // PusherApi + GET_PUSHERS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushers", "GET"), + SET_PUSHER(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushers/set", "POST"), + + // SignOutApi + LOGIN_AGAIN(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login", "POST"), + SIGN_OUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "logout", "POST"), + + // RoomApi + GET_PUBLIC_ROOMS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "publicRooms", "POST"), + CREATE_ROOM(NetworkConstants.URI_API_PREFIX_PATH_R0 + "createRoom", "POST"), + GET_ROOM_MESSAGES_FROM(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/messages", "GET"), + GET_MEMBERS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/members", "GET"), + SEND_EVENT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/send/{eventType}/{txId}", "PUT"), + GET_CONTEXT_OF_EVENT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/context/{eventId}", "GET"), + GET_EVENT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/event/{eventId}", "GET"), + SEND_READ_MARKER(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/read_markers", "POST"), + INVITE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/invite", "POST"), + INVITE_USING_THREE_PID(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/invite", "POST"), + SEND_STATE_EVENT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/state/{state_event_type}", "PUT"), + SEND_STATE_EVENT_WITH_STATE_KEY(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/state/{state_event_type}/{state_key}", "PUT"), + GET_ROOM_STATE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/state", "GET"), + SEND_RELATION(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/send_relation/{parent_id}/{relation_type}/{event_type}", "POST"), + GET_RELATIONS(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "rooms/{roomId}/relations/{eventId}/{relationType}/{eventType}", "GET"), + JOIN_ROOM(NetworkConstants.URI_API_PREFIX_PATH_R0 + "join/{roomIdOrAlias}", "POST"), + LEAVE_ROOM(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/leave", "POST"), + BAN_USER(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/ban", "POST"), + UNBAN_USER(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/unban", "POST"), + KICK_USER(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/kick", "POST"), + REDACT_EVENT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/redact/{eventId}/{txnId}", "PUT"), + REPORT_CONTENT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/report/{eventId}", "POST"), + GET_ALIASES(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "org.matrix.msc2432/rooms/{roomId}/aliases", "GET"), + SEND_TYPING_STATE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/typing/{userId}", "PUT"), + PUT_TAG(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/rooms/{roomId}/tags/{tag}", "PUT"), + DELETE_TAG(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/rooms/{roomId}/tags/{tag}", "DELETE"), + + // SyncApi + SYNC(NetworkConstants.URI_API_PREFIX_PATH_R0 + "sync", "GET"), + + // ThirdPartyApi + THIRD_PARTY_PROTOCOLS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "thirdparty/protocols", "GET"), + THIRD_PARTY_USER(NetworkConstants.URI_API_PREFIX_PATH_R0 + "thirdparty/protocols/user/{protocol}", "GET"), + + // SearchUserApi + SEARCH_USERS(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user_directory/search", "POST"), + + // AccountDataApi + SET_ACCOUNT_DATA(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/account_data/{type}", "PUT") +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt index f4688411ff..da50709de0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt @@ -28,6 +28,7 @@ import org.matrix.android.sdk.internal.network.interceptors.CurlLoggingIntercept import org.matrix.android.sdk.internal.network.interceptors.FormattedJsonHttpLogger import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor +import org.matrix.android.sdk.api.network.ApiInterceptor import java.util.concurrent.TimeUnit @Module @@ -54,6 +55,13 @@ internal object NetworkModule { return CurlLoggingInterceptor() } + @MatrixScope + @Provides + @JvmStatic + fun providesApiInterceptor(): ApiInterceptor { + return ApiInterceptor() + } + @MatrixScope @Provides @JvmStatic @@ -63,7 +71,8 @@ internal object NetworkModule { timeoutInterceptor: TimeOutInterceptor, userAgentInterceptor: UserAgentInterceptor, httpLoggingInterceptor: HttpLoggingInterceptor, - curlLoggingInterceptor: CurlLoggingInterceptor): OkHttpClient { + curlLoggingInterceptor: CurlLoggingInterceptor, + apiInterceptor: ApiInterceptor): OkHttpClient { return OkHttpClient.Builder() .connectTimeout(30, TimeUnit.SECONDS) .readTimeout(60, TimeUnit.SECONDS) @@ -76,6 +85,7 @@ internal object NetworkModule { .addInterceptor(timeoutInterceptor) .addInterceptor(userAgentInterceptor) .addInterceptor(httpLoggingInterceptor) + .addInterceptor(apiInterceptor) .apply { if (BuildConfig.LOG_PRIVATE_DATA) { addInterceptor(curlLoggingInterceptor) From 7db1d81eb697a4602922e09800767715e9967019 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 11 Mar 2021 16:51:17 +0300 Subject: [PATCH 2/8] Changelog added. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 55c7387379..ce3281d987 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ Improvements 🙌: - Crypto improvement | Bulk send NO_OLM withheld code - Display the room shield in all room setting screens - Improve message with Emoji only detection (#3017) + - Api interceptor to allow app developers peek responses (#2986) Bugfix 🐛: - Fix bad theme change for the MainActivity From 21cff9a7493070cc68701111f878cc4bea1ac0e0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 22 Mar 2021 16:36:44 +0100 Subject: [PATCH 3/8] Update after Ganfra's review, and kotlinification --- .../java/org/matrix/android/sdk/api/Matrix.kt | 5 ++- .../sdk/api/network/ApiInterceptorListener.kt | 21 ++++++++++ .../matrix/android/sdk/api/network/ApiPath.kt | 2 +- .../android/sdk/internal/di/NetworkModule.kt | 9 +---- .../network/ApiInterceptor.kt | 40 +++++++++---------- 5 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiInterceptorListener.kt rename matrix-sdk-android/src/main/java/org/matrix/android/sdk/{api => internal}/network/ApiInterceptor.kt (66%) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt index 90bfbe3de6..8a27f364d2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt @@ -25,11 +25,12 @@ import org.matrix.android.sdk.BuildConfig import org.matrix.android.sdk.api.auth.AuthenticationService import org.matrix.android.sdk.api.auth.HomeServerHistoryService import org.matrix.android.sdk.api.legacy.LegacySessionImporter -import org.matrix.android.sdk.api.network.ApiInterceptor +import org.matrix.android.sdk.api.network.ApiInterceptorListener import org.matrix.android.sdk.api.network.ApiPath import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.internal.SessionManager import org.matrix.android.sdk.internal.di.DaggerMatrixComponent +import org.matrix.android.sdk.internal.network.ApiInterceptor import org.matrix.android.sdk.internal.network.UserAgentHolder import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver import org.matrix.olm.OlmManager @@ -76,7 +77,7 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo return legacySessionImporter } - fun registerApiInterceptorListener(path: ApiPath, listener: ApiInterceptor.Listener) { + fun registerApiInterceptorListener(path: ApiPath, listener: ApiInterceptorListener) { apiInterceptor.addListener(path, listener) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiInterceptorListener.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiInterceptorListener.kt new file mode 100644 index 0000000000..ad21da8fdf --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiInterceptorListener.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.api.network + +interface ApiInterceptorListener { + fun onApiResponse(path: ApiPath, response: String) +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiPath.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiPath.kt index 4de8d49cf4..db112a30b2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiPath.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiPath.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 New Vector Ltd + * Copyright (c) 2021 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt index da50709de0..0d0892b608 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt @@ -28,7 +28,7 @@ import org.matrix.android.sdk.internal.network.interceptors.CurlLoggingIntercept import org.matrix.android.sdk.internal.network.interceptors.FormattedJsonHttpLogger import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor -import org.matrix.android.sdk.api.network.ApiInterceptor +import org.matrix.android.sdk.internal.network.ApiInterceptor import java.util.concurrent.TimeUnit @Module @@ -55,13 +55,6 @@ internal object NetworkModule { return CurlLoggingInterceptor() } - @MatrixScope - @Provides - @JvmStatic - fun providesApiInterceptor(): ApiInterceptor { - return ApiInterceptor() - } - @MatrixScope @Provides @JvmStatic diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiInterceptor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt similarity index 66% rename from matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiInterceptor.kt rename to matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt index 2b259a9797..8b188910a1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/network/ApiInterceptor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 The Matrix.org Foundation C.I.C. + * Copyright (c) 2021 New Vector Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,29 +14,28 @@ * limitations under the License. */ -package org.matrix.android.sdk.api.network +package org.matrix.android.sdk.internal.network import okhttp3.Interceptor import okhttp3.Response +import org.matrix.android.sdk.api.extensions.tryOrNull +import org.matrix.android.sdk.api.network.ApiInterceptorListener +import org.matrix.android.sdk.api.network.ApiPath +import org.matrix.android.sdk.internal.di.MatrixScope import timber.log.Timber import javax.inject.Inject -import javax.inject.Singleton /** * Interceptor class for provided api paths. */ -@Singleton -class ApiInterceptor @Inject constructor() : Interceptor { - - interface Listener { - fun onApiResponse(path: ApiPath, response: String) - } +@MatrixScope +internal class ApiInterceptor @Inject constructor() : Interceptor { init { Timber.d("ApiInterceptor.init") } - private val apiResponseListenersMap = mutableMapOf>() + private val apiResponseListenersMap = mutableMapOf>() override fun intercept(chain: Interceptor.Chain): Response { val request = chain.request() @@ -46,9 +45,11 @@ class ApiInterceptor @Inject constructor() : Interceptor { val response = chain.proceed(request) findApiPath(path, method)?.let { apiPath -> - response.peekBody(Long.MAX_VALUE).string().let { + response.peekBody(Long.MAX_VALUE).string().let { networkResponse -> apiResponseListenersMap[apiPath]?.forEach { listener -> - listener.onApiResponse(apiPath, it) + tryOrNull("Error in the implementation") { + listener.onApiResponse(apiPath, networkResponse) + } } } } @@ -70,21 +71,16 @@ class ApiInterceptor @Inject constructor() : Interceptor { if (patternSegments.size != pathSegments.size) return false - for (i in patternSegments.indices) { - if (patternSegments[i] != pathSegments[i] && !patternSegments[i].startsWith("{")) { - return false - } + return patternSegments.indices.all { i -> + patternSegments[i] == pathSegments[i] || patternSegments[i].startsWith("{") } - return true } /** * Adds listener to send intercepted api responses through. */ - fun addListener(path: ApiPath, listener: Listener) { - if (!apiResponseListenersMap.contains(path)) { - apiResponseListenersMap[path] = mutableListOf() - } - apiResponseListenersMap[path]?.add(listener) + fun addListener(path: ApiPath, listener: ApiInterceptorListener) { + apiResponseListenersMap.getOrPut(path) { mutableListOf() } + .add(listener) } } From f6e43a5305b9b2476025d136400d94a1e9d4a7cc Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 22 Mar 2021 17:13:16 +0100 Subject: [PATCH 4/8] Add Android test on ApiInterceptor --- matrix-sdk-android/build.gradle | 1 - .../java/org/matrix/android/sdk/api/Matrix.kt | 8 +++ .../sdk/api/network/ApiInterceptorTest.kt | 53 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 5ca5ce1e05..7fb626ab46 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -185,7 +185,6 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'org.amshove.kluent:kluent-android:1.61' - // Note: version sticks to 1.9.2 due to https://github.com/mockk/mockk/issues/281 androidTestImplementation 'io.mockk:mockk-android:1.11.0' androidTestImplementation "androidx.arch.core:core-testing:$arch_version" androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version" diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/Matrix.kt index 03943cea14..11251b8a5d 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/Matrix.kt @@ -27,9 +27,12 @@ import org.matrix.android.sdk.BuildConfig import org.matrix.android.sdk.api.auth.AuthenticationService import org.matrix.android.sdk.api.auth.HomeServerHistoryService import org.matrix.android.sdk.api.legacy.LegacySessionImporter +import org.matrix.android.sdk.api.network.ApiInterceptorListener +import org.matrix.android.sdk.api.network.ApiPath import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.common.DaggerTestMatrixComponent import org.matrix.android.sdk.internal.SessionManager +import org.matrix.android.sdk.internal.network.ApiInterceptor import org.matrix.android.sdk.internal.network.UserAgentHolder import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver import org.matrix.olm.OlmManager @@ -51,6 +54,7 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo @Inject internal lateinit var olmManager: OlmManager @Inject internal lateinit var sessionManager: SessionManager @Inject internal lateinit var homeServerHistoryService: HomeServerHistoryService + @Inject internal lateinit var apiInterceptor: ApiInterceptor private val uiHandler = Handler(Looper.getMainLooper()) @@ -79,6 +83,10 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo return legacySessionImporter } + fun registerApiInterceptorListener(path: ApiPath, listener: ApiInterceptorListener) { + apiInterceptor.addListener(path, listener) + } + companion object { private lateinit var instance: Matrix diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt new file mode 100644 index 0000000000..93fdccfd48 --- /dev/null +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.api.network + +import org.amshove.kluent.shouldBeEqualTo +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.runners.MethodSorters +import org.matrix.android.sdk.InstrumentedTest +import org.matrix.android.sdk.common.CommonTestHelper +import org.matrix.android.sdk.common.SessionTestParams +import org.matrix.android.sdk.common.TestConstants +import timber.log.Timber + +@RunWith(JUnit4::class) +@FixMethodOrder(MethodSorters.JVM) +class ApiInterceptorTest : InstrumentedTest { + + private val commonTestHelper = CommonTestHelper(context()) + + @Test + fun createAccountTest() { + var counter = 0 + commonTestHelper.matrix.registerApiInterceptorListener(ApiPath.REGISTER, object : ApiInterceptorListener { + override fun onApiResponse(path: ApiPath, response: String) { + Timber.w("onApiResponse($path): $response") + counter++ + } + }) + + val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true)) + + commonTestHelper.signOutAndClose(session) + + counter shouldBeEqualTo 2 + } +} From d85d44bf4b2f44c05b21f827686ed10da61f1d63 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 22 Mar 2021 18:09:42 +0100 Subject: [PATCH 5/8] Add ApiInterceptor.removeListener() --- .../org/matrix/android/sdk/InstrumentedTest.kt | 5 ----- .../java/org/matrix/android/sdk/api/Matrix.kt | 4 ++++ .../sdk/api/network/ApiInterceptorTest.kt | 17 +++++++++++------ .../java/org/matrix/android/sdk/api/Matrix.kt | 4 ++++ .../sdk/internal/network/ApiInterceptor.kt | 18 ++++++++++++++++-- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/InstrumentedTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/InstrumentedTest.kt index b784884363..583406346e 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/InstrumentedTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/InstrumentedTest.kt @@ -20,7 +20,6 @@ import android.content.Context import androidx.test.core.app.ApplicationProvider import org.matrix.android.sdk.test.shared.createTimberTestRule import org.junit.Rule -import java.io.File interface InstrumentedTest { @@ -30,8 +29,4 @@ interface InstrumentedTest { fun context(): Context { return ApplicationProvider.getApplicationContext() } - - fun cacheDir(): File { - return context().cacheDir - } } diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/Matrix.kt index 11251b8a5d..c439da8407 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/Matrix.kt @@ -87,6 +87,10 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo apiInterceptor.addListener(path, listener) } + fun unregisterApiInterceptorListener(path: ApiPath, listener: ApiInterceptorListener) { + apiInterceptor.removeListener(path, listener) + } + companion object { private lateinit var instance: Matrix diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt index 93fdccfd48..149acbc18a 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt @@ -35,19 +35,24 @@ class ApiInterceptorTest : InstrumentedTest { private val commonTestHelper = CommonTestHelper(context()) @Test - fun createAccountTest() { - var counter = 0 - commonTestHelper.matrix.registerApiInterceptorListener(ApiPath.REGISTER, object : ApiInterceptorListener { + fun apiInterceptorTest() { + val responses = mutableListOf() + + val listener = object : ApiInterceptorListener { override fun onApiResponse(path: ApiPath, response: String) { Timber.w("onApiResponse($path): $response") - counter++ + responses.add(response) } - }) + } + + commonTestHelper.matrix.registerApiInterceptorListener(ApiPath.REGISTER, listener) val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true)) commonTestHelper.signOutAndClose(session) - counter shouldBeEqualTo 2 + commonTestHelper.matrix.unregisterApiInterceptorListener(ApiPath.REGISTER, listener) + + responses.size shouldBeEqualTo 2 } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt index 8a27f364d2..9980259266 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt @@ -81,6 +81,10 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo apiInterceptor.addListener(path, listener) } + fun unregisterApiInterceptorListener(path: ApiPath, listener: ApiInterceptorListener) { + apiInterceptor.removeListener(path, listener) + } + companion object { private lateinit var instance: Matrix diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt index 8b188910a1..5d73264d11 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt @@ -80,7 +80,21 @@ internal class ApiInterceptor @Inject constructor() : Interceptor { * Adds listener to send intercepted api responses through. */ fun addListener(path: ApiPath, listener: ApiInterceptorListener) { - apiResponseListenersMap.getOrPut(path) { mutableListOf() } - .add(listener) + synchronized(apiResponseListenersMap) { + apiResponseListenersMap.getOrPut(path) { mutableListOf() } + .add(listener) + } + } + + /** + * Remove listener to send intercepted api responses through. + */ + fun removeListener(path: ApiPath, listener: ApiInterceptorListener) { + synchronized(apiResponseListenersMap) { + apiResponseListenersMap[path]?.remove(listener) + if (apiResponseListenersMap[path]?.isEmpty() == true) { + apiResponseListenersMap.remove(path) + } + } } } From f106176752e54d806b6abdcf18f9346c61f982f0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 22 Mar 2021 18:26:29 +0100 Subject: [PATCH 6/8] Add missing synchronized --- .../android/sdk/internal/network/ApiInterceptor.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt index 5d73264d11..afd3347283 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt @@ -44,11 +44,13 @@ internal class ApiInterceptor @Inject constructor() : Interceptor { val response = chain.proceed(request) - findApiPath(path, method)?.let { apiPath -> - response.peekBody(Long.MAX_VALUE).string().let { networkResponse -> - apiResponseListenersMap[apiPath]?.forEach { listener -> - tryOrNull("Error in the implementation") { - listener.onApiResponse(apiPath, networkResponse) + synchronized(apiResponseListenersMap) { + findApiPath(path, method)?.let { apiPath -> + response.peekBody(Long.MAX_VALUE).string().let { networkResponse -> + apiResponseListenersMap[apiPath]?.forEach { listener -> + tryOrNull("Error in the implementation") { + listener.onApiResponse(apiPath, networkResponse) + } } } } From 5cd86c685d42d8311a5409483085d5d45d321a4d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 22 Mar 2021 18:29:06 +0100 Subject: [PATCH 7/8] Copyright --- .../org/matrix/android/sdk/api/network/ApiInterceptorTest.kt | 2 +- .../org/matrix/android/sdk/internal/network/ApiInterceptor.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt index 149acbc18a..9371154aaf 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/network/ApiInterceptorTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 New Vector Ltd + * Copyright (c) 2021 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt index afd3347283..1dd6e75ea5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ApiInterceptor.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 New Vector Ltd + * Copyright (c) 2021 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 274aef8f248f3079934de1d52e74b3f4c2b54000 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 22 Mar 2021 19:15:06 +0100 Subject: [PATCH 8/8] Code qual --- tools/check/forbidden_strings_in_code.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/check/forbidden_strings_in_code.txt b/tools/check/forbidden_strings_in_code.txt index 468fe717c0..7b7c44b9fd 100644 --- a/tools/check/forbidden_strings_in_code.txt +++ b/tools/check/forbidden_strings_in_code.txt @@ -161,7 +161,7 @@ Formatter\.formatShortFileSize===1 # android\.text\.TextUtils ### This is not a rule, but a warning: the number of "enum class" has changed. For Json classes, it is mandatory that they have `@JsonClass(generateAdapter = false)`. If the enum is not used as a Json class, change the value in file forbidden_strings_in_code.txt -enum class===92 +enum class===93 ### Do not import temporary legacy classes import org.matrix.android.sdk.internal.legacy.riot===3