Search in sources :

Example 46 with ServiceInfo

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

the class ZenModeHelper method getServiceInfo.

private ServiceInfo getServiceInfo(ComponentName owner) {
    Intent queryIntent = new Intent();
    queryIntent.setComponent(owner);
    List<ResolveInfo> installedServices = mPm.queryIntentServicesAsUser(queryIntent, PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, UserHandle.getCallingUserId());
    if (installedServices != null) {
        for (int i = 0, count = installedServices.size(); i < count; i++) {
            ResolveInfo resolveInfo = installedServices.get(i);
            ServiceInfo info = resolveInfo.serviceInfo;
            if (mServiceConfig.bindPermission.equals(info.permission)) {
                return info;
            }
        }
    }
    return null;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) Intent(android.content.Intent)

Example 47 with ServiceInfo

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

the class TvInputManagerService method buildTvInputListLocked.

private void buildTvInputListLocked(int userId, String[] updatedPackages) {
    UserState userState = getOrCreateUserStateLocked(userId);
    userState.packageSet.clear();
    if (DEBUG)
        Slog.d(TAG, "buildTvInputList");
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> services = pm.queryIntentServicesAsUser(new Intent(TvInputService.SERVICE_INTERFACE), PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, userId);
    List<TvInputInfo> inputList = new ArrayList<>();
    for (ResolveInfo ri : services) {
        ServiceInfo si = ri.serviceInfo;
        if (!android.Manifest.permission.BIND_TV_INPUT.equals(si.permission)) {
            Slog.w(TAG, "Skipping TV input " + si.name + ": it does not require the permission " + android.Manifest.permission.BIND_TV_INPUT);
            continue;
        }
        ComponentName component = new ComponentName(si.packageName, si.name);
        if (hasHardwarePermission(pm, component)) {
            ServiceState serviceState = userState.serviceStateMap.get(component);
            if (serviceState == null) {
                // New hardware input found. Create a new ServiceState and connect to the
                // service to populate the hardware list.
                serviceState = new ServiceState(component, userId);
                userState.serviceStateMap.put(component, serviceState);
                updateServiceConnectionLocked(component, userId);
            } else {
                inputList.addAll(serviceState.hardwareInputList);
            }
        } else {
            try {
                TvInputInfo info = new TvInputInfo.Builder(mContext, ri).build();
                inputList.add(info);
            } catch (Exception e) {
                Slog.e(TAG, "failed to load TV input " + si.name, e);
                continue;
            }
        }
        userState.packageSet.add(si.packageName);
    }
    Map<String, TvInputState> inputMap = new HashMap<>();
    for (TvInputInfo info : inputList) {
        if (DEBUG) {
            Slog.d(TAG, "add " + info.getId());
        }
        TvInputState inputState = userState.inputMap.get(info.getId());
        if (inputState == null) {
            inputState = new TvInputState();
        }
        inputState.info = info;
        inputMap.put(info.getId(), inputState);
    }
    for (String inputId : inputMap.keySet()) {
        if (!userState.inputMap.containsKey(inputId)) {
            notifyInputAddedLocked(userState, inputId);
        } else if (updatedPackages != null) {
            // Notify the package updates
            ComponentName component = inputMap.get(inputId).info.getComponent();
            for (String updatedPackage : updatedPackages) {
                if (component.getPackageName().equals(updatedPackage)) {
                    updateServiceConnectionLocked(component, userId);
                    notifyInputUpdatedLocked(userState, inputId);
                    break;
                }
            }
        }
    }
    for (String inputId : userState.inputMap.keySet()) {
        if (!inputMap.containsKey(inputId)) {
            TvInputInfo info = userState.inputMap.get(inputId).info;
            ServiceState serviceState = userState.serviceStateMap.get(info.getComponent());
            if (serviceState != null) {
                abortPendingCreateSessionRequestsLocked(serviceState, inputId, userId);
            }
            notifyInputRemovedLocked(userState, inputId);
        }
    }
    userState.inputMap.clear();
    userState.inputMap = inputMap;
}
Also used : HashMap(java.util.HashMap) TvInputInfo(android.media.tv.TvInputInfo) ArrayList(java.util.ArrayList) Intent(android.content.Intent) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) OperationApplicationException(android.content.OperationApplicationException) ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Example 48 with ServiceInfo

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

the class TvRemoteProviderWatcher method scanPackages.

private void scanPackages() {
    if (!mRunning) {
        return;
    }
    if (DEBUG)
        Log.d(TAG, "scanPackages()");
    // Add providers for all new services.
    // Reorder the list so that providers left at the end will be the ones to remove.
    int targetIndex = 0;
    Intent intent = new Intent(TvRemoteProviderProxy.SERVICE_INTERFACE);
    for (ResolveInfo resolveInfo : mPackageManager.queryIntentServicesAsUser(intent, 0, mUserId)) {
        ServiceInfo serviceInfo = resolveInfo.serviceInfo;
        if (serviceInfo != null && verifyServiceTrusted(serviceInfo)) {
            int sourceIndex = findProvider(serviceInfo.packageName, serviceInfo.name);
            if (sourceIndex < 0) {
                TvRemoteProviderProxy providerProxy = new TvRemoteProviderProxy(mContext, new ComponentName(serviceInfo.packageName, serviceInfo.name), mUserId, serviceInfo.applicationInfo.uid);
                providerProxy.start();
                mProviderProxies.add(targetIndex++, providerProxy);
                mProvider.addProvider(providerProxy);
            } else if (sourceIndex >= targetIndex) {
                TvRemoteProviderProxy provider = mProviderProxies.get(sourceIndex);
                // restart the provider if needed
                provider.start();
                provider.rebindIfDisconnected();
                Collections.swap(mProviderProxies, sourceIndex, targetIndex++);
            }
        }
    }
    if (DEBUG)
        Log.d(TAG, "scanPackages() targetIndex " + targetIndex);
    // Remove providers for missing services.
    if (targetIndex < mProviderProxies.size()) {
        for (int i = mProviderProxies.size() - 1; i >= targetIndex; i--) {
            TvRemoteProviderProxy providerProxy = mProviderProxies.get(i);
            mProvider.removeProvider(providerProxy);
            mProviderProxies.remove(providerProxy);
            providerProxy.stop();
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 49 with ServiceInfo

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

the class WallpaperManagerService method bindWallpaperComponentLocked.

boolean bindWallpaperComponentLocked(ComponentName componentName, boolean force, boolean fromUser, WallpaperData wallpaper, IRemoteCallback reply) {
    if (DEBUG)
        Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
    // Has the component changed?
    if (!force) {
        if (wallpaper.connection != null) {
            if (wallpaper.wallpaperComponent == null) {
                if (componentName == null) {
                    if (DEBUG)
                        Slog.v(TAG, "bindWallpaperComponentLocked: still using default");
                    // Still using default wallpaper.
                    return true;
                }
            } else if (wallpaper.wallpaperComponent.equals(componentName)) {
                // Changing to same wallpaper.
                if (DEBUG)
                    Slog.v(TAG, "same wallpaper");
                return true;
            }
        }
    }
    try {
        if (componentName == null) {
            componentName = WallpaperManager.getDefaultWallpaperComponent(mContext);
            if (componentName == null) {
                // Fall back to static image wallpaper
                componentName = mImageWallpaper;
                //return;
                if (DEBUG)
                    Slog.v(TAG, "Using image wallpaper");
            }
        }
        int serviceUserId = wallpaper.userId;
        ServiceInfo si = mIPackageManager.getServiceInfo(componentName, PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS, serviceUserId);
        if (si == null) {
            // The wallpaper component we're trying to use doesn't exist
            Slog.w(TAG, "Attempted wallpaper " + componentName + " is unavailable");
            return false;
        }
        if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) {
            String msg = "Selected service does not require " + android.Manifest.permission.BIND_WALLPAPER + ": " + componentName;
            if (fromUser) {
                throw new SecurityException(msg);
            }
            Slog.w(TAG, msg);
            return false;
        }
        WallpaperInfo wi = null;
        Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
        if (componentName != null && !componentName.equals(mImageWallpaper)) {
            // Make sure the selected service is actually a wallpaper service.
            List<ResolveInfo> ris = mIPackageManager.queryIntentServices(intent, intent.resolveTypeIfNeeded(mContext.getContentResolver()), PackageManager.GET_META_DATA, serviceUserId).getList();
            for (int i = 0; i < ris.size(); i++) {
                ServiceInfo rsi = ris.get(i).serviceInfo;
                if (rsi.name.equals(si.name) && rsi.packageName.equals(si.packageName)) {
                    try {
                        wi = new WallpaperInfo(mContext, ris.get(i));
                    } catch (XmlPullParserException e) {
                        if (fromUser) {
                            throw new IllegalArgumentException(e);
                        }
                        Slog.w(TAG, e);
                        return false;
                    } catch (IOException e) {
                        if (fromUser) {
                            throw new IllegalArgumentException(e);
                        }
                        Slog.w(TAG, e);
                        return false;
                    }
                    break;
                }
            }
            if (wi == null) {
                String msg = "Selected service is not a wallpaper: " + componentName;
                if (fromUser) {
                    throw new SecurityException(msg);
                }
                Slog.w(TAG, msg);
                return false;
            }
        }
        // Bind the service!
        if (DEBUG)
            Slog.v(TAG, "Binding to:" + componentName);
        WallpaperConnection newConn = new WallpaperConnection(wi, wallpaper);
        intent.setComponent(componentName);
        intent.putExtra(Intent.EXTRA_CLIENT_LABEL, com.android.internal.R.string.wallpaper_binding_label);
        intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivityAsUser(mContext, 0, Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER), mContext.getText(com.android.internal.R.string.chooser_wallpaper)), 0, null, new UserHandle(serviceUserId)));
        if (!mContext.bindServiceAsUser(intent, newConn, Context.BIND_AUTO_CREATE | Context.BIND_SHOWING_UI | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, new UserHandle(serviceUserId))) {
            String msg = "Unable to bind service: " + componentName;
            if (fromUser) {
                throw new IllegalArgumentException(msg);
            }
            Slog.w(TAG, msg);
            return false;
        }
        if (wallpaper.userId == mCurrentUserId && mLastWallpaper != null) {
            detachWallpaperLocked(mLastWallpaper);
        }
        wallpaper.wallpaperComponent = componentName;
        wallpaper.connection = newConn;
        newConn.mReply = reply;
        try {
            if (wallpaper.userId == mCurrentUserId) {
                if (DEBUG)
                    Slog.v(TAG, "Adding window token: " + newConn.mToken);
                mIWindowManager.addWindowToken(newConn.mToken, WindowManager.LayoutParams.TYPE_WALLPAPER);
                mLastWallpaper = wallpaper;
            }
        } catch (RemoteException e) {
        }
    } catch (RemoteException e) {
        String msg = "Remote exception for " + componentName + "\n" + e;
        if (fromUser) {
            throw new IllegalArgumentException(msg);
        }
        Slog.w(TAG, msg);
        return false;
    }
    return true;
}
Also used : IWallpaperConnection(android.service.wallpaper.IWallpaperConnection) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IOException(java.io.IOException) Point(android.graphics.Point) ServiceInfo(android.content.pm.ServiceInfo) ResolveInfo(android.content.pm.ResolveInfo) UserHandle(android.os.UserHandle) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) RemoteException(android.os.RemoteException) WallpaperInfo(android.app.WallpaperInfo)

Example 50 with ServiceInfo

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

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)

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