Skip to content

Commit

Permalink
remove REQUEST_INSTALL_PACKAGES permission, rely on website for insta…
Browse files Browse the repository at this point in the history
…llation
  • Loading branch information
aderan committed Dec 10, 2024
1 parent c3109a7 commit 800f760
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/src/flat/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

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

<application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.agora.flat.data.AppEnv.Companion.ENV_SG_PROD
object ProtocolUrlManager {
private const val PRIVACY = "privacy"
private const val SERVICE = "service"
private const val WEBSITE = "website"

private lateinit var application: Context

Expand All @@ -20,25 +21,45 @@ object ProtocolUrlManager {
PRIVACY to mapOf(
ENV_CN_PROD to mapOf(
"en" to "https://www.flat.apprtc.cn/en/privacy.html", "zh" to "https://www.flat.apprtc.cn/privacy.html"
), ENV_CN_DEV to mapOf(
),
ENV_CN_DEV to mapOf(
"en" to "https://www.flat.apprtc.cn/en/privacy.html", "zh" to "https://www.flat.apprtc.cn/privacy.html"
), ENV_SG_PROD to mapOf(
),
ENV_SG_PROD to mapOf(
"en" to "https://flat.agora.io/privacy.html", "zh" to "https://flat.agora.io/zh/privacy.html"
), ENV_SG_DEV to mapOf(
),
ENV_SG_DEV to mapOf(
"en" to "https://flat.agora.io/privacy.html", "zh" to "https://flat.agora.io/zh/privacy.html"
)
),
SERVICE to mapOf(
),
), SERVICE to mapOf(
ENV_CN_PROD to mapOf(
"en" to "https://www.flat.apprtc.cn/en/service.html", "zh" to "https://www.flat.apprtc.cn/service.html"
), ENV_CN_DEV to mapOf(
),
ENV_CN_DEV to mapOf(
"en" to "https://www.flat.apprtc.cn/en/service.html", "zh" to "https://www.flat.apprtc.cn/service.html"
), ENV_SG_PROD to mapOf(
),
ENV_SG_PROD to mapOf(
"en" to "https://flat.agora.io/en/service.html", "zh" to "https://flat.agora.io/zh/service.html"
), ENV_SG_DEV to mapOf(
),
ENV_SG_DEV to mapOf(
"en" to "https://flat.agora.io/en/service.html", "zh" to "https://flat.agora.io/zh/service.html"
)
),
),

WEBSITE to mapOf(
ENV_CN_PROD to mapOf(
"en" to "https://www.flat.apprtc.cn/#download", "zh" to "https://www.flat.apprtc.cn/#download"
),
ENV_CN_DEV to mapOf(
"en" to "https://www.flat.apprtc.cn/#download", "zh" to "https://www.flat.apprtc.cn/#download"
),
ENV_SG_PROD to mapOf(
"en" to "https://flat.agora.io/#download", "zh" to "https://flat.agora.io/#download"
),
ENV_SG_DEV to mapOf(
"en" to "https://flat.agora.io/#download", "zh" to "https://flat.agora.io/#download"
),
)
)

fun init(app: Application) {
Expand All @@ -58,4 +79,11 @@ object ProtocolUrlManager {
val lang = LanguageManager.currentLocale().language
return urls[PRIVACY]!![env]?.get(lang) ?: "https://www.flat.apprtc.cn/privacy.html"
}

val Website: String
get() {
val env = appEnv.getEnv()
val lang = LanguageManager.currentLocale().language
return urls[WEBSITE]!![env]?.get(lang) ?: "https://www.flat.apprtc.cn/#download"
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/io/agora/flat/ui/compose/UpdateDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import io.agora.flat.R
import io.agora.flat.common.android.ProtocolUrlManager
import io.agora.flat.common.version.VersionCheckResult
import io.agora.flat.ui.theme.FlatTheme
import io.agora.flat.ui.theme.Shapes
import io.agora.flat.util.installApk
import io.agora.flat.util.launchBrowser
import kotlinx.coroutines.launch

@Composable
Expand Down Expand Up @@ -68,8 +70,14 @@ internal fun UpdateDialog(
onGotoMarket()
return@launch
}
// Open the website to download the app and install self
if (true) {
context.launchBrowser(ProtocolUrlManager.Website)
return@launch
}
downloading = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Need to declare android.permission.REQUEST_INSTALL_PACKAGES to call this api
val haveInstallPermission = context.packageManager.canRequestPackageInstalls()
if (!haveInstallPermission) {
showPermissionDialog = true
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/io/agora/flat/util/ContextExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,12 @@ fun Context.launchMarket() {
)
)
}
}

fun Context.launchBrowser(url: String) {
try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
} catch (e: Exception) {
// ignore
}
}

0 comments on commit 800f760

Please sign in to comment.