Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Todd Kennedy | 63ff464 | 2019-03-25 11:20:01 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 24 | import android.content.pm.InstantAppRequestInfo; |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 25 | import android.content.pm.InstantAppResolveInfo; |
Todd Kennedy | 02a6b73 | 2017-04-05 14:24:58 -0700 | [diff] [blame] | 26 | import android.os.Build; |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 27 | import android.os.Bundle; |
| 28 | import android.os.Handler; |
| 29 | import android.os.IBinder; |
| 30 | import android.os.IRemoteCallback; |
| 31 | import android.os.Looper; |
| 32 | import android.os.Message; |
| 33 | import android.os.RemoteException; |
Hai Zhang | bfa4f90 | 2018-08-21 11:33:33 -0700 | [diff] [blame] | 34 | import android.os.UserHandle; |
Todd Kennedy | 02a6b73 | 2017-04-05 14:24:58 -0700 | [diff] [blame] | 35 | import android.util.Log; |
| 36 | import android.util.Slog; |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 37 | |
Winson | 191069d | 2019-12-20 15:35:29 -0800 | [diff] [blame] | 38 | import com.android.internal.annotations.VisibleForTesting; |
Todd Kennedy | d3c5106 | 2017-03-17 16:03:29 -0700 | [diff] [blame] | 39 | import com.android.internal.os.SomeArgs; |
| 40 | |
Todd Kennedy | 02a6b73 | 2017-04-05 14:24:58 -0700 | [diff] [blame] | 41 | import java.util.Arrays; |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 42 | import java.util.Collections; |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 43 | import java.util.List; |
| 44 | |
| 45 | /** |
| 46 | * Base class for implementing the resolver service. |
| 47 | * @hide |
| 48 | */ |
| 49 | @SystemApi |
| 50 | public abstract class InstantAppResolverService extends Service { |
Patrick Baumann | 43c97a0 | 2018-01-31 20:09:03 +0000 | [diff] [blame] | 51 | private static final boolean DEBUG_INSTANT = Build.IS_DEBUGGABLE; |
Todd Kennedy | 02a6b73 | 2017-04-05 14:24:58 -0700 | [diff] [blame] | 52 | private static final String TAG = "PackageManager"; |
| 53 | |
Todd Kennedy | d3c5106 | 2017-03-17 16:03:29 -0700 | [diff] [blame] | 54 | /** @hide */ |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 55 | public static final String EXTRA_RESOLVE_INFO = "android.app.extra.RESOLVE_INFO"; |
Todd Kennedy | d3c5106 | 2017-03-17 16:03:29 -0700 | [diff] [blame] | 56 | /** @hide */ |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 57 | public static final String EXTRA_SEQUENCE = "android.app.extra.SEQUENCE"; |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 58 | Handler mHandler; |
| 59 | |
| 60 | /** |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 61 | * Called to retrieve resolve info for instant applications immediately. |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 62 | * |
| 63 | * @param digestPrefix The hash prefix of the instant app's domain. |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 64 | * |
| 65 | * @deprecated Should implement {@link #onGetInstantAppResolveInfo(InstantAppRequestInfo, |
| 66 | * InstantAppResolutionCallback)} |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 67 | */ |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 68 | @Deprecated |
Todd Kennedy | 63ff464 | 2019-03-25 11:20:01 -0700 | [diff] [blame] | 69 | public void onGetInstantAppResolveInfo(@Nullable int[] digestPrefix, @NonNull String token, |
| 70 | @NonNull InstantAppResolutionCallback callback) { |
Patrick Baumann | 3abf547 | 2018-03-01 09:58:23 -0800 | [diff] [blame] | 71 | throw new IllegalStateException("Must define onGetInstantAppResolveInfo"); |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /** |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 75 | * Called to retrieve intent filters for instant applications from potentially expensive |
| 76 | * sources. |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 77 | * |
| 78 | * @param digestPrefix The hash prefix of the instant app's domain. |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 79 | * |
| 80 | * @deprecated Should implement {@link #onGetInstantAppIntentFilter(InstantAppRequestInfo, |
| 81 | * InstantAppResolutionCallback)} |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 82 | */ |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 83 | @Deprecated |
Todd Kennedy | 63ff464 | 2019-03-25 11:20:01 -0700 | [diff] [blame] | 84 | public void onGetInstantAppIntentFilter(@Nullable int[] digestPrefix, @NonNull String token, |
| 85 | @NonNull InstantAppResolutionCallback callback) { |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 86 | throw new IllegalStateException("Must define onGetInstantAppIntentFilter"); |
| 87 | } |
| 88 | |
| 89 | /** |
Patrick Baumann | 3abf547 | 2018-03-01 09:58:23 -0800 | [diff] [blame] | 90 | * Called to retrieve resolve info for instant applications immediately. The response will be |
| 91 | * ignored if not provided within a reasonable time. {@link InstantAppResolveInfo}s provided |
| 92 | * in response to this method may be partial to request a second phase of resolution which will |
| 93 | * result in a subsequent call to |
| 94 | * {@link #onGetInstantAppIntentFilter(Intent, int[], String, InstantAppResolutionCallback)} |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 95 | * |
Patrick Baumann | 3abf547 | 2018-03-01 09:58:23 -0800 | [diff] [blame] | 96 | * @param sanitizedIntent The sanitized {@link Intent} used for resolution. A sanitized Intent |
| 97 | * is an intent with potential PII removed from the original intent. |
| 98 | * Fields removed include extras and the host + path of the data, if |
| 99 | * defined. |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 100 | * @param hostDigestPrefix The hash prefix of the instant app's domain. |
Patrick Baumann | 3abf547 | 2018-03-01 09:58:23 -0800 | [diff] [blame] | 101 | * @param token A unique identifier that will be provided in calls to |
| 102 | * {@link #onGetInstantAppIntentFilter(Intent, int[], String, |
| 103 | * InstantAppResolutionCallback)} |
| 104 | * and provided to the installer via {@link Intent#EXTRA_INSTANT_APP_TOKEN} to |
| 105 | * tie a single launch together. |
| 106 | * @param callback The {@link InstantAppResolutionCallback} to provide results to. |
| 107 | * |
| 108 | * @see InstantAppResolveInfo |
Hai Zhang | bfa4f90 | 2018-08-21 11:33:33 -0700 | [diff] [blame] | 109 | * |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 110 | * @deprecated Should implement {@link #onGetInstantAppResolveInfo(InstantAppRequestInfo, |
| 111 | * InstantAppResolutionCallback)} |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 112 | */ |
Hai Zhang | bfa4f90 | 2018-08-21 11:33:33 -0700 | [diff] [blame] | 113 | @Deprecated |
Todd Kennedy | 63ff464 | 2019-03-25 11:20:01 -0700 | [diff] [blame] | 114 | public void onGetInstantAppResolveInfo(@NonNull Intent sanitizedIntent, |
| 115 | @Nullable int[] hostDigestPrefix, @NonNull String token, |
| 116 | @NonNull InstantAppResolutionCallback callback) { |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 117 | // if not overridden, forward to old methods and filter out non-web intents |
Patrick Baumann | 0da8537 | 2018-02-02 16:07:35 -0800 | [diff] [blame] | 118 | if (sanitizedIntent.isWebIntent()) { |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 119 | onGetInstantAppResolveInfo(hostDigestPrefix, token, callback); |
| 120 | } else { |
| 121 | callback.onInstantAppResolveInfo(Collections.emptyList()); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
Patrick Baumann | 3abf547 | 2018-03-01 09:58:23 -0800 | [diff] [blame] | 126 | * Called to retrieve intent filters for potentially matching instant applications. Unlike |
| 127 | * {@link #onGetInstantAppResolveInfo(Intent, int[], String, InstantAppResolutionCallback)}, |
| 128 | * the response may take as long as necessary to respond. All {@link InstantAppResolveInfo}s |
| 129 | * provided in response to this method must be completely populated. |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 130 | * |
| 131 | * @param sanitizedIntent The sanitized {@link Intent} used for resolution. |
| 132 | * @param hostDigestPrefix The hash prefix of the instant app's domain or null if no host is |
| 133 | * defined. |
Patrick Baumann | 3abf547 | 2018-03-01 09:58:23 -0800 | [diff] [blame] | 134 | * @param token A unique identifier that was provided in |
| 135 | * {@link #onGetInstantAppResolveInfo(Intent, int[], String, |
| 136 | * InstantAppResolutionCallback)} |
| 137 | * and provided to the currently visible installer via |
| 138 | * {@link Intent#EXTRA_INSTANT_APP_TOKEN}. |
Hai Zhang | bfa4f90 | 2018-08-21 11:33:33 -0700 | [diff] [blame] | 139 | * @param callback The {@link InstantAppResolutionCallback} to provide results to. |
| 140 | * |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 141 | * @deprecated Should implement {@link #onGetInstantAppIntentFilter(InstantAppRequestInfo, |
| 142 | * InstantAppResolutionCallback)} |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 143 | */ |
Hai Zhang | bfa4f90 | 2018-08-21 11:33:33 -0700 | [diff] [blame] | 144 | @Deprecated |
Todd Kennedy | 63ff464 | 2019-03-25 11:20:01 -0700 | [diff] [blame] | 145 | public void onGetInstantAppIntentFilter(@NonNull Intent sanitizedIntent, |
| 146 | @Nullable int[] hostDigestPrefix, |
| 147 | @NonNull String token, @NonNull InstantAppResolutionCallback callback) { |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 148 | Log.e(TAG, "New onGetInstantAppIntentFilter is not overridden"); |
| 149 | // if not overridden, forward to old methods and filter out non-web intents |
Patrick Baumann | 0da8537 | 2018-02-02 16:07:35 -0800 | [diff] [blame] | 150 | if (sanitizedIntent.isWebIntent()) { |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 151 | onGetInstantAppIntentFilter(hostDigestPrefix, token, callback); |
| 152 | } else { |
| 153 | callback.onInstantAppResolveInfo(Collections.emptyList()); |
| 154 | } |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /** |
Hai Zhang | bfa4f90 | 2018-08-21 11:33:33 -0700 | [diff] [blame] | 158 | * Called to retrieve resolve info for instant applications immediately. The response will be |
| 159 | * ignored if not provided within a reasonable time. {@link InstantAppResolveInfo}s provided |
| 160 | * in response to this method may be partial to request a second phase of resolution which will |
| 161 | * result in a subsequent call to {@link #onGetInstantAppIntentFilter(Intent, int[], UserHandle, |
| 162 | * String, InstantAppResolutionCallback)} |
| 163 | * |
| 164 | * @param sanitizedIntent The sanitized {@link Intent} used for resolution. A sanitized Intent |
| 165 | * is an intent with potential PII removed from the original intent. |
| 166 | * Fields removed include extras and the host + path of the data, if |
| 167 | * defined. |
| 168 | * @param hostDigestPrefix The hash prefix of the instant app's domain. |
| 169 | * @param userHandle The user for which to resolve the instant app. |
| 170 | * @param token A unique identifier that will be provided in calls to {@link |
| 171 | * #onGetInstantAppIntentFilter(Intent, int[], UserHandle, String, |
| 172 | * InstantAppResolutionCallback)} and provided to the installer via {@link |
| 173 | * Intent#EXTRA_INSTANT_APP_TOKEN} to tie a single launch together. |
| 174 | * @param callback The {@link InstantAppResolutionCallback} to provide results to. |
| 175 | * |
| 176 | * @see InstantAppResolveInfo |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 177 | * |
| 178 | * @deprecated Should implement {@link #onGetInstantAppResolveInfo(InstantAppRequestInfo, |
| 179 | * InstantAppResolutionCallback |
Hai Zhang | bfa4f90 | 2018-08-21 11:33:33 -0700 | [diff] [blame] | 180 | */ |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 181 | @Deprecated |
Todd Kennedy | 63ff464 | 2019-03-25 11:20:01 -0700 | [diff] [blame] | 182 | public void onGetInstantAppResolveInfo(@NonNull Intent sanitizedIntent, |
| 183 | @Nullable int[] hostDigestPrefix, @NonNull UserHandle userHandle, |
| 184 | @NonNull String token, @NonNull InstantAppResolutionCallback callback) { |
Hai Zhang | bfa4f90 | 2018-08-21 11:33:33 -0700 | [diff] [blame] | 185 | // If not overridden, forward to the old method. |
| 186 | onGetInstantAppResolveInfo(sanitizedIntent, hostDigestPrefix, token, callback); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Called to retrieve intent filters for potentially matching instant applications. Unlike |
| 191 | * {@link #onGetInstantAppResolveInfo(Intent, int[], UserHandle, String, |
| 192 | * InstantAppResolutionCallback)}, the response may take as long as necessary to respond. All |
| 193 | * {@link InstantAppResolveInfo}s provided in response to this method must be completely |
| 194 | * populated. |
| 195 | * |
| 196 | * @param sanitizedIntent The sanitized {@link Intent} used for resolution. |
| 197 | * @param hostDigestPrefix The hash prefix of the instant app's domain or null if no host is |
| 198 | * defined. |
| 199 | * @param userHandle The user for which to resolve the instant app. |
| 200 | * @param token A unique identifier that was provided in {@link #onGetInstantAppResolveInfo( |
| 201 | * Intent, int[], UserHandle, String, InstantAppResolutionCallback)} and provided |
| 202 | * to the currently visible installer via {@link Intent#EXTRA_INSTANT_APP_TOKEN}. |
| 203 | * @param callback The {@link InstantAppResolutionCallback} to provide results to. |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 204 | * |
| 205 | * @deprecated Should implement {@link #onGetInstantAppIntentFilter(InstantAppRequestInfo, |
| 206 | * InstantAppResolutionCallback)} |
Hai Zhang | bfa4f90 | 2018-08-21 11:33:33 -0700 | [diff] [blame] | 207 | */ |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 208 | @Deprecated |
Todd Kennedy | 63ff464 | 2019-03-25 11:20:01 -0700 | [diff] [blame] | 209 | public void onGetInstantAppIntentFilter(@NonNull Intent sanitizedIntent, |
| 210 | @Nullable int[] hostDigestPrefix, @NonNull UserHandle userHandle, |
| 211 | @NonNull String token, @NonNull InstantAppResolutionCallback callback) { |
Hai Zhang | bfa4f90 | 2018-08-21 11:33:33 -0700 | [diff] [blame] | 212 | // If not overridden, forward to the old method. |
| 213 | onGetInstantAppIntentFilter(sanitizedIntent, hostDigestPrefix, token, callback); |
| 214 | } |
| 215 | |
| 216 | /** |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 217 | * Called to retrieve resolve info for instant applications immediately. The response will be |
| 218 | * ignored if not provided within a reasonable time. {@link InstantAppResolveInfo}s provided |
| 219 | * in response to this method may be partial to request a second phase of resolution which will |
| 220 | * result in a subsequent call to {@link #onGetInstantAppIntentFilter(InstantAppRequestInfo, |
| 221 | * InstantAppResolutionCallback)} |
| 222 | * |
| 223 | * @param request The parameters for this resolution request |
| 224 | * @param callback The {@link InstantAppResolutionCallback} to provide results to. |
| 225 | * |
| 226 | * @see InstantAppResolveInfo |
| 227 | */ |
| 228 | public void onGetInstantAppResolveInfo(@NonNull InstantAppRequestInfo request, |
| 229 | @NonNull InstantAppResolutionCallback callback) { |
| 230 | // If not overridden, forward to the old method. |
| 231 | onGetInstantAppResolveInfo(request.intent, request.hostDigestPrefix, request.userHandle, |
| 232 | request.token, callback); |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Called to retrieve intent filters for potentially matching instant applications. Unlike |
| 237 | * {@link #onGetInstantAppResolveInfo(InstantAppRequestInfo, InstantAppResolutionCallback)}, |
| 238 | * the response may take as long as necessary to respond. All {@link InstantAppResolveInfo}s |
| 239 | * provided in response to this method must be completely populated. |
| 240 | * |
| 241 | * @param request The parameters for this resolution request |
| 242 | * @param callback The {@link InstantAppResolutionCallback} to provide results to. |
| 243 | */ |
| 244 | public void onGetInstantAppIntentFilter(@NonNull InstantAppRequestInfo request, |
| 245 | @NonNull InstantAppResolutionCallback callback) { |
| 246 | // If not overridden, forward to the old method. |
| 247 | onGetInstantAppIntentFilter(request.intent, request.hostDigestPrefix, request.userHandle, |
| 248 | request.token, callback); |
| 249 | } |
| 250 | |
| 251 | /** |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 252 | * Returns a {@link Looper} to perform service operations on. |
| 253 | */ |
| 254 | Looper getLooper() { |
| 255 | return getBaseContext().getMainLooper(); |
| 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public final void attachBaseContext(Context base) { |
| 260 | super.attachBaseContext(base); |
| 261 | mHandler = new ServiceHandler(getLooper()); |
| 262 | } |
| 263 | |
| 264 | @Override |
| 265 | public final IBinder onBind(Intent intent) { |
| 266 | return new IInstantAppResolver.Stub() { |
| 267 | @Override |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 268 | public void getInstantAppResolveInfoList(InstantAppRequestInfo request, int sequence, |
| 269 | IRemoteCallback callback) { |
Patrick Baumann | 43c97a0 | 2018-01-31 20:09:03 +0000 | [diff] [blame] | 270 | if (DEBUG_INSTANT) { |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 271 | Slog.v(TAG, "[" + request.token + "] Phase1 called; posting"); |
Todd Kennedy | 46b4f2b | 2017-04-21 12:20:03 -0700 | [diff] [blame] | 272 | } |
Todd Kennedy | d3c5106 | 2017-03-17 16:03:29 -0700 | [diff] [blame] | 273 | final SomeArgs args = SomeArgs.obtain(); |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 274 | args.arg1 = request; |
| 275 | args.arg2 = callback; |
| 276 | mHandler.obtainMessage(ServiceHandler.MSG_GET_INSTANT_APP_RESOLVE_INFO, sequence, |
| 277 | 0, args).sendToTarget(); |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | @Override |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 281 | public void getInstantAppIntentFilterList(InstantAppRequestInfo request, |
| 282 | IRemoteCallback callback) { |
Patrick Baumann | 43c97a0 | 2018-01-31 20:09:03 +0000 | [diff] [blame] | 283 | if (DEBUG_INSTANT) { |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 284 | Slog.v(TAG, "[" + request.token + "] Phase2 called; posting"); |
Todd Kennedy | 46b4f2b | 2017-04-21 12:20:03 -0700 | [diff] [blame] | 285 | } |
Todd Kennedy | d3c5106 | 2017-03-17 16:03:29 -0700 | [diff] [blame] | 286 | final SomeArgs args = SomeArgs.obtain(); |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 287 | args.arg1 = request; |
| 288 | args.arg2 = callback; |
| 289 | mHandler.obtainMessage(ServiceHandler.MSG_GET_INSTANT_APP_INTENT_FILTER, args) |
| 290 | .sendToTarget(); |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 291 | } |
| 292 | }; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Callback to post results from instant app resolution. |
| 297 | */ |
| 298 | public static final class InstantAppResolutionCallback { |
| 299 | private final IRemoteCallback mCallback; |
| 300 | private final int mSequence; |
Winson | 191069d | 2019-12-20 15:35:29 -0800 | [diff] [blame] | 301 | |
| 302 | /** @hide **/ |
| 303 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 304 | public InstantAppResolutionCallback(int sequence, IRemoteCallback callback) { |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 305 | mCallback = callback; |
| 306 | mSequence = sequence; |
| 307 | } |
| 308 | |
| 309 | public void onInstantAppResolveInfo(List<InstantAppResolveInfo> resolveInfo) { |
| 310 | final Bundle data = new Bundle(); |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 311 | data.putParcelableList(EXTRA_RESOLVE_INFO, resolveInfo); |
Todd Kennedy | d3c5106 | 2017-03-17 16:03:29 -0700 | [diff] [blame] | 312 | data.putInt(EXTRA_SEQUENCE, mSequence); |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 313 | try { |
| 314 | mCallback.sendResult(data); |
| 315 | } catch (RemoteException e) { |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 320 | private final class ServiceHandler extends Handler { |
| 321 | public static final int MSG_GET_INSTANT_APP_RESOLVE_INFO = 1; |
| 322 | public static final int MSG_GET_INSTANT_APP_INTENT_FILTER = 2; |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 323 | public ServiceHandler(Looper looper) { |
| 324 | super(looper, null /*callback*/, true /*async*/); |
| 325 | } |
| 326 | |
| 327 | @Override |
| 328 | @SuppressWarnings("unchecked") |
| 329 | public void handleMessage(Message message) { |
| 330 | final int action = message.what; |
| 331 | switch (action) { |
| 332 | case MSG_GET_INSTANT_APP_RESOLVE_INFO: { |
Todd Kennedy | d3c5106 | 2017-03-17 16:03:29 -0700 | [diff] [blame] | 333 | final SomeArgs args = (SomeArgs) message.obj; |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 334 | final InstantAppRequestInfo request = (InstantAppRequestInfo) args.arg1; |
| 335 | final IRemoteCallback callback = (IRemoteCallback) args.arg2; |
| 336 | args.recycle(); |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 337 | final int sequence = message.arg1; |
Patrick Baumann | 43c97a0 | 2018-01-31 20:09:03 +0000 | [diff] [blame] | 338 | if (DEBUG_INSTANT) { |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 339 | Slog.d(TAG, "[" + request.token + "] Phase1 request;" |
| 340 | + " prefix: " + Arrays.toString(request.hostDigestPrefix) |
| 341 | + ", userId: " + request.userHandle.getIdentifier()); |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 342 | } |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 343 | onGetInstantAppResolveInfo(request, |
Todd Kennedy | d3c5106 | 2017-03-17 16:03:29 -0700 | [diff] [blame] | 344 | new InstantAppResolutionCallback(sequence, callback)); |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 345 | } break; |
| 346 | |
| 347 | case MSG_GET_INSTANT_APP_INTENT_FILTER: { |
Todd Kennedy | d3c5106 | 2017-03-17 16:03:29 -0700 | [diff] [blame] | 348 | final SomeArgs args = (SomeArgs) message.obj; |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 349 | final InstantAppRequestInfo request = (InstantAppRequestInfo) args.arg1; |
| 350 | final IRemoteCallback callback = (IRemoteCallback) args.arg2; |
| 351 | args.recycle(); |
Patrick Baumann | 43c97a0 | 2018-01-31 20:09:03 +0000 | [diff] [blame] | 352 | if (DEBUG_INSTANT) { |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 353 | Slog.d(TAG, "[" + request.token + "] Phase2 request;" |
| 354 | + " prefix: " + Arrays.toString(request.hostDigestPrefix) |
| 355 | + ", userId: " + request.userHandle.getIdentifier()); |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 356 | } |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 357 | onGetInstantAppIntentFilter(request, |
Todd Kennedy | d3c5106 | 2017-03-17 16:03:29 -0700 | [diff] [blame] | 358 | new InstantAppResolutionCallback(-1 /*sequence*/, callback)); |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 359 | } |
| 360 | break; |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 361 | |
| 362 | default: { |
| 363 | throw new IllegalArgumentException("Unknown message: " + action); |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | } |