TrustInterfaceService: Extend onboarding notification to ATV

Change-Id: I0db5c9327af5305f6dc573b06f519958bb23e4ec
This commit is contained in:
Bruno Martins
2022-03-31 22:46:51 +01:00
parent ff5e7166f0
commit 229282cd3e

View File

@@ -25,6 +25,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.SELinux;
@@ -59,7 +60,9 @@ public class TrustInterfaceService extends LineageSystemService {
private static final String INTENT_PARTS = "org.lineageos.lineageparts.TRUST_INTERFACE";
private static final String INTENT_ONBOARDING = "org.lineageos.lineageparts.TRUST_HINT";
private static final String CHANNEL_NAME = "TrustInterface";
private static final String TRUST_CHANNEL_ID = "TrustInterface";
private static final String TRUST_CHANNEL_ID_TV = "TrustInterface.tv";
private static final int ONBOARDING_NOTIFCATION_ID = 89;
private Context mContext;
@@ -143,7 +146,7 @@ public class TrustInterfaceService extends LineageSystemService {
PendingIntent pActionIntent = PendingIntent.getActivity(mContext, 0, actionIntent,
PendingIntent.FLAG_IMMUTABLE);
Notification.Builder notification = new Notification.Builder(mContext, CHANNEL_NAME)
Notification.Builder notification = new Notification.Builder(mContext, TRUST_CHANNEL_ID)
.setContentTitle(title)
.setContentText(message)
.setStyle(new Notification.BigTextStyle().bigText(message))
@@ -151,7 +154,8 @@ public class TrustInterfaceService extends LineageSystemService {
.setContentIntent(pMainIntent)
.addAction(R.drawable.ic_trust_notification_manage, action, pActionIntent)
.setColor(mContext.getColor(R.color.color_error))
.setSmallIcon(R.drawable.ic_warning);
.setSmallIcon(R.drawable.ic_warning)
.extend(new Notification.TvExtender().setChannelId(TRUST_CHANNEL_ID_TV));
createNotificationChannelIfNeeded();
mNotificationManager.notify(feature, notification.build());
@@ -179,13 +183,14 @@ public class TrustInterfaceService extends LineageSystemService {
PendingIntent pIntent = PendingIntent.getActivity(mContext, 0, intent,
PendingIntent.FLAG_IMMUTABLE);
Notification.Builder notification = new Notification.Builder(mContext, CHANNEL_NAME)
Notification.Builder notification = new Notification.Builder(mContext, TRUST_CHANNEL_ID)
.setContentTitle(title)
.setContentText(message)
.setStyle(new Notification.BigTextStyle().bigText(message))
.setAutoCancel(true)
.setContentIntent(pIntent)
.setSmallIcon(R.drawable.ic_trust);
.setSmallIcon(R.drawable.ic_trust)
.extend(new Notification.TvExtender().setChannelId(TRUST_CHANNEL_ID_TV));
createNotificationChannelIfNeeded();
mNotificationManager.notify(ONBOARDING_NOTIFCATION_ID, notification.build());
@@ -228,6 +233,10 @@ public class TrustInterfaceService extends LineageSystemService {
"You do not have permissions to use the Trust interface");
}
private boolean isTv() {
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
}
private boolean isWarningAllowed(int warning) {
return (LineageSettings.Secure.getInt(mContext.getContentResolver(),
LineageSettings.Secure.TRUST_WARNINGS,
@@ -253,15 +262,15 @@ public class TrustInterfaceService extends LineageSystemService {
}
private void createNotificationChannelIfNeeded() {
NotificationChannel channel = mNotificationManager.getNotificationChannel(CHANNEL_NAME);
String id = !isTv() ? TRUST_CHANNEL_ID : TRUST_CHANNEL_ID_TV;
NotificationChannel channel = mNotificationManager.getNotificationChannel(id);
if (channel != null) {
return;
}
String name = mContext.getString(R.string.trust_notification_channel);
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel trustChannel = new NotificationChannel(CHANNEL_NAME,
name, importance);
NotificationChannel trustChannel = new NotificationChannel(id, name, importance);
trustChannel.setBlockable(true);
mNotificationManager.createNotificationChannel(trustChannel);
}