• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 
17 package android.webkit.cts;
18 
19 import android.webkit.cts.R;
20 
21 import android.app.Activity;
22 import android.app.ActivityManager;
23 import android.os.Build;
24 import android.os.Bundle;
25 import android.view.ViewGroup;
26 import android.view.ViewParent;
27 import android.webkit.WebView;
28 
29 import com.android.compatibility.common.util.NullWebViewUtils;
30 
31 public class WebViewCtsActivity extends Activity {
32     private WebView mWebView;
33     private Exception mInflationException;
34 
35     @Override
onCreate(Bundle savedInstanceState)36     public void onCreate(Bundle savedInstanceState) {
37         try {
38             super.onCreate(savedInstanceState);
39             setContentView(R.layout.webview_layout);
40             mWebView = (WebView) findViewById(R.id.web_page);
41             mInflationException = null;
42         } catch (Exception e) {
43             NullWebViewUtils.determineIfWebViewAvailable(this, e);
44             // If WebView is available, then the exception we just caught should be propagated.
45             if (NullWebViewUtils.isWebViewAvailable()) {
46                 mInflationException = e;
47            }
48         }
49     }
50 
isMultiprocessMode()51     public boolean isMultiprocessMode() {
52         // Currently multiprocess is disabled on low RAM 32 bit devices.
53         return
54             Build.SUPPORTED_64_BIT_ABIS.length > 0 ||
55             !getSystemService(ActivityManager.class).isLowRamDevice();
56     }
57 
getWebView()58     public WebView getWebView() {
59         if (mInflationException != null) {
60             throw new RuntimeException("Exception caught in onCreate", mInflationException);
61         }
62         return mWebView;
63     }
64 
65     @Override
onDestroy()66     public void onDestroy() {
67         if (mWebView != null) {
68             ViewParent parent =  mWebView.getParent();
69             if (parent instanceof ViewGroup) {
70                 ((ViewGroup) parent).removeView(mWebView);
71             }
72             mWebView.destroy();
73         }
74         super.onDestroy();
75     }
76 }
77