Update to v102
diff --git a/patches/platform_frameworks_base/0001-Fix-backlight-control-on-Galaxy-S9.patch b/patches/platform_frameworks_base/0001-Fix-backlight-control-on-Galaxy-S9.patch
index 46691c6..e78bdc1 100644
--- a/patches/platform_frameworks_base/0001-Fix-backlight-control-on-Galaxy-S9.patch
+++ b/patches/platform_frameworks_base/0001-Fix-backlight-control-on-Galaxy-S9.patch
@@ -1,7 +1,7 @@
 From 83c5a5d0e192b901ec36059bf2fb1fc8d63de1a7 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Sat, 24 Mar 2018 08:01:48 +0100
-Subject: [PATCH 01/19] Fix backlight control on Galaxy S9(+)
+Subject: [PATCH 01/20] Fix backlight control on Galaxy S9(+)
 
 ---
  services/core/java/com/android/server/lights/LightsService.java | 7 +++++++
diff --git a/patches/platform_frameworks_base/0002-Relax-requirement-for-visible-flag-to-sdcards.patch b/patches/platform_frameworks_base/0002-Relax-requirement-for-visible-flag-to-sdcards.patch
index 4ce0d86..b72030d 100644
--- a/patches/platform_frameworks_base/0002-Relax-requirement-for-visible-flag-to-sdcards.patch
+++ b/patches/platform_frameworks_base/0002-Relax-requirement-for-visible-flag-to-sdcards.patch
@@ -1,7 +1,7 @@
 From 4547592e86f29d043daf0f3385c802949fa73193 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Tue, 28 Nov 2017 18:28:04 +0100
-Subject: [PATCH 02/19] Relax requirement for visible flag to sdcards
+Subject: [PATCH 02/20] Relax requirement for visible flag to sdcards
 
 The vast majority of sdcard readers are stable enough to be declared by
 the API. (I see no counter-example)
diff --git a/patches/platform_frameworks_base/0003-Also-scan-system-overlay.patch b/patches/platform_frameworks_base/0003-Also-scan-system-overlay.patch
index a64821d..6659de3 100644
--- a/patches/platform_frameworks_base/0003-Also-scan-system-overlay.patch
+++ b/patches/platform_frameworks_base/0003-Also-scan-system-overlay.patch
@@ -1,7 +1,7 @@
 From b3bf3329f50ba0fc4a494a772d5f76b66dc67a2c Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Tue, 1 May 2018 17:47:36 +0200
-Subject: [PATCH 03/19] Also scan /system/overlay
+Subject: [PATCH 03/20] Also scan /system/overlay
 
 Change-Id: Ib0223560606b80cdaaa986b159b34b4db0154589
 ---
diff --git a/patches/platform_frameworks_base/0004-Don-t-crash-if-there-is-IR-HAL-is-not-declared.patch b/patches/platform_frameworks_base/0004-Don-t-crash-if-there-is-IR-HAL-is-not-declared.patch
index 43cfc48..e6d5d6c 100644
--- a/patches/platform_frameworks_base/0004-Don-t-crash-if-there-is-IR-HAL-is-not-declared.patch
+++ b/patches/platform_frameworks_base/0004-Don-t-crash-if-there-is-IR-HAL-is-not-declared.patch
@@ -1,7 +1,7 @@
 From 89b3b71fc07b7069b7c5f345762925b9743e6361 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Thu, 17 May 2018 20:28:35 +0200
-Subject: [PATCH 04/19] Don't crash if there is IR HAL is not declared
+Subject: [PATCH 04/20] Don't crash if there is IR HAL is not declared
 
 ---
  services/core/java/com/android/server/ConsumerIrService.java | 2 --
diff --git a/patches/platform_frameworks_base/0005-Fix-62.patch b/patches/platform_frameworks_base/0005-Fix-62.patch
index caf028d..871f336 100644
--- a/patches/platform_frameworks_base/0005-Fix-62.patch
+++ b/patches/platform_frameworks_base/0005-Fix-62.patch
@@ -1,7 +1,7 @@
 From ca27968613cbe47b158a690f82347586264bbe54 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Wed, 30 May 2018 14:05:30 +0200
-Subject: [PATCH 05/19] Fix(?) #62
+Subject: [PATCH 05/20] Fix(?) #62
 
 ---
  .../SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java     | 5 ++++-
diff --git a/patches/platform_frameworks_base/0006-S9-brightness-override-only-for-screen.patch b/patches/platform_frameworks_base/0006-S9-brightness-override-only-for-screen.patch
index 3ecbdb3..7bf16c0 100644
--- a/patches/platform_frameworks_base/0006-S9-brightness-override-only-for-screen.patch
+++ b/patches/platform_frameworks_base/0006-S9-brightness-override-only-for-screen.patch
@@ -1,7 +1,7 @@
 From 5b5bafd457463ca4c90d3d2470703655179220ae Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <pierre-hugues.husson@softathome.com>
 Date: Thu, 7 Jun 2018 13:36:51 +0200
-Subject: [PATCH 06/19] S9 brightness override only for screen
+Subject: [PATCH 06/20] S9 brightness override only for screen
 
 ---
  .../core/java/com/android/server/lights/LightsService.java   | 12 +++++++-----
diff --git a/patches/platform_frameworks_base/0007-WIP-Fix-OP6-brightness.patch b/patches/platform_frameworks_base/0007-WIP-Fix-OP6-brightness.patch
index 8aafc40..2ed736c 100644
--- a/patches/platform_frameworks_base/0007-WIP-Fix-OP6-brightness.patch
+++ b/patches/platform_frameworks_base/0007-WIP-Fix-OP6-brightness.patch
@@ -1,7 +1,7 @@
 From c23233a753225db8dcb6c74c53c0edc0ab2be44e Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <pierre-hugues.husson@softathome.com>
 Date: Thu, 7 Jun 2018 13:42:02 +0200
-Subject: [PATCH 07/19] [WIP] Fix OP6 brightness
+Subject: [PATCH 07/20] [WIP] Fix OP6 brightness
 
 ---
  .../core/java/com/android/server/lights/LightsService.java   | 12 ++++++++++++
diff --git a/patches/platform_frameworks_base/0008-Try-to-make-brightness-more-generic-using-property-s.patch b/patches/platform_frameworks_base/0008-Try-to-make-brightness-more-generic-using-property-s.patch
index 4619a1b..f618518 100644
--- a/patches/platform_frameworks_base/0008-Try-to-make-brightness-more-generic-using-property-s.patch
+++ b/patches/platform_frameworks_base/0008-Try-to-make-brightness-more-generic-using-property-s.patch
@@ -1,7 +1,7 @@
 From c87dbdb6ff897e1f25ce90acf136b4606337db00 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Sun, 10 Jun 2018 22:54:55 +0200
-Subject: [PATCH 08/19] Try to make brightness more generic using property set
+Subject: [PATCH 08/20] Try to make brightness more generic using property set
  by rw-system
 
 ---
diff --git a/patches/platform_frameworks_base/0009-property-matching-RROs-allow-to-prefix-the-value-wit.patch b/patches/platform_frameworks_base/0009-property-matching-RROs-allow-to-prefix-the-value-wit.patch
index d5dd3af..7dc7265 100644
--- a/patches/platform_frameworks_base/0009-property-matching-RROs-allow-to-prefix-the-value-wit.patch
+++ b/patches/platform_frameworks_base/0009-property-matching-RROs-allow-to-prefix-the-value-wit.patch
@@ -1,7 +1,7 @@
 From af7f850833c9de9d3f055406038dfe7c9108a0e3 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Tue, 12 Jun 2018 22:55:32 +0200
-Subject: [PATCH 09/19] property-matching RROs: allow to prefix the value with
+Subject: [PATCH 09/20] property-matching RROs: allow to prefix the value with
  + to do glob match instead of exact match
 
 ---
diff --git a/patches/platform_frameworks_base/0010-Fix-typo-on-fnmatch-return-value-check.patch b/patches/platform_frameworks_base/0010-Fix-typo-on-fnmatch-return-value-check.patch
index dac4cc7..af92a01 100644
--- a/patches/platform_frameworks_base/0010-Fix-typo-on-fnmatch-return-value-check.patch
+++ b/patches/platform_frameworks_base/0010-Fix-typo-on-fnmatch-return-value-check.patch
@@ -1,7 +1,7 @@
 From 88e3e3df61a84c0a569fe128e1e22776af2e9aa8 Mon Sep 17 00:00:00 2001
 From: Song Fuchang <song.fc@gmail.com>
 Date: Sun, 17 Jun 2018 22:39:37 +0800
-Subject: [PATCH 10/19] Fix typo on fnmatch return value check
+Subject: [PATCH 10/20] Fix typo on fnmatch return value check
 
 ---
  cmds/idmap/scan.cpp | 2 +-
diff --git a/patches/platform_frameworks_base/0011-Add-Qualcomm-starlte.patch b/patches/platform_frameworks_base/0011-Add-Qualcomm-starlte.patch
index cea8a7c..8fae195 100644
--- a/patches/platform_frameworks_base/0011-Add-Qualcomm-starlte.patch
+++ b/patches/platform_frameworks_base/0011-Add-Qualcomm-starlte.patch
@@ -1,7 +1,7 @@
 From f91ab52edbb4ed99689e0347f08cb9cd135bdbc5 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Mon, 25 Jun 2018 22:43:32 +0200
-Subject: [PATCH 11/19] Add Qualcomm starlte
+Subject: [PATCH 11/20] Add Qualcomm starlte
 
 ---
  services/core/java/com/android/server/lights/LightsService.java | 4 +++-
diff --git a/patches/platform_frameworks_base/0012-Galaxy-S9-remaining-of-HAL-onEnroll-is-actually-a-pe.patch b/patches/platform_frameworks_base/0012-Galaxy-S9-remaining-of-HAL-onEnroll-is-actually-a-pe.patch
index 3493467..e3ff8c2 100644
--- a/patches/platform_frameworks_base/0012-Galaxy-S9-remaining-of-HAL-onEnroll-is-actually-a-pe.patch
+++ b/patches/platform_frameworks_base/0012-Galaxy-S9-remaining-of-HAL-onEnroll-is-actually-a-pe.patch
@@ -1,7 +1,7 @@
 From 880144142eec1864485ae289d6772e046453612d Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Mon, 2 Jul 2018 23:36:39 +0200
-Subject: [PATCH 12/19] [Galaxy S9] "remaining" of HAL onEnroll is actually a
+Subject: [PATCH 12/20] [Galaxy S9] "remaining" of HAL onEnroll is actually a
  percent of progress
 
 ---
diff --git a/patches/platform_frameworks_base/0013-Show-APN-Settings-for-CDMA-carriers.patch b/patches/platform_frameworks_base/0013-Show-APN-Settings-for-CDMA-carriers.patch
index 5330a7c..ea91c24 100644
--- a/patches/platform_frameworks_base/0013-Show-APN-Settings-for-CDMA-carriers.patch
+++ b/patches/platform_frameworks_base/0013-Show-APN-Settings-for-CDMA-carriers.patch
@@ -1,7 +1,7 @@
 From 879613f77988fb4b1c628fd51e6b330e02cddfc3 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Mon, 6 Aug 2018 12:49:00 +0200
-Subject: [PATCH 13/19] Show APN Settings for CDMA carriers
+Subject: [PATCH 13/20] Show APN Settings for CDMA carriers
 
 ---
  telephony/java/android/telephony/CarrierConfigManager.java | 2 +-
diff --git a/patches/platform_frameworks_base/0014-Change-SignalStrentgh-to-change-behaviour-based-on-p.patch b/patches/platform_frameworks_base/0014-Change-SignalStrentgh-to-change-behaviour-based-on-p.patch
index 82f6545..0ec58cb 100644
--- a/patches/platform_frameworks_base/0014-Change-SignalStrentgh-to-change-behaviour-based-on-p.patch
+++ b/patches/platform_frameworks_base/0014-Change-SignalStrentgh-to-change-behaviour-based-on-p.patch
@@ -1,7 +1,7 @@
 From fd818b3249a795d3e231fa9346372c183099c745 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Mon, 6 Aug 2018 20:01:44 +0200
-Subject: [PATCH 14/19] Change SignalStrentgh to change behaviour based on
+Subject: [PATCH 14/20] Change SignalStrentgh to change behaviour based on
  property
 
 Change-Id: I940ed724047567ec5195ac93ea04574c3d92f70b
diff --git a/patches/platform_frameworks_base/0015-idmap-Don-t-silently-ignore-RROs-with-same-priority.patch b/patches/platform_frameworks_base/0015-idmap-Don-t-silently-ignore-RROs-with-same-priority.patch
index 6d6b1e5..61c246f 100644
--- a/patches/platform_frameworks_base/0015-idmap-Don-t-silently-ignore-RROs-with-same-priority.patch
+++ b/patches/platform_frameworks_base/0015-idmap-Don-t-silently-ignore-RROs-with-same-priority.patch
@@ -1,7 +1,7 @@
 From 3ec335c1a6346e2f5ee03bf603839b730c12928c Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Sun, 19 Aug 2018 10:51:06 +0200
-Subject: [PATCH 15/19] idmap: Don't silently ignore RROs with same priority
+Subject: [PATCH 15/20] idmap: Don't silently ignore RROs with same priority
 
 Change-Id: I64a6899f1b30e0cd9e9a872b7ca83d831f038cbe
 ---
diff --git a/patches/platform_frameworks_base/0016-Move-SysuiDarkThemeOverlay-to-system.patch b/patches/platform_frameworks_base/0016-Move-SysuiDarkThemeOverlay-to-system.patch
index e052a73..0f51ddc 100644
--- a/patches/platform_frameworks_base/0016-Move-SysuiDarkThemeOverlay-to-system.patch
+++ b/patches/platform_frameworks_base/0016-Move-SysuiDarkThemeOverlay-to-system.patch
@@ -1,7 +1,7 @@
 From 9629e7118d06a375d96f2967be54f3c2348b5b89 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Sun, 19 Aug 2018 10:57:21 +0200
-Subject: [PATCH 16/19] Move SysuiDarkThemeOverlay to /system
+Subject: [PATCH 16/20] Move SysuiDarkThemeOverlay to /system
 
 Change-Id: I31b3edc5d1abcc1163a13e63c909fee9d27ff432
 ---
diff --git a/patches/platform_frameworks_base/0017-Reintroduce-button-backlight-and-respective-inactivi.patch b/patches/platform_frameworks_base/0017-Reintroduce-button-backlight-and-respective-inactivi.patch
index ccee4a4..559cec1 100644
--- a/patches/platform_frameworks_base/0017-Reintroduce-button-backlight-and-respective-inactivi.patch
+++ b/patches/platform_frameworks_base/0017-Reintroduce-button-backlight-and-respective-inactivi.patch
@@ -1,7 +1,7 @@
 From 4459e03e52773a42d83bca5a02172d658e7fc2b9 Mon Sep 17 00:00:00 2001
 From: Ricardo Cerqueira <cyanogenmod@cerqueira.org>
 Date: Fri, 23 Nov 2012 14:23:16 +0000
-Subject: [PATCH 17/19] Reintroduce button-backlight (and respective inactivity
+Subject: [PATCH 17/20] Reintroduce button-backlight (and respective inactivity
  timeout)
 
 The power manager rewrite from Change I1d7a52e98f0449f76d70bf421f6a7f245957d1d7
diff --git a/patches/platform_frameworks_base/0018-power-Disable-keyboard-button-lights-while-dozing-dr.patch b/patches/platform_frameworks_base/0018-power-Disable-keyboard-button-lights-while-dozing-dr.patch
index 7411c5f..b95699e 100644
--- a/patches/platform_frameworks_base/0018-power-Disable-keyboard-button-lights-while-dozing-dr.patch
+++ b/patches/platform_frameworks_base/0018-power-Disable-keyboard-button-lights-while-dozing-dr.patch
@@ -1,7 +1,7 @@
 From 70a48b3381acd2b8cf0ef090c188ae95635d5921 Mon Sep 17 00:00:00 2001
 From: Steve Kondik <steve@cyngn.com>
 Date: Sat, 3 Jan 2015 05:13:26 -0800
-Subject: [PATCH 18/19] power: Disable keyboard/button lights while
+Subject: [PATCH 18/20] power: Disable keyboard/button lights while
  dozing/dreaming
 
  * With hardkeys and doze mode enabled, entering suspend results in
diff --git a/patches/platform_frameworks_base/0019-It-is-okay-not-to-have-wifi-in-SystemUI-on-FDE-lock.patch b/patches/platform_frameworks_base/0019-It-is-okay-not-to-have-wifi-in-SystemUI-on-FDE-lock.patch
index aab3dbc..50ec568 100644
--- a/patches/platform_frameworks_base/0019-It-is-okay-not-to-have-wifi-in-SystemUI-on-FDE-lock.patch
+++ b/patches/platform_frameworks_base/0019-It-is-okay-not-to-have-wifi-in-SystemUI-on-FDE-lock.patch
@@ -1,7 +1,7 @@
 From bfa2cabcbae2e6b67acda5fad79e98104f66b915 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Mon, 20 Aug 2018 22:27:02 +0200
-Subject: [PATCH 19/19] It is okay not to have wifi in SystemUI (on FDE lock)
+Subject: [PATCH 19/20] It is okay not to have wifi in SystemUI (on FDE lock)
 
 ---
  .../SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java     | 2 +-
diff --git a/patches/platform_frameworks_base/0020-Don-t-wake-IR-HAL-to-the-infinity-and-beyond.patch b/patches/platform_frameworks_base/0020-Don-t-wake-IR-HAL-to-the-infinity-and-beyond.patch
new file mode 100644
index 0000000..6a07eca
--- /dev/null
+++ b/patches/platform_frameworks_base/0020-Don-t-wake-IR-HAL-to-the-infinity-and-beyond.patch
@@ -0,0 +1,42 @@
+From 99be786b380a2e4507f6b223471b7f28bb1018c8 Mon Sep 17 00:00:00 2001
+From: Pierre-Hugues Husson <phh@phh.me>
+Date: Tue, 21 Aug 2018 22:24:02 +0200
+Subject: [PATCH 20/20] Don't wake IR HAL to the infinity and beyond
+
+---
+ services/core/java/com/android/server/ConsumerIrService.java | 5 -----
+ services/core/jni/com_android_server_ConsumerIrService.cpp   | 2 +-
+ 2 files changed, 1 insertion(+), 6 deletions(-)
+
+diff --git a/services/core/java/com/android/server/ConsumerIrService.java b/services/core/java/com/android/server/ConsumerIrService.java
+index c574a03..82ec033 100644
+--- a/services/core/java/com/android/server/ConsumerIrService.java
++++ b/services/core/java/com/android/server/ConsumerIrService.java
+@@ -46,11 +46,6 @@ public class ConsumerIrService extends IConsumerIrService.Stub {
+         mWakeLock.setReferenceCounted(true);
+ 
+         mHasNativeHal = halOpen();
+-        if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CONSUMER_IR)) {
+-            if (!mHasNativeHal) {
+-                throw new RuntimeException("FEATURE_CONSUMER_IR present, but no IR HAL loaded!");
+-            }
+-        }
+     }
+ 
+     @Override
+diff --git a/services/core/jni/com_android_server_ConsumerIrService.cpp b/services/core/jni/com_android_server_ConsumerIrService.cpp
+index 2ca348b..148fba9 100644
+--- a/services/core/jni/com_android_server_ConsumerIrService.cpp
++++ b/services/core/jni/com_android_server_ConsumerIrService.cpp
+@@ -36,7 +36,7 @@ static sp<IConsumerIr> mHal;
+ 
+ static jboolean halOpen(JNIEnv* /* env */, jobject /* obj */) {
+     // TODO(b/31632518)
+-    mHal = IConsumerIr::getService();
++    mHal = IConsumerIr::tryGetService();
+     return mHal != nullptr;
+ }
+ 
+-- 
+2.7.4
+
diff --git a/patches/platform_frameworks_native/0001-AOSP-8.0-8.1-didn-t-use-presentOrValidate-so-it-s-br.patch b/patches/platform_frameworks_native/0001-AOSP-8.0-8.1-didn-t-use-presentOrValidate-so-it-s-br.patch
index d76395f..4c90fec 100644
--- a/patches/platform_frameworks_native/0001-AOSP-8.0-8.1-didn-t-use-presentOrValidate-so-it-s-br.patch
+++ b/patches/platform_frameworks_native/0001-AOSP-8.0-8.1-didn-t-use-presentOrValidate-so-it-s-br.patch
@@ -1,7 +1,7 @@
 From 3861d57b5dc895c08e15808d72235540d62bcd4a Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Tue, 14 Aug 2018 21:01:35 +0200
-Subject: [PATCH 1/2] AOSP 8.0/8.1 didn't use presentOrValidate, so it's
+Subject: [PATCH 1/4] AOSP 8.0/8.1 didn't use presentOrValidate, so it's
  broken. Don't use it
 
 ---
diff --git a/patches/platform_frameworks_native/0002-Ignore-usage-bits-verification.patch b/patches/platform_frameworks_native/0002-Ignore-usage-bits-verification.patch
index 775b423..af1c83b 100644
--- a/patches/platform_frameworks_native/0002-Ignore-usage-bits-verification.patch
+++ b/patches/platform_frameworks_native/0002-Ignore-usage-bits-verification.patch
@@ -1,7 +1,7 @@
 From f82e1419c8006bd9a6d40d5c6f59829858b88507 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Sun, 19 Aug 2018 23:07:24 +0200
-Subject: [PATCH 2/2] Ignore usage bits verification
+Subject: [PATCH 2/4] Ignore usage bits verification
 
 This didn't ignore as of 8.1, so we're ""safe""
 ---
diff --git a/patches/platform_frameworks_native/0003-device-Huawei-HWC-doesn-t-understand-0-0-0-0-fullscr.patch b/patches/platform_frameworks_native/0003-device-Huawei-HWC-doesn-t-understand-0-0-0-0-fullscr.patch
new file mode 100644
index 0000000..31390aa
--- /dev/null
+++ b/patches/platform_frameworks_native/0003-device-Huawei-HWC-doesn-t-understand-0-0-0-0-fullscr.patch
@@ -0,0 +1,74 @@
+From 7a4b9b1613ee04fd71f3ed83e45ba0a5fd040dfb Mon Sep 17 00:00:00 2001
+From: Pierre-Hugues Husson <phh@phh.me>
+Date: Fri, 5 Jan 2018 00:26:38 +0100
+Subject: [PATCH 3/4] [device] ::Huawei:: HWC doesn't understand 0,0,0,0 ==
+ fullscreen damage. Set it to the whole visible surface
+
+::Huawei:: Fix damage for Huawei compositor
+
+For Huawei compositor, the damage area is a region on the screen.
+But for SurfaceFlinger, this is a region on the source surface.
+On Huawei devices, do the plane conversion.
+
+This fixes several UI glitches, most notably GBoard.
+---
+ services/surfaceflinger/BufferLayer.cpp    | 8 +++++++-
+ services/surfaceflinger/SurfaceFlinger.cpp | 8 ++++++++
+ services/surfaceflinger/SurfaceFlinger.h   | 3 +++
+ 3 files changed, 18 insertions(+), 1 deletion(-)
+
+diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
+index fda7906..80c72d9 100644
+--- a/services/surfaceflinger/BufferLayer.cpp
++++ b/services/surfaceflinger/BufferLayer.cpp
+@@ -631,7 +631,13 @@ void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& displayDevice)
+         visible.dump(LOG_TAG);
+     }
+ 
+-    error = hwcLayer->setSurfaceDamage(surfaceDamageRegion);
++    if(mFlinger->mDamageUsesScreenReference) {
++        const auto& frame = hwcInfo.displayFrame;
++        auto fullSource = Region(Rect(frame.left, frame.top, frame.right, frame.bottom));
++        error = hwcLayer->setSurfaceDamage(fullSource);
++    } else {
++        error = hwcLayer->setSurfaceDamage(surfaceDamageRegion);
++    }
+     if (error != HWC2::Error::None) {
+         ALOGE("[%s] Failed to set surface damage: %s (%d)", mName.string(),
+               to_string(error).c_str(), static_cast<int32_t>(error));
+diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
+index 87baf8c..729671d 100644
+--- a/services/surfaceflinger/SurfaceFlinger.cpp
++++ b/services/surfaceflinger/SurfaceFlinger.cpp
+@@ -350,6 +350,14 @@ SurfaceFlinger::SurfaceFlinger() : SurfaceFlinger(SkipInitialization) {
+         // for production purposes later on.
+         setenv("TREBLE_TESTING_OVERRIDE", "true", true);
+     }
++
++    property_get("ro.hardware", value, "");
++    if(strstr(value, "hi3660")||
++            strstr(value, "hi6250") ||
++            strstr(value, "hi3670") ||
++            strstr(value, "kirin970")) {
++        mDamageUsesScreenReference = true;
++    }
+ }
+ 
+ void SurfaceFlinger::onFirstRef()
+diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
+index 8566b03..9b29bef 100644
+--- a/services/surfaceflinger/SurfaceFlinger.h
++++ b/services/surfaceflinger/SurfaceFlinger.h
+@@ -841,6 +841,9 @@ private:
+     // Restrict layers to use two buffers in their bufferqueues.
+     bool mLayerTripleBufferingDisabled = false;
+ 
++    bool mDamageUsesScreenReference;
++
++
+     // these are thread safe
+     mutable std::unique_ptr<MessageQueue> mEventQueue{std::make_unique<impl::MessageQueue>()};
+     FrameTracker mAnimFrameTracker;
+-- 
+2.7.4
+
diff --git a/patches/platform_frameworks_native/0004-Enable-fallback-to-old-ro.sf.hwrotation-property.patch b/patches/platform_frameworks_native/0004-Enable-fallback-to-old-ro.sf.hwrotation-property.patch
new file mode 100644
index 0000000..658e08a
--- /dev/null
+++ b/patches/platform_frameworks_native/0004-Enable-fallback-to-old-ro.sf.hwrotation-property.patch
@@ -0,0 +1,41 @@
+From c1d5c4623ee96cc37299a7da3034b8e8a1e62e9d Mon Sep 17 00:00:00 2001
+From: phh <phh@phh.me>
+Date: Wed, 22 Aug 2018 08:57:52 +0000
+Subject: [PATCH 4/4] Enable fallback to old ro.sf.hwrotation property
+
+---
+ services/surfaceflinger/SurfaceFlinger.cpp | 18 ++++++++++++++++++
+ 1 file changed, 18 insertions(+)
+
+diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
+index 729671d..f5bbae7 100644
+--- a/services/surfaceflinger/SurfaceFlinger.cpp
++++ b/services/surfaceflinger/SurfaceFlinger.cpp
+@@ -291,6 +291,24 @@ SurfaceFlinger::SurfaceFlinger() : SurfaceFlinger(SkipInitialization) {
+             mPrimaryDisplayOrientation = DisplayState::eOrientationDefault;
+             break;
+     }
++
++    if(primaryDisplayOrientation == V1_1::DisplayOrientation::ORIENTATION_0) {
++        int sfRotation = property_get_int32("ro.sf.hwrotation", -1);
++        switch(sfRotation) {
++            case 0:
++                mPrimaryDisplayOrientation = DisplayState::eOrientationDefault;
++                break;
++            case 90:
++                mPrimaryDisplayOrientation = DisplayState::eOrientation90;
++                break;
++            case 180:
++                mPrimaryDisplayOrientation = DisplayState::eOrientation180;
++                break;
++            case 270:
++                mPrimaryDisplayOrientation = DisplayState::eOrientation270;
++                break;
++        }
++    }
+     ALOGV("Primary Display Orientation is set to %2d.", mPrimaryDisplayOrientation);
+ 
+     mPrimaryDispSync.init(SurfaceFlinger::hasSyncFramework, SurfaceFlinger::dispSyncPresentTimeOffset);
+-- 
+2.7.4
+
diff --git a/patches/platform_system_core/0004-Fix-Samsung-TS-suspend-by-reseting-it-when-waking-up.patch b/patches/platform_system_core/0004-Fix-Samsung-TS-suspend-by-reseting-it-when-waking-up.patch
index 8beb827..fc51951 100644
--- a/patches/platform_system_core/0004-Fix-Samsung-TS-suspend-by-reseting-it-when-waking-up.patch
+++ b/patches/platform_system_core/0004-Fix-Samsung-TS-suspend-by-reseting-it-when-waking-up.patch
@@ -1,29 +1,21 @@
-From 97fc6c8d2a0ed3f823c7a955e97583960d2a752d Mon Sep 17 00:00:00 2001
+From 954a67616bd63aac1cb094117edbdfb2f04a405d Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Thu, 16 Aug 2018 22:29:11 +0200
 Subject: [PATCH 4/4] Fix Samsung TS suspend by reseting it when waking up
 
 Change-Id: I5ee289dcb2347bedc96573bf16bc4c3d1f1b9de3
 ---
- libsuspend/autosuspend_wakeup_count.cpp | 39 +++++++++++++++++++++++++++++++++
- 1 file changed, 39 insertions(+)
+ libsuspend/autosuspend_wakeup_count.cpp | 32 ++++++++++++++++++++++++++++++++
+ 1 file changed, 32 insertions(+)
 
 diff --git a/libsuspend/autosuspend_wakeup_count.cpp b/libsuspend/autosuspend_wakeup_count.cpp
-index 27c8629..b8580ef 100644
+index 27c8629..1624866 100644
 --- a/libsuspend/autosuspend_wakeup_count.cpp
 +++ b/libsuspend/autosuspend_wakeup_count.cpp
-@@ -53,6 +53,35 @@ static constexpr char sys_power_state[] = "/sys/power/state";
+@@ -53,6 +53,27 @@ static constexpr char sys_power_state[] = "/sys/power/state";
  static constexpr char sys_power_wakeup_count[] = "/sys/power/wakeup_count";
  static bool autosuspend_is_init = false;
  
-+static std::string samsung_touchscreen_readname(const std::string& path) {
-+    std::string fullPath = path + "/name";
-+    std::string name;
-+    if(!android::base::ReadFileToString(fullPath, &name))
-+        name = "unknown";
-+    return name;
-+}
-+
 +static std::string samsung_touchscreen_enabled() {
 +    int fd = -1;
 +    for(int i=0; i<30; i++) {
@@ -40,32 +32,33 @@
 +    return "";
 +}
 +
-+static bool samsung_touchscreen_set(bool enable) {
-+	const std::string path = samsung_touchscreen_enabled();
-+	return android::base::WriteStringToFile(path, enable ? "1" : "0");
++static bool samsung_touchscreen_set(const std::string& path, bool enable) {
++	LOG(INFO) << "Setting samsung to path " << path;
++	return android::base::WriteStringToFile(enable ? "1" : "0", path);
 +}
 +
  static void update_sleep_time(bool success) {
      if (success) {
          sleep_time = BASE_SLEEP_TIME;
-@@ -64,6 +93,7 @@ static void update_sleep_time(bool success) {
- 
- static void* suspend_thread_func(void* arg __attribute__((unused))) {
+@@ -66,6 +87,8 @@ static void* suspend_thread_func(void* arg __attribute__((unused))) {
      bool success = true;
-+    bool samsungTs = true;
  
      while (true) {
++        std::string samsungTs = samsung_touchscreen_enabled();
++
          update_sleep_time(success);
-@@ -95,6 +125,15 @@ static void* suspend_thread_func(void* arg __attribute__((unused))) {
+         usleep(sleep_time);
+         success = false;
+@@ -95,6 +118,15 @@ static void* suspend_thread_func(void* arg __attribute__((unused))) {
              LOG(VERBOSE) << "write " << sleep_state << " to " << sys_power_state;
              success = WriteStringToFd(sleep_state, state_fd);
  
 +            if(success) {
-+                if(samsungTs) {
-+                    LOG(VERBOSE) << "Resetting Samsung TS";
-+                    samsung_touchscreen_set(0);
-+                    for(int i=0; i<10 && !samsung_touchscreen_set(1); i++)
-+                        LOG(VERBOSE) << "Resetting Samsung TS: try " << i;
++                if(samsungTs != "") {
++                    LOG(INFO) << "Resetting Samsung TS";
++                    samsung_touchscreen_set(samsungTs, 0);
++                    for(int i=0; i<10 && !samsung_touchscreen_set(samsungTs, 1); i++)
++                        LOG(INFO) << "Resetting Samsung TS: try " << i;
 +                }
 +            }
 +