1/*
2 * Copyright (C) 2016 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 com.android.systemui.qs.external;
18
19import android.annotation.UserIdInt;
20import android.app.AppGlobals;
21import android.content.ComponentName;
22import android.content.Context;
23import android.content.pm.IPackageManager;
24import android.content.pm.PackageInfo;
25import android.content.pm.PackageManager;
26import android.content.pm.ServiceInfo;
27import android.os.RemoteException;
28
29// Adapter that wraps calls to PackageManager or IPackageManager for {@link TileLifecycleManager}.
30// TODO: This is very much an intermediate step to allow for PackageManager mocking and should be
31// abstracted into something more useful for other tests in systemui.
32public class PackageManagerAdapter {
33    private static final String TAG = "PackageManagerAdapter";
34
35    private PackageManager mPackageManager;
36    private IPackageManager mIPackageManager;
37
38    // Uses the PackageManager for the provided context.
39    // When necessary, uses the IPackagemanger in AppGlobals.
40    public PackageManagerAdapter(Context context) {
41        mPackageManager = context.getPackageManager();
42        mIPackageManager = AppGlobals.getPackageManager();
43    }
44
45    public ServiceInfo getServiceInfo(ComponentName className, int flags, int userId)
46            throws RemoteException {
47        return mIPackageManager.getServiceInfo(className, flags, userId);
48    }
49
50    public ServiceInfo getServiceInfo(ComponentName component, int flags)
51            throws PackageManager.NameNotFoundException {
52        return mPackageManager.getServiceInfo(component, flags);
53    }
54
55    public PackageInfo getPackageInfoAsUser(String packageName, int flags, @UserIdInt int userId)
56            throws PackageManager.NameNotFoundException {
57        return mPackageManager.getPackageInfoAsUser(packageName, flags, userId);
58    }
59}
60