Merge "Repost PageAgnostic mode notification when dismissed" into main
This commit is contained in:
@@ -28,17 +28,17 @@ public class Enable16KBootReceiver extends BroadcastReceiver {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
|
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (!Intent.ACTION_BOOT_COMPLETED.equals(action)) {
|
if (Intent.ACTION_BOOT_COMPLETED.equals(action)
|
||||||
return;
|
|| PageAgnosticNotificationService.INTENT_ACTION_DISMISSED.equals(action)) {
|
||||||
}
|
// Do nothing if device is not in page-agnostic mode
|
||||||
|
if (!Enable16kUtils.isPageAgnosticModeOn(context)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Do nothing if device is not in page-agnostic mode
|
// start a service to post persistent notification
|
||||||
if (!Enable16kUtils.isPageAgnosticModeOn(context)) {
|
Intent startServiceIntent = new Intent(context, PageAgnosticNotificationService.class);
|
||||||
return;
|
startServiceIntent.setAction(action);
|
||||||
|
context.startServiceAsUser(startServiceIntent, UserHandle.SYSTEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
// start a service to post persistent notification
|
|
||||||
Intent startNotificationIntent = new Intent(context, PageAgnosticNotificationService.class);
|
|
||||||
context.startServiceAsUser(startNotificationIntent, UserHandle.SYSTEM);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,8 @@ public class PageAgnosticNotificationService extends Service {
|
|||||||
|
|
||||||
private static final String NOTIFICATION_CHANNEL_ID =
|
private static final String NOTIFICATION_CHANNEL_ID =
|
||||||
"com.android.settings.development.PageAgnosticNotificationService";
|
"com.android.settings.development.PageAgnosticNotificationService";
|
||||||
|
public static final String INTENT_ACTION_DISMISSED =
|
||||||
|
"com.android.settings.development.NOTIFICATION_DISMISSED";
|
||||||
private static final int NOTIFICATION_ID = 1;
|
private static final int NOTIFICATION_ID = 1;
|
||||||
|
|
||||||
static final int DISABLE_UPDATES_SETTING = 1;
|
static final int DISABLE_UPDATES_SETTING = 1;
|
||||||
@@ -63,6 +65,9 @@ public class PageAgnosticNotificationService extends Service {
|
|||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
createNotificationChannel();
|
createNotificationChannel();
|
||||||
|
|
||||||
|
// No updates should be allowed in page-agnostic mode
|
||||||
|
disableAutomaticUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Notification buildNotification() {
|
private Notification buildNotification() {
|
||||||
@@ -89,6 +94,15 @@ public class PageAgnosticNotificationService extends Service {
|
|||||||
notifyIntent,
|
notifyIntent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
|
||||||
|
Intent dismissIntent = new Intent(this, Enable16KBootReceiver.class);
|
||||||
|
dismissIntent.setAction(INTENT_ACTION_DISMISSED);
|
||||||
|
PendingIntent dismissPendingIntent =
|
||||||
|
PendingIntent.getBroadcast(
|
||||||
|
this.getApplicationContext(),
|
||||||
|
0,
|
||||||
|
dismissIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
|
||||||
Notification.Action action =
|
Notification.Action action =
|
||||||
new Notification.Action.Builder(
|
new Notification.Action.Builder(
|
||||||
R.drawable.empty_icon,
|
R.drawable.empty_icon,
|
||||||
@@ -104,6 +118,7 @@ public class PageAgnosticNotificationService extends Service {
|
|||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setSmallIcon(R.drawable.ic_settings_24dp)
|
.setSmallIcon(R.drawable.ic_settings_24dp)
|
||||||
.setContentIntent(notifyPendingIntent)
|
.setContentIntent(notifyPendingIntent)
|
||||||
|
.setDeleteIntent(dismissPendingIntent)
|
||||||
.addAction(action);
|
.addAction(action);
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
@@ -131,9 +146,6 @@ public class PageAgnosticNotificationService extends Service {
|
|||||||
if (mNotificationManager != null) {
|
if (mNotificationManager != null) {
|
||||||
mNotificationManager.notify(NOTIFICATION_ID, notification);
|
mNotificationManager.notify(NOTIFICATION_ID, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No updates should be allowed in page-agnostic mode
|
|
||||||
disableAutomaticUpdates();
|
|
||||||
return Service.START_REDELIVER_INTENT;
|
return Service.START_REDELIVER_INTENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user