Merge "feat(HCT): Notification 'open settings' action behavoir" into main

This commit is contained in:
Jean Chen
2024-12-27 01:36:09 -08:00
committed by Android (Google) Code Review
2 changed files with 58 additions and 16 deletions

View File

@@ -54,6 +54,9 @@ public class HighContrastTextMigrationReceiver extends BroadcastReceiver {
static final String ACTION_RESTORED =
"com.android.settings.accessibility.ACTION_HIGH_CONTRAST_TEXT_RESTORED";
@VisibleForTesting
static final String ACTION_OPEN_SETTINGS =
"com.android.settings.accessibility.ACTION_OPEN_HIGH_CONTRAST_TEXT_SETTINGS";
@VisibleForTesting
static final int NOTIFICATION_ID = 1;
@Retention(RetentionPolicy.SOURCE)
@@ -74,7 +77,16 @@ public class HighContrastTextMigrationReceiver extends BroadcastReceiver {
return;
}
if (ACTION_RESTORED.equals(intent.getAction())) {
if (ACTION_OPEN_SETTINGS.equals(intent.getAction())) {
// Close notification drawer before opening the HCT setting.
context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
Intent settingsIntent = createHighContrastTextSettingsIntent(context);
settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(settingsIntent);
context.getSystemService(NotificationManager.class).cancel(NOTIFICATION_ID);
} else if (ACTION_RESTORED.equals(intent.getAction())) {
Log.i(TAG, "HCT attempted to be restored from backup; showing notification for userId: "
+ context.getUserId());
Settings.Secure.putInt(context.getContentResolver(),
@@ -125,21 +137,20 @@ public class HighContrastTextMigrationReceiver extends BroadcastReceiver {
R.string.accessibility_notification_high_contrast_text_content))
.setFlag(Notification.FLAG_NO_CLEAR, true);
Intent settingsIntent = new Intent(Settings.ACTION_TEXT_READING_SETTINGS);
settingsIntent.setPackage(context.getPackageName());
Intent settingsIntent = createHighContrastTextSettingsIntent(context);
if (settingsIntent.resolveActivity(context.getPackageManager()) != null) {
Bundle fragmentArgs = new Bundle();
fragmentArgs.putString(EXTRA_FRAGMENT_ARG_KEY,
TextReadingPreferenceFragment.HIGH_TEXT_CONTRAST_KEY);
settingsIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
PendingIntent settingsPendingIntent = PendingIntent.getActivity(context,
/* requestCode = */ 0, settingsIntent, PendingIntent.FLAG_IMMUTABLE);
Intent actionIntent = new Intent(context, HighContrastTextMigrationReceiver.class);
actionIntent.setAction(ACTION_OPEN_SETTINGS);
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0,
actionIntent, PendingIntent.FLAG_IMMUTABLE);
Notification.Action settingsAction = new Notification.Action.Builder(
/* icon= */ null,
context.getString(
R.string.accessibility_notification_high_contrast_text_action),
settingsPendingIntent
actionPendingIntent
).build();
notificationBuilder
@@ -156,4 +167,14 @@ public class HighContrastTextMigrationReceiver extends BroadcastReceiver {
notificationManager.createNotificationChannel(notificationChannel);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}
private Intent createHighContrastTextSettingsIntent(Context context) {
Intent settingsIntent = new Intent(Settings.ACTION_TEXT_READING_SETTINGS);
settingsIntent.setPackage(context.getPackageName());
Bundle fragmentArgs = new Bundle();
fragmentArgs.putString(EXTRA_FRAGMENT_ARG_KEY,
TextReadingPreferenceFragment.HIGH_TEXT_CONTRAST_KEY);
settingsIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
return settingsIntent;
}
}