blob: c40dd07192a14ff7c707baa93fa55e266b5ac309 [file] [log] [blame]
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2007 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
17package com.android.settings;
18
19import android.os.Bundle;
20import android.os.SystemProperties;
21import android.text.TextUtils;
22import android.util.Config;
23import android.util.Log;
24import android.webkit.WebView;
25import android.webkit.WebViewClient;
26import android.widget.Toast;
27
28import java.io.FileNotFoundException;
29import java.io.FileReader;
30import java.io.IOException;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070031
32import com.android.internal.app.AlertActivity;
33import com.android.internal.app.AlertController;
34
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070035/**
36 * The "dialog" that shows from "License" in the Settings app.
37 */
38public class SettingsLicenseActivity extends AlertActivity {
39
40 private static final String TAG = "SettingsLicenseActivity";
41 private static final boolean LOGV = false || Config.LOGV;
42
43 private static final String DEFAULT_LICENSE_PATH = "/system/etc/NOTICE.html";
44 private static final String PROPERTY_LICENSE_PATH = "ro.config.license_path";
45
46 @Override
47 protected void onCreate(Bundle savedInstanceState) {
48 super.onCreate(savedInstanceState);
49
50 String fileName = SystemProperties.get(PROPERTY_LICENSE_PATH, DEFAULT_LICENSE_PATH);
51 if (TextUtils.isEmpty(fileName)) {
52 Log.e(TAG, "The system property for the license file is empty.");
53 showErrorAndFinish();
54 return;
55 }
56
57 FileReader fileReader = null;
58 StringBuilder data = null;
59 try {
60 data = new StringBuilder(2048);
61 char tmp[] = new char[2048];
62 int numRead;
63 fileReader = new FileReader(fileName);
64 while ((numRead = fileReader.read(tmp)) >= 0) {
65 data.append(tmp, 0, numRead);
66 }
67 } catch (FileNotFoundException e) {
68 Log.e(TAG, "License HTML file not found at " + fileName, e);
69 showErrorAndFinish();
70 return;
71 } catch (IOException e) {
72 Log.e(TAG, "Error reading license HTML file at " + fileName, e);
73 showErrorAndFinish();
74 return;
75 } finally {
76 try {
77 if (fileReader != null) {
78 fileReader.close();
79 }
80 } catch (IOException e) {
81 }
82 }
83
84 if (TextUtils.isEmpty(data)) {
85 Log.e(TAG, "License HTML is empty (from " + fileName + ")");
86 showErrorAndFinish();
87 return;
88 }
89
90 WebView webView = new WebView(this);
91
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070092 // Begin the loading. This will be done in a separate thread in WebView.
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080093 webView.loadDataWithBaseURL(null, data.toString(), "text/html", "utf-8", null);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070094 webView.setWebViewClient(new WebViewClient() {
95 @Override
96 public void onPageFinished(WebView view, String url) {
97 // Change from 'Loading...' to the real title
98 mAlert.setTitle(getString(R.string.settings_license_activity_title));
99 }
100 });
101
102 final AlertController.AlertParams p = mAlertParams;
103 p.mTitle = getString(R.string.settings_license_activity_loading);
104 p.mView = webView;
105 p.mForceInverseBackground = true;
106 setupAlert();
107 }
108
109 private void showErrorAndFinish() {
110 Toast.makeText(this, R.string.settings_license_activity_unavailable, Toast.LENGTH_LONG)
111 .show();
112 finish();
113 }
114
115}