Merge branch 'master' into s
This commit is contained in:
@@ -479,17 +479,19 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
|
||||
private fun showNotification(group: WifiP2pGroup? = null) = ServiceNotification.startForeground(this,
|
||||
if (group == null) emptyMap() else mapOf(Pair(group.`interface`, group.clientList?.size ?: 0)))
|
||||
|
||||
private fun removeGroup() = p2pManager.removeGroup(channel, object : WifiP2pManager.ActionListener {
|
||||
override fun onSuccess() {
|
||||
launch { cleanLocked() }
|
||||
}
|
||||
override fun onFailure(reason: Int) {
|
||||
if (reason != WifiP2pManager.BUSY) {
|
||||
SmartSnackbar.make(formatReason(R.string.repeater_remove_group_failure, reason)).show()
|
||||
} // else assuming it's already gone
|
||||
onSuccess()
|
||||
}
|
||||
})
|
||||
private fun removeGroup() {
|
||||
p2pManager.removeGroup(channel ?: return, object : WifiP2pManager.ActionListener {
|
||||
override fun onSuccess() {
|
||||
launch { cleanLocked() }
|
||||
}
|
||||
override fun onFailure(reason: Int) {
|
||||
if (reason != WifiP2pManager.BUSY) {
|
||||
SmartSnackbar.make(formatReason(R.string.repeater_remove_group_failure, reason)).show()
|
||||
} // else assuming it's already gone
|
||||
onSuccess()
|
||||
}
|
||||
})
|
||||
}
|
||||
private fun cleanLocked() {
|
||||
if (receiverRegistered) {
|
||||
ensureReceiverUnregistered(receiver)
|
||||
|
||||
@@ -389,7 +389,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
||||
}
|
||||
}
|
||||
true
|
||||
} catch (e: IllegalArgumentException) {
|
||||
} catch (e: RuntimeException) {
|
||||
SmartSnackbar.make(e).show()
|
||||
false
|
||||
}
|
||||
|
||||
@@ -326,6 +326,10 @@ object WifiApManager {
|
||||
private val cancelLocalOnlyHotspotRequest by lazy {
|
||||
WifiManager::class.java.getDeclaredMethod("cancelLocalOnlyHotspotRequest")
|
||||
}
|
||||
/**
|
||||
* This is the only way to unregister requests besides app exiting.
|
||||
* Therefore, we are happy with crashing the app if reflection fails.
|
||||
*/
|
||||
@RequiresApi(26)
|
||||
fun cancelLocalOnlyHotspotRequest() = cancelLocalOnlyHotspotRequest(Services.wifi)
|
||||
|
||||
|
||||
@@ -213,8 +213,8 @@ data class SettingsGlobalPut(val name: String, val value: String) : RootCommandN
|
||||
override suspend fun execute() = withContext(Dispatchers.IO) {
|
||||
val process = ProcessBuilder("settings", "put", "global", name, value).fixPath(true).start()
|
||||
val error = process.inputStream.bufferedReader().readText()
|
||||
check(process.waitFor() == 0)
|
||||
if (error.isNotEmpty()) throw RemoteException(error)
|
||||
val exit = process.waitFor()
|
||||
if (exit != 0 || error.isNotEmpty()) throw RemoteException("Process exited with $exit: $error")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,10 +213,14 @@ private val newLookup by lazy @TargetApi(26) {
|
||||
* See also: https://stackoverflow.com/a/49532463/2245107
|
||||
*/
|
||||
fun InvocationHandler.callSuper(interfaceClass: Class<*>, proxy: Any, method: Method, args: Array<out Any?>?) = when {
|
||||
Build.VERSION.SDK_INT >= 26 && method.isDefault -> newLookup.newInstance(interfaceClass, 0xf) // ALL_MODES
|
||||
.`in`(interfaceClass).unreflectSpecial(method, interfaceClass).bindTo(proxy).run {
|
||||
if (args == null) invokeWithArguments() else invokeWithArguments(*args)
|
||||
}
|
||||
Build.VERSION.SDK_INT >= 26 && method.isDefault -> try {
|
||||
newLookup.newInstance(interfaceClass, 0xf) // ALL_MODES
|
||||
} catch (e: ReflectiveOperationException) {
|
||||
Timber.w(e)
|
||||
MethodHandles.lookup().`in`(interfaceClass)
|
||||
}.unreflectSpecial(method, interfaceClass).bindTo(proxy).run {
|
||||
if (args == null) invokeWithArguments() else invokeWithArguments(*args)
|
||||
}
|
||||
// otherwise, we just redispatch it to InvocationHandler
|
||||
method.declaringClass.isAssignableFrom(javaClass) -> when {
|
||||
method.declaringClass == Object::class.java -> when (method.name) {
|
||||
|
||||
Reference in New Issue
Block a user