2019-06-12 01:49:26 +02:00
|
|
|
package com.beemdevelopment.aegis.services;
|
|
|
|
|
2022-02-02 21:01:15 +01:00
|
|
|
import android.annotation.SuppressLint;
|
2019-06-12 01:49:26 +02:00
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.app.Service;
|
|
|
|
import android.content.Intent;
|
2022-02-02 21:01:15 +01:00
|
|
|
import android.os.Build;
|
2019-06-12 01:49:26 +02:00
|
|
|
import android.os.IBinder;
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.core.app.NotificationManagerCompat;
|
|
|
|
|
|
|
|
import com.beemdevelopment.aegis.R;
|
|
|
|
|
|
|
|
public class NotificationService extends Service {
|
2019-12-25 19:21:34 +01:00
|
|
|
public static final int VAULT_UNLOCKED_ID = 1;
|
2019-06-12 01:49:26 +02:00
|
|
|
|
|
|
|
private static final String CODE_LOCK_STATUS_ID = "lock_status_channel";
|
2019-12-25 19:21:34 +01:00
|
|
|
private static final String CODE_LOCK_VAULT_ACTION = "lock_vault";
|
2019-06-12 01:49:26 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int onStartCommand(Intent intent,int flags, int startId){
|
|
|
|
super.onStartCommand(intent, flags, startId);
|
|
|
|
serviceMethod();
|
|
|
|
return Service.START_STICKY;
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:01:15 +01:00
|
|
|
@SuppressLint("LaunchActivityFromNotification")
|
2019-06-12 01:49:26 +02:00
|
|
|
public void serviceMethod() {
|
2022-02-02 21:01:15 +01:00
|
|
|
int flags = 0;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
flags |= PendingIntent.FLAG_IMMUTABLE;
|
|
|
|
}
|
2019-12-25 19:21:34 +01:00
|
|
|
Intent intentAction = new Intent(CODE_LOCK_VAULT_ACTION);
|
2022-02-02 21:01:15 +01:00
|
|
|
PendingIntent lockDatabaseIntent = PendingIntent.getBroadcast(this, 1, intentAction, flags);
|
2020-01-02 13:03:45 +01:00
|
|
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CODE_LOCK_STATUS_ID)
|
2019-06-12 01:49:26 +02:00
|
|
|
.setSmallIcon(R.drawable.ic_fingerprint_black_24dp)
|
|
|
|
.setContentTitle(getString(R.string.app_name_full))
|
|
|
|
.setContentText(getString(R.string.vault_unlocked_state))
|
|
|
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
|
|
|
.setOngoing(true)
|
|
|
|
.setContentIntent(lockDatabaseIntent);
|
|
|
|
|
|
|
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
2019-12-25 19:21:34 +01:00
|
|
|
notificationManager.notify(VAULT_UNLOCKED_ID, builder.build());
|
2019-06-12 01:49:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
2019-12-25 19:21:34 +01:00
|
|
|
notificationManager.cancel(VAULT_UNLOCKED_ID);
|
2020-01-02 13:03:45 +01:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTaskRemoved(Intent rootIntent) {
|
|
|
|
super.onTaskRemoved(rootIntent);
|
|
|
|
stopSelf();
|
2019-06-12 01:49:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public IBinder onBind(Intent intent) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|