• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.server.pm;
18 
19 import android.content.ComponentName;
20 import android.content.IntentFilter;
21 import android.util.Log;
22 
23 import com.android.internal.util.XmlUtils;
24 
25 import org.xmlpull.v1.XmlPullParser;
26 import org.xmlpull.v1.XmlPullParserException;
27 import org.xmlpull.v1.XmlSerializer;
28 
29 import java.io.IOException;
30 
31 class PersistentPreferredActivity extends IntentFilter {
32     private static final String ATTR_NAME = "name"; // component name
33     private static final String ATTR_FILTER = "filter"; // filter
34     private static final String ATTR_SET_BY_DPM = "set-by-dpm"; // set by DPM
35 
36     private static final String TAG = "PersistentPreferredActivity";
37 
38     private static final boolean DEBUG_FILTERS = false;
39 
40     final ComponentName mComponent;
41     final boolean mIsSetByDpm;
42 
PersistentPreferredActivity(IntentFilter filter, ComponentName activity, boolean isSetByDpm)43     PersistentPreferredActivity(IntentFilter filter, ComponentName activity, boolean isSetByDpm) {
44         super(filter);
45         mComponent = activity;
46         mIsSetByDpm = isSetByDpm;
47     }
48 
PersistentPreferredActivity(XmlPullParser parser)49     PersistentPreferredActivity(XmlPullParser parser) throws XmlPullParserException, IOException {
50         String shortComponent = parser.getAttributeValue(null, ATTR_NAME);
51         mComponent = ComponentName.unflattenFromString(shortComponent);
52         if (mComponent == null) {
53             PackageManagerService.reportSettingsProblem(Log.WARN,
54                     "Error in package manager settings: " +
55                             "Bad activity name " + shortComponent +
56                             " at " + parser.getPositionDescription());
57         }
58         mIsSetByDpm = Boolean.parseBoolean(parser.getAttributeValue(null, ATTR_SET_BY_DPM));
59 
60         int outerDepth = parser.getDepth();
61         String tagName = parser.getName();
62         int type;
63         while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
64                 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
65             tagName = parser.getName();
66             if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
67                 continue;
68             } else if (type == XmlPullParser.START_TAG) {
69                 if (tagName.equals(ATTR_FILTER)) {
70                     break;
71                 } else {
72                     PackageManagerService.reportSettingsProblem(Log.WARN,
73                             "Unknown element: " + tagName +
74                             " at " + parser.getPositionDescription());
75                     XmlUtils.skipCurrentTag(parser);
76                 }
77             }
78         }
79         if (tagName.equals(ATTR_FILTER)) {
80             readFromXml(parser);
81         } else {
82             PackageManagerService.reportSettingsProblem(Log.WARN,
83                     "Missing element filter at " +
84                     parser.getPositionDescription());
85             XmlUtils.skipCurrentTag(parser);
86         }
87     }
88 
writeToXml(XmlSerializer serializer)89     public void writeToXml(XmlSerializer serializer) throws IOException {
90         serializer.attribute(null, ATTR_NAME, mComponent.flattenToShortString());
91         serializer.attribute(null, ATTR_SET_BY_DPM, Boolean.toString(mIsSetByDpm));
92         serializer.startTag(null, ATTR_FILTER);
93             super.writeToXml(serializer);
94         serializer.endTag(null, ATTR_FILTER);
95     }
96 
97     @Override
toString()98     public String toString() {
99         return "PersistentPreferredActivity{0x" + Integer.toHexString(System.identityHashCode(this))
100                 + " " + mComponent.flattenToShortString()
101                 + ", mIsSetByDpm=" + mIsSetByDpm + "}";
102     }
103 }
104