forked from GitHub-Mirror/riotX-android
Import settings from Riot - not all fonctional of course
This commit is contained in:
15
vector/src/fdroid/AndroidManifest.xml
Normal file
15
vector/src/fdroid/AndroidManifest.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="im.vector">
|
||||
|
||||
<application>
|
||||
|
||||
<receiver android:name=".receiver.OnApplicationUpgradeReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
56
vector/src/fdroid/java/im/vector/push/fcm/FcmHelper.java
Executable file
56
vector/src/fdroid/java/im/vector/push/fcm/FcmHelper.java
Executable file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2014 OpenMarket Ltd
|
||||
* 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.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class FcmHelper {
|
||||
|
||||
/**
|
||||
* Retrieves the FCM registration token.
|
||||
*
|
||||
* @return the FCM token or null if not received from FCM
|
||||
*/
|
||||
@Nullable
|
||||
public static String getFcmToken(Context context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store FCM token to the SharedPrefs
|
||||
*
|
||||
* @param context android context
|
||||
* @param token the token to store
|
||||
*/
|
||||
public static void storeFcmToken(@NonNull Context context,
|
||||
@Nullable String token) {
|
||||
// No op
|
||||
}
|
||||
|
||||
/**
|
||||
* onNewToken may not be called on application upgrade, so ensure my shared pref is set
|
||||
*
|
||||
* @param activity the first launch Activity
|
||||
*/
|
||||
public static void ensureFcmTokenIsRetrieved(final Activity activity) {
|
||||
// No op
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 androidx.fragment.app.Fragment
|
||||
import im.vector.fragments.troubleshoot.TestAccountSettings
|
||||
import im.vector.fragments.troubleshoot.TestDeviceSettings
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.push.fcm.troubleshoot.TestAutoStartBoot
|
||||
import im.vector.push.fcm.troubleshoot.TestBackgroundRestrictions
|
||||
import im.vector.riotredesign.features.settings.troubleshoot.NotificationTroubleshootTestManager
|
||||
import im.vector.riotredesign.features.settings.troubleshoot.TestBingRulesSettings
|
||||
import im.vector.riotredesign.features.settings.troubleshoot.TestSystemSettings
|
||||
|
||||
class NotificationTroubleshootTestManagerFactory {
|
||||
|
||||
companion object {
|
||||
fun createTestManager(fragment: Fragment, session: Session?): NotificationTroubleshootTestManager {
|
||||
val mgr = NotificationTroubleshootTestManager(fragment)
|
||||
mgr.addTest(TestSystemSettings(fragment))
|
||||
if (session != null) {
|
||||
mgr.addTest(TestAccountSettings(fragment, session))
|
||||
}
|
||||
mgr.addTest(TestDeviceSettings(fragment))
|
||||
if (session != null) {
|
||||
mgr.addTest(TestBingRulesSettings(fragment, session))
|
||||
}
|
||||
// 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 androidx.fragment.app.Fragment
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.features.settings.PreferencesManager
|
||||
import im.vector.riotredesign.features.settings.troubleshoot.TroubleshootTest
|
||||
|
||||
/**
|
||||
* 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 androidx.core.net.ConnectivityManagerCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.features.settings.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,0 +1,47 @@
|
||||
/*
|
||||
* 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 androidx.fragment.app.Fragment
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.utils.isIgnoringBatteryOptimizations
|
||||
import im.vector.riotredesign.core.utils.requestDisablingBatteryOptimization
|
||||
import im.vector.riotredesign.features.settings.troubleshoot.NotificationTroubleshootTestManager
|
||||
import im.vector.riotredesign.features.settings.troubleshoot.TroubleshootTest
|
||||
|
||||
// Not used anymore
|
||||
class TestBatteryOptimization(val fragment: Fragment) : TroubleshootTest(R.string.settings_troubleshoot_test_battery_title) {
|
||||
|
||||
override fun perform() {
|
||||
|
||||
if (fragment.context != null && isIgnoringBatteryOptimizations(fragment.context!!)) {
|
||||
description = fragment.getString(R.string.settings_troubleshoot_test_battery_success)
|
||||
status = TestStatus.SUCCESS
|
||||
quickFix = null
|
||||
} else {
|
||||
description = fragment.getString(R.string.settings_troubleshoot_test_battery_failed)
|
||||
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_battery_quickfix) {
|
||||
override fun doFix() {
|
||||
fragment.activity?.let {
|
||||
requestDisablingBatteryOptimization(it, fragment, NotificationTroubleshootTestManager.REQ_CODE_FIX)
|
||||
}
|
||||
}
|
||||
}
|
||||
status = TestStatus.FAILED
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class OnApplicationUpgradeReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Timber.d("## onReceive() : Application has been upgraded, restart event stream service.");
|
||||
|
||||
// Start Event stream
|
||||
// TODO EventStreamServiceX.Companion.onApplicationUpgrade(context);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user