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

Commit 5dc0c26c authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Teach NetworkIdentity about roaming.

And correctly upgrade NetworkIdentitySet written to disk, assuming
that old values aren't roaming.

Bug: 4724762
Change-Id: Ic25897ebbaf43be2390174d8e5fd08386bc8a345
parent d03fd3f0
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -33,11 +33,13 @@ public class NetworkIdentity {
    final int mType;
    final int mSubType;
    final String mSubscriberId;
    final boolean mRoaming;

    public NetworkIdentity(int type, int subType, String subscriberId) {
    public NetworkIdentity(int type, int subType, String subscriberId, boolean roaming) {
        this.mType = type;
        this.mSubType = subType;
        this.mSubscriberId = subscriberId;
        this.mRoaming = roaming;
    }

    @Override
@@ -50,7 +52,8 @@ public class NetworkIdentity {
        if (obj instanceof NetworkIdentity) {
            final NetworkIdentity ident = (NetworkIdentity) obj;
            return mType == ident.mType && mSubType == ident.mSubType
                    && Objects.equal(mSubscriberId, ident.mSubscriberId);
                    && Objects.equal(mSubscriberId, ident.mSubscriberId)
                    && mRoaming == ident.mRoaming;
        }
        return false;
    }
@@ -66,8 +69,9 @@ public class NetworkIdentity {
        }

        final String scrubSubscriberId = mSubscriberId != null ? "valid" : "null";
        final String roaming = mRoaming ? ", ROAMING" : "";
        return "[type=" + typeName + ", subType=" + subTypeName + ", subscriberId="
                + scrubSubscriberId + "]";
                + scrubSubscriberId + roaming + "]";
    }

    public int getType() {
@@ -82,6 +86,10 @@ public class NetworkIdentity {
        return mSubscriberId;
    }

    public boolean getRoaming() {
        return mRoaming;
    }

    /**
     * Build a {@link NetworkIdentity} from the given {@link NetworkState},
     * assuming that any mobile networks are using the current IMSI.
@@ -94,18 +102,21 @@ public class NetworkIdentity {
        // comes from an authoritative source.

        final String subscriberId;
        final boolean roaming;
        if (isNetworkTypeMobile(type)) {
            final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
                    Context.TELEPHONY_SERVICE);
            roaming = telephony.isNetworkRoaming();
            if (state.subscriberId != null) {
                subscriberId = state.subscriberId;
            } else {
                final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
                        Context.TELEPHONY_SERVICE);
                subscriberId = telephony.getSubscriberId();
            }
        } else {
            subscriberId = null;
            roaming = false;
        }
        return new NetworkIdentity(type, subType, subscriberId);
        return new NetworkIdentity(type, subType, subscriberId, roaming);
    }

}
+15 −3
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import java.util.HashSet;
 */
public class NetworkIdentitySet extends HashSet<NetworkIdentity> {
    private static final int VERSION_INIT = 1;
    private static final int VERSION_ADD_ROAMING = 2;

    public NetworkIdentitySet() {
    }
@@ -46,7 +47,18 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> {
                    final int type = in.readInt();
                    final int subType = in.readInt();
                    final String subscriberId = readOptionalString(in);
                    add(new NetworkIdentity(type, subType, subscriberId));
                    add(new NetworkIdentity(type, subType, subscriberId, false));
                }
                break;
            }
            case VERSION_ADD_ROAMING: {
                final int size = in.readInt();
                for (int i = 0; i < size; i++) {
                    final int type = in.readInt();
                    final int subType = in.readInt();
                    final String subscriberId = readOptionalString(in);
                    final boolean roaming = in.readBoolean();
                    add(new NetworkIdentity(type, subType, subscriberId, roaming));
                }
                break;
            }
@@ -57,13 +69,13 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> {
    }

    public void writeToStream(DataOutputStream out) throws IOException {
        out.writeInt(VERSION_INIT);
        out.writeInt(VERSION_ADD_ROAMING);
        out.writeInt(size());
        for (NetworkIdentity ident : this) {
            out.writeInt(VERSION_INIT);
            out.writeInt(ident.getType());
            out.writeInt(ident.getSubType());
            writeOptionalString(out, ident.getSubscriberId());
            out.writeBoolean(ident.getRoaming());
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -623,7 +623,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
        if (LOGV) Slog.v(TAG, "ensureActiveMobilePolicyLocked()");
        final String subscriberId = getActiveSubscriberId();
        final NetworkIdentity probeIdent = new NetworkIdentity(
                TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, subscriberId);
                TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, subscriberId, false);

        // examine to see if any policy is defined for active mobile
        boolean mobileDefined = false;