1 /* 2 * Copyright (C) 2014 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.tv.settings.about; 18 19 import com.android.tv.settings.R; 20 21 import android.app.Activity; 22 import android.content.ActivityNotFoundException; 23 import android.content.Intent; 24 import android.net.Uri; 25 import android.os.Bundle; 26 import android.os.SystemProperties; 27 import android.text.TextUtils; 28 import android.util.Log; 29 import android.widget.Toast; 30 31 import java.io.File; 32 33 34 /** 35 * Displays open source NOTICE files. 36 */ 37 public class LicenseActivity extends Activity { 38 39 private static final String TAG = "LicenseActivity"; 40 41 private static final String DEFAULT_LICENSE_PATH = "/system/etc/NOTICE.html.gz"; 42 private static final String PROPERTY_LICENSE_PATH = "ro.config.license_path"; 43 44 @Override 45 protected void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 48 final String path = SystemProperties.get(PROPERTY_LICENSE_PATH, DEFAULT_LICENSE_PATH); 49 if (TextUtils.isEmpty(path)) { 50 Log.e(TAG, "The system property for the license file is empty"); 51 showErrorAndFinish(); 52 return; 53 } 54 55 final File file = new File(path); 56 if (!file.exists() || file.length() == 0) { 57 Log.e(TAG, "License file " + path + " does not exist"); 58 showErrorAndFinish(); 59 return; 60 } 61 62 // Kick off external viewer due to WebView security restrictions; we 63 // carefully point it at HTMLViewer, since it offers to decompress 64 // before viewing. 65 final Intent intent = new Intent(Intent.ACTION_VIEW); 66 intent.setDataAndType(Uri.fromFile(file), "text/html"); 67 intent.putExtra(Intent.EXTRA_TITLE, getString(R.string.about_legal_license)); 68 intent.addCategory(Intent.CATEGORY_DEFAULT); 69 intent.setPackage("com.android.htmlviewer"); 70 71 try { 72 startActivity(intent); 73 finish(); 74 } catch (ActivityNotFoundException e) { 75 Log.e(TAG, "Failed to find viewer", e); 76 showErrorAndFinish(); 77 } 78 } 79 80 private void showErrorAndFinish() { 81 Toast.makeText(this, R.string.about_license_activity_unavailable, Toast.LENGTH_LONG) 82 .show(); 83 finish(); 84 } 85 } 86