OSDN Git Service

framework: add neon white list mechanism for applications installed with ABI2
[android-x86/frameworks-base.git] / services / java / com / android / server / pm / xmlCheckExt.java
1 package com.android.server.pm;
2 /*
3  * Copyright (C) 2006 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 import java.io.File;
19 import java.io.FileInputStream;
20 import java.io.FileNotFoundException;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.util.HashMap;
24 import java.util.List;
25
26 import org.xmlpull.v1.XmlPullParser;
27 import org.xmlpull.v1.XmlPullParserException;
28
29 import android.app.Activity;
30 import android.content.res.AssetManager;
31 import android.util.Log;
32 import android.util.Xml;
33
34 /*
35  * class xmlCheckExt is trying to check by xml rules definition
36  */
37 public class xmlCheckExt implements ICheckExt {
38     final private String TAG = "xmlCheckExt";
39     final private String CHECKXMLPATH = "/system/lib/arm/check.xml";
40     private HashMap<String,String > mMap = new  HashMap<String,String >();
41
42     public boolean doCheck(String... params) {
43         String param = null;
44         String param_tag = null;
45         try {
46             int eventType;
47             String tag;
48             if (params.length == 0)
49                 return false;
50             param = params[0];
51             param_tag = params[1];
52             XmlPullParser xmlParser = Xml.newPullParser();
53             File file = new File(CHECKXMLPATH);
54             if (!file.exists())
55                 return false;
56             InputStream in=null;
57             in = new FileInputStream(file);
58             xmlParser.setInput(in, "utf-8");
59
60             eventType = xmlParser.getEventType();
61             while (eventType != XmlPullParser.END_DOCUMENT) {
62                 switch (eventType) {
63                 case XmlPullParser.START_TAG:
64                     tag = xmlParser.getName();
65                     Log.d(TAG,"<"+tag+">");
66                     addTag(tag, xmlParser.nextText());
67                     break;
68                 case XmlPullParser.END_TAG:
69                     tag = xmlParser.getName();
70                     Log.d(TAG,"</"+tag+">");
71                     break;
72                 default:
73                     break;
74                 }
75                 eventType = xmlParser.next();
76             }
77           in.close();
78         } catch (XmlPullParserException e) {
79             // TODO Auto-generated catch block
80             e.printStackTrace();
81         } catch (FileNotFoundException e) {
82             // TODO Auto-generated catch block
83             e.printStackTrace();
84         } catch (IOException e) {
85             // TODO Auto-generated catch block
86             e.printStackTrace();
87         }
88         return checkPkgName(param, param_tag);
89     }
90
91     /*Function:checkTag
92      *Description:
93      * add tag name to hash map
94      *Parameter:
95      * tag - tag name in xml
96      * text - text for the tag
97      *Return:
98      * true
99      */
100     boolean addTag(String tag, String text) {
101         String pkgName = text;
102         Log.d(TAG, " pkgName = " + pkgName);
103         if(!mMap.containsKey(pkgName))
104             mMap.put(pkgName,tag);
105         return true;
106     }
107
108     boolean checkPkgName(String pkgName, String tag) {
109         String value = mMap.get(pkgName);
110         if (value == null)
111             return false;
112         else
113             return value.equals(tag);
114     }
115
116 }