<?xml version="1.0" encoding="utf-8"?>

<!-- Copyright 2019 The Chromium Authors
     Use of this source code is governed by a BSD-style license that can be
     found in the LICENSE file.
 -->
{% set default_manifest_package = "org.chromium.android_browsertests_apk" %}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
  package="{{ manifest_package|default(default_manifest_package) }}">

    <permission android:name="{{ manifest_package|default(default_manifest_package) }}.permission.CHILD_SERVICE" android:protectionLevel="signature" />

    <uses-feature android:glEsVersion="0x00020000" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.USE_FINGERPRINT" />
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    {% block extra_uses_permissions %}
    {% endblock %}

    <queries>
        <intent>
            <action android:name="org.chromium.chrome.browser.extensions.messaging.action.NATIVE_MESSAGING" />
        </intent>
    </queries>

    <application android:name="org.chromium.android_browsertests_apk.ChromeBrowserTestsApplication"
            android:label="ChromeBrowserTests"
            android:requestLegacyExternalStorage="true">

        <!--
          The default Activity started by Android browser tests.
          It's a subclass of ChromeTabbedActivity.
        -->
        <activity android:name="org.chromium.android_browsertests_apk.ChromeBrowserTestsActivity"
                  android:launchMode="singleTask"
                  android:theme="@style/Theme.Chromium.TabbedMode"
                  android:configChanges="orientation|keyboardHidden|keyboard|screenSize|screenLayout|smallestScreenSize"
                  android:hardwareAccelerated="true"
                  android:exported="true"
                  android:process=":test_process">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <!--
          Explicitly declare ChromeTabbedActivity for browser tests
          that will start it besides the default Activity
          (ChromeBrowserTestsActivity).

          The taskAffinity attribute is set to an empty string to
          ensure a ChromeTabbedActivity can be launched into a new Task
          when its Intent has FLAG_ACTIVITY_NEW_TASK and
          FLAG_ACTIVITY_MULTIPLE_TASK.
        -->
        <activity android:name="org.chromium.chrome.browser.ChromeTabbedActivity"
                  android:theme="@style/Theme.Chromium.TabbedMode"
                  android:exported="true"
                  android:launchMode="singleTask"
                  android:taskAffinity=""
                  android:configChanges="orientation|keyboardHidden|keyboard|screenSize|screenLayout|smallestScreenSize"
                  android:hardwareAccelerated="true"
                  android:process=":test_process">

          <!--
            Mirrors meta-data in the production manifest containing ChromeTabbedActivity.

            This is needed to enable MultiInstanceManagerApi31 in browser tests.
            See: https://source.chromium.org/chromium/chromium/src/+/main:chrome/android/java/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java;l=187-191;drc=0bcba72c5246a910240b311def40233f7d3f15af
          -->
          <meta-data
                android:name="android.activity.launch_mode"
                android:value="singleInstancePerTask"/>
        </activity>

        <activity android:name="org.chromium.chrome.browser.customtabs.CustomTabActivity"
          android:theme="@style/Theme.Chromium.Activity"
          android:exported="false"
          android:windowSoftInputMode="adjustResize"
                    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|mcc|mnc|screenLayout|smallestScreenSize|uiMode|navigation|density|touchscreen|colorMode"
          android:hardwareAccelerated="false"
          android:process=":test_process">
        </activity>

        <activity android:name="org.chromium.chrome.browser.devtools.DevToolsActivity"
          android:theme="@style/Theme.Chromium.Activity"
          android:exported="false"
          android:configChanges="orientation|keyboardHidden|keyboard|screenSize|screenLayout|smallestScreenSize"
          android:hardwareAccelerated="false"
          android:process=":test_process">
        </activity>

        <activity android:name="org.chromium.chrome.browser.media.MediaLauncherActivity"
                  android:theme="@android:style/Theme.NoDisplay"
                  android:excludeFromRecents="true"
                  android:exported="true"
                  android:enabled="false"><!-- This will be selectively enabled at runtime. -->
          <intent-filter tools:ignore="AppLinkUrlError">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <!-- TODO(crbug.com/40557607): Limit these to
                 supported MIME types. -->
            <data android:mimeType="image/*" />
            <data android:mimeType="video/*" />
            <data android:scheme="file" />
            <data android:scheme="content" />
          </intent-filter>
        </activity>

        <activity-alias android:name="org.chromium.chrome.browser.media.AudioLauncherActivity"
                        android:targetActivity="org.chromium.chrome.browser.media.MediaLauncherActivity"
                        android:exported="true"
                        android:enabled="false"><!-- This will be selectively enabled at runtime. -->
          <intent-filter tools:ignore="AppLinkUrlError">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <!-- TODO(crbug.com/40557607): Limit these to supported MIME types. -->
            <data android:mimeType="audio/*" />
            <data android:scheme="file" />
            <data android:scheme="content" />
          </intent-filter>
        </activity-alias>

        <activity android:name="org.chromium.chrome.browser.incognito.IncognitoTabLauncher"
                  android:theme="@android:style/Theme.NoDisplay"
                  android:taskAffinity=""
                  android:enabled="false"
                  android:excludeFromRecents="true"
                  android:exported="true">
          <intent-filter>
            <action android:name="org.chromium.chrome.browser.incognito.OPEN_PRIVATE_TAB" />
            <category android:name="android.intent.category.DEFAULT" />
          </intent-filter>
        </activity>

        <receiver android:name="org.chromium.chrome.browser.quickactionsearchwidget.QuickActionSearchWidgetProvider$QuickActionSearchWidgetProviderSearch"
            android:exported="true">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
        </receiver>

        <receiver android:name="org.chromium.chrome.browser.quickactionsearchwidget.QuickActionSearchWidgetProvider$QuickActionSearchWidgetProviderDino"
            android:exported="true">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
        </receiver>

        <service android:name="org.chromium.components.background_task_scheduler.internal.BackgroundTaskJobService"
                 android:exported="false"
                 android:process=":test_process"
                 android:permission="android.permission.BIND_JOB_SERVICE"/>

        <service android:name="org.chromium.chrome.browser.crash.ChromeMinidumpUploadJobService"
                 android:permission="android.permission.BIND_JOB_SERVICE"
                 android:exported="false"/>

        <service
            android:name="org.chromium.chrome.browser.webid.TestIdP"
            android:exported="true">
            <intent-filter>
                <action android:name="org.w3.FedCM" />
            </intent-filter>
        </service>

        <!-- The following service entries exist in order to allow us
             to start more than one sandboxed process. -->

        <!-- NOTE: If you change the values of "android:process" for any of the below services,
             you also need to update kHelperProcessExecutableName in chrome_constants.cc. -->
        {% set num_sandboxed_services = 40 %}
        <meta-data android:name="org.chromium.content.browser.NUM_SANDBOXED_SERVICES"
                   android:value="{{ num_sandboxed_services }}"/>

        {% for i in range(num_sandboxed_services) %}
        <service android:name="org.chromium.content.app.SandboxedProcessService{{ i }}"
                 android:process=":sandboxed_process{{ i }}"
                 android:isolatedProcess="true"
                 android:exported="false" />
        {% endfor %}

        {% set num_privileged_services = 5 %}
        <meta-data android:name="org.chromium.content.browser.NUM_PRIVILEGED_SERVICES"
                   android:value="{{ num_privileged_services }}"/>

        {% for i in range(num_privileged_services) %}
        <service android:name="org.chromium.content.app.PrivilegedProcessService{{ i }}"
                 android:process=":privileged_process{{ i }}"
                 android:isolatedProcess="false"
                 android:exported="false" />
        {% endfor %}

        <!-- Disables at startup init of Emoji2. See http://crbug.com/40764422 -->
        <provider
            android:authorities="{{ manifest_package|default(default_manifest_package) }}.androidx-startup"
            android:name="androidx.startup.InitializationProvider"
            android:exported="false"
            tools:node="remove" />

        <!-- Restricting to just 2 native-only services, one for zygote and one for non-zygote. -->
        {% for i in range(2) %}
        <service android:name="org.chromium.content.app.NativeOnlySandboxedProcessService{{ i }}"
            android:nativeService="true"
            android:process=":sandboxed_process{{ i }}"
            android:permission="{{ manifest_package|default(default_manifest_package) }}.permission.CHILD_SERVICE"
            android:isolatedProcess="true"
            android:exported="false" >
            <property android:name="android.app.PROPERTY_NATIVE_SERVICE_LIBRARY_NAME"
                android:value="lib{{ library_name }}.so" />
            <property android:name="android.app.PROPERTY_NATIVE_SERVICE_FUNCTION_NAME"
                android:value="NativeChildProcessService_onCreate" />
        </service>
        {% endfor %}

        <service android:name="org.chromium.build.gtest_apk.ProcessKeepaliveService"
            android:process=":test_process"
            android:exported="false" />
    </application>

    <instrumentation android:name="org.chromium.android_browsertests_apk.ChromeBrowserTestsInstrumentationTestRunner"
            android:label="ChromeBrowserTests"
      android:targetPackage="{{ manifest_package|default(default_manifest_package) }}"/>
</manifest>
