Songchun Fan | d1b41d4 | 2019-11-12 17:09:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
Alex Buynytskyy | ea14d19 | 2019-12-13 15:42:18 -0800 | [diff] [blame] | 17 | package android.content.pm; |
Songchun Fan | d1b41d4 | 2019-11-12 17:09:53 -0800 | [diff] [blame] | 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Songchun Fan | 4062c3c | 2019-12-16 16:43:41 -0800 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 22 | import android.content.ComponentName; |
Songchun Fan | d1b41d4 | 2019-11-12 17:09:53 -0800 | [diff] [blame] | 23 | import android.os.ParcelFileDescriptor; |
| 24 | |
Songchun Fan | d1b41d4 | 2019-11-12 17:09:53 -0800 | [diff] [blame] | 25 | import java.util.Map; |
Songchun Fan | d1b41d4 | 2019-11-12 17:09:53 -0800 | [diff] [blame] | 26 | |
| 27 | /** |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 28 | * This class represents the parameters used to configure a Data Loader. |
Songchun Fan | 4062c3c | 2019-12-16 16:43:41 -0800 | [diff] [blame] | 29 | * |
| 30 | * WARNING: This is a system API to aid internal development. |
| 31 | * Use at your own risk. It will change or be removed without warning. |
Songchun Fan | d1b41d4 | 2019-11-12 17:09:53 -0800 | [diff] [blame] | 32 | * @hide |
| 33 | */ |
Songchun Fan | 4062c3c | 2019-12-16 16:43:41 -0800 | [diff] [blame] | 34 | @SystemApi |
Alex Buynytskyy | ea14d19 | 2019-12-13 15:42:18 -0800 | [diff] [blame] | 35 | public class DataLoaderParams { |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 36 | @NonNull |
| 37 | private final DataLoaderParamsParcel mData; |
Songchun Fan | d1b41d4 | 2019-11-12 17:09:53 -0800 | [diff] [blame] | 38 | |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 39 | /** |
| 40 | * Creates and populates set of Data Loader parameters for Streaming installation. |
| 41 | * |
| 42 | * @param componentName Data Loader component supporting Streaming installation. |
| 43 | * @param arguments free form installation arguments |
| 44 | */ |
| 45 | public static final @NonNull DataLoaderParams forStreaming(@NonNull ComponentName componentName, |
| 46 | @NonNull String arguments) { |
| 47 | return new DataLoaderParams(DataLoaderType.STREAMING, componentName, arguments, null); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Creates and populates set of Data Loader parameters for Incremental installation. |
| 52 | * |
| 53 | * @param componentName Data Loader component supporting Incremental installation. |
| 54 | * @param arguments free form installation arguments |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 55 | */ |
| 56 | public static final @NonNull DataLoaderParams forIncremental( |
Songchun Fan | 82fddef | 2020-03-06 13:30:29 -0800 | [diff] [blame^] | 57 | @NonNull ComponentName componentName, @NonNull String arguments) { |
| 58 | return new DataLoaderParams(DataLoaderType.INCREMENTAL, componentName, arguments, null); |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** @hide */ |
| 62 | public DataLoaderParams(@NonNull @DataLoaderType int type, @NonNull ComponentName componentName, |
| 63 | @NonNull String arguments, @Nullable Map<String, ParcelFileDescriptor> namedFds) { |
Alex Buynytskyy | ea14d19 | 2019-12-13 15:42:18 -0800 | [diff] [blame] | 64 | DataLoaderParamsParcel data = new DataLoaderParamsParcel(); |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 65 | data.type = type; |
| 66 | data.packageName = componentName.getPackageName(); |
| 67 | data.className = componentName.getClassName(); |
| 68 | data.arguments = arguments; |
Songchun Fan | d1b41d4 | 2019-11-12 17:09:53 -0800 | [diff] [blame] | 69 | if (namedFds == null || namedFds.isEmpty()) { |
| 70 | data.dynamicArgs = new NamedParcelFileDescriptor[0]; |
| 71 | } else { |
| 72 | data.dynamicArgs = new NamedParcelFileDescriptor[namedFds.size()]; |
| 73 | int i = 0; |
| 74 | for (Map.Entry<String, ParcelFileDescriptor> namedFd : namedFds.entrySet()) { |
| 75 | data.dynamicArgs[i] = new NamedParcelFileDescriptor(); |
| 76 | data.dynamicArgs[i].name = namedFd.getKey(); |
| 77 | data.dynamicArgs[i].fd = namedFd.getValue(); |
| 78 | i += 1; |
| 79 | } |
| 80 | } |
| 81 | mData = data; |
| 82 | } |
| 83 | |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 84 | /** @hide */ |
| 85 | DataLoaderParams(@NonNull DataLoaderParamsParcel data) { |
Songchun Fan | d1b41d4 | 2019-11-12 17:09:53 -0800 | [diff] [blame] | 86 | mData = data; |
| 87 | } |
| 88 | |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 89 | /** @hide */ |
Alex Buynytskyy | ea14d19 | 2019-12-13 15:42:18 -0800 | [diff] [blame] | 90 | public final @NonNull DataLoaderParamsParcel getData() { |
Songchun Fan | d1b41d4 | 2019-11-12 17:09:53 -0800 | [diff] [blame] | 91 | return mData; |
| 92 | } |
| 93 | |
| 94 | /** |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 95 | * @return data loader type |
| 96 | */ |
| 97 | public final @NonNull @DataLoaderType int getType() { |
| 98 | return mData.type; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @return data loader's component name |
| 103 | */ |
| 104 | public final @NonNull ComponentName getComponentName() { |
| 105 | return new ComponentName(mData.packageName, mData.className); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @return data loader's arguments |
| 110 | */ |
| 111 | public final @NonNull String getArguments() { |
| 112 | return mData.arguments; |
| 113 | } |
Songchun Fan | d1b41d4 | 2019-11-12 17:09:53 -0800 | [diff] [blame] | 114 | } |