Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6cac319 authored by Jonathan Klee's avatar Jonathan Klee Committed by Nishith Khanna
Browse files

Introduce ContentProviderAuthData

which allows to use an auth token coming from
AppLounge for the Licensing feature.
parent f300a68a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ buildscript {

    ext.hiddenSecretVersion = '0.2.1'

    ext.appLoungeAuthDataVersion = '1.0.0'

    ext.androidMinSdk = 21
    ext.androidTargetSdk = 29
    ext.androidCompileSdk = 34
+3 −0
Original line number Diff line number Diff line
@@ -121,6 +121,9 @@ dependencies {
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
    implementation "androidx.preference:preference-ktx:$preferenceVersion"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"

    // AppLounge AuthData lib
    implementation "foundation.e.apps:auth-data-lib:$appLoungeAuthDataVersion"
}

wire {
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@
        android:name="android.permission.USE_CREDENTIALS"
        android:maxSdkVersion="22" />

    <uses-permission android:name="foundation.e.apps.permission.AUTH_DATA_PROVIDER" />

    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
+43 −0
Original line number Diff line number Diff line
package com.android.vending.licensing

import android.content.Context
import android.net.Uri
import android.util.Log
import foundation.e.apps.authdata.AuthDataContract
import org.microg.vending.billing.core.AuthData

class ContentProviderAuthData(
    private val context: Context
) {
    private var authData: AuthData? = null

    fun fetch(): AuthData? {
        Log.i(TAG, "Fetching auth data")

        val cursor = context.contentResolver.query(
            Uri.parse(AUTH_DATA_AUTHORITIES), null, null, null, null
        )

        if (cursor == null || !cursor.moveToFirst()) {
            return null
        }

        authData = AuthData(
            cursor.getString(cursor.getColumnIndexOrThrow(AuthDataContract.EMAIL_KEY)),
            cursor.getString(cursor.getColumnIndexOrThrow(AuthDataContract.AUTH_TOKEN_KEY)),
            cursor.getString(cursor.getColumnIndexOrThrow(AuthDataContract.GSF_ID_KEY)),
            cursor.getString(cursor.getColumnIndexOrThrow(AuthDataContract.CONSISTENCY_TOKEN_KEY)),
            cursor.getString(cursor.getColumnIndexOrThrow(AuthDataContract.DEVICE_CONFIG_TOKEN_KEY)),
            cursor.getString(cursor.getColumnIndexOrThrow(AuthDataContract.EXPERIMENTS_CONFIG_TOKEN_KEY)),
            cursor.getString(cursor.getColumnIndexOrThrow(AuthDataContract.DFE_COOKIE_KEY))
        )

        cursor.close()
        return authData
    }

    companion object {
        const val TAG = "ContentProviderAuthData"
        const val AUTH_DATA_AUTHORITIES = "content://foundation.e.apps.authdata.provider"
    }
}
+7 −5
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ package com.android.vending.licensing
import android.accounts.Account
import android.accounts.AccountManager
import android.accounts.AccountManagerFuture
import android.accounts.AuthenticatorException
import android.accounts.OperationCanceledException
import android.content.pm.PackageInfo
import android.os.Bundle
@@ -99,7 +98,8 @@ class ErrorResponse(
 */
@Throws(RemoteException::class)
suspend fun HttpClient.checkLicense(
    account: Account,
    account: Account?,
    contentProviderAuthData: ContentProviderAuthData,
    accountManager: AccountManager,
    androidId: String?,
    packageInfo: PackageInfo,
@@ -108,9 +108,11 @@ suspend fun HttpClient.checkLicense(
) : LicenseResponse {

    val auth = try {
        accountManager.getAuthToken(account, AUTH_TOKEN_SCOPE, false)
        account?.let {
            accountManager.getAuthToken(it, AUTH_TOKEN_SCOPE, false)
                .getString(AccountManager.KEY_AUTHTOKEN)
    } catch (e: AuthenticatorException) {
        } ?: contentProviderAuthData.fetch()?.authToken
    } catch (e: Exception) {
        Log.e(TAG, "Could not fetch auth token for account $account")
        return ErrorResponse(ERROR_CONTACTING_SERVER)
    }
Loading