Browse Source

Use androidx.enterprise:enterprise-feedback for give feedback to customer

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 year ago
parent
commit
7b46e6da0b

+ 3 - 0
app/build.gradle

@@ -274,6 +274,9 @@ dependencies {
         exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
     }
 
+    // Enterprise Feedback for AppConfig
+    implementation "androidx.enterprise:enterprise-feedback:1.1.0"
+
     // Jetpack Compose
     implementation(platform("androidx.compose:compose-bom:2024.05.00"))
     implementation("androidx.compose.ui:ui")

+ 5 - 3
app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt

@@ -10,10 +10,12 @@ package com.owncloud.android.utils.appConfig
 import android.content.Context
 import android.content.RestrictionsManager
 import android.content.res.Resources
+import com.owncloud.android.R
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
 import com.owncloud.android.lib.common.utils.Log_OC
+import com.owncloud.android.utils.enterpriseReporter.enterpriseFeedback
 
-class AppConfigManager(context: Context) {
+class AppConfigManager(private val context: Context) {
 
     private val restrictionsManager =
         context.getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
@@ -24,7 +26,7 @@ class AppConfigManager(context: Context) {
         val appRestrictions = restrictionsManager.applicationRestrictions
 
         if (!appRestrictions.containsKey(AppConfigKeys.ProxyHost.key) || !appRestrictions.containsKey(AppConfigKeys.ProxyPort.key)) {
-            // TODO Send feedback to customer
+            context.enterpriseFeedback(R.string.app_config_proxy_config_cannot_be_found_message)
         }
 
         val host = appRestrictions.getString(AppConfigKeys.ProxyHost.key)
@@ -34,7 +36,7 @@ class AppConfigManager(context: Context) {
             OwnCloudClientManagerFactory.setProxyHost(host)
             OwnCloudClientManagerFactory.setProxyPort(port)
         } catch (e: Resources.NotFoundException) {
-            // TODO Send feedback to customer
+            context.enterpriseFeedback(R.string.app_config_proxy_config_cannot_be_set_message)
            Log_OC.d(tag,"Proxy config cannot able to set due to: $e")
         }
     }

+ 49 - 0
app/src/main/java/com/owncloud/android/utils/enterpriseReporter/EnterpriseReporter.kt

@@ -0,0 +1,49 @@
+/*
+ * Nextcloud - Android Client
+ *
+ * SPDX-FileCopyrightText: 2024 Your Name <your@email.com>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+package com.owncloud.android.utils.enterpriseReporter
+
+import android.content.Context
+import androidx.enterprise.feedback.KeyedAppState
+import androidx.enterprise.feedback.KeyedAppStatesCallback
+import androidx.enterprise.feedback.KeyedAppStatesCallback.STATUS_EXCEEDED_BUFFER_ERROR
+import androidx.enterprise.feedback.KeyedAppStatesCallback.STATUS_SUCCESS
+import androidx.enterprise.feedback.KeyedAppStatesCallback.STATUS_TRANSACTION_TOO_LARGE_ERROR
+import androidx.enterprise.feedback.KeyedAppStatesCallback.STATUS_UNKNOWN_ERROR
+import androidx.enterprise.feedback.KeyedAppStatesReporter
+import com.owncloud.android.lib.common.utils.Log_OC
+
+fun Context.enterpriseFeedback(
+    messageId: Int,
+    severity: Int = KeyedAppState.SEVERITY_ERROR
+) {
+    val keyedAppStatesReporter = KeyedAppStatesReporter.create(this)
+    val keyedAppStateMessage = KeyedAppState.builder()
+        .setSeverity(severity)
+        .setMessage(getString(messageId))
+        .build()
+    val list: MutableList<KeyedAppState> = ArrayList()
+    list.add(keyedAppStateMessage)
+    keyedAppStatesReporter.setStates(list, Callback())
+}
+
+internal class Callback : KeyedAppStatesCallback {
+    override fun onResult(state: Int, throwable: Throwable?) {
+        when (state) {
+            STATUS_SUCCESS ->
+                Log_OC.i("ErrorReporter", "KeyedAppStatesCallback status: SUCCESS ")
+            STATUS_UNKNOWN_ERROR ->
+                Log_OC.i("ErrorReporter", "KeyedAppStatesCallback status: UNKNOWN_ERROR ")
+            STATUS_TRANSACTION_TOO_LARGE_ERROR ->
+                Log_OC.i("ErrorReporter", "KeyedAppStatesCallback status: TRANSACTION_TOO_LARGE_ERROR ")
+            STATUS_EXCEEDED_BUFFER_ERROR ->
+                Log_OC.i("ErrorReporter", "KeyedAppStatesCallback status: EXCEEDED_BUFFER_ERROR ")
+            else ->
+                Log_OC.i("ErrorReporter", "KeyedAppStatesCallback status: $state ")
+        }
+    }
+}

+ 3 - 0
app/src/main/res/values/strings.xml

@@ -32,6 +32,9 @@
     <string name="app_config_proxy_port_title">Port</string>
     <string name="app_config_proxy_port_description">Select a proxy port configuration</string>
 
+    <string name="app_config_proxy_config_cannot_be_found_message">Proxy configuration cannot be found</string>
+    <string name="app_config_proxy_config_cannot_be_set_message">Proxy configuration cannot be set</string>
+
     <string name="assistant_screen_task_types_error_state_message">Unable to fetch task types, please check your internet connection.</string>
     <string name="assistant_screen_task_list_error_state_message">Unable to fetch task list, please check your internet connection.</string>