PermissionGroupInfo.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
1/* 2 * Copyright (C) 2008 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 android.content.pm; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21import android.text.TextUtils; 22 23/** 24 * Information you can retrieve about a particular security permission 25 * group known to the system. This corresponds to information collected from the 26 * AndroidManifest.xml's <permission-group> tags. 27 */ 28public class PermissionGroupInfo extends PackageItemInfo implements Parcelable { 29 /** 30 * A string resource identifier (in the package's resources) of this 31 * permission's description. From the "description" attribute or, 32 * if not set, 0. 33 */ 34 public int descriptionRes; 35 36 /** 37 * The description string provided in the AndroidManifest file, if any. You 38 * probably don't want to use this, since it will be null if the description 39 * is in a resource. You probably want 40 * {@link PermissionInfo#loadDescription} instead. 41 */ 42 public CharSequence nonLocalizedDescription; 43 44 public PermissionGroupInfo() { 45 } 46 47 public PermissionGroupInfo(PermissionGroupInfo orig) { 48 super(orig); 49 descriptionRes = orig.descriptionRes; 50 nonLocalizedDescription = orig.nonLocalizedDescription; 51 } 52 53 /** 54 * Retrieve the textual description of this permission. This 55 * will call back on the given PackageManager to load the description from 56 * the application. 57 * 58 * @param pm A PackageManager from which the label can be loaded; usually 59 * the PackageManager from which you originally retrieved this item. 60 * 61 * @return Returns a CharSequence containing the permission's description. 62 * If there is no description, null is returned. 63 */ 64 public CharSequence loadDescription(PackageManager pm) { 65 if (nonLocalizedDescription != null) { 66 return nonLocalizedDescription; 67 } 68 if (descriptionRes != 0) { 69 CharSequence label = pm.getText(packageName, descriptionRes, null); 70 if (label != null) { 71 return label; 72 } 73 } 74 return null; 75 } 76 77 public String toString() { 78 return "PermissionGroupInfo{" 79 + Integer.toHexString(System.identityHashCode(this)) 80 + " " + name + "}"; 81 } 82 83 public int describeContents() { 84 return 0; 85 } 86 87 public void writeToParcel(Parcel dest, int parcelableFlags) { 88 super.writeToParcel(dest, parcelableFlags); 89 dest.writeInt(descriptionRes); 90 TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags); 91 } 92 93 public static final Creator<PermissionGroupInfo> CREATOR = 94 new Creator<PermissionGroupInfo>() { 95 public PermissionGroupInfo createFromParcel(Parcel source) { 96 return new PermissionGroupInfo(source); 97 } 98 public PermissionGroupInfo[] newArray(int size) { 99 return new PermissionGroupInfo[size]; 100 } 101 }; 102 103 private PermissionGroupInfo(Parcel source) { 104 super(source); 105 descriptionRes = source.readInt(); 106 nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); 107 } 108} 109