Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed the Hotspot feature from custom apps, and used the normal service instead of foreground service for readAloud feature. #4027

Merged
merged 8 commits into from
Oct 18, 2024
5 changes: 5 additions & 0 deletions app/detekt_baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<ID>PackageNaming:SimplePageChangeListener.kt$package org.kiwix.kiwixmobile.zimManager</ID>
<ID>PackageNaming:StartMultiSelection.kt$package
org.kiwix.kiwixmobile.zimManager.fileselectView.effects</ID>
<ID>PackageNaming:HotspotNotificationManager.kt$package org.kiwix.kiwixmobile.webserver.wifi_hotspot</ID>
<ID>PackageNaming:HotspotStateReceiver.kt$package org.kiwix.kiwixmobile.webserver.wifi_hotspot</ID>
<ID>PackageNaming:IpAddressCallbacks.kt$package org.kiwix.kiwixmobile.webserver.wifi_hotspot</ID>
<ID>PackageNaming:HotspotService.kt$package org.kiwix.kiwixmobile.webserver.wifi_hotspot</ID>
<ID>PackageNaming:ServerStatus.kt$package org.kiwix.kiwixmobile.webserver.wifi_hotspot</ID>
<ID>PackageNaming:ZimManageViewModel.kt$package org.kiwix.kiwixmobile.zimManager</ID>
<ID>ReturnCount:Fat32Checker.kt$Fat32Checker$private fun canCreate4GbFile(storage: String): Boolean</ID>
<ID>TooGenericExceptionCaught:FileWritingFileSystemChecker.kt$FileWritingFileSystemChecker$e: Exception</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.Findable.Text
import org.kiwix.kiwixmobile.Findable.ViewId
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.R.id
import org.kiwix.kiwixmobile.core.utils.files.Log
import org.kiwix.kiwixmobile.testutils.TestUtils
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
Expand Down Expand Up @@ -74,7 +75,7 @@ class ZimHostRobot : BaseRobot() {
fun startServer() {
// stop the server if it is already running.
stopServerIfAlreadyStarted()
clickOn(ViewId(R.id.startServerButton))
clickOn(ViewId(id.startServerButton))
assetWifiDialogDisplayed()
testFlakyView({ onView(withText("PROCEED")).perform(click()) })
}
Expand Down Expand Up @@ -115,7 +116,7 @@ class ZimHostRobot : BaseRobot() {
} catch (assertionFailedError: AssertionFailedError) {
try {
val recyclerViewItemsCount =
RecyclerViewItemCount(R.id.recyclerViewZimHost).checkRecyclerViewCount()
RecyclerViewItemCount(id.recyclerViewZimHost).checkRecyclerViewCount()
(0 until recyclerViewItemsCount)
.asSequence()
.filter { it != 0 }
Expand All @@ -129,14 +130,14 @@ class ZimHostRobot : BaseRobot() {
private fun selectZimFile(position: Int) {
try {
onView(
RecyclerViewMatcher(R.id.recyclerViewZimHost).atPositionOnView(
RecyclerViewMatcher(id.recyclerViewZimHost).atPositionOnView(
position,
R.id.itemBookCheckbox
)
).check(matches(ViewMatchers.isChecked()))
} catch (assertionError: AssertionFailedError) {
onView(
RecyclerViewMatcher(R.id.recyclerViewZimHost).atPositionOnView(
RecyclerViewMatcher(id.recyclerViewZimHost).atPositionOnView(
position,
R.id.itemBookCheckbox
)
Expand All @@ -147,14 +148,14 @@ class ZimHostRobot : BaseRobot() {
fun assertItemHostedOnServer(itemCount: Int) {
val checkedCheckboxCount =
RecyclerViewSelectedCheckBoxCountAssertion(
R.id.recyclerViewZimHost,
id.recyclerViewZimHost,
R.id.itemBookCheckbox
).countCheckedCheckboxes()
assertThat(checkedCheckboxCount, CoreMatchers.`is`(itemCount))
}

fun stopServer() {
testFlakyView({ onView(withId(R.id.startServerButton)).perform(click()) })
testFlakyView({ onView(withId(id.startServerButton)).perform(click()) })
}

fun assertServerStopped() {
Expand All @@ -163,11 +164,11 @@ class ZimHostRobot : BaseRobot() {
}

fun assertQrShown() {
isVisible(ViewId(R.id.serverQrCode))
isVisible(ViewId(id.serverQrCode))
}

fun assertQrNotShown() {
isNotVisible(ViewId(R.id.serverQrCode))
isNotVisible(ViewId(id.serverQrCode))
}

private fun pauseForBetterTestPerformance() {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
tools:ignore="CoarseFineLocation" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="${permission}" />
<!-- Device with versions >= Pie need this permission -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission
android:name="android.permission.NEARBY_WIFI_DEVICES"
android:usesPermissionFlags="neverForLocation"
tools:targetApi="s" />

<application
android:name=".KiwixApp"
Expand Down Expand Up @@ -136,5 +143,8 @@
<action android:name="KiwixSearchWidget.STAR_CLICKED" />
</intent-filter>
</receiver>
<service
android:name=".webserver.wifi_hotspot.HotspotService"
android:foregroundServiceType="dataSync" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import dagger.BindsInstance
import dagger.Subcomponent
import org.kiwix.kiwixmobile.core.di.ActivityScope
import org.kiwix.kiwixmobile.core.di.components.CoreActivityComponent
import org.kiwix.kiwixmobile.core.webserver.ZimHostModule
import org.kiwix.kiwixmobile.webserver.ZimHostModule
import org.kiwix.kiwixmobile.webserver.ZimHostFragment
import org.kiwix.kiwixmobile.di.modules.KiwixActivityModule
import org.kiwix.kiwixmobile.intro.IntroFragment
import org.kiwix.kiwixmobile.intro.IntroModule
Expand All @@ -49,6 +50,7 @@ interface KiwixActivityComponent : CoreActivityComponent {
fun inject(deleteFiles: DeleteFiles)
fun inject(localFileTransferFragment: LocalFileTransferFragment)
fun inject(languageFragment: LanguageFragment)
fun inject(zimHostFragment: ZimHostFragment)
fun inject(kiwixSettingsFragment: KiwixSettingsFragment)
fun inject(introActivity: IntroFragment)
fun inject(kiwixMainActivity: KiwixMainActivity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.kiwix.kiwixmobile.di.components
import dagger.Component
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
import org.kiwix.kiwixmobile.di.KiwixScope
import org.kiwix.kiwixmobile.di.components.ServiceComponent.Builder
import org.kiwix.kiwixmobile.di.modules.KiwixModule
import org.kiwix.kiwixmobile.di.modules.KiwixViewModelModule

Expand All @@ -31,4 +32,5 @@ import org.kiwix.kiwixmobile.di.modules.KiwixViewModelModule
)
interface KiwixComponent {
fun activityComponentBuilder(): KiwixActivityComponent.Builder
fun serviceComponent(): Builder
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Kiwix Android
* Copyright (c) 2019 Kiwix <android.kiwix.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package org.kiwix.kiwixmobile.di.components

import android.app.Service
import dagger.BindsInstance
import dagger.Subcomponent
import org.kiwix.kiwixmobile.di.ServiceScope
import org.kiwix.kiwixmobile.di.modules.ServiceModule
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService

@Subcomponent(modules = [ServiceModule::class])
@ServiceScope
interface ServiceComponent {
fun inject(hotspotService: HotspotService)

@Subcomponent.Builder
interface Builder {
@BindsInstance fun service(service: Service): Builder
fun build(): ServiceComponent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import dagger.Module
import org.kiwix.kiwixmobile.core.di.modules.ActivityModule
import org.kiwix.kiwixmobile.core.webserver.ZimHostModule

@Module(includes = [ActivityModule::class, ZimHostModule::class])
@Module(includes = [ActivityModule::class])

Check warning on line 24 in app/src/main/java/org/kiwix/kiwixmobile/di/modules/KiwixActivityModule.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/di/modules/KiwixActivityModule.kt#L24

Added line #L24 was not covered by tests
class KiwixActivityModule
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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
Expand Down Expand Up @@ -55,4 +56,9 @@ object KiwixModule {
// See: https://github.com/kiwix/kiwix-android/issues/2488
fun providesWiFiP2pManager(context: Context): WifiP2pManager? =
context.getSystemService(Context.WIFI_P2P_SERVICE) as WifiP2pManager?

@Provides
@KiwixScope
fun provideWifiManager(context: Context): WifiManager =
context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Kiwix Android
* Copyright (c) 2024 Kiwix <android.kiwix.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package org.kiwix.kiwixmobile.di.modules

import android.app.NotificationManager
import android.app.Service
import android.content.Context
import dagger.Module
import dagger.Provides
import org.kiwix.kiwixmobile.core.qr.GenerateQR
import org.kiwix.kiwixmobile.core.read_aloud.ReadAloudNotificationManger
import org.kiwix.kiwixmobile.di.ServiceScope
import org.kiwix.kiwixmobile.webserver.KiwixServer
import org.kiwix.kiwixmobile.webserver.WebServerHelper
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotNotificationManager
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotStateReceiver
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.IpAddressCallbacks

@Module
class ServiceModule {
@Provides
@ServiceScope
fun providesReadAloudNotificationManager(
notificationManager: NotificationManager,
context: Context
): ReadAloudNotificationManger = ReadAloudNotificationManger(notificationManager, context)

Check warning on line 42 in app/src/main/java/org/kiwix/kiwixmobile/di/modules/ServiceModule.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/di/modules/ServiceModule.kt#L42

Added line #L42 was not covered by tests

@Provides
@ServiceScope
fun providesWebServerHelper(
kiwixServerFactory: KiwixServer.Factory,
ipAddressCallbacks: IpAddressCallbacks
): WebServerHelper = WebServerHelper(kiwixServerFactory, ipAddressCallbacks)

@Provides
@ServiceScope
fun providesIpAddressCallbacks(service: Service): IpAddressCallbacks =
service as IpAddressCallbacks

@Provides
@ServiceScope
fun providesHotspotNotificationManager(
notificationManager: NotificationManager,
context: Context,
generateQR: GenerateQR,
): HotspotNotificationManager =
HotspotNotificationManager(notificationManager, context, generateQR)

@Provides
@ServiceScope
fun providesHotspotStateReceiver(callback: HotspotStateReceiver.Callback): HotspotStateReceiver =
HotspotStateReceiver(callback)

@Provides
@ServiceScope
fun providesHotspotStateReceiverCallback(service: Service): HotspotStateReceiver.Callback =
service as HotspotStateReceiver.Callback

@Provides
@ServiceScope
fun providesGenerateQr(): GenerateQR = GenerateQR()
}
17 changes: 15 additions & 2 deletions app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.graphics.drawable.Icon
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode
import androidx.core.os.ConfigurationCompat
Expand All @@ -40,6 +41,7 @@ import com.google.android.material.navigation.NavigationView
import eu.mhutti1.utils.storage.StorageDeviceUtils
import org.kiwix.kiwixmobile.BuildConfig
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.R.id
import org.kiwix.kiwixmobile.core.R.drawable
import org.kiwix.kiwixmobile.core.R.mipmap
import org.kiwix.kiwixmobile.core.R.string
Expand Down Expand Up @@ -98,8 +100,6 @@ class KiwixMainActivity : CoreMainActivity() {
override val notesFragmentResId: Int = R.id.notesFragment
override val readerFragmentResId: Int = R.id.readerFragment
override val helpFragmentResId: Int = R.id.helpFragment
override val zimHostFragmentResId: Int = R.id.zimHostFragment
override val navGraphId: Int = R.navigation.kiwix_nav_graph
override val topLevelDestinations =
setOf(R.id.downloadsFragment, R.id.libraryFragment, R.id.readerFragment)

Expand Down Expand Up @@ -272,6 +272,19 @@ class KiwixMainActivity : CoreMainActivity() {
}
}

override fun onNavigationItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
id.menu_host_books -> openZimHostFragment()
else -> return super.onNavigationItemSelected(item)
}
return true
}

private fun openZimHostFragment() {
disableDrawer()
navigate(R.id.zimHostFragment)
}

override fun getIconResId() = mipmap.ic_launcher

override fun createApplicationShortcuts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
@SuppressLint("InflateParams") fun showPreparingCopyMoveDialog() {
if (copyMovePreparingDialog == null) {
val dialogView: View =
activity.layoutInflater.inflate(R.layout.item_custom_spinner, null)
activity.layoutInflater.inflate(layout.item_custom_spinner, null)

Check warning on line 385 in app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/CopyMoveFileHandler.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/CopyMoveFileHandler.kt#L385

Added line #L385 was not covered by tests
copyMovePreparingDialog =
alertDialogShower.create(KiwixDialog.PreparingCopyingFilesDialog { dialogView })
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Kiwix Android
* Copyright (c) 2023 Kiwix <android.kiwix.org>
* Copyright (c) 2024 Kiwix <android.kiwix.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand All @@ -16,7 +16,7 @@
*
*/

package org.kiwix.kiwixmobile.core.webserver
package org.kiwix.kiwixmobile.webserver

import android.content.Context
import org.kiwix.kiwixmobile.core.utils.files.Log
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Kiwix Android
* Copyright (c) 2023 Kiwix <android.kiwix.org>
* Copyright (c) 2024 Kiwix <android.kiwix.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand All @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.core.webserver
package org.kiwix.kiwixmobile.webserver

import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
Expand All @@ -27,8 +27,8 @@ import org.kiwix.kiwixmobile.core.utils.ServerUtils.INVALID_IP
import org.kiwix.kiwixmobile.core.utils.ServerUtils.getIp
import org.kiwix.kiwixmobile.core.utils.ServerUtils.getIpAddress
import org.kiwix.kiwixmobile.core.utils.files.Log
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.IpAddressCallbacks
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.ServerStatus
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.IpAddressCallbacks
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.ServerStatus
import java.util.concurrent.TimeUnit
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.core.webserver
package org.kiwix.kiwixmobile.webserver

interface ZimHostCallbacks {
fun onServerStarted(ip: String)
Expand Down
Loading
Loading