mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 02:36:51 -07:00
Execute Regist on Android
This commit is contained in:
parent
cbc24bd58d
commit
cc9c8b8bc9
4 changed files with 59 additions and 9 deletions
|
@ -735,19 +735,24 @@ JNIEXPORT void JNICALL JNI_FCN(registStart)(JNIEnv *env, jobject obj, jobject re
|
|||
jclass regist_info_class = E->GetObjectClass(env, regist_info_obj);
|
||||
jstring host_string = E->GetObjectField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "host", "Ljava/lang/String;"));
|
||||
jboolean broadcast = E->GetBooleanField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "broadcast", "Z"));
|
||||
jstring psn_id_string = E->GetObjectField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "psnId", "Ljava/lang/String;"));
|
||||
jstring psn_online_id_string = E->GetObjectField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "psnOnlineId", "Ljava/lang/String;"));
|
||||
jbyteArray psn_account_id_array = E->GetObjectField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "psnAccountId", "[B"));
|
||||
jint pin = E->GetIntField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "pin", "I"));
|
||||
|
||||
ChiakiRegistInfo regist_info;
|
||||
ChiakiRegistInfo regist_info = { 0 };
|
||||
regist_info.host = E->GetStringUTFChars(env, host_string, NULL);
|
||||
regist_info.broadcast = broadcast;
|
||||
// TODO regist_info.psn_id = E->GetStringUTFChars(env, psn_id_string, NULL);
|
||||
if(psn_online_id_string)
|
||||
regist_info.psn_online_id = E->GetStringUTFChars(env, psn_online_id_string, NULL);
|
||||
if(psn_account_id_array && E->GetArrayLength(env, psn_account_id_array) == sizeof(regist_info.psn_account_id))
|
||||
E->GetByteArrayRegion(env, psn_account_id_array, 0, sizeof(regist_info.psn_account_id), (jbyte *)regist_info.psn_account_id);
|
||||
regist_info.pin = (uint32_t)pin;
|
||||
|
||||
err = chiaki_regist_start(®ist->regist, ®ist->log.log, ®ist_info, android_chiaki_regist_cb, regist);
|
||||
|
||||
E->ReleaseStringUTFChars(env, host_string, regist_info.host);
|
||||
// TODO E->ReleaseStringUTFChars(env, psn_id_string, regist_info.psn_id);
|
||||
if(regist_info.psn_online_id)
|
||||
E->ReleaseStringUTFChars(env, psn_online_id_string, regist_info.psn_online_id);
|
||||
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
|
|
|
@ -289,9 +289,16 @@ class DiscoveryService(
|
|||
data class RegistInfo(
|
||||
val host: String,
|
||||
val broadcast: Boolean,
|
||||
val psnId: String, // TODO: this is outdated now
|
||||
val psnOnlineId: String?,
|
||||
val psnAccountId: ByteArray?,
|
||||
val pin: Int
|
||||
): Parcelable
|
||||
{
|
||||
companion object
|
||||
{
|
||||
const val ACCOUNT_ID_SIZE = 8
|
||||
}
|
||||
}
|
||||
|
||||
data class RegistHost(
|
||||
val apSsid: String,
|
||||
|
|
|
@ -19,6 +19,8 @@ package com.metallic.chiaki.regist
|
|||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -28,6 +30,7 @@ import com.metallic.chiaki.R
|
|||
import com.metallic.chiaki.common.ext.RevealActivity
|
||||
import com.metallic.chiaki.lib.RegistInfo
|
||||
import kotlinx.android.synthetic.main.activity_regist.*
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
class RegistActivity: AppCompatActivity(), RevealActivity
|
||||
{
|
||||
|
@ -37,6 +40,8 @@ class RegistActivity: AppCompatActivity(), RevealActivity
|
|||
const val EXTRA_BROADCAST = "regist_broadcast"
|
||||
|
||||
private const val PIN_LENGTH = 8
|
||||
|
||||
private const val REQUEST_REGIST = 1
|
||||
}
|
||||
|
||||
override val revealWindow: Window get() = window
|
||||
|
@ -84,18 +89,33 @@ class RegistActivity: AppCompatActivity(), RevealActivity
|
|||
|
||||
private fun doRegist()
|
||||
{
|
||||
val ps4Version = viewModel.ps4Version.value ?: RegistViewModel.PS4Version.GE_7
|
||||
|
||||
val host = hostEditText.text.toString().trim()
|
||||
val hostValid = host.isNotEmpty()
|
||||
val broadcast = broadcastCheckBox.isChecked
|
||||
|
||||
val psnId = psnIdEditText.text.toString().trim()
|
||||
val psnIdValid = psnId.isNotEmpty()
|
||||
val psnOnlineId: String? = if(ps4Version == RegistViewModel.PS4Version.LT_7) psnId else null
|
||||
val psnAccountId: ByteArray? =
|
||||
if(ps4Version == RegistViewModel.PS4Version.GE_7)
|
||||
try { Base64.decode(psnId, Base64.DEFAULT) } catch(e: IllegalArgumentException) { null }
|
||||
else
|
||||
null
|
||||
val psnIdValid = when(ps4Version)
|
||||
{
|
||||
RegistViewModel.PS4Version.GE_7 -> psnAccountId != null && psnAccountId.size == RegistInfo.ACCOUNT_ID_SIZE
|
||||
RegistViewModel.PS4Version.LT_7 -> psnOnlineId?.isNotEmpty() ?: false
|
||||
}
|
||||
|
||||
|
||||
val pin = pinEditText.text.toString()
|
||||
val pinValid = pin.length == PIN_LENGTH
|
||||
|
||||
hostEditText.error = if(!hostValid) getString(R.string.regist_host_invalid) else null
|
||||
psnIdEditText.error =
|
||||
if(!psnIdValid)
|
||||
getString(when(viewModel.ps4Version.value ?: RegistViewModel.PS4Version.GE_7)
|
||||
getString(when(ps4Version)
|
||||
{
|
||||
RegistViewModel.PS4Version.GE_7 -> R.string.regist_psn_account_id_invalid
|
||||
RegistViewModel.PS4Version.LT_7 -> R.string.regist_psn_online_id_invalid
|
||||
|
@ -107,11 +127,18 @@ class RegistActivity: AppCompatActivity(), RevealActivity
|
|||
if(!hostValid || !psnIdValid || !pinValid)
|
||||
return
|
||||
|
||||
val registInfo = RegistInfo(host, broadcast, psnId, pin.toInt())
|
||||
val registInfo = RegistInfo(host, broadcast, psnOnlineId, psnAccountId, pin.toInt())
|
||||
|
||||
Intent(this, RegistExecuteActivity::class.java).also {
|
||||
it.putExtra(RegistExecuteActivity.EXTRA_REGIST_INFO, registInfo)
|
||||
startActivity(it)
|
||||
startActivityForResult(it, REQUEST_REGIST)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if(requestCode == REQUEST_REGIST && resultCode == RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
}
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package com.metallic.chiaki.regist
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.method.ScrollingMovementMethod
|
||||
|
@ -34,6 +36,8 @@ class RegistExecuteActivity: AppCompatActivity()
|
|||
companion object
|
||||
{
|
||||
const val EXTRA_REGIST_INFO = "regist_info"
|
||||
|
||||
const val RESULT_FAILED = Activity.RESULT_FIRST_USER
|
||||
}
|
||||
|
||||
private lateinit var viewModel: RegistExecuteViewModel
|
||||
|
@ -61,11 +65,18 @@ class RegistExecuteActivity: AppCompatActivity()
|
|||
{
|
||||
infoTextView.visibility = View.VISIBLE
|
||||
infoTextView.setText(R.string.regist_info_failed)
|
||||
setResult(RESULT_FAILED)
|
||||
}
|
||||
RegistExecuteViewModel.State.SUCCESSFUL ->
|
||||
{
|
||||
infoTextView.visibility = View.VISIBLE
|
||||
infoTextView.setText(R.string.regist_info_success)
|
||||
setResult(RESULT_OK)
|
||||
}
|
||||
RegistExecuteViewModel.State.STOPPED ->
|
||||
{
|
||||
infoTextView.visibility = View.GONE
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
}
|
||||
else -> infoTextView.visibility = View.GONE
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue