blob: 26880384e502e570d561edb613d5e4e992ae39ae [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;
21import android.os.Bundle;
22import android.os.RemoteException;
23
24/**
25 * Data loader manager takes care of data loaders of different packages. It provides methods to
26 * initialize a data loader binder service (binding and creating it), to return a binder of the data
27 * loader binder service and to destroy a data loader binder service.
28 * @see com.android.server.pm.DataLoaderManagerService
29 * @hide
30 */
31public class DataLoaderManager {
32 private static final String TAG = "DataLoaderManager";
33 private final IDataLoaderManager mService;
34
35 public DataLoaderManager(IDataLoaderManager service) {
36 mService = service;
37 }
38
39 /**
40 * Finds a data loader binder service and binds to it. This requires PackageManager.
41 *
42 * @param dataLoaderId ID for the new data loader binder service.
43 * @param params Bundle that contains parameters to configure the data loader service.
44 * Must contain:
45 * key: "packageName", value: String, package name of data loader service
46 * package;
47 * key: "extras", value: Bundle, client-specific data structures
48 *
49 * @param listener Callback for the data loader service to report status back to the
50 * caller.
51 * @return false if 1) target ID collides with a data loader that is already bound to data
52 * loader manager; 2) package name is not specified; 3) fails to find data loader package;
53 * or 4) fails to bind to the specified data loader service, otherwise return true.
54 */
55 public boolean initializeDataLoader(int dataLoaderId, @NonNull Bundle params,
56 @NonNull IDataLoaderStatusListener listener) {
57 try {
58 return mService.initializeDataLoader(dataLoaderId, params, listener);
59 } catch (RemoteException e) {
60 throw e.rethrowFromSystemServer();
61 }
62 }
63
64 /**
65 * Returns a binder interface of the data loader binder service, given its ID.
66 */
67 @Nullable
68 public IDataLoader getDataLoader(int dataLoaderId) {
69 try {
70 return mService.getDataLoader(dataLoaderId);
71 } catch (RemoteException e) {
72 throw e.rethrowFromSystemServer();
73 }
74 }
75
76 /**
77 * Destroys the data loader binder service and removes it from data loader manager service.
78 */
79 @Nullable
80 public void destroyDataLoader(int dataLoaderId) {
81 try {
82 mService.destroyDataLoader(dataLoaderId);
83 } catch (RemoteException e) {
84 throw e.rethrowFromSystemServer();
85 }
86 }
87}