diff --git a/android/.idea/codeStyles/Project.xml b/android/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..88ea3aa --- /dev/null +++ b/android/.idea/codeStyles/Project.xml @@ -0,0 +1,122 @@ + + + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+ + +
+
\ No newline at end of file diff --git a/android/.idea/codeStyles/codeStyleConfig.xml b/android/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/android/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/android/.idea/compiler.xml b/android/.idea/compiler.xml index 61a9130..fb7f4a8 100644 --- a/android/.idea/compiler.xml +++ b/android/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/android/.idea/gradle.xml b/android/.idea/gradle.xml index b617266..cc2be69 100644 --- a/android/.idea/gradle.xml +++ b/android/.idea/gradle.xml @@ -4,7 +4,7 @@ diff --git a/android/.idea/misc.xml b/android/.idea/misc.xml index d5d35ec..b8001c4 100644 --- a/android/.idea/misc.xml +++ b/android/.idea/misc.xml @@ -1,6 +1,17 @@ - + + + + diff --git a/android/app/build.gradle b/android/app/build.gradle index 817bc89..4517d25 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -21,6 +21,7 @@ android { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + debuggable false } } compileOptions { @@ -30,10 +31,17 @@ android { kotlinOptions { jvmTarget = '1.8' } + buildFeatures { + viewBinding true + } } dependencies { - + implementation ('io.socket:socket.io-client:2.0.1') { + // excluding org.json which is provided by Android + exclude group: 'org.json', module: 'json' + } + implementation fileTree(dir: 'libs', include: ['lineage-sdk.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.1.0' @@ -46,6 +54,6 @@ dependencies { implementation 'com.rabbitmq:amqp-client:5.9.0' implementation "com.squareup.okhttp3:okhttp:4.9.0" testImplementation 'junit:junit:4.+' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' } \ No newline at end of file diff --git a/android/app/libs/lineage-sdk.jar b/android/app/libs/lineage-sdk.jar new file mode 100644 index 0000000..63c8a4b Binary files /dev/null and b/android/app/libs/lineage-sdk.jar differ diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 70b3e7b..b83118c 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ + package="de.nicolasklier.livebeat" > @@ -19,18 +19,26 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:usesCleartextTraffic="true" - android:theme="@style/Theme.Livebeat"> + android:theme="@style/Theme.Livebeat" + android:usesCleartextTraffic="true" > + + - - - + + + + + + android:theme="@style/Theme.Livebeat.NoActionBar" > diff --git a/android/app/src/main/java/de/nicolasklier/livebeat/MainActivity.kt b/android/app/src/main/java/de/nicolasklier/livebeat/MainActivity.kt index 17c26db..5a935d6 100644 --- a/android/app/src/main/java/de/nicolasklier/livebeat/MainActivity.kt +++ b/android/app/src/main/java/de/nicolasklier/livebeat/MainActivity.kt @@ -10,16 +10,13 @@ import android.content.pm.PackageManager import android.graphics.Color import android.os.Build import android.os.Bundle -import android.os.Handler -import android.os.Looper import android.provider.Settings -import android.telephony.TelephonyManager -import android.util.Log import android.view.Menu import android.view.MenuItem import android.view.View import android.widget.Button import android.widget.TextView +import androidx.annotation.ColorInt import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat @@ -27,11 +24,9 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.snackbar.Snackbar import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory -import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody.Companion.toRequestBody -import java.util.logging.Logger @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") class MainActivity : AppCompatActivity() { @@ -46,6 +41,15 @@ class MainActivity : AppCompatActivity() { @SuppressLint("HardwareIds") fun checkIfPhoneIsRegistered() { + val pref = this.getPreferences(Context.MODE_PRIVATE) ?: return + val accessToken = pref.getString("accessToken", ""); + + // App is not setup + if (accessToken == "") { + val intent = Intent(baseContext, SetupActivity::class.java); + startActivity(intent); + } + if (TOKEN == "") return; Thread(Runnable { val androidId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) @@ -95,8 +99,6 @@ class MainActivity : AppCompatActivity() { setContentView(R.layout.activity_main) setSupportActionBar(findViewById(R.id.toolbar)) - val process = Runtime.getRuntime().exec("su") - // Check authorization val backendChecks = Thread(Runnable { val username = findViewById(R.id.username).text @@ -142,7 +144,7 @@ class MainActivity : AppCompatActivity() { USER = jsonToUser.fromJson(userInfoResponseBody) // Only start service if authentication went good. - startService(Intent(this, TrackerService::class.java)) + // startService(Intent(this, TrackerService::class.java)) Snackbar.make(findViewById(R.id.fab), "Login succeeded", Snackbar.LENGTH_SHORT) .setBackgroundTint(Color.GREEN) @@ -174,14 +176,6 @@ class MainActivity : AppCompatActivity() { val statusRabbit = intent.getBooleanExtra("statusRabbit", false) val statusHttp = intent.getIntExtra("statusHttp", 404) - if (statusRabbit) { - findViewById(R.id.rabbitStatus).text = "connected" - findViewById(R.id.rabbitStatus).setTextColor(Color.GREEN) - } else { - findViewById(R.id.rabbitStatus).text = "disconnected" - findViewById(R.id.rabbitStatus).setTextColor(Color.RED) - } - /*if (statusHttp == 200) { findViewById(R.id.httpStatus).text = "ONLINE (no login)" findViewById(R.id.httpStatus).setTextColor(Color.CYAN) @@ -203,6 +197,14 @@ class MainActivity : AppCompatActivity() { } } + @ColorInt + private fun getAccentColor(): Int { + val attr = intArrayOf(android.R.attr.colorAccent) + val typedArray = obtainStyledAttributes(android.R.style.Theme_DeviceDefault, attr) + return typedArray.getColor(0, Color.BLACK) + .also { typedArray.recycle() } + } + private fun checkPerms() { if (ActivityCompat.checkSelfPermission( this, diff --git a/android/app/src/main/java/de/nicolasklier/livebeat/Models.kt b/android/app/src/main/java/de/nicolasklier/livebeat/Models.kt index 4c6ad7e..45f2d11 100644 --- a/android/app/src/main/java/de/nicolasklier/livebeat/Models.kt +++ b/android/app/src/main/java/de/nicolasklier/livebeat/Models.kt @@ -22,12 +22,21 @@ class Phone( val architecture: String ) {} +class PhoneRegistration ( + val phone: Phone, + val token: String +) {} + +class PhoneSubmitPairCode ( + val phoneId: String, + val code: String +) {} + class User( val name: String, val type: String, val lastLogin: String, val twoFASecret: String?, - val brokerToken: String, val createdAt: String ) diff --git a/android/app/src/main/java/de/nicolasklier/livebeat/SetupActivity.kt b/android/app/src/main/java/de/nicolasklier/livebeat/SetupActivity.kt new file mode 100644 index 0000000..ca39790 --- /dev/null +++ b/android/app/src/main/java/de/nicolasklier/livebeat/SetupActivity.kt @@ -0,0 +1,195 @@ +package de.nicolasklier.livebeat + +import android.content.Context +import android.os.Build +import android.os.Bundle +import android.provider.Settings +import android.util.Log +import android.view.View +import android.widget.* +import androidx.appcompat.app.AppCompatActivity +import androidx.navigation.ui.AppBarConfiguration +import com.squareup.moshi.Moshi +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory +import de.nicolasklier.livebeat.databinding.ActivitySetupBinding +import de.nicolasklier.livebeat.dialogs.ErrorDialog +import de.nicolasklier.livebeat.dialogs.InputDialog +import io.socket.client.IO +import io.socket.client.Socket +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.RequestBody.Companion.toRequestBody +import org.json.JSONObject +import java.lang.Exception + +class SetupActivity : AppCompatActivity() { + + private lateinit var appBarConfiguration: AppBarConfiguration + private lateinit var binding: ActivitySetupBinding + + private var host = "" + private var username = "" + private var password = "" + private var token = "" + private lateinit var socket: Socket; + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + binding = ActivitySetupBinding.inflate(layoutInflater) + setContentView(binding.root) + + findViewById