use of android.content.res.XmlResourceParser in project android_frameworks_base by ResurrectionRemix.
the class XmlConfigSource method ensureInitialized.
private void ensureInitialized() {
synchronized (mLock) {
if (mInitialized) {
return;
}
try (XmlResourceParser parser = mContext.getResources().getXml(mResourceId)) {
parseNetworkSecurityConfig(parser);
mContext = null;
mInitialized = true;
} catch (Resources.NotFoundException | XmlPullParserException | IOException | ParserException e) {
throw new RuntimeException("Failed to parse XML configuration from " + mContext.getResources().getResourceEntryName(mResourceId), e);
}
}
}
use of android.content.res.XmlResourceParser in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SettingsInjector method parseServiceInfo.
/**
* Returns the settings parsed from the attributes of the
* {@link SettingInjectorService#META_DATA_NAME} tag, or null.
*
* Duplicates some code from {@link android.content.pm.RegisteredServicesCache}.
*/
private InjectedSetting parseServiceInfo(ResolveInfo service, UserHandle userHandle, PackageManager pm) throws XmlPullParserException, IOException {
ServiceInfo si = service.serviceInfo;
ApplicationInfo ai = si.applicationInfo;
if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
if (Log.isLoggable(TAG, Log.WARN)) {
Log.w(TAG, "Ignoring attempt to inject setting from app not in system image: " + service);
return null;
}
} else if (!DimmableIZatIconPreference.showIzat(mContext, si.packageName)) {
return null;
}
XmlResourceParser parser = null;
try {
parser = si.loadXmlMetaData(pm, SettingInjectorService.META_DATA_NAME);
if (parser == null) {
throw new XmlPullParserException("No " + SettingInjectorService.META_DATA_NAME + " meta-data for " + service + ": " + si);
}
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
}
String nodeName = parser.getName();
if (!SettingInjectorService.ATTRIBUTES_NAME.equals(nodeName)) {
throw new XmlPullParserException("Meta-data does not start with " + SettingInjectorService.ATTRIBUTES_NAME + " tag");
}
Resources res = pm.getResourcesForApplicationAsUser(si.packageName, userHandle.getIdentifier());
return parseAttributes(si.packageName, si.name, userHandle, res, attrs);
} catch (PackageManager.NameNotFoundException e) {
throw new XmlPullParserException("Unable to load resources for package " + si.packageName);
} finally {
if (parser != null) {
parser.close();
}
}
}
use of android.content.res.XmlResourceParser in project android_frameworks_base by ResurrectionRemix.
the class KeyphraseEnrollmentInfo method getKeyphraseMetadataFromApplicationInfo.
private KeyphraseMetadata getKeyphraseMetadataFromApplicationInfo(PackageManager pm, ApplicationInfo ai, List<String> parseErrors) {
XmlResourceParser parser = null;
String packageName = ai.packageName;
KeyphraseMetadata keyphraseMetadata = null;
try {
parser = ai.loadXmlMetaData(pm, VOICE_KEYPHRASE_META_DATA);
if (parser == null) {
String error = "No " + VOICE_KEYPHRASE_META_DATA + " meta-data for " + packageName;
parseErrors.add(error);
Slog.w(TAG, error);
return null;
}
Resources res = pm.getResourcesForApplication(ai);
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
}
String nodeName = parser.getName();
if (!"voice-enrollment-application".equals(nodeName)) {
String error = "Meta-data does not start with voice-enrollment-application tag for " + packageName;
parseErrors.add(error);
Slog.w(TAG, error);
return null;
}
TypedArray array = res.obtainAttributes(attrs, com.android.internal.R.styleable.VoiceEnrollmentApplication);
keyphraseMetadata = getKeyphraseFromTypedArray(array, packageName, parseErrors);
array.recycle();
} catch (XmlPullParserException e) {
String error = "Error parsing keyphrase enrollment meta-data for " + packageName;
parseErrors.add(error + ": " + e);
Slog.w(TAG, error, e);
} catch (IOException e) {
String error = "Error parsing keyphrase enrollment meta-data for " + packageName;
parseErrors.add(error + ": " + e);
Slog.w(TAG, error, e);
} catch (PackageManager.NameNotFoundException e) {
String error = "Error parsing keyphrase enrollment meta-data for " + packageName;
parseErrors.add(error + ": " + e);
Slog.w(TAG, error, e);
} finally {
if (parser != null)
parser.close();
}
return keyphraseMetadata;
}
use of android.content.res.XmlResourceParser in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class VoiceInputHelper method buildUi.
public void buildUi() {
// Get the currently selected interactor from the secure setting.
String currentSetting = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.VOICE_INTERACTION_SERVICE);
if (currentSetting != null && !currentSetting.isEmpty()) {
mCurrentVoiceInteraction = ComponentName.unflattenFromString(currentSetting);
} else {
mCurrentVoiceInteraction = null;
}
ArraySet<ComponentName> interactorRecognizers = new ArraySet<>();
// Iterate through all the available interactors and load up their info to show
// in the preference.
int size = mAvailableVoiceInteractions.size();
for (int i = 0; i < size; i++) {
ResolveInfo resolveInfo = mAvailableVoiceInteractions.get(i);
VoiceInteractionServiceInfo info = new VoiceInteractionServiceInfo(mContext.getPackageManager(), resolveInfo.serviceInfo);
if (info.getParseError() != null) {
Log.w("VoiceInteractionService", "Error in VoiceInteractionService " + resolveInfo.serviceInfo.packageName + "/" + resolveInfo.serviceInfo.name + ": " + info.getParseError());
continue;
}
mAvailableInteractionInfos.add(new InteractionInfo(mContext.getPackageManager(), info));
interactorRecognizers.add(new ComponentName(resolveInfo.serviceInfo.packageName, info.getRecognitionService()));
}
Collections.sort(mAvailableInteractionInfos);
// Get the currently selected recognizer from the secure setting.
currentSetting = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.VOICE_RECOGNITION_SERVICE);
if (currentSetting != null && !currentSetting.isEmpty()) {
mCurrentRecognizer = ComponentName.unflattenFromString(currentSetting);
} else {
mCurrentRecognizer = null;
}
// Iterate through all the available recognizers and load up their info to show
// in the preference.
size = mAvailableRecognition.size();
for (int i = 0; i < size; i++) {
ResolveInfo resolveInfo = mAvailableRecognition.get(i);
ComponentName comp = new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
if (interactorRecognizers.contains(comp)) {
//continue;
}
ServiceInfo si = resolveInfo.serviceInfo;
XmlResourceParser parser = null;
String settingsActivity = null;
try {
parser = si.loadXmlMetaData(mContext.getPackageManager(), RecognitionService.SERVICE_META_DATA);
if (parser == null) {
throw new XmlPullParserException("No " + RecognitionService.SERVICE_META_DATA + " meta-data for " + si.packageName);
}
Resources res = mContext.getPackageManager().getResourcesForApplication(si.applicationInfo);
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
}
String nodeName = parser.getName();
if (!"recognition-service".equals(nodeName)) {
throw new XmlPullParserException("Meta-data does not start with recognition-service tag");
}
TypedArray array = res.obtainAttributes(attrs, com.android.internal.R.styleable.RecognitionService);
settingsActivity = array.getString(com.android.internal.R.styleable.RecognitionService_settingsActivity);
array.recycle();
} catch (XmlPullParserException e) {
Log.e(TAG, "error parsing recognition service meta-data", e);
} catch (IOException e) {
Log.e(TAG, "error parsing recognition service meta-data", e);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "error parsing recognition service meta-data", e);
} finally {
if (parser != null)
parser.close();
}
mAvailableRecognizerInfos.add(new RecognizerInfo(mContext.getPackageManager(), resolveInfo.serviceInfo, settingsActivity));
}
Collections.sort(mAvailableRecognizerInfos);
}
use of android.content.res.XmlResourceParser in project cornerstone by Onskreen.
the class CSPanel method onCreate.
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/**
* Author: Onskreen
* Date: 13/07/2011
*
* Creates the Sharedpreference if it doesn't exist and store the
* cs panel packages if they don't exist. It also populates the
* mCornerstoneApps list which can be used across the class.
*/
SharedPreferences settings = getSharedPreferences(CS_PREFS, 4);
String panel0 = settings.getString("panel0", null);
String panel1 = settings.getString("panel1", null);
if (panel0 == null && panel1 == null) {
SharedPreferences.Editor editor = settings.edit();
editor.putString("panel0", "com.android.email");
editor.putString("panel1", "com.android.browser");
// Commit the edits!
editor.commit();
panel0 = "com.android.email";
panel1 = "com.android.browser";
}
mCornerstoneApps = new String[2];
mCornerstoneApps[0] = panel0;
mCornerstoneApps[1] = panel1;
/**
* Author: Onskreen
* Date: 20/07/2011
*
* populate the CLauncher package and class names
* from the cornerstone.xml
*/
if (mCSLauncherPkgName == null && mCSLauncherClassName == null) {
XmlResourceParser xpp = null;
try {
Resources res = this.getResources();
xpp = res.getXml(com.android.internal.R.xml.cornerstone);
xpp.next();
int eventType = xpp.getEventType();
String tag;
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_DOCUMENT) {
} else if (eventType == XmlPullParser.START_TAG) {
tag = xpp.getName();
if (tag.equals("launcher")) {
xpp.next();
tag = xpp.getName();
if (tag.equals("pkg")) {
xpp.next();
mCSLauncherPkgName = xpp.getText();
xpp.next();
}
xpp.next();
tag = xpp.getName();
if (tag.equals("class")) {
xpp.next();
mCSLauncherClassName = xpp.getText();
xpp.next();
}
break;
}
}
eventType = xpp.next();
}
xpp.close();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
xpp.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
xpp.close();
}
}
/**
* Author: Onskreen
* Date: 19/04/2011
*
* sets the contentview with appropriate layout file as per the current
* configuration.
*/
Configuration config = getApplicationContext().getResources().getConfiguration();
if (config != null) {
int orientation = config.orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
// Portrait
setContentView(R.layout.portrait_main);
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
// Landscape
setContentView(R.layout.landscape_main);
}
}
/**
* Author: Onskreen
* Date: 25/02/2011
*
* Initialize the UI controls at startup of the app
*/
initializeControls();
/**
* Author: Onskreen
* Date: 25/02/2011
*
* Update the UI controls in UI thread when WMS notifies the cornerstone app
*/
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
String pkg = (String) msg.obj;
int index = msg.what;
/**
* Author: Onskreen
* Date: 08/03/2011
*
* Sets the appropriate cs title for the app running in cs panel.
*/
CharSequence title = pkg;
if (pkg != null) {
try {
ApplicationInfo appInfo = mPkgManager.getApplicationInfo(pkg, 0);
if (appInfo != null) {
title = mPkgManager.getApplicationLabel(appInfo);
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
switch(index) {
case 0:
setCornerstoneAppControls(0);
csAppTitle1.setText(title);
break;
case 1:
setCornerstoneAppControls(1);
csAppTitle2.setText(title);
break;
default:
setCornerstoneAppControls(-1);
break;
}
}
};
/**
* Author: Onskreen
* Date: 28/02/2011
*
* Registers the ICornerstoneManager interface with AMS, so that AMS can notify conerstone app
* whenever user changes the focus
*/
try {
ActivityManagerNative.getDefault().setCornerstoneManager(mBinder);
} catch (RemoteException e) {
e.printStackTrace();
}
}
Aggregations