Merge "Generate fallback speed label in AccessPoint.java"
diff --git a/api/test-current.txt b/api/test-current.txt
index 36515a55..9ee2527 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -12070,6 +12070,15 @@
     field public int pageCacheOverflow;
   }
 
+  public final class SQLiteDirectCursorDriver implements android.database.sqlite.SQLiteCursorDriver {
+    ctor public SQLiteDirectCursorDriver(android.database.sqlite.SQLiteDatabase, java.lang.String, java.lang.String, android.os.CancellationSignal);
+    method public void cursorClosed();
+    method public void cursorDeactivated();
+    method public void cursorRequeried(android.database.Cursor);
+    method public android.database.Cursor query(android.database.sqlite.SQLiteDatabase.CursorFactory, java.lang.String[]);
+    method public void setBindArguments(java.lang.String[]);
+  }
+
   public class SQLiteDiskIOException extends android.database.sqlite.SQLiteException {
     ctor public SQLiteDiskIOException();
     ctor public SQLiteDiskIOException(java.lang.String);
diff --git a/cmds/incidentd/Android.mk b/cmds/incidentd/Android.mk
index 537c910..3b15634 100644
--- a/cmds/incidentd/Android.mk
+++ b/cmds/incidentd/Android.mk
@@ -54,9 +54,7 @@
         libservices \
         libutils
 
-ifeq (BUILD_WITH_INCIDENTD_RC,true)
 LOCAL_INIT_RC := incidentd.rc
-endif
 
 include $(BUILD_EXECUTABLE)
 
diff --git a/cmds/incidentd/src/Reporter.cpp b/cmds/incidentd/src/Reporter.cpp
index ea73bcd..4ffc119 100644
--- a/cmds/incidentd/src/Reporter.cpp
+++ b/cmds/incidentd/src/Reporter.cpp
@@ -225,9 +225,8 @@
     // and report to those that care that we're doing it.
     for (const Section** section=SECTION_LIST; *section; section++) {
         const int id = (*section)->id;
-        ALOGD("Taking incident report section %d '%s'", id, (*section)->name.string());
-
         if (this->batch.containsSection(id)) {
+            ALOGD("Taking incident report section %d '%s'", id, (*section)->name.string());
             // Notify listener of starting
             for (ReportRequestSet::iterator it=batch.begin(); it!=batch.end(); it++) {
                 if ((*it)->listener != NULL && (*it)->args.containsSection(id)) {
@@ -251,6 +250,7 @@
                             IIncidentReportStatusListener::STATUS_FINISHED);
                 }
             }
+            ALOGD("Finish incident report section %d '%s'", id, (*section)->name.string());
         }
     }
 
@@ -324,6 +324,7 @@
     struct stat st;
     status_t err;
 
+    ALOGD("Start uploading backlogs in %s", INCIDENT_DIRECTORY);
     if ((err = create_directory(INCIDENT_DIRECTORY)) != NO_ERROR) {
         ALOGE("directory doesn't exist: %s", strerror(-err));
         return REPORT_FINISHED;
@@ -337,6 +338,7 @@
     sp<DropBoxManager> dropbox = new DropBoxManager();
 
     // Enumerate, count and add up size
+    int count = 0;
     while ((entry = readdir(dir)) != NULL) {
         if (entry->d_name[0] == '.') {
             continue;
@@ -360,8 +362,9 @@
         // boot or the next checkin. If the directory gets too big older files will
         // be rotated out.
         unlink(filename.string());
+        count++;
     }
-
+    ALOGD("Successfully uploaded %d files to Dropbox.", count);
     closedir(dir);
 
     return REPORT_FINISHED;
diff --git a/config/compiled-classes-phone b/config/compiled-classes-phone
index 548dc38..c829728 100644
--- a/config/compiled-classes-phone
+++ b/config/compiled-classes-phone
@@ -4183,7 +4183,7 @@
 android.util.Base64$Coder
 android.util.Base64$Decoder
 android.util.Base64$Encoder
-android.util.BootTimingsTraceLog
+android.util.TimingsTraceLog
 android.util.ByteStringUtils
 android.util.ContainerHelpers
 android.util.DebugUtils
diff --git a/config/preloaded-classes b/config/preloaded-classes
index 9612231..b6be0ee 100644
--- a/config/preloaded-classes
+++ b/config/preloaded-classes
@@ -2276,7 +2276,7 @@
 android.util.Base64$Coder
 android.util.Base64$Decoder
 android.util.Base64$Encoder
-android.util.BootTimingsTraceLog
+android.util.TimingsTraceLog
 android.util.ContainerHelpers
 android.util.DisplayMetrics
 android.util.EventLog
diff --git a/core/java/android/database/sqlite/SQLiteDirectCursorDriver.java b/core/java/android/database/sqlite/SQLiteDirectCursorDriver.java
index 797430a..1721e0c 100644
--- a/core/java/android/database/sqlite/SQLiteDirectCursorDriver.java
+++ b/core/java/android/database/sqlite/SQLiteDirectCursorDriver.java
@@ -16,6 +16,7 @@
 
 package android.database.sqlite;
 
+import android.annotation.TestApi;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase.CursorFactory;
 import android.os.CancellationSignal;
@@ -25,6 +26,7 @@
  * 
  * @hide
  */
+@TestApi
 public final class SQLiteDirectCursorDriver implements SQLiteCursorDriver {
     private final SQLiteDatabase mDatabase;
     private final String mEditTable; 
diff --git a/core/java/android/os/IncidentManager.java b/core/java/android/os/IncidentManager.java
index bc8e2e4..1336c66 100644
--- a/core/java/android/os/IncidentManager.java
+++ b/core/java/android/os/IncidentManager.java
@@ -21,8 +21,6 @@
 import android.annotation.SystemService;
 import android.annotation.TestApi;
 import android.content.Context;
-import android.os.IIncidentManager;
-import android.os.ServiceManager;
 import android.provider.Settings;
 import android.util.Slog;
 
@@ -37,7 +35,7 @@
 public class IncidentManager {
     private static final String TAG = "incident";
 
-    private Context mContext;
+    private final Context mContext;
 
     /**
      * @hide
@@ -54,18 +52,7 @@
             android.Manifest.permission.PACKAGE_USAGE_STATS
     })
     public void reportIncident(IncidentReportArgs args) {
-        final IIncidentManager service = IIncidentManager.Stub.asInterface(
-                ServiceManager.getService("incident"));
-        if (service == null) {
-            Slog.e(TAG, "reportIncident can't find incident binder service");
-            return;
-        }
-
-        try {
-            service.reportIncident(args);
-        } catch (RemoteException ex) {
-            Slog.e(TAG, "reportIncident failed", ex);
-        }
+        reportIncidentInternal(args);
     }
 
     /**
@@ -89,7 +76,7 @@
     })
     public void reportIncident(String settingName, byte[] headerProto) {
         // Sections
-        String setting = Settings.System.getString(mContext.getContentResolver(), settingName);
+        String setting = Settings.Global.getString(mContext.getContentResolver(), settingName);
         IncidentReportArgs args;
         try {
             args = IncidentReportArgs.parseSetting(setting);
@@ -98,23 +85,25 @@
             return;
         }
         if (args == null) {
-            Slog.i(TAG, "Incident report requested but disabled: " + settingName);
+            Slog.i(TAG, String.format("Incident report requested but disabled with "
+                    + "settings [name: %s, value: %s]", settingName, setting));
             return;
         }
 
-        // Header
         args.addHeader(headerProto);
 
-        // Look up the service
+        Slog.i(TAG, "Taking incident report: " + settingName);
+        reportIncidentInternal(args);
+    }
+
+    private void reportIncidentInternal(IncidentReportArgs args) {
         final IIncidentManager service = IIncidentManager.Stub.asInterface(
-                ServiceManager.getService("incident"));
+                ServiceManager.getService(Context.INCIDENT_SERVICE));
         if (service == null) {
             Slog.e(TAG, "reportIncident can't find incident binder service");
             return;
         }
 
-        // Call the service
-        Slog.i(TAG, "Taking incident report: " + settingName);
         try {
             service.reportIncident(args);
         } catch (RemoteException ex) {
diff --git a/core/java/android/os/IncidentReportArgs.java b/core/java/android/os/IncidentReportArgs.java
index ce2ae10..abb3161 100644
--- a/core/java/android/os/IncidentReportArgs.java
+++ b/core/java/android/os/IncidentReportArgs.java
@@ -18,7 +18,6 @@
 
 import android.annotation.SystemApi;
 import android.annotation.TestApi;
-import android.content.Intent;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.util.IntArray;
@@ -50,10 +49,12 @@
         readFromParcel(in);
     }
 
+    @Override
     public int describeContents() {
         return 0;
     }
 
+    @Override
     public void writeToParcel(Parcel out, int flags) {
         out.writeInt(mAll ? 1 : 0);
 
@@ -100,6 +101,7 @@
     /**
      * Print this report as a string.
      */
+    @Override
     public String toString() {
         final StringBuilder sb = new StringBuilder("Incident(");
         if (mAll) {
@@ -131,10 +133,11 @@
     }
 
     /**
-     * Add this section to the incident report.
+     * Add this section to the incident report. Skip if the input is smaller than 2 since section
+     * id are only valid for positive integer as Protobuf field id. Here 1 is reserved for Header.
      */
     public void addSection(int section) {
-        if (!mAll) {
+        if (!mAll && section > 1) {
             mSections.add(section);
         }
     }
diff --git a/core/java/android/util/BootTimingsTraceLog.java b/core/java/android/util/TimingsTraceLog.java
similarity index 64%
rename from core/java/android/util/BootTimingsTraceLog.java
rename to core/java/android/util/TimingsTraceLog.java
index 7a702a9..36e9f77 100644
--- a/core/java/android/util/BootTimingsTraceLog.java
+++ b/core/java/android/util/TimingsTraceLog.java
@@ -11,7 +11,7 @@
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
- * limitations under the License
+ * limitations under the License.
  */
 
 package android.util;
@@ -24,22 +24,26 @@
 import java.util.Deque;
 
 /**
- * Helper class for reporting boot timing metrics.
+ * Helper class for reporting boot and shutdown timing metrics.
  * @hide
  */
-public class BootTimingsTraceLog {
+public class TimingsTraceLog {
     // Debug boot time for every step if it's non-user build.
     private static final boolean DEBUG_BOOT_TIME = !Build.IS_USER;
-    private final Deque<Pair<String, Long>> mStartTimes
-            = DEBUG_BOOT_TIME ? new ArrayDeque<>() : null;
+    private final Deque<Pair<String, Long>> mStartTimes =
+            DEBUG_BOOT_TIME ? new ArrayDeque<>() : null;
     private final String mTag;
     private long mTraceTag;
 
-    public BootTimingsTraceLog(String tag, long traceTag) {
+    public TimingsTraceLog(String tag, long traceTag) {
         mTag = tag;
         mTraceTag = traceTag;
     }
 
+    /**
+     * Begin tracing named section
+     * @param name name to appear in trace
+     */
     public void traceBegin(String name) {
         Trace.traceBegin(mTraceTag, name);
         if (DEBUG_BOOT_TIME) {
@@ -47,6 +51,10 @@
         }
     }
 
+    /**
+     * End tracing previously {@link #traceBegin(String) started} section.
+     * Also {@link #logDuration logs} the duration.
+     */
     public void traceEnd() {
         Trace.traceEnd(mTraceTag);
         if (!DEBUG_BOOT_TIME) {
@@ -57,8 +65,13 @@
             return;
         }
         Pair<String, Long> event = mStartTimes.pop();
-        // Log the duration so it can be parsed by external tools for performance reporting
-        Slog.d(mTag, event.first + " took to complete: "
-                + (SystemClock.elapsedRealtime() - event.second) + "ms");
+        logDuration(event.first, (SystemClock.elapsedRealtime() - event.second));
+    }
+
+    /**
+     * Log the duration so it can be parsed by external tools for performance reporting
+     */
+    public void logDuration(String name, long timeMs) {
+        Slog.d(mTag, name + " took to complete: " + timeMs + "ms");
     }
 }
diff --git a/core/java/android/webkit/WebViewFactory.java b/core/java/android/webkit/WebViewFactory.java
index 6a48242..668cfba 100644
--- a/core/java/android/webkit/WebViewFactory.java
+++ b/core/java/android/webkit/WebViewFactory.java
@@ -47,7 +47,7 @@
     // visible for WebViewZygoteInit to look up the class by reflection and call preloadInZygote.
     /** @hide */
     private static final String CHROMIUM_WEBVIEW_FACTORY =
-            "com.android.webview.chromium.WebViewChromiumFactoryProviderForO";
+            "com.android.webview.chromium.WebViewChromiumFactoryProviderForOMR1";
 
     private static final String CHROMIUM_WEBVIEW_FACTORY_METHOD = "create";
 
diff --git a/core/java/android/widget/ArrayAdapter.java b/core/java/android/widget/ArrayAdapter.java
index 690067b..f18f217 100644
--- a/core/java/android/widget/ArrayAdapter.java
+++ b/core/java/android/widget/ArrayAdapter.java
@@ -152,7 +152,8 @@
     }
 
     /**
-     * Constructor
+     * Constructor. This constructor will result in the underlying data collection being
+     * immutable, so methods such as {@link #clear()} will throw an exception.
      *
      * @param context The current context.
      * @param resource The resource ID for a layout file containing a TextView to use when
@@ -164,7 +165,8 @@
     }
 
     /**
-     * Constructor
+     * Constructor. This constructor will result in the underlying data collection being
+     * immutable, so methods such as {@link #clear()} will throw an exception.
      *
      * @param context The current context.
      * @param resource The resource ID for a layout file containing a layout to use when
@@ -218,6 +220,7 @@
      * Adds the specified object at the end of the array.
      *
      * @param object The object to add at the end of the array.
+     * @throws UnsupportedOperationException if the underlying data collection is immutable
      */
     public void add(@Nullable T object) {
         synchronized (mLock) {
@@ -261,6 +264,7 @@
      * Adds the specified items at the end of the array.
      *
      * @param items The items to add at the end of the array.
+     * @throws UnsupportedOperationException if the underlying data collection is immutable
      */
     public void addAll(T ... items) {
         synchronized (mLock) {
@@ -279,6 +283,7 @@
      *
      * @param object The object to insert into the array.
      * @param index The index at which the object must be inserted.
+     * @throws UnsupportedOperationException if the underlying data collection is immutable
      */
     public void insert(@Nullable T object, int index) {
         synchronized (mLock) {
@@ -296,6 +301,7 @@
      * Removes the specified object from the array.
      *
      * @param object The object to remove.
+     * @throws UnsupportedOperationException if the underlying data collection is immutable
      */
     public void remove(@Nullable T object) {
         synchronized (mLock) {
@@ -311,6 +317,8 @@
 
     /**
      * Remove all elements from the list.
+     *
+     * @throws UnsupportedOperationException if the underlying data collection is immutable
      */
     public void clear() {
         synchronized (mLock) {
diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java
index 240271e..e32a99e 100644
--- a/core/java/android/widget/SelectionActionModeHelper.java
+++ b/core/java/android/widget/SelectionActionModeHelper.java
@@ -55,7 +55,7 @@
     // TODO: Consider making this a ViewConfiguration.
     private static final int TIMEOUT_DURATION = 200;
 
-    private static final boolean SMART_SELECT_ANIMATION_ENABLED = false;
+    private static final boolean SMART_SELECT_ANIMATION_ENABLED = true;
 
     private final Editor mEditor;
     private final TextClassificationHelper mTextClassificationHelper;
@@ -201,6 +201,17 @@
                 convertSelectionToRectangles(layout, result.mStart, result.mEnd);
 
         /*
+         * Do not run the Smart Select animation when there are multiple lines involved, as this
+         * behavior is currently broken.
+         *
+         * TODO fix Smart Select Animation when the selection spans multiple lines
+         */
+        if (selectionRectangles.size() != 1) {
+            onAnimationEndCallback.run();
+            return;
+        }
+
+        /*
          * TODO Figure out a more robust approach for this
          * We have to translate all the generated rectangles by the top-left padding of the
          * TextView because the padding influences the rendering of the ViewOverlay, but is not
diff --git a/core/java/com/android/internal/os/WrapperInit.java b/core/java/com/android/internal/os/WrapperInit.java
index 89328b2..4901080 100644
--- a/core/java/com/android/internal/os/WrapperInit.java
+++ b/core/java/com/android/internal/os/WrapperInit.java
@@ -23,7 +23,7 @@
 import android.system.OsConstants;
 import android.system.StructCapUserData;
 import android.system.StructCapUserHeader;
-import android.util.BootTimingsTraceLog;
+import android.util.TimingsTraceLog;
 import android.util.Slog;
 import dalvik.system.VMRuntime;
 import java.io.DataOutputStream;
@@ -80,7 +80,7 @@
         }
 
         // Mimic system Zygote preloading.
-        ZygoteInit.preload(new BootTimingsTraceLog("WrapperInitTiming",
+        ZygoteInit.preload(new TimingsTraceLog("WrapperInitTiming",
                 Trace.TRACE_TAG_DALVIK));
 
         // Launch the application.
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 948f203..25e90ad 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -43,7 +43,7 @@
 import android.system.Os;
 import android.system.OsConstants;
 import android.text.Hyphenator;
-import android.util.BootTimingsTraceLog;
+import android.util.TimingsTraceLog;
 import android.util.EventLog;
 import android.util.Log;
 import android.util.Slog;
@@ -54,7 +54,6 @@
 
 import com.android.internal.util.Preconditions;
 import dalvik.system.DexFile;
-import dalvik.system.PathClassLoader;
 import dalvik.system.VMRuntime;
 import dalvik.system.ZygoteHooks;
 
@@ -120,7 +119,7 @@
 
     private static boolean sPreloadComplete;
 
-    static void preload(BootTimingsTraceLog bootTimingsTraceLog) {
+    static void preload(TimingsTraceLog bootTimingsTraceLog) {
         Log.d(TAG, "begin preload");
         bootTimingsTraceLog.traceBegin("BeginIcuCachePinning");
         beginIcuCachePinning();
@@ -153,7 +152,7 @@
         Preconditions.checkState(!sPreloadComplete);
         Log.i(TAG, "Lazily preloading resources.");
 
-        preload(new BootTimingsTraceLog("ZygoteInitTiming_lazy", Trace.TRACE_TAG_DALVIK));
+        preload(new TimingsTraceLog("ZygoteInitTiming_lazy", Trace.TRACE_TAG_DALVIK));
     }
 
     private static void beginIcuCachePinning() {
@@ -719,7 +718,7 @@
             }
 
             String bootTimeTag = Process.is64Bit() ? "Zygote64Timing" : "Zygote32Timing";
-            BootTimingsTraceLog bootTimingsTraceLog = new BootTimingsTraceLog(bootTimeTag,
+            TimingsTraceLog bootTimingsTraceLog = new TimingsTraceLog(bootTimeTag,
                     Trace.TRACE_TAG_DALVIK);
             bootTimingsTraceLog.traceBegin("ZygoteInit");
             RuntimeInit.enableDdms();
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
index d8da5ed..49a076f 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
@@ -30,10 +30,9 @@
 import android.os.Trace;
 import android.os.UserHandle;
 import android.util.ArraySet;
-import android.util.BootTimingsTraceLog;
+import android.util.TimingsTraceLog;
 import android.util.Log;
 
-import com.android.systemui.fragments.FragmentService;
 import com.android.systemui.globalactions.GlobalActionsComponent;
 import com.android.systemui.keyboard.KeyboardUI;
 import com.android.systemui.keyguard.KeyguardViewMediator;
@@ -52,7 +51,6 @@
 import com.android.systemui.statusbar.CommandQueue;
 import com.android.systemui.statusbar.phone.StatusBar;
 import com.android.systemui.statusbar.phone.StatusBarWindowManager;
-import com.android.systemui.tuner.TunerService;
 import com.android.systemui.usb.StorageNotification;
 import com.android.systemui.util.NotificationChannels;
 import com.android.systemui.util.leak.GarbageMonitor;
@@ -194,7 +192,7 @@
 
         Log.v(TAG, "Starting SystemUI services for user " +
                 Process.myUserHandle().getIdentifier() + ".");
-        BootTimingsTraceLog log = new BootTimingsTraceLog("SystemUIBootTiming",
+        TimingsTraceLog log = new TimingsTraceLog("SystemUIBootTiming",
                 Trace.TRACE_TAG_APP);
         log.traceBegin("StartServices");
         final int N = services.length;
diff --git a/services/art-profile b/services/art-profile
index 140465a..28762a8 100644
--- a/services/art-profile
+++ b/services/art-profile
@@ -5445,7 +5445,7 @@
 PLcom/android/server/am/ActivityManagerService;->stopAssociationLocked(ILjava/lang/String;ILandroid/content/ComponentName;)V
 PLcom/android/server/am/ActivityManagerService;->stopService(Landroid/app/IApplicationThread;Landroid/content/Intent;Ljava/lang/String;I)I
 PLcom/android/server/am/ActivityManagerService;->stopServiceToken(Landroid/content/ComponentName;Landroid/os/IBinder;I)Z
-PLcom/android/server/am/ActivityManagerService;->systemReady(Ljava/lang/Runnable;Landroid/util/BootTimingsTraceLog;)V
+PLcom/android/server/am/ActivityManagerService;->systemReady(Ljava/lang/Runnable;Landroid/util/TimingsTraceLog;)V
 PLcom/android/server/am/ActivityManagerService;->trimApplications()V
 PLcom/android/server/am/ActivityManagerService;->uidOnBackgroundWhitelist(I)Z
 PLcom/android/server/am/ActivityManagerService;->unbindFinished(Landroid/os/IBinder;Landroid/content/Intent;Z)V
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 47f3ec6..90df649 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -338,7 +338,7 @@
 import android.util.ArrayMap;
 import android.util.ArraySet;
 import android.util.AtomicFile;
-import android.util.BootTimingsTraceLog;
+import android.util.TimingsTraceLog;
 import android.util.DebugUtils;
 import android.util.DisplayMetrics;
 import android.util.EventLog;
@@ -14054,7 +14054,7 @@
         }
     }
 
-    public void systemReady(final Runnable goingCallback, BootTimingsTraceLog traceLog) {
+    public void systemReady(final Runnable goingCallback, TimingsTraceLog traceLog) {
         traceLog.traceBegin("PhaseActivityManagerReady");
         synchronized(this) {
             if (mSystemReady) {
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 5dcd5f3..776ebf1 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -227,7 +227,7 @@
 import android.util.ArrayMap;
 import android.util.ArraySet;
 import android.util.Base64;
-import android.util.BootTimingsTraceLog;
+import android.util.TimingsTraceLog;
 import android.util.DisplayMetrics;
 import android.util.EventLog;
 import android.util.ExceptionUtils;
@@ -2940,7 +2940,7 @@
                     UserHandle.USER_SYSTEM, storageFlags, true /* migrateAppData */,
                     true /* onlyCoreApps */);
             mPrepareAppDataFuture = SystemServerInitThreadPool.get().submit(() -> {
-                BootTimingsTraceLog traceLog = new BootTimingsTraceLog("SystemServerTimingAsync",
+                TimingsTraceLog traceLog = new TimingsTraceLog("SystemServerTimingAsync",
                         Trace.TRACE_TAG_PACKAGE_MANAGER);
                 traceLog.traceBegin("AppDataFixup");
                 try {
diff --git a/services/core/java/com/android/server/power/ShutdownThread.java b/services/core/java/com/android/server/power/ShutdownThread.java
index d0ca57a..d1a5953 100644
--- a/services/core/java/com/android/server/power/ShutdownThread.java
+++ b/services/core/java/com/android/server/power/ShutdownThread.java
@@ -45,16 +45,15 @@
 import android.os.SystemClock;
 import android.os.SystemProperties;
 import android.os.SystemVibrator;
+import android.os.Trace;
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.os.Vibrator;
 import android.os.storage.IStorageManager;
 import android.os.storage.IStorageShutdownObserver;
 import android.util.Log;
-import android.view.ViewGroup;
+import android.util.TimingsTraceLog;
 import android.view.WindowManager;
-import android.widget.ProgressBar;
-import android.widget.TextView;
 
 import com.android.internal.telephony.ITelephony;
 import com.android.server.RescueParty;
@@ -108,6 +107,9 @@
             .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
             .build();
 
+    private static final TimingsTraceLog SHUTDOWN_TIMINGS_LOG = new TimingsTraceLog(
+            "ShutdownTiming", Trace.TRACE_TAG_SYSTEM_SERVER);
+
     private final Object mActionDoneSync = new Object();
     private boolean mActionDone;
     private Context mContext;
@@ -346,6 +348,7 @@
     }
 
     private static void beginShutdownSequence(Context context) {
+        SHUTDOWN_TIMINGS_LOG.traceBegin("SystemServerShutdown");
         synchronized (sIsStartedGuard) {
             if (sIsStarted) {
                 Log.d(TAG, "Shutdown sequence already running, returning.");
@@ -427,6 +430,7 @@
             SystemProperties.set(REBOOT_SAFEMODE_PROPERTY, "1");
         }
 
+        SHUTDOWN_TIMINGS_LOG.traceBegin("SendShutdownBroadcast");
         Log.i(TAG, "Sending shutdown broadcast...");
 
         // First send the high-level shut down broadcast.
@@ -458,8 +462,10 @@
         if (mRebootHasProgressBar) {
             sInstance.setRebootProgress(BROADCAST_STOP_PERCENT, null);
         }
+        SHUTDOWN_TIMINGS_LOG.traceEnd(); // SendShutdownBroadcast
 
         Log.i(TAG, "Shutting down activity manager...");
+        SHUTDOWN_TIMINGS_LOG.traceBegin("ShutdownActivityManager");
 
         final IActivityManager am =
                 IActivityManager.Stub.asInterface(ServiceManager.checkService("activity"));
@@ -472,8 +478,10 @@
         if (mRebootHasProgressBar) {
             sInstance.setRebootProgress(ACTIVITY_MANAGER_STOP_PERCENT, null);
         }
+        SHUTDOWN_TIMINGS_LOG.traceEnd(); // ShutdownActivityManager
 
         Log.i(TAG, "Shutting down package manager...");
+        SHUTDOWN_TIMINGS_LOG.traceBegin("ShutdownPackageManager");
 
         final PackageManagerService pm = (PackageManagerService)
             ServiceManager.getService("package");
@@ -483,12 +491,15 @@
         if (mRebootHasProgressBar) {
             sInstance.setRebootProgress(PACKAGE_MANAGER_STOP_PERCENT, null);
         }
+        SHUTDOWN_TIMINGS_LOG.traceEnd(); // ShutdownPackageManager
 
         // Shutdown radios.
+        SHUTDOWN_TIMINGS_LOG.traceBegin("ShutdownRadios");
         shutdownRadios(MAX_RADIO_WAIT_TIME);
         if (mRebootHasProgressBar) {
             sInstance.setRebootProgress(RADIO_STOP_PERCENT, null);
         }
+        SHUTDOWN_TIMINGS_LOG.traceEnd(); // ShutdownRadios
 
         // Shutdown StorageManagerService to ensure media is in a safe state
         IStorageShutdownObserver observer = new IStorageShutdownObserver.Stub() {
@@ -499,6 +510,7 @@
         };
 
         Log.i(TAG, "Shutting down StorageManagerService");
+        SHUTDOWN_TIMINGS_LOG.traceBegin("ShutdownStorageManager");
 
         // Set initial variables and time out time.
         mActionDone = false;
@@ -518,7 +530,7 @@
             while (!mActionDone) {
                 long delay = endShutTime - SystemClock.elapsedRealtime();
                 if (delay <= 0) {
-                    Log.w(TAG, "Shutdown wait timed out");
+                    Log.w(TAG, "StorageManager shutdown wait timed out");
                     break;
                 } else if (mRebootHasProgressBar) {
                     int status = (int)((MAX_SHUTDOWN_WAIT_TIME - delay) * 1.0 *
@@ -533,6 +545,8 @@
                 }
             }
         }
+        SHUTDOWN_TIMINGS_LOG.traceEnd(); // ShutdownStorageManager
+
         if (mRebootHasProgressBar) {
             sInstance.setRebootProgress(MOUNT_SERVICE_STOP_PERCENT, null);
 
@@ -576,7 +590,7 @@
                 final IBluetoothManager bluetooth =
                         IBluetoothManager.Stub.asInterface(ServiceManager.checkService(
                                 BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE));
-
+                final long nfcShutdownStarted = SystemClock.elapsedRealtime();
                 try {
                     nfcOff = nfc == null ||
                              nfc.getState() == NfcAdapter.STATE_OFF;
@@ -589,6 +603,7 @@
                     nfcOff = true;
                 }
 
+                final long btShutdownStarted = SystemClock.elapsedRealtime();
                 try {
                     bluetoothReadyForShutdown = bluetooth == null ||
                             bluetooth.getState() == BluetoothAdapter.STATE_OFF;
@@ -601,6 +616,7 @@
                     bluetoothReadyForShutdown = true;
                 }
 
+                final long radioShutdownStarted = SystemClock.elapsedRealtime();
                 try {
                     radioOff = phone == null || !phone.needMobileRadioShutdown();
                     if (!radioOff) {
@@ -637,6 +653,8 @@
                         }
                         if (bluetoothReadyForShutdown) {
                             Log.i(TAG, "Bluetooth turned off.");
+                            SHUTDOWN_TIMINGS_LOG.logDuration("ShutdownBt",
+                                    SystemClock.elapsedRealtime() - btShutdownStarted);
                         }
                     }
                     if (!radioOff) {
@@ -648,6 +666,8 @@
                         }
                         if (radioOff) {
                             Log.i(TAG, "Radio turned off.");
+                            SHUTDOWN_TIMINGS_LOG.logDuration("ShutdownRadio",
+                                    SystemClock.elapsedRealtime() - radioShutdownStarted);
                         }
                     }
                     if (!nfcOff) {
@@ -659,6 +679,8 @@
                         }
                         if (nfcOff) {
                             Log.i(TAG, "NFC turned off.");
+                            SHUTDOWN_TIMINGS_LOG.logDuration("ShutdownNfc",
+                                    SystemClock.elapsedRealtime() - nfcShutdownStarted);
                         }
                     }
 
@@ -714,7 +736,7 @@
             } catch (InterruptedException unused) {
             }
         }
-
+        SHUTDOWN_TIMINGS_LOG.traceEnd(); // SystemServerShutdown
         // Shutdown power
         Log.i(TAG, "Performing low-level shutdown...");
         PowerManagerService.lowLevelShutdown(reason);
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index a1b9099..569b326 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -45,7 +45,7 @@
 import android.os.Trace;
 import android.os.UserHandle;
 import android.os.storage.IStorageManager;
-import android.util.BootTimingsTraceLog;
+import android.util.TimingsTraceLog;
 import android.util.DisplayMetrics;
 import android.util.EventLog;
 import android.util.Slog;
@@ -121,7 +121,6 @@
 import java.io.IOException;
 import java.util.Locale;
 import java.util.Timer;
-import java.util.TimerTask;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Future;
 
@@ -135,8 +134,8 @@
     // Tag for timing measurement of non-main asynchronous operations.
     private static final String SYSTEM_SERVER_TIMING_ASYNC_TAG = SYSTEM_SERVER_TIMING_TAG + "Async";
 
-    private static final BootTimingsTraceLog BOOT_TIMINGS_TRACE_LOG
-            = new BootTimingsTraceLog(SYSTEM_SERVER_TIMING_TAG, Trace.TRACE_TAG_SYSTEM_SERVER);
+    private static final TimingsTraceLog BOOT_TIMINGS_TRACE_LOG
+            = new TimingsTraceLog(SYSTEM_SERVER_TIMING_TAG, Trace.TRACE_TAG_SYSTEM_SERVER);
 
     private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
     private static final String ENCRYPTED_STATE = "1";
@@ -638,7 +637,7 @@
         // Start sensor service in a separate thread. Completion should be checked
         // before using it.
         mSensorServiceStart = SystemServerInitThreadPool.get().submit(() -> {
-            BootTimingsTraceLog traceLog = new BootTimingsTraceLog(
+            TimingsTraceLog traceLog = new TimingsTraceLog(
                     SYSTEM_SERVER_TIMING_ASYNC_TAG, Trace.TRACE_TAG_SYSTEM_SERVER);
             traceLog.traceBegin(START_SENSOR_SERVICE);
             startSensorService();
@@ -736,7 +735,7 @@
             mZygotePreload = SystemServerInitThreadPool.get().submit(() -> {
                 try {
                     Slog.i(TAG, SECONDARY_ZYGOTE_PRELOAD);
-                    BootTimingsTraceLog traceLog = new BootTimingsTraceLog(
+                    TimingsTraceLog traceLog = new TimingsTraceLog(
                             SYSTEM_SERVER_TIMING_ASYNC_TAG, Trace.TRACE_TAG_SYSTEM_SERVER);
                     traceLog.traceBegin(SECONDARY_ZYGOTE_PRELOAD);
                     if (!Process.zygoteProcess.preloadDefault(Build.SUPPORTED_32_BIT_ABIS[0])) {
@@ -1686,7 +1685,7 @@
             if (!mOnlyCore) {
                 webviewPrep = SystemServerInitThreadPool.get().submit(() -> {
                     Slog.i(TAG, WEBVIEW_PREPARATION);
-                    BootTimingsTraceLog traceLog = new BootTimingsTraceLog(
+                    TimingsTraceLog traceLog = new TimingsTraceLog(
                             SYSTEM_SERVER_TIMING_ASYNC_TAG, Trace.TRACE_TAG_SYSTEM_SERVER);
                     traceLog.traceBegin(WEBVIEW_PREPARATION);
                     ConcurrentUtils.waitForFutureNoInterrupt(mZygotePreload, "Zygote preload");
@@ -1842,7 +1841,7 @@
                 // TODO: Switch from checkService to getService once it's always
                 // in the build and should reliably be there.
                 final IIncidentManager incident = IIncidentManager.Stub.asInterface(
-                        ServiceManager.checkService("incident"));
+                        ServiceManager.getService(Context.INCIDENT_SERVICE));
                 if (incident != null) incident.systemRunning();
             } catch (Throwable e) {
                 reportWtf("Notifying incident daemon running", e);
diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java
index e3b027a..f78e4276 100644
--- a/telecomm/java/android/telecom/ConnectionService.java
+++ b/telecomm/java/android/telecom/ConnectionService.java
@@ -1440,6 +1440,12 @@
      */
     private void notifyCreateConnectionComplete(final String callId) {
         Log.i(this, "notifyCreateConnectionComplete %s", callId);
+        if (callId == null) {
+            // This could happen if the connection fails quickly and is removed from the
+            // ConnectionService before Telecom sends the create connection complete callback.
+            Log.w(this, "notifyCreateConnectionComplete: callId is null.");
+            return;
+        }
         onCreateConnectionComplete(findConnectionForAction(callId,
                 "notifyCreateConnectionComplete"));
     }
@@ -2166,7 +2172,7 @@
     }
 
     private Connection findConnectionForAction(String callId, String action) {
-        if (mConnectionById.containsKey(callId)) {
+        if (callId != null && mConnectionById.containsKey(callId)) {
             return mConnectionById.get(callId);
         }
         Log.w(this, "%s - Cannot find Connection %s", action, callId);
diff --git a/tools/incident_report/main.cpp b/tools/incident_report/main.cpp
index 78e5c05..250d118 100644
--- a/tools/incident_report/main.cpp
+++ b/tools/incident_report/main.cpp
@@ -97,6 +97,8 @@
                     message->addInt64(fieldId, value64);
                     break;
                 } else {
+                    fprintf(stderr, "bad VARINT: 0x%x (%d) at index %d\n", tag, tag,
+                                                    in->CurrentPosition());
                     return false;
                 }
             case WireFormatLite::WIRETYPE_FIXED64:
@@ -104,10 +106,14 @@
                     message->addInt64(fieldId, value64);
                     break;
                 } else {
+                    fprintf(stderr, "bad VARINT: 0x%x (%d) at index %d\n", tag, tag,
+                            in->CurrentPosition());
                     return false;
                 }
             case WireFormatLite::WIRETYPE_LENGTH_DELIMITED:
                 if (!read_length_delimited(in, fieldId, descriptor, message)) {
+                    fprintf(stderr, "bad LENGTH_DELIMITED: 0x%x (%d) at index %d\n",
+                            tag, tag, in->CurrentPosition());
                     return false;
                 }
                 break;
@@ -116,6 +122,8 @@
                     message->addInt32(fieldId, value32);
                     break;
                 } else {
+                    fprintf(stderr, "bad FIXED32: 0x%x (%d) at index %d\n", tag, tag,
+                            in->CurrentPosition());
                     return false;
                 }
             default:
@@ -146,7 +154,7 @@
                     out->printf("%f", *(float*)&node.value32);
                     break;
                 default:
-                    out->printf("(unexpected value %d (0x%x)", node.value32, node.value32);
+                    out->printf("(unexpected value32 %d (0x%x)", node.value32, node.value32);
                     break;
             }
             break;
@@ -177,8 +185,11 @@
                     }
                     break;
                 case FieldDescriptor::TYPE_ENUM:
+                    out->printf("%s", field->enum_type()->FindValueByNumber((int)node.value64)
+                            ->name().c_str());
+                    break;
                 default:
-                    out->printf("(unexpected value %ld (0x%x))", node.value64, node.value64);
+                    out->printf("(unexpected value64 %ld (0x%x))", node.value64, node.value64);
                     break;
             }
             break;