summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/api/system-current.txt8
-rw-r--r--core/java/android/service/chooser/CustomChoosers.java84
-rw-r--r--core/java/com/android/internal/app/NfcResolverActivity.java59
-rw-r--r--core/res/AndroidManifest.xml12
4 files changed, 163 insertions, 0 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index b19395feb4fe..742b903a49a1 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -11783,6 +11783,14 @@ package android.service.carrier {
}
+package android.service.chooser {
+
+ @FlaggedApi("android.service.chooser.support_nfc_resolver") public class CustomChoosers {
+ method @FlaggedApi("android.service.chooser.support_nfc_resolver") @NonNull public static android.content.Intent createNfcResolverIntent(@NonNull android.content.Intent, @Nullable CharSequence, @NonNull java.util.List<android.content.pm.ResolveInfo>);
+ }
+
+}
+
package android.service.cloudsearch {
public abstract class CloudSearchService extends android.app.Service {
diff --git a/core/java/android/service/chooser/CustomChoosers.java b/core/java/android/service/chooser/CustomChoosers.java
new file mode 100644
index 000000000000..5b89432b956d
--- /dev/null
+++ b/core/java/android/service/chooser/CustomChoosers.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+package android.service.chooser;
+
+import android.annotation.FlaggedApi;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.SystemApi;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Static helper methods that privileged clients can use to initiate Share sessions with extra
+ * customization options that aren't usually available in the stock "Resolver/Chooser" flows.
+ *
+ * @hide
+ */
+@FlaggedApi(Flags.FLAG_SUPPORT_NFC_RESOLVER)
+@SystemApi
+public class CustomChoosers {
+ /**
+ * Intent action to start a Share session with additional customization options. Clients should
+ * use the helper methods in this class to configure their customized share intents, and should
+ * avoid using this action to construct their own intents directly.
+ */
+ private static final String ACTION_SHOW_CUSTOMIZED_RESOLVER =
+ "android.service.chooser.action.SHOW_CUSTOMIZED_RESOLVER";
+
+ /**
+ * "Extras" key for an ArrayList of {@link ResolveInfo} records which are to be shown as the
+ * targets in the customized share session.
+ *
+ * @hide
+ */
+ public static final String EXTRA_RESOLVE_INFOS = "android.service.chooser.extra.RESOLVE_INFOS";
+
+ /**
+ * Build an {@link Intent} to dispatch a "Chooser flow" that picks a target resolution for the
+ * specified {@code target} intent, styling the Chooser UI according to the specified
+ * customization parameters.
+ *
+ * @param target The ambiguous intent that should be resolved to a specific target selected
+ * via the Chooser flow.
+ * @param title An optional "headline" string to display at the top of the Chooser UI, or null
+ * to use the system default.
+ * @param resolutionList Explicit resolution info for targets that should be shown in the
+ * dispatched Share UI.
+ *
+ * @hide
+ */
+ @FlaggedApi(Flags.FLAG_SUPPORT_NFC_RESOLVER)
+ @SystemApi
+ @NonNull
+ public static Intent createNfcResolverIntent(
+ @NonNull Intent target,
+ @Nullable CharSequence title,
+ @NonNull List<ResolveInfo> resolutionList) {
+ Intent resolverIntent = new Intent(ACTION_SHOW_CUSTOMIZED_RESOLVER);
+ resolverIntent.putExtra(Intent.EXTRA_INTENT, target);
+ resolverIntent.putExtra(Intent.EXTRA_TITLE, title);
+ resolverIntent.putParcelableArrayListExtra(
+ EXTRA_RESOLVE_INFOS, new ArrayList<>(resolutionList));
+ return resolverIntent;
+ }
+
+ private CustomChoosers() {}
+}
diff --git a/core/java/com/android/internal/app/NfcResolverActivity.java b/core/java/com/android/internal/app/NfcResolverActivity.java
new file mode 100644
index 000000000000..402192abaf0a
--- /dev/null
+++ b/core/java/com/android/internal/app/NfcResolverActivity.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+package com.android.internal.app;
+
+import static android.service.chooser.CustomChoosers.EXTRA_RESOLVE_INFOS;
+import static android.service.chooser.Flags.supportNfcResolver;
+
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
+
+import java.util.ArrayList;
+
+/**
+ * Caller-customizable variant of {@link ResolverActivity} to support the
+ * {@link CustomChoosers#showNfcResolver()} API.
+ */
+public class NfcResolverActivity extends ResolverActivity {
+
+ @Override
+ @SuppressWarnings("MissingSuperCall") // Called indirectly via `super_onCreate()`.
+ protected void onCreate(Bundle savedInstanceState) {
+ if (!supportNfcResolver()) {
+ super_onCreate(savedInstanceState);
+ finish();
+ return;
+ }
+
+ Intent intent = getIntent();
+ Intent target = intent.getParcelableExtra(Intent.EXTRA_INTENT, Intent.class);
+ ArrayList<ResolveInfo> rList =
+ intent.getParcelableArrayListExtra(EXTRA_RESOLVE_INFOS, ResolveInfo.class);
+ CharSequence title = intent.getExtras().getCharSequence(
+ Intent.EXTRA_TITLE,
+ getResources().getText(com.android.internal.R.string.chooseActivity));
+
+ super.onCreate(
+ savedInstanceState,
+ target,
+ title,
+ /* initialIntents=*/ null,
+ rList,
+ /* supportsAlwaysUseOption=*/ false);
+ }
+}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index df215aabdc33..38fde3dc2469 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -7898,6 +7898,18 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
+ <activity android:name="com.android.internal.app.NfcResolverActivity"
+ android:theme="@style/Theme.Dialog.Alert"
+ android:finishOnCloseSystemDialogs="true"
+ android:excludeFromRecents="true"
+ android:multiprocess="true"
+ android:permission="android.permission.SHOW_CUSTOMIZED_RESOLVER"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.service.chooser.action.SHOW_CUSTOMIZED_RESOLVER" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
<activity android:name="com.android.internal.app.IntentForwarderActivity"
android:finishOnCloseSystemDialogs="true"
android:theme="@style/Theme.DeviceDefault.Resolver"