Search in sources :

Example 31 with ParceledListSlice

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

the class AppWidgetServiceImpl method getInstalledProvidersForProfile.

@Override
public ParceledListSlice<AppWidgetProviderInfo> getInstalledProvidersForProfile(int categoryFilter, int profileId) {
    final int userId = UserHandle.getCallingUserId();
    if (DEBUG) {
        Slog.i(TAG, "getInstalledProvidersForProfiles() " + userId);
    }
    // Ensure the profile is in the group and enabled.
    if (!mSecurityPolicy.isEnabledGroupProfile(profileId)) {
        return null;
    }
    synchronized (mLock) {
        ensureGroupStateLoadedLocked(userId);
        ArrayList<AppWidgetProviderInfo> result = new ArrayList<AppWidgetProviderInfo>();
        final int providerCount = mProviders.size();
        for (int i = 0; i < providerCount; i++) {
            Provider provider = mProviders.get(i);
            AppWidgetProviderInfo info = provider.info;
            // Ignore an invalid provider or one not matching the filter.
            if (provider.zombie || (info.widgetCategory & categoryFilter) == 0) {
                continue;
            }
            // Add providers only for the requested profile that are white-listed.
            final int providerProfileId = info.getProfile().getIdentifier();
            if (providerProfileId == profileId && mSecurityPolicy.isProviderInCallerOrInProfileAndWhitelListed(provider.id.componentName.getPackageName(), providerProfileId)) {
                result.add(cloneIfLocalBinder(info));
            }
        }
        return new ParceledListSlice<AppWidgetProviderInfo>(result);
    }
}
Also used : ArrayList(java.util.ArrayList) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Point(android.graphics.Point) ParceledListSlice(android.content.pm.ParceledListSlice) WidgetBackupProvider(com.android.server.WidgetBackupProvider)

Example 32 with ParceledListSlice

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

the class AppWidgetServiceImpl method startListening.

@Override
public ParceledListSlice<PendingHostUpdate> startListening(IAppWidgetHost callbacks, String callingPackage, int hostId, int[] appWidgetIds) {
    final int userId = UserHandle.getCallingUserId();
    if (DEBUG) {
        Slog.i(TAG, "startListening() " + userId);
    }
    // Make sure the package runs under the caller uid.
    mSecurityPolicy.enforceCallFromPackage(callingPackage);
    synchronized (mLock) {
        ensureGroupStateLoadedLocked(userId);
        // NOTE: The lookup is enforcing security across users by making
        // sure the caller can only access hosts it owns.
        HostId id = new HostId(Binder.getCallingUid(), hostId, callingPackage);
        Host host = lookupOrAddHostLocked(id);
        host.callbacks = callbacks;
        int N = appWidgetIds.length;
        ArrayList<PendingHostUpdate> outUpdates = new ArrayList<>(N);
        LongSparseArray<PendingHostUpdate> updatesMap = new LongSparseArray<>();
        for (int i = 0; i < N; i++) {
            if (host.getPendingUpdatesForId(appWidgetIds[i], updatesMap)) {
                // We key the updates based on request id, so that the values are sorted in the
                // order they were received.
                int M = updatesMap.size();
                for (int j = 0; j < M; j++) {
                    outUpdates.add(updatesMap.valueAt(j));
                }
            }
        }
        return new ParceledListSlice<>(outUpdates);
    }
}
Also used : LongSparseArray(android.util.LongSparseArray) ArrayList(java.util.ArrayList) IAppWidgetHost(com.android.internal.appwidget.IAppWidgetHost) Point(android.graphics.Point) PendingHostUpdate(android.appwidget.PendingHostUpdate) ParceledListSlice(android.content.pm.ParceledListSlice)

Example 33 with ParceledListSlice

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

the class ActivityManagerService method getPersistedUriPermissions.

@Override
public ParceledListSlice<android.content.UriPermission> getPersistedUriPermissions(String packageName, boolean incoming) {
    enforceNotIsolatedCaller("getPersistedUriPermissions");
    Preconditions.checkNotNull(packageName, "packageName");
    final int callingUid = Binder.getCallingUid();
    final int callingUserId = UserHandle.getUserId(callingUid);
    final IPackageManager pm = AppGlobals.getPackageManager();
    try {
        final int packageUid = pm.getPackageUid(packageName, MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE, callingUserId);
        if (packageUid != callingUid) {
            throw new SecurityException("Package " + packageName + " does not belong to calling UID " + callingUid);
        }
    } catch (RemoteException e) {
        throw new SecurityException("Failed to verify package name ownership");
    }
    final ArrayList<android.content.UriPermission> result = Lists.newArrayList();
    synchronized (this) {
        if (incoming) {
            final ArrayMap<GrantUri, UriPermission> perms = mGrantedUriPermissions.get(callingUid);
            if (perms == null) {
                Slog.w(TAG, "No permission grants found for " + packageName);
            } else {
                for (UriPermission perm : perms.values()) {
                    if (packageName.equals(perm.targetPkg) && perm.persistedModeFlags != 0) {
                        result.add(perm.buildPersistedPublicApiObject());
                    }
                }
            }
        } else {
            final int size = mGrantedUriPermissions.size();
            for (int i = 0; i < size; i++) {
                final ArrayMap<GrantUri, UriPermission> perms = mGrantedUriPermissions.valueAt(i);
                for (UriPermission perm : perms.values()) {
                    if (packageName.equals(perm.sourcePkg) && perm.persistedModeFlags != 0) {
                        result.add(perm.buildPersistedPublicApiObject());
                    }
                }
            }
        }
    }
    return new ParceledListSlice<android.content.UriPermission>(result);
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException) Point(android.graphics.Point) ParceledListSlice(android.content.pm.ParceledListSlice)

Example 34 with ParceledListSlice

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

the class ActivityManagerService method getGrantedUriPermissions.

@Override
public ParceledListSlice<android.content.UriPermission> getGrantedUriPermissions(String packageName, int userId) {
    enforceCallingPermission(android.Manifest.permission.GET_APP_GRANTED_URI_PERMISSIONS, "getGrantedUriPermissions");
    final ArrayList<android.content.UriPermission> result = Lists.newArrayList();
    synchronized (this) {
        final int size = mGrantedUriPermissions.size();
        for (int i = 0; i < size; i++) {
            final ArrayMap<GrantUri, UriPermission> perms = mGrantedUriPermissions.valueAt(i);
            for (UriPermission perm : perms.values()) {
                if (packageName.equals(perm.targetPkg) && perm.targetUserId == userId && perm.persistedModeFlags != 0) {
                    result.add(perm.buildPersistedPublicApiObject());
                }
            }
        }
    }
    return new ParceledListSlice<android.content.UriPermission>(result);
}
Also used : Point(android.graphics.Point) ParceledListSlice(android.content.pm.ParceledListSlice)

Example 35 with ParceledListSlice

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

the class ActivityManagerService method getRecentTasks.

@Override
public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, int userId) {
    final int callingUid = Binder.getCallingUid();
    userId = mUserController.handleIncomingUser(Binder.getCallingPid(), callingUid, userId, false, ALLOW_FULL_ONLY, "getRecentTasks", null);
    final boolean includeProfiles = (flags & ActivityManager.RECENT_INCLUDE_PROFILES) != 0;
    final boolean withExcluded = (flags & ActivityManager.RECENT_WITH_EXCLUDED) != 0;
    synchronized (this) {
        final boolean allowed = isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), callingUid);
        final boolean detailed = checkCallingPermission(android.Manifest.permission.GET_DETAILED_TASKS) == PackageManager.PERMISSION_GRANTED;
        if (!isUserRunning(userId, ActivityManager.FLAG_AND_UNLOCKED)) {
            Slog.i(TAG, "user " + userId + " is still locked. Cannot load recents");
            return ParceledListSlice.emptyList();
        }
        mRecentTasks.loadUserRecentsLocked(userId);
        final int recentsCount = mRecentTasks.size();
        ArrayList<ActivityManager.RecentTaskInfo> res = new ArrayList<>(maxNum < recentsCount ? maxNum : recentsCount);
        final Set<Integer> includedUsers;
        if (includeProfiles) {
            includedUsers = mUserController.getProfileIds(userId);
        } else {
            includedUsers = new HashSet<>();
        }
        includedUsers.add(Integer.valueOf(userId));
        for (int i = 0; i < recentsCount && maxNum > 0; i++) {
            TaskRecord tr = mRecentTasks.get(i);
            // Only add calling user or related users recent tasks
            if (!includedUsers.contains(Integer.valueOf(tr.userId))) {
                if (DEBUG_RECENTS)
                    Slog.d(TAG_RECENTS, "Skipping, not user: " + tr);
                continue;
            }
            if (tr.realActivitySuspended) {
                if (DEBUG_RECENTS)
                    Slog.d(TAG_RECENTS, "Skipping, activity suspended: " + tr);
                continue;
            }
            if (i == 0 || withExcluded || (tr.intent == null) || ((tr.intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0)) {
                if (!allowed) {
                    // allow them to see a small subset of tasks -- their own and home.
                    if (!tr.isHomeTask() && tr.effectiveUid != callingUid) {
                        if (DEBUG_RECENTS)
                            Slog.d(TAG_RECENTS, "Skipping, not allowed: " + tr);
                        continue;
                    }
                }
                if ((flags & ActivityManager.RECENT_IGNORE_HOME_STACK_TASKS) != 0) {
                    if (tr.stack != null && tr.stack.isHomeStack()) {
                        if (DEBUG_RECENTS)
                            Slog.d(TAG_RECENTS, "Skipping, home stack task: " + tr);
                        continue;
                    }
                }
                if ((flags & ActivityManager.RECENT_INGORE_DOCKED_STACK_TOP_TASK) != 0) {
                    final ActivityStack stack = tr.stack;
                    if (stack != null && stack.isDockedStack() && stack.topTask() == tr) {
                        if (DEBUG_RECENTS)
                            Slog.d(TAG_RECENTS, "Skipping, top task in docked stack: " + tr);
                        continue;
                    }
                }
                if ((flags & ActivityManager.RECENT_INGORE_PINNED_STACK_TASKS) != 0) {
                    if (tr.stack != null && tr.stack.isPinnedStack()) {
                        if (DEBUG_RECENTS)
                            Slog.d(TAG_RECENTS, "Skipping, pinned stack task: " + tr);
                        continue;
                    }
                }
                if (tr.autoRemoveRecents && tr.getTopActivity() == null) {
                    // Don't include auto remove tasks that are finished or finishing.
                    if (DEBUG_RECENTS)
                        Slog.d(TAG_RECENTS, "Skipping, auto-remove without activity: " + tr);
                    continue;
                }
                if ((flags & ActivityManager.RECENT_IGNORE_UNAVAILABLE) != 0 && !tr.isAvailable) {
                    if (DEBUG_RECENTS)
                        Slog.d(TAG_RECENTS, "Skipping, unavail real act: " + tr);
                    continue;
                }
                if (!tr.mUserSetupComplete) {
                    // Don't include task launched while user is not done setting-up.
                    if (DEBUG_RECENTS)
                        Slog.d(TAG_RECENTS, "Skipping, user setup not complete: " + tr);
                    continue;
                }
                ActivityManager.RecentTaskInfo rti = createRecentTaskInfoFromTaskRecord(tr);
                if (!detailed) {
                    rti.baseIntent.replaceExtras((Bundle) null);
                }
                res.add(rti);
                maxNum--;
            }
        }
        return new ParceledListSlice<>(res);
    }
}
Also used : ArrayList(java.util.ArrayList) ActivityManager(android.app.ActivityManager) Point(android.graphics.Point) ParceledListSlice(android.content.pm.ParceledListSlice)

Aggregations

ParceledListSlice (android.content.pm.ParceledListSlice)43 ArrayList (java.util.ArrayList)24 Point (android.graphics.Point)16 IPackageInstallerSession (android.content.pm.IPackageInstallerSession)10 PackageInfo (android.content.pm.PackageInfo)10 SessionInfo (android.content.pm.PackageInstaller.SessionInfo)10 RemoteException (android.os.RemoteException)9 PackageParser (android.content.pm.PackageParser)7 ArraySet (android.util.ArraySet)7 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)5 PendingHostUpdate (android.appwidget.PendingHostUpdate)5 LongSparseArray (android.util.LongSparseArray)5 IAppWidgetHost (com.android.internal.appwidget.IAppWidgetHost)5 WidgetBackupProvider (com.android.server.WidgetBackupProvider)5 NonNull (android.annotation.NonNull)4 ActivityManager (android.app.ActivityManager)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 EphemeralApplicationInfo (android.content.pm.EphemeralApplicationInfo)2 FeatureInfo (android.content.pm.FeatureInfo)2 IPackageManager (android.content.pm.IPackageManager)2