Wakeup on Android

This commit is contained in:
Florian Märkl 2019-10-25 15:56:53 +02:00
commit ec569b5d71
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
6 changed files with 47 additions and 8 deletions

View file

@ -56,14 +56,14 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.preference:preference:1.1.0'
implementation 'com.google.android.material:material:1.1.0-alpha10'
implementation 'com.google.android.material:material:1.1.0-beta01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
implementation 'androidx.lifecycle:lifecycle-reactivestreams:2.1.0'
implementation "io.reactivex.rxjava2:rxjava:2.2.12"
implementation "io.reactivex.rxjava2:rxkotlin:2.4.0"
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
def room_version = "2.2.0-rc01"
def room_version = "2.2.1"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"

View file

@ -639,6 +639,16 @@ JNIEXPORT void JNICALL JNI_FCN(discoveryServiceFree)(JNIEnv *env, jobject obj, j
free(service);
}
JNIEXPORT jint JNICALL JNI_FCN(discoveryServiceWakeup)(JNIEnv *env, jobject obj, jlong ptr, jstring host_string, jlong user_credential)
{
AndroidDiscoveryService *service = (AndroidDiscoveryService *)ptr;
const char *host = E->GetStringUTFChars(env, host_string, NULL);
ChiakiErrorCode r = chiaki_discovery_wakeup(&global_log, service ? &service->service.discovery : NULL, host, (uint64_t)user_credential);
E->ReleaseStringUTFChars(env, host_string, host);
return r;
}
typedef struct android_chiaki_regist_t
{
AndroidChiakiLog log;

View file

@ -27,7 +27,10 @@ import com.metallic.chiaki.lib.DiscoveryServiceOptions
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
import java.lang.NumberFormatException
import java.net.InetSocketAddress
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
val DiscoveryHost.ps4Mac get() = this.hostId?.hexToByteArray()?.let {
if(it.size == MacAddress.LENGTH)
@ -81,6 +84,16 @@ class DiscoveryManager
active = false
}
fun sendWakeup(host: String, registKey: ByteArray)
{
val registKeyString = registKey.indexOfFirst { it == 0.toByte() }.let { end -> registKey.copyOfRange(0, if(end >= 0) end else registKey.size) }.toString(StandardCharsets.UTF_8)
val credential = try { registKeyString.toULong(16) } catch(e: NumberFormatException) {
Log.e("DiscoveryManager", "Failed to convert registKey to int", e)
return
}
DiscoveryService.wakeup(discoveryService, host, credential)
}
private fun updateService()
{
if(active && !paused && discoveryService == null)

View file

@ -68,6 +68,7 @@ private class ChiakiNative
@JvmStatic external fun sessionSetLoginPin(ptr: Long, pin: String)
@JvmStatic external fun discoveryServiceCreate(result: CreateResult, options: DiscoveryServiceOptions, javaService: DiscoveryService)
@JvmStatic external fun discoveryServiceFree(ptr: Long)
@JvmStatic external fun discoveryServiceWakeup(ptr: Long, host: String, userCredential: Long)
@JvmStatic external fun registStart(result: CreateResult, registInfo: RegistInfo, javaLog: ChiakiLog, javaRegist: Regist)
@JvmStatic external fun registStop(ptr: Long)
@JvmStatic external fun registFree(ptr: Long)
@ -278,6 +279,12 @@ class DiscoveryService(
options: DiscoveryServiceOptions,
val callback: ((hosts: List<DiscoveryHost>) -> Unit)?)
{
companion object
{
fun wakeup(service: DiscoveryService?, host: String, userCredential: ULong) =
ChiakiNative.discoveryServiceWakeup(service?.nativePtr ?: 0, host, userCredential.toLong())
}
private var nativePtr: Long
init

View file

@ -30,6 +30,7 @@ import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.LinearLayoutManager
import com.metallic.chiaki.R
import com.metallic.chiaki.TestStartActivity
import com.metallic.chiaki.common.DiscoveredDisplayHost
import com.metallic.chiaki.common.DisplayHost
import com.metallic.chiaki.common.Preferences
import com.metallic.chiaki.common.ext.RevealActivity
@ -37,6 +38,7 @@ import com.metallic.chiaki.common.ext.putRevealExtra
import com.metallic.chiaki.common.getDatabase
import com.metallic.chiaki.common.ext.viewModelFactory
import com.metallic.chiaki.lib.ConnectInfo
import com.metallic.chiaki.lib.DiscoveryHost
import com.metallic.chiaki.regist.RegistActivity
import com.metallic.chiaki.settings.SettingsActivity
import com.metallic.chiaki.stream.StreamActivity
@ -171,12 +173,18 @@ class MainActivity : AppCompatActivity()
val registeredHost = host.registeredHost
if(registeredHost != null)
{
// TODO: check standby
val connectInfo = ConnectInfo(host.host, registeredHost.rpRegistKey, registeredHost.rpKey, Preferences(this).videoProfile)
Intent(this, StreamActivity::class.java).let {
it.putExtra(StreamActivity.EXTRA_CONNECT_INFO, connectInfo)
startActivity(it)
if(host is DiscoveredDisplayHost && host.discoveredHost.state == DiscoveryHost.State.STANDBY)
{
// TODO: show AlertDialog
viewModel.discoveryManager.sendWakeup(host.host, registeredHost.rpRegistKey)
}
else
{
val connectInfo = ConnectInfo(host.host, registeredHost.rpRegistKey, registeredHost.rpKey, Preferences(this).videoProfile)
Intent(this, StreamActivity::class.java).let {
it.putExtra(StreamActivity.EXTRA_CONNECT_INFO, connectInfo)
startActivity(it)
}
}
}
else

View file

@ -2,6 +2,7 @@
<string name="app_name">Chiaki</string>
<string name="title_main">Chiaki 千秋</string>
<string name="title_settings">Settings</string>
<string name="alert_message_standby_wakeup">The Console is currently in standby mode. Do you want to send a Wakeup packet instead of trying to connect immediately?</string>
<string name="alert_message_session_quit">Session has quit: %s</string>
<string name="alert_message_session_create_error">Failed to create Session: %s</string>
<string name="alert_message_login_pin_request">Login PIN:</string>