• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 com.android.internal.util.XmlUtils;
20 import com.android.server.PreferredComponent;
21 
22 import org.xmlpull.v1.XmlPullParser;
23 import org.xmlpull.v1.XmlPullParserException;
24 import org.xmlpull.v1.XmlSerializer;
25 
26 import android.content.ComponentName;
27 import android.content.IntentFilter;
28 import android.util.Log;
29 
30 import java.io.IOException;
31 
32 class PreferredActivity extends IntentFilter implements PreferredComponent.Callbacks {
33     private static final String TAG = "PreferredActivity";
34 
35     private static final boolean DEBUG_FILTERS = false;
36 
37     final PreferredComponent mPref;
38 
PreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity, boolean always)39     PreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity,
40             boolean always) {
41         super(filter);
42         mPref = new PreferredComponent(this, match, set, activity, always);
43     }
44 
PreferredActivity(XmlPullParser parser)45     PreferredActivity(XmlPullParser parser) throws XmlPullParserException, IOException {
46         mPref = new PreferredComponent(this, parser);
47     }
48 
writeToXml(XmlSerializer serializer, boolean full)49     public void writeToXml(XmlSerializer serializer, boolean full) throws IOException {
50         mPref.writeToXml(serializer, full);
51         serializer.startTag(null, "filter");
52             super.writeToXml(serializer);
53         serializer.endTag(null, "filter");
54     }
55 
onReadTag(String tagName, XmlPullParser parser)56     public boolean onReadTag(String tagName, XmlPullParser parser) throws XmlPullParserException,
57             IOException {
58         if (tagName.equals("filter")) {
59             if (DEBUG_FILTERS) {
60                 Log.i(TAG, "Starting to parse filter...");
61             }
62             readFromXml(parser);
63             if (DEBUG_FILTERS) {
64                 Log.i(TAG, "Finished filter: depth=" + parser.getDepth() + " tag="
65                         + parser.getName());
66             }
67         } else {
68             PackageManagerService.reportSettingsProblem(Log.WARN,
69                     "Unknown element under <preferred-activities>: " + parser.getName());
70             XmlUtils.skipCurrentTag(parser);
71         }
72         return true;
73     }
74 
75     @Override
toString()76     public String toString() {
77         return "PreferredActivity{0x" + Integer.toHexString(System.identityHashCode(this))
78                 + " " + mPref.mComponent.flattenToShortString() + "}";
79     }
80 }
81