Skip to content

Commit

Permalink
1.使用自定义的文件选择器来选择本地文件
Browse files Browse the repository at this point in the history
2.修复自定义储存目录的相关Bug
3.英文支持
  • Loading branch information
wukaicheng committed May 30, 2021
1 parent 8721769 commit 3462756
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 92 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ dependencies {
implementation 'com.github.Ferfalk:SimpleSearchView:0.2.0'
//searchView

implementation 'com.umeng.umsdk:common:9.3.8'
implementation 'com.umeng.umsdk:asms:1.2.2'
//友盟

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/top/niunaijun/blackdex/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package top.niunaijun.blackboxa.app
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import com.umeng.commonsdk.UMConfigure
import top.niunaijun.blackdex.app.AppManager

/**
Expand All @@ -28,6 +29,7 @@ class App : Application() {
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
mContext = base!!
UMConfigure.init(base, "60b373136c421a3d97d23c29", "Github", 0, "")
AppManager.doAttachBaseContext(base)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BlackDexLoader {

private var mSavePath by AppSharedPreferenceDelegate(App.getContext(), "")

private var mSaveEnable by AppSharedPreferenceDelegate(App.getContext(), false)
private var mSaveEnable by AppSharedPreferenceDelegate(App.getContext(), true)

private var mDir = if (mSaveEnable) {
getDexDumpDir(App.getContext())
Expand Down Expand Up @@ -73,7 +73,7 @@ class BlackDexLoader {
return if (BuildCompat.isR()) {
val dump = File(
context.externalCacheDir?.parentFile?.parentFile?.parentFile?.parentFile,
"hupu/dexDump"
"Download/dexDump"
)
FileUtils.mkdirs(dump)
dump.absolutePath
Expand Down
21 changes: 12 additions & 9 deletions app/src/main/java/top/niunaijun/blackdex/data/DexDumpRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class DexDumpRepository {

fun getAppList(mAppListLiveData: MutableLiveData<List<AppInfo>>) {

val installedApplications: List<ApplicationInfo> = getPackageManager().getInstalledApplications(0)
val installedApplications: List<ApplicationInfo> =
getPackageManager().getInstalledApplications(0)
val installedList = mutableListOf<AppInfo>()

for (installedApplication in installedApplications) {
Expand All @@ -40,9 +41,9 @@ class DexDumpRepository {


val info = AppInfo(
installedApplication.loadLabel(getPackageManager()).toString(),
installedApplication.packageName,
installedApplication.loadIcon(getPackageManager())
installedApplication.loadLabel(getPackageManager()).toString(),
installedApplication.packageName,
installedApplication.loadIcon(getPackageManager())
)
installedList.add(info)
}
Expand All @@ -56,30 +57,32 @@ class DexDumpRepository {

val result = if (URLUtil.isValidUrl(source)) {
BlackDexCore.get().dumpDex(Uri.parse(source))
} else if (source.contains("/")) {
BlackDexCore.get().dumpDex(File(source))
} else {
BlackDexCore.get().dumpDex(source)
}

if(result){
if (result) {
dumpTaskId++
startCountdown(dexDumpLiveData)
}else{
} else {
dexDumpLiveData.postValue(DumpInfo(DumpInfo.TIMEOUT))
}

}


fun dumpSuccess(){
fun dumpSuccess() {
dumpTaskId++
}

private fun startCountdown(dexDumpLiveData: MutableLiveData<DumpInfo>){
private fun startCountdown(dexDumpLiveData: MutableLiveData<DumpInfo>) {
GlobalScope.launch {
val tempId = dumpTaskId
delay(10000)

if(tempId == dumpTaskId){
if (tempId == dumpTaskId) {
dexDumpLiveData.postValue(DumpInfo(DumpInfo.TIMEOUT))
}
}
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/top/niunaijun/blackdex/util/FileUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package top.niunaijun.blackdex.util

import java.io.File

/**
*
* @Description: file util
* @Author: wukaicheng
* @CreateDate: 2021/5/30 20:25
*/
object FileUtil {

fun filterApk(file: File):Boolean{
return (file.extension == "apk") or file.isDirectory
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import androidx.appcompat.widget.Toolbar
*/
open class BaseActivity : AppCompatActivity() {

protected fun initToolbar(toolbar: Toolbar,title:Int, showBack: Boolean = false, onBack: (() -> Unit)? = null) {
protected fun initToolbar(
toolbar: Toolbar,
title: Int,
showBack: Boolean = false,
onBack: (() -> Unit)? = null
) {
setSupportActionBar(toolbar)
toolbar.setTitle(title)
if (showBack) {
Expand All @@ -20,11 +25,13 @@ open class BaseActivity : AppCompatActivity() {
toolbar.setNavigationOnClickListener {
if (onBack != null) {
onBack()
}else{
} else {
finish()
}
}
}
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package top.niunaijun.blackdex.view.base

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.Settings
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.RequiresApi
import com.afollestad.materialdialogs.MaterialDialog
import top.niunaijun.blackbox.utils.compat.BuildCompat
import top.niunaijun.blackdex.R

/**
*
* @Description:request permission activity
* @Author: wukaicheng
* @CreateDate: 2021/5/30 21:27
*/
open class PermissionActivity:BaseActivity() {

protected var requestPermissionCallback: ((Boolean) -> Unit)? = null

protected fun requestStoragePermission() {
@RequiresApi(Build.VERSION_CODES.R)
if (BuildCompat.isR()) {
if (Environment.isExternalStorageManager()) {
//fuck 请求了读取全部文件权限竟然还要申请普通读写权限
requestPermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)
} else {
MaterialDialog(this).show {
title(R.string.grant_permission)
message(res = R.string.request_storage_msg)
negativeButton(res = R.string.request_later) {
if(requestPermissionCallback!=null){
requestPermissionCallback!!(false)
}
}
positiveButton(res = R.string.jump_grant) {
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
intent.data = Uri.fromParts("package", packageName, null)
startActivity(intent)
}
}
}
} else if (BuildCompat.isM() && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
requestPermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)
}else{
if(requestPermissionCallback!=null){
requestPermissionCallback!!(true)
}
}
}


@RequiresApi(Build.VERSION_CODES.M)
private val requestPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) {
if (it) {
if(requestPermissionCallback!=null){
requestPermissionCallback!!(true)
}
} else {
MaterialDialog(this).show {
title(res = R.string.request_fail)
message(res = R.string.denied_msg)
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
positiveButton(res = R.string.request_again) {
requestStoragePermission()
}

} else {
positiveButton(res = R.string.jump_grant) {
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
val uri = Uri.fromParts("package", packageName, null)
intent.data = uri
startActivity(intent)
}
}
negativeButton(res = R.string.request_later) {
if(requestPermissionCallback!=null){
requestPermissionCallback!!(false)
}
}
}
}
}


override fun onStart() {
super.onStart()
if(requestPermissionCallback!=null){
requestStoragePermission()
}
}

}
Loading

0 comments on commit 3462756

Please sign in to comment.