Skip to content

Commit 3d64bb3

Browse files
committed
Trying to address this bug
1 parent 7a2953b commit 3d64bb3

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/splashscreens/SplashImageTransferTask.java

+31-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
package com.google.androidbrowserhelper.trusted.splashscreens;
1616

1717
import android.annotation.SuppressLint;
18+
import android.app.UiModeManager;
1819
import android.content.Context;
1920
import android.content.SharedPreferences;
2021
import android.content.pm.PackageManager;
22+
import android.content.res.Configuration;
2123
import android.graphics.Bitmap;
2224
import android.os.AsyncTask;
2325
import android.util.Log;
@@ -68,6 +70,25 @@ public SplashImageTransferTask(Context context, Bitmap bitmap, String authority,
6870
mProviderPackage = providerPackage;
6971
}
7072

73+
/**
74+
* Get the current theme mode.
75+
*
76+
* @param context Context to get the UiModeManager service.
77+
* @return The current theme mode, either "light" or "dark".
78+
*/
79+
private String getCurrentThemeMode(Context context) {
80+
UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
81+
int nightModeFlags = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
82+
switch (nightModeFlags) {
83+
case Configuration.UI_MODE_NIGHT_YES:
84+
return "dark";
85+
case Configuration.UI_MODE_NIGHT_NO:
86+
case Configuration.UI_MODE_NIGHT_UNDEFINED:
87+
default:
88+
return "light";
89+
}
90+
}
91+
7192
/**
7293
* Executes the task. Should be called only once.
7394
* @param callback {@link Callback} to be called when done.
@@ -104,8 +125,13 @@ protected Boolean doInBackground(Void... args) {
104125
File file = new File(dir, FILE_NAME);
105126
SharedPreferences prefs =
106127
mContext.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE);
128+
107129
long lastUpdateTime = getLastAppUpdateTime();
108-
if (file.exists() && lastUpdateTime == prefs.getLong(PREF_LAST_UPDATE_TIME, 0)) {
130+
String currentThemeMode = getCurrentThemeMode(mContext);
131+
long savedLastUpdateTime = prefs.getLong(PREF_LAST_UPDATE_TIME, 0);
132+
String savedThemeMode = prefs.getString("themeMode", "light"); // Default to light for compatibility
133+
134+
if (file.exists() && lastUpdateTime == savedLastUpdateTime && currentThemeMode.equals(savedThemeMode)) {
109135
// Don't overwrite existing file, if it was saved later than the last time app was
110136
// updated
111137
return transferToCustomTabsProvider(file);
@@ -114,7 +140,10 @@ protected Boolean doInBackground(Void... args) {
114140
if (isCancelled()) return false;
115141
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
116142
os.flush();
117-
prefs.edit().putLong(PREF_LAST_UPDATE_TIME, lastUpdateTime).commit();
143+
prefs.edit()
144+
.putLong(PREF_LAST_UPDATE_TIME, lastUpdateTime)
145+
.putString("themeMode", currentThemeMode)
146+
.apply();
118147

119148
if (isCancelled()) return false;
120149
return transferToCustomTabsProvider(file);

0 commit comments

Comments
 (0)