Search in sources :

Example 51 with ServiceInfo

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);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) ActivityInfo(android.content.pm.ActivityInfo) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 52 with 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();
        }
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) XmlResourceParser(android.content.res.XmlResourceParser) PackageManager(android.content.pm.PackageManager) AttributeSet(android.util.AttributeSet) ApplicationInfo(android.content.pm.ApplicationInfo) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources)

Example 53 with ServiceInfo

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);
    }
}
Also used : Bundle(android.os.Bundle) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityManager(android.view.accessibility.AccessibilityManager) RestrictedPreference(com.android.settingslib.RestrictedPreference) ListPreference(android.support.v7.preference.ListPreference) RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) ComponentName(android.content.ComponentName)

Example 54 with ServiceInfo

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);
    }
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) Bundle(android.os.Bundle) ComponentName(android.content.ComponentName)

Example 55 with ServiceInfo

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);
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) ProviderInfo(android.content.pm.ProviderInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) TextView(android.widget.TextView) ComponentName(android.content.ComponentName) View(android.view.View) TextView(android.widget.TextView)

Aggregations

ServiceInfo (android.content.pm.ServiceInfo)238 ResolveInfo (android.content.pm.ResolveInfo)120 Intent (android.content.Intent)99 ComponentName (android.content.ComponentName)96 PackageManager (android.content.pm.PackageManager)62 RemoteException (android.os.RemoteException)48 PendingIntent (android.app.PendingIntent)37 ApplicationInfo (android.content.pm.ApplicationInfo)35 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)32 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)29 IOException (java.io.IOException)28 ArrayList (java.util.ArrayList)27 InputMethodInfo (android.view.inputmethod.InputMethodInfo)21 PackageInfo (android.content.pm.PackageInfo)18 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)16 Service (android.app.Service)13 Point (android.graphics.Point)11 SpellCheckerInfo (android.view.textservice.SpellCheckerInfo)11 ArraySet (android.util.ArraySet)10 ActivityInfo (android.content.pm.ActivityInfo)9