blob: 99c0907f1844d6891bdab95fdf3218dd7cb5b1af [file] [log] [blame]
Songchun Fand1b41d42019-11-12 17:09:53 -08001/*
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 Buynytskyyea14d192019-12-13 15:42:18 -080017package android.content.pm;
Songchun Fand1b41d42019-11-12 17:09:53 -080018
19import android.annotation.NonNull;
20import android.annotation.Nullable;
Songchun Fan4062c3c2019-12-16 16:43:41 -080021import android.annotation.SystemApi;
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -080022import android.content.ComponentName;
Songchun Fand1b41d42019-11-12 17:09:53 -080023import android.os.ParcelFileDescriptor;
24
Songchun Fand1b41d42019-11-12 17:09:53 -080025import java.util.Map;
Songchun Fand1b41d42019-11-12 17:09:53 -080026
27/**
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -080028 * This class represents the parameters used to configure a Data Loader.
Songchun Fan4062c3c2019-12-16 16:43:41 -080029 *
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 Fand1b41d42019-11-12 17:09:53 -080032 * @hide
33 */
Songchun Fan4062c3c2019-12-16 16:43:41 -080034@SystemApi
Alex Buynytskyyea14d192019-12-13 15:42:18 -080035public class DataLoaderParams {
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -080036 @NonNull
37 private final DataLoaderParamsParcel mData;
Songchun Fand1b41d42019-11-12 17:09:53 -080038
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -080039 /**
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 Buynytskyy1ecfcec2019-12-17 12:10:41 -080055 */
56 public static final @NonNull DataLoaderParams forIncremental(
Songchun Fan82fddef2020-03-06 13:30:29 -080057 @NonNull ComponentName componentName, @NonNull String arguments) {
58 return new DataLoaderParams(DataLoaderType.INCREMENTAL, componentName, arguments, null);
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -080059 }
60
61 /** @hide */
62 public DataLoaderParams(@NonNull @DataLoaderType int type, @NonNull ComponentName componentName,
63 @NonNull String arguments, @Nullable Map<String, ParcelFileDescriptor> namedFds) {
Alex Buynytskyyea14d192019-12-13 15:42:18 -080064 DataLoaderParamsParcel data = new DataLoaderParamsParcel();
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -080065 data.type = type;
66 data.packageName = componentName.getPackageName();
67 data.className = componentName.getClassName();
68 data.arguments = arguments;
Songchun Fand1b41d42019-11-12 17:09:53 -080069 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 Buynytskyy1ecfcec2019-12-17 12:10:41 -080084 /** @hide */
85 DataLoaderParams(@NonNull DataLoaderParamsParcel data) {
Songchun Fand1b41d42019-11-12 17:09:53 -080086 mData = data;
87 }
88
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -080089 /** @hide */
Alex Buynytskyyea14d192019-12-13 15:42:18 -080090 public final @NonNull DataLoaderParamsParcel getData() {
Songchun Fand1b41d42019-11-12 17:09:53 -080091 return mData;
92 }
93
94 /**
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -080095 * @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 Fand1b41d42019-11-12 17:09:53 -0800114}