Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature3/macgills/…
Browse files Browse the repository at this point in the history
…2303-service-worker-unregistration
  • Loading branch information
macgills committed Nov 24, 2020
2 parents f8c9c5b + 17b71ab commit f3324f2
Show file tree
Hide file tree
Showing 21 changed files with 263 additions and 73 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
coverageReport:
strategy:
matrix:
api-level: [21, 21]
api-level: [21, 21]
fail-fast: false
runs-on: macOS-latest
steps:
Expand Down Expand Up @@ -45,3 +45,11 @@ jobs:
- name: Upload coverage to Codecov
run: |
bash <(curl -s https://codecov.io/bash)
- name: Upload Coverage to GH-Actions
uses: actions/upload-artifact@v2.2.0
if: ${{ always() }}
with:
name: Tests Coverage Report
path: |
**/reports/
9 changes: 9 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ jobs:
- name: Static Analysis
run: ./gradlew ktlintCheck detekt app:lintDebug custom:lintCustomexampleDebug

- name: Upload Static Analysis Report
uses: actions/upload-artifact@v2.2.0
if: ${{ always() }}
with:
name: Static Analysis Report
path: |
**/reports/
build:

runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
NEW: Overhauled navigation
NEW: Updated translations
NEW: Support resizing Kiwix
NEW: Open search in ne wtab
NEW: Open search in new tab
BUGFIX: Search speed increased and loading state added
BUGFIX: Memory leaks patched
BUGFIX: More consistent labelling drives internal/external
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ To generate coverage reports for your automated tests run:

Code coverage results can be seen under `[module]/build/reports/`

### Continous Integration
### Continuous Integration

All PRs will have all these tests run and a combined coverage report will be attached, if coverage is to go down the PR will be marked failed. On Travis CI the automated tests are run on an emulator. To
learn more about the commands run on the CI please refer to [.github/workflows](https://github.com/kiwix/kiwix-android/tree/develop/.github/workflows).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ package org.kiwix.kiwixmobile.di.modules
import android.content.Context
import android.location.LocationManager
import android.net.wifi.WifiManager
import android.net.wifi.p2p.WifiP2pManager
import dagger.Module
import dagger.Provides
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.zim_manager.MountPointProducer
import org.kiwix.kiwixmobile.di.KiwixScope
import org.kiwix.kiwixmobile.zim_manager.Fat32Checker
import org.kiwix.kiwixmobile.zim_manager.FileWritingFileSystemChecker
import org.kiwix.kiwixmobile.zim_manager.MountFileSystemChecker
import org.kiwix.kiwixmobile.core.zim_manager.MountPointProducer

@Module
object KiwixModule {
Expand All @@ -52,4 +53,12 @@ object KiwixModule {
sharedPreferenceUtil,
listOf(MountFileSystemChecker(mountPointProducer), FileWritingFileSystemChecker())
)

@Provides
@KiwixScope
// We are forced to use the nullable type because of a
// crash on our nightly builds running on an emulator API 27
// See: https://github.com/kiwix/kiwix-android/issues/2488
fun providesWiFiP2pManager(context: Context): WifiP2pManager? =
context.getSystemService(Context.WIFI_P2P_SERVICE) as WifiP2pManager?
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import android.app.Service
import android.content.Context
import dagger.Module
import dagger.Provides
import org.kiwix.kiwixlib.Library
import org.kiwix.kiwixlib.JNIKiwixServer
import org.kiwix.kiwixlib.Library
import org.kiwix.kiwixmobile.di.ServiceScope
import org.kiwix.kiwixmobile.webserver.WebServerHelper
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotNotificationManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.kiwix.kiwixmobile.localFileTransfer

import android.app.Activity
import android.content.Context
import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -45,7 +45,7 @@ import java.net.Socket
private const val TIME_OUT = 15000

internal class SenderDevice(
private val activity: Activity,
private val context: Context,
private val wifiDirectManager: WifiDirectManager,
private val fileReceiverDeviceAddress: InetAddress
) {
Expand All @@ -59,7 +59,7 @@ internal class SenderDevice(
.forEachIndexed { fileIndex, fileItem ->
try {
Socket().use { socket ->
activity.contentResolver.openInputStream(fileItem?.fileUri!!).use { fileInputStream ->
context.contentResolver.openInputStream(fileItem?.fileUri!!).use { fileInputStream ->
socket.bind(null)
socket.connect(
InetSocketAddress(hostAddress, WifiDirectManager.FILE_TRANSFER_PORT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.kiwix.kiwixmobile.localFileTransfer

import android.app.Activity
import android.content.BroadcastReceiver
import android.content.Context
import android.content.IntentFilter
Expand All @@ -35,7 +34,7 @@ import android.net.wifi.p2p.WifiP2pManager.ConnectionInfoListener
import android.net.wifi.p2p.WifiP2pManager.PeerListListener
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.os.Looper
import android.os.Looper.getMainLooper
import android.util.Log
import android.widget.Toast
import androidx.lifecycle.LifecycleCoroutineScope
Expand All @@ -59,9 +58,10 @@ import javax.inject.Inject
*/
@SuppressWarnings("MissingPermission", "ProtectedMemberInFinalClass")
class WifiDirectManager @Inject constructor(
private val activity: Activity,
private val context: Context,
private val sharedPreferenceUtil: SharedPreferenceUtil,
private val alertDialogShower: AlertDialogShower
private val alertDialogShower: AlertDialogShower,
private val manager: WifiP2pManager?
) : ChannelListener, PeerListListener, ConnectionInfoListener, P2pEventListener {
var callbacks: Callbacks? = null

Expand All @@ -74,11 +74,8 @@ class WifiDirectManager @Inject constructor(
// Whether channel has retried connecting previously
private var shouldRetry = true

// Overall manager of Wifi p2p connections for the module
private lateinit var manager: WifiP2pManager

// Interface to the device's underlying wifi-p2p framework
private lateinit var channel: Channel
private var channel: Channel? = null

// For receiving the broadcasts given by above filter
private lateinit var receiver: BroadcastReceiver
Expand All @@ -94,8 +91,7 @@ class WifiDirectManager @Inject constructor(
fun startWifiDirectManager(filesForTransfer: List<FileItem>) {
this.filesForTransfer = filesForTransfer
isFileSender = filesForTransfer.isNotEmpty()
manager = activity.getSystemService(Context.WIFI_P2P_SERVICE) as WifiP2pManager
channel = manager.initialize(activity, Looper.getMainLooper(), null)
channel = manager?.initialize(context, getMainLooper(), null)
registerWifiDirectBroadcastReceiver()
}

Expand All @@ -110,20 +106,20 @@ class WifiDirectManager @Inject constructor(
addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION)
addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION)
}
activity.registerReceiver(receiver, intentFilter)
context.registerReceiver(receiver, intentFilter)
}

private fun unregisterWifiDirectBroadcastReceiver() = activity.unregisterReceiver(receiver)
private fun unregisterWifiDirectBroadcastReceiver() = context.unregisterReceiver(receiver)

fun discoverPeerDevices() {
manager.discoverPeers(channel, object : ActionListener {
manager?.discoverPeers(channel, object : ActionListener {
override fun onSuccess() {
activity.toast(R.string.discovery_initiated, Toast.LENGTH_SHORT)
context.toast(R.string.discovery_initiated, Toast.LENGTH_SHORT)
}

override fun onFailure(reason: Int) {
Log.d(TAG, "${activity.getString(R.string.discovery_failed)}: ${getErrorMessage(reason)}")
activity.toast(R.string.discovery_failed, Toast.LENGTH_SHORT)
Log.d(TAG, "${context.getString(R.string.discovery_failed)}: ${getErrorMessage(reason)}")
context.toast(R.string.discovery_failed, Toast.LENGTH_SHORT)
}
})
}
Expand All @@ -132,7 +128,7 @@ class WifiDirectManager @Inject constructor(
override fun onWifiP2pStateChanged(isEnabled: Boolean) {
isWifiP2pEnabled = isEnabled
if (!isWifiP2pEnabled) {
activity.toast(R.string.discovery_needs_wifi, Toast.LENGTH_SHORT)
context.toast(R.string.discovery_needs_wifi, Toast.LENGTH_SHORT)
callbacks?.onConnectionToPeersLost()
}
Log.d(TAG, "WiFi P2P state changed - $isWifiP2pEnabled")
Expand All @@ -141,14 +137,14 @@ class WifiDirectManager @Inject constructor(
override fun onPeersChanged() {
/* List of available peers has changed, so request & use the new list through
* PeerListListener.requestPeers() callback */
manager.requestPeers(channel, this)
manager?.requestPeers(channel, this)
Log.d(TAG, "P2P peers changed")
}

override fun onConnectionChanged(isConnected: Boolean) {
if (isConnected) {
// Request connection info about the wifi p2p group formed upon connection
manager.requestConnectionInfo(channel, this)
manager?.requestConnectionInfo(channel, this)
} else {
// Not connected after connection change -> Disconnected
callbacks?.onConnectionToPeersLost()
Expand All @@ -167,9 +163,9 @@ class WifiDirectManager @Inject constructor(
Log.d(TAG, "Channel lost, trying again")
callbacks?.onConnectionToPeersLost()
shouldRetry = false
manager.initialize(activity, Looper.getMainLooper(), this)
manager?.initialize(context, getMainLooper(), this)
} else {
activity.toast(R.string.severe_loss_error, Toast.LENGTH_LONG)
context.toast(R.string.severe_loss_error, Toast.LENGTH_LONG)
}
}

Expand All @@ -191,7 +187,7 @@ class WifiDirectManager @Inject constructor(
FileTransferConfirmation(senderSelectedPeerDevice.deviceName), {
hasSenderStartedConnection = true
connect(senderSelectedPeerDevice)
activity.toast(R.string.performing_handshake, Toast.LENGTH_LONG)
context.toast(R.string.performing_handshake, Toast.LENGTH_LONG)
})
}
}
Expand All @@ -201,15 +197,15 @@ class WifiDirectManager @Inject constructor(
deviceAddress = senderSelectedPeerDevice.deviceAddress
wps.setup = WpsInfo.PBC
}
manager.connect(channel, config, object : ActionListener {
manager?.connect(channel, config, object : ActionListener {
override fun onSuccess() {
// UI updated from broadcast receiver
}

override fun onFailure(reason: Int) {
val errorMessage = getErrorMessage(reason)
Log.d(TAG, activity.getString(R.string.connection_failed) + ": " + errorMessage)
activity.toast(R.string.connection_failed, Toast.LENGTH_LONG)
Log.d(TAG, context.getString(R.string.connection_failed) + ": " + errorMessage)
context.toast(R.string.connection_failed, Toast.LENGTH_LONG)
}
})
}
Expand All @@ -232,7 +228,7 @@ class WifiDirectManager @Inject constructor(
Log.d(TAG, "InetAddress is null")
}
onFileTransferAsyncTaskComplete(false)
activity.toast(R.string.connection_refused)
context.toast(R.string.connection_refused)
}
}
}
Expand All @@ -254,8 +250,8 @@ class WifiDirectManager @Inject constructor(
Log.d(LocalFileTransferFragment.TAG, "Starting file transfer")
val fileReceiverDeviceAddress =
if (groupInfo.isGroupOwner) inetAddress else groupInfo.groupOwnerAddress
activity.toast(R.string.preparing_files, Toast.LENGTH_LONG)
val senderDevice = SenderDevice(activity, this, fileReceiverDeviceAddress)
context.toast(R.string.preparing_files, Toast.LENGTH_LONG)
val senderDevice = SenderDevice(context, this, fileReceiverDeviceAddress)
val isFileSendSuccessfully = senderDevice.send(filesForTransfer)
onFileTransferAsyncTaskComplete(isFileSendSuccessfully)
if (BuildConfig.DEBUG) {
Expand All @@ -277,8 +273,8 @@ class WifiDirectManager @Inject constructor(
filesForTransfer[itemIndex].fileStatus = status
callbacks?.onFileStatusChanged(itemIndex)
if (status == FileStatus.ERROR) {
activity.toast(
activity.getString(
context.toast(
context.getString(
R.string.error_transferring, filesForTransfer[itemIndex].fileName
)
)
Expand All @@ -295,7 +291,7 @@ class WifiDirectManager @Inject constructor(
}

private fun disconnect() {
manager.removeGroup(channel, object : ActionListener {
manager?.removeGroup(channel, object : ActionListener {
override fun onFailure(reasonCode: Int) {
Log.d(TAG, "Disconnect failed. Reason: $reasonCode")
closeChannel()
Expand All @@ -310,7 +306,7 @@ class WifiDirectManager @Inject constructor(

private fun closeChannel() {
if (VERSION.SDK_INT >= VERSION_CODES.O_MR1) {
channel.close()
channel?.close()
}
}

Expand All @@ -325,9 +321,9 @@ class WifiDirectManager @Inject constructor(

private fun onFileTransferAsyncTaskComplete(wereAllFilesTransferred: Boolean) {
if (wereAllFilesTransferred) {
activity.toast(R.string.file_transfer_complete, Toast.LENGTH_LONG)
context.toast(R.string.file_transfer_complete, Toast.LENGTH_LONG)
} else {
activity.toast(R.string.error_during_transfer, Toast.LENGTH_LONG)
context.toast(R.string.error_during_transfer, Toast.LENGTH_LONG)
}
callbacks?.onFileTransferComplete()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.google.android.material.navigation.NavigationView
import kotlinx.android.synthetic.main.activity_kiwix_main.bottom_nav_view
import kotlinx.android.synthetic.main.activity_kiwix_main.drawer_nav_view
import kotlinx.android.synthetic.main.activity_kiwix_main.navigation_container
import kotlinx.android.synthetic.main.activity_kiwix_main.reader_drawer_nav_view
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
Expand All @@ -48,6 +49,7 @@ class KiwixMainActivity : CoreMainActivity() {
override val navController by lazy { findNavController(R.id.nav_host_fragment) }
override val drawerContainerLayout: DrawerLayout by lazy { navigation_container }
override val drawerNavView: NavigationView by lazy { drawer_nav_view }
override val readerTableOfContentsDrawer: NavigationView by lazy { reader_drawer_nav_view }
override val bookmarksFragmentResId: Int = R.id.bookmarksFragment
override val settingsFragmentResId: Int = R.id.kiwixSettingsFragment
override val historyFragmentResId: Int = R.id.historyFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import org.kiwix.kiwixlib.JNIKiwixException;
import org.kiwix.kiwixlib.Library;
import org.kiwix.kiwixlib.JNIKiwixServer;
import org.kiwix.kiwixlib.Library;
import org.kiwix.kiwixmobile.core.utils.ServerUtils;
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.IpAddressCallbacks;

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-b+roa+tara/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
<string name="file_system_does_not_support_4gb">\'U file system tune non ge supporte le file cchiù granne de 4GB</string>
<string name="detecting_file_system">Stoche a condrolle ce \'u file system tune pò ccrejà le file cchiù granne de 4GB</string>
<string name="cannot_open_file">Aprture d‘u fail sciute a male\nPe piacere pruève arrete a cercà stu fail jndr’à Schede d\'u despositive d\'a libbreria toje.</string>
<string name="send_files_title">Manne le file</string>
<string name="receive_files_title">Pigghie le file</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-sc/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
<string name="file_system_does_not_support_4gb">Su sistema de documentos (file system) tuo non suportat documentos prus mannos de 4GB</string>
<string name="detecting_file_system">Verifichende si su sistema de documentos podet creare documentos de 4GB</string>
<string name="cannot_open_file">Abertura de su documentu fallida\nPro praghere proa a chircare custu documentu in s\'Ischeda de sos Dispositivos de sa Biblioteca tua</string>
<string name="send_files_title">Imbia documentos</string>
<string name="receive_files_title">Retzi documentos</string>
</resources>
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Libs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ object Libs {
Versions.xfetch2okhttp

/**
* http://assertj.org
* https://assertj.github.io/doc/
*/
const val assertj_core: String = "org.assertj:assertj-core:" + Versions.assertj_core

Expand Down
Loading

0 comments on commit f3324f2

Please sign in to comment.