From 952a2566bdbb8e85d4517d7a436fafc60a3c0898 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 30 Jul 2019 12:49:28 +0200 Subject: [PATCH 1/4] make Widget/Integration mgr optional (#3224) --- CHANGES.rst | 2 +- vector/src/main/java/im/vector/Matrix.java | 7 +- .../vector/activity/AbstractWidgetActivity.kt | 11 +- .../activity/IntegrationManagerActivity.kt | 4 +- .../im/vector/activity/JitsiCallActivity.java | 11 +- .../vector/activity/StickerPickerActivity.kt | 2 +- .../vector/activity/VectorRoomActivity.java | 161 ++++++++++-------- .../java/im/vector/activity/WidgetActivity.kt | 22 ++- .../VectorSettingsPreferencesFragment.kt | 3 + .../im/vector/util/PreferencesManager.java | 26 +++ .../im/vector/util/SlashCommandsParser.java | 9 +- .../im/vector/view/ActiveWidgetsBanner.java | 20 ++- .../view/VectorOngoingConferenceCallView.java | 22 ++- .../widgets/IntegrationManagerConfig.kt | 29 ++++ .../vector/widgets/WidgetManagerProvider.kt | 52 ++++++ .../im/vector/widgets/WidgetsManager.java | 49 +++--- .../im/vector/widgets/WidgetsRestClient.java | 16 +- vector/src/main/res/values/config.xml | 3 +- vector/src/main/res/values/strings.xml | 1 + .../res/xml/vector_settings_preferences.xml | 6 + 20 files changed, 314 insertions(+), 142 deletions(-) create mode 100644 vector/src/main/java/im/vector/widgets/IntegrationManagerConfig.kt create mode 100644 vector/src/main/java/im/vector/widgets/WidgetManagerProvider.kt diff --git a/CHANGES.rst b/CHANGES.rst index 4f54328409..491961ec47 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,7 +6,7 @@ MatrixSdk: - Changelog: https://github.com/matrix-org/matrix-android-sdk/releases/tag/v0.XX Features: - - + - Make Widget/Integration Manager optional (#3224) Improvements: - diff --git a/vector/src/main/java/im/vector/Matrix.java b/vector/src/main/java/im/vector/Matrix.java index aef22781b0..220d3cca82 100755 --- a/vector/src/main/java/im/vector/Matrix.java +++ b/vector/src/main/java/im/vector/Matrix.java @@ -2,6 +2,7 @@ * Copyright 2016 OpenMarket Ltd * Copyright 2017 Vector Creations Ltd * Copyright 2018 New Vector Ltd + * Copyright 2019 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. @@ -74,6 +75,7 @@ import im.vector.tools.VectorUncaughtExceptionHandler; import im.vector.ui.badge.BadgeProxy; import im.vector.util.PreferencesManager; +import im.vector.widgets.WidgetManagerProvider; import im.vector.widgets.WidgetsManager; /** @@ -131,7 +133,10 @@ public void onLiveEvent(Event event, RoomState roomState) { mRefreshUnreadCounter |= Event.EVENT_TYPE_MESSAGE.equals(event.getType()) || Event.EVENT_TYPE_RECEIPT.equals(event.getType()); // TODO update to manage multisessions - WidgetsManager.getSharedInstance().onLiveEvent(instance.getDefaultSession(), event); + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(VectorApp.getInstance().getApplicationContext()); + if (wm != null) { + wm.onLiveEvent(instance.getDefaultSession(), event); + } } @Override diff --git a/vector/src/main/java/im/vector/activity/AbstractWidgetActivity.kt b/vector/src/main/java/im/vector/activity/AbstractWidgetActivity.kt index 626551c0f3..81a18139b5 100755 --- a/vector/src/main/java/im/vector/activity/AbstractWidgetActivity.kt +++ b/vector/src/main/java/im/vector/activity/AbstractWidgetActivity.kt @@ -34,6 +34,7 @@ import im.vector.types.JsonDict import im.vector.types.WidgetEventData import im.vector.util.AssetReader import im.vector.util.toJsonMap +import im.vector.widgets.WidgetManagerProvider import im.vector.widgets.WidgetsManager import org.matrix.androidsdk.MXSession import org.matrix.androidsdk.core.JsonUtils @@ -76,6 +77,7 @@ abstract class AbstractWidgetActivity : VectorAppCompatActivity() { private var mHistoryAlreadyCleared = false + lateinit var widgetManager : WidgetsManager /* ========================================================================================== * LIFE CYCLE * ========================================================================================== */ @@ -94,6 +96,11 @@ abstract class AbstractWidgetActivity : VectorAppCompatActivity() { mRoom = mSession!!.dataHandler.getRoom(intent.getStringExtra(EXTRA_ROOM_ID)) + widgetManager = WidgetManagerProvider.getWidgetManager(this) ?: run { + finish() + return + } + getScalarTokenAndLoadUrl() } @@ -101,7 +108,7 @@ abstract class AbstractWidgetActivity : VectorAppCompatActivity() { if (canScalarTokenBeProvided()) { showWaitingView() - WidgetsManager.getScalarToken(this, mSession!!, object : ApiCallback { + widgetManager.getScalarToken(this, mSession!!, object : ApiCallback { override fun onSuccess(scalarToken: String) { mIsRefreshingToken = false hideWaitingView() @@ -205,7 +212,7 @@ abstract class AbstractWidgetActivity : VectorAppCompatActivity() { && !mTokenAlreadyRefreshed) { mTokenAlreadyRefreshed = true mIsRefreshingToken = true - WidgetsManager.clearScalarToken(this@AbstractWidgetActivity, mSession) + widgetManager.clearScalarToken(this@AbstractWidgetActivity, mSession) // Hide the webview because it's displaying an error message we try to fix by refreshing the token mWebView.isVisible = false diff --git a/vector/src/main/java/im/vector/activity/IntegrationManagerActivity.kt b/vector/src/main/java/im/vector/activity/IntegrationManagerActivity.kt index e3c207839d..3cc80fcefb 100755 --- a/vector/src/main/java/im/vector/activity/IntegrationManagerActivity.kt +++ b/vector/src/main/java/im/vector/activity/IntegrationManagerActivity.kt @@ -74,7 +74,7 @@ class IntegrationManagerActivity : AbstractWidgetActivity() { */ override fun buildInterfaceUrl(scalarToken: String?): String? { try { - return StringBuilder(getString(R.string.integrations_ui_url)) + return StringBuilder(widgetManager.uiUrl) .apply { scalarToken?.let { appendParamToUrl("scalar_token", it) @@ -259,7 +259,7 @@ class IntegrationManagerActivity : AbstractWidgetActivity() { Log.d(LOG_TAG, "Received request to get widget in room " + mRoom!!.roomId) - val widgets = WidgetsManager.getSharedInstance().getActiveWidgets(mSession, mRoom) + val widgets = widgetManager.getActiveWidgets(mSession, mRoom) val responseData = ArrayList>() for (widget in widgets) { diff --git a/vector/src/main/java/im/vector/activity/JitsiCallActivity.java b/vector/src/main/java/im/vector/activity/JitsiCallActivity.java index 4dbcf230b2..0545c71ede 100755 --- a/vector/src/main/java/im/vector/activity/JitsiCallActivity.java +++ b/vector/src/main/java/im/vector/activity/JitsiCallActivity.java @@ -42,6 +42,7 @@ import im.vector.Matrix; import im.vector.R; import im.vector.widgets.Widget; +import im.vector.widgets.WidgetManagerProvider; import im.vector.widgets.WidgetsManager; /** @@ -232,7 +233,10 @@ public void onNewIntent(Intent intent) { protected void onStop() { super.onStop(); JitsiMeetActivityDelegate.onHostPause(this); - WidgetsManager.removeListener(mWidgetListener); + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(this); + if (wm != null) { + wm.removeListener(mWidgetListener); + } } @Override @@ -245,7 +249,10 @@ protected void onResume() { super.onResume(); JitsiMeetActivityDelegate.onHostResume(this); - WidgetsManager.addListener(mWidgetListener); + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(this); + if (wm != null) { + wm.addListener(mWidgetListener); + } } @Override diff --git a/vector/src/main/java/im/vector/activity/StickerPickerActivity.kt b/vector/src/main/java/im/vector/activity/StickerPickerActivity.kt index e368fe036e..a1ed6c3237 100755 --- a/vector/src/main/java/im/vector/activity/StickerPickerActivity.kt +++ b/vector/src/main/java/im/vector/activity/StickerPickerActivity.kt @@ -55,7 +55,7 @@ class StickerPickerActivity : AbstractWidgetActivity() { } override fun canScalarTokenBeProvided(): Boolean { - return WidgetsManager.isScalarUrl(this, mWidgetUrl) + return widgetManager.isScalarUrl(this, mWidgetUrl) } /** diff --git a/vector/src/main/java/im/vector/activity/VectorRoomActivity.java b/vector/src/main/java/im/vector/activity/VectorRoomActivity.java index 6cb0d60c07..82454b941b 100755 --- a/vector/src/main/java/im/vector/activity/VectorRoomActivity.java +++ b/vector/src/main/java/im/vector/activity/VectorRoomActivity.java @@ -2,6 +2,7 @@ * Copyright 2015 OpenMarket Ltd * Copyright 2017 Vector Creations Ltd * Copyright 2018 New Vector Ltd + * Copyright 2019 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. @@ -134,6 +135,7 @@ import im.vector.view.VectorOngoingConferenceCallView; import im.vector.view.VectorPendingCallView; import im.vector.widgets.Widget; +import im.vector.widgets.WidgetManagerProvider; import im.vector.widgets.WidgetsManager; /** @@ -860,34 +862,37 @@ public void onCloseWidgetClick(final Widget widget) { .setPositiveButton(R.string.remove, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - showWaitingView(); + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(VectorRoomActivity.this); + if (wm != null) { + showWaitingView(); - WidgetsManager.getSharedInstance().closeWidget(mSession, mRoom, widget.getWidgetId(), new ApiCallback() { - @Override - public void onSuccess(Void info) { - hideWaitingView(); - } + wm.closeWidget(mSession, mRoom, widget.getWidgetId(), new ApiCallback() { + @Override + public void onSuccess(Void info) { + hideWaitingView(); + } - private void onError(String errorMessage) { - hideWaitingView(); - Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show(); - } + private void onError(String errorMessage) { + hideWaitingView(); + Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show(); + } - @Override - public void onNetworkError(Exception e) { - onError(e.getLocalizedMessage()); - } + @Override + public void onNetworkError(Exception e) { + onError(e.getLocalizedMessage()); + } - @Override - public void onMatrixError(MatrixError e) { - onError(e.getLocalizedMessage()); - } + @Override + public void onMatrixError(MatrixError e) { + onError(e.getLocalizedMessage()); + } - @Override - public void onUnexpectedError(Exception e) { - onError(e.getLocalizedMessage()); - } - }); + @Override + public void onUnexpectedError(Exception e) { + onError(e.getLocalizedMessage()); + } + }); + } } }) .setNegativeButton(R.string.cancel, null) @@ -962,34 +967,37 @@ public void onVideoCallClick(Widget widget) { @Override public void onCloseWidgetClick(Widget widget) { - showWaitingView(); + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(VectorRoomActivity.this); + if (wm != null) { + showWaitingView(); - WidgetsManager.getSharedInstance().closeWidget(mSession, mRoom, widget.getWidgetId(), new ApiCallback() { - @Override - public void onSuccess(Void info) { - hideWaitingView(); - } + wm.closeWidget(mSession, mRoom, widget.getWidgetId(), new ApiCallback() { + @Override + public void onSuccess(Void info) { + hideWaitingView(); + } - private void onError(String errorMessage) { - hideWaitingView(); - Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show(); - } + private void onError(String errorMessage) { + hideWaitingView(); + Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show(); + } - @Override - public void onNetworkError(Exception e) { - onError(e.getLocalizedMessage()); - } + @Override + public void onNetworkError(Exception e) { + onError(e.getLocalizedMessage()); + } - @Override - public void onMatrixError(MatrixError e) { - onError(e.getLocalizedMessage()); - } + @Override + public void onMatrixError(MatrixError e) { + onError(e.getLocalizedMessage()); + } - @Override - public void onUnexpectedError(Exception e) { - onError(e.getLocalizedMessage()); - } - }); + @Override + public void onUnexpectedError(Exception e) { + onError(e.getLocalizedMessage()); + } + }); + } } @Override @@ -1483,6 +1491,8 @@ public boolean onPrepareOptionsMenu(Menu menu) { return true; } + boolean hasIntegrationManager = WidgetManagerProvider.INSTANCE.getWidgetManager(this) != null; + // the menu is only displayed when the current activity does not display a timeline search if (TextUtils.isEmpty(mEventId) && (null == sRoomPreviewData)) { RoomMember member = mRoom.getMember(mSession.getMyUserId()); @@ -1492,7 +1502,7 @@ public boolean onPrepareOptionsMenu(Menu menu) { searchInRoomMenuItem.setVisible(!mRoom.isEncrypted()); } if (useMatrixAppsMenuItem != null) { - useMatrixAppsMenuItem.setVisible(TextUtils.isEmpty(mEventId) && null == sRoomPreviewData); + useMatrixAppsMenuItem.setVisible(hasIntegrationManager && TextUtils.isEmpty(mEventId) && null == sRoomPreviewData); } if (resendUnsentMenuItem != null) { resendUnsentMenuItem.setVisible(mHasUnsentEvents); @@ -1761,37 +1771,40 @@ private void launchJitsiActivity(Widget widget, boolean aIsVideoCall) { * @param aIsVideoCall true if the call is a video one */ private void startJitsiCall(final boolean aIsVideoCall) { - enableActionBarHeader(HIDE_ACTION_BAR_HEADER); - showWaitingView(); + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(this); + if (wm != null) { + enableActionBarHeader(HIDE_ACTION_BAR_HEADER); + showWaitingView(); - WidgetsManager.getSharedInstance().createJitsiWidget(mSession, mRoom, aIsVideoCall, new ApiCallback() { - @Override - public void onSuccess(Widget widget) { - hideWaitingView(); + wm.createJitsiWidget(mSession, mRoom, aIsVideoCall, new ApiCallback() { + @Override + public void onSuccess(Widget widget) { + hideWaitingView(); - launchJitsiActivity(widget, aIsVideoCall); - } + launchJitsiActivity(widget, aIsVideoCall); + } - private void onError(String errorMessage) { - hideWaitingView(); - Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show(); - } + private void onError(String errorMessage) { + hideWaitingView(); + Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show(); + } - @Override - public void onNetworkError(Exception e) { - onError(e.getLocalizedMessage()); - } + @Override + public void onNetworkError(Exception e) { + onError(e.getLocalizedMessage()); + } - @Override - public void onMatrixError(MatrixError e) { - onError(e.getLocalizedMessage()); - } + @Override + public void onMatrixError(MatrixError e) { + onError(e.getLocalizedMessage()); + } - @Override - public void onUnexpectedError(Exception e) { - onError(e.getLocalizedMessage()); - } - }); + @Override + public void onUnexpectedError(Exception e) { + onError(e.getLocalizedMessage()); + } + }); + } } /** @@ -3842,7 +3855,9 @@ private void chooseMediaSource(boolean useNativeCamera, boolean isVoiceFeatureEn } // Send sticker - items.add(DialogListItem.SendSticker.INSTANCE); + if (WidgetManagerProvider.INSTANCE.getWidgetManager(this) != null) { + items.add(DialogListItem.SendSticker.INSTANCE); + } // Camera if (useNativeCamera) { diff --git a/vector/src/main/java/im/vector/activity/WidgetActivity.kt b/vector/src/main/java/im/vector/activity/WidgetActivity.kt index 3ec44c23dc..ca9d536108 100755 --- a/vector/src/main/java/im/vector/activity/WidgetActivity.kt +++ b/vector/src/main/java/im/vector/activity/WidgetActivity.kt @@ -38,6 +38,7 @@ import butterknife.OnClick import im.vector.Matrix import im.vector.R import im.vector.widgets.Widget +import im.vector.widgets.WidgetManagerProvider import im.vector.widgets.WidgetsManager import org.matrix.androidsdk.MXSession import org.matrix.androidsdk.core.Log @@ -73,6 +74,7 @@ class WidgetActivity : VectorAppCompatActivity() { private var mTokenAlreadyRefreshed = false private var mHistoryAlreadyCleared = false + private lateinit var widgetsManager: WidgetsManager /** * Widget events listener */ @@ -102,6 +104,12 @@ class WidgetActivity : VectorAppCompatActivity() { return } + widgetsManager = WidgetManagerProvider.getWidgetManager(this) ?: run { + Log.e(LOG_TAG, "## onCreate() : No widget manager ") + finish() + return + } + mSession = Matrix.getMXSession(this, mWidget!!.sessionId) if (null == mSession) { @@ -138,7 +146,7 @@ class WidgetActivity : VectorAppCompatActivity() { override fun onResume() { super.onResume() - WidgetsManager.addListener(mWidgetListener) + widgetsManager.addListener(mWidgetListener) mWidgetWebView.let { it.resumeTimers() @@ -156,7 +164,7 @@ class WidgetActivity : VectorAppCompatActivity() { it.onPause() } - WidgetsManager.removeListener(mWidgetListener) + widgetsManager.removeListener(mWidgetListener) } /* ========================================================================================== @@ -169,7 +177,7 @@ class WidgetActivity : VectorAppCompatActivity() { .setMessage(R.string.widget_delete_message_confirmation) .setPositiveButton(R.string.remove) { _, _ -> showWaitingView() - WidgetsManager.getSharedInstance().closeWidget(mSession, mRoom, mWidget!!.widgetId, object : ApiCallback { + widgetsManager.closeWidget(mSession, mRoom, mWidget!!.widgetId, object : ApiCallback { override fun onSuccess(info: Void?) { hideWaitingView() finish() @@ -214,7 +222,7 @@ class WidgetActivity : VectorAppCompatActivity() { * Refresh the status bar */ private fun refreshStatusBar() { - val canCloseWidget = null == WidgetsManager.getSharedInstance().checkWidgetPermission(mSession, mRoom) + val canCloseWidget = null == widgetsManager.checkWidgetPermission(mSession, mRoom) // close widget button mCloseWidgetIcon.isInvisible = !canCloseWidget @@ -273,14 +281,14 @@ class WidgetActivity : VectorAppCompatActivity() { // In case of 403, try to refresh the scalar token if (errorResponse?.statusCode == HttpsURLConnection.HTTP_FORBIDDEN && !mTokenAlreadyRefreshed - && WidgetsManager.isScalarUrl(this@WidgetActivity, mWidget!!.url)) { + && widgetsManager.isScalarUrl(this@WidgetActivity, mWidget!!.url)) { mTokenAlreadyRefreshed = true mIsRefreshingToken = true // Hide the webview because it's displaying an error message we try to fix by refreshing the token mWidgetWebView.isVisible = false - WidgetsManager.clearScalarToken(this@WidgetActivity, mSession) + widgetsManager.clearScalarToken(this@WidgetActivity, mSession) loadUrl() } } @@ -320,7 +328,7 @@ class WidgetActivity : VectorAppCompatActivity() { private fun loadUrl() { showWaitingView() - WidgetsManager.getFormattedWidgetUrl(this, mWidget!!, object : ApiCallback { + widgetsManager.getFormattedWidgetUrl(this, mWidget!!, object : ApiCallback { override fun onSuccess(url: String) { mIsRefreshingToken = false diff --git a/vector/src/main/java/im/vector/fragments/VectorSettingsPreferencesFragment.kt b/vector/src/main/java/im/vector/fragments/VectorSettingsPreferencesFragment.kt index 497e573416..5e022d7c97 100755 --- a/vector/src/main/java/im/vector/fragments/VectorSettingsPreferencesFragment.kt +++ b/vector/src/main/java/im/vector/fragments/VectorSettingsPreferencesFragment.kt @@ -645,6 +645,9 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref findPreference(PreferencesManager.SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY) .summary = mSession.homeServerConfig.identityServerUri.toString() + findPreference(PreferencesManager.SETTINGS_INTEGRATION_SERVER_URL) + .summary = PreferencesManager.getIntegrationServerUrl(context) + // Analytics // Analytics tracking management diff --git a/vector/src/main/java/im/vector/util/PreferencesManager.java b/vector/src/main/java/im/vector/util/PreferencesManager.java index 4a3be949ea..9b9a65e4be 100755 --- a/vector/src/main/java/im/vector/util/PreferencesManager.java +++ b/vector/src/main/java/im/vector/util/PreferencesManager.java @@ -2,6 +2,7 @@ * Copyright 2016 OpenMarket Ltd * Copyright 2017 Vector Creations Ltd * Copyright 2018 New Vector Ltd + * Copyright 2019 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. @@ -30,6 +31,7 @@ import org.matrix.androidsdk.core.Log; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -161,6 +163,10 @@ public class PreferencesManager { public static final String SETTINGS_USE_ANALYTICS_KEY = "SETTINGS_USE_ANALYTICS_KEY"; public static final String SETTINGS_USE_RAGE_SHAKE_KEY = "SETTINGS_USE_RAGE_SHAKE_KEY"; + //Integrations + public static final String SETTINGS_INTEGRATION_SERVER_URL = "SETTINGS_INTEGRATION_SERVER_URL"; + public static final String SETTINGS_INTEGRATION_WHITELIST_URL = "SETTINGS_INTEGRATION_WHITELIST_URL"; + // other public static final String SETTINGS_MEDIA_SAVING_PERIOD_KEY = "SETTINGS_MEDIA_SAVING_PERIOD_KEY"; private static final String SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY = "SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY"; @@ -266,9 +272,29 @@ public static void setDidAskUserToIgnoreBatteryOptimizations(Context context) { .apply(); } + public static String getIntegrationServerUrl(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_INTEGRATION_SERVER_URL, + context.getString(R.string.integration_server_url)); + } + + public static void setIntegrationServerUrl(Context context, String url) { + PreferenceManager.getDefaultSharedPreferences(context) + .edit() + .putString(SETTINGS_INTEGRATION_SERVER_URL, url) + .apply(); + } + + public static List getIntegrationWhiteListedUrl(Context context) { + Set defaultSet = new HashSet<>(Arrays.asList(context.getResources().getStringArray(R.array.integrations_widgets_urls))); + Set set = PreferenceManager.getDefaultSharedPreferences(context).getStringSet(SETTINGS_INTEGRATION_WHITELIST_URL, defaultSet); + return new ArrayList<>(set); + } + + public static boolean didMigrateToNotificationRework(Context context) { return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(DID_MIGRATE_TO_NOTIFICATION_REWORK, false); } + public static void setDidMigrateToNotificationRework(Context context) { PreferenceManager.getDefaultSharedPreferences(context) .edit() diff --git a/vector/src/main/java/im/vector/util/SlashCommandsParser.java b/vector/src/main/java/im/vector/util/SlashCommandsParser.java index e216dc7b1c..ff9b6e2af8 100755 --- a/vector/src/main/java/im/vector/util/SlashCommandsParser.java +++ b/vector/src/main/java/im/vector/util/SlashCommandsParser.java @@ -1,6 +1,7 @@ /* * Copyright 2016 OpenMarket Ltd * Copyright 2018 New Vector Ltd + * Copyright 2019 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. @@ -39,6 +40,7 @@ import im.vector.VectorApp; import im.vector.activity.CommonActivityUtils; import im.vector.activity.VectorRoomActivity; +import im.vector.widgets.WidgetManagerProvider; import im.vector.widgets.WidgetsManager; public class SlashCommandsParser { @@ -340,9 +342,12 @@ public void onMatrixError(final MatrixError e) { isIRCCmd = true; isIRCCmdValid = true; - WidgetsManager.clearScalarToken(activity, session); + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(activity); + if (wm != null) { + wm.clearScalarToken(activity, session); + Toast.makeText(activity, "Scalar token cleared", Toast.LENGTH_SHORT).show(); + } - Toast.makeText(activity, "Scalar token cleared", Toast.LENGTH_SHORT).show(); } if (!isIRCCmd) { diff --git a/vector/src/main/java/im/vector/view/ActiveWidgetsBanner.java b/vector/src/main/java/im/vector/view/ActiveWidgetsBanner.java index 63250fb4b9..f833a2d3df 100755 --- a/vector/src/main/java/im/vector/view/ActiveWidgetsBanner.java +++ b/vector/src/main/java/im/vector/view/ActiveWidgetsBanner.java @@ -1,6 +1,7 @@ /* * Copyright 2016 OpenMarket Ltd * Copyright 2018 New Vector Ltd + * Copyright 2019 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. @@ -32,6 +33,7 @@ import im.vector.R; import im.vector.widgets.Widget; +import im.vector.widgets.WidgetManagerProvider; import im.vector.widgets.WidgetsManager; /** @@ -166,8 +168,12 @@ public void setOnUpdateListener(onUpdateListener listener) { * Refresh the view visibility */ private void refresh() { + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(getContext()); + if (wm == null) { + return; + } if ((null != mRoom) && (null != mSession)) { - List activeWidgets = WidgetsManager.getSharedInstance().getActiveWebviewWidgets(mSession, mRoom); + List activeWidgets = wm.getActiveWebviewWidgets(mSession, mRoom); Widget firstWidget = null; if ((activeWidgets.size() != mActiveWidgets.size()) || !mActiveWidgets.containsAll(activeWidgets)) { @@ -193,7 +199,7 @@ private void refresh() { setVisibility((mActiveWidgets.size() > 0) ? View.VISIBLE : View.GONE); // show the close widget button if the user is allowed to do it - mCloseWidgetIcon.setVisibility(((null != firstWidget) && (null == WidgetsManager.getSharedInstance().checkWidgetPermission(mSession, mRoom))) ? + mCloseWidgetIcon.setVisibility(((null != firstWidget) && (null == wm.checkWidgetPermission(mSession, mRoom))) ? View.VISIBLE : View.GONE); } } @@ -203,13 +209,19 @@ private void refresh() { */ public void onActivityResume() { refresh(); - WidgetsManager.getSharedInstance().addListener(mWidgetListener); + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(getContext()); + if (wm != null) { + wm.addListener(mWidgetListener); + } } /** * The parent activity is suspended */ public void onActivityPause() { - WidgetsManager.getSharedInstance().removeListener(mWidgetListener); + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(getContext()); + if (wm != null) { + wm.removeListener(mWidgetListener); + } } } diff --git a/vector/src/main/java/im/vector/view/VectorOngoingConferenceCallView.java b/vector/src/main/java/im/vector/view/VectorOngoingConferenceCallView.java index 615fbad335..517b52e3c0 100755 --- a/vector/src/main/java/im/vector/view/VectorOngoingConferenceCallView.java +++ b/vector/src/main/java/im/vector/view/VectorOngoingConferenceCallView.java @@ -1,6 +1,7 @@ /* * Copyright 2016 OpenMarket Ltd * Copyright 2018 New Vector Ltd + * Copyright 2019 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. @@ -45,6 +46,7 @@ import butterknife.OnClick; import im.vector.R; import im.vector.widgets.Widget; +import im.vector.widgets.WidgetManagerProvider; import im.vector.widgets.WidgetsManager; /** @@ -239,8 +241,12 @@ public void setCallClickListener(ICallClickListener callClickListener) { * Refresh the view visibility */ public void refresh() { + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(getContext()); + if (wm == null) { + return; + } if ((null != mRoom) && (null != mSession)) { - List mActiveWidgets = WidgetsManager.getSharedInstance().getActiveJitsiWidgets(mSession, mRoom); + List mActiveWidgets = wm.getActiveJitsiWidgets(mSession, mRoom); Widget widget = mActiveWidgets.isEmpty() ? null : mActiveWidgets.get(0); if (mActiveWidget != widget) { @@ -258,7 +264,7 @@ public void refresh() { setVisibility(((!MXCallsManager.isCallInProgress(call) && mRoom.isOngoingConferenceCall()) || (null != mActiveWidget)) ? View.VISIBLE : View.GONE); // show the close widget button if the user is allowed to do it - mCloseWidgetIcon.setVisibility(((null != mActiveWidget) && (null == WidgetsManager.getSharedInstance().checkWidgetPermission(mSession, mRoom))) ? + mCloseWidgetIcon.setVisibility(((null != mActiveWidget) && (null == wm.checkWidgetPermission(mSession, mRoom))) ? View.VISIBLE : View.GONE); } } @@ -272,8 +278,10 @@ public void onActivityResume() { if (null != mSession) { mSession.mCallsManager.addListener(mCallsListener); } - - WidgetsManager.addListener(mWidgetListener); + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(getContext()); + if (wm != null) { + wm.addListener(mWidgetListener); + } } /** @@ -283,8 +291,10 @@ public void onActivityPause() { if (null != mSession) { mSession.mCallsManager.removeListener(mCallsListener); } - - WidgetsManager.removeListener(mWidgetListener); + WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(getContext()); + if (wm != null) { + wm.removeListener(mWidgetListener); + } } /** diff --git a/vector/src/main/java/im/vector/widgets/IntegrationManagerConfig.kt b/vector/src/main/java/im/vector/widgets/IntegrationManagerConfig.kt new file mode 100644 index 0000000000..8ac9790702 --- /dev/null +++ b/vector/src/main/java/im/vector/widgets/IntegrationManagerConfig.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2019 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 im.vector.widgets + +/** + * Configuration for an integration manager. + * By default, it uses URLs defined in the app settings but they can be overidden. + */ +data class IntegrationManagerConfig( + val uiUrl: String, + val apiUrl: String, + val jitsiUrl : String, + val whiteListedUrls : List = emptyList() +) + diff --git a/vector/src/main/java/im/vector/widgets/WidgetManagerProvider.kt b/vector/src/main/java/im/vector/widgets/WidgetManagerProvider.kt new file mode 100644 index 0000000000..a13e976d0d --- /dev/null +++ b/vector/src/main/java/im/vector/widgets/WidgetManagerProvider.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2019 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 im.vector.widgets + +import android.content.Context +import im.vector.R +import im.vector.util.PreferencesManager +import java.net.MalformedURLException +import java.net.URL + +object WidgetManagerProvider { + + private var widgetsManager: WidgetsManager? = null + + fun getWidgetManager(context: Context): WidgetsManager? { + if (widgetsManager != null) { + return widgetsManager + } + val serverURL = PreferencesManager.getIntegrationServerUrl(context) + if (serverURL.isNullOrBlank()) return null + return try { + URL(serverURL) + val defaultWhitelist = ArrayList(PreferencesManager.getIntegrationWhiteListedUrl(context)) + defaultWhitelist.add(0,"$serverURL/api") + + val config = IntegrationManagerConfig( + uiUrl = "$serverURL/", + apiUrl = "$serverURL/api", + jitsiUrl = "$serverURL/api/widgets/jitsi.html", + whiteListedUrls = defaultWhitelist) + WidgetsManager(config).also { + this.widgetsManager = it + } + } catch (e: MalformedURLException) { + null + } + + } +} \ No newline at end of file diff --git a/vector/src/main/java/im/vector/widgets/WidgetsManager.java b/vector/src/main/java/im/vector/widgets/WidgetsManager.java index 408df4186e..17d9fc5a73 100755 --- a/vector/src/main/java/im/vector/widgets/WidgetsManager.java +++ b/vector/src/main/java/im/vector/widgets/WidgetsManager.java @@ -1,6 +1,7 @@ /* * Copyright 2017 Vector Creations Ltd * Copyright 2018 New Vector Ltd + * Copyright 2019 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. @@ -71,6 +72,15 @@ public class WidgetsManager { */ private static final String SCALAR_TOKEN_PREFERENCE_KEY = "SCALAR_TOKEN_PREFERENCE_KEY"; + private final IntegrationManagerConfig config; + + public WidgetsManager(IntegrationManagerConfig config) { + this.config = config; + } + + public String getUIUrl() { + return config.getUiUrl(); + } /** * Widget error code */ @@ -90,17 +100,6 @@ public WidgetError(String code, String detailedErrorDescription) { } } - /** - * unique instance - */ - private static final WidgetsManager mSharedInstance = new WidgetsManager(); - - /** - * @return the shared instance - */ - public static WidgetsManager getSharedInstance() { - return mSharedInstance; - } /** * Pending widget creation callback @@ -335,7 +334,7 @@ public void createJitsiWidget(MXSession session, Room room, boolean withVideo, f // TODO: This url may come from scalar API // Note: this url can be used as is inside a web container (like iframe for Riot-web) // Riot-iOS does not directly use it but extracts params from it (see `[JitsiViewController openWidget:withVideo:]`) - String url = "https://scalar.vector.im/api/widgets/jitsi.html?confId=" + confId + String url = config.getJitsiUrl() + "?confId=" + confId + "&isAudioConf=" + (withVideo ? "false" : "true") + "&displayName=$matrix_display_name&avatarUrl=$matrix_avatar_url&email=$matrix_user_id"; @@ -385,14 +384,14 @@ public interface onWidgetUpdateListener { void onWidgetUpdate(Widget widget); } - private static final Set mListeners = new HashSet<>(); + private final Set mListeners = new HashSet<>(); /** * Add a listener. * * @param listener the listener to add */ - public static void addListener(onWidgetUpdateListener listener) { + public void addListener(onWidgetUpdateListener listener) { if (null != listener) { synchronized (mListeners) { mListeners.add(listener); @@ -405,7 +404,7 @@ public static void addListener(onWidgetUpdateListener listener) { * * @param listener the listener to remove */ - public static void removeListener(onWidgetUpdateListener listener) { + public void removeListener(onWidgetUpdateListener listener) { if (null != listener) { synchronized (mListeners) { mListeners.remove(listener); @@ -488,7 +487,7 @@ public void onLiveEvent(MXSession session, Event event) { * @param widget the widget * @param callback the callback */ - public static void getFormattedWidgetUrl(final Context context, final Widget widget, final ApiCallback callback) { + public void getFormattedWidgetUrl(final Context context, final Widget widget, final ApiCallback callback) { if (isScalarUrl(context, widget.getUrl())) { getScalarToken(context, Matrix.getInstance(context).getSession(widget.getSessionId()), new SimpleApiCallback(callback) { @Override @@ -513,19 +512,13 @@ public void onSuccess(String token) { * @param url * @return true if the url is allowed to receive the scalar token in parameter */ - public static boolean isScalarUrl(Context context, String url) { - String[] array = context.getResources().getStringArray(R.array.integrations_widgets_urls); - - if (array.length == 0) { - array = new String[]{context.getString(R.string.integrations_rest_url)}; - } - - for (String allowedUrl : array) { + public boolean isScalarUrl(Context context, String url) { + List allowed = config.getWhiteListedUrls(); + for (String allowedUrl : allowed) { if (url.startsWith(allowedUrl)) { return true; } } - return false; } @@ -536,7 +529,7 @@ public static boolean isScalarUrl(Context context, String url) { * @param session the session * @param callback the asynchronous callback */ - public static void getScalarToken(final Context context, final MXSession session, final ApiCallback callback) { + public void getScalarToken(final Context context, final MXSession session, final ApiCallback callback) { final String preferenceKey = SCALAR_TOKEN_PREFERENCE_KEY + session.getMyUserId(); final String scalarToken = PreferenceManager.getDefaultSharedPreferences(context).getString(preferenceKey, null); @@ -547,7 +540,7 @@ public static void getScalarToken(final Context context, final MXSession session session.openIdToken(new SimpleApiCallback>(callback) { @Override public void onSuccess(Map tokensMap) { - WidgetsRestClient widgetsRestClient = new WidgetsRestClient(context); + WidgetsRestClient widgetsRestClient = new WidgetsRestClient(context, config); widgetsRestClient.register(tokensMap, new SimpleApiCallback>(callback) { @Override @@ -577,7 +570,7 @@ public void onSuccess(Map response) { * @param context Android context * @param session current session, to retrieve the current user */ - public static void clearScalarToken(Context context, final MXSession session) { + public void clearScalarToken(Context context, final MXSession session) { final String preferenceKey = SCALAR_TOKEN_PREFERENCE_KEY + session.getMyUserId(); PreferenceManager.getDefaultSharedPreferences(context) diff --git a/vector/src/main/java/im/vector/widgets/WidgetsRestClient.java b/vector/src/main/java/im/vector/widgets/WidgetsRestClient.java index 1da8cb3dc1..dab54abeb3 100644 --- a/vector/src/main/java/im/vector/widgets/WidgetsRestClient.java +++ b/vector/src/main/java/im/vector/widgets/WidgetsRestClient.java @@ -1,6 +1,7 @@ /* * Copyright 2015 OpenMarket Ltd * Copyright 2018 New Vector Ltd + * Copyright 2019 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. @@ -26,8 +27,6 @@ import java.util.Map; -import im.vector.R; - class WidgetsRestClient extends RestClient { private static final String API_VERSION = "1.1"; @@ -35,9 +34,9 @@ class WidgetsRestClient extends RestClient { /** * {@inheritDoc} */ - public WidgetsRestClient(Context context) { + public WidgetsRestClient(Context context, IntegrationManagerConfig config) { super(new HomeServerConnectionConfig.Builder() - .withHomeServerUri(Uri.parse(context.getString(R.string.integrations_rest_url))) + .withHomeServerUri(Uri.parse(config.getApiUrl())) .build(), WidgetsApi.class, "", @@ -53,12 +52,7 @@ public WidgetsRestClient(Context context) { public void register(final Map params, final ApiCallback> callback) { final String description = "Register"; - mApi.register(params, API_VERSION).enqueue(new RestAdapterCallback>(description, - mUnsentEventsManager, callback, new RestAdapterCallback.RequestRetryCallBack() { - @Override - public void onRetry() { - register(params, callback); - } - })); + mApi.register(params, API_VERSION).enqueue(new RestAdapterCallback<>(description, + mUnsentEventsManager, callback, () -> register(params, callback))); } } diff --git a/vector/src/main/res/values/config.xml b/vector/src/main/res/values/config.xml index c82aee1062..75d7c1fb29 100755 --- a/vector/src/main/res/values/config.xml +++ b/vector/src/main/res/values/config.xml @@ -14,8 +14,7 @@ https://riot.im/bugreports/submit - "https://scalar.vector.im/" - "https://scalar.vector.im/api" + "https://scalar.vector.im" https://scalar-staging.riot.im/scalar/api diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index daab4259e8..2f4c330067 100755 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -809,6 +809,7 @@ Logged in as Home Server Identity Server + Integration Server User interface Language diff --git a/vector/src/main/res/xml/vector_settings_preferences.xml b/vector/src/main/res/xml/vector_settings_preferences.xml index 869006bbbe..4d88d2c0c9 100755 --- a/vector/src/main/res/xml/vector_settings_preferences.xml +++ b/vector/src/main/res/xml/vector_settings_preferences.xml @@ -424,6 +424,12 @@ android:title="@string/settings_identity_server" tools:summary="@string/default_identity_server_url" /> + + + From db78f88fe6910d2d0ee2e5f200dc9ceb42871fde Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 30 Jul 2019 17:32:29 +0200 Subject: [PATCH 2/4] Use 3 different preferences for UI/REST/JITSI --- .../VectorSettingsPreferencesFragment.kt | 4 +- .../im/vector/util/PreferencesManager.java | 46 +++++++++++++++---- .../vector/widgets/WidgetManagerProvider.kt | 19 +++++--- vector/src/main/res/values/config.xml | 4 +- .../res/xml/vector_settings_preferences.xml | 4 +- 5 files changed, 56 insertions(+), 21 deletions(-) diff --git a/vector/src/main/java/im/vector/fragments/VectorSettingsPreferencesFragment.kt b/vector/src/main/java/im/vector/fragments/VectorSettingsPreferencesFragment.kt index 5e022d7c97..ad5e5a9522 100755 --- a/vector/src/main/java/im/vector/fragments/VectorSettingsPreferencesFragment.kt +++ b/vector/src/main/java/im/vector/fragments/VectorSettingsPreferencesFragment.kt @@ -645,8 +645,8 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref findPreference(PreferencesManager.SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY) .summary = mSession.homeServerConfig.identityServerUri.toString() - findPreference(PreferencesManager.SETTINGS_INTEGRATION_SERVER_URL) - .summary = PreferencesManager.getIntegrationServerUrl(context) + findPreference(PreferencesManager.SETTINGS_INTEGRATION_SERVER_UI_URL) + .summary = PreferencesManager.getIntegrationServerUiUrl(context) // Analytics diff --git a/vector/src/main/java/im/vector/util/PreferencesManager.java b/vector/src/main/java/im/vector/util/PreferencesManager.java index 9b9a65e4be..99e05f8641 100755 --- a/vector/src/main/java/im/vector/util/PreferencesManager.java +++ b/vector/src/main/java/im/vector/util/PreferencesManager.java @@ -164,7 +164,9 @@ public class PreferencesManager { public static final String SETTINGS_USE_RAGE_SHAKE_KEY = "SETTINGS_USE_RAGE_SHAKE_KEY"; //Integrations - public static final String SETTINGS_INTEGRATION_SERVER_URL = "SETTINGS_INTEGRATION_SERVER_URL"; + public static final String SETTINGS_INTEGRATION_SERVER_UI_URL = "SETTINGS_INTEGRATION_SERVER_UI_URL"; + public static final String SETTINGS_INTEGRATION_SERVER_API_URL = "SETTINGS_INTEGRATION_SERVER_API_URL"; + public static final String SETTINGS_INTEGRATION_SERVER_JITSI_URL = "SETTINGS_INTEGRATION_SERVER_JITSI_URL"; public static final String SETTINGS_INTEGRATION_WHITELIST_URL = "SETTINGS_INTEGRATION_WHITELIST_URL"; // other @@ -272,16 +274,42 @@ public static void setDidAskUserToIgnoreBatteryOptimizations(Context context) { .apply(); } - public static String getIntegrationServerUrl(Context context) { - return PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_INTEGRATION_SERVER_URL, - context.getString(R.string.integration_server_url)); + public static String getIntegrationServerUiUrl(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_INTEGRATION_SERVER_UI_URL, + context.getString(R.string.integrations_ui_url)); } - public static void setIntegrationServerUrl(Context context, String url) { - PreferenceManager.getDefaultSharedPreferences(context) - .edit() - .putString(SETTINGS_INTEGRATION_SERVER_URL, url) - .apply(); + public static String getIntegrationServerApiUrl(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_INTEGRATION_SERVER_API_URL, + context.getString(R.string.integrations_rest_url)); + } + + public static String getIntegrationServerJitsiUrl(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_INTEGRATION_SERVER_JITSI_URL, + context.getString(R.string.integrations_jitsi_widget_url)); + } + + + public static void setIntegrationServerUrls(Context context, String uiURl, String apiURl, String jitsyUrl) { + if (uiURl != null) { + PreferenceManager.getDefaultSharedPreferences(context) + .edit() + .putString(SETTINGS_INTEGRATION_SERVER_UI_URL, uiURl) + .apply(); + } + if (apiURl != null) { + PreferenceManager.getDefaultSharedPreferences(context) + .edit() + .putString(SETTINGS_INTEGRATION_SERVER_API_URL, apiURl) + .apply(); + } + + if (jitsyUrl != null) { + PreferenceManager.getDefaultSharedPreferences(context) + .edit() + .putString(SETTINGS_INTEGRATION_SERVER_JITSI_URL, jitsyUrl) + .apply(); + } } public static List getIntegrationWhiteListedUrl(Context context) { diff --git a/vector/src/main/java/im/vector/widgets/WidgetManagerProvider.kt b/vector/src/main/java/im/vector/widgets/WidgetManagerProvider.kt index a13e976d0d..00ab76a923 100644 --- a/vector/src/main/java/im/vector/widgets/WidgetManagerProvider.kt +++ b/vector/src/main/java/im/vector/widgets/WidgetManagerProvider.kt @@ -29,17 +29,22 @@ object WidgetManagerProvider { if (widgetsManager != null) { return widgetsManager } - val serverURL = PreferencesManager.getIntegrationServerUrl(context) - if (serverURL.isNullOrBlank()) return null + val uiURl = PreferencesManager.getIntegrationServerUiUrl(context) + val apiURL = PreferencesManager.getIntegrationServerApiUrl(context) + val jitsiUrl = PreferencesManager.getIntegrationServerJitsiUrl(context) + if (uiURl.isNullOrBlank() || apiURL.isNullOrBlank() || jitsiUrl.isNullOrBlank()) return null return try { - URL(serverURL) + //Very basic validity check (well formed url) + URL(uiURl) + URL(apiURL) + URL(jitsiUrl) val defaultWhitelist = ArrayList(PreferencesManager.getIntegrationWhiteListedUrl(context)) - defaultWhitelist.add(0,"$serverURL/api") + defaultWhitelist.add(0,apiURL) val config = IntegrationManagerConfig( - uiUrl = "$serverURL/", - apiUrl = "$serverURL/api", - jitsiUrl = "$serverURL/api/widgets/jitsi.html", + uiUrl = uiURl, + apiUrl = apiURL, + jitsiUrl = jitsiUrl, whiteListedUrls = defaultWhitelist) WidgetsManager(config).also { this.widgetsManager = it diff --git a/vector/src/main/res/values/config.xml b/vector/src/main/res/values/config.xml index 75d7c1fb29..d841837e46 100755 --- a/vector/src/main/res/values/config.xml +++ b/vector/src/main/res/values/config.xml @@ -14,7 +14,9 @@ https://riot.im/bugreports/submit - "https://scalar.vector.im" + "https://scalar.vector.im/" + "https://scalar.vector.im/api" + "https://scalar.vector.im/api/widgets/jitsi.html" https://scalar-staging.riot.im/scalar/api diff --git a/vector/src/main/res/xml/vector_settings_preferences.xml b/vector/src/main/res/xml/vector_settings_preferences.xml index 4d88d2c0c9..66fbdca6bd 100755 --- a/vector/src/main/res/xml/vector_settings_preferences.xml +++ b/vector/src/main/res/xml/vector_settings_preferences.xml @@ -426,8 +426,8 @@ From c4fa0b8499a951df6004527aaa7e989b9edddb84 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 31 Jul 2019 10:30:40 +0200 Subject: [PATCH 3/4] Fix / disable jitsi when no integration mgr + dialog --- .../main/java/im/vector/activity/JitsiCallActivity.java | 4 ++++ .../main/java/im/vector/activity/VectorRoomActivity.java | 7 +++++++ vector/src/main/res/values/strings.xml | 4 +++- vector/src/main/res/xml/vector_settings_preferences.xml | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/activity/JitsiCallActivity.java b/vector/src/main/java/im/vector/activity/JitsiCallActivity.java index 0545c71ede..7a9ec345e2 100755 --- a/vector/src/main/java/im/vector/activity/JitsiCallActivity.java +++ b/vector/src/main/java/im/vector/activity/JitsiCallActivity.java @@ -109,6 +109,10 @@ public int getLayoutRes() { @Override @SuppressLint("NewApi") public void initUiAndData() { + if (WidgetManagerProvider.INSTANCE.getWidgetManager(this) == null) { + finish(); + return; + } // Waiting View setWaitingView(findViewById(R.id.jitsi_progress_layout)); diff --git a/vector/src/main/java/im/vector/activity/VectorRoomActivity.java b/vector/src/main/java/im/vector/activity/VectorRoomActivity.java index 82454b941b..c4900f9672 100755 --- a/vector/src/main/java/im/vector/activity/VectorRoomActivity.java +++ b/vector/src/main/java/im/vector/activity/VectorRoomActivity.java @@ -3993,6 +3993,13 @@ void onStartCallClick() { .setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton(R.string.ok, null) .show(); + } else if (WidgetManagerProvider.INSTANCE.getWidgetManager(this) == null) { + // display the dialog with the info text + new AlertDialog.Builder(this) + .setMessage(R.string.widget_integration_no_server) + .setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton(R.string.ok, null) + .show(); } else if (isUserAllowedToStartConfCall()) { if (mRoom.getNumberOfMembers() > 2) { new AlertDialog.Builder(this) diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 2f4c330067..2ae277e4d3 100755 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -809,7 +809,7 @@ Logged in as Home Server Identity Server - Integration Server + Integration Manager User interface Language @@ -1092,6 +1092,7 @@ Room %s is not visible. A required parameter is missing. A parameter is not valid. + No integration server configured. Add Matrix apps Use native camera Start the system camera instead of the custom camera screen. @@ -1629,4 +1630,5 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming Link copied to clipboard + diff --git a/vector/src/main/res/xml/vector_settings_preferences.xml b/vector/src/main/res/xml/vector_settings_preferences.xml index 66fbdca6bd..54e4664c29 100755 --- a/vector/src/main/res/xml/vector_settings_preferences.xml +++ b/vector/src/main/res/xml/vector_settings_preferences.xml @@ -428,7 +428,7 @@ + android:title="@string/settings_integration_manager"/> From d939d4fe844a28ea4b8de1f25ac15261c21672ea Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 1 Aug 2019 09:49:44 +0200 Subject: [PATCH 4/4] Increase jvm memory for graddle 5 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ed1c78ee3e..0fa86295d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit