From 9d86adaeabddb9a4122fab103df30d44ced25a3d Mon Sep 17 00:00:00 2001
From: wh <wanghang@rock-chips.com>
Date: Tue, 27 Jul 2021 15:38:03 +0800
Subject: [PATCH 1/3] Eink: make set api dpi function only effect activity

Signed-off-by: wh <wanghang@rock-chips.com>
Change-Id: Ia3e37ca79c17125345c8b48cb9753d8027a56965
---
 core/java/android/app/Activity.java            | 14 +++++++++-----
 core/java/android/content/ContextWrapper.java  | 18 ++++++++++--------
 .../statusbar/phone/NavigationBarFragment.java |  1 +
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index bccfac22198b..a034df782c70 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -969,6 +969,7 @@ public class Activity extends ContextThemeWrapper
     private boolean mIsInPictureInPictureMode;
 
     private boolean mCanRecreateWithDpi = false;
+    private int mLastStoreDpi = -1;
     private MyAppCustomConfigChangeReceiver mAppCustomConfigChangeReceiver = new MyAppCustomConfigChangeReceiver();
     private class MyAppCustomConfigChangeReceiver extends BroadcastReceiver {
         @Override
@@ -1261,7 +1262,7 @@ public class Activity extends ContextThemeWrapper
 
     @Override
     protected void attachBaseContext(Context newBase) {
-        super.attachBaseContext(newBase);
+        super.attachBaseContext(updateResources(newBase));
         if (newBase != null) {
             newBase.setAutofillClient(this);
             newBase.setContentCaptureOptions(getContentCaptureOptions());
@@ -1626,6 +1627,11 @@ public class Activity extends ContextThemeWrapper
         mRestoredFromBundle = savedInstanceState != null;
         mCalled = true;
 
+        try {
+            mLastStoreDpi = getCurrentStoreDpi(this, getPackageName());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -1966,11 +1972,9 @@ public class Activity extends ContextThemeWrapper
             if (mCanRecreateWithDpi) {
                 String packageName = getPackageName();
                 int storeDpi = getCurrentStoreDpi(this, packageName);
-                /*getResources().getConfiguration().densityDpi maybe incorrect*/
-                int currentDpi = getResources().getDisplayMetrics().densityDpi;
-                if (-1 != storeDpi && storeDpi != currentDpi) {
+                if (mLastStoreDpi != storeDpi) {
                     Slog.v(TAG, "recreate " + this + " with onresume storeDpi="
-                        + storeDpi + ", currentDpi=" + currentDpi);
+                        + storeDpi + ", mLastStoreDpi=" + mLastStoreDpi);
                     recreate();
                 }
             }
diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java
index 68c26a864c23..b08fb2b369ad 100644
--- a/core/java/android/content/ContextWrapper.java
+++ b/core/java/android/content/ContextWrapper.java
@@ -80,12 +80,8 @@ public class ContextWrapper extends Context {
         if (mBase != null) {
             throw new IllegalStateException("Base context already set");
         }
-        if (null == base) {
-            mBase = null;
-        } else {
-            String packageName = base.getPackageName();
-            mBase = updateResources(base, packageName);
-        }
+        mBase = base;
+        //mBase = updateResources(base);
     }
 
     /** @hide */
@@ -109,6 +105,8 @@ public class ContextWrapper extends Context {
                         if (isDpiSetting == 1) {
                             int densityDpiFromDB = cursor.getInt(cursor.getColumnIndex("app_dpi"));
                             densityDpi = densityDpiFromDB == -1 ? densityDpi : densityDpiFromDB;
+                        } else {
+                            densityDpi = -1;
                         }
                     }
                 }
@@ -122,8 +120,12 @@ public class ContextWrapper extends Context {
         return densityDpi;
     }
 
-
-    private Context updateResources(Context context, String packageName) {
+    /** @hide */
+    public Context updateResources(Context context) {
+        if (null == context) {
+            return context;
+        }
+        String packageName = context.getPackageName();
         int densityDpi = getCurrentStoreDpi(context, packageName);
         if (-1 == densityDpi) {
             return context;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
index cb26fc88cf68..d70273815a32 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
@@ -227,6 +227,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
 
     private final String[] BLACK_EINK_CONFIG_APP = new String[] {
             "com.android.systemui",
+            "com.android.permissioncontroller",
             "com.android.launcher3",
             "com.rockchip.notedemo",
     };
-- 
2.17.1

