Search in sources :

Example 81 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by crdroidandroid.

the class Bmgr method backupNowAllPackages.

private void backupNowAllPackages() {
    int userId = UserHandle.USER_SYSTEM;
    IPackageManager mPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
    if (mPm == null) {
        System.err.println(PM_NOT_RUNNING_ERR);
        return;
    }
    List<PackageInfo> installedPackages = null;
    try {
        installedPackages = mPm.getInstalledPackages(0, userId).getList();
    } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
    }
    if (installedPackages != null) {
        List<String> packages = new ArrayList<>();
        for (PackageInfo pi : installedPackages) {
            try {
                if (mBmgr.isAppEligibleForBackup(pi.packageName)) {
                    packages.add(pi.packageName);
                }
            } catch (RemoteException e) {
                System.err.println(e.toString());
                System.err.println(BMGR_NOT_RUNNING_ERR);
            }
        }
        backupNowPackages(packages);
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) RemoteException(android.os.RemoteException)

Example 82 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by crdroidandroid.

the class GLImpl method allowIndirectBuffers.

private static boolean allowIndirectBuffers(String appName) {
    boolean result = false;
    int version = 0;
    IPackageManager pm = AppGlobals.getPackageManager();
    try {
        ApplicationInfo applicationInfo = pm.getApplicationInfo(appName, 0, UserHandle.myUserId());
        if (applicationInfo != null) {
            version = applicationInfo.targetSdkVersion;
        }
    } catch (android.os.RemoteException e) {
    // ignore
    }
    Log.e("OpenGLES", String.format("Application %s (SDK target %d) called a GL11 Pointer method with an indirect Buffer.", appName, version));
    if (version <= Build.VERSION_CODES.CUPCAKE) {
        result = true;
    }
    return result;
}
Also used : IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 83 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by crdroidandroid.

the class NfcCommand method run.

@Override
public void run(String[] args) {
    boolean validCommand = false;
    if (args.length >= 2) {
        boolean flag = false;
        if ("enable".equals(args[1])) {
            flag = true;
            validCommand = true;
        } else if ("disable".equals(args[1])) {
            flag = false;
            validCommand = true;
        }
        if (validCommand) {
            IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
            try {
                if (pm.hasSystemFeature(PackageManager.FEATURE_NFC, 0) || pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION, 0)) {
                    INfcAdapter nfc = INfcAdapter.Stub.asInterface(ServiceManager.getService(Context.NFC_SERVICE));
                    try {
                        if (flag) {
                            nfc.enable();
                        } else
                            nfc.disable(true);
                    } catch (RemoteException e) {
                        System.err.println("NFC operation failed: " + e);
                    }
                } else {
                    System.err.println("NFC feature not supported.");
                }
            } catch (RemoteException e) {
                System.err.println("RemoteException while calling PackageManager, is the " + "system running?");
            }
            return;
        }
    }
    System.err.println(longHelp());
}
Also used : IPackageManager(android.content.pm.IPackageManager) INfcAdapter(android.nfc.INfcAdapter) RemoteException(android.os.RemoteException)

Example 84 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by crdroidandroid.

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)

Example 85 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by crdroidandroid.

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)

Aggregations

IPackageManager (android.content.pm.IPackageManager)192 RemoteException (android.os.RemoteException)182 ApplicationInfo (android.content.pm.ApplicationInfo)58 Point (android.graphics.Point)33 PackageInfo (android.content.pm.PackageInfo)32 ComponentName (android.content.ComponentName)29 Intent (android.content.Intent)26 ArrayList (java.util.ArrayList)20 PackageManager (android.content.pm.PackageManager)18 UserHandle (android.os.UserHandle)13 Context (android.content.Context)12 HashMap (java.util.HashMap)12 ProviderInfo (android.content.pm.ProviderInfo)10 PendingIntent (android.app.PendingIntent)9 HashSet (java.util.HashSet)9 UserManager (android.os.UserManager)8 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)7 ResolveInfo (android.content.pm.ResolveInfo)7 ActivityManager (android.app.ActivityManager)6 SpannableString (android.text.SpannableString)6