Skip to content
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

[Identity] Add support for http logoUri #4851

Merged
merged 3 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions identity/res/drawable/ic_baseline_question_mark_32.xml

This file was deleted.

1 change: 0 additions & 1 deletion identity/res/layout/consent_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@

<ImageView
android:id="@+id/merchant_logo"
android:src="@drawable/ic_baseline_question_mark_32"
android:layout_width="32dp"
android:layout_height="32dp" />

Expand Down
5 changes: 4 additions & 1 deletion identity/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.stripe.android.identity">

<uses-permission android:name="android.permission.CAMERA" />

<application>
<application
android:usesCleartextTraffic="true"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tag is required for accessing http:// links over api version m

tools:targetApi="m">
<activity
android:name=".IdentityActivity"
android:screenOrientation="portrait"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.identity.viewmodel

import android.net.Uri
import android.util.Log
import android.widget.ImageView
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
Expand All @@ -15,24 +16,26 @@ internal class ConsentFragmentViewModel(
private val identityRepository: IdentityRepository
) : ViewModel() {

private fun Uri.isRemote() = this.scheme == "https" || this.scheme == "http"

fun loadUriIntoImageView(
uri: Uri,
logoUri: Uri,
imageView: ImageView
) {
viewModelScope.launch(Dispatchers.IO) {
imageView.setImageURI(
when (uri.scheme) {
"https" -> {
identityIO.createUriForFile(identityRepository.downloadFile(uri.toString()))
}
"http" -> {
throw IllegalArgumentException("Only https is supported for remote Uri")
}
else -> {
uri
runCatching {
imageView.setImageURI(
if (logoUri.isRemote()) {
identityIO.createUriForFile(
identityRepository.downloadFile(logoUri.toString())
)
} else {
logoUri
}
}
)
)
}.onFailure {
Log.e(TAG, "Failed to set logoUri at $logoUri: $it")
}
}
}

Expand All @@ -48,4 +51,8 @@ internal class ConsentFragmentViewModel(
) as T
}
}

private companion object {
private val TAG: String = ConsentFragmentViewModel::class.java.simpleName
}
}
8 changes: 0 additions & 8 deletions stripe-core/api/stripe-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,6 @@ public final class com/stripe/android/core/networking/RetryDelaySupplier_Factory
public static fun newInstance ()Lcom/stripe/android/core/networking/RetryDelaySupplier;
}

public abstract class com/stripe/android/core/networking/StripeConnection$AbstractConnection : com/stripe/android/core/networking/StripeConnection {
public static final field $stable I
public fun <init> (Ljavax/net/ssl/HttpsURLConnection;)V
public fun close ()V
public synthetic fun getResponse ()Lcom/stripe/android/core/networking/StripeResponse;
public synthetic fun getResponseCode ()I
}

public final class com/stripe/android/core/networking/StripeConnection$Default : com/stripe/android/core/networking/StripeConnection$AbstractConnection {
public static final field $stable I
public synthetic fun createBodyFromResponseStream (Ljava/io/InputStream;)Ljava/lang/Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import androidx.annotation.RestrictTo
import com.stripe.android.core.exception.InvalidRequestException
import java.io.File
import java.io.IOException
import java.net.HttpURLConnection
import java.net.URL
import java.util.concurrent.TimeUnit
import javax.net.ssl.HttpsURLConnection

/**
* Factory to create [StripeConnection], which encapsulates an [HttpsURLConnection], triggers the
* Factory to create [StripeConnection], which encapsulates an [HttpURLConnection], triggers the
* request and parses the response with different body type as [StripeResponse].
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
Expand Down Expand Up @@ -43,8 +43,8 @@ interface ConnectionFactory {
)
}

private fun openConnectionAndApplyFields(request: StripeRequest): HttpsURLConnection {
return (URL(request.url).openConnection() as HttpsURLConnection).apply {
private fun openConnectionAndApplyFields(request: StripeRequest): HttpURLConnection {
return (URL(request.url).openConnection() as HttpURLConnection).apply {
connectTimeout = CONNECT_TIMEOUT
readTimeout = READ_TIMEOUT
useCaches = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.io.InputStream
import java.net.HttpURLConnection
import java.nio.charset.StandardCharsets
import java.util.Scanner
import javax.net.ssl.HttpsURLConnection

/**
* A wrapper for accessing a [HttpURLConnection]. Implements [Closeable] to simplify closing related
Expand All @@ -21,8 +20,9 @@ interface StripeConnection<ResponseBodyType> : Closeable {
val response: StripeResponse<ResponseBodyType>
fun createBodyFromResponseStream(responseStream: InputStream?): ResponseBodyType?

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
abstract class AbstractConnection<ResponseBodyType>(
private val conn: HttpsURLConnection
private val conn: HttpURLConnection
) : StripeConnection<ResponseBodyType> {
override val responseCode: Int
@JvmSynthetic
Expand Down Expand Up @@ -67,7 +67,7 @@ interface StripeConnection<ResponseBodyType> : Closeable {
* Default [StripeConnection] that converts the ResponseStream to a String.
*/
class Default internal constructor(
conn: HttpsURLConnection
conn: HttpURLConnection
) : AbstractConnection<String>(conn = conn) {

/**
Expand Down Expand Up @@ -95,7 +95,7 @@ interface StripeConnection<ResponseBodyType> : Closeable {
* [StripeConnection] that writes the ResponseStream to a File.
*/
class FileConnection internal constructor(
conn: HttpsURLConnection,
conn: HttpURLConnection,
private val outputFile: File
) : AbstractConnection<File>(conn = conn) {

Expand Down