1 /* 2 * Copyright (C) 2020 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 com.android.server.telecom; 18 19 import android.content.pm.ApplicationInfo; 20 import android.content.pm.PackageManager; 21 import android.telecom.Log; 22 23 /** 24 * Abstracts away dependency on the {@link PackageManager} required to fetch the label for an 25 * app. 26 */ 27 public interface AppLabelProxy { 28 String LOG_TAG = AppLabelProxy.class.getSimpleName(); 29 30 class Util { 31 /** 32 * Default impl of getAppLabel. 33 * @param pm PackageManager instance 34 * @param packageName package name to look up. 35 */ getAppLabel(PackageManager pm, String packageName)36 public static CharSequence getAppLabel(PackageManager pm, String packageName) { 37 try { 38 ApplicationInfo info = pm.getApplicationInfo(packageName, 0); 39 CharSequence result = pm.getApplicationLabel(info); 40 Log.i(LOG_TAG, "package %s: name is %s", packageName, result); 41 return result; 42 } catch (PackageManager.NameNotFoundException nnfe) { 43 Log.w(LOG_TAG, "Could not determine app label. Package name is %s", packageName); 44 } 45 46 return null; 47 } 48 } 49 getAppLabel(String packageName)50 CharSequence getAppLabel(String packageName); 51 } 52