1 /* 2 * Copyright (C) 2017 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.dialer.about; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Container class to store the name of a library and the filename of its associated license file. 24 */ 25 public final class License implements Comparable<License>, Parcelable { 26 // Name of the third-party library. 27 private final String libraryName; 28 // Byte offset in the file to the start of the license text. 29 private final long licenseOffset; 30 // Byte length of the license text. 31 private final int licenseLength; 32 33 /** 34 * Create an object representing a stored license. The text for all licenses is stored in a single 35 * file, so the offset and length describe this license's position within the file. 36 */ create(String libraryName, long licenseOffset, int licenseLength)37 static License create(String libraryName, long licenseOffset, int licenseLength) { 38 return new License(libraryName, licenseOffset, licenseLength); 39 } 40 41 public static final Parcelable.Creator<License> CREATOR = 42 new Parcelable.Creator<License>() { 43 @Override 44 public License createFromParcel(Parcel in) { 45 return new License(in); 46 } 47 48 @Override 49 public License[] newArray(int size) { 50 return new License[size]; 51 } 52 }; 53 54 @Override describeContents()55 public int describeContents() { 56 return 0; 57 } 58 59 @Override writeToParcel(Parcel dest, int flags)60 public void writeToParcel(Parcel dest, int flags) { 61 dest.writeString(libraryName); 62 dest.writeLong(licenseOffset); 63 dest.writeInt(licenseLength); 64 } 65 66 @Override compareTo(License o)67 public int compareTo(License o) { 68 return libraryName.compareToIgnoreCase(o.getLibraryName()); 69 } 70 71 @Override toString()72 public String toString() { 73 return getLibraryName(); 74 } 75 License(String libraryName, long licenseOffset, int licenseLength)76 private License(String libraryName, long licenseOffset, int licenseLength) { 77 this.libraryName = libraryName; 78 this.licenseOffset = licenseOffset; 79 this.licenseLength = licenseLength; 80 } 81 License(Parcel in)82 private License(Parcel in) { 83 libraryName = in.readString(); 84 licenseOffset = in.readLong(); 85 licenseLength = in.readInt(); 86 } 87 getLibraryName()88 String getLibraryName() { 89 return libraryName; 90 } 91 getLicenseOffset()92 long getLicenseOffset() { 93 return licenseOffset; 94 } 95 getLicenseLength()96 int getLicenseLength() { 97 return licenseLength; 98 } 99 } 100