Skip to content

Commit

Permalink
Corrected Configuration and Compatibility (#467)
Browse files Browse the repository at this point in the history
* These are already overridden in the root build.gradle.

* Cleaner toml.

* Can't hurt to also specify this.

* Required for usage in monorepo, otherwise subsequent builds fail.

* dependsOn Kotlin Compile

* More Visibility for Kotlin.

* Fixed compatibility after binary compatibility update.
  • Loading branch information
handstandsam authored Oct 3, 2022
1 parent d45dd9e commit 009c8eb
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 45 deletions.
60 changes: 27 additions & 33 deletions dropbox-sdk-android/src/main/java/com/dropbox/core/android/Auth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public class Auth {
}

/**
*
*
* @param scope A list of scope strings. Each scope correspond to a group of
* API endpoints. To call one API endpoint you have to obtains the scope first otherwise you
* will get HTTP 401.
Expand Down Expand Up @@ -294,43 +292,40 @@ public class Auth {
}

@JvmStatic
public val oAuth2Token: String?
get() {
val credential = dbxCredential ?: return null
return credential.accessToken
}
public fun getOAuth2Token(): String? {
val credential = getDbxCredential() ?: return null
return credential.accessToken
}

@JvmStatic
public val uid: String?
get() {
if (dbxCredential == null) {
return null
}
val data = AuthActivity.result
return data!!.getStringExtra(DropboxAuthIntent.EXTRA_UID)
public fun getUid(): String? {
if (getDbxCredential() == null) {
return null
}
val data = AuthActivity.result
return data!!.getStringExtra(DropboxAuthIntent.EXTRA_UID)
}

/**
*
*
* @return The result after
*/
@JvmStatic
public val dbxCredential: DbxCredential?
get() {
val data = AuthActivity.result ?: return null
val token = data.getStringExtra(DropboxAuthIntent.EXTRA_ACCESS_TOKEN)
val secret = data.getStringExtra(DropboxAuthIntent.EXTRA_ACCESS_SECRET)
val uid = data.getStringExtra(DropboxAuthIntent.EXTRA_UID)
if (token == null || "" == token || secret == null || "" == secret || uid == null || "" == uid) {
return null
}
val appKey = data.getStringExtra(DropboxAuthIntent.EXTRA_CONSUMER_KEY)
val refreshToken = data.getStringExtra(DropboxAuthIntent.EXTRA_REFRESH_TOKEN)
val expiresAt = data.getLongExtra(DropboxAuthIntent.EXTRA_EXPIRES_AT, -1)
val nullableExpiresAt = if (expiresAt >= 0) expiresAt else null
return DbxCredential(secret, nullableExpiresAt, refreshToken, appKey)
public fun getDbxCredential(): DbxCredential? {
val data = AuthActivity.result ?: return null
val token = data.getStringExtra(DropboxAuthIntent.EXTRA_ACCESS_TOKEN)
val secret = data.getStringExtra(DropboxAuthIntent.EXTRA_ACCESS_SECRET)
val uid = data.getStringExtra(DropboxAuthIntent.EXTRA_UID)
if (token == null || "" == token || secret == null || "" == secret || uid == null || "" == uid) {
return null
}
val appKey = data.getStringExtra(DropboxAuthIntent.EXTRA_CONSUMER_KEY)
val refreshToken = data.getStringExtra(DropboxAuthIntent.EXTRA_REFRESH_TOKEN)
val expiresAt = data.getLongExtra(DropboxAuthIntent.EXTRA_EXPIRES_AT, -1)
val nullableExpiresAt = if (expiresAt >= 0) expiresAt else null
return DbxCredential(secret, nullableExpiresAt, refreshToken, appKey)
}

/**
*
Expand All @@ -342,10 +337,9 @@ public class Auth {
* will get HTTP 401.
*/
@JvmStatic
public val scope: String?
get() {
val data = AuthActivity.result ?: return null
return data.getStringExtra(DropboxAuthIntent.EXTRA_SCOPE)
}
public fun getScope(): String? {
val data = AuthActivity.result ?: return null
return data.getStringExtra(DropboxAuthIntent.EXTRA_SCOPE)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public open class AuthActivity : Activity() {
startActivity(intent)
}

internal companion object {
public companion object {
private val TAG = AuthActivity::class.java.name

/**
Expand Down
11 changes: 11 additions & 0 deletions dropbox-sdk-java/api/dropbox-sdk-java.api
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ public class com/dropbox/core/android/AuthActivity : android/app/Activity {
public static final field ACTION_AUTHENTICATE_V2 Ljava/lang/String;
public static final field AUTH_PATH_CONNECT Ljava/lang/String;
public static final field AUTH_VERSION I
public static final field Companion Lcom/dropbox/core/android/AuthActivity$Companion;
public static field result Landroid/content/Intent;
public fun <init> ()V
public static final fun checkAppBeforeAuth (Landroid/content/Context;Ljava/lang/String;Z)Z
Expand All @@ -485,6 +486,16 @@ public class com/dropbox/core/android/AuthActivity : android/app/Activity {
public static final fun setSecurityProvider (Lcom/dropbox/core/android/AuthActivity$SecurityProvider;)V
}

public final class com/dropbox/core/android/AuthActivity$Companion {
public final fun checkAppBeforeAuth (Landroid/content/Context;Ljava/lang/String;Z)Z
public final fun makeIntent (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;
public final fun makeIntent (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;
public final fun setAuthParams (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
public final fun setAuthParams (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
public final fun setAuthParams (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public final fun setSecurityProvider (Lcom/dropbox/core/android/AuthActivity$SecurityProvider;)V
}

public abstract interface class com/dropbox/core/android/AuthActivity$SecurityProvider {
public abstract fun getSecureRandom ()Ljava/security/SecureRandom;
}
Expand Down
2 changes: 0 additions & 2 deletions dropbox-sdk-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ generateStone {
),

]
outputDir "${project.projectDir}/generated_stone_source/main"
}

generateTestStone {
Expand All @@ -306,5 +305,4 @@ generateTestStone {
)
),
]
outputDir "${project.projectDir}/generated_stone_source/test"
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class BaseSampleActivity : AppCompatActivity() {

val prefs = getSharedPreferences("dropbox-sample", Context.MODE_PRIVATE)

val uid = Auth.uid
val uid = Auth.getUid()
val storedUid = prefs.getString("user-id", null)
if (uid != null && uid != storedUid) {
prefs.edit().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class OpenWithActivity : BaseSampleActivity() {
* Generate an OpenWithIntent.
* Real 3rd party apps should never run this function as DropboxApp does this entirely
*/
val uid = Auth.uid
val uid = Auth.getUid()

// fake the URI
// WARNING: URI FORMAT IS NOT FINALIZED AND MAY CHANGE AT ANY TIME
Expand Down Expand Up @@ -150,7 +150,7 @@ class OpenWithActivity : BaseSampleActivity() {

override fun loadData() {
try {
var uid = Auth.uid
var uid = Auth.getUid()
if (uid == null) {
val prefs = getSharedPreferences("dropbox-sample", Context.MODE_PRIVATE)
uid = prefs.getString("user-id", null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DropboxOAuthUtil(
*/
fun onResume() {
if (isAwaitingResult) {
val authDbxCredential = Auth.dbxCredential //fetch the result from the AuthActivity
val authDbxCredential = Auth.getDbxCredential() //fetch the result from the AuthActivity
isAwaitingResult = false
if (authDbxCredential != null) {
dropboxCredentialUtil.storeCredentialLocally(authDbxCredential)
Expand Down
3 changes: 2 additions & 1 deletion gradle/dropboxJavaSdkLibs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ android-gradle-plugin = "7.2.2"
android-min-sdk = "21"
android-target-sdk = "33"
androidx-activity = "1.5.0"
binary-compatibility-validator = "0.11.1"
dependency-guard = "0.3.2"
junit-jupiter = "5.8.2"
kotlin = "1.6.21"
Expand Down Expand Up @@ -39,7 +40,7 @@ test-junit = 'junit:junit:4.13.2'


[plugins]
binary-compatibility-validator = "org.jetbrains.kotlinx.binary-compatibility-validator:0.11.1"
binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binary-compatibility-validator" }
blind-pirate-osgi = "com.github.blindpirate.osgi:0.0.6"
dependency-guard = { id = "com.dropbox.dependency-guard", version.ref = "dependency-guard" }
gradle-version-plugin = "com.github.ben-manes.versions:0.42.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class StonePlugin : Plugin<Project> {
val mySpecDir: String = specDirPropNameValue ?: "src/${sourceSet.name}/stone"

stoneTask.specDir(mySpecDir)
stoneTask.generatorDir("generator")
stoneTask.generatorDir("${project.projectDir.absoluteFile}/generator")
stoneTask.stoneDir("stone")
stoneTask.pythonCommand("python")
stoneTask.outputDir("${project.buildDir}/generated/source/stone/${sourceSet.name}")
Expand All @@ -72,14 +72,15 @@ public class StonePlugin : Plugin<Project> {
.withPropertyName("generatedStone")
stoneTask.outputs.cacheIf { true }

val compile: Task = project.tasks.getByName(sourceSet.getCompileTaskName("java"))
compile.dependsOn(stoneTask)
val compileJava: Task = project.tasks.getByName(sourceSet.getCompileTaskName("java"))
compileJava.dependsOn(stoneTask)
val compileKotlin: Task = project.tasks.getByName(sourceSet.getCompileTaskName("kotlin"))
compileKotlin.dependsOn(stoneTask)

project.afterEvaluate {
// Must run afterEvaluate so we can honor any output directory specified in user's config
sourceSet.java.srcDir("${stoneTask.getOutputDir().get()}/src")
}
}
}

}

0 comments on commit 009c8eb

Please sign in to comment.