Home | History | Annotate | Download | only in pm
      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 
     39     PreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity) {
     40         super(filter);
     41         mPref = new PreferredComponent(this, match, set, activity);
     42     }
     43 
     44     PreferredActivity(XmlPullParser parser) throws XmlPullParserException, IOException {
     45         mPref = new PreferredComponent(this, parser);
     46     }
     47 
     48     public void writeToXml(XmlSerializer serializer) throws IOException {
     49         mPref.writeToXml(serializer);
     50         serializer.startTag(null, "filter");
     51         super.writeToXml(serializer);
     52         serializer.endTag(null, "filter");
     53     }
     54 
     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