Search in sources :

Example 1 with TelephonyMetrics

use of com.android.internal.telephony.metrics.TelephonyMetrics in project android_frameworks_opt_telephony by LineageOS.

the class CarrierInfoManager method updateOrInsertCarrierKey.

/**
 * Inserts or update the Carrier Key in the database
 * @param imsiEncryptionInfo ImsiEncryptionInfo object.
 * @param context Context.
 */
public static void updateOrInsertCarrierKey(ImsiEncryptionInfo imsiEncryptionInfo, Context context, int phoneId) {
    byte[] keyBytes = imsiEncryptionInfo.getPublicKey().getEncoded();
    ContentResolver mContentResolver = context.getContentResolver();
    TelephonyMetrics tm = TelephonyMetrics.getInstance();
    // In the current design, MVNOs are not supported. If we decide to support them,
    // we'll need to add to this CL.
    ContentValues contentValues = new ContentValues();
    contentValues.put(Telephony.CarrierColumns.MCC, imsiEncryptionInfo.getMcc());
    contentValues.put(Telephony.CarrierColumns.MNC, imsiEncryptionInfo.getMnc());
    contentValues.put(Telephony.CarrierColumns.KEY_TYPE, imsiEncryptionInfo.getKeyType());
    contentValues.put(Telephony.CarrierColumns.KEY_IDENTIFIER, imsiEncryptionInfo.getKeyIdentifier());
    contentValues.put(Telephony.CarrierColumns.PUBLIC_KEY, keyBytes);
    contentValues.put(Telephony.CarrierColumns.EXPIRATION_TIME, imsiEncryptionInfo.getExpirationTime().getTime());
    boolean downloadSuccessfull = true;
    try {
        Log.i(LOG_TAG, "Inserting imsiEncryptionInfo into db");
        mContentResolver.insert(Telephony.CarrierColumns.CONTENT_URI, contentValues);
    } catch (SQLiteConstraintException e) {
        Log.i(LOG_TAG, "Insert failed, updating imsiEncryptionInfo into db");
        ContentValues updatedValues = new ContentValues();
        updatedValues.put(Telephony.CarrierColumns.PUBLIC_KEY, keyBytes);
        updatedValues.put(Telephony.CarrierColumns.EXPIRATION_TIME, imsiEncryptionInfo.getExpirationTime().getTime());
        updatedValues.put(Telephony.CarrierColumns.KEY_IDENTIFIER, imsiEncryptionInfo.getKeyIdentifier());
        try {
            int nRows = mContentResolver.update(Telephony.CarrierColumns.CONTENT_URI, updatedValues, "mcc=? and mnc=? and key_type=?", new String[] { imsiEncryptionInfo.getMcc(), imsiEncryptionInfo.getMnc(), String.valueOf(imsiEncryptionInfo.getKeyType()) });
            if (nRows == 0) {
                Log.d(LOG_TAG, "Error updating values:" + imsiEncryptionInfo);
                downloadSuccessfull = false;
            }
        } catch (Exception ex) {
            Log.d(LOG_TAG, "Error updating values:" + imsiEncryptionInfo + ex);
            downloadSuccessfull = false;
        }
    } catch (Exception e) {
        Log.d(LOG_TAG, "Error inserting/updating values:" + imsiEncryptionInfo + e);
        downloadSuccessfull = false;
    } finally {
        tm.writeCarrierKeyEvent(phoneId, imsiEncryptionInfo.getKeyType(), downloadSuccessfull);
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException) TelephonyMetrics(com.android.internal.telephony.metrics.TelephonyMetrics) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException) ContentResolver(android.content.ContentResolver)

Example 2 with TelephonyMetrics

use of com.android.internal.telephony.metrics.TelephonyMetrics in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionController method notifySubscriptionInfoChanged.

/**
 * Notify the changed of subscription info.
 */
@UnsupportedAppUsage
public void notifySubscriptionInfoChanged() {
    TelephonyRegistryManager trm = (TelephonyRegistryManager) mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE);
    if (DBG)
        logd("notifySubscriptionInfoChanged:");
    trm.notifySubscriptionInfoChanged();
    // FIXME: Remove if listener technique accepted.
    broadcastSimInfoContentChanged();
    MultiSimSettingController.getInstance().notifySubscriptionInfoChanged();
    TelephonyMetrics metrics = TelephonyMetrics.getInstance();
    List<SubscriptionInfo> subInfos;
    synchronized (mSubInfoListLock) {
        subInfos = new ArrayList<>(mCacheActiveSubInfoList);
    }
    if (mOpptSubInfoListChangedDirtyBit.getAndSet(false)) {
        notifyOpportunisticSubscriptionInfoChanged();
    }
    metrics.updateActiveSubscriptionInfoList(subInfos);
}
Also used : SubscriptionInfo(android.telephony.SubscriptionInfo) TelephonyMetrics(com.android.internal.telephony.metrics.TelephonyMetrics) TelephonyRegistryManager(android.telephony.TelephonyRegistryManager) UnsupportedAppUsage(android.compat.annotation.UnsupportedAppUsage)

Example 3 with TelephonyMetrics

use of com.android.internal.telephony.metrics.TelephonyMetrics in project android_frameworks_opt_telephony by LineageOS.

the class UsimDataDownloadHandler method addUsimDataDownloadToMetrics.

/**
 * Add the SMS-PP data to the telephony metrics, indicating if the message was forwarded
 * to the USIM. The metrics does not cover the case where the SMS-PP might be rejected
 * by the USIM itself.
 */
private void addUsimDataDownloadToMetrics(boolean result) {
    TelephonyMetrics metrics = TelephonyMetrics.getInstance();
    metrics.writeIncomingSMSPP(mPhoneId, android.telephony.SmsMessage.FORMAT_3GPP, result);
}
Also used : TelephonyMetrics(com.android.internal.telephony.metrics.TelephonyMetrics)

Example 4 with TelephonyMetrics

use of com.android.internal.telephony.metrics.TelephonyMetrics in project android_frameworks_opt_telephony by LineageOS.

the class PhoneFactory method makeDefaultPhone.

/**
 * FIXME replace this with some other way of making these
 * instances
 */
@UnsupportedAppUsage
public static void makeDefaultPhone(Context context) {
    synchronized (sLockProxyPhones) {
        if (!sMadeDefaults) {
            sContext = context;
            // create the telephony device controller.
            TelephonyDevController.create();
            TelephonyMetrics metrics = TelephonyMetrics.getInstance();
            metrics.setContext(context);
            int retryCount = 0;
            for (; ; ) {
                boolean hasException = false;
                retryCount++;
                try {
                    // use UNIX domain socket to
                    // prevent subsequent initialization
                    new LocalServerSocket("com.android.internal.telephony");
                } catch (java.io.IOException ex) {
                    hasException = true;
                }
                if (!hasException) {
                    break;
                } else if (retryCount > SOCKET_OPEN_MAX_RETRY) {
                    throw new RuntimeException("PhoneFactory probably already running");
                } else {
                    try {
                        Thread.sleep(SOCKET_OPEN_RETRY_MILLIS);
                    } catch (InterruptedException er) {
                    }
                }
            }
            // register statsd pullers.
            sMetricsCollector = new MetricsCollector(context);
            sPhoneNotifier = new DefaultPhoneNotifier(context);
            int cdmaSubscription = CdmaSubscriptionSourceManager.getDefault(context);
            Rlog.i(LOG_TAG, "Cdma Subscription set to " + cdmaSubscription);
            /* In case of multi SIM mode two instances of Phone, RIL are created,
                   where as in single SIM mode only instance. isMultiSimEnabled() function checks
                   whether it is single SIM or multi SIM mode */
            int numPhones = TelephonyManager.getDefault().getActiveModemCount();
            int[] networkModes = new int[numPhones];
            sPhones = new Phone[numPhones];
            sCommandsInterfaces = new RIL[numPhones];
            sTelephonyNetworkFactories = new TelephonyNetworkFactory[numPhones];
            for (int i = 0; i < numPhones; i++) {
                // reads the system properties and makes commandsinterface
                // Get preferred network type.
                networkModes[i] = RILConstants.PREFERRED_NETWORK_MODE;
                Rlog.i(LOG_TAG, "Network Mode set to " + Integer.toString(networkModes[i]));
                sCommandsInterfaces[i] = new RIL(context, networkModes[i], cdmaSubscription, i);
            }
            // Instantiate UiccController so that all other classes can just
            // call getInstance()
            sUiccController = UiccController.make(context);
            Rlog.i(LOG_TAG, "Creating SubscriptionController");
            TelephonyComponentFactory.getInstance().inject(SubscriptionController.class.getName()).initSubscriptionController(context);
            TelephonyComponentFactory.getInstance().inject(MultiSimSettingController.class.getName()).initMultiSimSettingController(context, SubscriptionController.getInstance());
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_EUICC)) {
                sEuiccController = EuiccController.init(context);
                sEuiccCardController = EuiccCardController.init(context);
            }
            for (int i = 0; i < numPhones; i++) {
                sPhones[i] = createPhone(context, i);
            }
            // FIXME: needs to be done in a more controlled manner in the future.
            if (numPhones > 0)
                sPhone = sPhones[0];
            // Ensure that we have a default SMS app. Requesting the app with
            // updateIfNeeded set to true is enough to configure a default SMS app.
            ComponentName componentName = SmsApplication.getDefaultSmsApplication(context, true);
            String packageName = "NONE";
            if (componentName != null) {
                packageName = componentName.getPackageName();
            }
            Rlog.i(LOG_TAG, "defaultSmsApplication: " + packageName);
            // Set up monitor to watch for changes to SMS packages
            SmsApplication.initSmsPackageMonitor(context);
            sMadeDefaults = true;
            Rlog.i(LOG_TAG, "Creating SubInfoRecordUpdater ");
            HandlerThread pfhandlerThread = new HandlerThread("PhoneFactoryHandlerThread");
            pfhandlerThread.start();
            sSubInfoRecordUpdater = TelephonyComponentFactory.getInstance().inject(SubscriptionInfoUpdater.class.getName()).makeSubscriptionInfoUpdater(pfhandlerThread.getLooper(), context, sCommandsInterfaces);
            // Only bring up IMS if the device supports having an IMS stack.
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
                // might need it when it is being opened.
                for (int i = 0; i < numPhones; i++) {
                    sPhones[i].createImsPhone();
                }
            } else {
                Rlog.i(LOG_TAG, "IMS is not supported on this device, skipping ImsResolver.");
            }
            sPhoneConfigurationManager = PhoneConfigurationManager.init(sContext);
            sCellularNetworkValidator = CellularNetworkValidator.make(sContext);
            int maxActivePhones = sPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
            sPhoneSwitcher = TelephonyComponentFactory.getInstance().inject(PhoneSwitcher.class.getName()).makePhoneSwitcher(maxActivePhones, sContext, Looper.myLooper());
            sProxyController = ProxyController.getInstance(context);
            sIntentBroadcaster = IntentBroadcaster.getInstance(context);
            sNotificationChannelController = new NotificationChannelController(context);
            for (int i = 0; i < numPhones; i++) {
                sTelephonyNetworkFactories[i] = new TelephonyNetworkFactory(Looper.myLooper(), sPhones[i]);
            }
        }
    }
}
Also used : MetricsCollector(com.android.internal.telephony.metrics.MetricsCollector) HandlerThread(android.os.HandlerThread) LocalServerSocket(android.net.LocalServerSocket) ComponentName(android.content.ComponentName) TelephonyMetrics(com.android.internal.telephony.metrics.TelephonyMetrics) TelephonyNetworkFactory(com.android.internal.telephony.dataconnection.TelephonyNetworkFactory) NotificationChannelController(com.android.internal.telephony.util.NotificationChannelController) UnsupportedAppUsage(android.compat.annotation.UnsupportedAppUsage)

Example 5 with TelephonyMetrics

use of com.android.internal.telephony.metrics.TelephonyMetrics in project android_frameworks_opt_telephony by LineageOS.

the class SmsBroadcastUndelivered method scanRawTable.

/**
 * Scan the raw table for complete SMS messages to broadcast, and old PDUs to delete.
 */
static void scanRawTable(Context context, CdmaInboundSmsHandler cdmaInboundSmsHandler, GsmInboundSmsHandler gsmInboundSmsHandler, long oldMessageTimestamp) {
    if (DBG)
        Rlog.d(TAG, "scanning raw table for undelivered messages");
    long startTime = System.nanoTime();
    ContentResolver contentResolver = context.getContentResolver();
    HashMap<SmsReferenceKey, Integer> multiPartReceivedCount = new HashMap<SmsReferenceKey, Integer>(4);
    HashSet<SmsReferenceKey> oldMultiPartMessages = new HashSet<SmsReferenceKey>(4);
    Cursor cursor = null;
    try {
        // query only non-deleted ones
        cursor = contentResolver.query(InboundSmsHandler.sRawUri, PDU_PENDING_MESSAGE_PROJECTION, "deleted = 0", null, null);
        if (cursor == null) {
            Rlog.e(TAG, "error getting pending message cursor");
            return;
        }
        boolean isCurrentFormat3gpp2 = InboundSmsHandler.isCurrentFormat3gpp2();
        while (cursor.moveToNext()) {
            InboundSmsTracker tracker;
            try {
                tracker = TelephonyComponentFactory.getInstance().inject(InboundSmsTracker.class.getName()).makeInboundSmsTracker(context, cursor, isCurrentFormat3gpp2);
            } catch (IllegalArgumentException e) {
                Rlog.e(TAG, "error loading SmsTracker: " + e);
                continue;
            }
            if (tracker.getMessageCount() == 1) {
                // deliver single-part message
                broadcastSms(tracker, cdmaInboundSmsHandler, gsmInboundSmsHandler);
            } else {
                SmsReferenceKey reference = new SmsReferenceKey(tracker);
                Integer receivedCount = multiPartReceivedCount.get(reference);
                if (receivedCount == null) {
                    // first segment seen
                    multiPartReceivedCount.put(reference, 1);
                    if (tracker.getTimestamp() < oldMessageTimestamp) {
                        // older than oldMessageTimestamp; delete if we don't find all the
                        // segments
                        oldMultiPartMessages.add(reference);
                    }
                } else {
                    int newCount = receivedCount + 1;
                    if (newCount == tracker.getMessageCount()) {
                        // to state machine which will find the other pieces to broadcast
                        if (DBG)
                            Rlog.d(TAG, "found complete multi-part message");
                        broadcastSms(tracker, cdmaInboundSmsHandler, gsmInboundSmsHandler);
                        // don't delete this old message until after we broadcast it
                        oldMultiPartMessages.remove(reference);
                    } else {
                        multiPartReceivedCount.put(reference, newCount);
                    }
                }
            }
        }
        // Retrieve the phone id, required for metrics
        int phoneId = getPhoneId(gsmInboundSmsHandler, cdmaInboundSmsHandler);
        // Delete old incomplete message segments
        for (SmsReferenceKey message : oldMultiPartMessages) {
            // delete permanently
            int rows = contentResolver.delete(InboundSmsHandler.sRawUriPermanentDelete, message.getDeleteWhere(), message.getDeleteWhereArgs());
            if (rows == 0) {
                Rlog.e(TAG, "No rows were deleted from raw table!");
            } else if (DBG) {
                Rlog.d(TAG, "Deleted " + rows + " rows from raw table for incomplete " + message.mMessageCount + " part message");
            }
            // Update metrics with dropped SMS
            if (rows > 0) {
                TelephonyMetrics metrics = TelephonyMetrics.getInstance();
                metrics.writeDroppedIncomingMultipartSms(phoneId, message.mFormat, rows, message.mMessageCount);
            }
        }
    } catch (SQLException e) {
        Rlog.e(TAG, "error reading pending SMS messages", e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        if (DBG)
            Rlog.d(TAG, "finished scanning raw table in " + ((System.nanoTime() - startTime) / 1000000) + " ms");
    }
}
Also used : HashMap(java.util.HashMap) SQLException(android.database.SQLException) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver) TelephonyMetrics(com.android.internal.telephony.metrics.TelephonyMetrics) HashSet(java.util.HashSet)

Aggregations

TelephonyMetrics (com.android.internal.telephony.metrics.TelephonyMetrics)5 UnsupportedAppUsage (android.compat.annotation.UnsupportedAppUsage)2 ContentResolver (android.content.ContentResolver)2 ComponentName (android.content.ComponentName)1 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 SQLException (android.database.SQLException)1 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)1 LocalServerSocket (android.net.LocalServerSocket)1 HandlerThread (android.os.HandlerThread)1 SubscriptionInfo (android.telephony.SubscriptionInfo)1 TelephonyRegistryManager (android.telephony.TelephonyRegistryManager)1 TelephonyNetworkFactory (com.android.internal.telephony.dataconnection.TelephonyNetworkFactory)1 MetricsCollector (com.android.internal.telephony.metrics.MetricsCollector)1 NotificationChannelController (com.android.internal.telephony.util.NotificationChannelController)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1