The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settings; |
| 18 | |
Jeff Sharkey | e16e44f | 2014-11-13 18:02:31 -0800 | [diff] [blame^] | 19 | import android.app.Activity; |
| 20 | import android.content.ActivityNotFoundException; |
| 21 | import android.content.Intent; |
| 22 | import android.net.Uri; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 23 | import android.os.Bundle; |
| 24 | import android.os.SystemProperties; |
| 25 | import android.text.TextUtils; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 26 | import android.util.Log; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 27 | import android.widget.Toast; |
| 28 | |
Jeff Sharkey | e16e44f | 2014-11-13 18:02:31 -0800 | [diff] [blame^] | 29 | import java.io.File; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 30 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 31 | /** |
| 32 | * The "dialog" that shows from "License" in the Settings app. |
| 33 | */ |
Henrik Carlsson | 2cb19ab | 2010-09-03 11:08:19 +0200 | [diff] [blame] | 34 | public class SettingsLicenseActivity extends Activity { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 35 | private static final String TAG = "SettingsLicenseActivity"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 36 | |
| 37 | private static final String DEFAULT_LICENSE_PATH = "/system/etc/NOTICE.html.gz"; |
| 38 | private static final String PROPERTY_LICENSE_PATH = "ro.config.license_path"; |
| 39 | |
| 40 | @Override |
| 41 | protected void onCreate(Bundle savedInstanceState) { |
| 42 | super.onCreate(savedInstanceState); |
| 43 | |
Jeff Sharkey | e16e44f | 2014-11-13 18:02:31 -0800 | [diff] [blame^] | 44 | final String path = SystemProperties.get(PROPERTY_LICENSE_PATH, DEFAULT_LICENSE_PATH); |
| 45 | if (TextUtils.isEmpty(path)) { |
| 46 | Log.e(TAG, "The system property for the license file is empty"); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 47 | showErrorAndFinish(); |
| 48 | return; |
| 49 | } |
| 50 | |
Jeff Sharkey | e16e44f | 2014-11-13 18:02:31 -0800 | [diff] [blame^] | 51 | final File file = new File(path); |
| 52 | if (!file.exists() || file.length() == 0) { |
| 53 | Log.e(TAG, "License file " + path + " does not exist"); |
| 54 | showErrorAndFinish(); |
| 55 | return; |
Henrik Carlsson | 2cb19ab | 2010-09-03 11:08:19 +0200 | [diff] [blame] | 56 | } |
Jeff Sharkey | e16e44f | 2014-11-13 18:02:31 -0800 | [diff] [blame^] | 57 | |
| 58 | // Kick off external viewer due to WebView security restrictions; we |
| 59 | // carefully point it at HTMLViewer, since it offers to decompress |
| 60 | // before viewing. |
| 61 | final Intent intent = new Intent(Intent.ACTION_VIEW); |
| 62 | intent.setDataAndType(Uri.fromFile(file), "text/html"); |
| 63 | intent.putExtra(Intent.EXTRA_TITLE, getString(R.string.settings_license_activity_title)); |
| 64 | intent.addCategory(Intent.CATEGORY_DEFAULT); |
| 65 | intent.setPackage("com.android.htmlviewer"); |
| 66 | |
| 67 | try { |
| 68 | startActivity(intent); |
| 69 | finish(); |
| 70 | } catch (ActivityNotFoundException e) { |
| 71 | Log.e(TAG, "Failed to find viewer", e); |
| 72 | showErrorAndFinish(); |
Amith Yamasani | c101d2d | 2011-11-11 13:25:07 -0800 | [diff] [blame] | 73 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | private void showErrorAndFinish() { |
| 77 | Toast.makeText(this, R.string.settings_license_activity_unavailable, Toast.LENGTH_LONG) |
| 78 | .show(); |
| 79 | finish(); |
| 80 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 81 | } |