Skip to content

Commit

Permalink
Merge branch 'microg:master' into patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
ale5000-git authored Aug 13, 2023
2 parents d58520b + 4651ed5 commit 6caa59e
Show file tree
Hide file tree
Showing 525 changed files with 38,385 additions and 3,901 deletions.
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ buildscript {
ext.androidTargetSdk = 29
ext.androidCompileSdk = 33

ext.localProperties = new Properties()

try {
ext.localProperties.load(rootProject.file('local.properties').newDataInputStream())
} catch (ignored) {
// Ignore
}

repositories {
mavenCentral()
google()
Expand All @@ -59,7 +67,7 @@ def execResult(...args) {
return stdout.toString()
}

def gmsVersion = "22.36.16"
def gmsVersion = "23.16.57"
def gmsVersionCode = Integer.parseInt(gmsVersion.replaceAll('\\.', ''))
def gitVersionBase = execResult('git', 'describe', '--tags', '--abbrev=0', '--match=v[0-9]*').trim().substring(1)
def gitCommitCount = Integer.parseInt(execResult('git', 'rev-list', '--count', "v$gitVersionBase..HEAD").trim())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.Handler
import android.os.Parcel
import android.provider.Telephony
Expand Down Expand Up @@ -62,7 +62,7 @@ private val UserProfileChangeRequest.deleteAttributeList: List<String>
}

private fun Intent.getSmsMessages(): Array<SmsMessage> {
return if (Build.VERSION.SDK_INT >= 19) {
return if (SDK_INT >= 19) {
Telephony.Sms.Intents.getMessagesFromIntent(this)
} else {
(getSerializableExtra("pdus") as? Array<ByteArray>)?.map { SmsMessage.createFromPdu(it) }.orEmpty().toTypedArray()
Expand All @@ -83,7 +83,7 @@ class FirebaseAuthService : BaseService(TAG, GmsService.FIREBASE_AUTH) {
}

class FirebaseAuthServiceImpl(private val context: Context, private val lifecycle: Lifecycle, private val packageName: String, private val libraryVersion: String?, private val apiKey: String) : IFirebaseAuthService.Stub(), LifecycleOwner {
private val client = IdentityToolkitClient(context, apiKey)
private val client by lazy { IdentityToolkitClient(context, apiKey, packageName, PackageUtils.firstSignatureDigestBytes(context, packageName)) }
private var authorizedDomain: String? = null

private suspend fun getAuthorizedDomain(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.android.volley.toolbox.Volley
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
import org.microg.gms.utils.toHexString
import java.io.UnsupportedEncodingException
import java.lang.RuntimeException
import java.nio.charset.Charset
Expand All @@ -29,19 +30,26 @@ import kotlin.coroutines.suspendCoroutine

private const val TAG = "GmsFirebaseAuthClient"

class IdentityToolkitClient(context: Context, private val apiKey: String) {
class IdentityToolkitClient(context: Context, private val apiKey: String, private val packageName: String? = null, private val certSha1Hash: ByteArray? = null) {
private val queue = Volley.newRequestQueue(context)

private fun buildRelyingPartyUrl(method: String) = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/$method?key=$apiKey"
private fun buildStsUrl(method: String) = "https://securetoken.googleapis.com/v1/$method?key=$apiKey"

private fun getRequestHeaders(): Map<String, String> = hashMapOf<String, String>().apply {
if (packageName != null) put("X-Android-Package", packageName)
if (certSha1Hash != null) put("X-Android-Cert", certSha1Hash.toHexString().uppercase())
}

private suspend fun request(method: String, data: JSONObject): JSONObject = suspendCoroutine { continuation ->
queue.add(JsonObjectRequest(POST, buildRelyingPartyUrl(method), data, {
queue.add(object : JsonObjectRequest(POST, buildRelyingPartyUrl(method), data, {
continuation.resume(it)
}, {
Log.d(TAG, String(it.networkResponse.data))
Log.d(TAG, "Error: ${it.networkResponse?.data?.decodeToString() ?: it.message}")
continuation.resumeWithException(RuntimeException(it))
}))
}) {
override fun getHeaders(): Map<String, String> = getRequestHeaders()
})
}

suspend fun createAuthUri(identifier: String? = null, tenantId: String? = null, continueUri: String? = "http://localhost"): JSONObject =
Expand Down Expand Up @@ -117,23 +125,23 @@ class IdentityToolkitClient(context: Context, private val apiKey: String) {
.put("sessionInfo", sessionInfo))

suspend fun getTokenByRefreshToken(refreshToken: String): JSONObject = suspendCoroutine { continuation ->
queue.add(StsRequest(POST, buildStsUrl("token"), "grant_type=refresh_token&refresh_token=$refreshToken", { continuation.resume(it) }, { continuation.resumeWithException(RuntimeException(it)) }))
}
}

private class StsRequest(method: Int, url: String, request: String?, listener: (JSONObject) -> Unit, errorListener: (VolleyError) -> Unit) : JsonRequest<JSONObject>(method, url, request, listener, errorListener) {
override fun parseNetworkResponse(response: NetworkResponse?): Response<JSONObject> {
return try {
val jsonString = String(response!!.data, Charset.forName(HttpHeaderParser.parseCharset(response!!.headers, PROTOCOL_CHARSET)))
Response.success(JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response))
} catch (e: UnsupportedEncodingException) {
Response.error(ParseError(e))
} catch (je: JSONException) {
Response.error(ParseError(je))
}
}

override fun getBodyContentType(): String {
return "application/x-www-form-urlencoded"
queue.add(object : JsonRequest<JSONObject>(POST, buildStsUrl("token"), "grant_type=refresh_token&refresh_token=$refreshToken", { continuation.resume(it) }, { continuation.resumeWithException(RuntimeException(it)) }) {
override fun parseNetworkResponse(response: NetworkResponse?): Response<JSONObject> {
return try {
val jsonString = String(response!!.data, Charset.forName(HttpHeaderParser.parseCharset(response!!.headers, PROTOCOL_CHARSET)))
Response.success(JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response))
} catch (e: UnsupportedEncodingException) {
Response.error(ParseError(e))
} catch (je: JSONException) {
Response.error(ParseError(je))
}
}

override fun getBodyContentType(): String {
return "application/x-www-form-urlencoded"
}

override fun getHeaders(): Map<String, String> = getRequestHeaders()
})
}
}
}
32 changes: 32 additions & 0 deletions play-services-ads-base/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'signing'

android {
compileSdkVersion androidCompileSdk
buildToolsVersion "$androidBuildVersionTools"

defaultConfig {
versionName version
minSdkVersion androidMinSdk
targetSdkVersion androidTargetSdk
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

apply from: '../gradle/publish-android.gradle'

description = 'microG implementation of play-services-ads-base'

dependencies {
api project(':play-services-basement')
}
7 changes: 7 additions & 0 deletions play-services-ads-base/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: 2023 microG Project Team
~ SPDX-License-Identifier: Apache-2.0
-->

<manifest package="com.google.android.gms.ads_base"/>
32 changes: 32 additions & 0 deletions play-services-ads-identifier/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'signing'

android {
compileSdkVersion androidCompileSdk
buildToolsVersion "$androidBuildVersionTools"

defaultConfig {
versionName version
minSdkVersion androidMinSdk
targetSdkVersion androidTargetSdk
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

apply from: '../gradle/publish-android.gradle'

description = 'microG implementation of play-services-ads-identifier'

dependencies {
api project(':play-services-basement')
}
32 changes: 32 additions & 0 deletions play-services-ads-identifier/core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

dependencies {
api project(':play-services-ads-identifier')
implementation project(':play-services-base-core')
}

android {
compileSdkVersion androidCompileSdk
buildToolsVersion "$androidBuildVersionTools"

defaultConfig {
versionName version
minSdkVersion androidMinSdk
targetSdkVersion androidTargetSdk
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
17 changes: 17 additions & 0 deletions play-services-ads-identifier/core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ SPDX-FileCopyrightText: 2023 microG Project Team
~ SPDX-License-Identifier: Apache-2.0
-->

<manifest package="org.microg.gms.ads.identifier"
xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<service android:name=".AdvertisingIdService">
<intent-filter>
<action android:name="com.google.android.gms.ads.identifier.service.START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/
package org.microg.gms.ads.identifier

import android.app.Service
import android.content.Intent
import android.os.IBinder
import com.google.android.gms.ads.identifier.internal.IAdvertisingIdService

class AdvertisingIdService : Service() {
override fun onBind(intent: Intent): IBinder? {
return AdvertisingIdServiceImpl().asBinder()
}
}

class AdvertisingIdServiceImpl : IAdvertisingIdService.Stub() {
override fun getAdvertisingId(): String {
return "00000000-0000-0000-0000-000000000000"
}

override fun isAdTrackingLimited(defaultHint: Boolean): Boolean {
return true
}

override fun generateAdvertisingId(packageName: String): String {
return advertisingId // Ad tracking limited
}

override fun setAdTrackingLimited(packageName: String, limited: Boolean) {
// Ignored, sorry :)
}
}
7 changes: 7 additions & 0 deletions play-services-ads-identifier/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: 2023 microG Project Team
~ SPDX-License-Identifier: Apache-2.0
-->

<manifest package="com.google.android.gms.ads.identifier"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
* Notice: Portions of this file are reproduced from work created and shared by Google and used
* according to terms described in the Creative Commons 4.0 Attribution License.
* See https://developers.google.com/readme/policies for details.
*/

package com.google.android.gms.ads.identifier;

import android.app.Activity;
import android.content.Context;
import android.provider.Settings;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;

import java.io.IOException;

/**
* Helper library for retrieval of advertising ID and related information such as the limit ad tracking setting.
* <p>
* It is intended that the advertising ID completely replace existing usage of other identifiers for ads purposes (such as use
* of {@code ANDROID_ID} in {@link Settings.Secure}) when Google Play Services is available. Cases where Google Play Services is
* unavailable are indicated by a {@link GooglePlayServicesNotAvailableException} being thrown by getAdvertisingIdInfo().
*/
public class AdvertisingIdClient {
/**
* Retrieves the user's advertising ID and limit ad tracking preference.
* <p>
* This method cannot be called in the main thread as it may block leading to ANRs. An {@code IllegalStateException} will be
* thrown if this is called on the main thread.
*
* @param context Current {@link Context} (such as the current {@link Activity}).
* @return AdvertisingIdClient.Info with user's advertising ID and limit ad tracking preference.
* @throws IOException signaling connection to Google Play Services failed.
* @throws IllegalStateException indicating this method was called on the main thread.
* @throws GooglePlayServicesNotAvailableException indicating that Google Play is not installed on this device.
* @throws GooglePlayServicesRepairableException indicating that there was a recoverable error connecting to Google Play Services.
*/
public static Info getAdvertisingIdInfo(Context context) {
// We don't actually implement this functionality, but always claim that ad tracking was limited by user preference
return new Info("00000000-0000-0000-0000-000000000000", true);
}

/**
* Includes both the advertising ID as well as the limit ad tracking setting.
*/
public static class Info {
private final String advertisingId;
private final boolean limitAdTrackingEnabled;

/**
* Constructs an {@code Info} Object with the specified advertising Id and limit ad tracking setting.
*
* @param advertisingId The advertising ID.
* @param limitAdTrackingEnabled The limit ad tracking setting. It is true if the user has limit ad tracking enabled. False, otherwise.
*/
public Info(String advertisingId, boolean limitAdTrackingEnabled) {
this.advertisingId = advertisingId;
this.limitAdTrackingEnabled = limitAdTrackingEnabled;
}

/**
* Retrieves the advertising ID.
*/
public String getId() {
return advertisingId;
}

/**
* Retrieves whether the user has limit ad tracking enabled or not.
* <p>
* When the returned value is true, the returned value of {@link #getId()} will always be
* {@code 00000000-0000-0000-0000-000000000000} starting with Android 12.
*/
public boolean isLimitAdTrackingEnabled() {
return limitAdTrackingEnabled;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2022 microG Project Team
* SPDX-License-Identifier: CC-BY-4.0
* Notice: Portions of this file are reproduced from work created and shared by Google and used
* according to terms described in the Creative Commons 4.0 Attribution License.
* See https://developers.google.com/readme/policies for details.
*/
/**
* Contains classes relating to the Android Advertising ID (AAID).
*/
package com.google.android.gms.ads.identifier;
Loading

0 comments on commit 6caa59e

Please sign in to comment.