Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 10ac0aaf authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Handle invalid PhoneAccountHandle for CarrierIdentifier"

parents 2e44e1ff be11b328
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -19,14 +19,16 @@ package com.android.voicemail.impl;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build.VERSION_CODES;
import android.support.annotation.Nullable;
import android.telecom.PhoneAccountHandle;
import android.telephony.TelephonyManager;
import com.google.auto.value.AutoValue;
import java.util.Optional;

/** Identifies a carrier. */
@AutoValue
@TargetApi(VERSION_CODES.O)
@SuppressWarnings("missingpermission")
@SuppressWarnings({"missingpermission", "AndroidApiChecker"})
public abstract class CarrierIdentifier {

  public abstract String mccMnc();
@@ -52,20 +54,25 @@ public abstract class CarrierIdentifier {
    return new AutoValue_CarrierIdentifier.Builder().setGid1("");
  }

  public static CarrierIdentifier forHandle(
      Context context, PhoneAccountHandle phoneAccountHandle) {
  /** Create a identifier for a {@link PhoneAccountHandle}. Absent if the handle is not valid. */
  public static Optional<CarrierIdentifier> forHandle(
      Context context, @Nullable PhoneAccountHandle phoneAccountHandle) {
    if (phoneAccountHandle == null) {
      return Optional.empty();
    }
    TelephonyManager telephonyManager =
        context
            .getSystemService(TelephonyManager.class)
            .createForPhoneAccountHandle(phoneAccountHandle);
    if (telephonyManager == null) {
      throw new IllegalArgumentException("Invalid PhoneAccountHandle");
      return Optional.empty();
    }
    String gid1 = telephonyManager.getGroupIdLevel1();
    if (gid1 == null) {
      gid1 = "";
    }

    return builder().setMccMnc(telephonyManager.getSimOperator()).setGid1(gid1).build();
    return Optional.of(
        builder().setMccMnc(telephonyManager.getSimOperator()).setGid1(gid1).build());
  }
}
+17 −18
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.voicemail.impl.protocol.VisualVoicemailProtocolFactory;
import com.android.voicemail.impl.sms.StatusMessage;
import com.android.voicemail.impl.sync.VvmAccountManager;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;

/**
@@ -55,7 +56,7 @@ import java.util.Set;
 * <p>TODO(twyen): refactor this to an interface.
 */
@TargetApi(VERSION_CODES.O)
@SuppressWarnings("missingpermission")
@SuppressWarnings({"missingpermission", "AndroidApiChecker"})
public class OmtpVvmCarrierConfigHelper {

  private static final String TAG = "OmtpVvmCarrierCfgHlpr";
@@ -105,11 +106,17 @@ public class OmtpVvmCarrierConfigHelper {
  public OmtpVvmCarrierConfigHelper(Context context, @Nullable PhoneAccountHandle handle) {
    this.context = context;
    phoneAccountHandle = handle;
    if (overrideConfigForTest != null) {
      overrideConfig = overrideConfigForTest;
      carrierConfig = new PersistableBundle();
      telephonyConfig = new PersistableBundle();
    } else {
      Optional<CarrierIdentifier> carrierIdentifier = CarrierIdentifier.forHandle(context, handle);
      TelephonyManager telephonyManager =
          context
              .getSystemService(TelephonyManager.class)
              .createForPhoneAccountHandle(phoneAccountHandle);
    if (telephonyManager == null) {
      if (telephonyManager == null || !carrierIdentifier.isPresent()) {
        VvmLog.e(TAG, "PhoneAccountHandle is invalid");
        carrierConfig = null;
        telephonyConfig = null;
@@ -118,12 +125,6 @@ public class OmtpVvmCarrierConfigHelper {
        protocol = null;
        return;
      }

    if (overrideConfigForTest != null) {
      overrideConfig = overrideConfigForTest;
      carrierConfig = new PersistableBundle();
      telephonyConfig = new PersistableBundle();
    } else {
      if (ConfigOverrideFragment.isOverridden(context)) {
        overrideConfig = ConfigOverrideFragment.getConfig(context);
        VvmLog.w(TAG, "Config override is activated: " + overrideConfig);
@@ -132,9 +133,7 @@ public class OmtpVvmCarrierConfigHelper {
      }

      carrierConfig = getCarrierConfig(telephonyManager);
      telephonyConfig =
          new DialerVvmConfigManager(context)
              .getConfig(CarrierIdentifier.forHandle(context, phoneAccountHandle));
      telephonyConfig = new DialerVvmConfigManager(context).getConfig(carrierIdentifier.get());
    }

    vvmType = getVvmType();