Skip to content

Commit

Permalink
updater dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
basti564 committed Feb 21, 2022
1 parent a30d3be commit 8ee61fc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.android.volley:volley:1.2.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
package="com.bos.oculess">

<uses-feature android:glEsVersion="0x00030001" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:banner="@mipmap/ic_banner"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:banner="@mipmap/ic_banner"
android:supportsRtl="true"
android:theme="@style/Theme.Oculess">
<receiver
Expand All @@ -19,6 +20,7 @@
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>

<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin" />
Expand Down
65 changes: 57 additions & 8 deletions app/src/main/java/com/bos/oculess/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.os.Looper
import android.net.Uri
import android.os.*
import android.provider.Settings
import android.text.Html
import android.util.Log
import android.view.WindowManager
import android.widget.Button
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.android.volley.Request
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
import com.bos.oculess.util.AppOpsUtil
import org.json.JSONException
import org.json.JSONObject
import org.json.JSONTokener
import kotlin.concurrent.fixedRateTimer
import android.os.Handler as Handler


class MainActivity : AppCompatActivity() {
Expand All @@ -33,6 +39,52 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val queue = Volley.newRequestQueue(this)

val manager = this.packageManager
val info = manager.getPackageInfo(this.packageName, PackageManager.GET_ACTIVITIES)

val stringRequest = StringRequest(
Request.Method.GET, "https://api.github.com/repos/basti564/oculess/releases/latest",
{ response ->
try {
val jsonObject =
JSONTokener("null").nextValue() as JSONObject
if (jsonObject.getString("tag_name") != "v" + info.versionName) {
Log.v("Oculess", "New version available!!!!")

val builder: AlertDialog.Builder = AlertDialog.Builder(this)
builder.setTitle("An update is available!")
builder.setMessage(
"We recommend you to update to the latest version of Oculess (" + jsonObject.getString(
"tag_name"
) + ")"
)
builder.setPositiveButton("View") { dialog, _ ->
val browserIntent = Intent(
Intent.ACTION_VIEW,
Uri.parse(jsonObject.getString("html_url"))
)
startActivity(browserIntent)
}
builder.setNegativeButton("Dismiss") { dialog, _ ->
dialog.dismiss()
}
val alertDialog: AlertDialog = builder.create()
alertDialog.show()
alertDialog.window!!.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
} else {
Log.i("Oculess", "Oculess is up to date :)")
}
}
catch (e: Exception){
Log.e("Oculess", "Received invalid JSON", e)
}
},
{ Log.w("Oculess", "Couldn't get update info") })

queue.add(stringRequest)

val updaterName = "com.oculus.updater"
val telemetryApps = arrayOf(
"com.oculus.unifiedtelemetry",
Expand Down Expand Up @@ -146,10 +198,7 @@ class MainActivity : AppCompatActivity() {
val alertDialog: AlertDialog = builder.create()

if (dpm.isAdminActive(
ComponentName(
"com.oculus.companion.server",
"com.oculus.companion.server.CompanionDeviceAdmin\$CompanionDeviceAdminReceiver"
)
deviceAdminReceiverComponentName
)
) {
alertDialog.show()
Expand Down

0 comments on commit 8ee61fc

Please sign in to comment.