Loading src/com/android/server/telecom/AppLabelProxy.java 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.telecom; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.telecom.Log; /** * Abstracts away dependency on the {@link PackageManager} required to fetch the label for an * app. */ public interface AppLabelProxy { String LOG_TAG = AppLabelProxy.class.getSimpleName(); class Util { /** * Default impl of getAppLabel. * @param pm PackageManager instance * @param packageName package name to look up. */ public static CharSequence getAppLabel(PackageManager pm, String packageName) { try { ApplicationInfo info = pm.getApplicationInfo(packageName, 0); CharSequence result = pm.getApplicationLabel(info); Log.i(LOG_TAG, "package %s: name is %s", packageName, result); return result; } catch (PackageManager.NameNotFoundException nnfe) { Log.w(LOG_TAG, "Could not determine app label. Package name is %s", packageName); } return null; } } CharSequence getAppLabel(String packageName); } src/com/android/server/telecom/CallScreeningServiceHelper.java +0 −9 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Handler; import android.os.IBinder; Loading @@ -44,14 +43,6 @@ import java.util.concurrent.CompletableFuture; public class CallScreeningServiceHelper { private static final String TAG = CallScreeningServiceHelper.class.getSimpleName(); /** * Abstracts away dependency on the {@link PackageManager} required to fetch the label for an * app. */ public interface AppLabelProxy { CharSequence getAppLabel(String packageName); } /** * Implementation of {@link CallScreeningService} adapter AIDL; provides a means for responses * from the call screening service to be handled. Loading src/com/android/server/telecom/CallsManager.java +7 −34 Original line number Diff line number Diff line Loading @@ -681,21 +681,8 @@ public class CallsManager extends Call.ListenerBase String carrierPackageName = getCarrierPackageName(); String defaultDialerPackageName = TelecomManager.from(mContext).getDefaultDialerPackage(); String userChosenPackageName = getRoleManagerAdapter().getDefaultCallScreeningApp(); CallScreeningServiceHelper.AppLabelProxy appLabelProxy = new CallScreeningServiceHelper.AppLabelProxy() { @Override public CharSequence getAppLabel(String packageName) { PackageManager pm = mContext.getPackageManager(); try { ApplicationInfo info = pm.getApplicationInfo(packageName, 0); return pm.getApplicationLabel(info); } catch (PackageManager.NameNotFoundException nnfe) { Log.w(this, "Could not determine package name."); } return null; } }; AppLabelProxy appLabelProxy = packageName -> AppLabelProxy.Util.getAppLabel( mContext.getPackageManager(), packageName); ParcelableCallUtils.Converter converter = new ParcelableCallUtils.Converter(); IncomingCallFilterGraph graph = new IncomingCallFilterGraph(incomingCall, Loading Loading @@ -1808,19 +1795,10 @@ public class CallsManager extends Call.ListenerBase new ParcelableCallUtils.Converter(), mCurrentUserHandle, theCall, new CallScreeningServiceHelper.AppLabelProxy() { new AppLabelProxy() { @Override public CharSequence getAppLabel(String packageName) { PackageManager pm = mContext.getPackageManager(); try { ApplicationInfo info = pm.getApplicationInfo( packageName, 0); return pm.getApplicationLabel(info); } catch (PackageManager.NameNotFoundException nnfe) { Log.w(this, "Could not determine package name."); } return null; return Util.getAppLabel(mContext.getPackageManager(), packageName); } }).process(); future.thenApply( v -> { Loading Loading @@ -2333,14 +2311,9 @@ public class CallsManager extends Call.ListenerBase return; } CharSequence requestingAppName; PackageManager pm = mContext.getPackageManager(); try { ApplicationInfo info = pm.getApplicationInfo( requestingPackageName, 0); requestingAppName = pm.getApplicationLabel(info); } catch (PackageManager.NameNotFoundException nnfe) { Log.w(this, "Could not determine package name."); CharSequence requestingAppName = AppLabelProxy.Util.getAppLabel( mContext.getPackageManager(), requestingPackageName); if (requestingAppName == null) { requestingAppName = requestingPackageName; } Loading src/com/android/server/telecom/PhoneAccountRegistrar.java +0 −8 Original line number Diff line number Diff line Loading @@ -130,14 +130,6 @@ public class PhoneAccountRegistrar { PhoneAccount phoneAccount) {} } /** * Abstracts away dependency on the {@link PackageManager} required to fetch the label for an * app. */ public interface AppLabelProxy { CharSequence getAppLabel(String packageName); } public static final String FILE_NAME = "phone-account-registrar-state.xml"; @VisibleForTesting public static final int EXPECTED_STATE_VERSION = 9; Loading src/com/android/server/telecom/TelecomSystem.java +3 −14 Original line number Diff line number Diff line Loading @@ -218,20 +218,9 @@ public class TelecomSystem { Log.startSession("TS.init"); mPhoneAccountRegistrar = new PhoneAccountRegistrar(mContext, defaultDialerCache, new PhoneAccountRegistrar.AppLabelProxy() { @Override public CharSequence getAppLabel(String packageName) { PackageManager pm = mContext.getPackageManager(); try { ApplicationInfo info = pm.getApplicationInfo(packageName, 0); return pm.getApplicationLabel(info); } catch (PackageManager.NameNotFoundException nnfe) { Log.w(this, "Could not determine package name."); } packageName -> AppLabelProxy.Util.getAppLabel( mContext.getPackageManager(), packageName)); return null; } }); mContactsAsyncHelper = contactsAsyncHelperFactory.create( new ContactsAsyncHelper.ContentResolverAdapter() { @Override Loading Loading
src/com/android/server/telecom/AppLabelProxy.java 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.telecom; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.telecom.Log; /** * Abstracts away dependency on the {@link PackageManager} required to fetch the label for an * app. */ public interface AppLabelProxy { String LOG_TAG = AppLabelProxy.class.getSimpleName(); class Util { /** * Default impl of getAppLabel. * @param pm PackageManager instance * @param packageName package name to look up. */ public static CharSequence getAppLabel(PackageManager pm, String packageName) { try { ApplicationInfo info = pm.getApplicationInfo(packageName, 0); CharSequence result = pm.getApplicationLabel(info); Log.i(LOG_TAG, "package %s: name is %s", packageName, result); return result; } catch (PackageManager.NameNotFoundException nnfe) { Log.w(LOG_TAG, "Could not determine app label. Package name is %s", packageName); } return null; } } CharSequence getAppLabel(String packageName); }
src/com/android/server/telecom/CallScreeningServiceHelper.java +0 −9 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Handler; import android.os.IBinder; Loading @@ -44,14 +43,6 @@ import java.util.concurrent.CompletableFuture; public class CallScreeningServiceHelper { private static final String TAG = CallScreeningServiceHelper.class.getSimpleName(); /** * Abstracts away dependency on the {@link PackageManager} required to fetch the label for an * app. */ public interface AppLabelProxy { CharSequence getAppLabel(String packageName); } /** * Implementation of {@link CallScreeningService} adapter AIDL; provides a means for responses * from the call screening service to be handled. Loading
src/com/android/server/telecom/CallsManager.java +7 −34 Original line number Diff line number Diff line Loading @@ -681,21 +681,8 @@ public class CallsManager extends Call.ListenerBase String carrierPackageName = getCarrierPackageName(); String defaultDialerPackageName = TelecomManager.from(mContext).getDefaultDialerPackage(); String userChosenPackageName = getRoleManagerAdapter().getDefaultCallScreeningApp(); CallScreeningServiceHelper.AppLabelProxy appLabelProxy = new CallScreeningServiceHelper.AppLabelProxy() { @Override public CharSequence getAppLabel(String packageName) { PackageManager pm = mContext.getPackageManager(); try { ApplicationInfo info = pm.getApplicationInfo(packageName, 0); return pm.getApplicationLabel(info); } catch (PackageManager.NameNotFoundException nnfe) { Log.w(this, "Could not determine package name."); } return null; } }; AppLabelProxy appLabelProxy = packageName -> AppLabelProxy.Util.getAppLabel( mContext.getPackageManager(), packageName); ParcelableCallUtils.Converter converter = new ParcelableCallUtils.Converter(); IncomingCallFilterGraph graph = new IncomingCallFilterGraph(incomingCall, Loading Loading @@ -1808,19 +1795,10 @@ public class CallsManager extends Call.ListenerBase new ParcelableCallUtils.Converter(), mCurrentUserHandle, theCall, new CallScreeningServiceHelper.AppLabelProxy() { new AppLabelProxy() { @Override public CharSequence getAppLabel(String packageName) { PackageManager pm = mContext.getPackageManager(); try { ApplicationInfo info = pm.getApplicationInfo( packageName, 0); return pm.getApplicationLabel(info); } catch (PackageManager.NameNotFoundException nnfe) { Log.w(this, "Could not determine package name."); } return null; return Util.getAppLabel(mContext.getPackageManager(), packageName); } }).process(); future.thenApply( v -> { Loading Loading @@ -2333,14 +2311,9 @@ public class CallsManager extends Call.ListenerBase return; } CharSequence requestingAppName; PackageManager pm = mContext.getPackageManager(); try { ApplicationInfo info = pm.getApplicationInfo( requestingPackageName, 0); requestingAppName = pm.getApplicationLabel(info); } catch (PackageManager.NameNotFoundException nnfe) { Log.w(this, "Could not determine package name."); CharSequence requestingAppName = AppLabelProxy.Util.getAppLabel( mContext.getPackageManager(), requestingPackageName); if (requestingAppName == null) { requestingAppName = requestingPackageName; } Loading
src/com/android/server/telecom/PhoneAccountRegistrar.java +0 −8 Original line number Diff line number Diff line Loading @@ -130,14 +130,6 @@ public class PhoneAccountRegistrar { PhoneAccount phoneAccount) {} } /** * Abstracts away dependency on the {@link PackageManager} required to fetch the label for an * app. */ public interface AppLabelProxy { CharSequence getAppLabel(String packageName); } public static final String FILE_NAME = "phone-account-registrar-state.xml"; @VisibleForTesting public static final int EXPECTED_STATE_VERSION = 9; Loading
src/com/android/server/telecom/TelecomSystem.java +3 −14 Original line number Diff line number Diff line Loading @@ -218,20 +218,9 @@ public class TelecomSystem { Log.startSession("TS.init"); mPhoneAccountRegistrar = new PhoneAccountRegistrar(mContext, defaultDialerCache, new PhoneAccountRegistrar.AppLabelProxy() { @Override public CharSequence getAppLabel(String packageName) { PackageManager pm = mContext.getPackageManager(); try { ApplicationInfo info = pm.getApplicationInfo(packageName, 0); return pm.getApplicationLabel(info); } catch (PackageManager.NameNotFoundException nnfe) { Log.w(this, "Could not determine package name."); } packageName -> AppLabelProxy.Util.getAppLabel( mContext.getPackageManager(), packageName)); return null; } }); mContactsAsyncHelper = contactsAsyncHelperFactory.create( new ContactsAsyncHelper.ContentResolverAdapter() { @Override Loading