blob: e0b7efe5c6033101939f612f98f4573bc6b14aac [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
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
Jeff Sharkeye16e44f2014-11-13 18:02:31 -080019import android.app.Activity;
20import android.content.ActivityNotFoundException;
21import android.content.Intent;
22import android.net.Uri;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080023import android.os.Bundle;
Jeff Sharkeya806f2b2016-01-28 19:03:18 -070024import android.os.StrictMode;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080025import android.os.SystemProperties;
26import android.text.TextUtils;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080027import android.util.Log;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080028import android.widget.Toast;
29
Jeff Sharkeye16e44f2014-11-13 18:02:31 -080030import java.io.File;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080031
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080032/**
33 * The "dialog" that shows from "License" in the Settings app.
34 */
Henrik Carlsson2cb19ab2010-09-03 11:08:19 +020035public class SettingsLicenseActivity extends Activity {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080036 private static final String TAG = "SettingsLicenseActivity";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080037
38 private static final String DEFAULT_LICENSE_PATH = "/system/etc/NOTICE.html.gz";
39 private static final String PROPERTY_LICENSE_PATH = "ro.config.license_path";
40
41 @Override
42 protected void onCreate(Bundle savedInstanceState) {
43 super.onCreate(savedInstanceState);
44
Jeff Sharkeye16e44f2014-11-13 18:02:31 -080045 final String path = SystemProperties.get(PROPERTY_LICENSE_PATH, DEFAULT_LICENSE_PATH);
46 if (TextUtils.isEmpty(path)) {
47 Log.e(TAG, "The system property for the license file is empty");
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080048 showErrorAndFinish();
49 return;
50 }
51
Jeff Sharkeye16e44f2014-11-13 18:02:31 -080052 final File file = new File(path);
53 if (!file.exists() || file.length() == 0) {
54 Log.e(TAG, "License file " + path + " does not exist");
55 showErrorAndFinish();
56 return;
Henrik Carlsson2cb19ab2010-09-03 11:08:19 +020057 }
Jeff Sharkeye16e44f2014-11-13 18:02:31 -080058
59 // Kick off external viewer due to WebView security restrictions; we
60 // carefully point it at HTMLViewer, since it offers to decompress
61 // before viewing.
62 final Intent intent = new Intent(Intent.ACTION_VIEW);
63 intent.setDataAndType(Uri.fromFile(file), "text/html");
64 intent.putExtra(Intent.EXTRA_TITLE, getString(R.string.settings_license_activity_title));
65 intent.addCategory(Intent.CATEGORY_DEFAULT);
66 intent.setPackage("com.android.htmlviewer");
67
68 try {
69 startActivity(intent);
70 finish();
71 } catch (ActivityNotFoundException e) {
72 Log.e(TAG, "Failed to find viewer", e);
73 showErrorAndFinish();
Amith Yamasanic101d2d2011-11-11 13:25:07 -080074 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080075 }
76
77 private void showErrorAndFinish() {
78 Toast.makeText(this, R.string.settings_license_activity_unavailable, Toast.LENGTH_LONG)
79 .show();
80 finish();
81 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080082}