This commit is contained in:
sim 2022-02-19 16:19:08 +01:00
parent bfeed9662c
commit 68861956d4
11 changed files with 543 additions and 533 deletions

View File

@ -23,9 +23,11 @@ import org.unifiedpush.distributor.nextpush.R
private const val TAG = "AccountUtils" private const val TAG = "AccountUtils"
const val PREF_NAME = "NextPush" private const val PREF_NAME = "NextPush"
const val PREF_DEVICE_ID = "deviceId" private const val PREF_DEVICE_ID = "deviceId"
const val PREF_URL = "url" private const val PREF_URL = "url"
object AccountUtils {
lateinit var ssoAccount: SingleSignOnAccount lateinit var ssoAccount: SingleSignOnAccount
@ -34,7 +36,10 @@ fun nextcloudAppNotInstalledDialog(context: Context) {
val builder = AlertDialog.Builder(context) val builder = AlertDialog.Builder(context)
var messageContent = context.getString(R.string.message_missing_nextcloud_app) var messageContent = context.getString(R.string.message_missing_nextcloud_app)
val installIntent = val installIntent =
Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.uri_market_nextcloud_app))) Intent(
Intent.ACTION_VIEW,
Uri.parse(context.getString(R.string.uri_market_nextcloud_app))
)
messageContent += if ( messageContent += if (
installIntent.resolveActivity(context.applicationContext.packageManager) != null installIntent.resolveActivity(context.applicationContext.packageManager) != null
) { ) {
@ -42,14 +47,14 @@ fun nextcloudAppNotInstalledDialog(context: Context) {
context.startActivity( context.startActivity(
Intent.createChooser( Intent.createChooser(
installIntent, installIntent,
context.getString(R.string.market_chooser_title)) context.getString(R.string.market_chooser_title)
)
) )
} }
builder.setPositiveButton(context.getString(R.string.install)) { builder.setPositiveButton(context.getString(R.string.install)) { _: DialogInterface, _: Int ->
_: DialogInterface, _: Int -> callback() callback()
} }
builder.setNegativeButton(context.getString(R.string.dismiss)) { builder.setNegativeButton(context.getString(R.string.dismiss)) { _: DialogInterface, _: Int ->
_: DialogInterface, _: Int ->
} }
"." "."
} else { } else {
@ -127,3 +132,4 @@ fun removeUrl(context: Context) {
.remove(PREF_URL) .remove(PREF_URL)
.commit() .commit()
} }
}

View File

@ -13,27 +13,22 @@ import android.widget.*
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.nextcloud.android.sso.AccountImporter import com.nextcloud.android.sso.AccountImporter
import com.nextcloud.android.sso.ui.UiExceptionManager import com.nextcloud.android.sso.ui.UiExceptionManager
import com.nextcloud.android.sso.AccountImporter.IAccountAccessGranted
import com.nextcloud.android.sso.api.NextcloudAPI.ApiConnectedListener
import com.nextcloud.android.sso.helper.SingleAccountHelper import com.nextcloud.android.sso.helper.SingleAccountHelper
import com.nextcloud.android.sso.model.SingleSignOnAccount
import java.lang.Exception
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.nextcloud.android.sso.AccountImporter.clearAllAuthTokens import com.nextcloud.android.sso.AccountImporter.clearAllAuthTokens
import com.nextcloud.android.sso.exceptions.* import com.nextcloud.android.sso.exceptions.*
import org.unifiedpush.distributor.nextpush.R import org.unifiedpush.distributor.nextpush.R
import org.unifiedpush.distributor.nextpush.account.isConnected import org.unifiedpush.distributor.nextpush.account.AccountUtils.connect
import org.unifiedpush.distributor.nextpush.account.connect import org.unifiedpush.distributor.nextpush.account.AccountUtils.isConnected
import org.unifiedpush.distributor.nextpush.account.nextcloudAppNotInstalledDialog import org.unifiedpush.distributor.nextpush.account.AccountUtils.nextcloudAppNotInstalledDialog
import org.unifiedpush.distributor.nextpush.account.ssoAccount import org.unifiedpush.distributor.nextpush.account.AccountUtils.ssoAccount
import org.unifiedpush.distributor.nextpush.api.apiDeleteApp import org.unifiedpush.distributor.nextpush.api.ApiUtils.apiDeleteApp
import org.unifiedpush.distributor.nextpush.api.apiDeleteDevice import org.unifiedpush.distributor.nextpush.api.ApiUtils.apiDeleteDevice
import org.unifiedpush.distributor.nextpush.distributor.sendUnregistered import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.sendUnregistered
import org.unifiedpush.distributor.nextpush.distributor.getDb import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.getDb
import org.unifiedpush.distributor.nextpush.services.* import org.unifiedpush.distributor.nextpush.services.*
import java.lang.String.format import java.lang.String.format
@ -64,22 +59,10 @@ class MainActivity : AppCompatActivity() {
requestCode, requestCode,
resultCode, resultCode,
data, data,
this, this
object : IAccountAccessGranted { ) { account ->
var callback: ApiConnectedListener = object : ApiConnectedListener {
override fun onConnected() {}
override fun onError(ex: Exception) {
Log.e(TAG, "Cannot get account access", ex)
}
}
override fun accountAccessGranted(account: SingleSignOnAccount) {
val context = applicationContext val context = applicationContext
// As this library supports multiple accounts we created some helper methods if you only want to use one.
// The following line stores the selected account as the "default" account which can be queried by using
// the SingleAccountHelper.getCurrentSingleSignOnAccount(context) method
SingleAccountHelper.setCurrentAccount(context, account.name) SingleAccountHelper.setCurrentAccount(context, account.name)
// Get the "default" account // Get the "default" account
@ -92,7 +75,6 @@ class MainActivity : AppCompatActivity() {
} }
showMain() showMain()
} }
})
} catch (e: AccountImportCancelledException) {} } catch (e: AccountImportCancelledException) {}
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
} }
@ -173,15 +155,15 @@ class MainActivity : AppCompatActivity() {
.apply() .apply()
apiDeleteDevice(this) apiDeleteDevice(this)
showStart() showStart()
finish(); finish()
startActivity(intent); startActivity(intent)
} }
alert.setNegativeButton(getString(R.string.discard)) { dialog, _ -> dialog.dismiss() } alert.setNegativeButton(getString(R.string.discard)) { dialog, _ -> dialog.dismiss() }
alert.show() alert.show()
} }
private fun setListView(){ private fun setListView(){
listView = findViewById<ListView>(R.id.applications_list) listView = findViewById(R.id.applications_list)
val db = getDb(this) val db = getDb(this)
val tokenList = db.listTokens().toMutableList() val tokenList = db.listTokens().toMutableList()
val appList = emptyArray<String>().toMutableList() val appList = emptyArray<String>().toMutableList()
@ -194,7 +176,7 @@ class MainActivity : AppCompatActivity() {
appList appList
) )
listView.setOnItemLongClickListener( listView.setOnItemLongClickListener(
fun(parent: AdapterView<*>, v: View, position: Int, id: Long): Boolean { fun(_: AdapterView<*>, _: View, position: Int, _: Long): Boolean {
val alert: android.app.AlertDialog.Builder = android.app.AlertDialog.Builder( val alert: android.app.AlertDialog.Builder = android.app.AlertDialog.Builder(
this) this)
alert.setTitle("Unregistering") alert.setTitle("Unregistering")
@ -202,9 +184,9 @@ class MainActivity : AppCompatActivity() {
alert.setPositiveButton("YES") { dialog, _ -> alert.setPositiveButton("YES") { dialog, _ ->
val connectorToken = tokenList[position] val connectorToken = tokenList[position]
sendUnregistered(this, connectorToken) sendUnregistered(this, connectorToken)
val db = getDb(this) val database = getDb(this)
val appToken = db.getAppToken(connectorToken) val appToken = database.getAppToken(connectorToken)
db.unregisterApp(connectorToken) database.unregisterApp(connectorToken)
apiDeleteApp(this, appToken) { apiDeleteApp(this, appToken) {
Log.d(TAG,"Unregistration is finished") Log.d(TAG,"Unregistration is finished")
} }

View File

@ -12,20 +12,26 @@ import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import okhttp3.sse.EventSource import okhttp3.sse.EventSource
import okhttp3.sse.EventSources import okhttp3.sse.EventSources
import org.unifiedpush.distributor.nextpush.account.* import org.unifiedpush.distributor.nextpush.account.AccountUtils.getDeviceId
import org.unifiedpush.distributor.nextpush.account.AccountUtils.removeDeviceId
import org.unifiedpush.distributor.nextpush.account.AccountUtils.removeUrl
import org.unifiedpush.distributor.nextpush.account.AccountUtils.saveDeviceId
import org.unifiedpush.distributor.nextpush.account.AccountUtils.saveUrl
import org.unifiedpush.distributor.nextpush.account.AccountUtils.ssoAccount
import org.unifiedpush.distributor.nextpush.api.ProviderApi.Companion.mApiEndpoint import org.unifiedpush.distributor.nextpush.api.ProviderApi.Companion.mApiEndpoint
import org.unifiedpush.distributor.nextpush.distributor.getDb import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.getDb
import org.unifiedpush.distributor.nextpush.distributor.sendUnregistered import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.sendUnregistered
import org.unifiedpush.distributor.nextpush.services.SSEListener import org.unifiedpush.distributor.nextpush.services.SSEListener
import retrofit2.NextcloudRetrofitApiBuilder import retrofit2.NextcloudRetrofitApiBuilder
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
private const val TAG = "ApiUtils" private const val TAG = "ApiUtils"
object ApiUtils {
val createQueue = emptyList<String>().toMutableList() val createQueue = emptyList<String>().toMutableList()
val delQueue = emptyList<String>().toMutableList() val delQueue = emptyList<String>().toMutableList()
private lateinit var mApi: ProviderApi private lateinit var mApi: ProviderApi
private lateinit var nextcloudAPI: NextcloudAPI private lateinit var nextcloudAPI: NextcloudAPI
private lateinit var factory: EventSource.Factory private lateinit var factory: EventSource.Factory
@ -42,16 +48,17 @@ private fun cApi(context: Context, callback: ()->Unit) {
if (::mApi.isInitialized and ::nextcloudAPI.isInitialized) { if (::mApi.isInitialized and ::nextcloudAPI.isInitialized) {
callback() callback()
} else { } else {
val callback = object : NextcloudAPI.ApiConnectedListener { val nCallback = object : NextcloudAPI.ApiConnectedListener {
override fun onConnected() { override fun onConnected() {
Log.d(TAG, "Api connected.") Log.d(TAG, "Api connected.")
callback() callback()
} }
override fun onError(ex: Exception) { override fun onError(ex: Exception) {
Log.d(TAG, "Cannot connect to API: ex = [$ex]") Log.d(TAG, "Cannot connect to API: ex = [$ex]")
} }
} }
nextcloudAPI = NextcloudAPI(context, ssoAccount, GsonBuilder().create(), callback) nextcloudAPI = NextcloudAPI(context, ssoAccount, GsonBuilder().create(), nCallback)
mApi = NextcloudRetrofitApiBuilder(nextcloudAPI, mApiEndpoint) mApi = NextcloudRetrofitApiBuilder(nextcloudAPI, mApiEndpoint)
.create(ProviderApi::class.java) .create(ProviderApi::class.java)
} }
@ -157,10 +164,12 @@ private fun cDeleteDevice(context: Context) {
removeDeviceId(context) removeDeviceId(context)
} }
fun apiCreateApp(context: Context, fun apiCreateApp(
context: Context,
appName: String, appName: String,
connectorToken: String, connectorToken: String,
callback: ()->Unit) { callback: () -> Unit
) {
cApi(context) { cApi(context) {
cCreateApp(context, appName, connectorToken) { cCreateApp(context, appName, connectorToken) {
callback() callback()
@ -168,10 +177,12 @@ fun apiCreateApp(context: Context,
} }
} }
private fun cCreateApp(context: Context, private fun cCreateApp(
context: Context,
appName: String, appName: String,
connectorToken: String, connectorToken: String,
callback: ()->Unit) { callback: () -> Unit
) {
// The unity of connector token must already be checked here // The unity of connector token must already be checked here
val parameters = mutableMapOf( val parameters = mutableMapOf(
"deviceId" to getDeviceId(context)!!, "deviceId" to getDeviceId(context)!!,
@ -249,3 +260,4 @@ private fun cDeleteApp(context: Context, connectorToken: String, callback: ()->U
} }
}) })
} }
}

View File

@ -1,8 +1,7 @@
package org.unifiedpush.distributor.nextpush.api package org.unifiedpush.distributor.nextpush.api
import io.reactivex.Observable; import io.reactivex.Observable
import retrofit2.http.PUT import retrofit2.http.PUT
import retrofit2.http.GET
import retrofit2.http.DELETE import retrofit2.http.DELETE
import retrofit2.http.Body import retrofit2.http.Body
import retrofit2.http.Path import retrofit2.http.Path
@ -14,9 +13,6 @@ interface ProviderApi {
@Body subscribeMap: MutableMap<String, String>? @Body subscribeMap: MutableMap<String, String>?
): Observable<ApiResponse>? ): Observable<ApiResponse>?
@GET("/device/{deviceId}")
fun syncDevice(@Path("deviceId") devideId: String?): Observable<SSEResponse?>?
@DELETE("/device/{deviceId}") @DELETE("/device/{deviceId}")
fun deleteDevice(@Path("deviceId") devideId: String?): Observable<ApiResponse>? fun deleteDevice(@Path("deviceId") devideId: String?): Observable<ApiResponse>?

View File

@ -3,7 +3,7 @@ package org.unifiedpush.distributor.nextpush.distributor
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.util.Log import android.util.Log
import org.unifiedpush.distributor.nextpush.account.getUrl import org.unifiedpush.distributor.nextpush.account.AccountUtils.getUrl
/** /**
* These functions are used to send messages to other apps * These functions are used to send messages to other apps
@ -11,6 +11,8 @@ import org.unifiedpush.distributor.nextpush.account.getUrl
private const val TAG = "DistributorUtils" private const val TAG = "DistributorUtils"
object DistributorUtils {
const val TOKEN_NEW = "token_new" const val TOKEN_NEW = "token_new"
const val TOKEN_REGISTERED_OK = "token_registered_ok" const val TOKEN_REGISTERED_OK = "token_registered_ok"
const val TOKEN_NOK = "token_nok" const val TOKEN_NOK = "token_nok"
@ -59,7 +61,7 @@ fun sendRegistrationFailed(
connectorToken: String, connectorToken: String,
message: String = "" message: String = ""
) { ) {
if (application.isNullOrBlank()) { application.ifBlank {
return return
} }
val broadcastIntent = Intent() val broadcastIntent = Intent()
@ -82,7 +84,7 @@ fun sendUnregistered(context: Context, connectorToken: String) {
context.sendBroadcast(broadcastIntent) context.sendBroadcast(broadcastIntent)
} }
fun getApp(context: Context, connectorToken: String): String?{ private fun getApp(context: Context, connectorToken: String): String? {
val db = getDb(context) val db = getDb(context)
val app = db.getPackageName(connectorToken) val app = db.getPackageName(connectorToken)
return if (app.isBlank()) { return if (app.isBlank()) {
@ -93,7 +95,7 @@ fun getApp(context: Context, connectorToken: String): String?{
} }
} }
fun getEndpoint(context: Context, connectorToken: String): String { private fun getEndpoint(context: Context, connectorToken: String): String {
val db = getDb(context) val db = getDb(context)
val appToken = db.getAppToken(connectorToken) val appToken = db.getAppToken(connectorToken)
return "${getUrl(context)}/push/$appToken" return "${getUrl(context)}/push/$appToken"
@ -109,3 +111,4 @@ fun checkToken(context: Context, connectorToken: String, app: String): String {
} }
return TOKEN_NOK return TOKEN_NOK
} }
}

View File

@ -8,18 +8,18 @@ import android.database.sqlite.SQLiteOpenHelper
private const val DB_NAME = "apps_db" private const val DB_NAME = "apps_db"
private const val DB_VERSION = 1 private const val DB_VERSION = 1
class MessagingDatabase(context: Context): private const val TABLE_APPS = "apps"
SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) { private const val FIELD_PACKAGE_NAME = "packageName"
private val TABLE_APPS = "apps" private const val FIELD_CONNECTOR_TOKEN = "connectorToken"
private val FIELD_PACKAGE_NAME = "packageName" private const val FIELD_APP_TOKEN = "appToken"
private val FIELD_CONNECTOR_TOKEN = "connectorToken" private const val CREATE_TABLE_APPS = "CREATE TABLE apps (" +
private val FIELD_APP_TOKEN = "appToken"
private val CREATE_TABLE_APPS = "CREATE TABLE apps (" +
"$FIELD_PACKAGE_NAME TEXT," + "$FIELD_PACKAGE_NAME TEXT," +
"$FIELD_CONNECTOR_TOKEN TEXT," + "$FIELD_CONNECTOR_TOKEN TEXT," +
"$FIELD_APP_TOKEN TEXT," + "$FIELD_APP_TOKEN TEXT," +
"PRIMARY KEY ($FIELD_CONNECTOR_TOKEN));" "PRIMARY KEY ($FIELD_CONNECTOR_TOKEN));"
class MessagingDatabase(context: Context):
SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
override fun onCreate(db: SQLiteDatabase) { override fun onCreate(db: SQLiteDatabase) {
db.execSQL(CREATE_TABLE_APPS) db.execSQL(CREATE_TABLE_APPS)

View File

@ -7,19 +7,14 @@ package org.unifiedpush.distributor.nextpush.distributor
const val ACTION_NEW_ENDPOINT = "org.unifiedpush.android.connector.NEW_ENDPOINT" const val ACTION_NEW_ENDPOINT = "org.unifiedpush.android.connector.NEW_ENDPOINT"
const val ACTION_REGISTRATION_FAILED = "org.unifiedpush.android.connector.REGISTRATION_FAILED" const val ACTION_REGISTRATION_FAILED = "org.unifiedpush.android.connector.REGISTRATION_FAILED"
const val ACTION_REGISTRATION_REFUSED = "org.unifiedpush.android.connector.REGISTRATION_REFUSED"
const val ACTION_UNREGISTERED = "org.unifiedpush.android.connector.UNREGISTERED" const val ACTION_UNREGISTERED = "org.unifiedpush.android.connector.UNREGISTERED"
const val ACTION_MESSAGE = "org.unifiedpush.android.connector.MESSAGE" const val ACTION_MESSAGE = "org.unifiedpush.android.connector.MESSAGE"
const val ACTION_REGISTER = "org.unifiedpush.android.distributor.REGISTER" const val ACTION_REGISTER = "org.unifiedpush.android.distributor.REGISTER"
const val ACTION_UNREGISTER = "org.unifiedpush.android.distributor.UNREGISTER" const val ACTION_UNREGISTER = "org.unifiedpush.android.distributor.UNREGISTER"
const val ACTION_MESSAGE_ACK = "org.unifiedpush.android.distributor.MESSAGE_ACK"
const val FEATURE_BYTES_MESSAGE = "org.unifiedpush.android.distributor.feature.BYTES_MESSAGE"
const val EXTRA_APPLICATION = "application" const val EXTRA_APPLICATION = "application"
const val EXTRA_TOKEN = "token" const val EXTRA_TOKEN = "token"
const val EXTRA_ENDPOINT = "endpoint" const val EXTRA_ENDPOINT = "endpoint"
const val EXTRA_MESSAGE = "message" const val EXTRA_MESSAGE = "message"
const val EXTRA_BYTES_MESSAGE = "bytesMessage" const val EXTRA_BYTES_MESSAGE = "bytesMessage"
const val EXTRA_MESSAGE_ID = "id"

View File

@ -4,13 +4,21 @@ import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.util.Log import android.util.Log
import org.unifiedpush.distributor.nextpush.account.isConnected import org.unifiedpush.distributor.nextpush.account.AccountUtils.isConnected
import org.unifiedpush.distributor.nextpush.api.ApiUtils.apiCreateApp
import org.unifiedpush.distributor.nextpush.api.ApiUtils.apiDeleteApp
import org.unifiedpush.distributor.nextpush.api.ApiUtils.createQueue
import org.unifiedpush.distributor.nextpush.api.ApiUtils.delQueue
import org.unifiedpush.distributor.nextpush.distributor.* import org.unifiedpush.distributor.nextpush.distributor.*
import org.unifiedpush.distributor.nextpush.api.createQueue import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.TOKEN_NEW
import org.unifiedpush.distributor.nextpush.api.delQueue import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.TOKEN_NOK
import org.unifiedpush.distributor.nextpush.api.apiCreateApp import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.TOKEN_REGISTERED_OK
import org.unifiedpush.distributor.nextpush.api.apiDeleteApp import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.checkToken
import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.getDb
import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.sendEndpoint
import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.sendRegistrationFailed
import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.sendUnregistered
import org.unifiedpush.distributor.nextpush.services.wakeLock import org.unifiedpush.distributor.nextpush.services.wakeLock
import java.lang.Exception import java.lang.Exception

View File

@ -12,8 +12,10 @@ import android.app.PendingIntent
import android.content.Intent import android.content.Intent
import org.unifiedpush.distributor.nextpush.activities.MainActivity import org.unifiedpush.distributor.nextpush.activities.MainActivity
const val NOTIF_ID_FOREGROUND = 51115 const val NOTIFICATION_ID_FOREGROUND = 51115
const val NOTIF_ID_WARNING = 51215 const val NOTIFICATION_ID_WARNING = 51215
object NotificationUtils {
private var warningShown = false private var warningShown = false
@ -22,7 +24,8 @@ fun createForegroundNotification(context: Context): Notification {
val notificationChannelId = "$appName.Listener" val notificationChannelId = "$appName.Listener"
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager; val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val channel = NotificationChannel( val channel = NotificationChannel(
notificationChannelId, notificationChannelId,
appName, appName,
@ -43,7 +46,8 @@ fun createForegroundNotification(context: Context): Notification {
notificationIntent, 0 notificationIntent, 0
) )
val builder: Notification.Builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) Notification.Builder( val builder: Notification.Builder =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) Notification.Builder(
context, context,
notificationChannelId notificationChannelId
) else Notification.Builder(context) ) else Notification.Builder(context)
@ -67,7 +71,7 @@ fun createWarningNotification(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationManager = val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager; context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val channel = NotificationChannel( val channel = NotificationChannel(
notificationChannelId, notificationChannelId,
appName, appName,
@ -103,13 +107,15 @@ fun createWarningNotification(context: Context) {
.setOngoing(true) .setOngoing(true)
with(NotificationManagerCompat.from(context)) { with(NotificationManagerCompat.from(context)) {
notify(NOTIF_ID_WARNING, builder.build()) notify(NOTIFICATION_ID_WARNING, builder.build())
} }
warningShown = true warningShown = true
} }
fun deleteWarningNotification(context: Context) { fun deleteWarningNotification(context: Context) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager; val notificationManager =
notificationManager.cancel(NOTIF_ID_WARNING) context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(NOTIFICATION_ID_WARNING)
warningShown = false warningShown = false
} }
}

View File

@ -11,9 +11,11 @@ import okhttp3.Response
import java.lang.Exception import java.lang.Exception
import com.google.gson.Gson import com.google.gson.Gson
import org.unifiedpush.distributor.nextpush.api.SSEResponse import org.unifiedpush.distributor.nextpush.api.SSEResponse
import org.unifiedpush.distributor.nextpush.distributor.getDb import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.getDb
import org.unifiedpush.distributor.nextpush.distributor.sendMessage import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.sendMessage
import org.unifiedpush.distributor.nextpush.distributor.sendUnregistered import org.unifiedpush.distributor.nextpush.distributor.DistributorUtils.sendUnregistered
import org.unifiedpush.distributor.nextpush.services.NotificationUtils.createWarningNotification
import org.unifiedpush.distributor.nextpush.services.NotificationUtils.deleteWarningNotification
private const val TAG = "SSEListener" private const val TAG = "SSEListener"

View File

@ -12,16 +12,17 @@ import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundExce
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException
import com.nextcloud.android.sso.helper.SingleAccountHelper import com.nextcloud.android.sso.helper.SingleAccountHelper
import org.unifiedpush.distributor.nextpush.account.ssoAccount import org.unifiedpush.distributor.nextpush.account.AccountUtils.ssoAccount
import org.unifiedpush.distributor.nextpush.account.nextcloudAppNotInstalledDialog import org.unifiedpush.distributor.nextpush.account.AccountUtils.nextcloudAppNotInstalledDialog
import android.net.Network import android.net.Network
import android.net.ConnectivityManager import android.net.ConnectivityManager
import android.net.ConnectivityManager.NetworkCallback import android.net.ConnectivityManager.NetworkCallback
import android.net.NetworkCapabilities import android.net.NetworkCapabilities
import org.unifiedpush.distributor.nextpush.api.apiDestroy import org.unifiedpush.distributor.nextpush.api.ApiUtils.apiDestroy
import org.unifiedpush.distributor.nextpush.api.apiSync import org.unifiedpush.distributor.nextpush.api.ApiUtils.apiSync
import org.unifiedpush.distributor.nextpush.services.NotificationUtils.createForegroundNotification
import java.lang.Exception import java.lang.Exception
private const val TAG = "StartService" private const val TAG = "StartService"
@ -54,7 +55,7 @@ class StartService: Service(){
super.onCreate() super.onCreate()
Log.i(TAG,"StartService created") Log.i(TAG,"StartService created")
val notification = createForegroundNotification(this) val notification = createForegroundNotification(this)
startForeground(NOTIF_ID_FOREGROUND, notification) startForeground(NOTIFICATION_ID_FOREGROUND, notification)
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@ -141,6 +142,5 @@ class StartService: Service(){
e.printStackTrace() e.printStackTrace()
} }
} }
} }