Skip to content

Commit 80ef16a

Browse files
devPalacioJay Palacio
and
Jay Palacio
authored
Support Android SDK 35 (#545)
* changes to compile under sdk35 --------- Co-authored-by: Jay Palacio <[email protected]>
1 parent 6e20330 commit 80ef16a

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

android/src/main/java/com/dropbox/core/android/DbxOfficialAppConnector.kt

+32-19
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import android.content.Intent
2626
import android.content.pm.PackageInfo
2727
import android.content.pm.PackageManager
2828
import android.net.Uri
29+
import android.os.Build
2930
import android.os.Parcel
3031
import android.util.Base64
31-
import com.dropbox.core.android.DropboxUidNotInitializedException
3232
import com.dropbox.core.android.internal.DropboxAuthIntent
3333

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

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

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

163-
//extras (used either dirction)
163+
// extras (used either dirction)
164164
public const val EXTRA_DROPBOX_PATH: String = "com.dropbox.android.intent.extra.DROPBOX_PATH"
165165
public const val EXTRA_DROPBOX_READ_ONLY: String = "com.dropbox.android.intent.extra.READ_ONLY"
166166
public const val EXTRA_DROPBOX_REV: String = "com.dropbox.android.intent.extra.DROPBOX_REV"
@@ -173,7 +173,6 @@ public class DbxOfficialAppConnector(uid: String?) {
173173
*/
174174
@JvmStatic
175175
public fun isInstalled(context: Context): DbxOfficialAppInstallInfo? {
176-
177176
// For now, use dAuth intent
178177
val authIntent = DropboxAuthIntent.buildActionAuthenticateIntent()
179178
val dropboxPackage = getDropboxAppPackage(context, authIntent) ?: return null
@@ -281,23 +280,37 @@ public class DbxOfficialAppConnector(uid: String?) {
281280
// The official app doesn't exist, or only an older version
282281
// is available, or multiple activities are confusing us.
283282
return null
284-
} else {
285-
// The official app exists. Make sure it's the correct one by
286-
// checking signing keys.
287-
val resolveInfo = manager.resolveActivity(intent, 0) ?: return null
288-
val packageInfo: PackageInfo = try {
289-
manager.getPackageInfo(
290-
resolveInfo.activityInfo.packageName,
291-
PackageManager.GET_SIGNATURES
292-
)
283+
}
284+
// The official app exists. Make sure it's the correct one by
285+
// checking signing keys.
286+
val resolveInfo = manager.resolveActivity(intent, 0) ?: return null
287+
val packageInfo: PackageInfo =
288+
try {
289+
if (Build.VERSION.SDK_INT >= 28) {
290+
manager.getPackageInfo(
291+
resolveInfo.activityInfo.packageName,
292+
PackageManager.GET_SIGNING_CERTIFICATES,
293+
)
294+
} else {
295+
manager.getPackageInfo(
296+
resolveInfo.activityInfo.packageName,
297+
PackageManager.GET_SIGNATURES
298+
)
299+
}
293300
} catch (e: PackageManager.NameNotFoundException) {
294301
return null
295302
}
296-
for (signature in packageInfo.signatures) {
297-
for (dbSignature in DROPBOX_APP_SIGNATURES) {
298-
if (dbSignature == signature.toCharsString()) {
299-
return packageInfo
300-
}
303+
304+
val signatures = if (Build.VERSION.SDK_INT >= 28) {
305+
packageInfo.signingInfo?.signingCertificateHistory
306+
} else {
307+
packageInfo.signatures
308+
} ?: return null
309+
310+
for (signature in signatures) {
311+
for (dbSignature in DROPBOX_APP_SIGNATURES) {
312+
if (dbSignature == signature.toCharsString()) {
313+
return packageInfo
301314
}
302315
}
303316
}
@@ -352,4 +365,4 @@ public class DbxOfficialAppConnector(uid: String?) {
352365
return openWithIntent
353366
}
354367
}
355-
}
368+
}

android/src/main/java/com/dropbox/core/android/internal/DropboxAuthIntent.kt

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal object DropboxAuthIntent {
1818
fun Context.getTargetSdkVersion(): Int? {
1919
return try {
2020
val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
21-
val targetSdkVersion: Int = packageInfo.applicationInfo.targetSdkVersion
21+
val targetSdkVersion: Int? = packageInfo.applicationInfo?.targetSdkVersion
2222
targetSdkVersion
2323
} catch (e: Exception) {
2424
null
@@ -34,7 +34,6 @@ internal object DropboxAuthIntent {
3434
stateNonce: String,
3535
authActivity: AuthActivity,
3636
): Intent {
37-
3837
val callingActivityFullyQualifiedClassName = authActivity::class.java.name
3938
val packageName = authActivity.packageName
4039

@@ -147,6 +146,4 @@ internal object DropboxAuthIntent {
147146
* Used for internal authentication. You won't ever have to use this.
148147
*/
149148
const val EXTRA_AUTH_QUERY_PARAMS: String = "AUTH_QUERY_PARAMS"
150-
151-
152-
}
149+
}

0 commit comments

Comments
 (0)