Search in sources :

Example 16 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

the class InputMethodUtils method setNonSelectedSystemImesDisabledUntilUsed.

public static void setNonSelectedSystemImesDisabledUntilUsed(IPackageManager packageManager, List<InputMethodInfo> enabledImis, int userId, String callingPackage) {
    if (DEBUG) {
        Slog.d(TAG, "setNonSelectedSystemImesDisabledUntilUsed");
    }
    final String[] systemImesDisabledUntilUsed = Resources.getSystem().getStringArray(com.android.internal.R.array.config_disabledUntilUsedPreinstalledImes);
    if (systemImesDisabledUntilUsed == null || systemImesDisabledUntilUsed.length == 0) {
        return;
    }
    // Only the current spell checker should be treated as an enabled one.
    final SpellCheckerInfo currentSpellChecker = TextServicesManager.getInstance().getCurrentSpellChecker();
    for (final String packageName : systemImesDisabledUntilUsed) {
        if (DEBUG) {
            Slog.d(TAG, "check " + packageName);
        }
        boolean enabledIme = false;
        for (int j = 0; j < enabledImis.size(); ++j) {
            final InputMethodInfo imi = enabledImis.get(j);
            if (packageName.equals(imi.getPackageName())) {
                enabledIme = true;
                break;
            }
        }
        if (enabledIme) {
            // enabled ime. skip
            continue;
        }
        if (currentSpellChecker != null && packageName.equals(currentSpellChecker.getPackageName())) {
            // enabled spell checker. skip
            if (DEBUG) {
                Slog.d(TAG, packageName + " is the current spell checker. skip");
            }
            continue;
        }
        ApplicationInfo ai = null;
        try {
            ai = packageManager.getApplicationInfo(packageName, PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, userId);
        } catch (RemoteException e) {
            Slog.w(TAG, "getApplicationInfo failed. packageName=" + packageName + " userId=" + userId, e);
            continue;
        }
        if (ai == null) {
            // No app found for packageName
            continue;
        }
        final boolean isSystemPackage = (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
        if (!isSystemPackage) {
            continue;
        }
        setDisabledUntilUsed(packageManager, packageName, userId, callingPackage);
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 17 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

the class NetworkScorerAppManagerTest method mockRecommendationServiceAvailable.

private void mockRecommendationServiceAvailable(final String packageName, int packageUid) {
    final ResolveInfo serviceInfo = new ResolveInfo();
    serviceInfo.serviceInfo = new ServiceInfo();
    serviceInfo.serviceInfo.name = ".RecommendationService";
    serviceInfo.serviceInfo.packageName = packageName;
    serviceInfo.serviceInfo.applicationInfo = new ApplicationInfo();
    serviceInfo.serviceInfo.applicationInfo.uid = packageUid;
    final int flags = 0;
    when(mMockPm.resolveService(Mockito.argThat(new ArgumentMatcher<Intent>() {

        @Override
        public boolean matchesObject(Object object) {
            Intent intent = (Intent) object;
            return NetworkScoreManager.ACTION_RECOMMEND_NETWORKS.equals(intent.getAction()) && packageName.equals(intent.getPackage());
        }
    }), Mockito.eq(flags))).thenReturn(serviceInfo);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) ArgumentMatcher(org.mockito.compat.ArgumentMatcher) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent)

Example 18 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

the class Icon method loadDrawableInner.

/**
     * Do the heavy lifting of loading the drawable, but stop short of applying any tint.
     */
private Drawable loadDrawableInner(Context context) {
    switch(mType) {
        case TYPE_BITMAP:
            return new BitmapDrawable(context.getResources(), getBitmap());
        case TYPE_RESOURCE:
            if (getResources() == null) {
                // figure out where to load resources from
                String resPackage = getResPackage();
                if (TextUtils.isEmpty(resPackage)) {
                    // if none is specified, try the given context
                    resPackage = context.getPackageName();
                }
                if ("android".equals(resPackage)) {
                    mObj1 = Resources.getSystem();
                } else {
                    final PackageManager pm = context.getPackageManager();
                    try {
                        ApplicationInfo ai = pm.getApplicationInfo(resPackage, PackageManager.GET_UNINSTALLED_PACKAGES);
                        if (ai != null) {
                            mObj1 = pm.getResourcesForApplication(ai);
                        } else {
                            break;
                        }
                    } catch (PackageManager.NameNotFoundException e) {
                        Log.e(TAG, String.format("Unable to find pkg=%s for icon %s", resPackage, this), e);
                        break;
                    }
                }
            }
            try {
                return getResources().getDrawable(getResId(), context.getTheme());
            } catch (RuntimeException e) {
                Log.e(TAG, String.format("Unable to load resource 0x%08x from pkg=%s", getResId(), getResPackage()), e);
            }
            break;
        case TYPE_DATA:
            return new BitmapDrawable(context.getResources(), BitmapFactory.decodeByteArray(getDataBytes(), getDataOffset(), getDataLength()));
        case TYPE_URI:
            final Uri uri = getUri();
            final String scheme = uri.getScheme();
            InputStream is = null;
            if (ContentResolver.SCHEME_CONTENT.equals(scheme) || ContentResolver.SCHEME_FILE.equals(scheme)) {
                try {
                    is = context.getContentResolver().openInputStream(uri);
                } catch (Exception e) {
                    Log.w(TAG, "Unable to load image from URI: " + uri, e);
                }
            } else {
                try {
                    is = new FileInputStream(new File(mString1));
                } catch (FileNotFoundException e) {
                    Log.w(TAG, "Unable to load image from path: " + uri, e);
                }
            }
            if (is != null) {
                return new BitmapDrawable(context.getResources(), BitmapFactory.decodeStream(is));
            }
            break;
    }
    return null;
}
Also used : PackageManager(android.content.pm.PackageManager) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ApplicationInfo(android.content.pm.ApplicationInfo) FileNotFoundException(java.io.FileNotFoundException) Uri(android.net.Uri) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream)

Example 19 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

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 20 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

the class AppRestrictionsHelper method fetchAndMergeApps.

public void fetchAndMergeApps() {
    mVisibleApps = new ArrayList<>();
    final PackageManager pm = mPackageManager;
    final IPackageManager ipm = mIPm;
    final HashSet<String> excludePackages = new HashSet<>();
    addSystemImes(excludePackages);
    // Add launchers
    Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
    if (mLeanback) {
        launcherIntent.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
    } else {
        launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    }
    addSystemApps(mVisibleApps, launcherIntent, excludePackages);
    // Add widgets
    Intent widgetIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    addSystemApps(mVisibleApps, widgetIntent, excludePackages);
    List<ApplicationInfo> installedApps = pm.getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES);
    for (ApplicationInfo app : installedApps) {
        // If it's not installed, skip
        if ((app.flags & ApplicationInfo.FLAG_INSTALLED) == 0)
            continue;
        if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && (app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0) {
            // Downloaded app
            SelectableAppInfo info = new SelectableAppInfo();
            info.packageName = app.packageName;
            info.appName = app.loadLabel(pm);
            info.activityName = info.appName;
            info.icon = app.loadIcon(pm);
            mVisibleApps.add(info);
        } else {
            try {
                PackageInfo pi = pm.getPackageInfo(app.packageName, 0);
                // but will still be marked as false and immutable.
                if (mRestrictedProfile && pi.requiredAccountType != null && pi.restrictedAccountType == null) {
                    mSelectedPackages.put(app.packageName, false);
                }
            } catch (PackageManager.NameNotFoundException re) {
            // Skip
            }
        }
    }
    // Get the list of apps already installed for the user
    List<ApplicationInfo> userApps = null;
    try {
        ParceledListSlice<ApplicationInfo> listSlice = ipm.getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES, mUser.getIdentifier());
        if (listSlice != null) {
            userApps = listSlice.getList();
        }
    } catch (RemoteException re) {
    // Ignore
    }
    if (userApps != null) {
        for (ApplicationInfo app : userApps) {
            if ((app.flags & ApplicationInfo.FLAG_INSTALLED) == 0)
                continue;
            if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && (app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0) {
                // Downloaded app
                SelectableAppInfo info = new SelectableAppInfo();
                info.packageName = app.packageName;
                info.appName = app.loadLabel(pm);
                info.activityName = info.appName;
                info.icon = app.loadIcon(pm);
                mVisibleApps.add(info);
            }
        }
    }
    // Sort the list of visible apps
    Collections.sort(mVisibleApps, new AppLabelComparator());
    // Remove dupes
    Set<String> dedupPackageSet = new HashSet<String>();
    for (int i = mVisibleApps.size() - 1; i >= 0; i--) {
        SelectableAppInfo info = mVisibleApps.get(i);
        if (DEBUG)
            Log.i(TAG, info.toString());
        String both = info.packageName + "+" + info.activityName;
        if (!TextUtils.isEmpty(info.packageName) && !TextUtils.isEmpty(info.activityName) && dedupPackageSet.contains(both)) {
            mVisibleApps.remove(i);
        } else {
            dedupPackageSet.add(both);
        }
    }
    // Establish master/slave relationship for entries that share a package name
    HashMap<String, SelectableAppInfo> packageMap = new HashMap<String, SelectableAppInfo>();
    for (SelectableAppInfo info : mVisibleApps) {
        if (packageMap.containsKey(info.packageName)) {
            info.masterEntry = packageMap.get(info.packageName);
        } else {
            packageMap.put(info.packageName, info);
        }
    }
}
Also used : HashMap(java.util.HashMap) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException) HashSet(java.util.HashSet)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)921 PackageManager (android.content.pm.PackageManager)345 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)274 RemoteException (android.os.RemoteException)204 Intent (android.content.Intent)103 ArrayList (java.util.ArrayList)98 IPackageManager (android.content.pm.IPackageManager)96 IOException (java.io.IOException)80 PackageInfo (android.content.pm.PackageInfo)79 ResolveInfo (android.content.pm.ResolveInfo)72 File (java.io.File)64 ComponentName (android.content.ComponentName)52 Context (android.content.Context)51 Bundle (android.os.Bundle)50 PendingIntent (android.app.PendingIntent)45 Drawable (android.graphics.drawable.Drawable)43 UserInfo (android.content.pm.UserInfo)40 ActivityInfo (android.content.pm.ActivityInfo)35 ServiceInfo (android.content.pm.ServiceInfo)35 Resources (android.content.res.Resources)33