Snap for 8417597 from dd5a84117c66e7d2cf6e491c40634cd0c0dc9c52 to sc-qpr3-release

Change-Id: Ibd034cfec82968cac0036c1372c17aeac6dbfe76
diff --git a/64bitonly/product/sdk_slim_arm64.mk b/64bitonly/product/sdk_slim_arm64.mk
new file mode 100644
index 0000000..1576e41
--- /dev/null
+++ b/64bitonly/product/sdk_slim_arm64.mk
@@ -0,0 +1,70 @@
+#
+# Copyright (C) 2021 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.
+#
+QEMU_USE_SYSTEM_EXT_PARTITIONS := true
+PRODUCT_USE_DYNAMIC_PARTITIONS := true
+# This is a build configuration for the 'slim' image targeted
+# for headless automated testing. Compared to the full AOSP 'sdk_phone'
+# image it removes/replaces most product apps, and turns off rendering
+# by default.
+#
+# All components inherited here go to system image
+#
+$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
+$(call inherit-product, $(SRC_TARGET_DIR)/product/generic_system.mk)
+
+# Enable mainline checking for exact this product name
+ifeq (sdk_slim_arm64,$(TARGET_PRODUCT))
+PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS := relaxed
+endif
+#
+# All components inherited here go to system_ext image
+#
+# don't include full handheld_system_Ext which includes SystemUi, Settings etc
+$(call inherit-product, $(SRC_TARGET_DIR)/product/media_system_ext.mk)
+$(call inherit-product, $(SRC_TARGET_DIR)/product/telephony_system_ext.mk)
+#
+# All components inherited here go to product image
+#
+# Just include webview, do not include most other apps
+$(call inherit-product, $(SRC_TARGET_DIR)/product/media_product.mk)
+# Include FakeSystemApp which replaces core system apps like Settings,
+# Launcher
+PRODUCT_PACKAGES += \
+    FakeSystemApp \
+#
+# All components inherited here go to vendor image
+#
+# this must go first - overwrites the goldfish handheld_core_hardware.xml
+$(call inherit-product, device/generic/goldfish/slim/vendor.mk)
+$(call inherit-product, device/generic/goldfish/64bitonly/product/arm64-vendor.mk)
+$(call inherit-product, device/generic/goldfish/64bitonly/product/emulator64_vendor.mk)
+$(call inherit-product, device/generic/goldfish/emulator64_x86_64/device.mk)
+
+# include the overlay that overrides systemui definitions with fakesystemapp
+DEVICE_PACKAGE_OVERLAYS := device/generic/goldfish/slim/overlay
+
+PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP := \
+     development/sys-img/images_atd_source.prop_template
+
+# Overrides
+PRODUCT_BRAND := Android
+PRODUCT_NAME := sdk_slim_arm64
+PRODUCT_DEVICE := emulator64_arm64
+PRODUCT_MODEL := Android ATD built for arm64
+# Disable <uses-library> checks for SDK product. It lacks some libraries (e.g.
+# RadioConfigLib), which makes it impossible to translate their module names to
+# library name, so the check fails.
+PRODUCT_BROKEN_VERIFY_USES_LIBRARIES := true
diff --git a/64bitonly/product/sdk_slim_x86_64.mk b/64bitonly/product/sdk_slim_x86_64.mk
new file mode 100644
index 0000000..c22a5fa
--- /dev/null
+++ b/64bitonly/product/sdk_slim_x86_64.mk
@@ -0,0 +1,70 @@
+#
+# Copyright (C) 2021 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.
+#
+QEMU_USE_SYSTEM_EXT_PARTITIONS := true
+PRODUCT_USE_DYNAMIC_PARTITIONS := true
+# This is a build configuration for the 'slim' image targeted
+# for headless automated testing. Compared to the full AOSP 'sdk_phone'
+# image it removes/replaces most product apps, and turns off rendering
+# by default.
+#
+# All components inherited here go to system image
+#
+$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
+$(call inherit-product, $(SRC_TARGET_DIR)/product/generic_system.mk)
+# Enable mainline checking for exact this product name
+ifeq (sdk_slim_x86_64,$(TARGET_PRODUCT))
+PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS := relaxed
+endif
+#
+# All components inherited here go to system_ext image
+#
+# don't include full handheld_system_Ext which includes SystemUi, Settings etc
+$(call inherit-product, $(SRC_TARGET_DIR)/product/media_system_ext.mk)
+$(call inherit-product, $(SRC_TARGET_DIR)/product/telephony_system_ext.mk)
+#
+# All components inherited here go to product image
+#
+# Just include webview, do not include most other apps
+$(call inherit-product, $(SRC_TARGET_DIR)/product/media_product.mk)
+# Include FakeSystemApp which replaces core system apps like Settings,
+# Launcher
+PRODUCT_PACKAGES += \
+    FakeSystemApp \
+#
+# All components inherited here go to vendor image
+#
+# this must go first - overwrites the goldfish handheld_core_hardware.xml
+$(call inherit-product, device/generic/goldfish/slim/vendor.mk)
+$(call inherit-product, device/generic/goldfish/64bitonly/product/x86_64-vendor.mk)
+$(call inherit-product, device/generic/goldfish/64bitonly/product/emulator64_vendor.mk)
+$(call inherit-product, device/generic/goldfish/emulator64_x86_64/device.mk)
+
+# include the overlay that overrides systemui definitions with fakesystemapp
+DEVICE_PACKAGE_OVERLAYS := device/generic/goldfish/slim/overlay
+
+PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP := \
+    development/sys-img/images_atd_source.prop_template
+
+
+# Overrides
+PRODUCT_BRAND := Android
+PRODUCT_NAME := sdk_slim_x86_64
+PRODUCT_DEVICE := emulator64_x86_64
+PRODUCT_MODEL := Android SDK built for x86_64
+# Disable <uses-library> checks for SDK product. It lacks some libraries (e.g.
+# RadioConfigLib), which makes it impossible to translate their module names to
+# library name, so the check fails.
+PRODUCT_BROKEN_VERIFY_USES_LIBRARIES := true
diff --git a/AndroidProducts.mk b/AndroidProducts.mk
index a4ff006..24cadfc 100644
--- a/AndroidProducts.mk
+++ b/AndroidProducts.mk
@@ -2,5 +2,7 @@
     $(LOCAL_DIR)/sdk_phone_x86_vendor.mk \
     $(LOCAL_DIR)/64bitonly/product/sdk_phone64_x86_64.mk \
     $(LOCAL_DIR)/64bitonly/product/sdk_phone64_arm64.mk \
+    $(LOCAL_DIR)/64bitonly/product/sdk_slim_x86_64.mk \
+    $(LOCAL_DIR)/64bitonly/product/sdk_slim_arm64.mk \
     $(LOCAL_DIR)/fvp.mk \
     $(LOCAL_DIR)/fvp_mini.mk
diff --git a/slim/FakeSystemApp/Android.bp b/slim/FakeSystemApp/Android.bp
new file mode 100644
index 0000000..9c7c2f3
--- /dev/null
+++ b/slim/FakeSystemApp/Android.bp
@@ -0,0 +1,11 @@
+android_app {
+    name: "FakeSystemApp",
+    platform_apis: true,
+    certificate: "platform",
+    manifest:  "AndroidManifest.xml",
+    srcs: [
+        "src/**/*.java",
+    ],
+    system_ext_specific: true,
+    overrides: ["DocumentsUI"],
+}
diff --git a/slim/FakeSystemApp/AndroidManifest.xml b/slim/FakeSystemApp/AndroidManifest.xml
new file mode 100644
index 0000000..213912c
--- /dev/null
+++ b/slim/FakeSystemApp/AndroidManifest.xml
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2021, 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.
+*/
+-->
+<manifest
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.fakesystemapp">
+    <uses-sdk android:targetSdkVersion="30" android:minSdkVersion="30"/>
+
+    <!-- WindowManager -->
+    <uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" />
+    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
+    <!-- Screen Capturing -->
+    <uses-permission android:name="android.permission.MANAGE_MEDIA_PROJECTION" />
+
+    <!-- Application needs SMS/MMS permissions -->
+    <uses-permission android:name="android.permission.READ_SMS"/>
+    <uses-permission android:name="android.permission.WRITE_SMS"/>
+    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
+    <uses-permission android:name="android.permission.RECEIVE_MMS"/>
+    <uses-permission android:name="android.permission.SEND_SMS"/>
+
+    <application
+        android:label="Fake System App"
+        android:supportsRtl="true"
+        >
+
+        <!--
+        FallbackHome activity is used when default launcher activity is not encryption aware.
+        Effectively replaces Settings:FallbackHome, which is needed to allow device to boot when
+        Settings is removed
+        -->
+        <activity android:name=".launcher.FallbackHome"
+                  android:excludeFromRecents="true"
+                  android:label=""
+                  android:screenOrientation="nosensor"
+                  android:directBootAware="true">
+            <intent-filter android:priority="-1000">
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.HOME"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+        </activity>
+
+        <activity android:name=".launcher.EmptyHomeActivity"
+                  android:excludeFromRecents="true"
+                  android:label=""
+                  android:screenOrientation="nosensor"
+                  android:enabled="true">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.HOME"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+        </activity>
+
+        <!-- started from MediaProjectionManager -->
+        <activity android:name=".systemui.SlimMediaProjectionPermissionActivity"
+                  android:exported="true"
+                  android:finishOnCloseSystemDialogs="true"
+                  android:launchMode="singleTop"
+                  android:excludeFromRecents="true"/>
+
+        <!-- appease the framework/CTS TelephonyProvider tests which wants a default SMS app -->
+        <!-- copy the required components from packages/apps/PermissionController/res/xml/roles.xml -->
+        <receiver android:name=".messaging.StubSmsDeliverReceiver"
+            android:permission="android.permission.BROADCAST_SMS"
+            android:enabled="true" >
+            <intent-filter>
+                <action android:name="android.provider.Telephony.SMS_DELIVER" />
+            </intent-filter>
+        </receiver>
+        <receiver android:name=".messaging.StubMmsWapPushDeliverReceiver"
+            android:permission="android.permission.BROADCAST_WAP_PUSH"
+            android:enabled="true">
+            <intent-filter>
+                <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
+                <data android:mimeType="application/vnd.wap.mms-message" />
+            </intent-filter>
+        </receiver>
+        <service
+            android:name=".messaging.StubNoConfirmationSmsSendService"
+            android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
+        android:exported="true">
+            <intent-filter>
+                <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
+                <data android:scheme="smsto" />
+            </intent-filter>
+        </service>
+        <activity android:name=".messaging.StubLaunchConversationActivity"
+                  android:configChanges="orientation|screenSize|keyboardHidden"
+                  android:screenOrientation="user"
+                  android:noHistory="true"
+                  android:documentLaunchMode="always">
+            <intent-filter>
+                <action android:name="android.intent.action.VIEW" />
+                <action android:name="android.intent.action.SENDTO" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.BROWSABLE" />
+                <data android:scheme="sms" />
+                <data android:scheme="smsto" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.VIEW" />
+                <action android:name="android.intent.action.SENDTO" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.BROWSABLE" />
+                <data android:scheme="mms" />
+                <data android:scheme="mmsto" />
+            </intent-filter>
+        </activity>
+        <activity android:name=".browser.StubBrowserActivity"
+                  android:exported="true" >
+            <!-- Catch intents which do not specify a MIME type -->
+            <intent-filter>
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.BROWSABLE" />
+                <data android:scheme="http" />
+                <data android:scheme="https" />
+            </intent-filter>
+            <!-- Catch intents which do specify a MIME type -->
+            <intent-filter>
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.BROWSABLE" />
+                <data android:scheme="http" />
+                <data android:scheme="https" />
+                <data android:mimeType="text/html"/>
+                <data android:mimeType="text/plain"/>
+                <data android:mimeType="application/xhtml+xml"/>
+                <data android:mimeType="application/vnd.wap.xhtml+xml"/> <!-- XHTML MP -->
+            </intent-filter>
+        </activity>
+
+    </application>
+</manifest>
diff --git a/slim/FakeSystemApp/res/drawable/ic_media_projection_permission.xml b/slim/FakeSystemApp/res/drawable/ic_media_projection_permission.xml
new file mode 100644
index 0000000..515af7e
--- /dev/null
+++ b/slim/FakeSystemApp/res/drawable/ic_media_projection_permission.xml
@@ -0,0 +1,26 @@
+<!--
+Copyright (C) 2021 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.
+-->
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+    android:insetLeft="2.5dp"
+    android:insetRight="2.5dp">
+    <vector android:width="24dp"
+            android:height="24dp"
+            android:viewportWidth="24.0"
+            android:viewportHeight="24.0">
+        <path android:fillColor="#FF000000" android:pathData="M1,18v3h3C4,19.34 2.66,18 1,18zM1,14v2c2.76,0 5,2.24 5,5h2C8,17.13 4.87,14 1,14zM1,10v2c4.97,0 9,4.03 9,9h2C12,14.92 7.07,10 1,10zM21,3H3C1.9,3 1,3.9 1,5v3h2V5h18v14h-7v2h7c1.1,0 2,-0.9 2,-2V5C23,3.9 22.1,3 21,3z"/>
+        <path android:fillColor="#FF0000" android:pathData="M19,7H5v1.63c3.96,1.28 7.09,4.41 8.37,8.37H19V7z"/>
+    </vector>
+</inset>
diff --git a/slim/FakeSystemApp/res/layout/media_projection_dialog_title.xml b/slim/FakeSystemApp/res/layout/media_projection_dialog_title.xml
new file mode 100644
index 0000000..7f5b814
--- /dev/null
+++ b/slim/FakeSystemApp/res/layout/media_projection_dialog_title.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright 2021, 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.
+-->
+
+<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
+        xmlns:android="http://schemas.android.com/apk/res/android"
+
+        android:paddingStart="?android:attr/dialogPreferredPadding"
+        android:paddingEnd="?android:attr/dialogPreferredPadding"
+        android:orientation="vertical">
+    <ImageView
+        android:id="@+id/dialog_icon"
+        android:src="@drawable/ic_media_projection_permission"
+        android:layout_height="24dp"
+        android:layout_width="24dp"
+        android:layout_marginTop="18dp"
+        android:layout_marginBottom="12dp"
+        android:layout_gravity="center_horizontal" />
+    <TextView
+        android:id="@+id/dialog_title"
+        android:gravity="center"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textSize="20sp"
+        android:textColor="?android:attr/textColorPrimary"
+        android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Title" />
+</LinearLayout>
diff --git a/slim/FakeSystemApp/res/values/strings.xml b/slim/FakeSystemApp/res/values/strings.xml
new file mode 100644
index 0000000..dab7a28
--- /dev/null
+++ b/slim/FakeSystemApp/res/values/strings.xml
@@ -0,0 +1,25 @@
+<!--
+  ~ Copyright (C) 2021 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 xmlns:android="http://schemas.android.com/apk/res/android"
+           xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+<string name="media_projection_action_text" msgid="3634906766918186440">"Start now"</string>
+    <string name="media_projection_dialog_text" msgid="1755705274910034772">"<xliff:g id="APP_SEEKING_PERMISSION">%s</xliff:g> will have access to all of the information that is visible on your screen or played from your device while recording or casting. This includes information such as passwords, payment details, photos, messages and audio that you play."</string>
+    <string name="media_projection_dialog_service_text" msgid="958000992162214611">"The service providing this function will have access to all of the information that is visible on your screen or played from your device while recording or casting. This includes information such as passwords, payment details, photos, messages and audio that you play."</string>
+    <string name="media_projection_dialog_service_title" msgid="2888507074107884040">"Start recording or casting?"</string>
+    <string name="media_projection_dialog_title" msgid="3316063622495360646">"Start recording or casting with <xliff:g id="APP_SEEKING_PERMISSION">%s</xliff:g>?"</string>
+    <string name="media_projection_remember_text" msgid="6896767327140422951">"Don\'t show again"</string>
+</resources>
\ No newline at end of file
diff --git a/slim/FakeSystemApp/src/com/android/fakesystemapp/browser/StubBrowserActivity.java b/slim/FakeSystemApp/src/com/android/fakesystemapp/browser/StubBrowserActivity.java
new file mode 100644
index 0000000..c93d9f6
--- /dev/null
+++ b/slim/FakeSystemApp/src/com/android/fakesystemapp/browser/StubBrowserActivity.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+package com.android.fakesystemapp.browser;
+
+import android.app.Activity;
+
+/**
+ * A blank activity used to handle browser intents.
+ *
+ * This allows code-under-test that attempt to resolve or send browser intents to pass on the slim
+ * image, which has no actual browser.
+ */
+public class StubBrowserActivity extends Activity {}
diff --git a/slim/FakeSystemApp/src/com/android/fakesystemapp/launcher/EmptyHomeActivity.java b/slim/FakeSystemApp/src/com/android/fakesystemapp/launcher/EmptyHomeActivity.java
new file mode 100644
index 0000000..3f2eaa3
--- /dev/null
+++ b/slim/FakeSystemApp/src/com/android/fakesystemapp/launcher/EmptyHomeActivity.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+package com.android.fakesystemapp.launcher;
+
+import android.app.Activity;
+
+/**
+ * A blank home activity used to replace the launcher activity.
+ *
+ * <p>This is in place to emulate the android system behavior when both the real Launcher and
+ * Settings app are installed.
+ *
+ * <ol>
+ *   <li>system boots - still encrypted.
+ *   <li>System looks for default home 'directBootAware' activity. Finds FallbackHome and launches
+ *   <li>user_unlocked event sent - FallbackHome triggers powermanager.userActivity and finishes
+ *   <li>System looks for home activity - finds EmptyHomeActivity and launches
+ * </ol>
+ */
+public class EmptyHomeActivity extends Activity {}
diff --git a/slim/FakeSystemApp/src/com/android/fakesystemapp/launcher/FallbackHome.java b/slim/FakeSystemApp/src/com/android/fakesystemapp/launcher/FallbackHome.java
new file mode 100644
index 0000000..7935667
--- /dev/null
+++ b/slim/FakeSystemApp/src/com/android/fakesystemapp/launcher/FallbackHome.java
@@ -0,0 +1,101 @@
+/*
+  * Copyright (C) 2021 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.
+*/
+
+package com.android.fakesystemapp.launcher;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.os.PowerManager;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.util.Log;
+
+import java.util.Objects;
+
+/**
+ * Home Activity that gets launched before user has unlocked device.
+ *
+ * Effectively replaces and mirrors logic in  com.android.settings.FallbackHome, so device
+ * boots when Settings app is removed from image.
+ */
+public final class FallbackHome extends Activity {
+
+    private static final String TAG = "FallbackHome";
+
+    private Handler mHandler;
+    private BroadcastReceiver mReceiver;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        mReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                maybeFinish();
+            }
+        };
+
+        mHandler = new Handler(getMainLooper()) {
+            @Override
+            public void handleMessage(Message msg) {
+                maybeFinish();
+            }
+        };
+
+        // TODO: consider adding logic to make screen black if not provisioned
+
+        registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
+        maybeFinish();
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        unregisterReceiver(mReceiver);
+    }
+
+    private void maybeFinish() {
+        if (getSystemService(UserManager.class).isUserUnlocked()) {
+            final Intent homeIntent = new Intent(Intent.ACTION_MAIN)
+                    .addCategory(Intent.CATEGORY_HOME);
+            final ResolveInfo homeInfo = getPackageManager().resolveActivity(homeIntent, 0);
+            if (Objects.equals(this.getClass().getName(), homeInfo.activityInfo.name)) {
+                if (UserManager.isSplitSystemUser()
+                        && UserHandle.myUserId() == UserHandle.USER_SYSTEM) {
+                    // This avoids the situation where the system user has no home activity after
+                    // SUW and this activity continues to throw out warnings. See b/28870689.
+                    return;
+                }
+                Log.d(TAG, "User unlocked but no home; let's hope someone enables one soon?");
+                mHandler.sendEmptyMessageDelayed(0, 500);
+            } else {
+                Log.d(TAG, String.format("User unlocked and real home %s found; let's go!", homeInfo.activityInfo.name));
+                getSystemService(PowerManager.class).userActivity(
+                        SystemClock.uptimeMillis(), false);
+                finish();
+            }
+        }
+    }
+}
diff --git a/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubLaunchConversationActivity.java b/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubLaunchConversationActivity.java
new file mode 100644
index 0000000..becf9cb
--- /dev/null
+++ b/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubLaunchConversationActivity.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+package com.android.fakesystemapp.messaging;
+
+import android.app.Activity;
+
+public class StubLaunchConversationActivity extends Activity {
+}
diff --git a/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubMmsWapPushDeliverReceiver.java b/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubMmsWapPushDeliverReceiver.java
new file mode 100644
index 0000000..10ba5e1
--- /dev/null
+++ b/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubMmsWapPushDeliverReceiver.java
@@ -0,0 +1,13 @@
+package com.android.fakesystemapp.messaging;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+public class StubMmsWapPushDeliverReceiver extends BroadcastReceiver {
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        // ignore
+    }
+}
diff --git a/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubNoConfirmationSmsSendService.java b/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubNoConfirmationSmsSendService.java
new file mode 100644
index 0000000..e351e8f
--- /dev/null
+++ b/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubNoConfirmationSmsSendService.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+package com.android.fakesystemapp.messaging;
+
+import android.app.IntentService;
+import android.content.Intent;
+
+public class StubNoConfirmationSmsSendService extends IntentService  {
+    public StubNoConfirmationSmsSendService(String name) {
+        super(name);
+    }
+
+    @Override
+    protected void onHandleIntent(Intent intent) {
+        // ignore
+    }
+}
diff --git a/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubSmsDeliverReceiver.java b/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubSmsDeliverReceiver.java
new file mode 100644
index 0000000..13154be
--- /dev/null
+++ b/slim/FakeSystemApp/src/com/android/fakesystemapp/messaging/StubSmsDeliverReceiver.java
@@ -0,0 +1,13 @@
+package com.android.fakesystemapp.messaging;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+public class StubSmsDeliverReceiver extends BroadcastReceiver {
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        // ignore
+    }
+}
diff --git a/slim/FakeSystemApp/src/com/android/fakesystemapp/systemui/SlimMediaProjectionPermissionActivity.java b/slim/FakeSystemApp/src/com/android/fakesystemapp/systemui/SlimMediaProjectionPermissionActivity.java
new file mode 100644
index 0000000..6eec84f
--- /dev/null
+++ b/slim/FakeSystemApp/src/com/android/fakesystemapp/systemui/SlimMediaProjectionPermissionActivity.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+package com.android.fakesystemapp.systemui;
+
+import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.media.projection.IMediaProjection;
+import android.media.projection.IMediaProjectionManager;
+import android.media.projection.MediaProjectionManager;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.text.TextPaint;
+import android.util.Log;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.TextView;
+
+import com.android.fakesystemapp.R;
+
+/**
+ * A  fork of systemui's MediaProjectionPermissionActivity
+ *
+ * Modifications are marked with SLIM-CHANGED
+ */
+public class SlimMediaProjectionPermissionActivity extends Activity implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
+    private static final String TAG = "MediaProjectionPermissionActivity";
+
+    private String mPackageName;
+    private int mUid;
+    private IMediaProjectionManager mService;
+
+    private AlertDialog mDialog;
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+
+        mPackageName = getCallingPackage();
+        IBinder b = ServiceManager.getService(MEDIA_PROJECTION_SERVICE);
+        mService = IMediaProjectionManager.Stub.asInterface(b);
+
+        if (mPackageName == null) {
+            finish();
+            return;
+        }
+
+        PackageManager packageManager = getPackageManager();
+        ApplicationInfo aInfo;
+        try {
+            aInfo = packageManager.getApplicationInfo(mPackageName, 0);
+            mUid = aInfo.uid;
+        } catch (PackageManager.NameNotFoundException e) {
+            Log.e(TAG, "unable to look up package name", e);
+            finish();
+            return;
+        }
+
+        try {
+            if (mService.hasProjectionPermission(mUid, mPackageName)) {
+                setResult(RESULT_OK, getMediaProjectionIntent(mUid, mPackageName));
+                finish();
+                return;
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error checking projection permissions", e);
+            finish();
+            return;
+        }
+
+        TextPaint paint = new TextPaint();
+        paint.setTextSize(42);
+
+
+        CharSequence dialogText = null;
+        CharSequence dialogTitle = null;
+        // SLIM-CHANGED - simplify text and title
+
+            dialogText = getString(R.string.media_projection_dialog_service_text);
+            dialogTitle = getString(R.string.media_projection_dialog_service_title);
+
+        View dialogTitleView = View.inflate(this, R.layout.media_projection_dialog_title, null);
+        TextView titleText = (TextView) dialogTitleView.findViewById(R.id.dialog_title);
+        titleText.setText(dialogTitle);
+
+        mDialog = new AlertDialog.Builder(this)
+                .setCustomTitle(dialogTitleView)
+                .setMessage(dialogText)
+                .setPositiveButton(R.string.media_projection_action_text, this)
+                .setNegativeButton(android.R.string.cancel, this)
+                .setOnCancelListener(this)
+                .create();
+
+        mDialog.create();
+        mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setFilterTouchesWhenObscured(true);
+
+        final Window w = mDialog.getWindow();
+        w.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+        w.addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+
+        mDialog.show();
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        if (mDialog != null) {
+            mDialog.dismiss();
+        }
+    }
+
+    @Override
+    public void onClick(DialogInterface dialog, int which) {
+        try {
+            if (which == AlertDialog.BUTTON_POSITIVE) {
+                setResult(RESULT_OK, getMediaProjectionIntent(mUid, mPackageName));
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error granting projection permission", e);
+            setResult(RESULT_CANCELED);
+        } finally {
+            if (mDialog != null) {
+                mDialog.dismiss();
+            }
+            finish();
+        }
+    }
+
+    private Intent getMediaProjectionIntent(int uid, String packageName)
+            throws RemoteException {
+        IMediaProjection projection = mService.createProjection(uid, packageName,
+                MediaProjectionManager.TYPE_SCREEN_CAPTURE, false /* permanentGrant */);
+        Intent intent = new Intent();
+        intent.putExtra(MediaProjectionManager.EXTRA_MEDIA_PROJECTION, projection.asBinder());
+        return intent;
+    }
+
+    @Override
+    public void onCancel(DialogInterface dialog) {
+        finish();
+    }
+
+}
+
diff --git a/slim/OWNERS b/slim/OWNERS
new file mode 100644
index 0000000..b567803
--- /dev/null
+++ b/slim/OWNERS
@@ -0,0 +1,2 @@
+yahan@google.com
+brettchabot@google.com
diff --git a/slim/README b/slim/README
new file mode 100644
index 0000000..e95d139
--- /dev/null
+++ b/slim/README
@@ -0,0 +1,2 @@
+Contains components for the slim system image.
+
diff --git a/slim/data/etc/android.hardware.disable.xml b/slim/data/etc/android.hardware.disable.xml
new file mode 100644
index 0000000..a96f8f9
--- /dev/null
+++ b/slim/data/etc/android.hardware.disable.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 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.
+-->
+<!-- Empty permissions to replace any existing permissions with. -->
+<permissions>
+</permissions>
diff --git a/slim/data/etc/slim_handheld_core_hardware.xml b/slim/data/etc/slim_handheld_core_hardware.xml
new file mode 100644
index 0000000..c933d72
--- /dev/null
+++ b/slim/data/etc/slim_handheld_core_hardware.xml
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 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.
+
+This file should be almost identical to device/generic/goldfish/data/etc/handheld_core_hardware.xml.
+     The differences are:
+       Remove features available in goldfish:
+         android.software.secure_lock_screen
+         android.software.picture_in_picture
+-->
+<permissions>
+    <feature name="android.hardware.audio.output" />
+    <feature name="android.hardware.bluetooth" />
+    <feature name="android.hardware.camera" />
+    <feature name="android.hardware.location" />
+    <feature name="android.hardware.location.gps" />
+    <feature name="android.hardware.location.network" />
+    <feature name="android.hardware.sensor.accelerometer" />
+    <feature name="android.hardware.sensor.ambient_temperature" />
+    <feature name="android.hardware.sensor.compass" />
+    <feature name="android.hardware.sensor.barometer" />
+    <feature name="android.hardware.sensor.light" />
+    <feature name="android.hardware.sensor.proximity" />
+    <feature name="android.hardware.sensor.relative_humidity" />
+    <feature name="android.hardware.sensor.gyroscope" />
+    <feature name="android.hardware.sensor.hinge_angle" />
+    <feature name="android.hardware.telephony" />
+    <feature name="android.hardware.telephony.gsm" />
+    <feature name="android.hardware.touchscreen" />
+    <feature name="android.hardware.microphone" />
+    <feature name="android.hardware.screen.portrait" />
+    <feature name="android.hardware.screen.landscape" />
+
+    <!-- basic system services -->
+    <feature name="android.software.app_widgets" />
+    <feature name="android.software.connectionservice" />
+    <feature name="android.software.voice_recognizers" notLowRam="true" />
+    <feature name="android.software.backup" />
+    <feature name="android.software.home_screen" />
+    <feature name="android.software.input_methods" />
+    <feature name="android.software.midi" />
+    <feature name="android.software.print" />
+    <feature name="android.software.cant_save_state" />
+    <feature name="android.software.companion_device_setup" />
+
+    <!-- Feature to specify if the device supports adding device admins. -->
+    <feature name="android.software.device_admin" />
+
+    <!-- Feature to specify if the device support managed users. -->
+    <feature name="android.software.managed_users" />
+
+    <feature name="android.software.activities_on_secondary_displays" />
+
+    <feature name="android.software.cts" />
+
+    <!-- Feature to specify if the device supports controls. -->
+    <feature name="android.software.controls" />
+
+    <!-- devices with GPS must include android.hardware.location.gps.xml -->
+    <!-- devices with an autofocus camera and/or flash must include either
+         android.hardware.camera.autofocus.xml or
+         android.hardware.camera.autofocus-flash.xml -->
+    <!-- devices with a front facing camera must include
+         android.hardware.camera.front.xml -->
+    <!-- devices with WiFi must also include android.hardware.wifi.xml -->
+    <!-- devices that support multitouch must include the most appropriate one
+         of these files:
+
+         If only partial (non-independent) pointers are supported:
+         android.hardware.touchscreen.multitouch.xml
+
+         If up to 4 independently tracked pointers are supported:
+         include android.hardware.touchscreen.multitouch.distinct.xml
+
+         If 5 or more independently tracked pointers are supported:
+         include android.hardware.touchscreen.multitouch.jazzhand.xml
+
+         ONLY ONE of the above should be included. -->
+    <!-- devices with an ambient light sensor must also include
+         android.hardware.sensor.light.xml -->
+    <!-- devices with a proximity sensor must also include
+         android.hardware.sensor.proximity.xml -->
+    <!-- GSM phones must also include android.hardware.telephony.gsm.xml -->
+    <!-- CDMA phones must also include android.hardware.telephony.cdma.xml -->
+    <!-- Devices that have low-latency audio stacks suitable for apps like
+         VoIP may include android.hardware.audio.low_latency.xml. ONLY apps
+         that meet the requirements specified in the CDD may include this. -->
+</permissions>
diff --git a/slim/overlay/frameworks/base/core/res/res/values/config.xml b/slim/overlay/frameworks/base/core/res/res/values/config.xml
new file mode 100644
index 0000000..7a99de5
--- /dev/null
+++ b/slim/overlay/frameworks/base/core/res/res/values/config.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2021 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>
+  <!--
+    Component name of media projection permission dialog.
+    In a full emulator image this is housed in systemui.
+    Since slim image removes systemui, point the framework
+    at the equivalent in fakesystemapp.
+  -->
+  <string name="config_mediaProjectionPermissionDialogComponent" translatable="false">com.android.fakesystemapp/.systemui.SlimMediaProjectionPermissionActivity</string>
+  <!-- appease the cts TelephonyProvider tests, which can have abscure failures if there is no default SMS app -->
+  <string name="default_sms_application" translatable="false">com.android.fakesystemapp</string>
+
+  <!-- turn off features provided by SystemUI, which slim image does not have -->
+  <bool name="config_quickSettingsSupported">false</bool>
+  <bool name="config_supportsInsecureLockScreen">false</bool>
+  <bool name="config_supportsSplitScreenMultiWindow">false</bool>
+  <bool name ="config_enableWallpaperService">false</bool>
+  <bool name="config_checkWallpaperAtBoot">false</bool>
+
+  <!-- turn off window manager snapshots, which do hardware rendering -->
+  <bool name="config_disableTaskSnapshots">true</bool>
+</resources>
diff --git a/slim/vendor.mk b/slim/vendor.mk
new file mode 100644
index 0000000..ad2ffdf
--- /dev/null
+++ b/slim/vendor.mk
@@ -0,0 +1,26 @@
+#
+# Copyright (C) 2021 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.
+
+#
+# This file overwrites the handheld_core_hardware.xml from goldfish
+#
+
+# Copy slim_core_hardware and overwrite handheld_core_hardware.xml with a disable config.
+PRODUCT_COPY_FILES += \
+    device/generic/goldfish/slim/data/etc/android.hardware.disable.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/handheld_core_hardware.xml \
+    device/generic/goldfish/slim/data/etc/slim_handheld_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/slim_handheld_core_hardware.xml \
+
+PRODUCT_SYSTEM_DEFAULT_PROPERTIES += \
+    debug.hwui.drawing_enabled=0