1 /*
2  * Copyright (C) 2022 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 com.android.devicelockcontroller.activities;
18 
19 import android.os.Bundle;
20 import android.webkit.WebResourceRequest;
21 import android.webkit.WebView;
22 import android.webkit.WebViewClient;
23 
24 import androidx.annotation.Nullable;
25 import androidx.annotation.VisibleForTesting;
26 import androidx.appcompat.app.AppCompatActivity;
27 
28 import com.android.devicelockcontroller.R;
29 import com.android.devicelockcontroller.util.LogUtil;
30 
31 /**
32  * Activity to show help articles. The url for the article is provided as an extra param.
33  */
34 public final class HelpActivity extends AppCompatActivity {
35     private static final String TAG = HelpActivity.class.getSimpleName();
36     public static final String EXTRA_URL_PARAM = "URL";
37 
38     private WebView mWebView;
39 
40     @Override
onCreate(@ullable Bundle savedInstanceState)41     protected void onCreate(@Nullable Bundle savedInstanceState) {
42         super.onCreate(savedInstanceState);
43         setContentView(R.layout.help_activity);
44 
45         mWebView = findViewById(R.id.webview);
46         Bundle extras = getIntent().getExtras();
47         if (extras == null) {
48             LogUtil.e(TAG, "No extras present in the launch intent");
49             finish();
50             return;
51         }
52 
53         String url = extras.getString(EXTRA_URL_PARAM);
54         if (url == null) {
55             LogUtil.e(TAG, "URL param missing in intent extras");
56             finish();
57             return;
58         }
59         mWebView.setWebViewClient(
60                 new WebViewClient() {
61                     @Override
62                     public boolean shouldOverrideUrlLoading(WebView view,
63                             WebResourceRequest request) {
64                         return false;
65                     }
66                 });
67         mWebView.loadUrl(url);
68     }
69 
70     @VisibleForTesting
getWebView()71     WebView getWebView() {
72         return mWebView;
73     }
74 }
75