瀏覽代碼

Only branded plus client can use app config

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 年之前
父節點
當前提交
325dc8620a

+ 7 - 7
app/src/androidTest/java/com/nextcloud/utils/AppConfigManagerTests.kt

@@ -17,7 +17,7 @@ import org.junit.Test
 class AppConfigManagerTests : AbstractIT() {
 
     @Test
-    fun testSetProxyConfigWhenGivenClientBrandedAndCorrectBundleDataProxyConfigurationShouldSet() {
+    fun testSetProxyConfigWhenGivenClientBrandedPlusAndCorrectBundleDataProxyConfigurationShouldSet() {
         val proxySetting = Bundle().apply {
             putString(AppConfigKeys.ProxyHost.key, "nextcloud.cloud.cloud.com")
             putInt(AppConfigKeys.ProxyPort.key, 441212)
@@ -35,7 +35,7 @@ class AppConfigManagerTests : AbstractIT() {
     }
 
     @Test
-    fun testSetProxyConfigWhenGivenClientNotBrandedAndCorrectBundleDataProxyConfigurationShouldNotSet() {
+    fun testSetProxyConfigWhenGivenClientNotBrandedPlusAndCorrectBundleDataProxyConfigurationShouldNotSet() {
         val proxySetting = Bundle().apply {
             putString(AppConfigKeys.ProxyHost.key, "nextcloud.cloud.cloud.com")
             putInt(AppConfigKeys.ProxyPort.key, 441212)
@@ -53,7 +53,7 @@ class AppConfigManagerTests : AbstractIT() {
     }
 
     @Test
-    fun testSetProxyConfigWhenGivenClientBrandedAndBrokenBundleDataProxyConfigurationShouldSetDefaultValues() {
+    fun testSetProxyConfigWhenGivenClientBrandedPlusAndBrokenBundleDataProxyConfigurationShouldSetDefaultValues() {
         val proxySetting = Bundle()
 
         AppConfigManager(targetContext, proxySetting).run {
@@ -68,18 +68,18 @@ class AppConfigManagerTests : AbstractIT() {
     }
 
     @Test
-    fun testGetBaseUrlConfigWhenGivenClientBrandedAndCorrectBundleDataBaseUrlConfigurationShouldSet() {
+    fun testGetBaseUrlConfigWhenGivenClientBrandedPlusAndCorrectBundleDataBaseUrlConfigurationShouldSet() {
         val baseUrlConfig = Bundle().apply {
             putString(AppConfigKeys.BaseUrl.key, "nextcloud.cloud.cloud")
         }
         val sut = AppConfigManager(targetContext, baseUrlConfig)
-        assert(!sut.getBaseUrl().isNullOrEmpty())
+        assert(!sut.getBaseUrl(true).isNullOrEmpty())
     }
 
     @Test
-    fun testGetBaseUrlConfigWhenGivenClientBrandedAndBrokenBundleDataBaseUrlConfigurationShouldNotSet() {
+    fun testGetBaseUrlConfigWhenGivenClientBrandedPlusAndBrokenBundleDataBaseUrlConfigurationShouldNotSet() {
         val baseUrlConfig = Bundle()
         val sut = AppConfigManager(targetContext, baseUrlConfig)
-        assert(sut.getBaseUrl().isNullOrEmpty())
+        assert(sut.getBaseUrl(true).isNullOrEmpty())
     }
 }

+ 5 - 6
app/src/main/java/com/owncloud/android/MainApp.java

@@ -329,7 +329,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
 
         OwnCloudClientManagerFactory.setUserAgent(getUserAgent());
 
-        appConfigManager.setProxyConfig(isClientBranded());
+        appConfigManager.setProxyConfig(isClientBrandedPlus());
 
         // initialise thumbnails cache on background thread
         new ThumbnailsCacheManager.InitDiskCacheTask().execute();
@@ -376,21 +376,20 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
             passCodeManager.setCanAskPin(true);
             Log_OC.d(TAG, "APP IN BACKGROUND");
         } else if (event == Lifecycle.Event.ON_RESUME) {
-            appConfigManager.setProxyConfig(isClientBranded());
+            appConfigManager.setProxyConfig(isClientBrandedPlus());
             Log_OC.d(TAG, "APP ON RESUME");
         }
     });
 
-    public static boolean isClientBranded() {
-        Resources resources = getAppContext().getResources();
-        return (resources.getBoolean(R.bool.is_branded_client) || resources.getBoolean(R.bool.is_branded_plus_client));
+    public static boolean isClientBrandedPlus() {
+        return (getAppContext().getResources().getBoolean(R.bool.is_branded_plus_client));
     }
 
     private final IntentFilter restrictionsFilter = new IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED);
 
     private final BroadcastReceiver restrictionsReceiver = new BroadcastReceiver() {
         @Override public void onReceive(Context context, Intent intent) {
-            appConfigManager.setProxyConfig(isClientBranded());
+            appConfigManager.setProxyConfig(isClientBrandedPlus());
         }
     };
 

+ 1 - 1
app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -328,7 +328,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
         if (getResources().getBoolean(R.bool.is_branded_plus_client)) {
             webViewLoginMethod = true;
-            webloginUrl = appConfigManager.getBaseUrl();
+            webloginUrl = appConfigManager.getBaseUrl(true);
         } else if (getIntent().getBooleanExtra(EXTRA_USE_PROVIDER_AS_WEBLOGIN, false)) {
             webViewLoginMethod = true;
             webloginUrl = getString(R.string.provider_registration_server);

+ 9 - 4
app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt

@@ -18,9 +18,9 @@ class AppConfigManager(private val context: Context, private val appRestrictions
 
     private val tag = "AppConfigManager"
 
-    fun setProxyConfig(isBranded: Boolean) {
-        if (!isBranded) {
-            Log_OC.d(tag, "Proxy configuration cannot be set. Client is not branded.")
+    fun setProxyConfig(isBrandedPlus: Boolean) {
+        if (!isBrandedPlus) {
+            Log_OC.d(tag, "Proxy configuration cannot be set. Client is not branded plus.")
             return
         }
 
@@ -51,7 +51,12 @@ class AppConfigManager(private val context: Context, private val appRestrictions
         }
     }
 
-    fun getBaseUrl(): String? {
+    fun getBaseUrl(isBrandedPlus: Boolean): String? {
+        if (!isBrandedPlus) {
+            Log_OC.d(tag, "Proxy configuration cannot be set. Client is not branded plus.")
+            return null
+        }
+
         return if (appRestrictions.containsKey(AppConfigKeys.BaseUrl.key)) {
             appRestrictions.getString(AppConfigKeys.BaseUrl.key)
         } else {