1af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch/* 2af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * Copyright (C) 2016 The Android Open Source Project 3af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * 4af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * Licensed under the Apache License, Version 2.0 (the "License"); 5af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * you may not use this file except in compliance with the License. 6af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * You may obtain a copy of the License at 7af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * 8af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * http://www.apache.org/licenses/LICENSE-2.0 9af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * 10af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * Unless required by applicable law or agreed to in writing, software 11af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * distributed under the License is distributed on an "AS IS" BASIS, 12af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * See the License for the specific language governing permissions and 14af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch * limitations under the License. 15af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch */ 16af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch 17af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitschpackage com.android.systemui.qs.external; 18af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch 19af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitschimport android.annotation.UserIdInt; 20af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitschimport android.app.AppGlobals; 21af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitschimport android.content.ComponentName; 22af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitschimport android.content.Context; 23af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitschimport android.content.pm.IPackageManager; 24af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitschimport android.content.pm.PackageInfo; 25af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitschimport android.content.pm.PackageManager; 26af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitschimport android.content.pm.ServiceInfo; 27af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitschimport android.os.RemoteException; 28af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch 29af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch// Adapter that wraps calls to PackageManager or IPackageManager for {@link TileLifecycleManager}. 30af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch// TODO: This is very much an intermediate step to allow for PackageManager mocking and should be 31af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch// abstracted into something more useful for other tests in systemui. 32af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitschpublic class PackageManagerAdapter { 33af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch private static final String TAG = "PackageManagerAdapter"; 34af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch 35af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch private PackageManager mPackageManager; 36af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch private IPackageManager mIPackageManager; 37af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch 38af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch // Uses the PackageManager for the provided context. 39af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch // When necessary, uses the IPackagemanger in AppGlobals. 40af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch public PackageManagerAdapter(Context context) { 41af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch mPackageManager = context.getPackageManager(); 42af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch mIPackageManager = AppGlobals.getPackageManager(); 43af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch } 44af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch 45af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch public ServiceInfo getServiceInfo(ComponentName className, int flags, int userId) 46af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch throws RemoteException { 47af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch return mIPackageManager.getServiceInfo(className, flags, userId); 48af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch } 49af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch 50af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch public ServiceInfo getServiceInfo(ComponentName component, int flags) 51af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch throws PackageManager.NameNotFoundException { 52af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch return mPackageManager.getServiceInfo(component, flags); 53af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch } 54af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch 55af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch public PackageInfo getPackageInfoAsUser(String packageName, int flags, @UserIdInt int userId) 56af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch throws PackageManager.NameNotFoundException { 57af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch return mPackageManager.getPackageInfoAsUser(packageName, flags, userId); 58af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch } 59af2076afb32d7a49c2a6f8afba8e28e88677041fGeoffrey Pitsch} 60