Remove Google integration
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
/build
|
||||
*/**/g_services.json
|
||||
@@ -1,51 +0,0 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.library)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdk = libs.versions.compileSdk.get().toInt()
|
||||
|
||||
defaultConfig {
|
||||
minSdk = libs.versions.minSdk.get().toInt()
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles("consumer-rules.pro")
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
consumerProguardFiles("proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
namespace = "de.mm20.launcher2.gservices"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.bundles.kotlin)
|
||||
implementation(libs.androidx.core)
|
||||
implementation(libs.androidx.appcompat)
|
||||
implementation(libs.androidx.browser)
|
||||
implementation(libs.bundles.androidx.lifecycle)
|
||||
|
||||
implementation(libs.google.auth)
|
||||
implementation(libs.google.apiclient)
|
||||
implementation(libs.google.drive)
|
||||
implementation(libs.google.oauth2)
|
||||
|
||||
implementation(project(":core:i18n"))
|
||||
implementation(project(":core:crashreporter"))
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
-keep class org.apache.** { *; }
|
||||
-dontwarn edu.umd.cs.findbugs.annotations.Nullable
|
||||
-dontwarn java.lang.reflect.AnnotatedType
|
||||
-dontwarn javax.lang.model.element.Modifier
|
||||
-dontwarn javax.script.ScriptEngine
|
||||
-dontwarn javax.script.ScriptEngineManager
|
||||
-dontwarn org.apache.http.client.config.RequestConfig$Builder
|
||||
-dontwarn org.apache.http.client.config.RequestConfig
|
||||
-dontwarn org.apache.http.client.methods.HttpPatch
|
||||
-dontwarn org.apache.http.conn.DnsResolver
|
||||
-dontwarn org.apache.http.conn.HttpClientConnectionManager
|
||||
-dontwarn org.apache.http.conn.HttpConnectionFactory
|
||||
-dontwarn org.apache.http.conn.SchemePortResolver
|
||||
-dontwarn org.apache.http.conn.socket.LayeredConnectionSocketFactory
|
||||
-dontwarn org.apache.http.conn.socket.PlainConnectionSocketFactory
|
||||
-dontwarn org.apache.http.conn.ssl.SSLConnectionSocketFactory
|
||||
-dontwarn org.apache.http.impl.client.CloseableHttpClient
|
||||
-dontwarn org.apache.http.impl.client.HttpClientBuilder
|
||||
-dontwarn org.apache.http.impl.conn.PoolingHttpClientConnectionManager
|
||||
-dontwarn org.apache.http.impl.conn.SystemDefaultRoutePlanner
|
||||
-dontwarn org.bouncycastle.jsse.BCSSLParameters
|
||||
-dontwarn org.bouncycastle.jsse.BCSSLSocket
|
||||
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
|
||||
-dontwarn org.conscrypt.Conscrypt$Version
|
||||
-dontwarn org.conscrypt.Conscrypt
|
||||
-dontwarn org.conscrypt.ConscryptHostnameVerifier
|
||||
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
|
||||
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
|
||||
-dontwarn org.openjsse.net.ssl.OpenJSSE
|
||||
Vendored
-23
@@ -1,23 +0,0 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.kts.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-keep class com.google.** { *; }
|
||||
@@ -1,20 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application>
|
||||
<activity
|
||||
android:name="de.mm20.launcher2.gservices.GoogleAuthRedirectActivity"
|
||||
android:theme="@style/GoogleSigninTheme"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
|
||||
<data
|
||||
android:path="/google-auth-redirect"
|
||||
android:scheme="${applicationId}" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -1,40 +0,0 @@
|
||||
package de.mm20.launcher2.gservices
|
||||
|
||||
import com.google.api.services.drive.model.File
|
||||
import java.util.*
|
||||
|
||||
data class DriveFile(
|
||||
val fileId : String,
|
||||
val label: String,
|
||||
val size: Long,
|
||||
val mimeType : String,
|
||||
val isDirectory : Boolean,
|
||||
val directoryColor: String?,
|
||||
val viewUri: String,
|
||||
val metadata: DriveFileMeta
|
||||
) {
|
||||
companion object {
|
||||
fun fromApiDriveFile(file: File): DriveFile {
|
||||
return DriveFile(
|
||||
fileId = file.id,
|
||||
label = file.name,
|
||||
size = file.getSize() ?: 0,
|
||||
isDirectory = file.mimeType == "application/vnd.google-apps.folder",
|
||||
mimeType = file.mimeType,
|
||||
metadata = DriveFileMeta(
|
||||
owners = file.owners?.map { it.displayName ?: it.emailAddress ?: "" } ?: emptyList(),
|
||||
width = file.imageMediaMetadata?.width ?: file.videoMediaMetadata?.width,
|
||||
height = file.imageMediaMetadata?.height ?: file.videoMediaMetadata?.height
|
||||
),
|
||||
directoryColor = file.folderColorRgb?.lowercase(Locale.ROOT),
|
||||
viewUri = file.webViewLink ?: ""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class DriveFileMeta(
|
||||
val owners : List<String>,
|
||||
val width: Int?,
|
||||
val height: Int?
|
||||
)
|
||||
@@ -1,5 +0,0 @@
|
||||
package de.mm20.launcher2.gservices
|
||||
|
||||
data class GoogleAccount(
|
||||
val name: String
|
||||
)
|
||||
@@ -1,251 +0,0 @@
|
||||
package de.mm20.launcher2.gservices
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.browser.customtabs.*
|
||||
import androidx.core.content.edit
|
||||
import com.google.api.client.auth.oauth2.Credential
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets
|
||||
import com.google.api.client.http.HttpRequestInitializer
|
||||
import com.google.api.client.http.javanet.NetHttpTransport
|
||||
import com.google.api.client.json.gson.GsonFactory
|
||||
import com.google.api.client.util.store.FileDataStoreFactory
|
||||
import com.google.api.services.drive.Drive
|
||||
import com.google.api.services.oauth2.Oauth2
|
||||
import de.mm20.launcher2.crashreporter.CrashReporter
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
class GoogleApiHelper private constructor(private val context: Context) {
|
||||
|
||||
val transport by lazy {
|
||||
NetHttpTransport()
|
||||
}
|
||||
|
||||
suspend fun queryGDriveFiles(query: String): List<DriveFile> {
|
||||
val requestInitializer = getRequestInitializer() ?: return emptyList()
|
||||
val jsonFactory = GsonFactory.getDefaultInstance()
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val drive =
|
||||
Drive.Builder(transport, jsonFactory, requestInitializer).build()
|
||||
val request = drive.files().list()
|
||||
request.q = "name contains '${query.replace("'", "")}'"
|
||||
request.pageSize = 10
|
||||
request.fields =
|
||||
"files(id, webViewLink, size, name, mimeType, owners, imageMediaMetadata, videoMediaMetadata, folderColorRgb)"
|
||||
request.corpora = "user"
|
||||
val response = request.execute()
|
||||
val files = response.files ?: return@withContext emptyList()
|
||||
files.map { DriveFile.fromApiDriveFile(it) }
|
||||
|
||||
} catch (e: IOException) {
|
||||
emptyList()
|
||||
} catch (e: Error) {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getCredential(): Credential? {
|
||||
val authFlow = getAuthFlow() ?: return null
|
||||
return withContext(Dispatchers.IO) {
|
||||
val credential: Credential? = authFlow.loadCredential(USER_ID)
|
||||
if ((credential?.expiresInSeconds ?: 0) < 5 * 60) {
|
||||
try {
|
||||
if (credential?.refreshToken() == false) return@withContext null
|
||||
} catch (e: IOException) {
|
||||
CrashReporter.logException(e)
|
||||
}
|
||||
}
|
||||
return@withContext credential
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getRequestInitializer(): HttpRequestInitializer? {
|
||||
val credential = getCredential() ?: return null
|
||||
|
||||
return HttpRequestInitializer { request ->
|
||||
credential.initialize(request)
|
||||
request?.connectTimeout = 5000
|
||||
request?.readTimeout = 10000
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getAccount(): GoogleAccount? {
|
||||
|
||||
val name = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getString(
|
||||
PREF_ACCOUNT_NAME,
|
||||
null
|
||||
) ?: loadAccountName()
|
||||
|
||||
|
||||
return name?.let {
|
||||
GoogleAccount(name = it)
|
||||
}
|
||||
}
|
||||
|
||||
fun isAvailable(): Boolean {
|
||||
return getConfigResId() != 0
|
||||
}
|
||||
|
||||
private fun getConfigResId(): Int {
|
||||
return context.resources.getIdentifier("g_services", "raw", context.packageName)
|
||||
}
|
||||
|
||||
|
||||
private fun getAuthFlow(throwErrors: Boolean = false): GoogleAuthorizationCodeFlow? {
|
||||
val configResId = getConfigResId()
|
||||
if (configResId == 0) return null
|
||||
val jsonFactory = GsonFactory.getDefaultInstance()
|
||||
try {
|
||||
return GoogleAuthorizationCodeFlow.Builder(
|
||||
NetHttpTransport(),
|
||||
jsonFactory,
|
||||
GoogleClientSecrets.load(
|
||||
jsonFactory,
|
||||
context.resources.openRawResource(configResId).reader()
|
||||
),
|
||||
SCOPES
|
||||
)
|
||||
.setCredentialDataStore(
|
||||
FileDataStoreFactory(context.filesDir).getDataStore(
|
||||
"google_signin"
|
||||
)
|
||||
)
|
||||
.build()
|
||||
} catch (e: IOException) {
|
||||
if (throwErrors) throw e
|
||||
else {
|
||||
File(context.filesDir, "google_signin").delete()
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit {
|
||||
putString(PREF_ACCOUNT_NAME, null)
|
||||
}
|
||||
Log.e("MM20", "Google account has been reset because data store couldn't be readg")
|
||||
CrashReporter.logException(e)
|
||||
return getAuthFlow(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var callback: (() -> Unit)? = null
|
||||
|
||||
suspend fun login(activity: Activity) {
|
||||
val authFlow = getAuthFlow() ?: return
|
||||
|
||||
suspendCancellableCoroutine<Unit> {
|
||||
val url = authFlow
|
||||
.newAuthorizationUrl()
|
||||
.setRedirectUri(getRedirectUri())
|
||||
.toString()
|
||||
val themeColor = 0xFF4285f4.toInt()
|
||||
|
||||
val customTabsIntent = CustomTabsIntent
|
||||
.Builder()
|
||||
.setDefaultColorSchemeParams(
|
||||
CustomTabColorSchemeParams.Builder()
|
||||
.setToolbarColor(themeColor)
|
||||
.setNavigationBarColor(themeColor)
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
|
||||
callingActivity = activity.javaClass
|
||||
callback = {
|
||||
it.resumeWith(Result.success(Unit))
|
||||
}
|
||||
it.invokeOnCancellation {
|
||||
callback = null
|
||||
Log.d("MM20", "Google Signin has been canceled")
|
||||
}
|
||||
|
||||
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
|
||||
customTabsIntent.launchUrl(activity, Uri.parse(url))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun finishAuthFlow(activity: Activity, code: String) {
|
||||
val authFlow = getAuthFlow() ?: return
|
||||
withContext(Dispatchers.IO) {
|
||||
val tokenResponse = try {
|
||||
authFlow.newTokenRequest(code).setRedirectUri(getRedirectUri()).execute()
|
||||
} catch (e: IOException) {
|
||||
CrashReporter.logException(e)
|
||||
return@withContext
|
||||
}
|
||||
authFlow.createAndStoreCredential(tokenResponse, USER_ID)
|
||||
}
|
||||
loadAccountName()
|
||||
returnToPreviousActivity(activity)
|
||||
}
|
||||
|
||||
fun cancelAuthFlow(activity: Activity) {
|
||||
returnToPreviousActivity(activity)
|
||||
}
|
||||
|
||||
private fun returnToPreviousActivity(activity: Activity) {
|
||||
val intent = Intent(activity, callingActivity)
|
||||
callingActivity = null
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
activity.startActivity(intent)
|
||||
callback?.invoke()
|
||||
}
|
||||
|
||||
private suspend fun loadAccountName(): String? {
|
||||
val requestInitializer = getRequestInitializer() ?: return null
|
||||
val jsonFactory = GsonFactory.getDefaultInstance()
|
||||
val oauth2 = Oauth2.Builder(transport, jsonFactory, requestInitializer).build()
|
||||
try {
|
||||
val meResponse = withContext(Dispatchers.IO) {
|
||||
oauth2.userinfo().v2().me().get().execute()
|
||||
}
|
||||
if (meResponse != null) {
|
||||
val name = meResponse.name
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit {
|
||||
putString(PREF_ACCOUNT_NAME, name)
|
||||
}
|
||||
return name
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
CrashReporter.logException(e)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
fun logout() {
|
||||
val authFlow = getAuthFlow() ?: return
|
||||
authFlow.credentialDataStore.clear()
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit {
|
||||
putString(PREF_ACCOUNT_NAME, null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getRedirectUri(): String {
|
||||
return "${context.packageName}:/google-auth-redirect"
|
||||
}
|
||||
|
||||
companion object {
|
||||
private lateinit var instance: GoogleApiHelper
|
||||
|
||||
fun getInstance(context: Context): GoogleApiHelper {
|
||||
if (!::instance.isInitialized) instance = GoogleApiHelper(context.applicationContext)
|
||||
return instance
|
||||
}
|
||||
|
||||
val SCOPES = setOf("https://www.googleapis.com/auth/drive.metadata.readonly", "profile")
|
||||
const val USER_ID = "google-user"
|
||||
const val PREFS = "google-account"
|
||||
const val PREF_ACCOUNT_NAME = "name"
|
||||
|
||||
private var callingActivity: Class<Activity>? = null
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package de.mm20.launcher2.gservices
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class GoogleAuthRedirectActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val gServiceHelper = GoogleApiHelper.getInstance(this)
|
||||
val code = intent.data?.getQueryParameter("code")
|
||||
if (code == null) {
|
||||
gServiceHelper.cancelAuthFlow(this)
|
||||
finish()
|
||||
}
|
||||
else {
|
||||
lifecycleScope.launch {
|
||||
gServiceHelper.finishAuthFlow(this@GoogleAuthRedirectActivity, code)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="46dp"
|
||||
android:height="46dp"
|
||||
android:viewportWidth="46"
|
||||
android:viewportHeight="46">
|
||||
<path
|
||||
android:pathData="m45.265,23.521c0,-1.624 -0.146,-3.186 -0.416,-4.685L23.278,18.836L23.278,27.695L35.604,27.695c-0.531,2.863 -2.145,5.288 -4.57,6.912v5.747h7.402c4.331,-3.987 6.829,-9.859 6.829,-16.834z"
|
||||
android:strokeWidth="2.54476"
|
||||
android:fillColor="#4285f4"
|
||||
android:fillType="evenOdd"
|
||||
android:strokeColor="#00000000"/>
|
||||
<path
|
||||
android:pathData="m23.278,45.903c6.184,0 11.368,-2.051 15.157,-5.549l-7.402,-5.747c-2.051,1.374 -4.674,2.186 -7.756,2.186 -5.965,0 -11.014,-4.029 -12.815,-9.442h-7.652v5.934C6.58,40.77 14.325,45.903 23.278,45.903Z"
|
||||
android:strokeWidth="2.54476"
|
||||
android:fillColor="#34a853"
|
||||
android:fillType="evenOdd"
|
||||
android:strokeColor="#00000000"/>
|
||||
<path
|
||||
android:pathData="M10.463,27.352C10.005,25.977 9.745,24.509 9.745,23c0,-1.51 0.26,-2.977 0.718,-4.352L10.463,12.715L2.811,12.715C1.26,15.806 0.375,19.304 0.375,23c0,3.696 0.885,7.194 2.436,10.285z"
|
||||
android:strokeWidth="2.54476"
|
||||
android:fillColor="#fbbc05"
|
||||
android:fillType="evenOdd"
|
||||
android:strokeColor="#00000000"/>
|
||||
<path
|
||||
android:pathData="m23.278,9.206c3.363,0 6.382,1.156 8.755,3.425l6.569,-6.569C34.636,2.367 29.451,0.097 23.278,0.097c-8.953,0 -16.698,5.132 -20.467,12.617l7.652,5.934c1.801,-5.413 6.85,-9.442 12.815,-9.442z"
|
||||
android:strokeWidth="2.54476"
|
||||
android:fillColor="#ea4335"
|
||||
android:fillType="evenOdd"
|
||||
android:strokeColor="#00000000"/>
|
||||
</vector>
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="GoogleSigninTheme" parent="@style/Theme.AppCompat.NoActionBar">
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -1 +0,0 @@
|
||||
{"installed":{"client_id":"xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com","project_id":"xxxxx-xxxxxxxxxxxxx","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
|
||||
Reference in New Issue
Block a user