Search in sources :

Example 61 with UserHandle

use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.

the class AccountManagerService method isPrivileged.

private boolean isPrivileged(int callingUid) {
    final int callingUserId = UserHandle.getUserId(callingUid);
    final PackageManager userPackageManager;
    try {
        userPackageManager = mContext.createPackageContextAsUser("android", 0, new UserHandle(callingUserId)).getPackageManager();
    } catch (NameNotFoundException e) {
        return false;
    }
    String[] packages = userPackageManager.getPackagesForUid(callingUid);
    for (String name : packages) {
        try {
            PackageInfo packageInfo = userPackageManager.getPackageInfo(name, 0);
            if (packageInfo != null && (packageInfo.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0) {
                return true;
            }
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }
    return false;
}
Also used : PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) UserHandle(android.os.UserHandle)

Example 62 with UserHandle

use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.

the class DpmMockContext method addUser.

public File addUser(int userId, int flags) {
    // Set up (default) UserInfo for CALLER_USER_HANDLE.
    final UserInfo uh = new UserInfo(userId, "user" + userId, flags);
    when(userManager.getUserInfo(eq(userId))).thenReturn(uh);
    mUserInfos.add(uh);
    when(userManager.getUsers()).thenReturn(mUserInfos);
    when(userManager.getUsers(anyBoolean())).thenReturn(mUserInfos);
    when(userManager.isUserRunning(eq(new UserHandle(userId)))).thenReturn(true);
    when(userManager.getUserInfo(anyInt())).thenAnswer(new Answer<UserInfo>() {

        @Override
        public UserInfo answer(InvocationOnMock invocation) throws Throwable {
            final int userId = (int) invocation.getArguments()[0];
            for (UserInfo ui : mUserInfos) {
                if (ui.id == userId) {
                    return ui;
                }
            }
            return null;
        }
    });
    when(userManager.getProfiles(anyInt())).thenAnswer(new Answer<List<UserInfo>>() {

        @Override
        public List<UserInfo> answer(InvocationOnMock invocation) throws Throwable {
            final int userId = (int) invocation.getArguments()[0];
            return getProfiles(userId);
        }
    });
    when(userManager.getProfileIdsWithDisabled(anyInt())).thenAnswer(new Answer<int[]>() {

        @Override
        public int[] answer(InvocationOnMock invocation) throws Throwable {
            final int userId = (int) invocation.getArguments()[0];
            List<UserInfo> profiles = getProfiles(userId);
            int[] results = new int[profiles.size()];
            for (int i = 0; i < results.length; i++) {
                results[i] = profiles.get(i).id;
            }
            return results;
        }
    });
    when(accountManager.getAccountsAsUser(anyInt())).thenReturn(new Account[0]);
    // Create a data directory.
    final File dir = new File(dataDir, "user" + userId);
    DpmTestUtils.clearDir(dir);
    when(environment.getUserSystemDirectory(eq(userId))).thenReturn(dir);
    return dir;
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) UserHandle(android.os.UserHandle) UserInfo(android.content.pm.UserInfo) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 63 with UserHandle

use of android.os.UserHandle in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccountSettings method onPrepareOptionsMenu.

@Override
public void onPrepareOptionsMenu(Menu menu) {
    final UserHandle currentProfile = Process.myUserHandle();
    if (mProfiles.size() == 1) {
        menu.findItem(R.id.account_settings_menu_auto_sync).setVisible(true).setOnMenuItemClickListener(new MasterSyncStateClickListener(currentProfile)).setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(currentProfile.getIdentifier()));
        menu.findItem(R.id.account_settings_menu_auto_sync_personal).setVisible(false);
        menu.findItem(R.id.account_settings_menu_auto_sync_work).setVisible(false);
    } else if (mProfiles.size() > 1) {
        // We assume there's only one managed profile, otherwise UI needs to change
        final UserHandle managedProfile = mProfiles.valueAt(1).userInfo.getUserHandle();
        menu.findItem(R.id.account_settings_menu_auto_sync_personal).setVisible(true).setOnMenuItemClickListener(new MasterSyncStateClickListener(currentProfile)).setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(currentProfile.getIdentifier()));
        menu.findItem(R.id.account_settings_menu_auto_sync_work).setVisible(true).setOnMenuItemClickListener(new MasterSyncStateClickListener(managedProfile)).setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(managedProfile.getIdentifier()));
        menu.findItem(R.id.account_settings_menu_auto_sync).setVisible(false);
    } else {
        Log.w(TAG, "Method onPrepareOptionsMenu called before mProfiles was initialized");
    }
}
Also used : UserHandle(android.os.UserHandle)

Example 64 with UserHandle

use of android.os.UserHandle in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ProtectedAccountView method findIntendedAccount.

/**
     * Given the string the user entered in the 'username' field, find
     * the stored account that they probably intended.  Prefer, in order:
     *
     *   - an exact match for what was typed, or
     *   - a case-insensitive match for what was typed, or
     *   - if they didn't include a domain, an exact match of the username, or
     *   - if they didn't include a domain, a case-insensitive
     *     match of the username.
     *
     * If there is a tie for the best match, choose neither --
     * the user needs to be more specific.
     *
     * @return an account name from the database, or null if we can't
     * find a single best match.
     */
private Account findIntendedAccount(String username) {
    Account[] accounts = AccountManager.get(mContext).getAccountsByTypeAsUser("com.google", new UserHandle(ActivityManager.getCurrentUser()));
    // Try to figure out which account they meant if they
    // typed only the username (and not the domain), or got
    // the case wrong.
    Account bestAccount = null;
    int bestScore = 0;
    for (Account a : accounts) {
        int score = 0;
        if (username.equals(a.name)) {
            score = 4;
        } else if (username.equalsIgnoreCase(a.name)) {
            score = 3;
        } else if (username.indexOf('@') < 0) {
            int i = a.name.indexOf('@');
            if (i >= 0) {
                String aUsername = a.name.substring(0, i);
                if (username.equals(aUsername)) {
                    score = 2;
                } else if (username.equalsIgnoreCase(aUsername)) {
                    score = 1;
                }
            }
        }
        if (score > bestScore) {
            bestAccount = a;
            bestScore = score;
        } else if (score == bestScore) {
            bestAccount = null;
        }
    }
    return bestAccount;
}
Also used : Account(android.accounts.Account) UserHandle(android.os.UserHandle)

Example 65 with UserHandle

use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.

the class SearchableInfo method getActivityMetaData.

/**
     * Gets search information for the given activity.
     *
     * @param context Context to use for reading activity resources.
     * @param activityInfo Activity to get search information from.
     * @return Search information about the given activity, or {@code null} if
     *         the activity has no or invalid searchability meta-data.
     *
     * @hide For use by SearchManagerService.
     */
public static SearchableInfo getActivityMetaData(Context context, ActivityInfo activityInfo, int userId) {
    Context userContext = null;
    try {
        userContext = context.createPackageContextAsUser("system", 0, new UserHandle(userId));
    } catch (NameNotFoundException nnfe) {
        Log.e(LOG_TAG, "Couldn't create package context for user " + userId);
        return null;
    }
    // for each component, try to find metadata
    XmlResourceParser xml = activityInfo.loadXmlMetaData(userContext.getPackageManager(), MD_LABEL_SEARCHABLE);
    if (xml == null) {
        return null;
    }
    ComponentName cName = new ComponentName(activityInfo.packageName, activityInfo.name);
    SearchableInfo searchable = getActivityMetaData(userContext, xml, cName);
    xml.close();
    if (DBG) {
        if (searchable != null) {
            Log.d(LOG_TAG, "Checked " + activityInfo.name + ",label=" + searchable.getLabelId() + ",icon=" + searchable.getIconId() + ",suggestAuthority=" + searchable.getSuggestAuthority() + ",target=" + searchable.getSearchActivity().getClassName() + ",global=" + searchable.shouldIncludeInGlobalSearch() + ",settingsDescription=" + searchable.getSettingsDescriptionId() + ",threshold=" + searchable.getSuggestThreshold());
        } else {
            Log.d(LOG_TAG, "Checked " + activityInfo.name + ", no searchable meta-data");
        }
    }
    return searchable;
}
Also used : Context(android.content.Context) XmlResourceParser(android.content.res.XmlResourceParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName)

Aggregations

UserHandle (android.os.UserHandle)1087 Intent (android.content.Intent)306 RemoteException (android.os.RemoteException)205 Test (org.junit.Test)165 UserInfo (android.content.pm.UserInfo)152 PendingIntent (android.app.PendingIntent)134 Bundle (android.os.Bundle)127 Context (android.content.Context)126 ApplicationInfo (android.content.pm.ApplicationInfo)93 ArrayList (java.util.ArrayList)91 PackageManager (android.content.pm.PackageManager)86 UserManager (android.os.UserManager)85 ComponentName (android.content.ComponentName)82 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)82 Drawable (android.graphics.drawable.Drawable)61 IBinder (android.os.IBinder)49 IOException (java.io.IOException)45 Config (org.robolectric.annotation.Config)41 Account (android.accounts.Account)39 ResolveInfo (android.content.pm.ResolveInfo)37