Search in sources :

Example 31 with UserHandle

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

the class AccountManagerService method createNoCredentialsPermissionNotification.

private void createNoCredentialsPermissionNotification(Account account, Intent intent, String packageName, int userId) {
    int uid = intent.getIntExtra(GrantCredentialsPermissionActivity.EXTRAS_REQUESTING_UID, -1);
    String authTokenType = intent.getStringExtra(GrantCredentialsPermissionActivity.EXTRAS_AUTH_TOKEN_TYPE);
    final String titleAndSubtitle = mContext.getString(R.string.permission_request_notification_with_subtitle, account.name);
    final int index = titleAndSubtitle.indexOf('\n');
    String title = titleAndSubtitle;
    String subtitle = "";
    if (index > 0) {
        title = titleAndSubtitle.substring(0, index);
        subtitle = titleAndSubtitle.substring(index + 1);
    }
    UserHandle user = new UserHandle(userId);
    Context contextForUser = getContextForUser(user);
    Notification n = new Notification.Builder(contextForUser).setSmallIcon(android.R.drawable.stat_sys_warning).setWhen(0).setColor(contextForUser.getColor(com.android.internal.R.color.system_notification_accent_color)).setContentTitle(title).setContentText(subtitle).setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT, null, user)).build();
    installNotification(getCredentialPermissionNotificationId(account, authTokenType, uid), n, packageName, user.getIdentifier());
}
Also used : Context(android.content.Context) UserHandle(android.os.UserHandle) Notification(android.app.Notification)

Example 32 with UserHandle

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

the class AccountManagerService method sendAccountsChangedBroadcast.

private void sendAccountsChangedBroadcast(int userId) {
    Log.i(TAG, "the accounts changed, sending broadcast of " + ACCOUNTS_CHANGED_INTENT.getAction());
    mContext.sendBroadcastAsUser(ACCOUNTS_CHANGED_INTENT, new UserHandle(userId));
}
Also used : UserHandle(android.os.UserHandle)

Example 33 with UserHandle

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

the class AccountManagerService method doNotification.

private void doNotification(UserAccounts accounts, Account account, CharSequence message, Intent intent, String packageName, final int userId) {
    long identityToken = clearCallingIdentity();
    try {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "doNotification: " + message + " intent:" + intent);
        }
        if (intent.getComponent() != null && GrantCredentialsPermissionActivity.class.getName().equals(intent.getComponent().getClassName())) {
            createNoCredentialsPermissionNotification(account, intent, packageName, userId);
        } else {
            Context contextForUser = getContextForUser(new UserHandle(userId));
            final Integer notificationId = getSigninRequiredNotificationId(accounts, account);
            intent.addCategory(String.valueOf(notificationId));
            final String notificationTitleFormat = contextForUser.getText(R.string.notification_title).toString();
            Notification n = new Notification.Builder(contextForUser).setWhen(0).setSmallIcon(android.R.drawable.stat_sys_warning).setColor(contextForUser.getColor(com.android.internal.R.color.system_notification_accent_color)).setContentTitle(String.format(notificationTitleFormat, account.name)).setContentText(message).setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT, null, new UserHandle(userId))).build();
            installNotification(notificationId, n, packageName, userId);
        }
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
Also used : Context(android.content.Context) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UserHandle(android.os.UserHandle) Notification(android.app.Notification)

Example 34 with UserHandle

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

the class AccountManagerService method revokeAppPermission.

/**
     * Don't allow callers with the given uid permission to get credentials for
     * account/authTokenType.
     * <p>
     * Although this is public it can only be accessed via the AccountManagerService object
     * which is in the system. This means we don't need to protect it with permissions.
     * @hide
     */
private void revokeAppPermission(Account account, String authTokenType, int uid) {
    if (account == null || authTokenType == null) {
        Log.e(TAG, "revokeAppPermission: called with invalid arguments", new Exception());
        return;
    }
    UserAccounts accounts = getUserAccounts(UserHandle.getUserId(uid));
    synchronized (accounts.cacheLock) {
        final SQLiteDatabase db = accounts.openHelper.getWritableDatabase();
        db.beginTransaction();
        try {
            long accountId = getAccountIdLocked(db, account);
            if (accountId >= 0) {
                db.delete(TABLE_GRANTS, GRANTS_ACCOUNTS_ID + "=? AND " + GRANTS_AUTH_TOKEN_TYPE + "=? AND " + GRANTS_GRANTEE_UID + "=?", new String[] { String.valueOf(accountId), authTokenType, String.valueOf(uid) });
                db.setTransactionSuccessful();
            }
        } finally {
            db.endTransaction();
        }
        cancelNotification(getCredentialPermissionNotificationId(account, authTokenType, uid), new UserHandle(accounts.userId));
    }
    // Listeners are a final CopyOnWriteArrayList, hence no lock needed.
    for (AccountManagerInternal.OnAppPermissionChangeListener listener : mAppPermissionChangeListeners) {
        mMessageHandler.post(() -> listener.onAppPermissionChanged(account, uid));
    }
}
Also used : AccountManagerInternal(android.accounts.AccountManagerInternal) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) UserHandle(android.os.UserHandle) GeneralSecurityException(java.security.GeneralSecurityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 35 with UserHandle

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

the class ServiceRecord method postNotification.

public void postNotification() {
    final int appUid = appInfo.uid;
    final int appPid = app.pid;
    if (foregroundId != 0 && foregroundNoti != null) {
        // Do asynchronous communication with notification manager to
        // avoid deadlocks.
        final String localPackageName = packageName;
        final int localForegroundId = foregroundId;
        final Notification _foregroundNoti = foregroundNoti;
        ams.mHandler.post(new Runnable() {

            public void run() {
                NotificationManagerInternal nm = LocalServices.getService(NotificationManagerInternal.class);
                if (nm == null) {
                    return;
                }
                Notification localForegroundNoti = _foregroundNoti;
                try {
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // It is not correct for the caller to not supply a notification
                        // icon, but this used to be able to slip through, so for
                        // those dirty apps we will create a notification clearly
                        // blaming the app.
                        Slog.v(TAG, "Attempted to start a foreground service (" + name + ") with a broken notification (no icon: " + localForegroundNoti + ")");
                        CharSequence appName = appInfo.loadLabel(ams.mContext.getPackageManager());
                        if (appName == null) {
                            appName = appInfo.packageName;
                        }
                        Context ctx = null;
                        try {
                            ctx = ams.mContext.createPackageContextAsUser(appInfo.packageName, 0, new UserHandle(userId));
                            Notification.Builder notiBuilder = new Notification.Builder(ctx);
                            // it's ugly, but it clearly identifies the app
                            notiBuilder.setSmallIcon(appInfo.icon);
                            // mark as foreground
                            notiBuilder.setFlag(Notification.FLAG_FOREGROUND_SERVICE, true);
                            // we are doing the app a kindness here
                            notiBuilder.setPriority(Notification.PRIORITY_MIN);
                            Intent runningIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            runningIntent.setData(Uri.fromParts("package", appInfo.packageName, null));
                            PendingIntent pi = PendingIntent.getActivity(ams.mContext, 0, runningIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                            notiBuilder.setColor(ams.mContext.getColor(com.android.internal.R.color.system_notification_accent_color));
                            notiBuilder.setContentTitle(ams.mContext.getString(com.android.internal.R.string.app_running_notification_title, appName));
                            notiBuilder.setContentText(ams.mContext.getString(com.android.internal.R.string.app_running_notification_text, appName));
                            notiBuilder.setContentIntent(pi);
                            localForegroundNoti = notiBuilder.build();
                        } catch (PackageManager.NameNotFoundException e) {
                        }
                    }
                    if (localForegroundNoti.getSmallIcon() == null) {
                        // being foreground.
                        throw new RuntimeException("invalid service notification: " + foregroundNoti);
                    }
                    int[] outId = new int[1];
                    nm.enqueueNotification(localPackageName, localPackageName, appUid, appPid, null, localForegroundId, localForegroundNoti, outId, userId);
                    // save it for amending next time
                    foregroundNoti = localForegroundNoti;
                } catch (RuntimeException e) {
                    Slog.w(TAG, "Error showing notification for service", e);
                    // If it gave us a garbage notification, it doesn't
                    // get to be foreground.
                    ams.setServiceForeground(name, ServiceRecord.this, 0, null, 0);
                    ams.crashApplication(appUid, appPid, localPackageName, "Bad notification for startForeground: " + e);
                }
            }
        });
    }
}
Also used : NotificationManagerInternal(com.android.server.notification.NotificationManagerInternal) Context(android.content.Context) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent)

Aggregations

UserHandle (android.os.UserHandle)568 Intent (android.content.Intent)231 RemoteException (android.os.RemoteException)163 PendingIntent (android.app.PendingIntent)132 ComponentName (android.content.ComponentName)69 Context (android.content.Context)68 UserInfo (android.content.pm.UserInfo)66 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)62 Bundle (android.os.Bundle)50 IBinder (android.os.IBinder)49 UserManager (android.os.UserManager)44 PackageManager (android.content.pm.PackageManager)40 ApplicationInfo (android.content.pm.ApplicationInfo)30 IOException (java.io.IOException)30 ArrayList (java.util.ArrayList)30 ActivityNotFoundException (android.content.ActivityNotFoundException)28 Notification (android.app.Notification)27 ServiceConnection (android.content.ServiceConnection)27 IPackageManager (android.content.pm.IPackageManager)27 Pair (android.util.Pair)23