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 
17 package android.content.pm;
18 
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21 import android.content.ComponentName;
22 
23 /**
24  * This class represents the parameters used to configure a DataLoader.
25  *
26  * {@see android.service.dataloader.DataLoaderService.DataLoader}
27  * @hide
28  */
29 @SystemApi
30 public class DataLoaderParams {
31     @NonNull
32     private final DataLoaderParamsParcel mData;
33 
34     /**
35      * Creates and populates set of DataLoader parameters for Streaming installation.
36      *
37      * @param componentName the component implementing a DataLoaderService that is responsible
38      *                      for providing data blocks while streaming.
39      * @param arguments free form installation arguments.
40      */
forStreaming(@onNull ComponentName componentName, @NonNull String arguments)41     public static final @NonNull DataLoaderParams forStreaming(@NonNull ComponentName componentName,
42             @NonNull String arguments) {
43         return new DataLoaderParams(DataLoaderType.STREAMING, componentName, arguments);
44     }
45 
46     /**
47      * Creates and populates set of Data Loader parameters for Incremental installation.
48      *
49      * @param componentName DataLoaderService component supporting Incremental installation.
50      * @param arguments free form installation arguments
51      *
52      * @hide
53      */
54     @SystemApi
forIncremental( @onNull ComponentName componentName, @NonNull String arguments)55     public static final @NonNull DataLoaderParams forIncremental(
56             @NonNull ComponentName componentName, @NonNull String arguments) {
57         return new DataLoaderParams(DataLoaderType.INCREMENTAL, componentName, arguments);
58     }
59 
60     /** @hide */
DataLoaderParams(@onNull @ataLoaderType int type, @NonNull ComponentName componentName, @NonNull String arguments)61     public DataLoaderParams(@NonNull @DataLoaderType int type, @NonNull ComponentName componentName,
62             @NonNull String arguments) {
63         DataLoaderParamsParcel data = new DataLoaderParamsParcel();
64         data.type = type;
65         data.packageName = componentName.getPackageName();
66         data.className = componentName.getClassName();
67         data.arguments = arguments;
68         mData = data;
69     }
70 
71     /** @hide */
DataLoaderParams(@onNull DataLoaderParamsParcel data)72     DataLoaderParams(@NonNull DataLoaderParamsParcel data) {
73         mData = data;
74     }
75 
76     /** @hide */
getData()77     public final @NonNull DataLoaderParamsParcel getData() {
78         return mData;
79     }
80 
81     /**
82      * @return data loader type
83      */
getType()84     public final @NonNull @DataLoaderType int getType() {
85         return mData.type;
86     }
87 
88     /**
89      * @return data loader's component name
90      */
getComponentName()91     public final @NonNull ComponentName getComponentName() {
92         return new ComponentName(mData.packageName, mData.className);
93     }
94 
95     /**
96      * @return data loader's arguments
97      */
getArguments()98     public final @NonNull String getArguments() {
99         return mData.arguments;
100     }
101 }
102