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

Commit 9a5c6568 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

Merge branch '1546-dump_authdata' into 'main'

Issue 1546: Dump authdata

See merge request !356
parents d1a46c82 9d68163c
Loading
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -74,6 +74,15 @@
            </intent-filter>
        </receiver>
        
        <receiver android:name=".receivers.DumpAuthData"
            android:enabled="true"
            android:exported="true"
            tools:ignore="ExportedReceiver">
            <intent-filter>
                <action android:name="foundation.e.apps.action.DUMP_GACCOUNT_INFO"/>
            </intent-filter>
        </receiver>

        <!-- TODO: ExportedReceiver, suppressing because changes are needed in other apps -->
        <receiver android:name=".install.receiver.PWAPlayerStatusReceiver"
            tools:ignore="ExportedReceiver"
+3 −0
Original line number Diff line number Diff line
@@ -6,4 +6,7 @@ object Constants {
    const val PREFERENCE_SHOW_FOSS = "showFOSSApplications"
    const val PREFERENCE_SHOW_PWA = "showPWAApplications"
    const val PREFERENCE_SHOW_GPLAY = "showAllApplications"

    const val ACTION_AUTHDATA_DUMP = "foundation.e.apps.action.DUMP_GACCOUNT_INFO"
    const val TAG_AUTHDATA_DUMP = "AUTHDATA_DUMP"
}
+67 −0
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * 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 <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps.receivers

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.aurora.gplayapi.data.models.AuthData
import com.google.gson.Gson
import foundation.e.apps.data.Constants.ACTION_AUTHDATA_DUMP
import foundation.e.apps.data.Constants.TAG_AUTHDATA_DUMP
import foundation.e.apps.data.preference.DataStoreModule
import org.json.JSONObject
import timber.log.Timber

/**
 * ADB commands:
 *
 * adb logcat -c
 * adb logcat -s "AUTHDATA_DUMP" &
 * adb shell am broadcast -a foundation.e.apps.action.DUMP_GACCOUNT_INFO --receiver-include-background
 */
class DumpAuthData: BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
        if (intent?.action != ACTION_AUTHDATA_DUMP || context == null) {
            return
        }
        getAuthDataDump(context).let {
            Timber.tag(TAG_AUTHDATA_DUMP).i(it)
        }
    }

    private fun getAuthDataDump(context: Context): String {
        val gson = Gson()
        // TODO: replace with context.configuration
        val authData = DataStoreModule(context, gson).getAuthDataSync().let {
            gson.fromJson(it, AuthData::class.java)
        }
        val filteredData = JSONObject().apply {
            put("email", authData.email)
            put("authToken", authData.authToken)
            put("gsfId", authData.gsfId)
            put("locale", authData.locale)
            put("tokenDispenserUrl", authData.tokenDispenserUrl)
            put("deviceCheckInConsistencyToken", authData.deviceCheckInConsistencyToken)
            put("deviceConfigToken", authData.deviceConfigToken)
            put("dfeCookie", authData.dfeCookie)
            put("isAnonymous", authData.isAnonymous)
            put("deviceInfoProvider", authData.deviceInfoProvider)
        }
        return filteredData.toString(4)
    }
}
 No newline at end of file
+1 −1

File changed.

Contains only whitespace changes.