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

Commit 9521f8c0 authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Improve TelephonyNetworkRequest logs.

Preserve historic logs and list them in bugreports.
General aid to debugging.

bug:27517447
Change-Id: I5d82047b9c0a84edb9ae40782fd6868360bebeaf
parent 91abb548
Loading
Loading
Loading
Loading
+35 −11
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ public class PhoneFactory {
    static private PhoneNotifier sPhoneNotifier;
    static private Context sContext;
    static private PhoneSwitcher sPhoneSwitcher;
    static private SubscriptionMonitor sSubscriptionMonitor;
    static private TelephonyNetworkFactory[] sTelephonyNetworkFactories;

    static private final HashMap<String, LocalLog>sLocalLogs = new HashMap<String, LocalLog>();
@@ -212,8 +213,7 @@ public class PhoneFactory {
                        ServiceManager.getService("telephony.registry"));
                SubscriptionController sc = SubscriptionController.getInstance();

                SubscriptionMonitor subscriptionMonitor = new SubscriptionMonitor(tr,
                        sContext, sc, numPhones);
                sSubscriptionMonitor = new SubscriptionMonitor(tr, sContext, sc, numPhones);

                sPhoneSwitcher = new PhoneSwitcher(MAX_ACTIVE_PHONES, numPhones,
                        sContext, sc, Looper.myLooper(), tr, sCommandsInterfaces,
@@ -225,7 +225,7 @@ public class PhoneFactory {
                sTelephonyNetworkFactories = new TelephonyNetworkFactory[numPhones];
                for (int i = 0; i < numPhones; i++) {
                    sTelephonyNetworkFactories[i] = new TelephonyNetworkFactory(
                            sPhoneSwitcher, sc, subscriptionMonitor, Looper.myLooper(),
                            sPhoneSwitcher, sc, sSubscriptionMonitor, Looper.myLooper(),
                            sContext, i, sPhones[i].mDcTracker);
                }
            }
@@ -366,7 +366,8 @@ public class PhoneFactory {
        }
    }

    public static void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    public static void dump(FileDescriptor fd, PrintWriter printwriter, String[] args) {
        IndentingPrintWriter pw = new IndentingPrintWriter(printwriter, "  ");
        pw.println("PhoneFactory:");
        pw.println(" sMadeDefaults=" + sMadeDefaults);

@@ -375,6 +376,7 @@ public class PhoneFactory {

        Phone[] phones = (Phone[])PhoneFactory.getPhones();
        for (int i = 0; i < phones.length; i++) {
            pw.increaseIndent();
            Phone phone = phones[i];

            try {
@@ -398,42 +400,64 @@ public class PhoneFactory {
                e.printStackTrace();
            }
            pw.flush();
            pw.decreaseIndent();
            pw.println("++++++++++++++++++++++++++++++++");
        }

        pw.println("SubscriptionMonitor:");
        pw.increaseIndent();
        try {
            sSubscriptionMonitor.dump(fd, pw, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
        pw.decreaseIndent();
        pw.println("++++++++++++++++++++++++++++++++");

        pw.println("UiccController:");
        pw.increaseIndent();
        try {
            sUiccController.dump(fd, pw, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
        pw.flush();
        pw.decreaseIndent();
        pw.println("++++++++++++++++++++++++++++++++");

        pw.println("SubscriptionController:");
        pw.increaseIndent();
        try {
            SubscriptionController.getInstance().dump(fd, pw, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
        pw.flush();
        pw.decreaseIndent();
        pw.println("++++++++++++++++++++++++++++++++");

        pw.println("SubInfoRecordUpdater:");
        pw.increaseIndent();
        try {
            sSubInfoRecordUpdater.dump(fd, pw, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
        pw.flush();

        pw.decreaseIndent();
        pw.println("++++++++++++++++++++++++++++++++");

        pw.println("LocalLogs:");
        pw.increaseIndent();
        synchronized (sLocalLogs) {
            final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ");
            for (String key : sLocalLogs.keySet()) {
                ipw.println(key);
                ipw.increaseIndent();
                sLocalLogs.get(key).dump(fd, ipw, args);
                ipw.decreaseIndent();
                pw.println(key);
                pw.increaseIndent();
                sLocalLogs.get(key).dump(fd, pw, args);
                pw.decreaseIndent();
            }
            ipw.flush();
            pw.flush();
        }
        pw.decreaseIndent();
    }
}
+13 −14
Original line number Diff line number Diff line
@@ -223,17 +223,6 @@ public class RetryManager {
        mApnType = apnType;
    }

    @Override
    public String toString() {
        String ret = "RetryManager: { forever=" + mRetryForever + " maxRetry=" + mMaxRetryCount
                + " retry=" + mRetryCount + " config={" + mConfig + "} retryArray={";
        for (RetryRec r : mRetryArray) {
            ret += r.mDelayTime + ":" + r.mRandomizationTime + " ";
        }
        ret += "}}";
        return ret;
    }

    /**
     * Configure for using string which allow arbitrary
     * sequences of times. See class comments for the
@@ -368,7 +357,8 @@ public class RetryManager {
        }

        if (VDBG) {
            log("mInterApnDelay = " + mInterApnDelay + ", mFailFastInterApnDelay = " + mFailFastInterApnDelay);
            log("mInterApnDelay = " + mInterApnDelay + ", mFailFastInterApnDelay = " +
                    mFailFastInterApnDelay);
        }

        configure(configString);
@@ -546,8 +536,9 @@ public class RetryManager {

        if (failFastEnabled && delay > mFailFastInterApnDelay) {
            // If we enable fail fast mode, and the delay we got is longer than
            // fail-fast delay (mFailFastInterApnDelay), use the fail-fast delay. If the delay we calculated
            // is already shorter than fail-fast delay, then ignore fail-fast delay.
            // fail-fast delay (mFailFastInterApnDelay), use the fail-fast delay.
            // If the delay we calculated is already shorter than fail-fast delay,
            // then ignore fail-fast delay.
            delay = mFailFastInterApnDelay;
        }

@@ -632,6 +623,14 @@ public class RetryManager {
        return (failFastEnabled) ? mFailFastInterApnDelay : mInterApnDelay;
    }

    public String toString() {
        return "mApnType=" + mApnType + " mRetryCount=" + mRetryCount +
                " mMaxRetryCount=" + mMaxRetryCount + " mCurrentApnIndex=" + mCurrentApnIndex +
                " mSameApnRtryCount=" + mSameApnRetryCount + " mModemSuggestedDelay=" +
                mModemSuggestedDelay + " mRetryForever=" + mRetryForever +
                " mConfig={" + mConfig + "}";
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("  RetryManager");
        pw.println("***************************************");
+29 −12
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.Rlog;
import android.telephony.SubscriptionManager;
import android.util.LocalLog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.ISub;
@@ -37,6 +38,8 @@ import com.android.internal.telephony.IOnSubscriptionsChangedListener;
import com.android.internal.telephony.ITelephonyRegistry;
import com.android.internal.telephony.PhoneConstants;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.IllegalArgumentException;

/**
@@ -61,6 +64,9 @@ public class SubscriptionMonitor {
    private final static boolean VDBG = true;
    private final static String LOG_TAG = "SubscriptionMonitor";

    private final static int MAX_LOGLINES = 100;
    private final LocalLog mLocalLog = new LocalLog(MAX_LOGLINES);

    public SubscriptionMonitor(ITelephonyRegistry tr, Context context,
            SubscriptionController subscriptionController, int numPhones) {
        try {
@@ -102,16 +108,14 @@ public class SubscriptionMonitor {
            new IOnSubscriptionsChangedListener.Stub() {
        @Override
        public void onSubscriptionsChanged() {
            if (VDBG) log("onSubscriptionsChanged");
            synchronized (mLock) {
                for (int phoneId = 0; phoneId < mPhoneSubId.length; phoneId++) {
                    final int newSubId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
                    final int oldSubId = mPhoneSubId[phoneId];
                    if (oldSubId != newSubId) {
                        if (VDBG) {
                            log("Phone[" + phoneId + "] subId changed " + oldSubId + "->"
                                    + newSubId);
                        }
                        log("Phone[" + phoneId + "] subId changed " + oldSubId + "->" +
                                newSubId + ", " +
                                mSubscriptionsChangedRegistrants[phoneId].size() + " registrants");
                        mPhoneSubId[phoneId] = newSubId;
                        mSubscriptionsChangedRegistrants[phoneId].notifyRegistrants();

@@ -120,7 +124,9 @@ public class SubscriptionMonitor {

                        // check if this affects default data
                        if (newSubId == mDefaultDataSubId || oldSubId == mDefaultDataSubId) {
                            if (VDBG) log("mDefaultDataSubId = " + mDefaultDataSubId);
                            log("mDefaultDataSubId = " + mDefaultDataSubId + ", " +
                                    mDefaultDataSubChangedRegistrants[phoneId].size() +
                                    " registrants");
                            mDefaultDataSubChangedRegistrants[phoneId].notifyRegistrants();
                            if (newSubId == mDefaultDataSubId) {
                                mDefaultDataPhoneId = phoneId;
@@ -139,14 +145,9 @@ public class SubscriptionMonitor {
            final int newDefaultDataSubId = mSubscriptionController.getDefaultDataSubId();
            synchronized (mLock) {
                if (mDefaultDataSubId != newDefaultDataSubId) {
                    if (VDBG) log("Got Default changed " + mDefaultDataSubId + "->" +
                            newDefaultDataSubId);
                    log("Default changed " + mDefaultDataSubId + "->" + newDefaultDataSubId);
                    final int oldDefaultDataSubId = mDefaultDataSubId;
                    final int oldDefaultDataPhoneId = mDefaultDataPhoneId;
                    if (VDBG) {
                        log("oldDefaultDataSubId=" + mDefaultDataSubId +
                                ", oldDefaultDataPhoneId=" + mDefaultDataPhoneId);
                    }
                    mDefaultDataSubId = newDefaultDataSubId;

                    int newDefaultDataPhoneId =
@@ -162,6 +163,15 @@ public class SubscriptionMonitor {
                    }

                    if (newDefaultDataPhoneId != oldDefaultDataPhoneId) {
                        log("Default phoneId changed " + oldDefaultDataPhoneId + "->" +
                                newDefaultDataPhoneId + ", " +
                                (invalidPhoneId(oldDefaultDataPhoneId) ?
                                 0 :
                                 mDefaultDataSubChangedRegistrants[oldDefaultDataPhoneId].size()) +
                                "," + (invalidPhoneId(newDefaultDataPhoneId) ?
                                  0 :
                                  mDefaultDataSubChangedRegistrants[newDefaultDataPhoneId].size()) +
                                " registrants");
                        mDefaultDataPhoneId = newDefaultDataPhoneId;
                        if (!invalidPhoneId(oldDefaultDataPhoneId)) {
                            mDefaultDataSubChangedRegistrants[oldDefaultDataPhoneId].
@@ -217,5 +227,12 @@ public class SubscriptionMonitor {

    private void log(String s) {
        Rlog.d(LOG_TAG, s);
        mLocalLog.log(s);
    }

    public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
        synchronized (mLock) {
            mLocalLog.dump(fd, printWriter, args);
        }
    }
}
+18 −21
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.internal.util.IndentingPrintWriter;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -388,6 +389,8 @@ public class ApnContext {
    }

    private final ArrayList<LocalLog> mLocalLogs = new ArrayList<LocalLog>();
    private final ArrayDeque<LocalLog> mHistoryLogs = new ArrayDeque<LocalLog>();
    private final static int MAX_HISTORY_LOG_COUNT = 4;

    public void requestLog(String str) {
        synchronized (mRefCountLock) {
@@ -399,12 +402,6 @@ public class ApnContext {

    public void incRefCount(LocalLog log) {
        synchronized (mRefCountLock) {
            if (mRefCount == 0) {
               // we wanted to leave the last in so it could actually capture the tear down
               // of the network
               requestLog("clearing log with size=" + mLocalLogs.size());
               mLocalLogs.clear();
            }
            if (mLocalLogs.contains(log)) {
                log.log("ApnContext.incRefCount has duplicate add - " + mRefCount);
            } else {
@@ -419,15 +416,14 @@ public class ApnContext {

    public void decRefCount(LocalLog log) {
        synchronized (mRefCountLock) {
            // leave the last log alive to capture the actual tear down
            if (mRefCount != 1) {
            if (mLocalLogs.remove(log)) {
                log.log("ApnContext.decRefCount - " + mRefCount);
                } else {
                    log.log("ApnContext.decRefCount didn't find log - " + mRefCount);
                mHistoryLogs.addFirst(log);
                while (mHistoryLogs.size() > MAX_HISTORY_LOG_COUNT) {
                    mHistoryLogs.removeLast();
                }
            } else {
                log.log("ApnContext.decRefCount - 1");
                log.log("ApnContext.decRefCount didn't find log - " + mRefCount);
            }
            if (mRefCount-- == 1) {
                mDcTracker.setEnabled(apnIdForApnName(mApnType), false);
@@ -681,15 +677,16 @@ public class ApnContext {
        final IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, "  ");
        synchronized (mRefCountLock) {
            pw.println(toString());
            if (mRefCount > 0) {
            pw.increaseIndent();
            for (LocalLog l : mLocalLogs) {
                l.dump(fd, pw, args);
            }
                pw.decreaseIndent();
            if (mHistoryLogs.size() > 0) pw.println("Historical Logs:");
            for (LocalLog l : mHistoryLogs) {
                l.dump(fd, pw, args);
            }
            pw.decreaseIndent();
            pw.println("mRetryManager={" + mRetryManager.toString() + "}");
        }

        mRetryManager.dump(fd, pw, args);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -228,6 +228,7 @@ public class TelephonyNetworkFactory extends NetworkFactory {
            localLog = mDefaultRequests.get(networkRequest);
            if (localLog == null) {
                localLog = new LocalLog(REQUEST_LOG_SIZE);
                localLog.log("created for " + networkRequest);
                mDefaultRequests.put(networkRequest, localLog);
                isApplicable = mIsDefault;
            }