Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 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; |
Amith Yamasani | a3f133a | 2012-08-09 17:11:28 -0700 | [diff] [blame] | 36 | static final String ATTR_USER_ID = "userId"; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 37 | |
| 38 | final PreferredComponent mPref; |
| 39 | |
| 40 | PreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity) { |
| 41 | super(filter); |
| 42 | mPref = new PreferredComponent(this, match, set, activity); |
| 43 | } |
| 44 | |
| 45 | PreferredActivity(XmlPullParser parser) throws XmlPullParserException, IOException { |
| 46 | mPref = new PreferredComponent(this, parser); |
| 47 | } |
| 48 | |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame^] | 49 | public void writeToXml(XmlSerializer serializer, boolean full) throws IOException { |
| 50 | mPref.writeToXml(serializer, full); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 51 | serializer.startTag(null, "filter"); |
Amith Yamasani | a3f133a | 2012-08-09 17:11:28 -0700 | [diff] [blame] | 52 | super.writeToXml(serializer); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 53 | serializer.endTag(null, "filter"); |
| 54 | } |
| 55 | |
| 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 | } |