-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
DynamicLink: Added network connection conversion processing #2662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c2f3f20
DynamicLink: Added network connection conversion processing
DaVinci9196 cc7b9ea
Merge into common requests
DaVinci9196 d651b5e
cleanup code
DaVinci9196 5c09a06
Improve the createShortDynamicLink method
DaVinci9196 e75f8ae
optimized
DaVinci9196 25c0f64
cleanUp
DaVinci9196 95d3fd7
cleanUp
DaVinci9196 21b1185
handle exceptions
DaVinci9196 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
play-services-base/core/src/main/kotlin/org/microg/gms/utils/DynamicLinkUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2024 microG Project Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.microg.gms.utils | ||
|
|
||
| import android.content.Context | ||
| import android.os.Build.VERSION.SDK_INT | ||
| import android.os.LocaleList | ||
| import com.android.volley.NetworkResponse | ||
| import com.android.volley.ParseError | ||
| import com.android.volley.Request | ||
| import com.android.volley.Request.Method.POST | ||
| import com.android.volley.RequestQueue | ||
| import com.android.volley.Response | ||
| import com.android.volley.VolleyError | ||
| import com.android.volley.toolbox.HttpHeaderParser | ||
| import com.android.volley.toolbox.JsonRequest | ||
| import com.squareup.wire.Message | ||
| import com.squareup.wire.ProtoAdapter | ||
| import kotlinx.coroutines.CompletableDeferred | ||
| import okio.ByteString.Companion.decodeHex | ||
| import org.json.JSONException | ||
| import org.json.JSONObject | ||
| import org.microg.gms.ClientIdInfo | ||
| import org.microg.gms.ClientPlatform | ||
| import org.microg.gms.LinkInfo | ||
| import org.microg.gms.MutateAppInviteLinkRequest | ||
| import org.microg.gms.MutateAppInviteLinkResponse | ||
| import org.microg.gms.MutateDataRequest | ||
| import org.microg.gms.MutateDataResponseWithError | ||
| import org.microg.gms.MutateOperation | ||
| import org.microg.gms.MutateOperationId | ||
| import org.microg.gms.SystemInfo | ||
| import org.microg.gms.common.Constants | ||
| import java.io.UnsupportedEncodingException | ||
| import java.nio.charset.Charset | ||
| import java.util.HashMap | ||
| import java.util.Locale | ||
| import kotlin.collections.firstOrNull | ||
| import kotlin.coroutines.resume | ||
| import kotlin.coroutines.resumeWithException | ||
| import kotlin.coroutines.suspendCoroutine | ||
|
|
||
| object DynamicLinkUtils { | ||
|
|
||
| suspend fun requestLinkResponse(linkUrl: String, queue: RequestQueue): MutateAppInviteLinkResponse? { | ||
| val request = ProtobufPostRequest( | ||
| "https://datamixer-pa.googleapis.com/v1/mutateonekey?alt=proto&key=AIzaSyAP-gfH3qvi6vgHZbSYwQ_XHqV_mXHhzIk", MutateOperation( | ||
| id = MutateOperationId.AppInviteLink, mutateRequest = MutateDataRequest( | ||
| appInviteLink = MutateAppInviteLinkRequest( | ||
| client = ClientIdInfo( | ||
| platform = ClientPlatform.Android, | ||
| packageName = Constants.GMS_PACKAGE_NAME, | ||
| signature = Constants.GMS_PACKAGE_SIGNATURE_SHA1.decodeHex().base64(), | ||
| language = Locale.getDefault().language | ||
| ), link = LinkInfo( | ||
| invitationId = "", uri = linkUrl | ||
| ), system = SystemInfo( | ||
| gms = SystemInfo.GmsInfo( | ||
| versionCode = Constants.GMS_VERSION_CODE | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ), MutateDataResponseWithError.ADAPTER | ||
| ) | ||
| val response = try { | ||
| request.sendAndAwait(queue) | ||
| } catch (e: Exception) { | ||
| return null | ||
| } | ||
| if (response.errorStatus != null || response.dataResponse?.appInviteLink == null) return null | ||
| return response.dataResponse?.appInviteLink | ||
| } | ||
|
|
||
| suspend fun requestShortLinks(context: Context, packageName: String, apiKey: String, longDynamicLink: String, queue: RequestQueue) = suspendCoroutine<JSONObject> { con -> | ||
| queue.add(object : JsonRequest<JSONObject>(POST, "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=$apiKey", JSONObject().apply { | ||
| put("longDynamicLink", longDynamicLink) | ||
| }.toString(), { | ||
| con.resume(it) | ||
| }, { | ||
| con.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), null) | ||
| } catch (e: UnsupportedEncodingException) { | ||
| Response.error(ParseError(e)) | ||
| } catch (je: JSONException) { | ||
| Response.error(ParseError(je)) | ||
| } | ||
| } | ||
|
|
||
| override fun getHeaders(): Map<String, String?> = mapOf( | ||
| "X-Android-Package" to packageName, | ||
| "X-Android-Cert" to context.packageManager.getCertificates(packageName).firstOrNull()?.digest("SHA1")?.toHexString()?.uppercase() | ||
| ) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| internal class ProtobufPostRequest<I : Message<I, *>, O>(url: String, private val i: I, private val oAdapter: ProtoAdapter<O>) : Request<O>(Method.POST, url, null) { | ||
| private val deferred = CompletableDeferred<O>() | ||
|
|
||
| override fun getHeaders(): Map<String, String> { | ||
| val headers = HashMap(super.getHeaders()) | ||
| headers["Accept-Language"] = if (SDK_INT >= 24) LocaleList.getDefault().toLanguageTags() else Locale.getDefault().language | ||
| headers["X-Android-Package"] = Constants.GMS_PACKAGE_NAME | ||
| headers["X-Android-Cert"] = Constants.GMS_PACKAGE_SIGNATURE_SHA1 | ||
| return headers | ||
| } | ||
|
|
||
| override fun getBody(): ByteArray = i.encode() | ||
|
|
||
| override fun getBodyContentType(): String = "application/x-protobuf" | ||
|
|
||
| override fun parseNetworkResponse(response: NetworkResponse): Response<O> { | ||
| return try { | ||
| Response.success(oAdapter.decode(response.data), null) | ||
| } catch (e: VolleyError) { | ||
| Response.error(e) | ||
| } catch (e: Exception) { | ||
| Response.error(VolleyError()) | ||
| } | ||
| } | ||
|
|
||
| override fun deliverResponse(response: O) { | ||
| deferred.complete(response) | ||
| } | ||
|
|
||
| override fun deliverError(error: VolleyError) { | ||
| deferred.completeExceptionally(error) | ||
| } | ||
|
|
||
| suspend fun await(): O = deferred.await() | ||
|
|
||
| suspend fun sendAndAwait(queue: RequestQueue): O { | ||
| queue.add(this) | ||
| return await() | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
...nvite/core/src/main/proto/datamixer.proto → ...core-proto/src/main/proto/datamixer.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
...services-core/src/main/java/org/microg/gms/firebase/dynamiclinks/DynamicLinksService.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.