Search in sources :

Example 71 with ApplicationInfo

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

the class RecentLocationApps method getRequestFromOps.

/**
     * Creates a Request entry for the given PackageOps.
     *
     * This method examines the time interval of the PackageOps first. If the PackageOps is older
     * than the designated interval, this method ignores the PackageOps object and returns null.
     * When the PackageOps is fresh enough, this method returns a Request object for the package
     */
private Request getRequestFromOps(long now, AppOpsManager.PackageOps ops) {
    String packageName = ops.getPackageName();
    List<AppOpsManager.OpEntry> entries = ops.getOps();
    boolean highBattery = false;
    boolean normalBattery = false;
    // Earliest time for a location request to end and still be shown in list.
    long recentLocationCutoffTime = now - RECENT_TIME_INTERVAL_MILLIS;
    for (AppOpsManager.OpEntry entry : entries) {
        if (entry.isRunning() || entry.getTime() >= recentLocationCutoffTime) {
            switch(entry.getOp()) {
                case AppOpsManager.OP_MONITOR_LOCATION:
                    normalBattery = true;
                    break;
                case AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION:
                    highBattery = true;
                    break;
                default:
                    break;
            }
        }
    }
    if (!highBattery && !normalBattery) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, packageName + " hadn't used location within the time interval.");
        }
        return null;
    }
    // The package is fresh enough, continue.
    int uid = ops.getUid();
    int userId = UserHandle.getUserId(uid);
    Request request = null;
    try {
        IPackageManager ipm = AppGlobals.getPackageManager();
        ApplicationInfo appInfo = ipm.getApplicationInfo(packageName, PackageManager.GET_META_DATA, userId);
        if (appInfo == null) {
            Log.w(TAG, "Null application info retrieved for package " + packageName + ", userId " + userId);
            return null;
        }
        final UserHandle userHandle = new UserHandle(userId);
        Drawable appIcon = mPackageManager.getApplicationIcon(appInfo);
        Drawable icon = mPackageManager.getUserBadgedIcon(appIcon, userHandle);
        CharSequence appLabel = mPackageManager.getApplicationLabel(appInfo);
        CharSequence badgedAppLabel = mPackageManager.getUserBadgedLabel(appLabel, userHandle);
        if (appLabel.toString().contentEquals(badgedAppLabel)) {
            // If badged label is not different from original then no need for it as
            // a separate content description.
            badgedAppLabel = null;
        }
        request = new Request(packageName, userHandle, icon, appLabel, highBattery, badgedAppLabel);
    } catch (RemoteException e) {
        Log.w(TAG, "Error while retrieving application info for package " + packageName + ", userId " + userId, e);
    }
    return request;
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) Drawable(android.graphics.drawable.Drawable) AppOpsManager(android.app.AppOpsManager) IPackageManager(android.content.pm.IPackageManager) UserHandle(android.os.UserHandle) RemoteException(android.os.RemoteException)

Example 72 with ApplicationInfo

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

the class AppRestrictionsHelper method addSystemApps.

/**
     * Add system apps that match an intent to the list, excluding any packages in the exclude list.
     * @param visibleApps list of apps to append the new list to
     * @param intent the intent to match
     * @param excludePackages the set of package names to be excluded, since they're required
     */
private void addSystemApps(List<SelectableAppInfo> visibleApps, Intent intent, Set<String> excludePackages) {
    final PackageManager pm = mPackageManager;
    List<ResolveInfo> launchableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.MATCH_UNINSTALLED_PACKAGES);
    for (ResolveInfo app : launchableApps) {
        if (app.activityInfo != null && app.activityInfo.applicationInfo != null) {
            final String packageName = app.activityInfo.packageName;
            int flags = app.activityInfo.applicationInfo.flags;
            if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0 || (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
                // Skip excluded packages
                if (excludePackages.contains(packageName))
                    continue;
                int enabled = pm.getApplicationEnabledSetting(packageName);
                if (enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED || enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
                    // Check if the app is already enabled for the target user
                    ApplicationInfo targetUserAppInfo = getAppInfoForUser(packageName, 0, mUser);
                    if (targetUserAppInfo == null || (targetUserAppInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
                        continue;
                    }
                }
                SelectableAppInfo info = new SelectableAppInfo();
                info.packageName = app.activityInfo.packageName;
                info.appName = app.activityInfo.applicationInfo.loadLabel(pm);
                info.icon = app.activityInfo.loadIcon(pm);
                info.activityName = app.activityInfo.loadLabel(pm);
                if (info.activityName == null)
                    info.activityName = info.appName;
                visibleApps.add(info);
            }
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 73 with ApplicationInfo

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

the class UidDetailProvider method buildUidDetail.

/**
     * Build {@link UidDetail} object, blocking until all {@link Drawable}
     * lookup is finished.
     */
private UidDetail buildUidDetail(int uid) {
    final Resources res = mContext.getResources();
    final PackageManager pm = mContext.getPackageManager();
    final UidDetail detail = new UidDetail();
    detail.label = pm.getNameForUid(uid);
    detail.icon = pm.getDefaultActivityIcon();
    // handle special case labels
    switch(uid) {
        case android.os.Process.SYSTEM_UID:
            detail.label = res.getString(R.string.process_kernel_label);
            detail.icon = pm.getDefaultActivityIcon();
            return detail;
        case TrafficStats.UID_REMOVED:
            detail.label = res.getString(UserManager.supportsMultipleUsers() ? R.string.data_usage_uninstalled_apps_users : R.string.data_usage_uninstalled_apps);
            detail.icon = pm.getDefaultActivityIcon();
            return detail;
        case TrafficStats.UID_TETHERING:
            final ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
            detail.label = res.getString(Utils.getTetheringLabel(cm));
            detail.icon = pm.getDefaultActivityIcon();
            return detail;
    }
    final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    // Handle keys that are actually user handles
    if (isKeyForUser(uid)) {
        final int userHandle = getUserIdForKey(uid);
        final UserInfo info = um.getUserInfo(userHandle);
        if (info != null) {
            detail.label = Utils.getUserLabel(mContext, info);
            detail.icon = Utils.getUserIcon(mContext, um, info);
            return detail;
        }
    }
    // otherwise fall back to using packagemanager labels
    final String[] packageNames = pm.getPackagesForUid(uid);
    final int length = packageNames != null ? packageNames.length : 0;
    try {
        final int userId = UserHandle.getUserId(uid);
        UserHandle userHandle = new UserHandle(userId);
        IPackageManager ipm = AppGlobals.getPackageManager();
        if (length == 1) {
            final ApplicationInfo info = ipm.getApplicationInfo(packageNames[0], 0, /* no flags */
            userId);
            if (info != null) {
                detail.label = info.loadLabel(pm).toString();
                detail.icon = um.getBadgedIconForUser(info.loadIcon(pm), new UserHandle(userId));
            }
        } else if (length > 1) {
            detail.detailLabels = new CharSequence[length];
            detail.detailContentDescriptions = new CharSequence[length];
            for (int i = 0; i < length; i++) {
                final String packageName = packageNames[i];
                final PackageInfo packageInfo = pm.getPackageInfo(packageName, 0);
                final ApplicationInfo appInfo = ipm.getApplicationInfo(packageName, 0, /* no flags */
                userId);
                if (appInfo != null) {
                    detail.detailLabels[i] = appInfo.loadLabel(pm).toString();
                    detail.detailContentDescriptions[i] = um.getBadgedLabelForUser(detail.detailLabels[i], userHandle);
                    if (packageInfo.sharedUserLabel != 0) {
                        detail.label = pm.getText(packageName, packageInfo.sharedUserLabel, packageInfo.applicationInfo).toString();
                        detail.icon = um.getBadgedIconForUser(appInfo.loadIcon(pm), userHandle);
                    }
                }
            }
        }
        detail.contentDescription = um.getBadgedLabelForUser(detail.label, userHandle);
    } catch (NameNotFoundException e) {
        Log.w(TAG, "Error while building UI detail for uid " + uid, e);
    } catch (RemoteException e) {
        Log.w(TAG, "Error while building UI detail for uid " + uid, e);
    }
    if (TextUtils.isEmpty(detail.label)) {
        detail.label = Integer.toString(uid);
    }
    return detail;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ConnectivityManager(android.net.ConnectivityManager) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) UserInfo(android.content.pm.UserInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) IPackageManager(android.content.pm.IPackageManager) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) Resources(android.content.res.Resources) RemoteException(android.os.RemoteException)

Example 74 with ApplicationInfo

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

the class AppRestrictionsHelper method applyUserAppState.

public void applyUserAppState(String packageName, boolean enabled, OnDisableUiForPackageListener listener) {
    final int userId = mUser.getIdentifier();
    if (enabled) {
        // Enable selected apps
        try {
            ApplicationInfo info = mIPm.getApplicationInfo(packageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, userId);
            if (info == null || !info.enabled || (info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
                mIPm.installExistingPackageAsUser(packageName, mUser.getIdentifier());
                if (DEBUG) {
                    Log.d(TAG, "Installing " + packageName);
                }
            }
            if (info != null && (info.privateFlags & ApplicationInfo.PRIVATE_FLAG_HIDDEN) != 0 && (info.flags & ApplicationInfo.FLAG_INSTALLED) != 0) {
                listener.onDisableUiForPackage(packageName);
                mIPm.setApplicationHiddenSettingAsUser(packageName, false, userId);
                if (DEBUG) {
                    Log.d(TAG, "Unhiding " + packageName);
                }
            }
        } catch (RemoteException re) {
        // Ignore
        }
    } else {
        // Blacklist all other apps, system or downloaded
        try {
            ApplicationInfo info = mIPm.getApplicationInfo(packageName, 0, userId);
            if (info != null) {
                if (mRestrictedProfile) {
                    mIPm.deletePackageAsUser(packageName, null, mUser.getIdentifier(), PackageManager.DELETE_SYSTEM_APP);
                    if (DEBUG) {
                        Log.d(TAG, "Uninstalling " + packageName);
                    }
                } else {
                    listener.onDisableUiForPackage(packageName);
                    mIPm.setApplicationHiddenSettingAsUser(packageName, true, userId);
                    if (DEBUG) {
                        Log.d(TAG, "Hiding " + packageName);
                    }
                }
            }
        } catch (RemoteException re) {
        // Ignore
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 75 with ApplicationInfo

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

the class InputMethodManagerService method updateInputMethodsFromSettingsLocked.

void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) {
    if (enabledMayChange) {
        List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
        for (int i = 0; i < enabled.size(); i++) {
            // We allow the user to select "disabled until used" apps, so if they
            // are enabling one of those here we now need to make it enabled.
            InputMethodInfo imm = enabled.get(i);
            try {
                ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(), PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, mSettings.getCurrentUserId());
                if (ai != null && ai.enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
                    if (DEBUG) {
                        Slog.d(TAG, "Update state(" + imm.getId() + "): DISABLED_UNTIL_USED -> DEFAULT");
                    }
                    mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(), PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(), mContext.getBasePackageName());
                }
            } catch (RemoteException e) {
            }
        }
    }
    // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and
    // ENABLED_INPUT_METHODS is taking care of keeping them correctly in
    // sync, so we will never have a DEFAULT_INPUT_METHOD that is not
    // enabled.
    String id = mSettings.getSelectedInputMethod();
    // There is no input method selected, try to choose new applicable input method.
    if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) {
        id = mSettings.getSelectedInputMethod();
    }
    if (!TextUtils.isEmpty(id)) {
        try {
            setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id));
        } catch (IllegalArgumentException e) {
            Slog.w(TAG, "Unknown input method from prefs: " + id, e);
            resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_SWITCH_IME_FAILED);
        }
        mShortcutInputMethodsAndSubtypes.clear();
    } else {
        // There is no longer an input method set, so stop any current one.
        resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_NO_IME);
    }
    // code to disable the CM Phone IME switcher with config_show_cmIMESwitcher set = false
    try {
        mShowOngoingImeSwitcherForPhones = CMSettings.System.getInt(mContext.getContentResolver(), CMSettings.System.STATUS_BAR_IME_SWITCHER) == 1;
    } catch (CMSettings.CMSettingNotFoundException e) {
        mShowOngoingImeSwitcherForPhones = mRes.getBoolean(com.android.internal.R.bool.config_show_cmIMESwitcher);
    }
    // Here is not the perfect place to reset the switching controller. Ideally
    // mSwitchingController and mSettings should be able to share the same state.
    // TODO: Make sure that mSwitchingController and mSettings are sharing the
    // the same enabled IMEs list.
    mSwitchingController.resetCircularListLocked(mContext);
}
Also used : CMSettings(cyanogenmod.providers.CMSettings) ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)1914 PackageManager (android.content.pm.PackageManager)682 Test (org.junit.Test)366 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)363 ArrayList (java.util.ArrayList)258 Intent (android.content.Intent)231 RemoteException (android.os.RemoteException)229 PackageInfo (android.content.pm.PackageInfo)214 ResolveInfo (android.content.pm.ResolveInfo)177 IOException (java.io.IOException)122 ActivityInfo (android.content.pm.ActivityInfo)114 IPackageManager (android.content.pm.IPackageManager)109 UserHandle (android.os.UserHandle)108 Context (android.content.Context)103 Bundle (android.os.Bundle)103 File (java.io.File)100 Drawable (android.graphics.drawable.Drawable)91 UserInfo (android.content.pm.UserInfo)89 ComponentName (android.content.ComponentName)69 SmallTest (android.support.test.filters.SmallTest)66