Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Notification Troubleshoot v1
Browse files Browse the repository at this point in the history
Added notification troubleshoot page in settings, that runs diagnostics tests with quickfixes when available.
  • Loading branch information
BillCarsonFr committed Dec 19, 2018
1 parent 841f642 commit d2e342b
Show file tree
Hide file tree
Showing 43 changed files with 1,496 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -13,3 +13,5 @@
/local.properties

/tmp

captures/
4 changes: 0 additions & 4 deletions vector/src/app/java/im/vector/push/fcm/FcmHelper.java
Expand Up @@ -114,10 +114,6 @@ private static boolean checkPlayServices(Activity activity) {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(activity);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(activity, resultCode, 9000 /*hey does the magic number*/)
.show();
}
return false;
}
return true;
Expand Down
@@ -0,0 +1,43 @@
/*
* Copyright 2018 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.push.fcm

import android.support.v4.app.Fragment
import im.vector.fragments.troubleshoot.NotificationTroubleshootTestManager
import im.vector.fragments.troubleshoot.TestAccountSettings
import im.vector.fragments.troubleshoot.TestDeviceSettings
import im.vector.fragments.troubleshoot.TestSystemSettings
import im.vector.push.fcm.troubleshoot.*
import org.matrix.androidsdk.MXSession

class NotificationTroubleshootTestManagerFactory {

companion object {
fun createTestManager(fragment: Fragment, session: MXSession?): NotificationTroubleshootTestManager {
val mgr = NotificationTroubleshootTestManager(fragment)
mgr.addTest(TestSystemSettings(fragment))
if (session != null) {
mgr.addTest(TestAccountSettings(fragment, session))
}
mgr.addTest(TestDeviceSettings(fragment))
mgr.addTest(TestPlayServices(fragment))
mgr.addTest(TestFirebaseToken(fragment))
mgr.addTest(TestTokenRegistration(fragment))
return mgr
}
}

}
@@ -0,0 +1,53 @@
/*
* Copyright 2018 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.push.fcm.troubleshoot

import android.support.v4.app.Fragment
import com.google.firebase.iid.FirebaseInstanceId
import im.vector.R
import im.vector.fragments.troubleshoot.TroubleshootTest
import org.matrix.androidsdk.util.Log

/*
* Test that app can successfully retrieve a token via firebase
*/
class TestFirebaseToken(val fragment: Fragment) : TroubleshootTest(R.string.settings_troubleshoot_test_fcm_title) {

override fun perform() {
status = TestStatus.RUNNING
fragment.activity?.let { fragmentActivity ->
FirebaseInstanceId.getInstance().instanceId
.addOnCompleteListener(fragmentActivity) { task ->
if (!task.isSuccessful) {
val errorMsg = if (task.exception == null) "Unknown" else task.exception!!.localizedMessage
description = fragment.getString(R.string.settings_troubleshoot_test_fcm_failed, errorMsg)
status = TestStatus.FAILED

} else {
task.result?.token?.let {
val tok = it.substring(0, Math.min(8, it.length)) + "********************"
description = fragment.getString(R.string.settings_troubleshoot_test_fcm_success, tok)
Log.e(this::class.java.simpleName, "Retrieved FCM token success [$it].")
}
status = TestStatus.SUCCESS
}
}
} ?: run {
status = TestStatus.FAILED
}
}

}
@@ -0,0 +1,55 @@
/*
* Copyright 2018 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.push.fcm.troubleshoot

import android.support.v4.app.Fragment
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import im.vector.R
import im.vector.fragments.troubleshoot.TroubleshootTest
import org.matrix.androidsdk.util.Log

/*
* Check that the play services APK is available an up-to-date. If needed provide quick fix to install it.
*/
class TestPlayServices(val fragment: Fragment) : TroubleshootTest(R.string.settings_troubleshoot_test_play_services_title) {

override fun perform() {
val apiAvailability = GoogleApiAvailability.getInstance()
val resultCode = apiAvailability.isGooglePlayServicesAvailable(fragment.context)
if (resultCode == ConnectionResult.SUCCESS) {
quickFix = null
description = fragment.getString(R.string.settings_troubleshoot_test_play_services_success)
status = TestStatus.SUCCESS
} else {
if (apiAvailability.isUserResolvableError(resultCode)) {
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_play_services_quickfix) {
override fun doFix() {
fragment.activity?.let {
apiAvailability.getErrorDialog(it, resultCode, 9000 /*hey does the magic number*/).show()
}
}
}
Log.e(this::javaClass.name, "Play Services apk error $resultCode -> ${apiAvailability.getErrorString(resultCode)}.")
}

description = fragment.getString(R.string.settings_troubleshoot_test_play_services_failed, apiAvailability.getErrorString(resultCode))
status = TestStatus.FAILED
}
}

}

@@ -0,0 +1,56 @@
/*
* Copyright 2018 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.push.fcm.troubleshoot

import android.support.v4.app.Fragment
import im.vector.Matrix
import im.vector.R
import im.vector.VectorApp
import im.vector.fragments.troubleshoot.TroubleshootTest
import org.matrix.androidsdk.rest.callback.ApiCallback
import org.matrix.androidsdk.rest.model.MatrixError
import java.lang.Exception

/**
* Force registration of the token to HomeServer
*/
class TestTokenRegistration(val fragment: Fragment) : TroubleshootTest(R.string.settings_troubleshoot_test_token_registration_title) {

override fun perform() {
Matrix.getInstance(VectorApp.getInstance().baseContext).pushManager.forceSessionsRegistration(object : ApiCallback<Void> {
override fun onSuccess(info: Void?) {
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_success)
status = TestStatus.SUCCESS
}

override fun onNetworkError(e: Exception?) {
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_failed, e?.localizedMessage)
status = TestStatus.FAILED
}

override fun onMatrixError(e: MatrixError?) {
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_failed, e?.localizedMessage)
status = TestStatus.FAILED
}

override fun onUnexpectedError(e: Exception?) {
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_failed, e?.localizedMessage)
status = TestStatus.FAILED
}
})
}

}
@@ -0,0 +1,45 @@
/*
* Copyright 2018 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.push.fcm

import android.support.v4.app.Fragment
import im.vector.fragments.troubleshoot.NotificationTroubleshootTestManager
import im.vector.fragments.troubleshoot.TestAccountSettings
import im.vector.fragments.troubleshoot.TestDeviceSettings
import im.vector.fragments.troubleshoot.TestSystemSettings
import im.vector.push.fcm.troubleshoot.*
import org.matrix.androidsdk.MXSession

class NotificationTroubleshootTestManagerFactory {

companion object {
fun createTestManager(fragment: Fragment, session: MXSession?): NotificationTroubleshootTestManager {
val mgr = NotificationTroubleshootTestManager(fragment)
mgr.addTest(TestSystemSettings(fragment))
if (session != null) {
mgr.addTest(TestAccountSettings(fragment, session))
}
mgr.addTest(TestDeviceSettings(fragment))
mgr.addTest(TestNotificationServiceRunning(fragment))
mgr.addTest(TestServiceRestart(fragment))
mgr.addTest(TestAutoStartBoot(fragment))
mgr.addTest(TestBackgroundRestrictions(fragment))
mgr.addTest(TestBatteryOptimization(fragment))
return mgr
}
}

}
@@ -0,0 +1,44 @@
/*
* Copyright 2018 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.push.fcm.troubleshoot

import android.support.v4.app.Fragment
import im.vector.R
import im.vector.fragments.troubleshoot.TroubleshootTest
import im.vector.util.PreferencesManager

/**
* Test that the application is started on boot
*/
class TestAutoStartBoot(val fragment: Fragment) : TroubleshootTest(R.string.settings_troubleshoot_test_service_boot_title) {

override fun perform() {
if (PreferencesManager.autoStartOnBoot(fragment.context)) {
description = fragment.getString(R.string.settings_troubleshoot_test_service_boot_success)
status = TestStatus.SUCCESS
quickFix = null
} else {
description = fragment.getString(R.string.settings_troubleshoot_test_service_boot_failed)
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_service_boot_quickfix) {
override fun doFix() {
PreferencesManager.setAutoStartOnBoot(fragment.context, true)
manager?.retry()
}
}
status = TestStatus.FAILED
}
}
}
@@ -0,0 +1,71 @@
/*
* Copyright 2018 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.push.fcm.troubleshoot

import android.content.Context
import android.net.ConnectivityManager
import android.support.v4.app.Fragment
import android.support.v4.net.ConnectivityManagerCompat
import im.vector.R
import im.vector.fragments.troubleshoot.TroubleshootTest

class TestBackgroundRestrictions(val fragment: Fragment) : TroubleshootTest(R.string.settings_troubleshoot_test_bg_restricted_title) {

override fun perform() {
(fragment.context!!.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).apply {
// Checks if the device is on a metered network
if (isActiveNetworkMetered) {
// Checks user’s Data Saver settings.
val restrictBackgroundStatus = ConnectivityManagerCompat.getRestrictBackgroundStatus(this)
when (restrictBackgroundStatus) {
ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED -> {
// Background data usage is blocked for this app. Wherever possible,
// the app should also use less data in the foreground.
description = fragment.getString(R.string.settings_troubleshoot_test_bg_restricted_failed,
"RESTRICT_BACKGROUND_STATUS_ENABLED")
status = TestStatus.FAILED
quickFix = null
}
ConnectivityManager.RESTRICT_BACKGROUND_STATUS_WHITELISTED -> {
// The app is whitelisted. Wherever possible,
// the app should use less data in the foreground and background.
description = fragment.getString(R.string.settings_troubleshoot_test_bg_restricted_success,
"RESTRICT_BACKGROUND_STATUS_WHITELISTED")
status = TestStatus.SUCCESS
quickFix = null
}
ConnectivityManager.RESTRICT_BACKGROUND_STATUS_DISABLED -> {
// Data Saver is disabled. Since the device is connected to a
// metered network, the app should use less data wherever possible.
description = fragment.getString(R.string.settings_troubleshoot_test_bg_restricted_success,
"RESTRICT_BACKGROUND_STATUS_DISABLED")
status = TestStatus.SUCCESS
quickFix = null
}

}

} else {
// The device is not on a metered network.
// Use data as required to perform syncs, downloads, and updates.
description = fragment.getString(R.string.settings_troubleshoot_test_bg_restricted_success, "")
status = TestStatus.SUCCESS
quickFix = null
}
}
}

}

0 comments on commit d2e342b

Please sign in to comment.