Skip to content

Commit

Permalink
Play Source
Browse files Browse the repository at this point in the history
* Play Search: Search only works for package names. Install will work for some apps. Very alpha.
  • Loading branch information
rumboalla committed Mar 24, 2024
1 parent 057a0c9 commit 8bfd3f0
Show file tree
Hide file tree
Showing 17 changed files with 568 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,17 @@ dependencies {
implementation("androidx.work:work-runtime-ktx:2.9.0")
implementation("io.insert-koin:koin-android:3.4.2")
implementation("io.insert-koin:koin-androidx-compose:3.4.2")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.11.0")
implementation("com.squareup.retrofit2:retrofit:2.10.0")
implementation("com.squareup.retrofit2:converter-gson:2.10.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
implementation("com.google.code.gson:gson:2.10.1")
implementation("io.coil-kt:coil-compose:2.4.0")
implementation("com.github.rumboalla.KryptoPrefs:kryptoprefs:0.4.3")
implementation("com.github.rumboalla.KryptoPrefs:kryptoprefs-gson:0.4.3")
implementation("org.jsoup:jsoup:1.16.1")
implementation("com.github.topjohnwu.libsu:core:5.2.1")
implementation("io.github.g00fy2:versioncompare:1.5.0")
implementation("com.gitlab.AuroraOSS:gplayapi:3.2.10")

testImplementation("junit:junit:4.13.2")

Expand Down
1 change: 1 addition & 0 deletions app/src/main/kotlin/com/apkupdater/data/ui/Source.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ val IzzySource = Source("F-Droid (Izzy)", R.drawable.ic_izzy)
val AptoideSource = Source("Aptoide", R.drawable.ic_aptoide)
val ApkPureSource = Source("ApkPure", R.drawable.ic_apkpure)
val GitLabSource = Source("GitLab", R.drawable.ic_gitlab)
val PlaySource = Source("Play", R.drawable.ic_play)
5 changes: 4 additions & 1 deletion app/src/main/kotlin/com/apkupdater/di/MainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.apkupdater.repository.AptoideRepository
import com.apkupdater.repository.FdroidRepository
import com.apkupdater.repository.GitHubRepository
import com.apkupdater.repository.GitLabRepository
import com.apkupdater.repository.PlayRepository
import com.apkupdater.repository.SearchRepository
import com.apkupdater.repository.UpdatesRepository
import com.apkupdater.service.ApkMirrorService
Expand Down Expand Up @@ -145,13 +146,15 @@ val mainModule = module {

single { AptoideRepository(get(), get(), get()) }

single { PlayRepository(get(), get(), get()) }

single(named("main")) { FdroidRepository(get(), "https://f-droid.org/repo/", FdroidSource, get()) }

single(named("izzy")) { FdroidRepository(get(), "https://apt.izzysoft.de/fdroid/repo/", IzzySource, get()) }

single { UpdatesRepository(get(), get(), get(), get(named("main")), get(named("izzy")), get(), get(), get(), get()) }

single { SearchRepository(get(), get(named("main")), get(named("izzy")), get(), get(), get(), get(), get()) }
single { SearchRepository(get(), get(named("main")), get(named("izzy")), get(), get(), get(), get(), get(), get()) }

single { KryptoBuilder.nocrypt(get(), androidContext().getString(R.string.app_name)) }

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/kotlin/com/apkupdater/prefs/Prefs.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.apkupdater.prefs

import com.apkupdater.data.ui.Screen
import com.aurora.gplayapi.data.models.AuthData
import com.kryptoprefs.context.KryptoContext
import com.kryptoprefs.gson.json
import com.kryptoprefs.preferences.KryptoPrefs
Expand Down Expand Up @@ -29,11 +30,13 @@ class Prefs(
val useIzzy = boolean("useIzzy", defValue = true, backed = true)
val useAptoide = boolean("useAptoide", defValue = true, backed = true)
val useApkPure = boolean("useApkPure", defValue = true, backed = true)
val usePlay = boolean("usePlay", defValue = true, backed = true)
val enableAlarm = boolean("enableAlarm", defValue = false, backed = true)
val alarmHour = int("alarmHour", defValue = 12, backed = true)
val alarmFrequency = int("alarmFrequency", 0, backed = true)
val androidTvUi = boolean("androidTvUi", defValue = isAndroidTv, backed = true)
val rootInstall = boolean("rootInstall", defValue = false, backed = true)
val theme = int("theme", defValue = 0, backed = true)
val lastTab = string("lastTab", defValue = Screen.Updates.route, backed = true)
val playAuthData = json("playAuthData", AuthData("", ""), true)
}
70 changes: 70 additions & 0 deletions app/src/main/kotlin/com/apkupdater/repository/PlayRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.apkupdater.repository

import android.content.Context
import android.net.Uri
import android.util.Log
import com.apkupdater.data.ui.AppUpdate
import com.apkupdater.data.ui.PlaySource
import com.apkupdater.prefs.Prefs
import com.apkupdater.util.play.NativeDeviceInfoProvider
import com.apkupdater.util.play.PlayHttpClient
import com.aurora.gplayapi.data.models.AuthData
import com.aurora.gplayapi.helpers.AppDetailsHelper
import com.aurora.gplayapi.helpers.PurchaseHelper
import com.google.gson.Gson
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow


class PlayRepository(
private val context: Context,
private val gson: Gson,
private val prefs: Prefs
) {
private suspend fun auth(): AuthData {
val savedData = prefs.playAuthData.get()
if (savedData.email.isEmpty()) {
val properties = NativeDeviceInfoProvider(context).getNativeDeviceProperties()
val playResponse = PlayHttpClient.postAuth(
"https://auroraoss.com/api/auth",
gson.toJson(properties).toByteArray()
)
if (playResponse.isSuccessful) {
val authData = gson.fromJson(String(playResponse.responseBytes), AuthData::class.java)
prefs.playAuthData.put(authData)
return authData
}
throw IllegalStateException("Auth not successful.")
}
return savedData
}

suspend fun search(text: String) = flow {
if (text.contains(" ") || !text.contains(".")) {
emit(Result.success(emptyList()))
return@flow
}
val authData = auth()
val details = AppDetailsHelper(authData).using(PlayHttpClient)
val app = details.getAppByPackageName(text)
val files = PurchaseHelper(authData).purchase(app.packageName, app.versionCode, app.offerType)
val link = files.joinToString(separator = ",") { it.url }
val update = AppUpdate(
app.displayName,
app.packageName,
app.versionName,
"",
app.versionCode.toLong(),
0L,
PlaySource,
Uri.parse(app.iconArtwork.url),
link,
whatsNew = app.changes
)
emit(Result.success(listOf(update)))
}.catch {
emit(Result.failure(it))
Log.e("PlayRepository", "Error searching.", it)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SearchRepository(
private val gitHubRepository: GitHubRepository,
private val apkPureRepository: ApkPureRepository,
private val gitLabRepository: GitLabRepository,
private val playRepository: PlayRepository,
private val prefs: Prefs
) {

Expand All @@ -29,6 +30,7 @@ class SearchRepository(
if (prefs.useGitHub.get()) sources.add(gitHubRepository.search(text))
if (prefs.useApkPure.get()) sources.add(apkPureRepository.search(text))
if (prefs.useGitLab.get()) sources.add(gitLabRepository.search(text))
if (prefs.usePlay.get()) sources.add(playRepository.search(text))

if (sources.isNotEmpty()) {
sources.combine { updates ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ fun Settings(viewModel: SettingsViewModel) = LazyColumn {
stringResource(R.string.source_apkpure),
R.drawable.ic_apkpure
)
SwitchSetting(
{ viewModel.getUsePlay() },
{ viewModel.setUsePlay(it) },
stringResource(R.string.source_play) + " (Alpha)",
R.drawable.ic_play
)
}

item {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/kotlin/com/apkupdater/util/SessionInstaller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,7 @@ class SessionInstaller(private val context: Context) {
file.delete()
}

suspend fun playInstall(id: Int, packageName: String, streams: List<InputStream>) =
install(id, packageName, streams)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.apkupdater.util.play

import android.opengl.GLES10
import android.text.TextUtils
import javax.microedition.khronos.egl.EGL10
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.egl.EGLContext
import javax.microedition.khronos.egl.EGLDisplay


object EglExtensionProvider {
@JvmStatic
val eglExtensions: List<String>
get() {
val glExtensions: MutableSet<String> = HashSet()
val egl10 = EGLContext.getEGL() as EGL10
val display = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY)
egl10.eglInitialize(display, IntArray(2))
val cf = IntArray(1)
if (egl10.eglGetConfigs(display, null, 0, cf)) {
val configs = arrayOfNulls<EGLConfig>(cf[0])
if (egl10.eglGetConfigs(display, configs, cf[0], cf)) {
val a1 = intArrayOf(EGL10.EGL_WIDTH, EGL10.EGL_PBUFFER_BIT, EGL10.EGL_HEIGHT, EGL10.EGL_PBUFFER_BIT, EGL10.EGL_NONE)
val a2 = intArrayOf(12440, EGL10.EGL_PIXMAP_BIT, EGL10.EGL_NONE)
val a3 = IntArray(1)
for (i in 0 until cf[0]) {
egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_CONFIG_CAVEAT, a3)
if (a3[0] != EGL10.EGL_SLOW_CONFIG) {
egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_SURFACE_TYPE, a3)
if (1 and a3[0] != 0) {
egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_RENDERABLE_TYPE, a3)
if (1 and a3[0] != 0) {
addExtensionsForConfig(egl10, display, configs[i], a1, null, glExtensions)
}
if (4 and a3[0] != 0) {
addExtensionsForConfig(egl10, display, configs[i], a1, a2, glExtensions)
}
}
}
}
}
}
egl10.eglTerminate(display)
return ArrayList(glExtensions).sorted()
}

private fun addExtensionsForConfig(
egl10: EGL10,
eglDisplay: EGLDisplay,
eglConfig: EGLConfig?,
ai: IntArray,
ai1: IntArray?,
set: MutableSet<String>
) {
val eglContext = egl10.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, ai1)
if (eglContext === EGL10.EGL_NO_CONTEXT) {
return
}
val eglSurface = egl10.eglCreatePbufferSurface(eglDisplay, eglConfig, ai)
if (eglSurface === EGL10.EGL_NO_SURFACE) {
egl10.eglDestroyContext(eglDisplay, eglContext)
} else {
egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)
val s = GLES10.glGetString(7939)
if (!TextUtils.isEmpty(s)) {
val split = s.split(" ".toRegex()).toTypedArray()
val i = split.size
set.addAll(listOf(*split).subList(0, i))
}
egl10.eglMakeCurrent(
eglDisplay,
EGL10.EGL_NO_SURFACE,
EGL10.EGL_NO_SURFACE,
EGL10.EGL_NO_CONTEXT
)
egl10.eglDestroySurface(eglDisplay, eglSurface)
egl10.eglDestroyContext(eglDisplay, eglContext)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.apkupdater.util.play

import com.aurora.gplayapi.network.IHttpClient


interface IProxyHttpClient : IHttpClient {
@Throws(UnsupportedOperationException::class)
fun setProxy(proxyInfo: ProxyInfo): IHttpClient
}
Loading

0 comments on commit 8bfd3f0

Please sign in to comment.