<!--
  Copyright 2024 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.android.photopicker">

  <!--
    This permission identifies Photopicker to MediaProvider and allows access
    to private system APIs.

    Declared by MediaProvider and requires the 'media' certificate to obtain.
  -->
  <uses-permission
    android:name="com.android.providers.media.permission.MANAGE_CLOUD_MEDIA_PROVIDERS"/>

  <!-- Required to inspect network capabilities through ConnectivityManager -->
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

  <!-- Permissions required for reading device configs -->
  <uses-permission android:name="android.permission.READ_DEVICE_CONFIG"/>

   <!-- Permissions required for fetching User profiles -->
  <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>

  <!--
    Required for resolving packages based on their UID for privacy banner
    Also required for resolving DocumentsUI and CloudMediaProviders.
  -->
  <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>

  <application
          android:name="com.android.photopicker.PhotopickerApplication"
          android:icon="@mipmap/photopicker_app_icon"
          android:label="@string/photopicker_application_label"
          android:crossProfile="true"
          android:allowBackup="false"
          android:enableOnBackInvokedCallback="true"
          android:supportsRtl="true">

    <activity
      android:name="com.android.photopicker.MainActivity"
      android:enabled="false"
      android:enableOnBackInvokedCallback="false"
      android:exported="true"
      android:theme="@style/Theme.Photopicker"
      android:label="@string/photopicker_application_label"
      android:windowSoftInputMode="adjustResize"
      android:excludeFromRecents="true">

      <intent-filter android:priority="110" >
                <action android:name="android.provider.action.PICK_IMAGES"/>
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
                <data android:mimeType="video/*" />
      </intent-filter>
      <intent-filter android:priority="105" >
                <action android:name="android.provider.action.PICK_IMAGES"/>
                <category android:name="android.intent.category.DEFAULT"/>
      </intent-filter>
    </activity>

    <activity-alias
        android:name="com.android.photopicker.PhotopickerGetContentActivity"
        android:enabled="false"
        android:targetActivity="com.android.photopicker.MainActivity"
        android:exported="true"
        android:excludeFromRecents="true">
        <intent-filter android:priority="110" >
            <action android:name="android.intent.action.GET_CONTENT"/>
            <category android:name="android.intent.category.OPENABLE"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="image/*"/>
            <data android:mimeType="video/*"/>
        </intent-filter>
    </activity-alias>

    <activity-alias
        android:name="com.android.photopicker.PhotopickerUserSelectActivity"
        android:targetActivity="com.android.photopicker.MainActivity"
        android:permission="android.permission.GRANT_RUNTIME_PERMISSIONS"
        android:exported="true"
        android:enabled="false"
        android:excludeFromRecents="true">
        <intent-filter android:priority="105">
            <action android:name="android.provider.action.USER_SELECT_IMAGES_FOR_APP" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
            <data android:mimeType="video/*" />
        </intent-filter>
        <intent-filter android:priority="105">
            <action android:name="android.provider.action.USER_SELECT_IMAGES_FOR_APP" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity-alias>

    <!--
      Receiver that receives broadcasts from MediaProvider when the DeviceConfig is updated.
      This is required because Photopicker does not have a persistent process of its own, but
      needs to enable or disable various package components based on flag state. MediaProvider
      sends broadcasts to Photopicker anytime the DeviceConfig is updated so that Photopicker
      can wake up and evaluate its component state.

      These broadcasts are scoped to the MANAGE_CLOUD_MEDIA_PROVIDERS permission so that other
      apps are unable to eavesdrop on these broadcasts (though they contain no data and are just
      a wake up signal).
    -->
    <receiver android:name="com.android.photopicker.PhotopickerDeviceConfigReceiver"
              android:exported="true"
              android:enabled="@bool/config_enablePhotopickerDeviceConfigReceiver"
              android:permission="com.android.providers.media.permission.MANAGE_CLOUD_MEDIA_PROVIDERS">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
      </intent-filter>
    </receiver>

    <!--
    The Embedded Photopicker service that allows external apps to launch an embedded photopicker
    experience inside of their own application. This service uses Remote Rendering to provide a
    view to the binding application, and renders the view from the photopicker process.
    See EmbeddedService and Session classes for the entrypoints into the Embedded Photopicker.
    -->
    <service android:name="com.android.photopicker.core.embedded.EmbeddedService"
             android:exported="true">
      <intent-filter>
        <action android:name="com.android.photopicker.core.embedded.EmbeddedService.BIND" />
      </intent-filter>
    </service>

  </application>

</manifest>
