Search in sources :

Example 71 with ComponentName

use of android.content.ComponentName in project platform_frameworks_base by android.

the class RemoteDisplayProviderWatcher method scanPackages.

private void scanPackages() {
    if (!mRunning) {
        return;
    }
    // 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(RemoteDisplayState.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) {
                RemoteDisplayProviderProxy provider = new RemoteDisplayProviderProxy(mContext, new ComponentName(serviceInfo.packageName, serviceInfo.name), mUserId);
                provider.start();
                mProviders.add(targetIndex++, provider);
                mCallback.addProvider(provider);
            } else if (sourceIndex >= targetIndex) {
                RemoteDisplayProviderProxy provider = mProviders.get(sourceIndex);
                // restart the provider if needed
                provider.start();
                provider.rebindIfDisconnected();
                Collections.swap(mProviders, sourceIndex, targetIndex++);
            }
        }
    }
    // Remove providers for missing services.
    if (targetIndex < mProviders.size()) {
        for (int i = mProviders.size() - 1; i >= targetIndex; i--) {
            RemoteDisplayProviderProxy provider = mProviders.get(i);
            mCallback.removeProvider(provider);
            mProviders.remove(provider);
            provider.stop();
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 72 with ComponentName

use of android.content.ComponentName in project platform_frameworks_base by android.

the class Settings method applyDefaultPreferredActivityLPw.

private void applyDefaultPreferredActivityLPw(PackageManagerService service, Intent intent, int flags, ComponentName cn, String scheme, PatternMatcher ssp, IntentFilter.AuthorityEntry auth, PatternMatcher path, int userId) {
    flags = service.updateFlagsForResolve(flags, userId, intent);
    List<ResolveInfo> ri = service.mActivities.queryIntent(intent, intent.getType(), flags, 0);
    if (PackageManagerService.DEBUG_PREFERRED)
        Log.d(TAG, "Queried " + intent + " results: " + ri);
    int systemMatch = 0;
    int thirdPartyMatch = 0;
    if (ri != null && ri.size() > 1) {
        boolean haveAct = false;
        ComponentName haveNonSys = null;
        ComponentName[] set = new ComponentName[ri.size()];
        for (int i = 0; i < ri.size(); i++) {
            ActivityInfo ai = ri.get(i).activityInfo;
            set[i] = new ComponentName(ai.packageName, ai.name);
            if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                if (ri.get(i).match >= thirdPartyMatch) {
                    // want to set a preferred app for this intent.
                    if (PackageManagerService.DEBUG_PREFERRED)
                        Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": non-system!");
                    haveNonSys = set[i];
                    break;
                }
            } else if (cn.getPackageName().equals(ai.packageName) && cn.getClassName().equals(ai.name)) {
                if (PackageManagerService.DEBUG_PREFERRED)
                    Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": default!");
                haveAct = true;
                systemMatch = ri.get(i).match;
            } else {
                if (PackageManagerService.DEBUG_PREFERRED)
                    Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": skipped");
            }
        }
        if (haveNonSys != null && thirdPartyMatch < systemMatch) {
            // If we have a matching third party app, but its match is not as
            // good as the built-in system app, then we don't want to actually
            // consider it a match because presumably the built-in app is still
            // the thing we want users to see by default.
            haveNonSys = null;
        }
        if (haveAct && haveNonSys == null) {
            IntentFilter filter = new IntentFilter();
            if (intent.getAction() != null) {
                filter.addAction(intent.getAction());
            }
            if (intent.getCategories() != null) {
                for (String cat : intent.getCategories()) {
                    filter.addCategory(cat);
                }
            }
            if ((flags & MATCH_DEFAULT_ONLY) != 0) {
                filter.addCategory(Intent.CATEGORY_DEFAULT);
            }
            if (scheme != null) {
                filter.addDataScheme(scheme);
            }
            if (ssp != null) {
                filter.addDataSchemeSpecificPart(ssp.getPath(), ssp.getType());
            }
            if (auth != null) {
                filter.addDataAuthority(auth);
            }
            if (path != null) {
                filter.addDataPath(path);
            }
            if (intent.getType() != null) {
                try {
                    filter.addDataType(intent.getType());
                } catch (IntentFilter.MalformedMimeTypeException ex) {
                    Slog.w(TAG, "Malformed mimetype " + intent.getType() + " for " + cn);
                }
            }
            PreferredActivity pa = new PreferredActivity(filter, systemMatch, set, cn, true);
            editPreferredActivitiesLPw(userId).addFilter(pa);
        } else if (haveNonSys == null) {
            StringBuilder sb = new StringBuilder();
            sb.append("No component ");
            sb.append(cn.flattenToShortString());
            sb.append(" found setting preferred ");
            sb.append(intent);
            sb.append("; possible matches are ");
            for (int i = 0; i < set.length; i++) {
                if (i > 0)
                    sb.append(", ");
                sb.append(set[i].flattenToShortString());
            }
            Slog.w(TAG, sb.toString());
        } else {
            Slog.i(TAG, "Not setting preferred " + intent + "; found third party match " + haveNonSys.flattenToShortString());
        }
    } else {
        Slog.w(TAG, "No potential matches found for " + intent + " while setting preferred " + cn.flattenToShortString());
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) IntentFilter(android.content.IntentFilter) ComponentName(android.content.ComponentName)

Example 73 with ComponentName

use of android.content.ComponentName in project platform_frameworks_base by android.

the class ShortcutPackage method adjustRanks.

/**
     * Re-calculate the ranks for all shortcuts.
     */
public void adjustRanks() {
    final ShortcutService s = mShortcutUser.mService;
    final long now = s.injectCurrentTimeMillis();
    // First, clear ranks for floating shortcuts.
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        if (si.isFloating()) {
            if (si.getRank() != 0) {
                si.setTimestamp(now);
                si.setRank(0);
            }
        }
    }
    // Then adjust ranks.  Ranks are unique for each activity, so we first need to sort
    // shortcuts to each activity.
    // Then sort the shortcuts within each activity with mShortcutRankComparator, and
    // assign ranks from 0.
    final ArrayMap<ComponentName, ArrayList<ShortcutInfo>> all = sortShortcutsToActivities();
    for (int outer = all.size() - 1; outer >= 0; outer--) {
        // For each activity.
        final ArrayList<ShortcutInfo> list = all.valueAt(outer);
        // Sort by ranks and other signals.
        Collections.sort(list, mShortcutRankComparator);
        int rank = 0;
        final int size = list.size();
        for (int i = 0; i < size; i++) {
            final ShortcutInfo si = list.get(i);
            if (si.isManifestShortcut()) {
                // Don't adjust ranks for manifest shortcuts.
                continue;
            }
            // At this point, it must be dynamic.
            if (!si.isDynamic()) {
                s.wtf("Non-dynamic shortcut found.");
                continue;
            }
            final int thisRank = rank++;
            if (si.getRank() != thisRank) {
                si.setTimestamp(now);
                si.setRank(thisRank);
            }
        }
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName)

Example 74 with ComponentName

use of android.content.ComponentName in project platform_frameworks_base by android.

the class ShortcutPackage method enforceShortcutCountsBeforeOperation.

/**
     * Called by
     * {@link android.content.pm.ShortcutManager#setDynamicShortcuts},
     * {@link android.content.pm.ShortcutManager#addDynamicShortcuts}, and
     * {@link android.content.pm.ShortcutManager#updateShortcuts} before actually performing
     * the operation to make sure the operation wouldn't result in the target activities having
     * more than the allowed number of dynamic/manifest shortcuts.
     *
     * @param newList shortcut list passed to set, add or updateShortcuts().
     * @param operation add, set or update.
     * @throws IllegalArgumentException if the operation would result in going over the max
     *                                  shortcut count for any activity.
     */
public void enforceShortcutCountsBeforeOperation(List<ShortcutInfo> newList, @ShortcutOperation int operation) {
    final ShortcutService service = mShortcutUser.mService;
    // Current # of dynamic / manifest shortcuts for each activity.
    // (If it's for update, then don't count dynamic shortcuts, since they'll be replaced
    // anyway.)
    final ArrayMap<ComponentName, Integer> counts = new ArrayMap<>(4);
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo shortcut = mShortcuts.valueAt(i);
        if (shortcut.isManifestShortcut()) {
            incrementCountForActivity(counts, shortcut.getActivity(), 1);
        } else if (shortcut.isDynamic() && (operation != ShortcutService.OPERATION_SET)) {
            incrementCountForActivity(counts, shortcut.getActivity(), 1);
        }
    }
    for (int i = newList.size() - 1; i >= 0; i--) {
        final ShortcutInfo newShortcut = newList.get(i);
        final ComponentName newActivity = newShortcut.getActivity();
        if (newActivity == null) {
            if (operation != ShortcutService.OPERATION_UPDATE) {
                service.wtf("Activity must not be null at this point");
                // Just ignore this invalid case.
                continue;
            }
            // Activity can be null for update.
            continue;
        }
        final ShortcutInfo original = mShortcuts.get(newShortcut.getId());
        if (original == null) {
            if (operation == ShortcutService.OPERATION_UPDATE) {
                // When updating, ignore if there's no target.
                continue;
            }
            // Add() or set(), and there's no existing shortcut with the same ID.  We're
            // simply publishing (as opposed to updating) this shortcut, so just +1.
            incrementCountForActivity(counts, newActivity, 1);
            continue;
        }
        if (original.isFloating() && (operation == ShortcutService.OPERATION_UPDATE)) {
            // Updating floating shortcuts doesn't affect the count, so ignore.
            continue;
        }
        // dynamic shortcuts in the first loop.
        if (operation != ShortcutService.OPERATION_SET) {
            final ComponentName oldActivity = original.getActivity();
            if (!original.isFloating()) {
                incrementCountForActivity(counts, oldActivity, -1);
            }
        }
        incrementCountForActivity(counts, newActivity, 1);
    }
    // Then make sure none of the activities have more than the max number of shortcuts.
    for (int i = counts.size() - 1; i >= 0; i--) {
        service.enforceMaxActivityShortcuts(counts.valueAt(i));
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ArrayMap(android.util.ArrayMap) ComponentName(android.content.ComponentName)

Example 75 with ComponentName

use of android.content.ComponentName in project platform_frameworks_base by android.

the class ShortcutService method hasShortcutHostPermissionInner.

// This method is extracted so we can directly call this method from unit tests,
// even when hasShortcutPermission() is overridden.
@VisibleForTesting
boolean hasShortcutHostPermissionInner(@NonNull String callingPackage, int userId) {
    synchronized (mLock) {
        throwIfUserLockedL(userId);
        final ShortcutUser user = getUserShortcutsLocked(userId);
        // Always trust the in-memory cache.
        final ComponentName cached = user.getCachedLauncher();
        if (cached != null) {
            if (cached.getPackageName().equals(callingPackage)) {
                return true;
            }
        }
        // If the cached one doesn't match, then go ahead
        final List<ResolveInfo> allHomeCandidates = new ArrayList<>();
        // Default launcher from package manager.
        final long startGetHomeActivitiesAsUser = injectElapsedRealtime();
        final ComponentName defaultLauncher = mPackageManagerInternal.getHomeActivitiesAsUser(allHomeCandidates, userId);
        logDurationStat(Stats.GET_DEFAULT_HOME, startGetHomeActivitiesAsUser);
        ComponentName detected;
        if (defaultLauncher != null) {
            detected = defaultLauncher;
            if (DEBUG) {
                Slog.v(TAG, "Default launcher from PM: " + detected);
            }
        } else {
            detected = user.getLastKnownLauncher();
            if (detected != null) {
                if (injectIsActivityEnabledAndExported(detected, userId)) {
                    if (DEBUG) {
                        Slog.v(TAG, "Cached launcher: " + detected);
                    }
                } else {
                    Slog.w(TAG, "Cached launcher " + detected + " no longer exists");
                    detected = null;
                    user.clearLauncher();
                }
            }
        }
        if (detected == null) {
            // If we reach here, that means it's the first check since the user was created,
            // and there's already multiple launchers and there's no default set.
            // Find the system one with the highest priority.
            // (We need to check the priority too because of FallbackHome in Settings.)
            // If there's no system launcher yet, then no one can access shortcuts, until
            // the user explicitly
            final int size = allHomeCandidates.size();
            int lastPriority = Integer.MIN_VALUE;
            for (int i = 0; i < size; i++) {
                final ResolveInfo ri = allHomeCandidates.get(i);
                if (!ri.activityInfo.applicationInfo.isSystemApp()) {
                    continue;
                }
                if (DEBUG) {
                    Slog.d(TAG, String.format("hasShortcutPermissionInner: pkg=%s prio=%d", ri.activityInfo.getComponentName(), ri.priority));
                }
                if (ri.priority < lastPriority) {
                    continue;
                }
                detected = ri.activityInfo.getComponentName();
                lastPriority = ri.priority;
            }
        }
        // Update the cache.
        user.setLauncher(detected);
        if (detected != null) {
            if (DEBUG) {
                Slog.v(TAG, "Detected launcher: " + detected);
            }
            return detected.getPackageName().equals(callingPackage);
        } else {
            // Default launcher not found.
            return false;
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

ComponentName (android.content.ComponentName)2548 Intent (android.content.Intent)959 ResolveInfo (android.content.pm.ResolveInfo)375 RemoteException (android.os.RemoteException)317 PackageManager (android.content.pm.PackageManager)269 PendingIntent (android.app.PendingIntent)252 ActivityInfo (android.content.pm.ActivityInfo)243 ArrayList (java.util.ArrayList)242 ShortcutInfo (android.content.pm.ShortcutInfo)152 Point (android.graphics.Point)145 Bundle (android.os.Bundle)139 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)132 IBinder (android.os.IBinder)128 IOException (java.io.IOException)125 ServiceConnection (android.content.ServiceConnection)96 ServiceInfo (android.content.pm.ServiceInfo)96 UserHandle (android.os.UserHandle)86 ArraySet (android.util.ArraySet)73 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Uri (android.net.Uri)68