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