am 4b84a5a7: am dd3b86e2: am 927fbe57: Merge "mediaserver: fix HDCP failures"

* commit '4b84a5a7192289ee54ebba157d9b6490b4d500ba':
  mediaserver: fix HDCP failures
diff --git a/BoardConfig.mk b/BoardConfig.mk
index a2bf303..9f79b96 100755
--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -44,7 +44,7 @@
 
 BOARD_EGL_CFG := device/samsung/manta/egl.cfg
 
-#OVERRIDE_RS_DRIVER := libRSDriverArm.so
+OVERRIDE_RS_DRIVER := libRSDriverArm.so
 
 #BOARD_USES_HGL := true
 #BOARD_USES_OVERLAY := true
@@ -77,8 +77,6 @@
 
 BOARD_CHARGER_DISABLE_INIT_BLANK := true
 
-TARGET_RECOVERY_PIXEL_FORMAT := RGBX_8888
-TARGET_RECOVERY_UI_LIB := librecovery_ui_manta
 TARGET_RECOVERY_UPDATER_LIBS += librecovery_updater_manta
 TARGET_RELEASETOOLS_EXTENSIONS := device/samsung/manta
 
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index 8a0ca37..96dfd8e 100644
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -78,7 +78,7 @@
 struct pcm_config pcm_config_in = {
     .channels = 2,
     .rate = 44100,
-    .period_size = 1024,
+    .period_size = 256,
     .period_count = 2,
     .format = PCM_FORMAT_S16_LE,
 };
@@ -842,7 +842,8 @@
     buffer->frame_count = (buffer->frame_count > in->frames_in) ?
                                 in->frames_in : buffer->frame_count;
     buffer->i16 = in->buffer +
-            (pcm_config_in.period_size - in->frames_in) * popcount(in->channel_mask);
+            (pcm_config_in.period_size - in->frames_in) *
+                audio_channel_count_from_in_mask(in->channel_mask);
 
     return in->read_status;
 
@@ -867,7 +868,7 @@
 static ssize_t read_frames(struct stream_in *in, void *buffer, ssize_t frames)
 {
     ssize_t frames_wr = 0;
-    size_t frame_size = audio_stream_frame_size(&in->stream.common);
+    size_t frame_size = audio_stream_in_frame_size(&in->stream);
 
     while (frames_wr < frames) {
         size_t frames_rd = frames - frames_wr;
@@ -920,7 +921,7 @@
     struct stream_out *out = (struct stream_out *)stream;
 
     return out->config.period_size *
-            audio_stream_frame_size((struct audio_stream *)stream);
+            audio_stream_out_frame_size((const struct audio_stream_out *)stream);
 }
 
 static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
@@ -1176,7 +1177,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) /
                out_get_sample_rate(&stream->common));
     }
 
@@ -1266,7 +1267,7 @@
 
     return get_input_buffer_size(in->requested_rate,
                                  AUDIO_FORMAT_PCM_16_BIT,
-                                 popcount(in_get_channels(stream)));
+                                 audio_channel_count_from_in_mask(in_get_channels(stream)));
 }
 
 static audio_format_t in_get_format(const struct audio_stream *stream)
@@ -1424,7 +1425,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
@@ -1464,7 +1465,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);
@@ -1550,7 +1551,7 @@
         out->channel_mask = config->channel_mask;
         out->config = pcm_config_hdmi_multi;
         out->config.rate = config->sample_rate;
-        out->config.channels = popcount(config->channel_mask);
+        out->config.channels = audio_channel_count_from_out_mask(config->channel_mask);
         out->pcm_device = PCM_DEVICE;
         type = OUTPUT_HDMI;
     } else if (flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) {
@@ -1697,7 +1698,7 @@
 {
 
     return get_input_buffer_size(config->sample_rate, config->format,
-                                 popcount(config->channel_mask));
+                                 audio_channel_count_from_in_mask(config->channel_mask));
 }
 
 static int adev_open_input_stream(struct audio_hw_device *dev,
@@ -1749,7 +1750,7 @@
     in->channel_mask = config->channel_mask;
 
     in->buffer = malloc(pcm_config_in.period_size * pcm_config_in.channels
-                                               * audio_stream_frame_size(&in->stream.common));
+                                               * audio_stream_in_frame_size(&in->stream));
 
     if (!in->buffer) {
         ret = -ENOMEM;
@@ -1762,7 +1763,7 @@
 
         ret = create_resampler(pcm_config_in.rate,
                                in->requested_rate,
-                               popcount(in->channel_mask),
+                               audio_channel_count_from_in_mask(in->channel_mask),
                                RESAMPLER_QUALITY_DEFAULT,
                                &in->buf_provider,
                                &in->resampler);
@@ -1864,6 +1865,14 @@
 
     *device = &adev->hw_device.common;
 
+    char value[PROPERTY_VALUE_MAX];
+    if (property_get("audio_hal.period_size", value, NULL) > 0) {
+        pcm_config.period_size = atoi(value);
+        pcm_config_in.period_size = pcm_config.period_size;
+    }
+    if (property_get("audio_hal.in_period_size", value, NULL) > 0)
+        pcm_config_in.period_size = atoi(value);
+
     return 0;
 }
 
diff --git a/audio_policy.conf b/audio_policy.conf
index 3cad223..3063575 100644
--- a/audio_policy.conf
+++ b/audio_policy.conf
@@ -72,12 +72,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/bcmdhd.cal b/bcmdhd.cal
index bceb98b..1e4562e 100644
--- a/bcmdhd.cal
+++ b/bcmdhd.cal
@@ -17,8 +17,8 @@
 rxchain=0x3
 aa2g=3
 aa5g=3
-ccode=EU
-regrev=57
+ccode=XV
+regrev=1
 pa2gw0a0=0xFFB9
 pa2gw1a0=0x12AC
 pa2gw2a0=0xFED9
diff --git a/device.mk b/device.mk
index 0154a01..5747615 100644
--- a/device.mk
+++ b/device.mk
@@ -53,6 +53,9 @@
     frameworks/native/data/etc/android.hardware.touchscreen.multitouch.jazzhand.xml:system/etc/permissions/android.hardware.touchscreen.multitouch.jazzhand.xml \
     frameworks/native/data/etc/android.hardware.wifi.xml:system/etc/permissions/android.hardware.wifi.xml \
     frameworks/native/data/etc/android.hardware.wifi.direct.xml:system/etc/permissions/android.hardware.wifi.direct.xml \
+    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/samsung/manta/media_codecs.xml:system/etc/media_codecs.xml \
     device/samsung/manta/media_profiles.xml:system/etc/media_profiles.xml \
     frameworks/native/data/etc/android.hardware.camera.flash-autofocus.xml:system/etc/permissions/android.hardware.camera.flash-autofocus.xml \
@@ -65,7 +68,8 @@
     frameworks/native/data/etc/android.hardware.sensor.compass.xml:system/etc/permissions/android.hardware.sensor.compass.xml \
     frameworks/native/data/etc/android.hardware.sensor.gyroscope.xml:system/etc/permissions/android.hardware.sensor.gyroscope.xml \
     frameworks/native/data/etc/android.hardware.sensor.light.xml:system/etc/permissions/android.hardware.sensor.light.xml \
-    frameworks/native/data/etc/android.hardware.audio.low_latency.xml:system/etc/permissions/android.hardware.audio.low_latency.xml
+    frameworks/native/data/etc/android.hardware.audio.low_latency.xml:system/etc/permissions/android.hardware.audio.low_latency.xml \
+    frameworks/native/data/etc/android.hardware.ethernet.xml:system/etc/permissions/android.hardware.ethernet.xml
 
 PRODUCT_COPY_FILES += \
     device/samsung/manta/bcmdhd.cal:system/etc/wifi/bcmdhd.cal
@@ -100,20 +104,10 @@
 PRODUCT_PACKAGES += \
     nfc_nci.manta \
     NfcNci \
-    Tag \
-    com.android.nfc_extras
-
-# NFCEE access control
-ifeq ($(TARGET_BUILD_VARIANT),user)
-    NFCEE_ACCESS_PATH := device/samsung/manta/nfc/nfcee_access.xml
-else
-    NFCEE_ACCESS_PATH := device/samsung/manta/nfc/nfcee_access_debug.xml
-endif
+    Tag
 
 # NFC access control + feature files + configuration
 PRODUCT_COPY_FILES += \
-    $(NFCEE_ACCESS_PATH):system/etc/nfcee_access.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 \
     frameworks/native/data/etc/android.hardware.nfc.hce.xml:system/etc/permissions/android.hardware.nfc.hce.xml \
     device/samsung/manta/nfc/libnfc-brcm.conf:system/etc/libnfc-brcm.conf
@@ -175,7 +169,8 @@
     ro.hwui.text_small_cache_height=1024 \
     ro.hwui.text_large_cache_width=2048 \
     ro.hwui.text_large_cache_height=1024 \
-    ro.hwui.disable_scissor_opt=true
+    ro.hwui.disable_scissor_opt=true \
+    af.fast_track_multiplier=1
 
 # setup dalvik vm configs.
 $(call inherit-product, frameworks/native/build/tablet-10in-xhdpi-2048-dalvik-heap.mk)
@@ -188,9 +183,12 @@
 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += \
     persist.sys.usb.config=mtp
 
+# Allows healthd to boot directly from charger mode rather than initiating a reboot.
+PRODUCT_DEFAULT_PROPERTY_OVERRIDES += \
+    ro.enable_boot_charger_mode=1
+
 # for off charging mode
 PRODUCT_PACKAGES += \
-    charger \
     charger_res_images
 
 $(call inherit-product-if-exists, hardware/samsung_slsi/exynos5/exynos5.mk)
diff --git a/health/healthd-manta.cpp b/health/healthd-manta.cpp
index 94a42ee..04d546d 100644
--- a/health/healthd-manta.cpp
+++ b/health/healthd-manta.cpp
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <healthd.h>
+#include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
 #include <batteryservice/BatteryService.h>
@@ -25,10 +26,14 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+/* Nominal voltage for ENERGY_COUNTER computation */
+#define VOLTAGE_NOMINAL 3.7
+
 #define POWER_SUPPLY_SUBSYSTEM "power_supply"
 #define POWER_SUPPLY_SYSFS_PATH "/sys/class/" POWER_SUPPLY_SUBSYSTEM
 
 #define DS2784_PATH POWER_SUPPLY_SYSFS_PATH "/ds2784-fuelgauge"
+#define CHARGE_COUNTER_EXT_PATH DS2784_PATH "/charge_counter_ext"
 
 using namespace android;
 
@@ -209,9 +214,8 @@
         manta_bat_check_temp(props);
     } else {
          props->batteryTemperature = 42;  /* 4.2C */
-         props->batteryVoltage = 4242; /* 4242mV */
+         props->batteryVoltage = 4342;    /* 4342mV */
          props->batteryLevel = 42;        /* 42% */
-         props->batteryCurrentNow = 42000;/* 42mA */
     }
 
     if (props->batteryStatus == BATTERY_STATUS_FULL &&
@@ -285,6 +289,45 @@
     return 0;
 }
 
+static int read_sysfs(const char *path, char *buf, size_t size) {
+    char *cp = NULL;
+
+    int fd = open(path, O_RDONLY, 0);
+    if (fd == -1) {
+        KLOG_ERROR(LOG_TAG, "Could not open '%s'\n", path);
+        return -1;
+    }
+
+    ssize_t count = TEMP_FAILURE_RETRY(read(fd, buf, size));
+    if (count > 0)
+            cp = (char *)memrchr(buf, '\n', count);
+
+    if (cp)
+        *cp = '\0';
+    else
+        buf[0] = '\0';
+
+    close(fd);
+    return count;
+}
+
+static int64_t get_int64_field(const char *path) {
+    const int SIZE = 21;
+    char buf[SIZE];
+
+    int64_t value = 0;
+    if (read_sysfs(path, buf, SIZE) > 0) {
+        value = strtoll(buf, NULL, 0);
+    }
+    return value;
+}
+
+static int manta_energy_counter(int64_t *energy)
+{
+    *energy = get_int64_field(CHARGE_COUNTER_EXT_PATH) * VOLTAGE_NOMINAL;
+    return 0;
+}
+
 void healthd_board_init(struct healthd_config *config)
 {
     charge_enabled_fd = open(POWER_SUPPLY_SYSFS_PATH
@@ -298,7 +341,9 @@
     if (access(config->batteryCurrentNowPath.string(), R_OK) == 0) {
         manta_bat_batterypresent = true;
     } else {
-        KLOG_INFO("Missing battery, using fake battery data\n");
+        KLOG_INFO(LOG_TAG, "Missing battery, using fake battery data\n");
         config->batteryCurrentNowPath.clear();
     }
+
+    config->energyCounter = manta_energy_counter;
 }
diff --git a/init.manta.rc b/init.manta.rc
index 83963d4..7eecd29 100644
--- a/init.manta.rc
+++ b/init.manta.rc
@@ -104,12 +104,10 @@
 
 service p2p_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 \
-    -puse_multi_chan_concurrent=1 -N -ip2p0 -Dnl80211 \
-    -c/data/misc/wifi/p2p_supplicant.conf \
+    -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=1use_multi_chan_concurrent=1 \
+    -puse_p2p_group_interface=1 \
     -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
@@ -123,7 +121,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
@@ -176,6 +173,7 @@
 
 service battery_charger /charger
     class charger
+    critical
     seclabel u:r:healthd:s0
 
 # Set watchdog timer to 30 seconds and pet it every 10 seconds to get a 20 second margin
diff --git a/kernel b/kernel
index 72c2b7b..2bff089 100644
--- a/kernel
+++ b/kernel
Binary files differ
diff --git a/libsensors/sensors.cpp b/libsensors/sensors.cpp
index 8e6c2d6..a11375b 100644
--- a/libsensors/sensors.cpp
+++ b/libsensors/sensors.cpp
@@ -64,11 +64,11 @@
       { "BH1721fvc Light sensor",
           "Rohm",
           1, SENSORS_LIGHT_HANDLE,
-          SENSOR_TYPE_LIGHT, 65528.0f, 1.0f, 0.20f, 16000, 0, 0, 0, 0, { } },
+          SENSOR_TYPE_LIGHT, 65528.0f, 1.0f, 0.20f, 16000, 0, 0, 0, 0, 0, 0, { } },
       { "BMP182 Pressure sensor",
           "Bosch",
           1, SENSORS_PRESSURE_HANDLE,
-          SENSOR_TYPE_PRESSURE, 1100.0f, 0.01f, 0.06f, 50000, 0, 0, 0, 0, { } },
+          SENSOR_TYPE_PRESSURE, 1100.0f, 0.01f, 0.06f, 50000, 0, 0, 0, 0, 0, 0, { } },
 };
 static int numSensors = LOCAL_SENSORS;
 
diff --git a/media_codecs.xml b/media_codecs.xml
index 3ac942b..ebbb943 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,6 +78,8 @@
 -->
 
 <MediaCodecs>
+    <Include href="media_codecs_google_audio.xml" />
+    <Include href="media_codecs_google_telephony.xml" />
     <Decoders>
         <MediaCodec name="OMX.Exynos.MPEG4.Decoder" type="video/mp4v-es" >
             <Quirk name="requires-allocate-on-input-ports" />
@@ -93,21 +97,6 @@
             <Quirk name="requires-allocate-on-input-ports" />
             <Quirk name="requires-allocate-on-output-ports" />
         </MediaCodec>
-
-        <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" />
     </Decoders>
 
     <Encoders>
@@ -123,11 +112,6 @@
             <Quirk name="requires-allocate-on-input-ports" />
             <Quirk name="requires-allocate-on-output-ports" />
         </MediaCodec>
-
-        <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" />
     </Encoders>
+    <Include href="media_codecs_google_video.xml" />
 </MediaCodecs>
diff --git a/nfc/libnfc-brcm.conf b/nfc/libnfc-brcm.conf
index 726c86f..37bbd68 100644
--- a/nfc/libnfc-brcm.conf
+++ b/nfc/libnfc-brcm.conf
@@ -124,14 +124,14 @@
 # The value is set to 3 by default as it assumes we will discover 0xF2,
 # 0xF3, and 0xF4. If a platform will exclude and SE, this value can be reduced
 # so that the stack will not wait any longer than necessary.
-#NFA_MAX_EE_SUPPORTED=3
+NFA_MAX_EE_SUPPORTED=0
 
 ###############################################################################
 # Configure the single default SE to use.  The default is to use the first
 # SE that is detected by the stack.  This value might be used when the phone
 # supports multiple SE (e.g. 0xF3 and 0xF4) but you want to force it to use
 # one of them (e.g. 0xF4).
-ACTIVE_SE=0xF4
+ACTIVE_SE=0x00
 
 ###############################################################################
 # Configure the default NfcA/IsoDep techology and protocol route. Can be
@@ -208,9 +208,9 @@
 ###############################################################################
 # When screen is turned off, specify the desired power state of the controller.
 # 0: power-off-sleep state; DEFAULT
-# 1: full-power state
+# 1: full-power state (note: this is still low-power ("snooze") on BRCM devices.
 # 2: screen-off card-emulation (CE4/CE3/CE1 modes are used)
-#SCREEN_OFF_POWER_STATE=0
+SCREEN_OFF_POWER_STATE=1
 
 ###############################################################################
 # Firmware patch file
@@ -306,3 +306,13 @@
 # Default poll duration (in ms)
 #  The defualt is 500ms if not set (see nfc_target.h)
 #NFA_DM_DISC_DURATION_POLL=333
+
+###############################################################################
+# Choose the presence-check algorithm for type-4 tag.  If not defined,
+# the default value is 1.
+# 0  NFA_RW_PRES_CHK_DEFAULT; Let stack selects an algorithm
+# 1  NFA_RW_PRES_CHK_I_BLOCK; ISO-DEP protocol's empty I-block
+# 2  NFA_RW_PRES_CHK_RESET; Deactivate to Sleep, then re-activate
+# 3  NFA_RW_PRES_CHK_RB_CH0; Type-4 tag protocol's ReadBinary command on channel 0
+# 4  NFA_RW_PRES_CHK_RB_CH3; Type-4 tag protocol's ReadBinary command on channel 3
+PRESENCE_CHECK_ALGORITHM=1
diff --git a/nfc/nfcee_access.xml b/nfc/nfcee_access.xml
deleted file mode 100644
index 02e12fd..0000000
--- a/nfc/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/nfc/nfcee_access_debug.xml b/nfc/nfcee_access_debug.xml
deleted file mode 100644
index a96a2d1..0000000
--- a/nfc/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 51fa7f6..0b20eba 100644
--- a/overlay/frameworks/base/core/res/res/values/config.xml
+++ b/overlay/frameworks/base/core/res/res/values/config.xml
@@ -166,6 +166,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>
 
     <bool name="config_ui_enableFadingMarquee">false</bool>
 
diff --git a/overlay/packages/apps/Nfc/res/values/provisioning.xml b/overlay/packages/apps/Nfc/res/values/provisioning.xml
index 1ca59e3..0508900 100644
--- a/overlay/packages/apps/Nfc/res/values/provisioning.xml
+++ b/overlay/packages/apps/Nfc/res/values/provisioning.xml
@@ -17,12 +17,11 @@
 <!-- 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_manta.c b/power/power_manta.c
index 077520b..1d3e72d 100644
--- a/power/power_manta.c
+++ b/power/power_manta.c
@@ -21,6 +21,9 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <stdlib.h>
+#include <linux/time.h>
+#include <stdbool.h>
 //#define LOG_NDEBUG 0
 
 #define LOG_TAG "MantaPowerHAL"
@@ -30,6 +33,16 @@
 #include <hardware/power.h>
 
 #define BOOSTPULSE_PATH "/sys/devices/system/cpu/cpufreq/interactive/boostpulse"
+#define BOOST_PATH "/sys/devices/system/cpu/cpufreq/interactive/boost"
+#define CPU_MAX_FREQ_PATH "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"
+//BOOST_PULSE_DURATION and BOOT_PULSE_DURATION_STR should always be in sync
+#define BOOST_PULSE_DURATION 1000000
+#define BOOST_PULSE_DURATION_STR "1000000"
+#define NSEC_PER_SEC 1000000000
+#define USEC_PER_SEC 1000000
+#define NSEC_PER_USEC 100
+#define LOW_POWER_MAX_FREQ "800000"
+#define NORMAL_MAX_FREQ "1700000"
 
 struct manta_power_module {
     struct power_module base;
@@ -39,6 +52,11 @@
     const char *touchscreen_power_path;
 };
 
+static unsigned int vsync_count;
+static struct timespec last_touch_boost;
+static bool touch_boost;
+static bool low_power_mode = false;
+
 static void sysfs_write(const char *path, char *s)
 {
     char buf[80];
@@ -115,7 +133,7 @@
     sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay",
                 "80000");
     sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/boostpulse_duration",
-                "500000");
+                BOOST_PULSE_DURATION_STR);
     sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/io_is_busy", "1");
 
     init_touchscreen_power_path(manta);
@@ -133,8 +151,8 @@
      * 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 ? "1700000" : "800000");
+    sysfs_write(CPU_MAX_FREQ_PATH,
+                (!on || low_power_mode) ? LOW_POWER_MAX_FREQ : NORMAL_MAX_FREQ);
 
     sysfs_write(manta->touchscreen_power_path, on ? "Y" : "N");
 
@@ -163,29 +181,89 @@
     return manta->boostpulse_fd;
 }
 
+static struct timespec timespec_diff(struct timespec lhs, struct timespec rhs)
+{
+    struct timespec result;
+    if (rhs.tv_nsec > lhs.tv_nsec) {
+        result.tv_sec = lhs.tv_sec - rhs.tv_sec - 1;
+        result.tv_nsec = NSEC_PER_SEC + lhs.tv_nsec - rhs.tv_nsec;
+    } else {
+        result.tv_sec = lhs.tv_sec - rhs.tv_sec;
+        result.tv_nsec = lhs.tv_nsec - rhs.tv_nsec;
+    }
+    return result;
+}
+
+static int check_boostpulse_on(struct timespec diff)
+{
+    long boost_ns = (BOOST_PULSE_DURATION * NSEC_PER_USEC) % NSEC_PER_SEC;
+    long boost_s = BOOST_PULSE_DURATION / USEC_PER_SEC;
+
+    if (diff.tv_sec == boost_s)
+        return (diff.tv_nsec < boost_ns);
+    return (diff.tv_sec < boost_s);
+}
+
 static void manta_power_hint(struct power_module *module, power_hint_t hint,
                              void *data)
 {
     struct manta_power_module *manta = (struct manta_power_module *) module;
+    struct timespec now, diff;
     char buf[80];
     int len;
 
     switch (hint) {
      case POWER_HINT_INTERACTION:
         if (boostpulse_open(manta) >= 0) {
+            pthread_mutex_lock(&manta->lock);
             len = write(manta->boostpulse_fd, "1", 1);
 
             if (len < 0) {
                 strerror_r(errno, buf, sizeof(buf));
                 ALOGE("Error writing to %s: %s\n", BOOSTPULSE_PATH, buf);
+            } else {
+                clock_gettime(CLOCK_MONOTONIC, &last_touch_boost);
+                touch_boost = true;
             }
+            pthread_mutex_unlock(&manta->lock);
         }
 
         break;
 
-   case POWER_HINT_VSYNC:
+     case POWER_HINT_VSYNC:
+        pthread_mutex_lock(&manta->lock);
+        if (data) {
+            if (vsync_count < UINT_MAX)
+                vsync_count++;
+        } else {
+            if (vsync_count)
+                vsync_count--;
+            if (vsync_count == 0 && touch_boost) {
+                touch_boost = false;
+                clock_gettime(CLOCK_MONOTONIC, &now);
+                diff = timespec_diff(now, last_touch_boost);
+                if (check_boostpulse_on(diff)) {
+                    sysfs_write(BOOST_PATH, "0");
+                }
+            }
+        }
+        pthread_mutex_unlock(&manta->lock);
         break;
 
+    case POWER_HINT_LOW_POWER:
+        pthread_mutex_lock(&manta->lock);
+        if (data) {
+            sysfs_write(CPU_MAX_FREQ_PATH, LOW_POWER_MAX_FREQ);
+            // reduces the refresh rate
+            system("service call SurfaceFlinger 1016 i32 1");
+        } else {
+            sysfs_write(CPU_MAX_FREQ_PATH, NORMAL_MAX_FREQ);
+            // restores the refresh rate
+            system("service call SurfaceFlinger 1016 i32 0");
+        }
+        low_power_mode = data;
+        pthread_mutex_unlock(&manta->lock);
+        break;
     default:
             break;
     }
diff --git a/proprietary-blobs.txt b/proprietary-blobs.txt
index 395365f..0fb57d6 100644
--- a/proprietary-blobs.txt
+++ b/proprietary-blobs.txt
@@ -29,6 +29,7 @@
 /system/vendor/lib/libdrmdecrypt.so
 /system/vendor/lib/libmalicore.bc
 /system/vendor/lib/libRSDriverArm.so
+/system/vendor/lib/libbccArm.so
 /system/vendor/lib/libstagefright_hdcp.so
 /system/vendor/secapp/00060308060501020000000000000000.tlbin
 /system/vendor/secapp/020a0000000000000000000000000000.drbin
diff --git a/recovery/Android.mk b/recovery/Android.mk
index 1a2b865..71d4815 100644
--- a/recovery/Android.mk
+++ b/recovery/Android.mk
@@ -1,17 +1,6 @@
 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_manta
-
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-
 # Edify extension functions for doing bootloader updates on manta devices.
 
 LOCAL_MODULE_TAGS := optional
diff --git a/recovery/recovery_ui.cpp b/recovery/recovery_ui.cpp
deleted file mode 100644
index 5d82755..0000000
--- a/recovery/recovery_ui.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 2012 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 MantaUI : public ScreenRecoveryUI {
-  public:
-    MantaUI() :
-        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 MantaDevice : public Device {
-  public:
-    MantaDevice() :
-        ui(new MantaUI) {
-    }
-
-    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 MantaDevice;
-}
diff --git a/self-extractors/extract-lists.txt b/self-extractors/extract-lists.txt
new file mode 100644
index 0000000..e051009
--- /dev/null
+++ b/self-extractors/extract-lists.txt
@@ -0,0 +1,33 @@
+  audience)
+    TO_EXTRACT="\
+            system/vendor/firmware/es305_fw.bin \
+            "
+    ;;
+  broadcom)
+    TO_EXTRACT="\
+            system/vendor/firmware/bcm2079x_firmware.ncd \
+            system/vendor/firmware/bcm2079x_pre_firmware.ncd \
+            system/vendor/firmware/bcm43241.hcd \
+            "
+    ;;
+  samsung)
+    TO_EXTRACT="\
+            system/vendor/firmware/fimc_is_fw.bin \
+            system/vendor/firmware/fimc_is_fw2.bin \
+            system/vendor/firmware/maxtouch.fw \
+            system/vendor/firmware/mfc_fw.bin \
+            system/vendor/firmware/setfile.bin \
+            system/vendor/firmware/setfile_4e5.bin \
+            system/vendor/firmware/setfile_6a3.bin \
+            system/vendor/lib/egl/libGLES_mali.so \
+            system/vendor/lib/libdrmdecrypt.so \
+            system/vendor/lib/libmalicore.bc \
+            system/vendor/lib/libRSDriverArm.so \
+            system/vendor/lib/libbccArm.so \
+            system/vendor/lib/libstagefright_hdcp.so \
+            system/vendor/secapp/00060308060501020000000000000000.tlbin \
+            system/vendor/secapp/020a0000000000000000000000000000.drbin \
+            system/vendor/secapp/07060000000000000000000000000000.tlbin \
+            system/vendor/secapp/ffffffff000000000000000000000005.tlbin \
+            "
+    ;;
diff --git a/self-extractors/files-by-owner.sh b/self-extractors/files-by-owner.sh
new file mode 100755
index 0000000..f035837
--- /dev/null
+++ b/self-extractors/files-by-owner.sh
@@ -0,0 +1,95 @@
+#!/bin/sh
+
+# Copyright 2013 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.
+
+rm -f extract-lists.txt
+cat ../vendor_owner_info.txt |
+cut -d : -f 2 |
+sort -u |
+grep -v google |
+while read target_owner
+do
+cat > $target_owner/staging/device-partial.mk << EOF
+# Copyright 2013 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.
+
+EOF
+echo -n "# " >> $target_owner/staging/device-partial.mk
+case $target_owner in
+audience)
+echo -n Audience >> $target_owner/staging/device-partial.mk
+;;
+broadcom)
+echo -n Broadcom >> $target_owner/staging/device-partial.mk
+;;
+samsung)
+echo -n Samsung >> $target_owner/staging/device-partial.mk
+;;
+esac
+echo " blob(s) necessary for Manta hardware" >> $target_owner/staging/device-partial.mk
+echo "PRODUCT_COPY_FILES := \\" >> $target_owner/staging/device-partial.mk
+
+echo "  $target_owner)" >> extract-lists.txt
+echo "    TO_EXTRACT=\"\\" >> extract-lists.txt
+
+
+cat ../proprietary-blobs.txt |
+grep ^/ |
+cut -b 2- |
+sort |
+while read file
+do
+
+auto_owner=$(grep ^$file: ../vendor_owner_info.txt | cut -d : -f 2)
+if test $file = system/lib/hw/gps.msm8960.so -o $file = system/lib/libgps.utils.so -o $file = system/lib/libloc_adapter.so -o $file = system/lib/libloc_eng.so
+then
+auto_owner=qcom
+fi
+
+if test "$auto_owner" = "" -a $file != system/etc/firmware/wcd9310/wcd9310_anc.bin -a $file != system/etc/firmware/wcd9310/wcd9310_mbhc.bin
+then
+echo $file has no known owner
+fi
+
+if test "$auto_owner" = "$target_owner"
+then
+if test $file != system/lib/libacdbloader.so
+then
+echo "    vendor/$target_owner/manta/proprietary/$(basename $file):$file:$target_owner \\" >> $target_owner/staging/device-partial.mk
+fi
+echo "            $file \\" >> extract-lists.txt
+fi
+done
+
+echo >> $target_owner/staging/device-partial.mk
+if test $target_owner = qcom
+then
+echo PRODUCT_PACKAGES := libacdbloader >> $target_owner/staging/device-partial.mk
+fi
+
+echo "            \"" >> extract-lists.txt
+echo "    ;;" >> extract-lists.txt
+done
diff --git a/self-extractors/generate-packages.sh b/self-extractors/generate-packages.sh
index f4d69e3..2bcd6b4 100755
--- a/self-extractors/generate-packages.sh
+++ b/self-extractors/generate-packages.sh
@@ -103,6 +103,7 @@
             system/vendor/lib/libdrmdecrypt.so \
             system/vendor/lib/libmalicore.bc \
             system/vendor/lib/libRSDriverArm.so \
+            system/vendor/lib/libbccArm.so \
             system/vendor/lib/libstagefright_hdcp.so \
             system/vendor/secapp/00060308060501020000000000000000.tlbin \
             system/vendor/secapp/020a0000000000000000000000000000.drbin \
diff --git a/self-extractors/samsung/staging/proprietary/Android.mk b/self-extractors/samsung/staging/proprietary/Android.mk
index 18c9e88..3bb098a 100644
--- a/self-extractors/samsung/staging/proprietary/Android.mk
+++ b/self-extractors/samsung/staging/proprietary/Android.mk
@@ -127,6 +127,16 @@
 include $(BUILD_PREBUILT)
 
 include $(CLEAR_VARS)
+LOCAL_MODULE := libbccArm
+LOCAL_SRC_FILES := libbccArm.so
+LOCAL_MODULE_SUFFIX := .so
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_OWNER := samsung_arm
+include $(BUILD_PREBUILT)
+
+include $(CLEAR_VARS)
 LOCAL_MODULE := libstagefright_hdcp
 LOCAL_SRC_FILES := libstagefright_hdcp.so
 LOCAL_MODULE_SUFFIX := .so
diff --git a/vendor_owner_info.txt b/vendor_owner_info.txt
new file mode 100644
index 0000000..d099a5d
--- /dev/null
+++ b/vendor_owner_info.txt
@@ -0,0 +1,22 @@
+root/adb_keys:google
+system/vendor/firmware/es305_fw.bin:audience
+system/vendor/firmware/bcm2079x_firmware.ncd:broadcom
+system/vendor/firmware/bcm2079x_pre_firmware.ncd:broadcom
+system/vendor/firmware/bcm43241.hcd:broadcom
+system/vendor/firmware/fimc_is_fw.bin:samsung
+system/vendor/firmware/fimc_is_fw2.bin:samsung
+system/vendor/firmware/maxtouch.fw:samsung
+system/vendor/firmware/mfc_fw.bin:samsung
+system/vendor/firmware/setfile.bin:samsung
+system/vendor/firmware/setfile_4e5.bin:samsung
+system/vendor/firmware/setfile_6a3.bin:samsung
+system/vendor/lib/egl/libGLES_mali.so:samsung
+system/vendor/lib/libdrmdecrypt.so:samsung
+system/vendor/lib/libmalicore.bc:samsung
+system/vendor/lib/libRSDriverArm.so:samsung
+system/vendor/lib/libbccArm.so:samsung
+system/vendor/lib/libstagefright_hdcp.so:samsung
+system/vendor/secapp/00060308060501020000000000000000.tlbin:samsung
+system/vendor/secapp/020a0000000000000000000000000000.drbin:samsung
+system/vendor/secapp/07060000000000000000000000000000.tlbin:samsung
+system/vendor/secapp/ffffffff000000000000000000000005.tlbin:samsung