OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.webapps; | |
6 | |
7 import android.content.Context; | |
8 import android.content.SharedPreferences; | |
9 import android.preference.PreferenceManager; | |
10 | |
11 import org.chromium.base.FileUtils; | |
12 import org.chromium.base.ThreadUtils; | |
13 import org.chromium.webapk.lib.client.DexOptimizer; | |
14 | |
15 import java.io.File; | |
16 | |
17 /** | |
18 * Updates installed WebAPKs after a Chrome update. | |
19 */ | |
20 public class WebApkVersionManager { | |
21 /** | |
22 * Name of the shared preference to store whether an attempt to extract the WebAPK runtime | |
23 * library was made. | |
24 */ | |
25 private static final String TRIED_EXTRACTING_DEX_PREF = | |
26 "web_apk_version_manager_tried_extracting_dex"; | |
gone
2016/05/25 21:11:02
nit: Prepend the package here instead:
"org.chrom
| |
27 | |
28 private static final String TAG = "WebApkVersionManager"; | |
gone
2016/05/25 21:11:02
TAG is only necessary if you have logs, which you
| |
29 | |
30 /** | |
31 * Tries to extract the WebAPK runtime dex from the Chrome APK if it has not tried already. | |
32 * Should not be called on UI thread. | |
33 * @param Context context | |
gone
2016/05/25 21:11:02
Fill in the @param description or remove it. It's
| |
34 */ | |
35 public static void updateWebApksIfNeeded(Context context) { | |
36 assert !ThreadUtils.runningOnUiThread(); | |
37 | |
38 SharedPreferences preferences = | |
39 PreferenceManager.getDefaultSharedPreferences(context.getApplica tionContext()); | |
gone
2016/05/25 21:11:02
Can you use ContextUtils.getApplicationContext() h
| |
40 if (preferences.getBoolean(TRIED_EXTRACTING_DEX_PREF, false)) { | |
41 return; | |
42 } | |
43 | |
44 SharedPreferences.Editor editor = preferences.edit(); | |
45 editor.putBoolean(TRIED_EXTRACTING_DEX_PREF, true); | |
46 editor.apply(); | |
47 | |
48 File dexDir = context.getDir("dex", Context.MODE_PRIVATE); | |
49 File dexFile = new File(dexDir, "web_apk.dex"); | |
50 if (!FileUtils.extractAsset(context, "web_apk.dex", dexFile) | |
51 || !DexOptimizer.optimize(dexFile)) { | |
52 return; | |
53 } | |
54 | |
55 // Make dex file world-readable so that WebAPK can use it. | |
56 dexFile.setReadable(true, false); | |
57 } | |
58 } | |
OLD | NEW |