Merge "Use TelephonyManagerShim factory method"

This commit is contained in:
Treehugger Robot
2022-04-12 07:42:21 +00:00
committed by Gerrit Code Review

View File

@@ -29,7 +29,6 @@ import android.content.pm.PackageManager;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.NetworkSpecifier; import android.net.NetworkSpecifier;
import android.net.TelephonyNetworkSpecifier; import android.net.TelephonyNetworkSpecifier;
import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.os.Process; import android.os.Process;
@@ -94,11 +93,7 @@ public class CarrierPrivilegeAuthenticator extends BroadcastReceiver {
@NonNull final TelephonyManager t) { @NonNull final TelephonyManager t) {
mContext = c; mContext = c;
mTelephonyManager = t; mTelephonyManager = t;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S) { mTelephonyManagerShim = TelephonyManagerShimImpl.newInstance(mTelephonyManager);
mTelephonyManagerShim = new TelephonyManagerShimImpl(mTelephonyManager);
} else {
mTelephonyManagerShim = null;
}
mThread = new HandlerThread(TAG); mThread = new HandlerThread(TAG);
mThread.start(); mThread.start();
mHandler = new Handler(mThread.getLooper()) {}; mHandler = new Handler(mThread.getLooper()) {};
@@ -192,36 +187,30 @@ public class CarrierPrivilegeAuthenticator extends BroadcastReceiver {
private void addCarrierPrivilegesListener(int logicalSlotIndex, Executor executor, private void addCarrierPrivilegesListener(int logicalSlotIndex, Executor executor,
CarrierPrivilegesListenerShim listener) { CarrierPrivilegesListenerShim listener) {
if (mTelephonyManagerShim == null) {
return;
}
try { try {
mTelephonyManagerShim.addCarrierPrivilegesListener( mTelephonyManagerShim.addCarrierPrivilegesListener(
logicalSlotIndex, executor, listener); logicalSlotIndex, executor, listener);
} catch (UnsupportedApiLevelException unsupportedApiLevelException) { } catch (UnsupportedApiLevelException unsupportedApiLevelException) {
// Should not happen since CarrierPrivilegeAuthenticator is only used on T+
Log.e(TAG, "addCarrierPrivilegesListener API is not available"); Log.e(TAG, "addCarrierPrivilegesListener API is not available");
} }
} }
private void removeCarrierPrivilegesListener(CarrierPrivilegesListenerShim listener) { private void removeCarrierPrivilegesListener(CarrierPrivilegesListenerShim listener) {
if (mTelephonyManagerShim == null) {
return;
}
try { try {
mTelephonyManagerShim.removeCarrierPrivilegesListener(listener); mTelephonyManagerShim.removeCarrierPrivilegesListener(listener);
} catch (UnsupportedApiLevelException unsupportedApiLevelException) { } catch (UnsupportedApiLevelException unsupportedApiLevelException) {
// Should not happen since CarrierPrivilegeAuthenticator is only used on T+
Log.e(TAG, "removeCarrierPrivilegesListener API is not available"); Log.e(TAG, "removeCarrierPrivilegesListener API is not available");
} }
} }
private String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { private String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
if (mTelephonyManagerShim == null) {
return null;
}
try { try {
return mTelephonyManagerShim.getCarrierServicePackageNameForLogicalSlot( return mTelephonyManagerShim.getCarrierServicePackageNameForLogicalSlot(
logicalSlotIndex); logicalSlotIndex);
} catch (UnsupportedApiLevelException unsupportedApiLevelException) { } catch (UnsupportedApiLevelException unsupportedApiLevelException) {
// Should not happen since CarrierPrivilegeAuthenticator is only used on T+
Log.e(TAG, "getCarrierServicePackageNameForLogicalSlot API is not available"); Log.e(TAG, "getCarrierServicePackageNameForLogicalSlot API is not available");
} }
return null; return null;