use of android.content.pm.ServiceInfo in project android_frameworks_base by ResurrectionRemix.
the class NetworkScorerAppManagerTest method buildResolveInfo.
private ResolveInfoHolder buildResolveInfo(String packageName, int packageUid, boolean hasReceiverPermission, boolean hasScorePermission, boolean hasConfigActivity, boolean hasServiceInfo) throws Exception {
Mockito.when(mMockPm.checkPermission(permission.SCORE_NETWORKS, packageName)).thenReturn(hasScorePermission ? PackageManager.PERMISSION_GRANTED : PackageManager.PERMISSION_DENIED);
ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.activityInfo = new ActivityInfo();
resolveInfo.activityInfo.packageName = packageName;
resolveInfo.activityInfo.applicationInfo = new ApplicationInfo();
resolveInfo.activityInfo.applicationInfo.uid = packageUid;
if (hasReceiverPermission) {
resolveInfo.activityInfo.permission = permission.BROADCAST_NETWORK_PRIVILEGED;
}
ResolveInfo configActivityInfo = null;
if (hasConfigActivity) {
configActivityInfo = new ResolveInfo();
configActivityInfo.activityInfo = new ActivityInfo();
configActivityInfo.activityInfo.name = ".ConfigActivity";
}
ResolveInfo serviceInfo = null;
if (hasServiceInfo) {
serviceInfo = new ResolveInfo();
serviceInfo.serviceInfo = new ServiceInfo();
serviceInfo.serviceInfo.name = ".ScoringService";
}
return new ResolveInfoHolder(resolveInfo, configActivityInfo, serviceInfo);
}
use of android.content.pm.ServiceInfo 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.pm.ServiceInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AccessibilitySettings method updateServicesPreferences.
private void updateServicesPreferences() {
// Since services category is auto generated we have to do a pass
// to generate it since services can come and go and then based on
// the global accessibility state to decided whether it is enabled.
// Generate.
mServicesCategory.removeAll();
AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity());
List<AccessibilityServiceInfo> installedServices = accessibilityManager.getInstalledAccessibilityServiceList();
Set<ComponentName> enabledServices = AccessibilityUtils.getEnabledServicesFromSettings(getActivity());
List<String> permittedServices = mDpm.getPermittedAccessibilityServices(UserHandle.myUserId());
final boolean accessibilityEnabled = Settings.Secure.getInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
for (int i = 0, count = installedServices.size(); i < count; ++i) {
AccessibilityServiceInfo info = installedServices.get(i);
RestrictedPreference preference = new RestrictedPreference(getActivity());
String title = info.getResolveInfo().loadLabel(getPackageManager()).toString();
ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);
preference.setKey(componentName.flattenToString());
preference.setTitle(title);
final boolean serviceEnabled = accessibilityEnabled && enabledServices.contains(componentName);
String serviceEnabledString;
if (serviceEnabled) {
serviceEnabledString = getString(R.string.accessibility_feature_state_on);
} else {
serviceEnabledString = getString(R.string.accessibility_feature_state_off);
}
// Disable all accessibility services that are not permitted.
String packageName = serviceInfo.packageName;
boolean serviceAllowed = permittedServices == null || permittedServices.contains(packageName);
if (!serviceAllowed && !serviceEnabled) {
EnforcedAdmin admin = RestrictedLockUtils.checkIfAccessibilityServiceDisallowed(getActivity(), serviceInfo.packageName, UserHandle.myUserId());
if (admin != null) {
preference.setDisabledByAdmin(admin);
} else {
preference.setEnabled(false);
}
} else {
preference.setEnabled(true);
}
preference.setSummary(serviceEnabledString);
preference.setOrder(i);
preference.setFragment(ToggleAccessibilityServicePreferenceFragment.class.getName());
preference.setPersistent(true);
Bundle extras = preference.getExtras();
extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey());
extras.putBoolean(EXTRA_CHECKED, serviceEnabled);
extras.putString(EXTRA_TITLE, title);
String description = info.loadDescription(getPackageManager());
if (TextUtils.isEmpty(description)) {
description = getString(R.string.accessibility_service_default_description);
}
extras.putString(EXTRA_SUMMARY, description);
String settingsClassName = info.getSettingsActivityName();
if (!TextUtils.isEmpty(settingsClassName)) {
extras.putString(EXTRA_SETTINGS_TITLE, getString(R.string.accessibility_menu_item_settings));
extras.putString(EXTRA_SETTINGS_COMPONENT_NAME, new ComponentName(info.getResolveInfo().serviceInfo.packageName, settingsClassName).flattenToString());
}
extras.putParcelable(EXTRA_COMPONENT_NAME, componentName);
mServicesCategory.addPreference(preference);
}
if (mServicesCategory.getPreferenceCount() == 0) {
if (mNoServicesMessagePreference == null) {
mNoServicesMessagePreference = new Preference(getPrefContext());
mNoServicesMessagePreference.setPersistent(false);
mNoServicesMessagePreference.setLayoutResource(R.layout.text_description_preference);
mNoServicesMessagePreference.setSelectable(false);
mNoServicesMessagePreference.setSummary(getString(R.string.accessibility_no_services_installed));
}
mServicesCategory.addPreference(mNoServicesMessagePreference);
}
}
use of android.content.pm.ServiceInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AccessibilitySettingsForSetupWizard method updateScreenReaderPreference.
private void updateScreenReaderPreference() {
// Find a screen reader.
AccessibilityServiceInfo info = findFirstServiceWithSpokenFeedback();
if (info == null) {
getPreferenceScreen().removePreference(mScreenReaderPreference);
return;
} else {
mScreenReaderPreference.setEnabled(true);
ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
String title = info.getResolveInfo().loadLabel(getPackageManager()).toString();
mScreenReaderPreference.setTitle(title);
ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);
mScreenReaderPreference.setKey(componentName.flattenToString());
// Update the extras.
Bundle extras = mScreenReaderPreference.getExtras();
extras.putParcelable(AccessibilitySettings.EXTRA_COMPONENT_NAME, componentName);
extras.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY, mScreenReaderPreference.getKey());
extras.putString(AccessibilitySettings.EXTRA_TITLE, title);
String description = info.loadDescription(getPackageManager());
if (TextUtils.isEmpty(description)) {
description = getString(R.string.accessibility_service_default_description);
}
extras.putString(AccessibilitySettings.EXTRA_SUMMARY, description);
}
}
use of android.content.pm.ServiceInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RunningServiceDetails method addProcessDetailsView.
void addProcessDetailsView(RunningState.ProcessItem pi, boolean isMain) {
addProcessesHeader();
ActiveDetail detail = new ActiveDetail();
View root = mInflater.inflate(R.layout.running_service_details_process, mAllDetails, false);
mAllDetails.addView(root);
detail.mRootView = root;
detail.mViewHolder = new RunningProcessesView.ViewHolder(root);
detail.mActiveItem = detail.mViewHolder.bind(mState, pi, mBuilder);
TextView description = (TextView) root.findViewById(R.id.comp_description);
if (pi.mUserId != UserHandle.myUserId()) {
// Processes for another user are all shown batched together; there is
// no reason to have a description.
description.setVisibility(View.GONE);
} else if (isMain) {
description.setText(R.string.main_running_process_description);
} else {
int textid = 0;
CharSequence label = null;
ActivityManager.RunningAppProcessInfo rpi = pi.mRunningProcessInfo;
final ComponentName comp = rpi.importanceReasonComponent;
// + " pid=" + rpi.importanceReasonPid + " comp=" + comp);
switch(rpi.importanceReasonCode) {
case ActivityManager.RunningAppProcessInfo.REASON_PROVIDER_IN_USE:
textid = R.string.process_provider_in_use_description;
if (rpi.importanceReasonComponent != null) {
try {
ProviderInfo prov = getActivity().getPackageManager().getProviderInfo(rpi.importanceReasonComponent, 0);
label = RunningState.makeLabel(getActivity().getPackageManager(), prov.name, prov);
} catch (NameNotFoundException e) {
}
}
break;
case ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_USE:
textid = R.string.process_service_in_use_description;
if (rpi.importanceReasonComponent != null) {
try {
ServiceInfo serv = getActivity().getPackageManager().getServiceInfo(rpi.importanceReasonComponent, 0);
label = RunningState.makeLabel(getActivity().getPackageManager(), serv.name, serv);
} catch (NameNotFoundException e) {
}
}
break;
}
if (textid != 0 && label != null) {
description.setText(getActivity().getString(textid, label));
}
}
mActiveDetails.add(detail);
}
Aggregations