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