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    /**
45     * Flag for {@link #flags}, corresponding to <code>personalInfo</code>
46     * value of {@link android.R.attr#permissionGroupFlags}.
47     * @hide
48     */
49    public static final int FLAG_PERSONAL_INFO = 1<<0;
50
51    /**
52     * Additional flags about this group as given by
53     * {@link android.R.attr#permissionGroupFlags}.
54     * @hide
55     */
56    public int flags;
57
58    /**
59     * Prioritization of this group, for visually sorting with other groups.
60     * @hide
61     */
62    public int priority;
63
64    public PermissionGroupInfo() {
65    }
66
67    public PermissionGroupInfo(PermissionGroupInfo orig) {
68        super(orig);
69        descriptionRes = orig.descriptionRes;
70        nonLocalizedDescription = orig.nonLocalizedDescription;
71        flags = orig.flags;
72        priority = orig.priority;
73    }
74
75    /**
76     * Retrieve the textual description of this permission.  This
77     * will call back on the given PackageManager to load the description from
78     * the application.
79     *
80     * @param pm A PackageManager from which the label can be loaded; usually
81     * the PackageManager from which you originally retrieved this item.
82     *
83     * @return Returns a CharSequence containing the permission's description.
84     * If there is no description, null is returned.
85     */
86    public CharSequence loadDescription(PackageManager pm) {
87        if (nonLocalizedDescription != null) {
88            return nonLocalizedDescription;
89        }
90        if (descriptionRes != 0) {
91            CharSequence label = pm.getText(packageName, descriptionRes, null);
92            if (label != null) {
93                return label;
94            }
95        }
96        return null;
97    }
98
99    public String toString() {
100        return "PermissionGroupInfo{"
101            + Integer.toHexString(System.identityHashCode(this))
102            + " " + name + " flgs=0x" + Integer.toHexString(flags) + "}";
103    }
104
105    public int describeContents() {
106        return 0;
107    }
108
109    public void writeToParcel(Parcel dest, int parcelableFlags) {
110        super.writeToParcel(dest, parcelableFlags);
111        dest.writeInt(descriptionRes);
112        TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags);
113        dest.writeInt(flags);
114        dest.writeInt(priority);
115    }
116
117    public static final Creator<PermissionGroupInfo> CREATOR =
118            new Creator<PermissionGroupInfo>() {
119        public PermissionGroupInfo createFromParcel(Parcel source) {
120            return new PermissionGroupInfo(source);
121        }
122        public PermissionGroupInfo[] newArray(int size) {
123            return new PermissionGroupInfo[size];
124        }
125    };
126
127    private PermissionGroupInfo(Parcel source) {
128        super(source);
129        descriptionRes = source.readInt();
130        nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
131        flags = source.readInt();
132        priority = source.readInt();
133    }
134}
135