Commit 21b1226e authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Move SharedPrefs from WebApkVersionManager to ChromePreferenceKeys

Register them in ChromePreferenceKeys and use SharedPreferencesManager
consistently instead of SharedPreferences directly.

Bug: 1022108
Change-Id: I37170d334330199bfd996791934c4e5e6f0763d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003752Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732646}
parent 84410a9d
...@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.webapps; ...@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.webapps;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
...@@ -15,6 +14,8 @@ import org.chromium.base.FileUtils; ...@@ -15,6 +14,8 @@ import org.chromium.base.FileUtils;
import org.chromium.base.StrictModeContext; import org.chromium.base.StrictModeContext;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.webapk.lib.client.DexOptimizer; import org.chromium.webapk.lib.client.DexOptimizer;
import org.chromium.webapk.lib.client.WebApkVersion; import org.chromium.webapk.lib.client.WebApkVersion;
import org.chromium.webapk.lib.common.WebApkCommonUtils; import org.chromium.webapk.lib.common.WebApkCommonUtils;
...@@ -25,18 +26,6 @@ import java.io.File; ...@@ -25,18 +26,6 @@ import java.io.File;
* Updates installed WebAPKs after a Chrome update. * Updates installed WebAPKs after a Chrome update.
*/ */
public class WebApkVersionManager { public class WebApkVersionManager {
/**
* Name of the shared preference for the version number of the dynamically loaded dex.
*/
private static final String EXTRACTED_DEX_VERSION_PREF =
"org.chromium.chrome.browser.webapps.extracted_dex_version";
/**
* Name of the shared preference for the Android OS version at the time that the dex was last
* extracted from Chrome's assets and optimized.
*/
private static final String LAST_SDK_VERSION_PREF =
"org.chromium.chrome.browser.webapps.last_sdk_version";
/** /**
* Tries to extract the WebAPK runtime dex from the Chrome APK if it has not tried already. * Tries to extract the WebAPK runtime dex from the Chrome APK if it has not tried already.
...@@ -47,9 +36,10 @@ public class WebApkVersionManager { ...@@ -47,9 +36,10 @@ public class WebApkVersionManager {
public static void updateWebApksIfNeeded() { public static void updateWebApksIfNeeded() {
assert !ThreadUtils.runningOnUiThread(); assert !ThreadUtils.runningOnUiThread();
SharedPreferences preferences = ContextUtils.getAppSharedPreferences(); SharedPreferencesManager preferences = SharedPreferencesManager.getInstance();
int extractedDexVersion = preferences.getInt(EXTRACTED_DEX_VERSION_PREF, -1); int extractedDexVersion =
int lastSdkVersion = preferences.getInt(LAST_SDK_VERSION_PREF, -1); preferences.readInt(ChromePreferenceKeys.WEBAPK_EXTRACTED_DEX_VERSION, -1);
int lastSdkVersion = preferences.readInt(ChromePreferenceKeys.WEBAPK_LAST_SDK_VERSION, -1);
if (!CommandLine.getInstance().hasSwitch( if (!CommandLine.getInstance().hasSwitch(
ChromeSwitches.ALWAYS_EXTRACT_WEBAPK_RUNTIME_DEX_ON_STARTUP) ChromeSwitches.ALWAYS_EXTRACT_WEBAPK_RUNTIME_DEX_ON_STARTUP)
&& extractedDexVersion == WebApkVersion.CURRENT_RUNTIME_DEX_VERSION && extractedDexVersion == WebApkVersion.CURRENT_RUNTIME_DEX_VERSION
...@@ -57,10 +47,9 @@ public class WebApkVersionManager { ...@@ -57,10 +47,9 @@ public class WebApkVersionManager {
return; return;
} }
SharedPreferences.Editor editor = preferences.edit(); preferences.writeInt(ChromePreferenceKeys.WEBAPK_EXTRACTED_DEX_VERSION,
editor.putInt(EXTRACTED_DEX_VERSION_PREF, WebApkVersion.CURRENT_RUNTIME_DEX_VERSION); WebApkVersion.CURRENT_RUNTIME_DEX_VERSION);
editor.putInt(LAST_SDK_VERSION_PREF, Build.VERSION.SDK_INT); preferences.writeInt(ChromePreferenceKeys.WEBAPK_LAST_SDK_VERSION, Build.VERSION.SDK_INT);
editor.apply();
Context context = ContextUtils.getApplicationContext(); Context context = ContextUtils.getApplicationContext();
File dexDir = context.getDir("dex", Context.MODE_PRIVATE); File dexDir = context.getDir("dex", Context.MODE_PRIVATE);
......
...@@ -558,6 +558,19 @@ public final class ChromePreferenceKeys { ...@@ -558,6 +558,19 @@ public final class ChromePreferenceKeys {
public static final String VR_SHOULD_REGISTER_ASSETS_COMPONENT_ON_STARTUP = public static final String VR_SHOULD_REGISTER_ASSETS_COMPONENT_ON_STARTUP =
"should_register_vr_assets_component_on_startup"; "should_register_vr_assets_component_on_startup";
/**
* Name of the shared preference for the version number of the dynamically loaded dex.
*/
public static final String WEBAPK_EXTRACTED_DEX_VERSION =
"org.chromium.chrome.browser.webapps.extracted_dex_version";
/**
* Name of the shared preference for the Android OS version at the time that the dex was last
* extracted from Chrome's assets and optimized.
*/
public static final String WEBAPK_LAST_SDK_VERSION =
"org.chromium.chrome.browser.webapps.last_sdk_version";
/** Key for deferred recording of list of uninstalled WebAPK packages. */ /** Key for deferred recording of list of uninstalled WebAPK packages. */
public static final String WEBAPK_UNINSTALLED_PACKAGES = "webapk_uninstalled_packages"; public static final String WEBAPK_UNINSTALLED_PACKAGES = "webapk_uninstalled_packages";
...@@ -784,6 +797,8 @@ public final class ChromePreferenceKeys { ...@@ -784,6 +797,8 @@ public final class ChromePreferenceKeys {
VARIATION_CACHED_BOTTOM_TOOLBAR, VARIATION_CACHED_BOTTOM_TOOLBAR,
VERIFIED_DIGITAL_ASSET_LINKS, VERIFIED_DIGITAL_ASSET_LINKS,
VR_SHOULD_REGISTER_ASSETS_COMPONENT_ON_STARTUP, VR_SHOULD_REGISTER_ASSETS_COMPONENT_ON_STARTUP,
WEBAPK_EXTRACTED_DEX_VERSION,
WEBAPK_LAST_SDK_VERSION,
WEBAPK_UNINSTALLED_PACKAGES WEBAPK_UNINSTALLED_PACKAGES
); );
// clang-format on // clang-format on
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment