Skip to content

Commit

Permalink
v1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cczhr committed Jun 15, 2021
1 parent b69df4c commit cf7b118
Show file tree
Hide file tree
Showing 14 changed files with 1,134 additions and 72 deletions.
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
minSdkVersion 24
targetSdkVersion 30
versionCode 5
versionName "1.1.1"
versionName "1.1.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -63,4 +63,7 @@ dependencies {
implementation "androidx.room:room-ktx:2.2.5"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.6"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.6"
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.8.6'
}
8 changes: 5 additions & 3 deletions app/src/main/java/com/cczhr/otglocation/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import com.google.android.material.floatingactionbutton.FloatingActionButton
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext


/**
Expand All @@ -32,6 +31,9 @@ abstract class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope()
private lateinit var permissionsResult: (Boolean) -> Unit
protected abstract val layoutId: Int
protected abstract fun init()
override val coroutineContext: CoroutineContext = SupervisorJob() + Dispatchers.Main +
CoroutineExceptionHandler { _, exception -> handleException(exception) }
protected open fun handleException(t: Throwable) = t.printStackTrace()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(layoutId)
Expand Down
123 changes: 114 additions & 9 deletions app/src/main/java/com/cczhr/otglocation/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
package com.cczhr.otglocation

import android.annotation.SuppressLint
import android.app.Dialog
import android.app.ProgressDialog
import android.content.Intent
import android.text.TextUtils
import android.util.Log
import android.view.View
import androidx.lifecycle.Observer
import com.amap.api.mapcore.util.it
import com.cczhr.otglocation.net.RetrofitManager
import com.cczhr.otglocation.utils.*
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import java.lang.Exception


class MainActivity : BaseActivity() {
Expand All @@ -19,9 +31,20 @@ class MainActivity : BaseActivity() {
var isConnected = false
var hasDeveloperImg = false

var progressDialog: ProgressDialog? = null

@SuppressLint("SetTextI18n")


override fun handleException(t: Throwable) {
super.handleException(t)
CommonUtil.showToast(Application.context, "下载失败")
progressDialog?.dismiss()
}

override fun init() {


version?.text = "V ${Application.getVersion()}"
latitude.setText(Application.getLat())
longitude.setText(Application.getLon())
Expand All @@ -48,7 +71,7 @@ class MainActivity : BaseActivity() {
})

hotPlugTools.register(this, { deviceNode ->
libTools.startUsbmuxd(deviceNode,{
libTools.startUsbmuxd(deviceNode, {
isConnected = true
connect_status.setText(R.string.connected)
}, {
Expand Down Expand Up @@ -78,8 +101,10 @@ class MainActivity : BaseActivity() {
log.setText("")
}


}


override fun onDestroy() {
super.onDestroy()
libTools.release()
Expand All @@ -88,21 +113,23 @@ class MainActivity : BaseActivity() {


fun logAdd(str: String) {

log.append(str + "\n")
log.setSelection(log.text.toString().length)


}

fun selectLocation(view: View) {
val lat = latitude.text.toString().toDoubleOrNull()
val lon = longitude.text.toString().toDoubleOrNull()
val intent=Intent(this, MapActivity::class.java)
val intent = Intent(this, MapActivity::class.java)
if (lat != null && lon != null) {
intent.putExtra("lat",lat)
intent.putExtra("lon",lon)
intent.putExtra("lat", lat)
intent.putExtra("lon", lon)
}

startActivityForResult(intent , 102)
startActivityForResult(intent, 102)
}


Expand Down Expand Up @@ -141,7 +168,7 @@ class MainActivity : BaseActivity() {
}

fun modifyLocation(view: View) {
if(!checkStatus())
if (!checkStatus())
return
var lat = latitude.text.toString().toDoubleOrNull()
var lon = longitude.text.toString().toDoubleOrNull()
Expand All @@ -165,7 +192,7 @@ class MainActivity : BaseActivity() {
}

fun restoreLocation(view: View) {
if(!checkStatus())
if (!checkStatus())
return

libTools.resetLocation {
Expand All @@ -186,11 +213,89 @@ class MainActivity : BaseActivity() {
CommonUtil.showToast(Application.context, "请安装组件!")
else if (!isConnected)
CommonUtil.showToast(Application.context, "请连接设备!")
else if(!hasDeveloperImg)
else if (!hasDeveloperImg)
CommonUtil.showToast(Application.context, "开发者驱动未挂载!")

return hasLib&&isConnected&&hasDeveloperImg
return hasLib && isConnected && hasDeveloperImg
}

fun downloadDriver(view: View) {
val version = product_version.text.toString()
if (version.isEmpty()) {
CommonUtil.showToast(Application.context, "请连接设备后再点击下载!")
return
}
progressDialog = CommonUtil.getProgressDialog(this, R.string.please_wait)
launch(Dispatchers.Main) {
var downloadUrl = ""
val deviceSupport = RetrofitManager.getInstance().getBaseApi().getDeviceSupport()
if (deviceSupport == null) {
return@launch
} else {
for (item in deviceSupport) {
if (item.name.contains(version)) {
downloadUrl = item.download_url
break
}

}
}
if (downloadUrl.isEmpty()) {
progressDialog?.dismiss()
CommonUtil.showToast(Application.context, "没有找到对应的开发者驱动")
logAdd("没有找到对应的开发者驱动!")
return@launch
}

downloadUrl = downloadUrl.replace(
"https://raw.githubusercontent.com/",
"https://raw.fastgit.org/"
)
logAdd("正在下载")

RetrofitManager.getInstance().getBaseApi().get(downloadUrl)
.downloadFile("ios.zip", IMobileDeviceTools.DEVICE_PATH).collect {
when (it) {
-1 -> {
progressDialog?.dismiss()
logAdd("下载失败")
}
100 -> {
progressDialog?.dismiss()
logAdd("下载完成")
}
else -> {
progressDialog?.progress = it
}
}
}
logAdd("正在解压")
withContext(Dispatchers.IO) {
ZipUtils.unzipFile(
IMobileDeviceTools.DEVICE_PATH + File.separator + "ios.zip",
IMobileDeviceTools.DEVICE_PATH
)
}
val path1 =
FileUtils.findFile(File(IMobileDeviceTools.DEVICE_PATH), "DeveloperDiskImage.dmg")
val path2 = FileUtils.findFile(
File(IMobileDeviceTools.DEVICE_PATH),
"DeveloperDiskImage.dmg.signature"
)
if (path1.isNotEmpty() && path2.isNotEmpty()) {
libTools.mountImage(version, path1, path2) {
hasDeveloperImg = it
developer_img.text = it.toString()
if (it)
logAdd("重要的事情说两遍:写入成功!现在你可以修改定位了!\n")
else
logAdd("开发者镜像写入失败!\n")
}
} else {
logAdd("下载文件不完整 路径1:$path1 路径2:$path2")
}

}
}

}
23 changes: 23 additions & 0 deletions app/src/main/java/com/cczhr/otglocation/net/Api.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.cczhr.otglocation.net

import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Streaming
import retrofit2.http.Url


/**
* @author cczhr
* @description
* @since 2021/6/10 10:06
*/
interface Api {
@GET("repos/iGhibli/iOS-DeviceSupport/contents/DeviceSupport")
suspend fun getDeviceSupport(): DeviceSupportBean?

@Streaming
@GET
fun get(@Url fileUrl: String): Call<ResponseBody>
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/cczhr/otglocation/net/DeviceSupportBean.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.cczhr.otglocation.net

/**
* @author cczhr
* @description
* @since 2021/6/10 09:33
*/
class DeviceSupportBean : ArrayList<DeviceSupportBeanItem>()

data class DeviceSupportBeanItem(
val _links: Links,
val download_url: String,
val html_url: String,
val name: String,
val path: String,
val sha: String,
val size: Any,
val type: String,
val url: String
)

data class Links(
val html: String,
val self: String
)
84 changes: 84 additions & 0 deletions app/src/main/java/com/cczhr/otglocation/net/LoggingInterceptor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.cczhr.otglocation.net

import android.util.Log
import okhttp3.*
import okio.Buffer
import org.json.JSONException
import org.json.JSONObject


/**
* @author cczhr
* @description
* @since 2021/6/10 10:17
*/
class LoggingInterceptor : Interceptor {
val TAG = "LoggingInterceptor"
override fun intercept(chain: Interceptor.Chain): Response {
val request: Request = chain.request()
val t1 = System.nanoTime() //请求发起的时间

val method: String = request.method()
val jsonObject = JSONObject()
if ("POST" == method || "PUT" == method) {
if (request.body() is FormBody) {
val body = request.body() as? FormBody
if (body != null) {
for (i in 0 until body.size()) {
try {
jsonObject.put(body.name(i), body.encodedValue(i))
} catch (e: JSONException) {
e.printStackTrace()
}
}
}
Log.e(
TAG,
"request" + java.lang.String.format(
"发送请求 %s on %s %nRequestParams:%s%nMethod:%s",
request.url(), chain.connection(), jsonObject.toString(), request.method()
)
)
} else {
val buffer = Buffer()
val requestBody: RequestBody? = request.body()
if (requestBody != null) {
request.body()!!.writeTo(buffer)
val body: String = buffer.readUtf8()
Log.e(
TAG,
"request" + java.lang.String.format(
"发送请求 %s on %s %nRequestParams:%s%nMethod:%s",
request.url(), chain.connection(), body, request.method()
)
)
}
}
} else {
Log.e(
TAG,
"request" + java.lang.String.format(
"发送请求 %s on %s%nMethod:%s",
request.url(), chain.connection(), request.method()
)
)
}
val response = chain.proceed(request)
return try {
val t2 = System.nanoTime() //收到响应的时间
val responseBody = response.peekBody((1024 * 1024).toLong())
Log.e(
TAG,
"request" + String.format(
"接收响应: %s %n返回json:【%s】 %n耗时:%.1fms",
response.request().url(),
responseBody.string(),
(t2 - t1) / 1e6
)
)
response
} catch (e: Exception) {
response
}
}
}
Loading

0 comments on commit cf7b118

Please sign in to comment.