blob: 4a6193888685c8dcd65573ee2cebb83019aa93bf [file] [log] [blame]
Songchun Fan6dd47b52019-11-29 15:20:18 -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
17package android.content.pm;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
Songchun Fan6dd47b52019-11-29 15:20:18 -080021import android.os.RemoteException;
22
23/**
24 * Data loader manager takes care of data loaders of different packages. It provides methods to
25 * initialize a data loader binder service (binding and creating it), to return a binder of the data
26 * loader binder service and to destroy a data loader binder service.
27 * @see com.android.server.pm.DataLoaderManagerService
28 * @hide
29 */
30public class DataLoaderManager {
31 private static final String TAG = "DataLoaderManager";
32 private final IDataLoaderManager mService;
33
34 public DataLoaderManager(IDataLoaderManager service) {
35 mService = service;
36 }
37
38 /**
39 * Finds a data loader binder service and binds to it. This requires PackageManager.
40 *
41 * @param dataLoaderId ID for the new data loader binder service.
Songchun Fan6381d612020-02-26 17:59:41 -080042 * @param params DataLoaderParamsParcel object that contains data loader params, including
43 * its package name, class name, and additional parameters.
44 * @param control FileSystemControlParcel that contains filesystem control handlers.
Songchun Fan6dd47b52019-11-29 15:20:18 -080045 * @param listener Callback for the data loader service to report status back to the
46 * caller.
47 * @return false if 1) target ID collides with a data loader that is already bound to data
48 * loader manager; 2) package name is not specified; 3) fails to find data loader package;
49 * or 4) fails to bind to the specified data loader service, otherwise return true.
50 */
Songchun Fan6381d612020-02-26 17:59:41 -080051 public boolean initializeDataLoader(int dataLoaderId, @NonNull DataLoaderParamsParcel params,
52 @NonNull FileSystemControlParcel control, @NonNull IDataLoaderStatusListener listener) {
Songchun Fan6dd47b52019-11-29 15:20:18 -080053 try {
Songchun Fan6381d612020-02-26 17:59:41 -080054 return mService.initializeDataLoader(dataLoaderId, params, control, listener);
Songchun Fan6dd47b52019-11-29 15:20:18 -080055 } catch (RemoteException e) {
56 throw e.rethrowFromSystemServer();
57 }
58 }
59
60 /**
61 * Returns a binder interface of the data loader binder service, given its ID.
62 */
63 @Nullable
64 public IDataLoader getDataLoader(int dataLoaderId) {
65 try {
66 return mService.getDataLoader(dataLoaderId);
67 } catch (RemoteException e) {
68 throw e.rethrowFromSystemServer();
69 }
70 }
71
72 /**
73 * Destroys the data loader binder service and removes it from data loader manager service.
74 */
75 @Nullable
76 public void destroyDataLoader(int dataLoaderId) {
77 try {
78 mService.destroyDataLoader(dataLoaderId);
79 } catch (RemoteException e) {
80 throw e.rethrowFromSystemServer();
81 }
82 }
83}