Search in sources :

Example 71 with ServiceInfo

use of android.content.pm.ServiceInfo in project android_frameworks_base by DirtyUnicorns.

the class DevicePolicyManagerService method getPermittedInputMethodsForCurrentUser.

@Override
public List getPermittedInputMethodsForCurrentUser() {
    UserInfo currentUser;
    try {
        currentUser = mInjector.getIActivityManager().getCurrentUser();
    } catch (RemoteException e) {
        Slog.e(LOG_TAG, "Failed to make remote calls to get current user", e);
        // Activity managed is dead, just allow all IMEs
        return null;
    }
    int userId = currentUser.id;
    synchronized (this) {
        List<String> result = null;
        // If we have multiple profiles we return the intersection of the
        // permitted lists. This can happen in cases where we have a device
        // and profile owner.
        int[] profileIds = mUserManager.getProfileIdsWithDisabled(userId);
        for (int profileId : profileIds) {
            // Just loop though all admins, only device or profiles
            // owners can have permitted lists set.
            DevicePolicyData policy = getUserDataUnchecked(profileId);
            final int N = policy.mAdminList.size();
            for (int j = 0; j < N; j++) {
                ActiveAdmin admin = policy.mAdminList.get(j);
                List<String> fromAdmin = admin.permittedInputMethods;
                if (fromAdmin != null) {
                    if (result == null) {
                        result = new ArrayList<String>(fromAdmin);
                    } else {
                        result.retainAll(fromAdmin);
                    }
                }
            }
        }
        // If we have a permitted list add all system input methods.
        if (result != null) {
            InputMethodManager inputMethodManager = mContext.getSystemService(InputMethodManager.class);
            List<InputMethodInfo> imes = inputMethodManager.getInputMethodList();
            long id = mInjector.binderClearCallingIdentity();
            try {
                if (imes != null) {
                    for (InputMethodInfo ime : imes) {
                        ServiceInfo serviceInfo = ime.getServiceInfo();
                        ApplicationInfo applicationInfo = serviceInfo.applicationInfo;
                        if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                            result.add(serviceInfo.packageName);
                        }
                    }
                }
            } finally {
                mInjector.binderRestoreCallingIdentity(id);
            }
        }
        return result;
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) UserInfo(android.content.pm.UserInfo) InputMethodManager(android.view.inputmethod.InputMethodManager) ParcelableString(com.android.internal.util.ParcelableString) InputMethodInfo(android.view.inputmethod.InputMethodInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) RemoteException(android.os.RemoteException)

Example 72 with ServiceInfo

use of android.content.pm.ServiceInfo in project android_frameworks_base by DirtyUnicorns.

the class DevicePolicyManagerService method getPermittedAccessibilityServicesForUser.

@Override
public List getPermittedAccessibilityServicesForUser(int userId) {
    if (!mHasFeature) {
        return null;
    }
    synchronized (this) {
        List<String> result = null;
        // If we have multiple profiles we return the intersection of the
        // permitted lists. This can happen in cases where we have a device
        // and profile owner.
        int[] profileIds = mUserManager.getProfileIdsWithDisabled(userId);
        for (int profileId : profileIds) {
            // Just loop though all admins, only device or profiles
            // owners can have permitted lists set.
            DevicePolicyData policy = getUserDataUnchecked(profileId);
            final int N = policy.mAdminList.size();
            for (int j = 0; j < N; j++) {
                ActiveAdmin admin = policy.mAdminList.get(j);
                List<String> fromAdmin = admin.permittedAccessiblityServices;
                if (fromAdmin != null) {
                    if (result == null) {
                        result = new ArrayList<>(fromAdmin);
                    } else {
                        result.retainAll(fromAdmin);
                    }
                }
            }
        }
        // If we have a permitted list add all system accessibility services.
        if (result != null) {
            long id = mInjector.binderClearCallingIdentity();
            try {
                UserInfo user = getUserInfo(userId);
                if (user.isManagedProfile()) {
                    userId = user.profileGroupId;
                }
                AccessibilityManager accessibilityManager = getAccessibilityManagerForUser(userId);
                List<AccessibilityServiceInfo> installedServices = accessibilityManager.getInstalledAccessibilityServiceList();
                if (installedServices != null) {
                    for (AccessibilityServiceInfo service : installedServices) {
                        ServiceInfo serviceInfo = service.getResolveInfo().serviceInfo;
                        ApplicationInfo applicationInfo = serviceInfo.applicationInfo;
                        if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                            result.add(serviceInfo.packageName);
                        }
                    }
                }
            } finally {
                mInjector.binderRestoreCallingIdentity(id);
            }
        }
        return result;
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) UserInfo(android.content.pm.UserInfo) ParcelableString(com.android.internal.util.ParcelableString) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityManager(android.view.accessibility.AccessibilityManager) IAccessibilityManager(android.view.accessibility.IAccessibilityManager)

Example 73 with ServiceInfo

use of android.content.pm.ServiceInfo in project android_frameworks_base by DirtyUnicorns.

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 74 with ServiceInfo

use of android.content.pm.ServiceInfo in project android_frameworks_base by DirtyUnicorns.

the class CustomTile method setTileIcon.

private void setTileIcon() {
    try {
        PackageManager pm = mContext.getPackageManager();
        int flags = PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE;
        if (isSystemApp(pm)) {
            flags |= PackageManager.MATCH_DISABLED_COMPONENTS;
        }
        ServiceInfo info = pm.getServiceInfo(mComponent, flags);
        int icon = info.icon != 0 ? info.icon : info.applicationInfo.icon;
        // Update the icon if its not set or is the default icon.
        boolean updateIcon = mTile.getIcon() == null || iconEquals(mTile.getIcon(), mDefaultIcon);
        mDefaultIcon = icon != 0 ? android.graphics.drawable.Icon.createWithResource(mComponent.getPackageName(), icon) : null;
        if (updateIcon) {
            mTile.setIcon(mDefaultIcon);
        }
        // Update the label if there is no label.
        if (mTile.getLabel() == null) {
            mTile.setLabel(info.loadLabel(pm));
        }
    } catch (Exception e) {
        mDefaultIcon = null;
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException)

Example 75 with ServiceInfo

use of android.content.pm.ServiceInfo in project android_frameworks_base by DirtyUnicorns.

the class AccessibilityManagerService method readInstalledAccessibilityServiceLocked.

private boolean readInstalledAccessibilityServiceLocked(UserState userState) {
    mTempAccessibilityServiceInfoList.clear();
    List<ResolveInfo> installedServices = mPackageManager.queryIntentServicesAsUser(new Intent(AccessibilityService.SERVICE_INTERFACE), PackageManager.GET_SERVICES | PackageManager.GET_META_DATA | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, mCurrentUserId);
    for (int i = 0, count = installedServices.size(); i < count; i++) {
        ResolveInfo resolveInfo = installedServices.get(i);
        ServiceInfo serviceInfo = resolveInfo.serviceInfo;
        if (!android.Manifest.permission.BIND_ACCESSIBILITY_SERVICE.equals(serviceInfo.permission)) {
            Slog.w(LOG_TAG, "Skipping accessibilty service " + new ComponentName(serviceInfo.packageName, serviceInfo.name).flattenToShortString() + ": it does not require the permission " + android.Manifest.permission.BIND_ACCESSIBILITY_SERVICE);
            continue;
        }
        AccessibilityServiceInfo accessibilityServiceInfo;
        try {
            accessibilityServiceInfo = new AccessibilityServiceInfo(resolveInfo, mContext);
            mTempAccessibilityServiceInfoList.add(accessibilityServiceInfo);
        } catch (XmlPullParserException | IOException xppe) {
            Slog.e(LOG_TAG, "Error while initializing AccessibilityServiceInfo", xppe);
        }
    }
    if (!mTempAccessibilityServiceInfoList.equals(userState.mInstalledServices)) {
        userState.mInstalledServices.clear();
        userState.mInstalledServices.addAll(mTempAccessibilityServiceInfoList);
        mTempAccessibilityServiceInfoList.clear();
        return true;
    }
    mTempAccessibilityServiceInfoList.clear();
    return false;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) Point(android.graphics.Point)

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