Pārlūkot izejas kodu

refactor: 删除权限REQUEST_INSTALL_PACKAGES(谷歌商店权限要求)
refactor: 删除File.install

drake 2 gadi atpakaļ
vecāks
revīzija
7cbe157cf1

+ 6 - 18
docs/download-file.md

@@ -14,28 +14,16 @@ Download函数一调用就会开始执行下载文件请求, 然后`await`则会
 
 支持丰富的下载定制方案, 并且会不断地更新完善
 
-=== "下载文件"
-    ```kotlin
-    scopeNetLife {
-        val file =
-            Get<File>("https://download.sublimetext.com/Sublime%20Text%20Build%203211.dmg") {
-                setDownloadFileName("net.apk")
-                setDownloadDir(requireContext().filesDir)
-                setDownloadMd5Verify()
-            }.await()
-    }
-    ```
-
-=== "下载并安装"
-    ```kotlin
-    scopeNetLife {
+```kotlin
+scopeNetLife {
+    val file =
         Get<File>("https://download.sublimetext.com/Sublime%20Text%20Build%203211.dmg") {
             setDownloadFileName("net.apk")
             setDownloadDir(requireContext().filesDir)
             setDownloadMd5Verify()
-        }.await().install()
-    }
-    ```
+        }.await()
+}
+```
 
 配置选项
 

+ 0 - 10
net/src/main/AndroidManifest.xml

@@ -5,7 +5,6 @@
 
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
-    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
 
     <application
         android:networkSecurityConfig="@xml/network_security_config"
@@ -16,15 +15,6 @@
             android:enabled="true"
             android:exported="false"
             android:multiprocess="true" />
-        <provider
-            android:name=".component.NetFileProvider"
-            android:authorities="${applicationId}.drake.netFileProvider"
-            android:exported="false"
-            android:grantUriPermissions="true">
-            <meta-data
-                android:name="android.support.FILE_PROVIDER_PATHS"
-                android:resource="@xml/net_file_paths" />
-        </provider>
     </application>
 
 </manifest>

+ 0 - 8
net/src/main/java/com/drake/net/component/NetFileProvider.kt

@@ -1,8 +0,0 @@
-package com.drake.net.component
-
-import androidx.core.content.FileProvider
-
-/**
- * 用于临时获取文件读写权限
- */
-class NetFileProvider : FileProvider()

+ 0 - 44
net/src/main/java/com/drake/net/utils/FileUtils.kt

@@ -1,12 +1,7 @@
 package com.drake.net.utils
 
-import android.content.Intent
-import android.net.Uri
-import android.os.Build
 import android.webkit.MimeTypeMap
-import androidx.core.content.FileProvider
 import com.drake.net.Net
-import com.drake.net.NetConfig
 import okhttp3.MediaType
 import okhttp3.MediaType.Companion.toMediaTypeOrNull
 import okhttp3.RequestBody
@@ -62,43 +57,4 @@ fun File.toRequestBody(contentType: MediaType? = null): RequestBody {
             source().use { source -> sink.writeAll(source) }
         }
     }
-}
-
-/**
- * 安装APK
- * @throws IllegalArgumentException 文件不存在或非apk后缀
- * @throws UnsupportedOperationException 系统不存在包管理器
- */
-@Throws(IllegalArgumentException::class, UnsupportedOperationException::class)
-fun File.install() {
-    val context = NetConfig.app
-
-    if (!this.exists()) {
-        throw IllegalArgumentException("The file does not exist ($absolutePath)")
-    }
-    if (name.substringAfterLast(".").lowercase() != "apk") {
-        throw IllegalArgumentException("The file is not an apk file ($absolutePath)")
-    }
-
-    val intent = Intent(Intent.ACTION_VIEW)
-    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
-    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
-    }
-    val uri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-        FileProvider.getUriForFile(
-            context,
-            "${context.packageName}.drake.netFileProvider",
-            this
-        )
-    } else {
-        Uri.fromFile(this)
-    }
-    intent.setDataAndType(uri, "application/vnd.android.package-archive")
-
-    if (context.packageManager.resolveActivity(intent, 0) != null) {
-        context.startActivity(intent)
-    } else {
-        throw UnsupportedOperationException("Unable to find installation activity")
-    }
 }

+ 0 - 18
net/src/main/res/xml/net_file_paths.xml

@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<paths>
-    <files-path
-        name="files"
-        path="." />
-    <cache-path
-        name="cache"
-        path="." />
-    <external-path
-        name="external"
-        path="." />
-    <external-files-path
-        name="external_file_path"
-        path="." />
-    <external-cache-path
-        name="external_cache_path"
-        path="." />
-</paths>