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

Commit d7f8632a authored by Pankaj Kanwar's avatar Pankaj Kanwar Committed by Android (Google) Code Review
Browse files

Merge "Address IMSI privacy issues."

parents 542b9716 f07403c2
Loading
Loading
Loading
Loading
+26 −0
Original line number Original line Diff line number Diff line
@@ -640,6 +640,9 @@ message TelephonyEvent {


    // Carrier Identification Matching Event
    // Carrier Identification Matching Event
    CARRIER_ID_MATCHING = 13;
    CARRIER_ID_MATCHING = 13;

    // Carrier Key Change event.
    CARRIER_KEY_CHANGED = 14;
  }
  }


  // Setup a packet data connection
  // Setup a packet data connection
@@ -830,6 +833,26 @@ message TelephonyEvent {
    optional RilDataCall call = 3;
    optional RilDataCall call = 3;
  }
  }


  // Carrier Key Change Event.
  message CarrierKeyChange {

    enum KeyType {

      // Key Type Unknown.
      UNKNOWN = 0;
      // Key Type for WLAN.
      WLAN = 1;
      // Key Type for EPDG.
      EPDG = 2;
    }

    // Key type of the Encryption key.
    optional KeyType key_type = 1;

    // Whether the download was successful or not.
    optional bool isDownloadSuccessful = 2;
  }

  // Deactivate packet data connection
  // Deactivate packet data connection
  message RilDeactivateDataCall {
  message RilDeactivateDataCall {


@@ -931,6 +954,9 @@ message TelephonyEvent {


  // Carrier id matching event
  // Carrier id matching event
  optional CarrierIdMatching carrier_id_matching = 16;
  optional CarrierIdMatching carrier_id_matching = 16;

  // Carrier key change
  optional CarrierKeyChange carrier_key_change = 17;
}
}


enum TimeInterval {
enum TimeInterval {
+12 −3
Original line number Original line Diff line number Diff line
@@ -27,6 +27,8 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;


import com.android.internal.telephony.metrics.TelephonyMetrics;

import java.util.Date;
import java.util.Date;


/**
/**
@@ -98,9 +100,10 @@ public class CarrierInfoManager {
     * @param context Context.
     * @param context Context.
     */
     */
    public static void updateOrInsertCarrierKey(ImsiEncryptionInfo imsiEncryptionInfo,
    public static void updateOrInsertCarrierKey(ImsiEncryptionInfo imsiEncryptionInfo,
                                                Context context) {
                                                Context context, int phoneId) {
        byte[] keyBytes = imsiEncryptionInfo.getPublicKey().getEncoded();
        byte[] keyBytes = imsiEncryptionInfo.getPublicKey().getEncoded();
        ContentResolver mContentResolver = context.getContentResolver();
        ContentResolver mContentResolver = context.getContentResolver();
        TelephonyMetrics tm = TelephonyMetrics.getInstance();
        // In the current design, MVNOs are not supported. If we decide to support them,
        // In the current design, MVNOs are not supported. If we decide to support them,
        // we'll need to add to this CL.
        // we'll need to add to this CL.
        ContentValues contentValues = new ContentValues();
        ContentValues contentValues = new ContentValues();
@@ -113,6 +116,7 @@ public class CarrierInfoManager {
        contentValues.put(Telephony.CarrierColumns.PUBLIC_KEY, keyBytes);
        contentValues.put(Telephony.CarrierColumns.PUBLIC_KEY, keyBytes);
        contentValues.put(Telephony.CarrierColumns.EXPIRATION_TIME,
        contentValues.put(Telephony.CarrierColumns.EXPIRATION_TIME,
                imsiEncryptionInfo.getExpirationTime().getTime());
                imsiEncryptionInfo.getExpirationTime().getTime());
        boolean downloadSuccessfull = true;
        try {
        try {
            Log.i(LOG_TAG, "Inserting imsiEncryptionInfo into db");
            Log.i(LOG_TAG, "Inserting imsiEncryptionInfo into db");
            mContentResolver.insert(Telephony.CarrierColumns.CONTENT_URI, contentValues);
            mContentResolver.insert(Telephony.CarrierColumns.CONTENT_URI, contentValues);
@@ -133,12 +137,17 @@ public class CarrierInfoManager {
                                String.valueOf(imsiEncryptionInfo.getKeyType())});
                                String.valueOf(imsiEncryptionInfo.getKeyType())});
                if (nRows == 0) {
                if (nRows == 0) {
                    Log.d(LOG_TAG, "Error updating values:" + imsiEncryptionInfo);
                    Log.d(LOG_TAG, "Error updating values:" + imsiEncryptionInfo);
                    downloadSuccessfull = false;
                }
                }
            } catch (Exception ex) {
            } catch (Exception ex) {
                Log.d(LOG_TAG, "Error updating values:" + imsiEncryptionInfo + ex);
                Log.d(LOG_TAG, "Error updating values:" + imsiEncryptionInfo + ex);
                downloadSuccessfull = false;
            }
            }
        }  catch (Exception e) {
        }  catch (Exception e) {
            Log.d(LOG_TAG, "Error inserting/updating values:" + imsiEncryptionInfo + e);
            Log.d(LOG_TAG, "Error inserting/updating values:" + imsiEncryptionInfo + e);
            downloadSuccessfull = false;
        } finally {
            tm.writeCarrierKeyEvent(phoneId, imsiEncryptionInfo.getKeyType(), downloadSuccessfull);
        }
        }
    }
    }


@@ -153,9 +162,9 @@ public class CarrierInfoManager {
     * @param context Context.
     * @param context Context.
     */
     */
    public static void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo,
    public static void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo,
                                                       Context context) {
                                                       Context context, int phoneId) {
        Log.i(LOG_TAG, "inserting carrier key: " + imsiEncryptionInfo);
        Log.i(LOG_TAG, "inserting carrier key: " + imsiEncryptionInfo);
        updateOrInsertCarrierKey(imsiEncryptionInfo, context);
        updateOrInsertCarrierKey(imsiEncryptionInfo, context, phoneId);
        //todo send key to modem. Will be done in a subsequent CL.
        //todo send key to modem. Will be done in a subsequent CL.
    }
    }


+1 −1
Original line number Original line Diff line number Diff line
@@ -1537,7 +1537,7 @@ public class GsmCdmaPhone extends Phone {


    @Override
    @Override
    public void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo) {
    public void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo) {
        CarrierInfoManager.setCarrierInfoForImsiEncryption(imsiEncryptionInfo, mContext);
        CarrierInfoManager.setCarrierInfoForImsiEncryption(imsiEncryptionInfo, mContext, mPhoneId);
    }
    }


    @Override
    @Override
+7 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.internal.telephony.nano.TelephonyProto.ImsConnectionSt
import static com.android.internal.telephony.nano.TelephonyProto.RilDataCall;
import static com.android.internal.telephony.nano.TelephonyProto.RilDataCall;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierIdMatching;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierIdMatching;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierKeyChange;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.ModemRestart;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.ModemRestart;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilDeactivateDataCall;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilDeactivateDataCall;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCall;
import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCall;
@@ -126,4 +127,10 @@ public class TelephonyEventBuilder {
        mEvent.carrierIdMatching = carrierIdMatching;
        mEvent.carrierIdMatching = carrierIdMatching;
        return this;
        return this;
    }
    }

    public TelephonyEventBuilder setCarrierKeyChange(CarrierKeyChange carrierKeyChange) {
        mEvent.type = TelephonyEvent.Type.CARRIER_KEY_CHANGED;
        mEvent.carrierKeyChange = carrierKeyChange;
        return this;
    }
}
}
+18 −1
Original line number Original line Diff line number Diff line
@@ -68,6 +68,7 @@ import com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession.E
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierIdMatching;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierIdMatching;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierIdMatchingResult;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierIdMatchingResult;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.CarrierKeyChange;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.ModemRestart;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.ModemRestart;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilDeactivateDataCall;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilDeactivateDataCall;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCall;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCall;
@@ -510,7 +511,6 @@ public class TelephonyMetrics {
        log.endTime = new TelephonyProto.Time();
        log.endTime = new TelephonyProto.Time();
        log.endTime.systemTimestampMillis = System.currentTimeMillis();
        log.endTime.systemTimestampMillis = System.currentTimeMillis();
        log.endTime.elapsedTimestampMillis = SystemClock.elapsedRealtime();
        log.endTime.elapsedTimestampMillis = SystemClock.elapsedRealtime();

        return log;
        return log;
    }
    }


@@ -525,6 +525,23 @@ public class TelephonyMetrics {
                * (SESSION_START_PRECISION_MINUTES));
                * (SESSION_START_PRECISION_MINUTES));
    }
    }


    /**
     * Write the Carrier Key change event
     *
     * @param phoneId Phone id
     * @param keyType type of key
     * @param isDownloadSuccessful true if the key was successfully downloaded
     */
    public void writeCarrierKeyEvent(int phoneId, int keyType,  boolean isDownloadSuccessful) {
        final CarrierKeyChange carrierKeyChange = new CarrierKeyChange();
        carrierKeyChange.keyType = keyType;
        carrierKeyChange.isDownloadSuccessful = isDownloadSuccessful;
        TelephonyEvent event = new TelephonyEventBuilder(phoneId).setCarrierKeyChange(
                carrierKeyChange).build();
        addTelephonyEvent(event);
    }


    /**
    /**
     * Get the time interval with reduced prevision
     * Get the time interval with reduced prevision
     *
     *