This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added notification troubleshoot page in settings, that runs diagnostics tests with quickfixes when available.
- Loading branch information
1 parent
841f642
commit d2e342b
Showing
43 changed files
with
1,496 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
/local.properties | ||
|
||
/tmp | ||
|
||
captures/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
vector/src/app/java/im/vector/push/fcm/NotificationTroubleshootTestManagerFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
vector/src/app/java/im/vector/push/fcm/troubleshoot/TestFirebaseToken.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
vector/src/app/java/im/vector/push/fcm/troubleshoot/TestPlayServices.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
|
||
} | ||
|
56 changes: 56 additions & 0 deletions
56
vector/src/app/java/im/vector/push/fcm/troubleshoot/TestTokenRegistration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
}) | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
vector/src/appfdroid/java/im/vector/push/fcm/NotificationTroubleshootTestManagerFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
vector/src/appfdroid/java/im/vector/push/fcm/troubleshoot/TestAutoStartBoot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
vector/src/appfdroid/java/im/vector/push/fcm/troubleshoot/TestBackgroundRestrictions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.