Songchun Fan | 6dd47b5 | 2019-11-29 15:20:18 -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 | |
| 17 | package android.content.pm; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Songchun Fan | 6dd47b5 | 2019-11-29 15:20:18 -0800 | [diff] [blame] | 21 | import 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 | */ |
| 30 | public 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 Fan | 6381d61 | 2020-02-26 17:59:41 -0800 | [diff] [blame] | 42 | * @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 Fan | 6dd47b5 | 2019-11-29 15:20:18 -0800 | [diff] [blame] | 45 | * @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 Fan | 6381d61 | 2020-02-26 17:59:41 -0800 | [diff] [blame] | 51 | public boolean initializeDataLoader(int dataLoaderId, @NonNull DataLoaderParamsParcel params, |
| 52 | @NonNull FileSystemControlParcel control, @NonNull IDataLoaderStatusListener listener) { |
Songchun Fan | 6dd47b5 | 2019-11-29 15:20:18 -0800 | [diff] [blame] | 53 | try { |
Songchun Fan | 6381d61 | 2020-02-26 17:59:41 -0800 | [diff] [blame] | 54 | return mService.initializeDataLoader(dataLoaderId, params, control, listener); |
Songchun Fan | 6dd47b5 | 2019-11-29 15:20:18 -0800 | [diff] [blame] | 55 | } 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 | } |