The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 17 | package com.android.browser; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 19 | import android.app.Application; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.pm.PackageManager; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 22 | import android.util.Log; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 23 | import android.os.Process; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 24 | |
Tarun Nainani | ea28dde | 2014-08-27 17:25:09 -0700 | [diff] [blame^] | 25 | import org.chromium.content.browser.ResourceExtractor; |
| 26 | import org.chromium.base.PathUtils; |
| 27 | |
Vivek Sekhar | 0989b45 | 2014-08-01 12:30:35 -0700 | [diff] [blame] | 28 | import org.codeaurora.swe.Engine; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 29 | |
Axesh R. Ajmera | 70a6ec7 | 2014-06-10 18:03:50 -0700 | [diff] [blame] | 30 | import com.android.browser.BrowserConfig; |
| 31 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 32 | public class Browser extends Application { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 33 | |
| 34 | private final static String LOGTAG = "browser"; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 35 | |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 36 | // Set to true to enable verbose logging. |
John Reck | 6c2e2f3 | 2011-08-22 13:41:23 -0700 | [diff] [blame] | 37 | final static boolean LOGV_ENABLED = false; |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 38 | |
| 39 | // Set to true to enable extra debug logging. |
| 40 | final static boolean LOGD_ENABLED = true; |
| 41 | |
Tarun Nainani | ea28dde | 2014-08-27 17:25:09 -0700 | [diff] [blame^] | 42 | private static final String[] MP_MANDATORY_PAKS = new String[] { |
| 43 | "webviewchromium.pak", |
| 44 | "icudtl.dat" |
| 45 | }; |
| 46 | |
John Reck | 6f48ba5 | 2010-12-03 16:03:14 -0800 | [diff] [blame] | 47 | @Override |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 48 | public void onCreate() { |
Kristian Monsen | e800e8e | 2010-12-06 16:59:33 +0000 | [diff] [blame] | 49 | super.onCreate(); |
Tarun Nainani | ea28dde | 2014-08-27 17:25:09 -0700 | [diff] [blame^] | 50 | initializeApplicationParameters(); |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 51 | if (LOGV_ENABLED) |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 52 | Log.v(LOGTAG, "Browser.onCreate: this=" + this); |
Kristian Monsen | e800e8e | 2010-12-06 16:59:33 +0000 | [diff] [blame] | 53 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 54 | // SWE: Avoid initializing databases for sandboxed processes. |
| 55 | // Must have INITIALIZE_DATABASE permission in AndroidManifest.xml only for browser process |
Vivek Sekhar | 0989b45 | 2014-08-01 12:30:35 -0700 | [diff] [blame] | 56 | final String INITIALIZE_DATABASE = BrowserConfig.AUTHORITY + |
Axesh R. Ajmera | 70a6ec7 | 2014-06-10 18:03:50 -0700 | [diff] [blame] | 57 | ".permission.INITIALIZE_DATABASE"; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 58 | final Context context = getApplicationContext(); |
Vivek Sekhar | 0989b45 | 2014-08-01 12:30:35 -0700 | [diff] [blame] | 59 | boolean isActivityContext = (context.checkPermission(INITIALIZE_DATABASE, |
| 60 | Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED); |
| 61 | if (isActivityContext) { |
| 62 | // Initialize the SWE engine. |
| 63 | Engine.initialize(context); |
| 64 | BrowserSettings.initialize(context); |
| 65 | Preloader.initialize(context); |
Tarun Nainani | ea28dde | 2014-08-27 17:25:09 -0700 | [diff] [blame^] | 66 | } |
| 67 | |
| 68 | } |
| 69 | |
| 70 | public static void initializeApplicationParameters() { |
| 71 | ResourceExtractor.setMandatoryPaksToExtract(MP_MANDATORY_PAKS); |
| 72 | PathUtils.setPrivateDataDirectorySuffix("android_browser"); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 73 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 74 | } |
| 75 | |