am 973d9ace: Merge "grouper: label boot block device"

* commit '973d9ace4ab733c2220713d0624e5014bccbf148':
  grouper: label boot block device
diff --git a/BoardConfig.mk b/BoardConfig.mk
index 72bb7be..48bc59d 100644
--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -33,8 +33,6 @@
 
 BOARD_HAL_STATIC_LIBRARIES := libdumpstate.grouper
 
-TARGET_RECOVERY_UI_LIB := librecovery_ui_grouper
-
 TARGET_RELEASETOOLS_EXTENSIONS := device/asus/grouper
 
 -include vendor/asus/grouper/BoardConfigVendor.mk
diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk
index 27b343c..d9e18e9 100644
--- a/BoardConfigCommon.mk
+++ b/BoardConfigCommon.mk
@@ -38,6 +38,8 @@
 TARGET_USERIMAGES_USE_EXT4 := true
 
 BOARD_SYSTEMIMAGE_PARTITION_SIZE := 681574400
+# Disable journaling on system.img to save space.
+BOARD_SYSTEMIMAGE_JOURNAL_SIZE := 0
 BOARD_USERDATAIMAGE_PARTITION_SIZE := 6567231488
 BOARD_FLASH_BLOCK_SIZE := 4096
 
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index bcec532..53daadb 100644
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -49,7 +49,8 @@
 #define OUT_SAMPLING_RATE 44100
 
 #define IN_PERIOD_SIZE 1024
-#define IN_PERIOD_COUNT 4
+#define IN_PERIOD_SIZE_LOW_LATENCY 512
+#define IN_PERIOD_COUNT 2
 #define IN_SAMPLING_RATE 44100
 
 #define SCO_PERIOD_SIZE 256
@@ -86,6 +87,16 @@
     .stop_threshold = (IN_PERIOD_SIZE * IN_PERIOD_COUNT),
 };
 
+struct pcm_config pcm_config_in_low_latency = {
+    .channels = 2,
+    .rate = IN_SAMPLING_RATE,
+    .period_size = IN_PERIOD_SIZE_LOW_LATENCY,
+    .period_count = IN_PERIOD_COUNT,
+    .format = PCM_FORMAT_S16_LE,
+    .start_threshold = 1,
+    .stop_threshold = (IN_PERIOD_SIZE_LOW_LATENCY * IN_PERIOD_COUNT),
+};
+
 struct pcm_config pcm_config_sco = {
     .channels = 1,
     .rate = SCO_SAMPLING_RATE,
@@ -135,7 +146,8 @@
 
     pthread_mutex_t lock; /* see note below on mutex acquisition order */
     struct pcm *pcm;
-    struct pcm_config *pcm_config;
+    struct pcm_config *pcm_config;          /* current configuration */
+    struct pcm_config *pcm_config_non_sco;  /* configuration to return after SCO is done */
     bool standby;
 
     unsigned int requested_rate;
@@ -338,7 +350,7 @@
         in->pcm_config = &pcm_config_sco;
     } else {
         device = PCM_DEVICE;
-        in->pcm_config = &pcm_config_in;
+        in->pcm_config = in->pcm_config_non_sco;
     }
 
     /*
@@ -463,7 +475,7 @@
         if (in->resampler != NULL) {
             in->resampler->resample_from_provider(in->resampler,
                     (int16_t *)((char *)buffer +
-                            frames_wr * audio_stream_frame_size(&in->stream.common)),
+                            frames_wr * audio_stream_in_frame_size(&in->stream)),
                     &frames_rd);
         } else {
             struct resampler_buffer buf = {
@@ -473,9 +485,9 @@
             get_next_buffer(&in->buf_provider, &buf);
             if (buf.raw != NULL) {
                 memcpy((char *)buffer +
-                           frames_wr * audio_stream_frame_size(&in->stream.common),
+                           frames_wr * audio_stream_in_frame_size(&in->stream),
                         buf.raw,
-                        buf.frame_count * audio_stream_frame_size(&in->stream.common));
+                        buf.frame_count * audio_stream_in_frame_size(&in->stream));
                 frames_rd = buf.frame_count;
             }
             release_buffer(&in->buf_provider, &buf);
@@ -505,7 +517,7 @@
 static size_t out_get_buffer_size(const struct audio_stream *stream)
 {
     return pcm_config_out.period_size *
-               audio_stream_frame_size((struct audio_stream *)stream);
+               audio_stream_out_frame_size((const struct audio_stream_out *)stream);
 }
 
 static uint32_t out_get_channels(const struct audio_stream *stream)
@@ -614,7 +626,7 @@
     int ret = 0;
     struct stream_out *out = (struct stream_out *)stream;
     struct audio_device *adev = out->dev;
-    size_t frame_size = audio_stream_frame_size(&out->stream.common);
+    size_t frame_size = audio_stream_out_frame_size(stream);
     int16_t *in_buffer = (int16_t *)buffer;
     size_t in_frames = bytes / frame_size;
     size_t out_frames;
@@ -661,7 +673,7 @@
     }
 
     /* Reduce number of channels, if necessary */
-    if (popcount(out_get_channels(&stream->common)) >
+    if (audio_channel_count_from_out_mask(out_get_channels(&stream->common)) >
                  (int)out->pcm_config->channels) {
         unsigned int i;
 
@@ -756,7 +768,7 @@
     pthread_mutex_unlock(&out->lock);
 
     if (ret != 0) {
-        usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
+        usleep(bytes * 1000000 / audio_stream_out_frame_size(&stream->common) /
                out_get_sample_rate(&stream->common));
     }
 
@@ -837,7 +849,7 @@
             in->pcm_config->rate;
     size = ((size + 15) / 16) * 16;
 
-    return size * audio_stream_frame_size((struct audio_stream *)stream);
+    return size * audio_stream_in_frame_size(&in->stream);
 }
 
 static uint32_t in_get_channels(const struct audio_stream *stream)
@@ -928,7 +940,7 @@
     int ret = 0;
     struct stream_in *in = (struct stream_in *)stream;
     struct audio_device *adev = in->dev;
-    size_t frames_rq = bytes / audio_stream_frame_size(&stream->common);
+    size_t frames_rq = bytes / audio_stream_in_frame_size(stream);
 
     /*
      * acquiring hw device mutex systematically is useful if a low
@@ -981,7 +993,7 @@
 
 exit:
     if (ret < 0)
-        usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
+        usleep(bytes * 1000000 / audio_stream_in_frame_size(stream) /
                in_get_sample_rate(&stream->common));
 
     pthread_mutex_unlock(&in->lock);
@@ -1011,7 +1023,8 @@
                                    audio_devices_t devices,
                                    audio_output_flags_t flags,
                                    struct audio_config *config,
-                                   struct audio_stream_out **stream_out)
+                                   struct audio_stream_out **stream_out,
+                                   const char *address __unused)
 {
     struct audio_device *adev = (struct audio_device *)dev;
     struct stream_out *out;
@@ -1171,7 +1184,7 @@
     size = (pcm_config_in.period_size * config->sample_rate) / pcm_config_in.rate;
     size = ((size + 15) / 16) * 16;
 
-    return (size * popcount(config->channel_mask) *
+    return (size * audio_channel_count_from_in_mask(config->channel_mask) *
                 audio_bytes_per_sample(config->format));
 }
 
@@ -1179,7 +1192,10 @@
                                   audio_io_handle_t handle,
                                   audio_devices_t devices,
                                   struct audio_config *config,
-                                  struct audio_stream_in **stream_in)
+                                  struct audio_stream_in **stream_in,
+                                  audio_input_flags_t flags,
+                                  const char *address __unused,
+                                  audio_source_t source __unused)
 {
     struct audio_device *adev = (struct audio_device *)dev;
     struct stream_in *in;
@@ -1216,7 +1232,10 @@
     in->dev = adev;
     in->standby = true;
     in->requested_rate = config->sample_rate;
-    in->pcm_config = &pcm_config_in; /* default PCM config */
+    /* default PCM config */
+    in->pcm_config = (config->sample_rate == IN_SAMPLING_RATE) && (flags & AUDIO_INPUT_FLAG_FAST) ?
+            &pcm_config_in_low_latency : &pcm_config_in;
+    in->pcm_config_non_sco = in->pcm_config;
 
     *stream_in = &in->stream;
     return 0;
diff --git a/audio_policy.conf b/audio_policy.conf
index 3cc637d..ed5b00a 100644
--- a/audio_policy.conf
+++ b/audio_policy.conf
@@ -58,12 +58,20 @@
         devices AUDIO_DEVICE_OUT_USB_ACCESSORY
       }
       usb_device {
-        sampling_rates 44100
+        sampling_rates dynamic
         channel_masks AUDIO_CHANNEL_OUT_STEREO
-        formats AUDIO_FORMAT_PCM_16_BIT
+        formats dynamic
         devices AUDIO_DEVICE_OUT_USB_DEVICE
       }
     }
+    inputs {
+      usb_device {
+        sampling_rates dynamic
+        channel_masks AUDIO_CHANNEL_IN_STEREO
+        formats AUDIO_FORMAT_PCM_16_BIT
+        devices AUDIO_DEVICE_IN_USB_DEVICE
+      }
+    }
   }
   r_submix {
     outputs {
diff --git a/device-common.mk b/device-common.mk
index eb11af8..a940f26 100644
--- a/device-common.mk
+++ b/device-common.mk
@@ -20,16 +20,22 @@
   LOCAL_KERNEL := $(TARGET_PREBUILT_KERNEL)
 endif
 
-PRODUCT_AAPT_CONFIG := normal large tvdpi hdpi
+PRODUCT_AAPT_CONFIG := normal large
 PRODUCT_AAPT_PREF_CONFIG := tvdpi
-
+# A list of dpis to select prebuilt apk, in precedence order.
+PRODUCT_AAPT_PREBUILT_DPI := hdpi
 
 PRODUCT_PROPERTY_OVERRIDES := \
     wifi.interface=wlan0 \
     wifi.supplicant_scan_interval=15 \
     tf.enable=y \
+    persist.sys.media.legacy-drm=true \
     drm.service.enabled=true
 
+# libhwui flags
+PRODUCT_PROPERTY_OVERRIDES += \
+    debug.hwui.render_dirty_regions=false
+
 # Set default USB interface
 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += \
     persist.sys.usb.config=mtp
@@ -59,7 +65,8 @@
     frameworks/native/data/etc/android.hardware.touchscreen.multitouch.jazzhand.xml:system/etc/permissions/android.hardware.touchscreen.multitouch.jazzhand.xml \
     frameworks/native/data/etc/android.software.sip.voip.xml:system/etc/permissions/android.software.sip.voip.xml \
     frameworks/native/data/etc/android.hardware.usb.host.xml:system/etc/permissions/android.hardware.usb.host.xml \
-    frameworks/native/data/etc/android.hardware.usb.accessory.xml:system/etc/permissions/android.hardware.usb.accessory.xml
+    frameworks/native/data/etc/android.hardware.usb.accessory.xml:system/etc/permissions/android.hardware.usb.accessory.xml \
+    frameworks/native/data/etc/android.hardware.ethernet.xml:system/etc/permissions/android.hardware.ethernet.xml
 
 PRODUCT_COPY_FILES += \
     device/asus/grouper/elan-touchscreen.idc:system/usr/idc/elan-touchscreen.idc \
@@ -82,7 +89,6 @@
     audio.usb.default \
     audio.r_submix.default \
     librs_jni \
-    setup_fs \
     l2ping \
     hcitool \
     bttest \
@@ -95,8 +101,12 @@
 PRODUCT_PACKAGES += \
     nfc.grouper \
     Nfc \
-    Tag \
-    com.android.nfc_extras
+    Tag
+
+# Filesystem management tools
+PRODUCT_PACKAGES += \
+    e2fsck \
+    setup_fs
 
 PRODUCT_CHARACTERISTICS := tablet,nosdcard
 
@@ -106,6 +116,9 @@
 
 # media codec config xml file
 PRODUCT_COPY_FILES += \
+    frameworks/av/media/libstagefright/data/media_codecs_google_audio.xml:system/etc/media_codecs_google_audio.xml \
+    frameworks/av/media/libstagefright/data/media_codecs_google_telephony.xml:system/etc/media_codecs_google_telephony.xml \
+    frameworks/av/media/libstagefright/data/media_codecs_google_video.xml:system/etc/media_codecs_google_video.xml \
     device/asus/grouper/media_codecs.xml:system/etc/media_codecs.xml
 
 # audio mixer paths
@@ -118,17 +131,7 @@
 
 PRODUCT_COPY_FILES += \
     frameworks/native/data/etc/com.nxp.mifare.xml:system/etc/permissions/com.nxp.mifare.xml \
-    frameworks/native/data/etc/com.android.nfc_extras.xml:system/etc/permissions/com.android.nfc_extras.xml \
     frameworks/native/data/etc/android.hardware.nfc.xml:system/etc/permissions/android.hardware.nfc.xml
 
-# NFCEE access control
-ifeq ($(TARGET_BUILD_VARIANT),user)
-    NFCEE_ACCESS_PATH := device/asus/grouper/nfcee_access.xml
-else
-    NFCEE_ACCESS_PATH := device/asus/grouper/nfcee_access_debug.xml
-endif
-PRODUCT_COPY_FILES += \
-    $(NFCEE_ACCESS_PATH):system/etc/nfcee_access.xml
-
 WIFI_BAND := 802_11_BG
  $(call inherit-product-if-exists, hardware/broadcom/wlan/bcmdhd/firmware/bcm4330/device-bcm.mk)
diff --git a/fstab.grouper b/fstab.grouper
index c1bddbc..3948ebf 100644
--- a/fstab.grouper
+++ b/fstab.grouper
@@ -5,8 +5,8 @@
 
 
 /dev/block/platform/sdhci-tegra.3/by-name/APP           /system             ext4      ro                                                            wait
-/dev/block/platform/sdhci-tegra.3/by-name/CAC           /cache              ext4      noatime,nosuid,nodev,nomblk_io_submit,errors=panic    wait
-/dev/block/platform/sdhci-tegra.3/by-name/UDA           /data               ext4      noatime,nosuid,nodev,nomblk_io_submit,errors=panic    wait,encryptable=/dev/block/platform/sdhci-tegra.3/by-name/MDA
+/dev/block/platform/sdhci-tegra.3/by-name/CAC           /cache              ext4      noatime,nosuid,nodev,nomblk_io_submit,errors=panic    wait,check
+/dev/block/platform/sdhci-tegra.3/by-name/UDA           /data               ext4      noatime,nosuid,nodev,nomblk_io_submit,errors=panic    wait,check,encryptable=/dev/block/platform/sdhci-tegra.3/by-name/MDA
 /dev/block/platform/sdhci-tegra.3/by-name/MSC           /misc               emmc      defaults                                                      defaults
 /dev/block/platform/sdhci-tegra.3/by-name/LNX           /boot               emmc      defaults                                                      defaults
 /dev/block/platform/sdhci-tegra.3/by-name/SOS           /recovery           emmc      defaults                                                      defaults
diff --git a/gpio-keys.kl b/gpio-keys.kl
index 95287bc..9bc6891 100644
--- a/gpio-keys.kl
+++ b/gpio-keys.kl
@@ -1,4 +1,4 @@
-key 116   POWER             WAKE
-key 115   VOLUME_UP         WAKE_DROPPED
-key 114   VOLUME_DOWN       WAKE_DROPPED
+key 116   POWER
+key 115   VOLUME_UP
+key 114   VOLUME_DOWN
 
diff --git a/init.grouper.rc b/init.grouper.rc
index e6b1e9f..e44ac19 100644
--- a/init.grouper.rc
+++ b/init.grouper.rc
@@ -46,6 +46,11 @@
     mkdir /data/calibration
     mkdir /data/amit
 
+    # gps
+    mkdir /data/gps
+    chown gps system /data/gps
+    chmod 770 /data/gps
+
     # Set indication (checked by vold) that we have finished this action
     setprop vold.post_fs_data_done 1
 
@@ -250,6 +255,10 @@
 # Interactive governor settings
     chown system system /sys/devices/system/cpu/cpufreq/interactive/boost_factor
     chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boost_factor
+    chown system system /sys/devices/system/cpu/cpufreq/interactive/core_lock_count
+    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/core_lock_count
+    chown system system /sys/devices/system/cpu/cpufreq/interactive/core_lock_period
+    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/core_lock_period
     chown system system /sys/devices/system/cpu/cpufreq/interactive/go_maxspeed_load
     chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/go_maxspeed_load
     chown system system /sys/devices/system/cpu/cpufreq/interactive/io_is_busy
@@ -285,9 +294,6 @@
     write /sys/class/gpio/gpio162/direction out
     chown gps system /sys/class/gpio/gpio162/value
     chmod 0664 /sys/class/gpio/gpio162/value
-    mkdir /data/gps
-    chown gps system /data/gps
-    chmod 770 /data/gps
     chown gps system /dev/ttyHS1
     chmod 0660 /dev/ttyHS1
 
@@ -305,7 +311,6 @@
 service wpa_supplicant /system/bin/wpa_supplicant \
     -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
     -I/system/etc/wifi/wpa_supplicant_overlay.conf \
-    -O/data/misc/wifi/sockets \
     -e/data/misc/wifi/entropy.bin -g@android:wpa_wlan0
     #   we will start as root and wpa_supplicant will switch to user wifi
     #   after setting up the capabilities required for WEXT
@@ -318,8 +323,7 @@
 
 service p2p_supplicant /system/bin/wpa_supplicant \
     -iwlan0 -Dnl80211 -iwlan0 -c/data/misc/wifi/wpa_supplicant.conf \
-    -I/system/etc/wifi/wpa_supplicant_overlay.conf \
-    -O/data/misc/wifi/sockets -N \
+    -I/system/etc/wifi/wpa_supplicant_overlay.conf -N \
     -ip2p0 -Dnl80211 -c /data/misc/wifi/p2p_supplicant.conf \
     -I/system/etc/wifi/p2p_supplicant_overlay.conf \
     -puse_p2p_group_interface=1 -e/data/misc/wifi/entropy.bin \
@@ -381,21 +385,19 @@
 #Sensor load calibration files end
 
 # virtual sdcard daemon running as media_rw (1023)
-service sdcard /system/bin/sdcard -u 1023 -g 1023 -l /data/media /mnt/shell/emulated
+service sdcard /system/bin/sdcard -u 1023 -g 1023 -t 4 -l /data/media /mnt/shell/emulated
     class late_start
 
 # bugreport is triggered by the VOLUME-DOWN and VOLUME-UP keys
 service bugreport /system/bin/dumpstate -d -p -B \
-        -o /data/data/com.android.shell/files/bugreports/bugreport \
-        -b /system/media/audio/ui/Dock.ogg -e /system/media/audio/ui/Undock.ogg
+        -o /data/data/com.android.shell/files/bugreports/bugreport
     class main
     disabled
     oneshot
     keycodes 115 114
 
 # Start GPS daemon
-  on boot
-  service gps-daemon /system/bin/glgps -c /system/etc/gps/gpsconfig.xml
+service gps-daemon /system/bin/glgps -c /system/etc/gps/gpsconfig.xml
   user gps
   group system
   class late_start
diff --git a/kernel b/kernel
index a60497e..3b6c49e 100644
--- a/kernel
+++ b/kernel
Binary files differ
diff --git a/keymaster/keymaster_grouper.cpp b/keymaster/keymaster_grouper.cpp
index c9c23af..6cf102d 100644
--- a/keymaster/keymaster_grouper.cpp
+++ b/keymaster/keymaster_grouper.cpp
@@ -36,7 +36,7 @@
 #include <cryptoki.h>
 #include <pkcs11.h>
 
-#include <utils/UniquePtr.h>
+#include <UniquePtr.h>
 
 
 /** The size of a key ID in bytes */
@@ -910,6 +910,7 @@
     dev->common.version = 1;
     dev->common.module = (struct hw_module_t*) module;
     dev->common.close = tee_close;
+    dev->flags = 0;
 
     dev->generate_keypair = tee_generate_keypair;
     dev->import_keypair = tee_import_keypair;
@@ -969,8 +970,8 @@
 __attribute__ ((visibility ("default"))) = {
     common: {
         tag: HARDWARE_MODULE_TAG,
-        version_major: 1,
-        version_minor: 0,
+        module_api_version: KEYMASTER_MODULE_API_VERSION_0_3,
+        hal_api_version: HARDWARE_HAL_API_VERSION,
         id: KEYSTORE_HARDWARE_MODULE_ID,
         name: "Keymaster TEE HAL",
         author: "The Android Open Source Project",
diff --git a/media_codecs.xml b/media_codecs.xml
index c55db6e..e824924 100644
--- a/media_codecs.xml
+++ b/media_codecs.xml
@@ -16,10 +16,12 @@
 
 <!--
 <!DOCTYPE MediaCodecs [
-<!ELEMENT MediaCodecs (Decoders,Encoders)>
-<!ELEMENT Decoders (MediaCodec*)>
-<!ELEMENT Encoders (MediaCodec*)>
-<!ELEMENT MediaCodec (Type*,Quirk*)>
+<!ELEMENT Include EMPTY>
+<!ATTLIST Include href CDATA #REQUIRED>
+<!ELEMENT MediaCodecs (Decoders|Encoders|Include)*>
+<!ELEMENT Decoders (MediaCodec|Include)*>
+<!ELEMENT Encoders (MediaCodec|Include)*>
+<!ELEMENT MediaCodec (Type|Quirk|Include)*>
 <!ATTLIST MediaCodec name CDATA #REQUIRED>
 <!ATTLIST MediaCodec type CDATA>
 <!ELEMENT Type EMPTY>
@@ -76,38 +78,75 @@
 -->
 
 <MediaCodecs>
+    <Include href="media_codecs_google_audio.xml" />
+    <Include href="media_codecs_google_telephony.xml" />
     <Decoders>
-        <MediaCodec name="OMX.Nvidia.mp4.decode" type="video/mp4v-es" />
-        <MediaCodec name="OMX.Nvidia.h263.decode" type="video/3gpp" />
-        <MediaCodec name="OMX.Nvidia.h264.decode" type="video/avc" />
-        <MediaCodec name="OMX.Nvidia.mpeg2v.decode" type="video/mpeg2" />
-        <MediaCodec name="OMX.Nvidia.mp2.decoder" type="audio/mpeg-L2" />
-
-        <MediaCodec name="OMX.google.mp3.decoder" type="audio/mpeg" />
-        <MediaCodec name="OMX.google.amrnb.decoder" type="audio/3gpp" />
-        <MediaCodec name="OMX.google.amrwb.decoder" type="audio/amr-wb" />
-        <MediaCodec name="OMX.google.aac.decoder" type="audio/mp4a-latm" />
-        <MediaCodec name="OMX.google.g711.alaw.decoder" type="audio/g711-alaw" />
-        <MediaCodec name="OMX.google.g711.mlaw.decoder" type="audio/g711-mlaw" />
-        <MediaCodec name="OMX.google.vorbis.decoder" type="audio/vorbis" />
-        <MediaCodec name="OMX.google.gsm.decoder" type="audio/gsm" />
-
-        <MediaCodec name="OMX.google.mpeg4.decoder" type="video/mp4v-es" />
-        <MediaCodec name="OMX.google.h263.decoder" type="video/3gpp" />
-        <MediaCodec name="OMX.google.h264.decoder" type="video/avc" />
-        <MediaCodec name="OMX.google.vp8.decoder" type="video/x-vnd.on2.vp8" />
-        <MediaCodec name="OMX.google.vp9.decoder" type="video/x-vnd.on2.vp9" />
+        <MediaCodec name="OMX.Nvidia.mp4.decode" type="video/mp4v-es" >
+            <Limit name="size" min="32x32" max="1920x1088" />
+            <Limit name="alignment" value="2x2" />
+            <Limit name="block-size" value="16x16" />
+            <Limit name="blocks-per-second" min="1" max="244800" />
+            <Limit name="bitrate" range="1-10000000" />
+            <Feature name="adaptive-playback" />
+        </MediaCodec>
+        <MediaCodec name="OMX.Nvidia.h263.decode" type="video/3gpp" >
+            <Limit name="size" min="32x32" max="720x576" />
+            <Limit name="alignment" value="2x2" />
+            <Feature name="adaptive-playback" />
+        </MediaCodec>
+        <MediaCodec name="OMX.Nvidia.h264.decode" type="video/avc" >
+            <Limit name="size" min="32x32" max="1920x1088" />
+            <Limit name="alignment" value="2x2" />
+            <Limit name="block-size" value="16x16" />
+            <Limit name="blocks-per-second" min="1" max="244800" />
+            <Limit name="bitrate" range="1-40000000" />
+            <Feature name="adaptive-playback" />
+        </MediaCodec>
+        <MediaCodec name="OMX.Nvidia.h264.decode.secure" type="video/avc" >
+            <Limit name="size" min="32x32" max="1920x1088" />
+            <Limit name="alignment" value="2x2" />
+            <Limit name="block-size" value="16x16" />
+            <Limit name="blocks-per-second" min="1" max="244800" />
+            <Limit name="bitrate" range="1-40000000" />
+            <Feature name="adaptive-playback" />
+            <Feature name="secure-playback" required="true" />
+        </MediaCodec>
+        <MediaCodec name="OMX.Nvidia.mpeg2v.decode" type="video/mpeg2" >
+            <Limit name="size" min="32x32" max="1920x1088" />
+            <Limit name="alignment" value="2x2" />
+            <Limit name="block-size" value="16x16" />
+            <Limit name="blocks-per-second" min="1" max="244800" />
+            <Limit name="bitrate" range="1-40000000" />
+            <Feature name="adaptive-playback" />
+        </MediaCodec>
+        <MediaCodec name="OMX.Nvidia.mp2.decoder" type="audio/mpeg-L2" >
+            <Limit name="channel-count" max="6" />
+            <Limit name="sample-rate" ranges="16000,22050,24000,32000,44100,48000" />
+            <Limit name="bitrate" range="8000-384000" />
+        </MediaCodec>
     </Decoders>
 
     <Encoders>
-        <MediaCodec name="OMX.Nvidia.mp4.encoder" type="video/mp4v-es" />
-        <MediaCodec name="OMX.Nvidia.h263.encoder" type="video/3gpp" />
-        <MediaCodec name="OMX.Nvidia.h264.encoder" type="video/avc" />
-
-        <MediaCodec name="OMX.google.amrnb.encoder" type="audio/3gpp" />
-        <MediaCodec name="OMX.google.amrwb.encoder" type="audio/amr-wb" />
-        <MediaCodec name="OMX.google.aac.encoder" type="audio/mp4a-latm" />
-        <MediaCodec name="OMX.google.flac.encoder" type="audio/flac" />
-        <MediaCodec name="OMX.google.vp8.encoder" type="video/x-vnd.on2.vp8" />
+        <MediaCodec name="OMX.Nvidia.mp4.encoder" type="video/mp4v-es" >
+            <Limit name="size" min="48x48" max="1920x1088" />
+            <Limit name="alignment" value="2x2" />
+            <Limit name="block-size" value="16x16" />
+            <Limit name="blocks-per-second" min="1" max="195840" />
+            <Limit name="bitrate" range="1-14000000" />
+        </MediaCodec>
+        <MediaCodec name="OMX.Nvidia.h263.encoder" type="video/3gpp" >
+            <Limit name="size" min="176x144" max="352x288" />
+            <Limit name="alignment" value="16x16" />
+            <Limit name="block-size" value="16x16" />
+            <Limit name="aspect-ratio" in="blocks" value="11:9" />
+        </MediaCodec>
+        <MediaCodec name="OMX.Nvidia.h264.encoder" type="video/avc" >
+            <Limit name="size" min="48x48" max="1920x1088" />
+            <Limit name="alignment" value="2x2" />
+            <Limit name="block-size" value="16x16" />
+            <Limit name="blocks-per-second" min="1" max="195840" />
+            <Limit name="bitrate" range="1-14000000" />
+        </MediaCodec>
     </Encoders>
+    <Include href="media_codecs_google_video.xml" />
 </MediaCodecs>
diff --git a/nfcee_access.xml b/nfcee_access.xml
deleted file mode 100644
index 02e12fd..0000000
--- a/nfcee_access.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- Applications granted NFCEE access on user builds
-
-    See packages/apps/Nfc/etc/sample_nfcee_access.xml for full documentation.
-     -->
-
-    <!--  Google wallet release signature -->
-    <signer android:signature="3082044c30820334a003020102020900a8cd17c93da5d990300d06092a864886f70d01010505003077310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f6964311330110603550403130a476f6f676c65204e4643301e170d3131303332343031303635335a170d3338303830393031303635335a3077310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f6964311330110603550403130a476f6f676c65204e464330820120300d06092a864886f70d01010105000382010d00308201080282010100c30f88add9b492096a2c586a5a9a80356bfa026958f8ff0c5dfaf59f49268ad870dee821a53e1f5b170fc96245a3c982a7cb4527053be35e34f396d24b2291ec0c528d6e26927465e06875ea621f7ff98c40e3345b204907cc9354743acdaace65565f48ba74cd4121cdc876df3522badb095c20d934c56a3e5c393ee5f0e02f8fe0621f918d1f35a82489252c6fa6b63392a7686b3e48612d06a9cf6f49bff11d5d96289c9dfe14ac5762439697dd29eafdb9810de3263513a905ac8e8eaf20907e46750a5ab7bf9a77262f47b03f5a3c6e6d7b51343f69c7f725f70bcc1b4ad592250b705a86e6e83ee2ae37fe5701bcbdb26feefdfff60f6a5bdfb5b64793020103a381dc3081d9301d0603551d0e041604141ccece0eea4dc1121fc7515f0d0a0c72e08cc96d3081a90603551d230481a130819e80141ccece0eea4dc1121fc7515f0d0a0c72e08cc96da17ba4793077310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f6964311330110603550403130a476f6f676c65204e4643820900a8cd17c93da5d990300c0603551d13040530030101ff300d06092a864886f70d01010505000382010100a470c728e1d31b06d9af6ae768b565046c57806b9843724931d75d4ca10c321520d33ccfed2aa65462234c9ef9b6f910cc676b99cb7f9895d6c06763574fbb78331275dc5cf38fbaa918d7938c051ffba2ade8f303cde8d9e68a048d1fdb9e7c9f2a49b222c68fff422bf15569b85eeeedb04aa30873dbe64b9c9e74f8f2c2f6c40124aaa8d1780d18512b540add28b3e9581971a4170dd868cf5f31e44712b2c23bb51037d7ef9f87a6e5bdb35e2ceb6bb022636c17a56a96bc7a50258c0bd2ed7b31555a18452e17321a0d52838c82f63f742d74ff79586a5cbb7faf7198a84bcf744310e9e927597f00a23dd00660800c2238d90b2fb372dfdbba75bd852e" />
-
-</resources>
diff --git a/nfcee_access_debug.xml b/nfcee_access_debug.xml
deleted file mode 100644
index a96a2d1..0000000
--- a/nfcee_access_debug.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- Applications granted NFCEE access on userdebug/eng builds
-
-    See packages/apps/Nfc/etc/sample_nfcee_access.xml for full documentation.
-     -->
-
-    <!-- Google Wallet dev signature -->
-    <signer android:signature="3082044c30820334a003020102020900de7695041d7650c0300d06092a864886f70d01010505003077310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f6964311330110603550403130a476f6f676c65204e4643301e170d3131303332343031303332345a170d3338303830393031303332345a3077310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f6964311330110603550403130a476f6f676c65204e464330820120300d06092a864886f70d01010105000382010d00308201080282010100e6ff3defe92aa10d71eb0fa6408bc036b7e243eeed68a6a4763dc7a52a31757cdac61fe510bb73c716e4000104265b347fcecef4c42bf1e1379dd0a876f028227fbbc1f9bdd5d713b2f6a935a379d2cba9c96f92d2d0787c11f1eb19548008a6a072b34b91836cfa0ae1276780e9007530166986a11c9cef46cef7c704806dde9431fb60284d120ab0e7de1d633f07687d468c51139afffdc6bc9a207ca904b8be1da0aa7b4e97756f43606488be5cae3c68e8bb7942cdf51607c930a2fcda655b75d0759cba89ad06e739bd0ba29b1f404296c2c0a85a847f5ab0d067c6c3ec9c49212042ac63a7e53b546c65b46080b4e3e680e23e1f77cfe7f6de744b1a65020103a381dc3081d9301d0603551d0e04160414a2e89064b05d08865c34db930a9d840050117aec3081a90603551d230481a130819e8014a2e89064b05d08865c34db930a9d840050117aeca17ba4793077310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f6964311330110603550403130a476f6f676c65204e4643820900de7695041d7650c0300c0603551d13040530030101ff300d06092a864886f70d010105050003820101003771870ce87c3c52ea84899230c6e962d94b4d5f1293c25d88261541fd90b5555d1285cef3b8312c3f5df691a8aae04cb981b305e427fd1d2d9e1987e1d29078f13c8452990f1821980263d8d4bd36519348d8d8ba26d8b99fbf09f5fd3ebb0ea3c2f0c9376f1e1fca76f3a6a405429d081b752a7a90b756e9ab44da41abc8e1e8f88ac2758da743fb73e650719a57840ccb6b7add21b99fc681e456e1872c223d5c074adf55f6abda268c2d8b64ea0a8845eecd968f92b493127e75c753c3ff30cbc678b51c9f52961472f17da20a0dc6274aa2463434c1a9b614df697d8ff5ca8101e7a25c7db3fb055d65569c04b01d389cabba57b3a1703ec2e74a88d334" />
-
-    <!-- Google wallet release signature -->
-    <signer android:signature="3082044c30820334a003020102020900a8cd17c93da5d990300d06092a864886f70d01010505003077310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f6964311330110603550403130a476f6f676c65204e4643301e170d3131303332343031303635335a170d3338303830393031303635335a3077310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f6964311330110603550403130a476f6f676c65204e464330820120300d06092a864886f70d01010105000382010d00308201080282010100c30f88add9b492096a2c586a5a9a80356bfa026958f8ff0c5dfaf59f49268ad870dee821a53e1f5b170fc96245a3c982a7cb4527053be35e34f396d24b2291ec0c528d6e26927465e06875ea621f7ff98c40e3345b204907cc9354743acdaace65565f48ba74cd4121cdc876df3522badb095c20d934c56a3e5c393ee5f0e02f8fe0621f918d1f35a82489252c6fa6b63392a7686b3e48612d06a9cf6f49bff11d5d96289c9dfe14ac5762439697dd29eafdb9810de3263513a905ac8e8eaf20907e46750a5ab7bf9a77262f47b03f5a3c6e6d7b51343f69c7f725f70bcc1b4ad592250b705a86e6e83ee2ae37fe5701bcbdb26feefdfff60f6a5bdfb5b64793020103a381dc3081d9301d0603551d0e041604141ccece0eea4dc1121fc7515f0d0a0c72e08cc96d3081a90603551d230481a130819e80141ccece0eea4dc1121fc7515f0d0a0c72e08cc96da17ba4793077310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f6964311330110603550403130a476f6f676c65204e4643820900a8cd17c93da5d990300c0603551d13040530030101ff300d06092a864886f70d01010505000382010100a470c728e1d31b06d9af6ae768b565046c57806b9843724931d75d4ca10c321520d33ccfed2aa65462234c9ef9b6f910cc676b99cb7f9895d6c06763574fbb78331275dc5cf38fbaa918d7938c051ffba2ade8f303cde8d9e68a048d1fdb9e7c9f2a49b222c68fff422bf15569b85eeeedb04aa30873dbe64b9c9e74f8f2c2f6c40124aaa8d1780d18512b540add28b3e9581971a4170dd868cf5f31e44712b2c23bb51037d7ef9f87a6e5bdb35e2ceb6bb022636c17a56a96bc7a50258c0bd2ed7b31555a18452e17321a0d52838c82f63f742d74ff79586a5cbb7faf7198a84bcf744310e9e927597f00a23dd00660800c2238d90b2fb372dfdbba75bd852e" />
-
-    <!-- Platform dev-keys signature -->
-    <signer android:signature="308204a830820390a003020102020900bcdfe81405d5c69e300d06092a864886f70d0101050500308194310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e20566965773110300e060355040a1307416e64726f69643110300e060355040b1307416e64726f69643110300e06035504031307416e64726f69643122302006092a864886f70d0109011613616e64726f696440616e64726f69642e636f6d301e170d3131303931393230303634325a170d3339303230343230303634325a308194310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e20566965773110300e060355040a1307416e64726f69643110300e060355040b1307416e64726f69643110300e06035504031307416e64726f69643122302006092a864886f70d0109011613616e64726f696440616e64726f69642e636f6d30820120300d06092a864886f70d01010105000382010d00308201080282010100ef7a8a34d8151d0479a239903261fe5026c520d5d88cd65920c98e096d2770f49636da9ffc4e80c472b05bd62a435f8266912aa2a34a18f6f4856f9ef52c10b88c267627136726823e8f3389b051ba92920e10bbaae0e38879efbe681b05863b655d81a6f3b75a85eb230b38b23ea4ef56f2161ff01652ae2049881adbe60d3bf8b5386a81f7404c0cf0c111c0a35ab0a9760426e4af12add73327ec433e047e3517f47a2d3674c2b819354d56eb7fd6c9aa67dd05b4bb1ca8a7e1946c2494e9364ea677a25481ac81f434bff3dd56e93e59fccef0e24a753461cd1cf15f22b62251d07416057ac5ca3e03a24f7f4eca876bacc5a1828acbde04c5cfdb608c47020103a381fc3081f9301d0603551d0e0416041402f997668541fa74693bea699a5766893a362a5d3081c90603551d230481c13081be801402f997668541fa74693bea699a5766893a362a5da1819aa48197308194310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e20566965773110300e060355040a1307416e64726f69643110300e060355040b1307416e64726f69643110300e06035504031307416e64726f69643122302006092a864886f70d0109011613616e64726f696440616e64726f69642e636f6d820900bcdfe81405d5c69e300c0603551d13040530030101ff300d06092a864886f70d0101050500038201010047d6fb32cadeae4444c379b3441ff9ba10990c23d10472c54fb7ebd9c33b2a173836337e1c175c980847a8894f6a99782e9c2e2133629254295fe52749f93ec1e39d213dd06d0ba99de3b6b5d4d856fafe74e08113b7b23a1b56f4918ed41218a03b9564456480b665200267d3770a9463db413c6a47bd81d725cb7d39c9d0941693c59cbe727d40415f0815c3c8363fb8fa2e028ceeb3bbfbc6b119db5b72f0edb0bb417bfcbf74d9fa069de22afe56a50bcde7ea1078749bb9ec0adc0e6de045641ee3a82c576645160b4ab9710d3cb3201f23957da8de9084c0bec93ad1c8c2054195f13c926db07c8bdf15673acf6d791ec1d3a0d7e1b3470447acd95873" />
-
-</resources>
diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml
index 5b5a7a0..ab21b67 100644
--- a/overlay/frameworks/base/core/res/res/values/config.xml
+++ b/overlay/frameworks/base/core/res/res/values/config.xml
@@ -84,6 +84,8 @@
     The default represents a dual-mode smartphone -->
     <string translatable="false" name="config_wifi_p2p_device_type">1-0050F204-1</string>
 
+    <bool name="config_ui_enableFadingMarquee">true</bool>
+
     <!-- List of file paths for USB host busses to exclude from USB host support.
          For example, if the first USB bus on the device is used to communicate
          with the modem or some other restricted hardware, add "/dev/bus/usb/001/"
@@ -230,6 +232,8 @@
 
     <!--  Maximum number of supported users -->
     <integer name="config_multiuserMaximumUsers">8</integer>
+    <!-- Whether UI for multi user should be shown -->
+    <bool name="config_enableMultiUserUI">true</bool>
 
     <!-- reference volume index for music stream to limit headphone volume and display warning -->
     <integer name="config_safe_media_volume_index">6</integer>
diff --git a/overlay/frameworks/base/packages/SystemUI/res/values/config.xml b/overlay/frameworks/base/packages/SystemUI/res/values/config.xml
new file mode 100644
index 0000000..5aaaa57
--- /dev/null
+++ b/overlay/frameworks/base/packages/SystemUI/res/values/config.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2014 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ 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
+  -->
+
+<resources>
+    <!-- Defines the implementation of the velocity tracker to be used for the panel expansion. Can
+         be 'platform' or 'noisy' (i.e. for noisy touch screens). -->
+    <string name="velocity_tracker_impl" translatable="false">noisy</string>
+
+    <!-- Show camera affordance on Keyguard -->
+    <bool name="config_keyguardShowCameraAffordance">false</bool>
+
+    <!-- Disable expensive shadows -->
+    <bool name="config_recents_fake_shadows">true</bool>
+
+    <!-- Use hardware layers in recents -->
+    <bool name="config_recents_use_hardware_layers">true</bool>
+</resources>
diff --git a/overlay/packages/apps/Nfc/res/values/provisioning.xml b/overlay/packages/apps/Nfc/res/values/provisioning.xml
index 1ca59e3..c996eb5 100644
--- a/overlay/packages/apps/Nfc/res/values/provisioning.xml
+++ b/overlay/packages/apps/Nfc/res/values/provisioning.xml
@@ -17,12 +17,10 @@
 <!-- NFC resources that may need to be customized
      for different hardware or product builds. -->
 <resources>
-    <!-- Whether the device can receive NFC data in setup wizard -->
-    <bool name="enable_nfc_provisioning">true</bool>
-
     <!-- The accepted mime-types when NFC is enabled in setup wizard.
          Mime-types must be lower case, wildcards are *not* accepted. -->
     <string-array name="provisioning_mime_types">
         <item>application/vnd.com.google.android.nfcprovision</item>
+        <item>application/com.android.managedprovisioning</item>
     </string-array>
 </resources>
diff --git a/power/power.c b/power/power.c
index 687fe0b..327cf06 100644
--- a/power/power.c
+++ b/power/power.c
@@ -18,6 +18,13 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <sys/socket.h>
+#include <cutils/uevent.h>
+#include <sys/poll.h>
+#include <pthread.h>
+#include <linux/netlink.h>
+#include <stdlib.h>
+#include <stdbool.h>
 
 #define LOG_TAG "Grouper PowerHAL"
 #include <utils/Log.h>
@@ -26,10 +33,36 @@
 #include <hardware/power.h>
 
 #define BOOST_PATH      "/sys/devices/system/cpu/cpufreq/interactive/boost"
+#define UEVENT_MSG_LEN 2048
+#define TOTAL_CPUS 4
+#define RETRY_TIME_CHANGING_FREQ 20
+#define SLEEP_USEC_BETWN_RETRY 200
+#define LOW_POWER_MAX_FREQ "640000"
+#define LOW_POWER_MIN_FREQ "51000"
+#define NORMAL_MAX_FREQ "1300000"
+#define UEVENT_STRING "online@/devices/system/cpu/"
+
 static int boost_fd = -1;
 static int boost_warned;
 
-static void sysfs_write(char *path, char *s)
+static struct pollfd pfd;
+static char *cpu_path_min[] = {
+    "/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq",
+    "/sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq",
+    "/sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq",
+    "/sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq",
+};
+static char *cpu_path_max[] = {
+    "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq",
+    "/sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq",
+    "/sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq",
+    "/sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq",
+};
+static bool freq_set[TOTAL_CPUS];
+static bool low_power_mode = false;
+static pthread_mutex_t low_power_mode_lock = PTHREAD_MUTEX_INITIALIZER;
+
+static int sysfs_write(char *path, char *s)
 {
     char buf[80];
     int len;
@@ -38,19 +71,115 @@
     if (fd < 0) {
         strerror_r(errno, buf, sizeof(buf));
         ALOGE("Error opening %s: %s\n", path, buf);
-        return;
+        return -1;
     }
 
     len = write(fd, s, strlen(s));
     if (len < 0) {
         strerror_r(errno, buf, sizeof(buf));
         ALOGE("Error writing to %s: %s\n", path, buf);
+        return -1;
     }
 
     close(fd);
+    return 0;
 }
 
-static void grouper_power_init(struct power_module *module)
+static int uevent_event()
+{
+    char msg[UEVENT_MSG_LEN];
+    char *cp;
+    int n, cpu, ret, retry = RETRY_TIME_CHANGING_FREQ;
+
+    n = recv(pfd.fd, msg, UEVENT_MSG_LEN, MSG_DONTWAIT);
+    if (n <= 0) {
+        return -1;
+    }
+    if (n >= UEVENT_MSG_LEN) {   /* overflow -- discard */
+        return -1;
+    }
+
+    cp = msg;
+
+    if (strstr(cp, UEVENT_STRING)) {
+        n = strlen(cp);
+        errno = 0;
+        cpu = strtol(cp + n - 1, NULL, 10);
+
+        if (errno == EINVAL || errno == ERANGE || cpu < 0 || cpu >= TOTAL_CPUS) {
+            return -1;
+        }
+
+        pthread_mutex_lock(&low_power_mode_lock);
+        if (low_power_mode && !freq_set[cpu]) {
+            while (retry) {
+                sysfs_write(cpu_path_min[cpu], LOW_POWER_MIN_FREQ);
+                ret = sysfs_write(cpu_path_max[cpu], LOW_POWER_MAX_FREQ);
+                if (!ret) {
+                    freq_set[cpu] = true;
+                    break;
+                }
+                usleep(SLEEP_USEC_BETWN_RETRY);
+                retry--;
+           }
+        } else if (!low_power_mode && freq_set[cpu]) {
+             while (retry) {
+                  ret = sysfs_write(cpu_path_max[cpu], NORMAL_MAX_FREQ);
+                  if (!ret) {
+                      freq_set[cpu] = false;
+                      break;
+                  }
+                  usleep(SLEEP_USEC_BETWN_RETRY);
+                  retry--;
+             }
+        }
+        pthread_mutex_unlock(&low_power_mode_lock);
+    }
+    return 0;
+}
+
+void *thread_uevent(__attribute__((unused)) void *x)
+{
+    while (1) {
+        int nevents, ret;
+
+        nevents = poll(&pfd, 1, -1);
+
+        if (nevents == -1) {
+            if (errno == EINTR)
+                continue;
+            ALOGE("powerhal: thread_uevent: poll_wait failed\n");
+            break;
+        }
+        ret = uevent_event();
+        if (ret < 0)
+            ALOGE("Error processing the uevent event");
+    }
+    return NULL;
+}
+
+
+static void uevent_init()
+{
+    struct sockaddr_nl client;
+    pthread_t tid;
+    pfd.fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
+
+    if (pfd.fd < 0) {
+        ALOGE("%s: failed to open: %s", __func__, strerror(errno));
+        return;
+    }
+    memset(&client, 0, sizeof(struct sockaddr_nl));
+    pthread_create(&tid, NULL, thread_uevent, NULL);
+    client.nl_family = AF_NETLINK;
+    client.nl_pid = tid;
+    client.nl_groups = -1;
+    pfd.events = POLLIN;
+    bind(pfd.fd, (void *)&client, sizeof(struct sockaddr_nl));
+    return;
+}
+
+static void grouper_power_init( __attribute__((unused)) struct power_module *module)
 {
     /*
      * cpufreq interactive governor: timer 20ms, min sample 100ms,
@@ -58,45 +187,67 @@
      */
 
     sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/timer_rate",
-                "20000");
+                "50000");
     sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/min_sample_time",
-                "30000");
+                "500000");
     sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load",
-                "85");
+                "75");
     sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/boost_factor",
 		"0");
     sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/input_boost",
 		"1");
+    uevent_init();
 }
 
-static void grouper_power_set_interactive(struct power_module *module, int on)
+static void grouper_power_set_interactive(__attribute__((unused)) struct power_module *module,
+                                          __attribute__((unused)) int on)
 {
-    /*
-     * Lower maximum frequency when screen is off.  CPU 0 and 1 share a
-     * cpufreq policy.
-     */
-
-    sysfs_write("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq",
-                on ? "1300000" : "700000");
-
-    sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/input_boost",
-                on ? "1" : "0");
-
-    sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/boost_factor",
-                on ? "0" : "2");
-
+	if (on) {
+		sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load", "75");
+		sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/core_lock_period", "3000000");
+		sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/core_lock_count", "2");
+		sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/input_boost", "1");
+	}
+	else {
+		sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load", "85");
+		sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/core_lock_period", "200000");
+		sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/core_lock_count", "0");
+		sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/input_boost", "0");
+	}
 }
 
-static void grouper_power_hint(struct power_module *module, power_hint_t hint,
+static void grouper_power_hint(__attribute__((unused)) struct power_module *module, power_hint_t hint,
                             void *data)
 {
     char buf[80];
-    int len;
+    int len, cpu, ret;
 
     switch (hint) {
     case POWER_HINT_VSYNC:
         break;
 
+    case POWER_HINT_LOW_POWER:
+        pthread_mutex_lock(&low_power_mode_lock);
+        if (data) {
+            low_power_mode = true;
+            for (cpu = 0; cpu < TOTAL_CPUS; cpu++) {
+                sysfs_write(cpu_path_min[cpu], LOW_POWER_MIN_FREQ);
+                ret = sysfs_write(cpu_path_max[cpu], LOW_POWER_MAX_FREQ);
+                if (!ret) {
+                    freq_set[cpu] = true;
+                }
+            }
+        } else {
+            low_power_mode = false;
+            for (cpu = 0; cpu < TOTAL_CPUS; cpu++) {
+                ret = sysfs_write(cpu_path_max[cpu], NORMAL_MAX_FREQ);
+                if (!ret) {
+                    freq_set[cpu] = false;
+                }
+            }
+        }
+        pthread_mutex_unlock(&low_power_mode_lock);
+        break;
     default:
             break;
     }
diff --git a/recovery/Android.mk b/recovery/Android.mk
deleted file mode 100644
index 21383ce..0000000
--- a/recovery/Android.mk
+++ /dev/null
@@ -1,13 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := eng
-LOCAL_C_INCLUDES += bootable/recovery
-LOCAL_SRC_FILES := recovery_ui.cpp
-
-# should match TARGET_RECOVERY_UI_LIB set in BoardConfig.mk
-LOCAL_MODULE := librecovery_ui_grouper
-
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
diff --git a/recovery/recovery_ui.cpp b/recovery/recovery_ui.cpp
deleted file mode 100644
index ec3a05d..0000000
--- a/recovery/recovery_ui.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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.
- */
-
-#include <linux/input.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-
-#include "common.h"
-#include "device.h"
-#include "screen_ui.h"
-
-const char* HEADERS[] = { "Volume up/down to move highlight;",
-                          "power button to select.",
-                          "",
-                          NULL };
-
-const char* ITEMS[] = { "reboot system now",
-                        "apply update from ADB",
-                        "wipe data/factory reset",
-                        "wipe cache partition",
-                        NULL };
-
-class GrouperUI : public ScreenRecoveryUI {
-  public:
-    GrouperUI() :
-        consecutive_power_keys(0) {
-    }
-
-    virtual KeyAction CheckKey(int key) {
-        if (IsKeyPressed(KEY_POWER) && key == KEY_VOLUMEUP) {
-            return TOGGLE;
-        }
-        if (key == KEY_POWER) {
-            ++consecutive_power_keys;
-            if (consecutive_power_keys >= 7) {
-                return REBOOT;
-            }
-        } else {
-            consecutive_power_keys = 0;
-        }
-        return ENQUEUE;
-    }
-
-  private:
-    int consecutive_power_keys;
-};
-
-
-class GrouperDevice : public Device {
-  public:
-    GrouperDevice() :
-        ui(new GrouperUI) {
-    }
-
-    RecoveryUI* GetUI() { return ui; }
-
-    int HandleMenuKey(int key_code, int visible) {
-        if (visible) {
-            switch (key_code) {
-              case KEY_DOWN:
-              case KEY_VOLUMEDOWN:
-                return kHighlightDown;
-
-              case KEY_UP:
-              case KEY_VOLUMEUP:
-                return kHighlightUp;
-
-              case KEY_POWER:
-                return kInvokeItem;
-            }
-        }
-
-        return kNoAction;
-    }
-
-    BuiltinAction InvokeMenuItem(int menu_position) {
-        switch (menu_position) {
-          case 0: return REBOOT;
-          case 1: return APPLY_ADB_SIDELOAD;
-          case 2: return WIPE_DATA;
-          case 3: return WIPE_CACHE;
-          default: return NO_ACTION;
-        }
-    }
-
-    const char* const* GetMenuHeaders() { return HEADERS; }
-    const char* const* GetMenuItems() { return ITEMS; }
-
-  private:
-    RecoveryUI* ui;
-};
-
-Device* make_device() {
-    return new GrouperDevice;
-}
diff --git a/releasetools.py b/releasetools.py
index 99b3c03..97d14e6 100644
--- a/releasetools.py
+++ b/releasetools.py
@@ -25,6 +25,10 @@
   else:
     WriteBootloader(info, bootloader_bin)
 
+def IncrementalOTA_InstallBegin(info):
+  info.script.Unmount("/system")
+  info.script.TunePartition("/system", "-O", "^has_journal")
+  info.script.Mount("/system")
 
 def IncrementalOTA_InstallEnd(info):
   try:
diff --git a/self-extractors/extract-lists.txt b/self-extractors/extract-lists.txt
new file mode 100644
index 0000000..65ba040
--- /dev/null
+++ b/self-extractors/extract-lists.txt
@@ -0,0 +1,103 @@
+  asus)
+    TO_EXTRACT="\
+            system/bin/sensors-config \
+            system/lib/hw/camera.tegra3.so \
+            system/lib/hw/sensors.grouper.so \
+            system/lib/libsensors.lightsensor.so \
+            system/vendor/lib/drm/libdrmwvmplugin.so \
+            system/vendor/lib/libwvm.so \
+            "
+    ;;
+  broadcom)
+    TO_EXTRACT="\
+            system/bin/glgps \
+            system/etc/firmware/bcm4330.hcd \
+            system/etc/gps/gpsconfig.xml \
+            system/lib/hw/gps.tegra3.so \
+            "
+    ;;
+  elan)
+    TO_EXTRACT="\
+            system/etc/firmware/touch_fw.ekt \
+            "
+    ;;
+  invensense)
+    TO_EXTRACT="\
+            system/lib/libinvensense_hal.so \
+            system/lib/libmllite.so \
+            system/lib/libmplmpu.so \
+            "
+    ;;
+  nvidia)
+    TO_EXTRACT="\
+            system/bin/tf_daemon \
+            system/etc/firmware/nvavp_os_00001000.bin \
+            system/etc/firmware/nvavp_os_0ff00000.bin \
+            system/etc/firmware/nvavp_os_e0000000.bin \
+            system/etc/firmware/nvavp_os_eff00000.bin \
+            system/etc/firmware/nvavp_vid_ucode_alt.bin \
+            system/etc/nvcamera.conf \
+            system/etc/nvram.txt \
+            system/lib/egl/libEGL_tegra.so \
+            system/lib/egl/libGLESv1_CM_tegra.so \
+            system/lib/egl/libGLESv2_tegra.so \
+            system/lib/hw/gralloc.tegra3.so \
+            system/lib/hw/hwcomposer.tegra3.so \
+            system/lib/libardrv_dynamic.so \
+            system/lib/libcgdrv.so \
+            system/lib/libnvapputil.so \
+            system/lib/libnvasfparserhal.so \
+            system/lib/libnvaviparserhal.so \
+            system/lib/libnvavp.so \
+            system/lib/libnvcamerahdr.so \
+            system/lib/libnvddk_2d.so \
+            system/lib/libnvddk_2d_v2.so \
+            system/lib/libnvdispmgr_d.so \
+            system/lib/libnvmm.so \
+            system/lib/libnvmmlite.so \
+            system/lib/libnvmmlite_audio.so \
+            system/lib/libnvmmlite_image.so \
+            system/lib/libnvmmlite_utils.so \
+            system/lib/libnvmmlite_video.so \
+            system/lib/libnvmm_audio.so \
+            system/lib/libnvmm_camera.so \
+            system/lib/libnvmm_contentpipe.so \
+            system/lib/libnvmm_image.so \
+            system/lib/libnvmm_manager.so \
+            system/lib/libnvmm_misc.so \
+            system/lib/libnvmm_parser.so \
+            system/lib/libnvmm_service.so \
+            system/lib/libnvmm_utils.so \
+            system/lib/libnvmm_video.so \
+            system/lib/libnvmm_writer.so \
+            system/lib/libnvodm_dtvtuner.so \
+            system/lib/libnvodm_hdmi.so \
+            system/lib/libnvodm_imager.so \
+            system/lib/libnvodm_misc.so \
+            system/lib/libnvodm_query.so \
+            system/lib/libnvomx.so \
+            system/lib/libnvomxilclient.so \
+            system/lib/libnvos.so \
+            system/lib/libnvparser.so \
+            system/lib/libnvrm.so \
+            system/lib/libnvrm_graphics.so \
+            system/lib/libnvsm.so \
+            system/lib/libnvtvmr.so \
+            system/lib/libnvwinsys.so \
+            system/lib/libnvwsi.so \
+            system/lib/libstagefrighthw.so \
+            system/lib/libtf_crypto_sst.so \
+            "
+    ;;
+  nxp)
+    TO_EXTRACT="\
+            system/vendor/firmware/libpn544_fw.so \
+            "
+    ;;
+  widevine)
+    TO_EXTRACT="\
+            system/lib/libdrmdecrypt.so \
+            system/vendor/lib/libwvdrm_L1.so \
+            system/vendor/lib/libWVStreamControlAPI_L1.so
+            "
+    ;;
diff --git a/self-extractors/nvidia/staging/keymaster/keymaster_grouper.cpp b/self-extractors/nvidia/staging/keymaster/keymaster_grouper.cpp
index e5fea58..37f306a 100644
--- a/self-extractors/nvidia/staging/keymaster/keymaster_grouper.cpp
+++ b/self-extractors/nvidia/staging/keymaster/keymaster_grouper.cpp
@@ -36,7 +36,7 @@
 #include <cryptoki.h>
 #include <pkcs11.h>
 
-#include <utils/UniquePtr.h>
+#include <UniquePtr.h>
 
 
 /** The size of a key ID in bytes */
diff --git a/sepolicy/sensors_config.te b/sepolicy/sensors_config.te
index 9b81253..1a42a44 100644
--- a/sepolicy/sensors_config.te
+++ b/sepolicy/sensors_config.te
@@ -12,14 +12,12 @@
 allow sensors_config system_file:file execute_no_trans;
 
 # Mount /dev/block/platform/sdhci-tegra.3/by-name/PER
-# We would mount this with a context= mount option and
-# a context other than vfat if we could change sensors-config.
 allow sensors_config sensors_data_file:dir mounton;
-allow sensors_config vfat:filesystem { mount unmount };
-allow sensors_config { vfat block_device }:dir search;
+allow sensors_config sdcard_external:filesystem { mount unmount };
+allow sensors_config { sdcard_external block_device }:dir search;
 
 # Read from the mounted PER partition
-allow sensors_config vfat:file r_file_perms;
+allow sensors_config sdcard_external:file r_file_perms;
 
 # Need to chmod and chown files (/data/lightsensor, /data/sensors)
 allow sensors_config self:capability { chown fowner };