-
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathDistribution.kt
More file actions
87 lines (79 loc) · 2.88 KB
/
Distribution.kt
File metadata and controls
87 lines (79 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package io.sentry.android.distribution
import android.content.Context
import android.content.Intent
import android.net.Uri
import io.sentry.android.distribution.internal.DistributionInternal
/**
* The public Android SDK for Sentry Build Distribution.
*
* Provides functionality to check for app updates and download new versions from Sentry's preprod
* artifacts system.
*/
public object Distribution {
/**
* Initialize build distribution with default options. This should be called once per process,
* typically in Application.onCreate().
*
* @param context Android context
*/
public fun init(context: Context) {
init(context) {}
}
/**
* Initialize build distribution with the provided configuration. This should be called once per
* process, typically in Application.onCreate().
*
* @param context Android context
* @param configuration Configuration handler for build distribution options
*/
public fun init(context: Context, configuration: (DistributionOptions) -> Unit) {
val options = DistributionOptions()
configuration(options)
DistributionInternal.init(context, options)
}
/**
* Check if build distribution is enabled and properly configured.
*
* @return true if build distribution is enabled
*/
public fun isEnabled(): Boolean {
return DistributionInternal.isEnabled()
}
/**
* Check for available updates synchronously (blocking call). This method will block the calling
* thread while making the network request. Consider using checkForUpdate with callback for
* non-blocking behavior.
*
* @param context Android context
* @return UpdateStatus indicating if an update is available, up to date, or error
*/
public fun checkForUpdateBlocking(context: Context): UpdateStatus {
return DistributionInternal.checkForUpdateBlocking(context)
}
/**
* Check for available updates asynchronously using a callback.
*
* @param context Android context
* @param onResult Callback that will be called with the UpdateStatus result
*/
public fun checkForUpdate(context: Context, onResult: (UpdateStatus) -> Unit) {
DistributionInternal.checkForUpdateAsync(context, onResult)
}
/**
* Download and install the provided update by opening the download URL in the default browser or
* appropriate application.
*
* @param context Android context
* @param info Information about the update to download
*/
public fun downloadUpdate(context: Context, info: UpdateInfo) {
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(info.downloadUrl))
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
try {
context.startActivity(browserIntent)
} catch (e: android.content.ActivityNotFoundException) {
// No application can handle the HTTP/HTTPS URL, typically no browser installed
// Silently fail as this is expected behavior in some environments
}
}
}