Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.microg.gms.moduleinstall

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import com.google.android.gms.common.Feature
Expand All @@ -27,22 +29,30 @@ import org.microg.gms.common.GmsService

private const val TAG = "ModuleInstall"

private const val ACTION_SCAN_DOCUMENT = "com.google.android.gms.mlkit.ACTION_SCAN_DOCUMENT"
private const val FEATURE_PREFIX_DOCUMENT_SCANNER = "mlkit.docscan."

class ModuleInstallService : BaseService(TAG, GmsService.MODULE_INSTALL) {
override fun handleServiceRequest(callback: IGmsCallbacks, request: GetServiceRequest, service: GmsService) {
val binder = ModuleInstallServiceImpl().asBinder()
val binder = ModuleInstallServiceImpl(this).asBinder()
callback.onPostInitCompleteWithConnectionInfo(CommonStatusCodes.SUCCESS, binder, ConnectionInfo().apply {
features = arrayOf(Feature("moduleinstall", 7))
})
}
}

class ModuleInstallServiceImpl : IModuleInstallService.Stub() {
class ModuleInstallServiceImpl(private val context: Context) : IModuleInstallService.Stub() {
override fun areModulesAvailable(callbacks: IModuleInstallCallbacks?, request: ApiFeatureRequest?) {
Log.d(TAG, "Not yet implemented: areModulesAvailable $request")
runCatching { callbacks?.onModuleAvailabilityResponse(Status.SUCCESS, ModuleAvailabilityResponse(true, STATUS_ALREADY_AVAILABLE)) }
}

override fun installModules(callbacks: IModuleInstallCallbacks?, request: ApiFeatureRequest?, listener: IModuleInstallStatusListener?) {
if (isProvidedLocally(request)) {
Log.d(TAG, "installModules: provided locally $request")
runCatching { callbacks?.onModuleInstallResponse(Status.SUCCESS, ModuleInstallResponse(0, true)) }
return
}
Log.d(TAG, "Not yet implemented: installModules $request")
runCatching { callbacks?.onModuleInstallResponse(Status.CANCELED, ModuleInstallResponse(0, true)) }
}
Expand All @@ -62,4 +72,13 @@ class ModuleInstallServiceImpl : IModuleInstallService.Stub() {
runCatching { callback?.onResult(Status.SUCCESS) }
}

}
private fun isProvidedLocally(request: ApiFeatureRequest?): Boolean {
val features = request?.features.orEmpty()
if (features.isEmpty()) return false
if (features.all { it.name.startsWith(FEATURE_PREFIX_DOCUMENT_SCANNER) }) {
val intent = Intent(ACTION_SCAN_DOCUMENT).setPackage(context.packageName)
return context.packageManager.resolveActivity(intent, 0) != null
}
return false
}
}
13 changes: 13 additions & 0 deletions play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,19 @@
</intent-filter>
</activity>

<activity
android:name="org.microg.gms.mlkit.DocumentScanningActivity"
android:exported="true"
android:process=":ui"
android:excludeFromRecents="true"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
<intent-filter>
<action android:name="com.google.android.gms.mlkit.ACTION_SCAN_DOCUMENT" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<service
android:name="com.google.android.gms.maps.auth.ApiTokenService"
android:exported="true"/>
Expand Down
Loading
Loading