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"; | |
27 | |
28 private static final String TAG = "WebApkVersionManager"; | |
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 | |
34 */ | |
35 public static void updateWebApksIfNeeded(Context context) { | |
36 assert !ThreadUtils.runningOnUiThread(); | |
37 | |
38 // TODO(pkotwicz|hanxi): Detect whether the manifest of installed APKs n eeds to be updated. | |
39 // (crbug.com/604513) | |
40 | |
41 SharedPreferences preferences = | |
42 PreferenceManager.getDefaultSharedPreferences(context.getApplica tionContext()); | |
43 if (preferences.getBoolean(TRIED_EXTRACTING_DEX_PREF, false)) { | |
Xi Han
2016/05/25 15:36:13
Please move the comments in line 38 and 39 right a
pkotwicz
2016/05/25 17:16:42
I removed the comment entirely for now :)
| |
44 return; | |
45 } | |
46 | |
47 SharedPreferences.Editor editor = preferences.edit(); | |
48 editor.putBoolean(TRIED_EXTRACTING_DEX_PREF, true); | |
49 editor.apply(); | |
50 | |
51 File dexDir = context.getDir("dex", Context.MODE_PRIVATE); | |
52 File dexFile = new File(dexDir, "web_apk.dex"); | |
53 if (!FileUtils.extractAsset(context, "web_apk.dex", dexFile) | |
54 || !DexOptimizer.optimize(dexFile)) { | |
55 return; | |
56 } | |
57 | |
58 // Make dex file world-readable so that WebAPK can use it. | |
59 dexFile.setReadable(true, false); | |
60 } | |
61 } | |
OLD | NEW |