// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/ash/settings/pages/apps/apps_section.h"

#include <array>

#include "ash/constants/ash_features.h"
#include "ash/constants/chrome_webui_url_constants.h"
#include "ash/constants/url_constants.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/ash/arc/arc_util.h"
#include "chrome/browser/ash/child_accounts/on_device_controls/app_controls_service_factory.h"
#include "chrome/browser/ui/webui/ash/settings/pages/apps/android_apps_handler.h"
#include "chrome/browser/ui/webui/ash/settings/pages/crostini/guest_os_handler.h"
#include "chrome/browser/ui/webui/ash/settings/pages/system_preferences/startup_section.h"
#include "chrome/browser/ui/webui/ash/settings/search/search_tag_registry.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_features.h"
#include "chrome/browser/web_applications/link_capturing_features.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/os_settings_resources.h"
#include "chromeos/ash/experiences/arc/app/arc_app_constants.h"
#include "chromeos/ash/experiences/arc/arc_prefs.h"
#include "chromeos/ash/experiences/arc/arc_util.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/isolated_web_apps_policy.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/common/content_features.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/chromeos/devicetype_utils.h"
#include "ui/webui/webui_util.h"

namespace ash::settings {

namespace mojom {
using ::chromeos::settings::mojom::kAppDetailsSubpagePath;
using ::chromeos::settings::mojom::kAppManagementSubpagePath;
using ::chromeos::settings::mojom::kAppNotificationsManagerSubpagePath;
using ::chromeos::settings::mojom::kAppNotificationsSubpagePath;
using ::chromeos::settings::mojom::kAppParentalControlsSubpagePath;
using ::chromeos::settings::mojom::kAppsSectionPath;
using ::chromeos::settings::mojom::kArcVmUsbPreferencesSubpagePath;
using ::chromeos::settings::mojom::kGooglePlayStoreSubpagePath;
using ::chromeos::settings::mojom::Section;
using ::chromeos::settings::mojom::Setting;
using ::chromeos::settings::mojom::Subpage;
}  // namespace mojom

namespace {

base::span<const SearchConcept> GetAppsSearchConcepts() {
  static constexpr auto tags = std::to_array<SearchConcept>({
      {IDS_OS_SETTINGS_TAG_APPS,
       mojom::kAppsSectionPath,
       mojom::SearchResultIcon::kAppsGrid,
       mojom::SearchResultDefaultRank::kMedium,
       mojom::SearchResultType::kSection,
       {.section = mojom::Section::kApps}},
      {IDS_OS_SETTINGS_TAG_APPS_MANAGEMENT,
       mojom::kAppManagementSubpagePath,
       mojom::SearchResultIcon::kAppsGrid,
       mojom::SearchResultDefaultRank::kMedium,
       mojom::SearchResultType::kSubpage,
       {.subpage = mojom::Subpage::kAppManagement},
       {IDS_OS_SETTINGS_TAG_APPS_MANAGEMENT_ALT1, SearchConcept::kAltTagEnd}},
  });
  return tags;
}

base::span<const SearchConcept> GetAppNotificationsSearchConcepts() {
  static constexpr auto tags = std::to_array<SearchConcept>({
      {IDS_OS_SETTINGS_TAG_APP_NOTIFICATIONS,
       mojom::kAppNotificationsSubpagePath,
       mojom::SearchResultIcon::kNotifications,
       mojom::SearchResultDefaultRank::kMedium,
       mojom::SearchResultType::kSubpage,
       {.subpage = mojom::Subpage::kAppNotifications}},
  });
  return tags;
}

base::span<const SearchConcept> GetAppNotificationsManagerSearchConcepts() {
  static constexpr auto tags = std::to_array<SearchConcept>({
      {IDS_OS_SETTINGS_TAG_APP_NOTIFICATIONS_MANAGER,
       mojom::kAppNotificationsManagerSubpagePath,
       mojom::SearchResultIcon::kNotifications,
       mojom::SearchResultDefaultRank::kMedium,
       mojom::SearchResultType::kSubpage,
       {.subpage = mojom::Subpage::kAppNotificationsManager}},
  });
  return tags;
}

base::span<const SearchConcept> GetAppBadgingSearchConcepts() {
  static constexpr auto tags = std::to_array<SearchConcept>(
      {{IDS_OS_SETTINGS_TAG_APP_BADGING,
        mojom::kAppNotificationsSubpagePath,
        mojom::SearchResultIcon::kNotifications,
        mojom::SearchResultDefaultRank::kMedium,
        mojom::SearchResultType::kSetting,
        {.setting = mojom::Setting::kAppBadgingOnOff}}});
  return tags;
}

base::span<const SearchConcept> GetTurnOffAppNotificationSearchConcepts() {
  static constexpr auto tags = std::to_array<SearchConcept>(
      {{IDS_OS_SETTINGS_TAG_DO_NOT_DISTURB_TURN_OFF,
        mojom::kAppNotificationsSubpagePath,
        mojom::SearchResultIcon::kNotifications,
        mojom::SearchResultDefaultRank::kMedium,
        mojom::SearchResultType::kSetting,
        {.setting = mojom::Setting::kDoNotDisturbOnOff},
        {IDS_OS_SETTINGS_TAG_DO_NOT_DISTURB_TURN_OFF_ALT1,
         SearchConcept::kAltTagEnd}}});
  return tags;
}

base::span<const SearchConcept> GetTurnOnAppNotificationSearchConcepts() {
  static constexpr auto tags = std::to_array<SearchConcept>(
      {{IDS_OS_SETTINGS_TAG_DO_NOT_DISTURB_TURN_ON,
        mojom::kAppNotificationsSubpagePath,
        mojom::SearchResultIcon::kNotifications,
        mojom::SearchResultDefaultRank::kMedium,
        mojom::SearchResultType::kSetting,
        {.setting = mojom::Setting::kDoNotDisturbOnOff},
        {IDS_OS_SETTINGS_TAG_DO_NOT_DISTURB_TURN_ON_ALT1,
         SearchConcept::kAltTagEnd}}});
  return tags;
}

base::span<const SearchConcept> GetAndroidPlayStoreSearchConcepts() {
  static constexpr auto tags = std::to_array<SearchConcept>({
      {IDS_OS_SETTINGS_TAG_PLAY_STORE,
       mojom::kGooglePlayStoreSubpagePath,
       mojom::SearchResultIcon::kGooglePlay,
       mojom::SearchResultDefaultRank::kMedium,
       mojom::SearchResultType::kSubpage,
       {.subpage = mojom::Subpage::kGooglePlayStore}},
      {IDS_OS_SETTINGS_TAG_REMOVE_PLAY_STORE,
       mojom::kGooglePlayStoreSubpagePath,
       mojom::SearchResultIcon::kGooglePlay,
       mojom::SearchResultDefaultRank::kMedium,
       mojom::SearchResultType::kSetting,
       {.setting = mojom::Setting::kRemovePlayStore},
       {IDS_OS_SETTINGS_TAG_REMOVE_PLAY_STORE_ALT1, SearchConcept::kAltTagEnd}},
  });
  return tags;
}

base::span<const SearchConcept> GetAndroidSettingsSearchConcepts() {
  static constexpr auto tags = std::to_array<SearchConcept>({
      {IDS_OS_SETTINGS_TAG_ANDROID_SETTINGS_WITH_PLAY_STORE,
       mojom::kGooglePlayStoreSubpagePath,
       mojom::SearchResultIcon::kGooglePlay,
       mojom::SearchResultDefaultRank::kMedium,
       mojom::SearchResultType::kSetting,
       {.setting = mojom::Setting::kManageAndroidPreferences},
       {IDS_OS_SETTINGS_TAG_ANDROID_SETTINGS_WITH_PLAY_STORE_ALT1,
        SearchConcept::kAltTagEnd}},
  });
  return tags;
}

base::span<const SearchConcept> GetAndroidNoPlayStoreSearchConcepts() {
  static constexpr auto tags = std::to_array<SearchConcept>({
      {IDS_OS_SETTINGS_TAG_ANDROID_SETTINGS,
       mojom::kAppsSectionPath,
       mojom::SearchResultIcon::kAndroid,
       mojom::SearchResultDefaultRank::kMedium,
       mojom::SearchResultType::kSetting,
       {.setting = mojom::Setting::kManageAndroidPreferences},
       {IDS_OS_SETTINGS_TAG_ANDROID_SETTINGS_ALT1, SearchConcept::kAltTagEnd}},
  });
  return tags;
}

base::span<const SearchConcept> GetAndroidPlayStoreDisabledSearchConcepts() {
  static constexpr auto tags = std::to_array<SearchConcept>({
      {IDS_OS_SETTINGS_TAG_ANDROID_TURN_ON_PLAY_STORE,
       mojom::kAppsSectionPath,
       mojom::SearchResultIcon::kAndroid,
       mojom::SearchResultDefaultRank::kMedium,
       mojom::SearchResultType::kSetting,
       {.setting = mojom::Setting::kTurnOnPlayStore},
       {IDS_OS_SETTINGS_TAG_ANDROID_TURN_ON_PLAY_STORE_ALT1,
        SearchConcept::kAltTagEnd}},
  });
  return tags;
}


base::span<const SearchConcept> GetParentalControlsSearchConcepts() {
  // Redirect search queries to the parental controls row in the Apps section
  // because the app parental controls page should only be accessed after the
  // user has entered their PIN, which is triggered from the settings row.
  static constexpr auto tags = std::to_array<SearchConcept>(
      {{IDS_OS_SETTINGS_TAG_APPS_PARENTAL_CONTROLS,
        mojom::kAppsSectionPath,
        mojom::SearchResultIcon::kAppsParentalControls,
        mojom::SearchResultDefaultRank::kMedium,
        mojom::SearchResultType::kSetting,
        {.setting = mojom::Setting::kAppParentalControls},
        {IDS_OS_SETTINGS_TAG_APPS_PARENTAL_CONTROLS_ALT1,
         SearchConcept::kAltTagEnd}}});
  return tags;
}

base::span<const SearchConcept> GetTurnOnIsolatedWebAppsSearchConcepts() {
  static constexpr auto tags = std::to_array<SearchConcept>(
      {{IDS_OS_SETTINGS_TAG_TURN_ON_ISOLATED_WEB_APPS,
        mojom::kAppsSectionPath,
        mojom::SearchResultIcon::kNotifications,
        mojom::SearchResultDefaultRank::kMedium,
        mojom::SearchResultType::kSetting,
        {.setting = mojom::Setting::kEnableIsolatedWebAppsOnOff},
        {IDS_OS_SETTINGS_TAG_TURN_ON_ISOLATED_WEB_APPS_ALT1,
         SearchConcept::kAltTagEnd}}});
  return tags;
}

void AddAppManagementStrings(content::WebUIDataSource* html_source) {
  webui::LocalizedString kLocalizedStrings[] = {
      {"appManagementAppDetailsTitle", IDS_APP_MANAGEMENT_APP_DETAILS_TITLE},
      {"appManagementAppDetailsTooltipWebA11y",
       IDS_APP_MANAGEMENT_APP_DETAILS_TOOLTIP_WEB_A11Y},
      {"appManagementAppDetailsTypeAndroid",
       IDS_OS_SETTINGS_APP_DETAILS_TYPE_ANDROID},
      {"appManagementAppDetailsTypeChrome",
       IDS_OS_SETTINGS_APP_DETAILS_TYPE_CHROME},
      {"appManagementAppDetailsTypeWeb", IDS_OS_SETTINGS_APP_DETAILS_TYPE_WEB},
      {"appManagementAppDetailsTypeCrosSystem",
       IDS_OS_SETTINGS_APP_DETAILS_TYPE_CROS_SYSTEM},
      {"appManagementAppDetailsInstallSourceWebStore",
       IDS_APP_MANAGEMENT_APP_DETAILS_INSTALL_SOURCE_WEB_STORE},
      {"appManagementAppDetailsInstallSourcePlayStore",
       IDS_APP_MANAGEMENT_APP_DETAILS_INSTALL_SOURCE_PLAY_STORE},
      {"appManagementAppDetailsInstallSourceBrowser",
       IDS_APP_MANAGEMENT_APP_DETAILS_INSTALL_SOURCE_BROWSER},
      {"appManagementAppDetailsSubappDataSharingExplanation",
       IDS_APP_MANAGEMENT_APP_DETAILS_SUBAPP_DATA_SHARING_EXPLANATION},
      {"appManagementAppDetailsTypeAndSourcePreinstalledApp",
       IDS_APP_MANAGEMENT_APP_DETAILS_TYPE_AND_SOURCE_PREINSTALLED_APP},
      {"appManagementAppDetailsTypeAndSourceCombined",
       IDS_APP_MANAGEMENT_APP_DETAILS_TYPE_AND_SOURCE_COMBINED},
      {"appManagementAppDetailsTypeAndroidInstallReasonPolicy",
       IDS_OS_SETTINGS_APP_DETAILS_TYPE_ANDROID_INSTALL_REASON_POLICY},
      {"appManagementAppDetailsTypeChromeInstallReasonPolicy",
       IDS_OS_SETTINGS_APP_DETAILS_TYPE_CHROME_INSTALL_REASON_POLICY},
      {"appManagementAppDetailsTypeWebInstallReasonPolicy",
       IDS_OS_SETTINGS_APP_DETAILS_TYPE_WEB_INSTALL_REASON_POLICY},
      {"appManagementAppDetailsVersion",
       IDS_APP_MANAGEMENT_APP_DETAILS_VERSION},
      {"appManagementAppDetailsStorageTitle",
       IDS_APP_MANAGEMENT_APP_DETAILS_STORAGE_TITLE},
      {"appManagementAppDetailsAppSize",
       IDS_APP_MANAGEMENT_APP_DETAILS_APP_SIZE},
      {"appManagementAppDetailsDataSize",
       IDS_APP_MANAGEMENT_APP_DETAILS_DATA_SIZE},
      {"appManagementAppInstalledByPolicyLabel",
       IDS_APP_MANAGEMENT_POLICY_APP_POLICY_STRING},
      {"appManagementArcManagePermissionsLabel",
       IDS_APP_MANAGEMENT_ARC_MANAGE_PERMISSIONS},
      {"appManagementCameraPermissionLabel", IDS_APP_MANAGEMENT_CAMERA},
      {"appManagementContactsPermissionLabel", IDS_APP_MANAGEMENT_CONTACTS},
      {"appManagementFileHandlingHeader",
       IDS_APP_MANAGEMENT_FILE_HANDLING_HEADER},
      {"appManagementIntentOverlapChangeButton",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_CHANGE_BUTTON},
      {"appManagementIntentOverlapDialogText1App",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_DIALOG_TEXT_1_APP},
      {"appManagementIntentOverlapDialogText2Apps",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_DIALOG_TEXT_2_APPS},
      {"appManagementIntentOverlapDialogText3Apps",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_DIALOG_TEXT_3_APPS},
      {"appManagementIntentOverlapDialogText4Apps",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_DIALOG_TEXT_4_APPS},
      {"appManagementIntentOverlapDialogText5OrMoreApps",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_DIALOG_TEXT_5_OR_MORE_APPS},
      {"appManagementIntentOverlapDialogTitle",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_DIALOG_TITLE},
      {"appManagementIntentOverlapWarningText1App",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_WARNING_TEXT_1_APP},
      {"appManagementIntentOverlapWarningText2Apps",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_WARNING_TEXT_2_APPS},
      {"appManagementIntentOverlapWarningText3Apps",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_WARNING_TEXT_3_APPS},
      {"appManagementIntentOverlapWarningText4Apps",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_WARNING_TEXT_4_APPS},
      {"appManagementIntentOverlapWarningText5OrMoreApps",
       IDS_APP_MANAGEMENT_INTENT_OVERLAP_WARNING_TEXT_5_OR_MORE_APPS},
      {"appManagementIntentSettingsDialogTitle",
       IDS_APP_MANAGEMENT_INTENT_SETTINGS_DIALOG_TITLE},
      {"appManagementIntentSettingsTitle",
       IDS_APP_MANAGEMENT_INTENT_SETTINGS_TITLE},
      {"appManagementIntentSharingOpenAppLabel",
       IDS_OS_SETTINGS_OPEN_IN_APP_TITLE},
      {"appManagementPermissionItemClickTogglePermission",
       IDS_OS_SETTINGS_PERMISSION_ITEM_CLICK_TOGGLE_PERMISSION},
      {"appManagementIntentSharingOpenBrowserLabel",
       IDS_APP_MANAGEMENT_INTENT_SHARING_BROWSER_OPEN},
      {"appManagementIntentSharingOpenExistingTabLabel",
       IDS_APP_MANAGEMENT_INTENT_SHARING_APP_OPEN_EXISTING_TAB},
      {"appManagementIntentSharingOpenNewTabLabel",
       IDS_APP_MANAGEMENT_INTENT_SHARING_BROWSER_OPEN_NEW_TAB},
      {"appManagementIntentSharingTabExplanation",
       IDS_APP_MANAGEMENT_INTENT_SHARING_TAB_EXPLANATION},
      {"appManagementLocationPermissionLabel", IDS_APP_MANAGEMENT_LOCATION},
      {"appManagementMicrophonePermissionLabel", IDS_APP_MANAGEMENT_MICROPHONE},
      {"appManagementMorePermissionsLabel", IDS_APP_MANAGEMENT_MORE_SETTINGS},
      {"appManagementMorePermissionsLabelAndroidApp",
       IDS_OS_SETTINGS_APP_PERMISSIONS_TITLE_ANDROID},
      {"appManagementMorePermissionsLabelWebApp",
       IDS_OS_SETTINGS_APP_PERMISSIONS_TITLE_WEB_APP},
      {"appManagementMorePermissionsLabelChromeApp",
       IDS_OS_SETTINGS_APP_PERMISSIONS_TITLE_CHROME_APP},
      {"appManagementNoAppsFound", IDS_APP_MANAGEMENT_NO_APPS_FOUND},
      {"appManagementNoPermissions",
       IDS_APPLICATION_INFO_APP_NO_PERMISSIONS_TEXT},
      {"appManagementNotificationsLabel",
       IDS_OS_SETTINGS_APP_NOTIFICATIONS_TITLE},
      {"appManagementParentAppPermissionExplanation",
       IDS_APP_MANAGEMENT_PARENT_APP_PERMISSION_EXPLANATION},
      {"appManagementPermissionAllowed", IDS_APP_MANAGEMENT_PERMISSION_ALLOWED},
      {"appManagementPermissionAllowedWithDetails",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_WITH_DETAILS},
      {"appManagementPermissionAsk", IDS_APP_MANAGEMENT_PERMISSION_ASK},
      {"appManagementPermissionDenied", IDS_APP_MANAGEMENT_PERMISSION_DENIED},
      {"appManagementPermissionsLabel", IDS_APP_MANAGEMENT_PERMISSIONS},
      {"appManagementPinToShelfLabel", IDS_APP_MANAGEMENT_PIN_TO_SHELF},
      {"appManagementPresetWindowSizesLabel",
       IDS_APP_MANAGEMENT_PRESET_WINDOW_SIZES},
      {"appManagementPresetWindowSizesText",
       IDS_APP_MANAGEMENT_PRESET_WINDOW_SIZES_TEXT},
      {"appManagementPrintingPermissionLabel", IDS_APP_MANAGEMENT_PRINTING},
      {"appManagementSearchPrompt", IDS_APP_MANAGEMENT_SEARCH_PROMPT},
      {"appManagementStoragePermissionLabel", IDS_APP_MANAGEMENT_STORAGE},
      {"appManagementSubAppsListHeading",
       IDS_APP_MANAGEMENT_SUB_APPS_LIST_HEADING},
      {"appManagementSubAppPermissionExplanation",
       IDS_APP_MANAGEMENT_SUB_APP_PERMISSION_EXPLANATION},
      {"appManagementUninstallLabel", IDS_APP_MANAGEMENT_UNINSTALL_APP},
      {"close", IDS_CLOSE},
      {"fileHandlingOverflowDialogTitle",
       IDS_APP_MANAGEMENT_FILE_HANDLING_OVERFLOW_DIALOG_TITLE},
      {"fileHandlingSetDefaults",
       IDS_APP_MANAGEMENT_FILE_HANDLING_SET_DEFAULTS_LINK},
      {"appManagementCheckForUpdates",
       IDS_SETTINGS_ABOUT_PAGE_CHECK_FOR_UPDATES},
      {"appManagementCheckingForUpdates", IDS_APP_MANAGEMENT_CHECKING},
      {"appManagementApplyUpdate", IDS_APP_MANAGEMENT_APPLY_UPDATE},
      {"appManagementAppIsUpToDate", IDS_APP_MANAGEMENT_APP_IS_UP_TO_DATE},
      {"appManagementUpdateFoundDialogTitle",
       IDS_APP_MANAGEMENT_UPDATE_FOUND_DIALOG_TITLE},
      {"appManagementUpdateFoundDialogDescription",
       IDS_APP_MANAGEMENT_UPDATE_FOUND_DIALOG_DESCRIPTION},
      {"appManagementUpdateFoundWarningDialogDescription",
       IDS_APP_MANAGEMENT_UPDATE_FOUND_WARNING_DIALOG_DESCRIPTION},
  };
  html_source->AddLocalizedStrings(kLocalizedStrings);
}

void AddGuestOsStrings(content::WebUIDataSource* html_source) {
  // These strings are shared by the supported guest environments.
  static constexpr webui::LocalizedString kLocalizedStrings[] = {
      {"guestOsSharedPaths", IDS_SETTINGS_GUEST_OS_SHARED_PATHS},
      {"guestOsSharedPathsListHeading",
       IDS_SETTINGS_GUEST_OS_SHARED_PATHS_LIST_HEADING},
      {"guestOsSharedPathsInstructionsRemove",
       IDS_SETTINGS_GUEST_OS_SHARED_PATHS_INSTRUCTIONS_REMOVE},
      {"guestOsSharedPathsStopSharing",
       IDS_SETTINGS_GUEST_OS_SHARED_PATHS_STOP_SHARING},
      {"guestOsSharedPathsRemoveFailureDialogTitle",
       IDS_SETTINGS_GUEST_OS_SHARED_PATHS_REMOVE_FAILURE_DIALOG_TITLE},
      {"guestOsSharedPathsRemoveFailureTryAgain",
       IDS_SETTINGS_GUEST_OS_SHARED_PATHS_REMOVE_FAILURE_TRY_AGAIN},
      {"guestOsSharedPathsListEmptyMessage",
       IDS_SETTINGS_GUEST_OS_SHARED_PATHS_LIST_EMPTY_MESSAGE},
      {"guestOsSharedUsbDevicesLabel",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_LABEL},
      {"guestOsSharedUsbDevicesDescription",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_DESCRIPTION},
      {"guestOsSharedUsbDevicesExtraDescription",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_EXTRA_DESCRIPTION},
      {"guestOsSharedUsbDevicesListEmptyMessage",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_LIST_EMPTY_MESSAGE},
      {"guestOsSharedUsbDevicesInUse",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_IN_USE},
      {"guestOsSharedUsbDevicesReassign",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_REASSIGN},
      {"guestOsSharedUsbDevicesTableTitle",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_TABLE_TITLE},
      {"guestOsSharedUsbDevicesAddTitle",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_ADD_TITLE},
      {"guestOsSharedUsbDevicesNoneAttached",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_NONE_ATTACHED},
      {"guestOsSharedUsbDevicesNotificationDialogTitleEnable",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_NOTIFICATION_DIALOG_TITLE_ENABLE},
      {"guestOsSharedUsbDevicesNotificationDialogTitleDisable",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_NOTIFICATION_DIALOG_TITLE_DISABLE},
      {"guestOsSharedUsbDevicesNotificationDialogAccept",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_NOTIFICATION_DIALOG_ACCEPT},
      {"guestOsSharedUsbDevicesNotificationsLabel",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_NOTIFICATION_LABEL},
      {"guestOsSharedUsbPersistentPassthroughLabel",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_PERSISTENT_PASSTHROUGH_LABEL},
      {"guestOsSharedUsbPersistentPassthroughDialogTitleEnable",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_PERSISTENT_PASSTHROUGH_DIALOG_TITLE_ENABLE},
      {"guestOsSharedUsbPersistentPassthroughDialogTitleDisable",
       IDS_SETTINGS_GUEST_OS_SHARED_USB_PERSISTENT_PASSTHROUGH_DIALOG_TITLE_DISABLE},
  };
  html_source->AddLocalizedStrings(kLocalizedStrings);
}

void AddBorealisStrings(content::WebUIDataSource* html_source) {
  static constexpr webui::LocalizedString kLocalizedStrings[] = {
      {"borealisMainPermissionText",
       IDS_SETTINGS_APPS_BOREALIS_MAIN_PERMISSION_TEXT},
      {"borealisAppPermissionText",
       IDS_SETTINGS_APPS_BOREALIS_APP_PERMISSION_TEXT},
  };
  html_source->AddLocalizedStrings(kLocalizedStrings);
}

void AddAppParentalControlsStrings(content::WebUIDataSource* html_source) {
  static constexpr webui::LocalizedString kLocalizedStrings[] = {
      {"appParentalControlsAccessDialogTitle",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_ACCESS_DIALOG_TITLE},
      {"appParentalControlsBlockedAppsCountText",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_BLOCKED_APPS_COUNT_TEXT},
      {"appParentalControlsChoosePinSubtitle",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_CHOOSE_PIN_SUBTITLE},
      {"appParentalControlsChoosePinTitle",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_CHOOSE_PIN_TITLE},
      {"appParentalControlsConfirmPinTitle",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_CONFIRM_PIN_TITLE},
      {"appParentalControlsForgotPinLinkName",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_FORGOT_PIN_LINK_NAME},
      {"appParentalControlsHeaderText",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_APPS_TITLE_TEXT},
      {"appParentalControlsNoAppsText",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_NO_APPS_FOUND_TEXT},
      {"appParentalControlsPinIncorrectErrorText",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_PIN_INCORRECT_ERROR_TEXT},
      {"appParentalControlsPinMismatchErrorText",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_PIN_MISMATCH_ERROR_TEXT},
      {"appParentalControlsSearchPrompt",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_SEARCH_PROMPT},
      {"appParentalControlsTitle", IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_LABEL},
      {"appParentalControlsPinWrongLengthErrorText",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_PIN_WRONG_LENGTH_ERROR_TEXT},
      {"appParentalControlsPinNumericErrorText",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_PIN_NUMERIC_ERROR_TEXT},
      {"appParentalControlsTitle", IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_LABEL},
      {"appParentalControlsSetUpButton",
       IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_SET_UP_BUTTON},
      {"appParentalControlsTitle", IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_LABEL},
  };

  html_source->AddLocalizedStrings(kLocalizedStrings);

  html_source->AddString("appParentalControlsLearnMoreUrl",
                         ash::external_urls::kAppParentalControlsLearnMoreUrl);

  html_source->AddString(
      "appParentalControlsSubtitle",
      l10n_util::GetStringFUTF16(
          IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_SUBLABEL,
          ui::GetChromeOSDeviceName(),
          ash::external_urls::kAppParentalControlsLearnMoreUrl));
  html_source->AddString(
      "appParentalControlsSubtitleDescription",
      l10n_util::GetStringFUTF16(
          IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_SUBLABEL_DESCRIPTION,
          ui::GetChromeOSDeviceName()));
}

}  // namespace

AppsSection::AppsSection(Profile* profile,
                         SearchTagRegistry* search_tag_registry,
                         PrefService* pref_service,
                         ArcAppListPrefs* arc_app_list_prefs,
                         apps::AppServiceProxy* app_service_proxy)
    : OsSettingsSection(profile, search_tag_registry),
      pref_service_(pref_service),
      arc_app_list_prefs_(arc_app_list_prefs),
      app_service_proxy_(app_service_proxy),
      is_arc_allowed_(arc::IsArcAllowedForProfile(profile)) {
  SearchTagRegistry::ScopedTagUpdater updater = registry()->StartUpdate();
  updater.AddSearchTags(GetAppsSearchConcepts());

  // Note: The MessageCenterAsh check here is added for unit testing purposes
  // otherwise check statements are not needed in production.
  if (MessageCenterAsh::Get()) {
    MessageCenterAsh::Get()->AddObserver(this);
    OnQuietModeChanged(MessageCenterAsh::Get()->IsQuietMode());
  }

  if (is_arc_allowed_) {
    pref_change_registrar_.Init(pref_service_);
    pref_change_registrar_.Add(
        arc::prefs::kArcEnabled,
        base::BindRepeating(&AppsSection::UpdateAndroidSearchTags,
                            base::Unretained(this)));

    if (arc_app_list_prefs_) {
      arc_app_list_prefs_->AddObserver(this);
    }

    UpdateAndroidSearchTags();
  }

  if (web_app::IsIwaUnmanagedInstallFeatureEnabled(profile)) {
    updater.AddSearchTags(GetTurnOnIsolatedWebAppsSearchConcepts());
  }

  if (on_device_controls::AppControlsServiceFactory::
          IsOnDeviceAppControlsAvailable(profile)) {
    updater.AddSearchTags(GetParentalControlsSearchConcepts());
  }
}

AppsSection::~AppsSection() {
  // TODO(crbug.com/1237465): observer is never removed because ash::Shell is
  // destroyed first.
  // Note: The MessageCenterAsh check is also added for unit testing purposes.
  if (MessageCenterAsh::Get()) {
    MessageCenterAsh::Get()->RemoveObserver(this);
  }

  if (arc::IsArcAllowedForProfile(profile())) {
    if (arc_app_list_prefs_) {
      arc_app_list_prefs_->RemoveObserver(this);
    }
  }
}

void AppsSection::AddLoadTimeData(content::WebUIDataSource* html_source) {
  webui::LocalizedString kLocalizedStrings[] = {
      {"appsPageTitle", IDS_SETTINGS_APPS_TITLE},
      {"appsMenuItemDescription", IDS_OS_SETTINGS_APPS_MENU_ITEM_DESCRIPTION},
      {"appsmenuItemDescriptionArcUnavailable",
       IDS_OS_SETTINGS_APPS_MENU_ITEM_DESCRIPTION_ARC_UNAVAILABLE},
      {"appManagementTitle", IDS_SETTINGS_APPS_LINK_TEXT},
      {"appNotificationsTitle", IDS_SETTINGS_APP_NOTIFICATIONS_LINK_TEXT},
      {"doNotDisturbToggleTitle",
       IDS_SETTINGS_APP_NOTIFICATIONS_DO_NOT_DISTURB_TOGGLE_TITLE},
      {"manageIsolatedWebAppsLinkText",
       IDS_SETTINGS_MANAGE_ISOLATED_WEB_APPS_LINK_TEXT},
      {"manageIsolatedWebAppsTitle",
       IDS_SETTINGS_MANAGE_ISOLATED_WEB_APPS_SUBPAGE_TITLE},

      {"appNotificationsManagerLabel",
       IDS_OS_SETTINGS_NOTIFICATIONS_MANAGER_LABEL},
      {"appNotificationsManagerSublabel",
       IDS_OS_SETTINGS_NOTIFICATIONS_MANAGER_LINK_DESCRIPTION},
      {"doNotDisturbToggleDescription",
       IDS_OS_SETTINGS_APP_NOTIFICATIONS_DO_NOT_DISTURB_TOGGLE_DESCRIPTION},
      {"appNotificationsLinkToBrowserSettingsDescription",
       IDS_SETTINGS_APP_NOTIFICATIONS_LINK_TO_BROWSER_SETTINGS_DESCRIPTION},
      {"appNotificationsRowSublabel",
       IDS_OS_SETTINGS_APP_NOTIFICATIONS_LINK_DESCRIPTION},
      {"appNotificationsCountDescription",
       IDS_SETTINGS_APP_NOTIFICATIONS_SUBLABEL_TEXT},
      {"appNotificationsDoNotDisturbEnabledDescription",
       IDS_SETTINGS_APP_NOTIFICATIONS_DND_ENABLED_SUBLABEL_TEXT},
      {"appBadgingToggleLabel", IDS_SETTINGS_APP_BADGING_TOGGLE_LABEL},
      {"appBadgingToggleSublabel", IDS_SETTINGS_APP_BADGING_TOGGLE_SUBLABEL},
      {"enableIsolatedWebAppsToggleLabel",
       IDS_SETTINGS_ENABLE_ISOLATED_WEB_APPS_LABEL},
      {"appManagementAppLanguageLabel", IDS_APP_MANAGEMENT_APP_LANGUAGE_LABEL},
      {"permissionAllowedTextWithTurnOnCameraAccessButton",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_TEXT_WITH_TURN_ON_SYSTEM_CAMERA_ACCESS_BUTTON},
      {"permissionAllowedTextWithTurnOnMicrophoneAccessButton",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_TEXT_WITH_TURN_ON_SYSTEM_MICROPHONE_ACCESS_BUTTON},
      {"permissionAllowedTextWithTurnOnLocationAccessButton",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_TEXT_WITH_TURN_ON_SYSTEM_LOCATION_ACCESS_BUTTON},
      {"permissionAllowedTextWithDetailsAndTurnOnCameraAccessButton",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_TEXT_WITH_DETAILS_AND_TURN_ON_SYSTEM_CAMERA_ACCESS_BUTTON},
      {"permissionAllowedTextWithDetailsAndTurnOnMicrophoneAccessButton",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_TEXT_WITH_DETAILS_AND_TURN_ON_SYSTEM_MICROPHONE_ACCESS_BUTTON},
      {"permissionAllowedTextWithDetailsAndTurnOnLocationAccessButton",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_TEXT_WITH_DETAILS_AND_TURN_ON_SYSTEM_LOCATION_ACCESS_BUTTON},
      {"permissionAllowedButNoCameraConnectedText",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_BUT_NO_CAMERA_CONNECTED_TEXT},
      {"permissionAllowedButNoMicrophoneConnectedText",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_BUT_NO_MICROPHONE_CONNECTED_TEXT},
      {"permissionAllowedButNoCameraConnectedTextWithDetails",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_BUT_NO_CAMERA_CONNECTED_TEXT_WITH_DETAILS},
      {"permissionAllowedButNoMicrophoneConnectedTextWithDetails",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_BUT_NO_MICROPHONE_CONNECTED_TEXT_WITH_DETAILS},
      {"permissionAllowedButMicrophoneHwSwitchActiveText",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_BUT_MICROPHONE_HW_SWITCH_ACTIVE_TEXT},
      {"permissionAllowedButMicrophoneHwSwitchActiveTextWithDetails",
       IDS_APP_MANAGEMENT_PERMISSION_ALLOWED_BUT_MICROPHONE_HW_SWITCH_ACTIVE_TEXT_WITH_DETAILS},
  };
  html_source->AddLocalizedStrings(kLocalizedStrings);

  html_source->AddBoolean("appManagementArcReadOnlyPermissions",
                          arc::IsReadOnlyPermissionsEnabled());

  html_source->AddString("appManagementDeviceName",
                         ui::GetChromeOSDeviceName());

  html_source->AddString(
      "appNotificationsBrowserSettingsURL",
      ash::chrome_urls::kChromeUIAppNotificationsBrowserSettingsURL);

  // We have 2 variants of Android apps settings. Default case, when the Play
  // Store app exists we show expandable section that allows as to
  // enable/disable the Play Store and link to Android settings which is
  // available once settings app is registered in the system.
  // For AOSP images we don't have the Play Store app. In last case we Android
  // apps settings consists only from root link to Android settings and only
  // visible once settings app is registered.
  html_source->AddBoolean("androidAppsVisible", is_arc_allowed_);
  html_source->AddBoolean("isPlayStoreAvailable", arc::IsPlayStoreAvailable());

  html_source->AddBoolean("isArcVmEnabled", arc::IsArcVmEnabled());

  html_source->AddBoolean(
      "showManageIsolatedWebAppsRow",
      web_app::IsIwaUnmanagedInstallFeatureEnabled(profile()));
  html_source->AddString("isolatedWebAppsDescription",
                         l10n_util::GetStringFUTF16(
                             IDS_SETTINGS_ISOLATED_WEB_APPS_DESCRIPTION,
                             ash::external_urls::kIsolatedWebAppsLearnMoreUrl));
  html_source->AddString("isolatedWebAppsLearnMoreUrl",
                         ash::external_urls::kIsolatedWebAppsLearnMoreUrl);
  html_source->AddBoolean(
      "isIwaInlineUpdateEnabled",
      base::FeatureList::IsEnabled(ash::features::kIsolatedWebAppInlineUpdate));

  html_source->AddBoolean("privacyHubLocationAccessControlEnabled",
                          ash::features::IsCrosPrivacyHubLocationEnabled());

  html_source->AddBoolean("isAppParentalControlsFeatureAvailable",
                          on_device_controls::AppControlsServiceFactory::
                              IsOnDeviceAppControlsAvailable(profile()));

  html_source->AddBoolean("updateAppStringsOnSettingsEnabled",
                          base::FeatureList::IsEnabled(
                              apps::features::kUpdateAppStringsOnSettings));

  AddAppManagementStrings(html_source);
  AddGuestOsStrings(html_source);
  AddAndroidAppStrings(html_source);
  AddBorealisStrings(html_source);
  AddAppParentalControlsStrings(html_source);
}

void AppsSection::AddHandlers(content::WebUI* web_ui) {
  web_ui->AddMessageHandler(
      std::make_unique<AndroidAppsHandler>(profile(), app_service_proxy_));
  if (arc::IsArcVmEnabled()) {
    web_ui->AddMessageHandler(std::make_unique<GuestOsHandler>(profile()));
  }
}

int AppsSection::GetSectionNameMessageId() const {
  return IDS_SETTINGS_APPS_TITLE;
}

mojom::Section AppsSection::GetSection() const {
  return mojom::Section::kApps;
}

mojom::SearchResultIcon AppsSection::GetSectionIcon() const {
  return mojom::SearchResultIcon::kAppsGrid;
}

const char* AppsSection::GetSectionPath() const {
  return mojom::kAppsSectionPath;
}

bool AppsSection::LogMetric(mojom::Setting setting, base::Value& value) const {
  if (setting == mojom::Setting::kDoNotDisturbOnOff) {
    base::UmaHistogramBoolean("ChromeOS.Settings.Apps.DoNotDisturbOnOff",
                              value.GetBool());
    return true;
  }
  if (setting == mojom::Setting::kAppNotificationOnOff) {
    base::UmaHistogramBoolean(
        "ChromeOS.Settings.NotificationPage.PermissionOnOff", value.GetBool());
    return true;
  }
  return false;
}

void AppsSection::RegisterHierarchy(HierarchyGenerator* generator) const {
  generator->RegisterTopLevelSetting(mojom::Setting::kTurnOnPlayStore);
  generator->RegisterTopLevelSetting(mojom::Setting::kAppParentalControls);

  // Manage apps.
  generator->RegisterTopLevelSubpage(IDS_SETTINGS_APPS_LINK_TEXT,
                                     mojom::Subpage::kAppManagement,
                                     mojom::SearchResultIcon::kAppsGrid,
                                     mojom::SearchResultDefaultRank::kMedium,
                                     mojom::kAppManagementSubpagePath);

  // App Notifications
  generator->RegisterTopLevelSubpage(IDS_SETTINGS_APP_NOTIFICATIONS_LINK_TEXT,
                                     mojom::Subpage::kAppNotifications,
                                     mojom::SearchResultIcon::kAppsGrid,
                                     mojom::SearchResultDefaultRank::kMedium,
                                     mojom::kAppNotificationsSubpagePath);
  generator->RegisterNestedSubpage(
      IDS_OS_SETTINGS_TAG_APP_NOTIFICATIONS_MANAGER,
      mojom::Subpage::kAppNotificationsManager,
      mojom::Subpage::kAppNotifications, mojom::SearchResultIcon::kAppsGrid,
      mojom::SearchResultDefaultRank::kMedium,
      mojom::kAppNotificationsManagerSubpagePath);
  generator->RegisterNestedSetting(mojom::Setting::kDoNotDisturbOnOff,
                                   mojom::Subpage::kAppNotifications);
  generator->RegisterNestedSetting(mojom::Setting::kAppBadgingOnOff,
                                   mojom::Subpage::kAppNotifications);
  generator->RegisterNestedSetting(mojom::Setting::kAppNotificationOnOff,
                                   mojom::Subpage::kAppNotifications);

  generator->RegisterTopLevelSetting(
      mojom::Setting::kEnableIsolatedWebAppsOnOff);

  // Note: The subpage name in the UI is updated dynamically based on the app
  // being shown, but we use a generic "App details" string here.
  generator->RegisterNestedSubpage(
      IDS_SETTINGS_APP_DETAILS_TITLE, mojom::Subpage::kAppDetails,
      mojom::Subpage::kAppManagement, mojom::SearchResultIcon::kAppsGrid,
      mojom::SearchResultDefaultRank::kMedium, mojom::kAppDetailsSubpagePath);
  generator->RegisterNestedSetting(mojom::Setting::kAppPinToShelfOnOff,
                                   mojom::Subpage::kAppDetails);
  generator->RegisterNestedSetting(mojom::Setting::kAppResizeLockOnOff,
                                   mojom::Subpage::kAppDetails);

  // Google Play Store.
  generator->RegisterTopLevelSubpage(IDS_OS_SETTINGS_ANDROID_APPS_LABEL,
                                     mojom::Subpage::kGooglePlayStore,
                                     mojom::SearchResultIcon::kGooglePlay,
                                     mojom::SearchResultDefaultRank::kMedium,
                                     mojom::kGooglePlayStoreSubpagePath);
  static constexpr mojom::Setting kGooglePlayStoreSettings[] = {
      mojom::Setting::kManageAndroidPreferences,
      mojom::Setting::kRemovePlayStore,
  };
  RegisterNestedSettingBulk(mojom::Subpage::kGooglePlayStore,
                            kGooglePlayStoreSettings, generator);
  generator->RegisterTopLevelAltSetting(
      mojom::Setting::kManageAndroidPreferences);

  generator->RegisterNestedSubpage(
      IDS_SETTINGS_GUEST_OS_SHARED_USB_DEVICES_LABEL,
      mojom::Subpage::kArcVmUsbPreferences, mojom::Subpage::kGooglePlayStore,
      mojom::SearchResultIcon::kGooglePlay,
      mojom::SearchResultDefaultRank::kMedium,
      mojom::kArcVmUsbPreferencesSubpagePath);

  // On-device parental controls for apps
  generator->RegisterTopLevelSubpage(
      IDS_OS_SETTINGS_APP_PARENTAL_CONTROLS_LABEL,
      mojom::Subpage::kAppParentalControls,
      mojom::SearchResultIcon::kAppsParentalControls,
      mojom::SearchResultDefaultRank::kMedium,
      mojom::kAppParentalControlsSubpagePath);
}

void AppsSection::OnAppRegistered(const std::string& app_id,
                                  const ArcAppListPrefs::AppInfo& app_info) {
  UpdateAndroidSearchTags();
}

void AppsSection::AddAndroidAppStrings(content::WebUIDataSource* html_source) {
  webui::LocalizedString kLocalizedStrings[] = {
      {"androidAppsPageLabel", IDS_OS_SETTINGS_ANDROID_APPS_LABEL},
      {"androidAppsEnable", IDS_SETTINGS_TURN_ON},
      {"androidAppsManageApps", IDS_OS_SETTINGS_ANDROID_APPS_MANAGE_APPS},
      {"androidAppsRemove", IDS_OS_SETTINGS_ANDROID_APPS_REMOVE},
      {"androidAppsRemoveButton", IDS_SETTINGS_ANDROID_APPS_REMOVE_BUTTON},
      {"androidAppsDisableDialogTitle",
       IDS_OS_SETTINGS_ANDROID_APPS_DISABLE_DIALOG_TITLE},
      {"androidAppsDisableDialogMessage",
       IDS_OS_SETTINGS_ANDROID_APPS_DISABLE_DIALOG_MESSAGE},
      {"androidAppsDisableDialogRemove",
       IDS_SETTINGS_ANDROID_APPS_REMOVE_BUTTON},
      {"arcvmSharedUsbDevicesDescription",
       IDS_SETTINGS_APPS_ARC_VM_SHARED_USB_DEVICES_DESCRIPTION},
      {"androidAppsEnableButtonRole",
       IDS_SETTINGS_ANDROID_APPS_ENABLE_BUTTON_ROLE},
      {"androidOpenGooglePlay", IDS_OS_SETTINGS_OPEN_GOOGLE_PLAY},
      {"appLanguageDeviceLanguageLabel",
       IDS_OS_SETTINGS_APP_LANGUAGE_DEVICE_LANGUAGE_LABEL},
      {"appLanguageDialogTitle", IDS_OS_SETTINGS_APP_LANGUAGE_DIALOG_TITLE},
      {"appLanguageDialogSearchPlaceholderText",
       IDS_OS_SETTINGS_APP_LANGUAGE_DIALOG_SEARCH_PLACEHOLDER_TEXT},
      {"appLanguageDialogSuggestedLabel",
       IDS_OS_SETTINGS_APP_LANGUAGE_DIALOG_SUGGESTED_LABEL},
      {"appLanguageDialogAllLanguagesLabel",
       IDS_OS_SETTINGS_APP_LANGUAGE_DIALOG_ALL_LANGUAGES_LABEL},
      {"appLanguageDialogUpdateButtonText",
       IDS_OS_SETTINGS_APP_LANGUAGE_DIALOG_UPDATE_BUTTON_TEXT},
  };
  html_source->AddLocalizedStrings(kLocalizedStrings);
  html_source->AddLocalizedString("androidAppsPageTitle",
                                  arc::IsPlayStoreAvailable()
                                      ? IDS_SETTINGS_ANDROID_APPS_TITLE
                                      : IDS_SETTINGS_ANDROID_SETTINGS_TITLE);
  html_source->AddString(
      "androidAppsSubtext",
      l10n_util::GetStringFUTF16(
          IDS_OS_SETTINGS_ANDROID_APPS_SUBTEXT,
          GetHelpUrlWithBoard(ash::external_urls::kAndroidAppsLearnMoreURL)));
  html_source->AddLocalizedString(
      "androidAppsSubtextDescription",
      IDS_OS_SETTINGS_ANDROID_APPS_SUBTEXT_DESCRIPTION);
}

void AppsSection::UpdateAndroidSearchTags() {
  SearchTagRegistry::ScopedTagUpdater updater = registry()->StartUpdate();

  updater.RemoveSearchTags(GetAndroidNoPlayStoreSearchConcepts());
  updater.RemoveSearchTags(GetAndroidPlayStoreDisabledSearchConcepts());
  updater.RemoveSearchTags(GetAndroidPlayStoreSearchConcepts());
  updater.RemoveSearchTags(GetAndroidSettingsSearchConcepts());

  if (!arc::IsPlayStoreAvailable()) {
    updater.AddSearchTags(GetAndroidNoPlayStoreSearchConcepts());
    return;
  }

  if (!arc::IsArcPlayStoreEnabledForProfile(profile())) {
    updater.AddSearchTags(GetAndroidPlayStoreDisabledSearchConcepts());
    return;
  }

  updater.AddSearchTags(GetAndroidPlayStoreSearchConcepts());

  if (arc_app_list_prefs_ &&
      arc_app_list_prefs_->IsRegistered(arc::kSettingsAppId)) {
    updater.AddSearchTags(GetAndroidSettingsSearchConcepts());
  }
}

void AppsSection::OnQuietModeChanged(bool in_quiet_mode) {
  SearchTagRegistry::ScopedTagUpdater updater = registry()->StartUpdate();

  updater.RemoveSearchTags(GetTurnOnAppNotificationSearchConcepts());
  updater.RemoveSearchTags(GetTurnOffAppNotificationSearchConcepts());
  updater.RemoveSearchTags(GetAppNotificationsSearchConcepts());
  updater.RemoveSearchTags(GetAppNotificationsManagerSearchConcepts());
  updater.RemoveSearchTags(GetAppBadgingSearchConcepts());

  updater.AddSearchTags(GetAppNotificationsSearchConcepts());
  updater.AddSearchTags(GetAppNotificationsManagerSearchConcepts());
  updater.AddSearchTags(GetAppBadgingSearchConcepts());

  if (!MessageCenterAsh::Get()->IsQuietMode()) {
    updater.AddSearchTags(GetTurnOnAppNotificationSearchConcepts());
    return;
  }

  updater.AddSearchTags(GetTurnOffAppNotificationSearchConcepts());
}

}  // namespace ash::settings
