mirror of
https://github.com/basti564/Oculess.git
synced 2024-11-24 11:12:36 +01:00
updater dialog
This commit is contained in:
parent
a30d3be0f7
commit
8ee61fc958
@ -38,6 +38,7 @@ dependencies {
|
|||||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||||
implementation 'com.google.android.material:material:1.4.0'
|
implementation 'com.google.android.material:material:1.4.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
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.ext:junit:1.1.3'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||||
}
|
}
|
@ -3,13 +3,14 @@
|
|||||||
package="com.bos.oculess">
|
package="com.bos.oculess">
|
||||||
|
|
||||||
<uses-feature android:glEsVersion="0x00030001" />
|
<uses-feature android:glEsVersion="0x00030001" />
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
android:banner="@mipmap/ic_banner"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:banner="@mipmap/ic_banner"
|
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.Oculess">
|
android:theme="@style/Theme.Oculess">
|
||||||
<receiver
|
<receiver
|
||||||
@ -19,6 +20,7 @@
|
|||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
|
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.app.device_admin"
|
android:name="android.app.device_admin"
|
||||||
android:resource="@xml/device_admin" />
|
android:resource="@xml/device_admin" />
|
||||||
|
@ -7,21 +7,27 @@ import android.content.ComponentName
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ApplicationInfo
|
import android.content.pm.ApplicationInfo
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Build
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.*
|
||||||
import android.os.Looper
|
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.text.Html
|
import android.text.Html
|
||||||
|
import android.util.Log
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
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 com.bos.oculess.util.AppOpsUtil
|
||||||
|
import org.json.JSONException
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.json.JSONTokener
|
||||||
import kotlin.concurrent.fixedRateTimer
|
import kotlin.concurrent.fixedRateTimer
|
||||||
import android.os.Handler as Handler
|
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
@ -33,6 +39,52 @@ class MainActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
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 updaterName = "com.oculus.updater"
|
||||||
val telemetryApps = arrayOf(
|
val telemetryApps = arrayOf(
|
||||||
"com.oculus.unifiedtelemetry",
|
"com.oculus.unifiedtelemetry",
|
||||||
@ -146,10 +198,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val alertDialog: AlertDialog = builder.create()
|
val alertDialog: AlertDialog = builder.create()
|
||||||
|
|
||||||
if (dpm.isAdminActive(
|
if (dpm.isAdminActive(
|
||||||
ComponentName(
|
deviceAdminReceiverComponentName
|
||||||
"com.oculus.companion.server",
|
|
||||||
"com.oculus.companion.server.CompanionDeviceAdmin\$CompanionDeviceAdminReceiver"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
alertDialog.show()
|
alertDialog.show()
|
||||||
|
Loading…
Reference in New Issue
Block a user