Search in sources :

Example 86 with UserHandle

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

the class ChooseTypeAndAccountActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "ChooseTypeAndAccountActivity.onCreate(savedInstanceState=" + savedInstanceState + ")");
    }
    String message = null;
    try {
        IBinder activityToken = getActivityToken();
        mCallingUid = ActivityManagerNative.getDefault().getLaunchedFromUid(activityToken);
        mCallingPackage = ActivityManagerNative.getDefault().getLaunchedFromPackage(activityToken);
        if (mCallingUid != 0 && mCallingPackage != null) {
            Bundle restrictions = UserManager.get(this).getUserRestrictions(new UserHandle(UserHandle.getUserId(mCallingUid)));
            mDisallowAddAccounts = restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false);
        }
    } catch (RemoteException re) {
        // Couldn't figure out caller details
        Log.w(getClass().getSimpleName(), "Unable to get caller identity \n" + re);
    }
    // save some items we use frequently
    final Intent intent = getIntent();
    if (savedInstanceState != null) {
        mPendingRequest = savedInstanceState.getInt(KEY_INSTANCE_STATE_PENDING_REQUEST);
        mExistingAccounts = savedInstanceState.getParcelableArray(KEY_INSTANCE_STATE_EXISTING_ACCOUNTS);
        // Makes sure that any user selection is preserved across orientation changes.
        mSelectedAccountName = savedInstanceState.getString(KEY_INSTANCE_STATE_SELECTED_ACCOUNT_NAME);
        mSelectedAddNewAccount = savedInstanceState.getBoolean(KEY_INSTANCE_STATE_SELECTED_ADD_ACCOUNT, false);
        mAccounts = savedInstanceState.getParcelableArrayList(KEY_INSTANCE_STATE_ACCOUNT_LIST);
    } else {
        mPendingRequest = REQUEST_NULL;
        mExistingAccounts = null;
        // If the selected account as specified in the intent matches one in the list we will
        // show is as pre-selected.
        Account selectedAccount = (Account) intent.getParcelableExtra(EXTRA_SELECTED_ACCOUNT);
        if (selectedAccount != null) {
            mSelectedAccountName = selectedAccount.name;
        }
    }
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "selected account name is " + mSelectedAccountName);
    }
    mSetOfAllowableAccounts = getAllowableAccountSet(intent);
    mSetOfRelevantAccountTypes = getReleventAccountTypes(intent);
    mDescriptionOverride = intent.getStringExtra(EXTRA_DESCRIPTION_TEXT_OVERRIDE);
    mAccounts = getAcceptableAccountChoices(AccountManager.get(this));
    if (mAccounts.isEmpty() && mDisallowAddAccounts) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.app_not_authorized);
        mDontShowPicker = true;
    }
    if (mDontShowPicker) {
        super.onCreate(savedInstanceState);
        return;
    }
    // No account -> launch add account activity directly
    if (mPendingRequest == REQUEST_NULL) {
        // add account. Otherwise let the user choose.
        if (mAccounts.isEmpty()) {
            setNonLabelThemeAndCallSuperCreate(savedInstanceState);
            if (mSetOfRelevantAccountTypes.size() == 1) {
                runAddAccountForAuthenticator(mSetOfRelevantAccountTypes.iterator().next());
            } else {
                startChooseAccountTypeActivity();
            }
        }
    }
    String[] listItems = getListOfDisplayableOptions(mAccounts);
    mSelectedItemIndex = getItemIndexToSelect(mAccounts, mSelectedAccountName, mSelectedAddNewAccount);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.choose_type_and_account);
    overrideDescriptionIfSupplied(mDescriptionOverride);
    populateUIAccountList(listItems);
    // Only enable "OK" button if something has been selected.
    mOkButton = (Button) findViewById(android.R.id.button2);
    mOkButton.setEnabled(mSelectedItemIndex != SELECTED_ITEM_NONE);
}
Also used : IBinder(android.os.IBinder) Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 87 with UserHandle

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

the class KeyguardViewMediator method sendUserPresentBroadcast.

private void sendUserPresentBroadcast() {
    synchronized (this) {
        if (mBootCompleted) {
            int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
            final UserHandle currentUser = new UserHandle(currentUserId);
            final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
            for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
                mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
            }
            getLockPatternUtils().userPresent(currentUserId);
        } else {
            mBootSendUserPresent = true;
        }
    }
}
Also used : UserManager(android.os.UserManager) UserHandle(android.os.UserHandle)

Example 88 with UserHandle

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

the class DevicePolicyManagerService method getApplicationRestrictions.

@Override
public Bundle getApplicationRestrictions(ComponentName who, String packageName) {
    enforceCanManageApplicationRestrictions(who);
    final UserHandle userHandle = mInjector.binderGetCallingUserHandle();
    final long id = mInjector.binderClearCallingIdentity();
    try {
        Bundle bundle = mUserManager.getApplicationRestrictions(packageName, userHandle);
        // returns null, but DPM method should return an empty Bundle as per JavaDoc
        return bundle != null ? bundle : Bundle.EMPTY;
    } finally {
        mInjector.binderRestoreCallingIdentity(id);
    }
}
Also used : Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) UserHandle(android.os.UserHandle)

Example 89 with UserHandle

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

the class DevicePolicyManagerService method installCaCert.

@Override
public boolean installCaCert(ComponentName admin, byte[] certBuffer) throws RemoteException {
    enforceCanManageCaCerts(admin);
    byte[] pemCert;
    try {
        X509Certificate cert = parseCert(certBuffer);
        pemCert = Credentials.convertToPem(cert);
    } catch (CertificateException ce) {
        Log.e(LOG_TAG, "Problem converting cert", ce);
        return false;
    } catch (IOException ioe) {
        Log.e(LOG_TAG, "Problem reading cert", ioe);
        return false;
    }
    final UserHandle userHandle = new UserHandle(UserHandle.getCallingUserId());
    final long id = mInjector.binderClearCallingIdentity();
    try {
        final KeyChainConnection keyChainConnection = KeyChain.bindAsUser(mContext, userHandle);
        try {
            keyChainConnection.getService().installCaCertificate(pemCert);
            return true;
        } catch (RemoteException e) {
            Log.e(LOG_TAG, "installCaCertsToKeyChain(): ", e);
        } finally {
            keyChainConnection.close();
        }
    } catch (InterruptedException e1) {
        Log.w(LOG_TAG, "installCaCertsToKeyChain(): ", e1);
        Thread.currentThread().interrupt();
    } finally {
        mInjector.binderRestoreCallingIdentity(id);
    }
    return false;
}
Also used : UserHandle(android.os.UserHandle) KeyChainConnection(android.security.KeyChain.KeyChainConnection) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) RemoteException(android.os.RemoteException) X509Certificate(java.security.cert.X509Certificate)

Example 90 with UserHandle

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

the class DevicePolicyManagerService method startManagedQuickContact.

@Override
public void startManagedQuickContact(String actualLookupKey, long actualContactId, boolean isContactIdIgnored, long actualDirectoryId, Intent originalIntent) {
    final Intent intent = QuickContact.rebuildManagedQuickContactsIntent(actualLookupKey, actualContactId, isContactIdIgnored, actualDirectoryId, originalIntent);
    final int callingUserId = UserHandle.getCallingUserId();
    final long ident = mInjector.binderClearCallingIdentity();
    try {
        synchronized (this) {
            final int managedUserId = getManagedUserId(callingUserId);
            if (managedUserId < 0) {
                return;
            }
            if (isCrossProfileQuickContactDisabled(managedUserId)) {
                if (VERBOSE_LOG) {
                    Log.v(LOG_TAG, "Cross-profile contacts access disabled for user " + managedUserId);
                }
                return;
            }
            ContactsInternal.startQuickContactWithErrorToastForUser(mContext, intent, new UserHandle(managedUserId));
        }
    } finally {
        mInjector.binderRestoreCallingIdentity(ident);
    }
}
Also used : UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

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