Skip to content

Commit

Permalink
Support Android SDK 35 (#545)
Browse files Browse the repository at this point in the history
* changes to compile under sdk35
---------

Co-authored-by: Jay Palacio <[email protected]>
  • Loading branch information
devPalacio and Jay Palacio authored Jul 12, 2024
1 parent 6e20330 commit 80ef16a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Parcel
import android.util.Base64
import com.dropbox.core.android.DropboxUidNotInitializedException
import com.dropbox.core.android.internal.DropboxAuthIntent

/**
Expand Down Expand Up @@ -152,15 +152,15 @@ public class DbxOfficialAppConnector(uid: String?) {
public const val EXTRA_DROPBOX_UID: String = "com.dropbox.android.intent.extra.DROPBOX_UID"
public const val EXTRA_CALLING_PACKAGE: String = "com.dropbox.android.intent.extra.CALLING_PACKAGE"

//OpenWith intent definitions. You won't need to use this unless you are our official partner in openwith.
// OpenWith intent definitions. You won't need to use this unless you are our official partner in openwith.
// from Dropbox actions
public const val ACTION_DBXC_EDIT: String = "com.dropbox.android.intent.action.DBXC_EDIT"
public const val ACTION_DBXC_VIEW: String = "com.dropbox.android.intent.action.DBXC_VIEW"

// to Dropbox actions
public const val ACTION_SHOW_DROPBOX_PREVIEW: String = "com.dropbox.android.intent.action.SHOW_PREVIEW"

//extras (used either dirction)
// extras (used either dirction)
public const val EXTRA_DROPBOX_PATH: String = "com.dropbox.android.intent.extra.DROPBOX_PATH"
public const val EXTRA_DROPBOX_READ_ONLY: String = "com.dropbox.android.intent.extra.READ_ONLY"
public const val EXTRA_DROPBOX_REV: String = "com.dropbox.android.intent.extra.DROPBOX_REV"
Expand All @@ -173,7 +173,6 @@ public class DbxOfficialAppConnector(uid: String?) {
*/
@JvmStatic
public fun isInstalled(context: Context): DbxOfficialAppInstallInfo? {

// For now, use dAuth intent
val authIntent = DropboxAuthIntent.buildActionAuthenticateIntent()
val dropboxPackage = getDropboxAppPackage(context, authIntent) ?: return null
Expand Down Expand Up @@ -281,23 +280,37 @@ public class DbxOfficialAppConnector(uid: String?) {
// The official app doesn't exist, or only an older version
// is available, or multiple activities are confusing us.
return null
} else {
// The official app exists. Make sure it's the correct one by
// checking signing keys.
val resolveInfo = manager.resolveActivity(intent, 0) ?: return null
val packageInfo: PackageInfo = try {
manager.getPackageInfo(
resolveInfo.activityInfo.packageName,
PackageManager.GET_SIGNATURES
)
}
// The official app exists. Make sure it's the correct one by
// checking signing keys.
val resolveInfo = manager.resolveActivity(intent, 0) ?: return null
val packageInfo: PackageInfo =
try {
if (Build.VERSION.SDK_INT >= 28) {
manager.getPackageInfo(
resolveInfo.activityInfo.packageName,
PackageManager.GET_SIGNING_CERTIFICATES,
)
} else {
manager.getPackageInfo(
resolveInfo.activityInfo.packageName,
PackageManager.GET_SIGNATURES
)
}
} catch (e: PackageManager.NameNotFoundException) {
return null
}
for (signature in packageInfo.signatures) {
for (dbSignature in DROPBOX_APP_SIGNATURES) {
if (dbSignature == signature.toCharsString()) {
return packageInfo
}

val signatures = if (Build.VERSION.SDK_INT >= 28) {
packageInfo.signingInfo?.signingCertificateHistory
} else {
packageInfo.signatures
} ?: return null

for (signature in signatures) {
for (dbSignature in DROPBOX_APP_SIGNATURES) {
if (dbSignature == signature.toCharsString()) {
return packageInfo
}
}
}
Expand Down Expand Up @@ -352,4 +365,4 @@ public class DbxOfficialAppConnector(uid: String?) {
return openWithIntent
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal object DropboxAuthIntent {
fun Context.getTargetSdkVersion(): Int? {
return try {
val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
val targetSdkVersion: Int = packageInfo.applicationInfo.targetSdkVersion
val targetSdkVersion: Int? = packageInfo.applicationInfo?.targetSdkVersion
targetSdkVersion
} catch (e: Exception) {
null
Expand All @@ -34,7 +34,6 @@ internal object DropboxAuthIntent {
stateNonce: String,
authActivity: AuthActivity,
): Intent {

val callingActivityFullyQualifiedClassName = authActivity::class.java.name
val packageName = authActivity.packageName

Expand Down Expand Up @@ -147,6 +146,4 @@ internal object DropboxAuthIntent {
* Used for internal authentication. You won't ever have to use this.
*/
const val EXTRA_AUTH_QUERY_PARAMS: String = "AUTH_QUERY_PARAMS"


}
}

0 comments on commit 80ef16a

Please sign in to comment.