Search in sources :

Example 36 with RemoteException

use of android.os.RemoteException 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)

Example 37 with RemoteException

use of android.os.RemoteException in project platform_frameworks_base by android.

the class DisplayDensityUtils method setForcedDisplayDensity.

/**
     * Asynchronously applies display density changes to the specified display.
     * <p>
     * The change will be applied to the user specified by the value of
     * {@link UserHandle#myUserId()} at the time the method is called.
     *
     * @param displayId the identifier of the display to modify
     * @param density the density to force for the specified display
     */
public static void setForcedDisplayDensity(final int displayId, final int density) {
    final int userId = UserHandle.myUserId();
    AsyncTask.execute(() -> {
        try {
            final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
            wm.setForcedDisplayDensityForUser(displayId, density, userId);
        } catch (RemoteException exc) {
            Log.w(LOG_TAG, "Unable to save forced display density setting");
        }
    });
}
Also used : IWindowManager(android.view.IWindowManager) RemoteException(android.os.RemoteException)

Example 38 with RemoteException

use of android.os.RemoteException in project platform_frameworks_base by android.

the class DisplayDensityUtils method clearForcedDisplayDensity.

/**
     * Asynchronously applies display density changes to the specified display.
     * <p>
     * The change will be applied to the user specified by the value of
     * {@link UserHandle#myUserId()} at the time the method is called.
     *
     * @param displayId the identifier of the display to modify
     */
public static void clearForcedDisplayDensity(final int displayId) {
    final int userId = UserHandle.myUserId();
    AsyncTask.execute(() -> {
        try {
            final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
            wm.clearForcedDisplayDensityForUser(displayId, userId);
        } catch (RemoteException exc) {
            Log.w(LOG_TAG, "Unable to clear forced display density setting");
        }
    });
}
Also used : IWindowManager(android.view.IWindowManager) RemoteException(android.os.RemoteException)

Example 39 with RemoteException

use of android.os.RemoteException in project platform_frameworks_base by android.

the class ApplicationsState method addPackage.

void addPackage(String pkgName, int userId) {
    try {
        synchronized (mEntriesMap) {
            if (DEBUG_LOCKING)
                Log.v(TAG, "addPackage acquired lock");
            if (DEBUG)
                Log.i(TAG, "Adding package " + pkgName);
            if (!mResumed) {
                // here.
                if (DEBUG_LOCKING)
                    Log.v(TAG, "addPackage release lock: not resumed");
                return;
            }
            if (indexOfApplicationInfoLocked(pkgName, userId) >= 0) {
                if (DEBUG)
                    Log.i(TAG, "Package already exists!");
                if (DEBUG_LOCKING)
                    Log.v(TAG, "addPackage release lock: already exists");
                return;
            }
            ApplicationInfo info = mIpm.getApplicationInfo(pkgName, mUm.isUserAdmin(userId) ? mAdminRetrieveFlags : mRetrieveFlags, userId);
            if (info == null) {
                return;
            }
            if (!info.enabled) {
                if (info.enabledSetting != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
                    return;
                }
                mHaveDisabledApps = true;
            }
            mApplications.add(info);
            if (!mBackgroundHandler.hasMessages(BackgroundHandler.MSG_LOAD_ENTRIES)) {
                mBackgroundHandler.sendEmptyMessage(BackgroundHandler.MSG_LOAD_ENTRIES);
            }
            if (!mMainHandler.hasMessages(MainHandler.MSG_PACKAGE_LIST_CHANGED)) {
                mMainHandler.sendEmptyMessage(MainHandler.MSG_PACKAGE_LIST_CHANGED);
            }
            if (DEBUG_LOCKING)
                Log.v(TAG, "addPackage releasing lock");
        }
    } catch (RemoteException e) {
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 40 with RemoteException

use of android.os.RemoteException in project platform_frameworks_base by android.

the class GuestResumeSessionReceiver method wipeGuestSession.

/**
     * Wipes the guest session.
     *
     * The guest must be the current user and its id must be {@param userId}.
     */
private static void wipeGuestSession(Context context, int userId) {
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    UserInfo currentUser;
    try {
        currentUser = ActivityManagerNative.getDefault().getCurrentUser();
    } catch (RemoteException e) {
        Log.e(TAG, "Couldn't wipe session because ActivityManager is dead");
        return;
    }
    if (currentUser.id != userId) {
        Log.w(TAG, "User requesting to start a new session (" + userId + ")" + " is not current user (" + currentUser.id + ")");
        return;
    }
    if (!currentUser.isGuest()) {
        Log.w(TAG, "User requesting to start a new session (" + userId + ")" + " is not a guest");
        return;
    }
    boolean marked = userManager.markGuestForDeletion(currentUser.id);
    if (!marked) {
        Log.w(TAG, "Couldn't mark the guest for deletion for user " + userId);
        return;
    }
    UserInfo newGuest = userManager.createGuest(context, currentUser.name);
    try {
        if (newGuest == null) {
            Log.e(TAG, "Could not create new guest, switching back to system user");
            ActivityManagerNative.getDefault().switchUser(UserHandle.USER_SYSTEM);
            userManager.removeUser(currentUser.id);
            WindowManagerGlobal.getWindowManagerService().lockNow(null);
            return;
        }
        ActivityManagerNative.getDefault().switchUser(newGuest.id);
        userManager.removeUser(currentUser.id);
    } catch (RemoteException e) {
        Log.e(TAG, "Couldn't wipe session because ActivityManager or WindowManager is dead");
        return;
    }
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) RemoteException(android.os.RemoteException)

Aggregations

RemoteException (android.os.RemoteException)4527 Intent (android.content.Intent)595 IBinder (android.os.IBinder)480 Bundle (android.os.Bundle)461 Point (android.graphics.Point)423 IOException (java.io.IOException)381 PendingIntent (android.app.PendingIntent)274 ComponentName (android.content.ComponentName)265 ArrayList (java.util.ArrayList)248 ApplicationInfo (android.content.pm.ApplicationInfo)190 IPackageManager (android.content.pm.IPackageManager)190 Message (android.os.Message)184 Uri (android.net.Uri)157 UserHandle (android.os.UserHandle)154 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)151 Cursor (android.database.Cursor)150 Configuration (android.content.res.Configuration)133 UserInfo (android.content.pm.UserInfo)129 AndroidRuntimeException (android.util.AndroidRuntimeException)128 ParcelFileDescriptor (android.os.ParcelFileDescriptor)126