Merge "Bump target level to 3"
diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk
index b879d96..d527c0e 100644
--- a/BoardConfigCommon.mk
+++ b/BoardConfigCommon.mk
@@ -41,6 +41,9 @@
 TARGET_COPY_OUT_PRODUCT := product
 BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_USES_METADATA_PARTITION := true
+# Cache partition size: 64M
+BOARD_CACHEIMAGE_PARTITION_SIZE := 67108864
+BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
 # Super partition
 TARGET_USE_DYNAMIC_PARTITIONS := true
 BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT := true
diff --git a/db845c/BoardConfig.mk b/db845c/BoardConfig.mk
index 816c465..9d31f97 100644
--- a/db845c/BoardConfig.mk
+++ b/db845c/BoardConfig.mk
@@ -19,7 +19,7 @@
 BOARD_USERDATAIMAGE_PARTITION_SIZE := 21474836480 #20G
 BOARD_FLASH_BLOCK_SIZE := 512
 # Super partition
-BOARD_SUPER_PARTITION_SIZE := 10737418240 #10G
-BOARD_DB_DYNAMIC_PARTITIONS_SIZE := 10737418240 #10G
+BOARD_SUPER_PARTITION_SIZE := 12437225472
+BOARD_DB_DYNAMIC_PARTITIONS_SIZE := 12437225472
 BOARD_SUPER_PARTITION_METADATA_DEVICE := super
 BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE := true
diff --git a/db845c/device.mk b/db845c/device.mk
index 23299ad..c6825a3 100644
--- a/db845c/device.mk
+++ b/db845c/device.mk
@@ -23,7 +23,7 @@
 PRODUCT_COPY_FILES := \
     $(DB845C_KERNEL_DIR)/Image.gz:kernel \
     $(DB845C_KERNEL_DIR)/sdm845-db845c.dtb:dtb.img \
-    device/linaro/dragonboard/fstab.ramdisk.common:$(TARGET_COPY_OUT_RAMDISK)/fstab.db845c \
+    device/linaro/dragonboard/fstab.common:$(TARGET_COPY_OUT_RAMDISK)/fstab.db845c \
     device/linaro/dragonboard/fstab.common:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.db845c \
     device/linaro/dragonboard/init.common.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.db845c.rc \
     device/linaro/dragonboard/init.common.usb.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.db845c.usb.rc \
@@ -32,9 +32,10 @@
 # Build generic Audio HAL
 PRODUCT_PACKAGES := audio.primary.db845c
 
-# Build and install Qcom userspace tools to talk to dsp and modem
 PRODUCT_PACKAGES += \
     pd-mapper \
+    qrtr-ns \
+    qrtr-cfg \
     qrtr-lookup \
     rmtfs \
     tqftpserv
diff --git a/device-common.mk b/device-common.mk
index d0f540e..6fffd07 100644
--- a/device-common.mk
+++ b/device-common.mk
@@ -26,6 +26,9 @@
 PRODUCT_SHIPPING_API_LEVEL := 29
 PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS := false
 
+# Enable Scoped Storage related
+$(call inherit-product, $(SRC_TARGET_DIR)/product/emulated_storage.mk)
+
 # vndk
 PRODUCT_PACKAGES := vndk-sp
 
@@ -138,6 +141,10 @@
 PRODUCT_COPY_FILES += \
     $(LOCAL_PATH)/seccomp_policy/mediaswcodec.policy:$(TARGET_COPY_OUT_VENDOR)/etc/seccomp_policy/mediaswcodec.policy
 
+# Copy hardware config file(s)
+PRODUCT_COPY_FILES +=  \
+        device/linaro/dragonboard/etc/permissions/android.software.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.xml
+
 # Memtrack
 PRODUCT_PACKAGES += \
     memtrack.default \
diff --git a/etc/permissions/android.software.xml b/etc/permissions/android.software.xml
new file mode 100644
index 0000000..742a086
--- /dev/null
+++ b/etc/permissions/android.software.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 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.
+-->
+
+<!-- These are the hardware components that all handheld devices
+     must include. Devices with optional hardware must also include extra
+     hardware files, per the comments below.
+
+     Handheld devices include phones, mobile Internet devices (MIDs),
+     Personal Media Players (PMPs), small tablets (7" or less), and similar
+     devices.
+-->
+<permissions>
+    <!-- following features are said to be "basic system services"
+         in frameworks/native/data/etc/tablet_core_hardware.xml,
+    -->
+    <feature name="android.software.activities_on_secondary_displays" />
+    <feature name="android.software.autofill" />
+    <feature name="android.software.companion_device_setup" />
+    <feature name="android.software.home_screen" />
+    <feature name="android.software.input_methods" />
+    <feature name="android.software.picture_in_picture" />
+    <feature name="android.software.print" />
+
+    <!-- need by following cts test
+        android.app.cts.ActivityManagerProcessStateTest#testCantSaveStateLaunchAndBackground
+        android.app.cts.ActivityManagerProcessStateTest#testCantSaveStateLaunchAndSwitch
+    -->
+    <feature name="android.software.cant_save_state" />
+
+</permissions>
diff --git a/fstab.common b/fstab.common
index dbba930..1cdac6e 100644
--- a/fstab.common
+++ b/fstab.common
@@ -1,7 +1,8 @@
-# Android fstab file.
-#<src>                  <mnt_point>         <type>    <mnt_flags and options>                              <fs_mgr_flags>
-# The filesystem that contains the filesystem checker binary (typically /system) cannot
-# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK
-/dev/block/platform/soc@0/1d84000.ufshc/by-name/userdata /data		ext4	discard,noatime,noauto_da_alloc,data=ordered,user_xattr,barrier=1,inlinecrypt	wait,formattable,fileencryption=aes-256-xts:aes-256-cts:v2+inlinecrypt_optimized
-/dev/block/by-name/metadata	/metadata	ext4	noatime,nosuid,nodev,discard					wait,formattable
+system		/system		ext4	noatime,ro,errors=panic		wait,logical,first_stage_mount
+/dev/block/platform/soc@0/1d84000.ufshc/by-name/userdata /data		ext4	discard,noatime,noauto_da_alloc,data=ordered,user_xattr,barrier=1,inlinecrypt	wait,formattable,fileencryption=aes-256-xts:aes-256-cts:v2+inlinecrypt_optimized,quota
+/dev/block/platform/soc@0/1d84000.ufshc/by-name/metadata	/metadata	ext4	noatime,nosuid,nodev,discard					wait,formattable
+/dev/block/platform/soc@0/1d84000.ufshc/by-name/cache /cache	 ext4	nodev,noatime,nosuid,errors=panic wait
 /devices/platform/soc@0/8804000.sdhci/mmc_host/mmc*	auto	auto	defaults	voldmanaged=sdcard1:auto
+vendor		/vendor		ext4	noatime,ro,errors=panic		wait,logical,first_stage_mount
+system_ext	/system_ext	ext4	noatime,ro,errors=panic		wait,logical,first_stage_mount
+product	/product	ext4	noatime,ro,errors=panic		wait,logical,first_stage_mount
diff --git a/fstab.ramdisk.common b/fstab.ramdisk.common
deleted file mode 100644
index 9554d4e..0000000
--- a/fstab.ramdisk.common
+++ /dev/null
@@ -1,4 +0,0 @@
-system		/system		ext4	noatime,ro,errors=panic		wait,logical,first_stage_mount
-vendor		/vendor		ext4	noatime,ro,errors=panic		wait,logical,first_stage_mount
-system_ext	/system_ext	ext4	noatime,ro,errors=panic		wait,logical,first_stage_mount
-product	/product	ext4	noatime,ro,errors=panic		wait,logical,first_stage_mount
diff --git a/gralloc/Android.mk b/gralloc/Android.mk
index 049b019..ec1c38e 100644
--- a/gralloc/Android.mk
+++ b/gralloc/Android.mk
@@ -28,7 +28,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libdrm \
-	libgbm \
+	libgbm_mesa \
 	liblog \
 	libcutils
 
diff --git a/gralloc/gralloc.cpp b/gralloc/gralloc.cpp
index c71e901..1cc9f55 100644
--- a/gralloc/gralloc.cpp
+++ b/gralloc/gralloc.cpp
@@ -24,7 +24,7 @@
 
 #define LOG_TAG "GRALLOC-GBM"
 
-#include <cutils/log.h>
+#include <log/log.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
diff --git a/gralloc/gralloc_gbm.cpp b/gralloc/gralloc_gbm.cpp
index bdb41b8..29d11cd 100644
--- a/gralloc/gralloc_gbm.cpp
+++ b/gralloc/gralloc_gbm.cpp
@@ -24,11 +24,12 @@
 
 #define LOG_TAG "GRALLOC-GBM"
 
-#include <cutils/log.h>
+#include <log/log.h>
 #include <cutils/atomic.h>
 #include <cutils/properties.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -382,8 +383,7 @@
 	gbm_bo_handle_map.emplace(handle, bo);
 
 	/* in pixels */
-	struct gralloc_handle_t *ghandle = gralloc_handle(handle);
-	*stride = ghandle->stride / gralloc_gbm_get_bpp(format);
+	*stride = gralloc_handle(handle)->stride / gralloc_gbm_get_bpp(format);
 
 	return handle;
 }
@@ -420,7 +420,7 @@
 		gbm_bo_set_user_data(bo, bo_data, gralloc_gbm_destroy_user_data);
 	}
 
-	ALOGI("lock bo %p, cnt=%d, usage=%x", bo, bo_data->lock_count, usage);
+	ALOGV("lock bo %p, cnt=%d, usage=%x", bo, bo_data->lock_count, usage);
 
 	/* allow multiple locks with compatible usages */
 	if (bo_data->lock_count && (bo_data->locked_for & usage) != usage)
@@ -491,10 +491,10 @@
 {
 	struct gralloc_handle_t *hnd = gralloc_handle(handle);
 	int ystride, cstride;
-	void *addr;
+	void *addr = 0;
 	int err;
 
-	ALOGD("handle %p, hnd %p, usage 0x%x", handle, hnd, usage);
+	ALOGV("handle %p, hnd %p, usage 0x%x", handle, hnd, usage);
 
 	err = gralloc_gbm_bo_lock(handle, usage, x, y, w, h, &addr);
 	if (err)
diff --git a/installer/db845c/flash-all-aosp.sh b/installer/db845c/flash-all-aosp.sh
index e6b1995..b3c677b 100755
--- a/installer/db845c/flash-all-aosp.sh
+++ b/installer/db845c/flash-all-aosp.sh
@@ -40,6 +40,8 @@
 fastboot flash boot "${ANDROID_PRODUCT_OUT}"/boot.img
 echo "FLASH-ALL-AOSP: Flash super/dynamic image"
 fastboot flash super "${ANDROID_PRODUCT_OUT}"/super.img
+echo "FLASH-ALL-AOSP: Flash cache image"
+fastboot flash cache "${ANDROID_PRODUCT_OUT}"/cache.img
 echo "FLASH-ALL-AOSP: Flash userdata image"
 fastboot flash userdata "${ANDROID_PRODUCT_OUT}"/userdata.img
 
diff --git a/manifest.xml b/manifest.xml
index 0a3f708..0c7ae03 100644
--- a/manifest.xml
+++ b/manifest.xml
@@ -142,22 +142,4 @@
             <instance>default</instance>
         </interface>
     </hal>
-    <hal format="hidl">
-        <name>android.hardware.wifi.hostapd</name>
-        <transport>hwbinder</transport>
-        <version>1.1</version>
-        <interface>
-            <name>IHostapd</name>
-            <instance>default</instance>
-        </interface>
-    </hal>
-    <hal format="hidl">
-        <name>android.hardware.wifi.supplicant</name>
-        <transport>hwbinder</transport>
-        <version>1.2</version>
-        <interface>
-            <name>ISupplicant</name>
-            <instance>default</instance>
-        </interface>
-    </hal>
 </manifest>
diff --git a/pixel3_mainline/device.mk b/pixel3_mainline/device.mk
index 8109ad3..e394c60 100644
--- a/pixel3_mainline/device.mk
+++ b/pixel3_mainline/device.mk
@@ -19,7 +19,7 @@
 $(call inherit-product, frameworks/native/build/phone-xhdpi-2048-dalvik-heap.mk)
 
 PRODUCT_COPY_FILES := \
-    device/linaro/dragonboard/fstab.ramdisk.common:$(TARGET_COPY_OUT_RAMDISK)/fstab.pixel3_mainline \
+    device/linaro/dragonboard/fstab.common:$(TARGET_COPY_OUT_RAMDISK)/fstab.pixel3_mainline \
     device/linaro/dragonboard/fstab.common:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.pixel3_mainline \
     device/linaro/dragonboard/init.common.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.pixel3_mainline.rc \
     device/linaro/dragonboard/init.common.usb.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.pixel3_mainline.usb.rc \
diff --git a/qcom/init.qcom.rc b/qcom/init.qcom.rc
index ba4f24c..94e9038 100644
--- a/qcom/init.qcom.rc
+++ b/qcom/init.qcom.rc
@@ -1,3 +1,10 @@
+service qrtr-ns /vendor/bin/qrtr-ns -f 1
+    class core
+    user root
+    group system
+    disabled
+    oneshot
+
 service pd_mapper /vendor/bin/pd-mapper
     class core
     user root
@@ -19,6 +26,10 @@
     disabled
     oneshot
 
+on early-init
+    exec - root -- /vendor/bin/qrtr-cfg 1
+    start qrtr-ns
+
 on post-fs
     start pd_mapper
     exec - root -- /system/bin/sleep 1
diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts
index f223cc4..bc69fcc 100644
--- a/sepolicy/file_contexts
+++ b/sepolicy/file_contexts
@@ -4,6 +4,7 @@
 /dev/block/platform/soc@0/1d84000\.ufshc/by-name/metadata	u:object_r:metadata_block_device:s0
 /dev/block/platform/soc@0/1d84000\.ufshc/by-name/super		u:object_r:super_block_device:s0
 /dev/block/platform/soc@0/1d84000\.ufshc/by-name/userdata	u:object_r:userdata_block_device:s0
+/dev/block/platform/soc@0/1d84000\.ufshc/by-name/cache		u:object_r:cache_block_device:s0
 
 /dev/dri				u:object_r:dri_device:s0
 /dev/dri/card0				u:object_r:graphics_device:s0
@@ -31,6 +32,8 @@
 
 /vendor/bin/hw/android\.hardware\.gatekeeper@1\.0-service\.software			u:object_r:hal_gatekeeper_default_exec:s0
 /vendor/bin/pd-mapper									u:object_r:pd_mapper_exec:s0
+/vendor/bin/qrtr-cfg									u:object_r:qrtr_exec:s0
+/vendor/bin/qrtr-ns									u:object_r:qrtr_exec:s0
 /vendor/bin/rmtfs									u:object_r:rmtfs_exec:s0
 /vendor/bin/tqftpserv									u:object_r:tqftpserv_exec:s0
 
@@ -38,5 +41,6 @@
 /vendor/lib(64)?/hw/gralloc\.gbm\.so							u:object_r:same_process_hal_file:s0
 /vendor/lib(64)?/libdrm\.so								u:object_r:same_process_hal_file:s0
 /vendor/lib(64)?/libdrm_freedreno\.so							u:object_r:same_process_hal_file:s0
-/vendor/lib(64)?/libgbm\.so								u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libgbm_mesa\.so							u:object_r:same_process_hal_file:s0
 /vendor/lib(64)?/libglapi\.so								u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libqrtr\.so								u:object_r:same_process_hal_file:s0
diff --git a/sepolicy/qrtr.te b/sepolicy/qrtr.te
new file mode 100644
index 0000000..8344398
--- /dev/null
+++ b/sepolicy/qrtr.te
@@ -0,0 +1,8 @@
+type qrtr, domain;
+type qrtr_exec, exec_type, vendor_file_type, file_type;
+init_daemon_domain(qrtr)
+
+allow qrtr self:capability net_admin;
+allow qrtr self:capability sys_admin;
+allow qrtr self:qipcrtr_socket create_socket_perms_no_ioctl;
+allow qrtr self:netlink_route_socket { create nlmsg_write read write };