Search in sources :

Example 46 with SystemApi

use of android.annotation.SystemApi in project android_frameworks_base by crdroidandroid.

the class AccountManager method startUpdateCredentialsSession.

/**
     * Asks the user to enter a new password for an account but not updating the
     * saved credentials for the account until {@link #finishSession} is called.
     * <p>
     * This method may be called from any thread, but the returned
     * {@link AccountManagerFuture} must not be used on the main thread.
     * <p>
     * <b>NOTE:</b> The saved credentials for the account alone will not be
     * updated by calling this API alone. #finishSession should be called after
     * this to update local credentials
     *
     * @param account The account to update credentials for
     * @param authTokenType The credentials entered must allow an auth token of
     *            this type to be created (but no actual auth token is
     *            returned); may be null
     * @param options Authenticator-specific options for the request; may be
     *            null or empty
     * @param activity The {@link Activity} context to use for launching a new
     *            authenticator-defined sub-Activity to prompt the user to enter
     *            a password; used only to call startActivity(); if null, the
     *            prompt will not be launched directly, but the necessary
     *            {@link Intent} will be returned to the caller instead
     * @param callback Callback to invoke when the request completes, null for
     *            no callback
     * @param handler {@link Handler} identifying the callback thread, null for
     *            the main thread
     * @return An {@link AccountManagerFuture} which resolves to a Bundle with
     *         these fields if an activity was supplied and user was
     *         successfully re-authenticated to the account:
     *         <ul>
     *         <li>{@link #KEY_ACCOUNT_SESSION_BUNDLE} - encrypted Bundle for
     *         updating the local credentials on device later.
     *         <li>{@link #KEY_ACCOUNT_STATUS_TOKEN} - optional, token to check
     *         status of the account
     *         </ul>
     *         If no activity was specified, the returned Bundle contains
     *         {@link #KEY_INTENT} with the {@link Intent} needed to launch the
     *         password prompt. If an error occurred,
     *         {@link AccountManagerFuture#getResult()} throws:
     *         <ul>
     *         <li>{@link AuthenticatorException} if the authenticator failed to
     *         respond
     *         <li>{@link OperationCanceledException} if the operation was
     *         canceled for any reason, including the user canceling the
     *         password prompt
     *         <li>{@link IOException} if the authenticator experienced an I/O
     *         problem verifying the password, usually because of network
     *         trouble
     *         </ul>
     * @see #finishSession
     * @hide
     */
@SystemApi
public AccountManagerFuture<Bundle> startUpdateCredentialsSession(final Account account, final String authTokenType, final Bundle options, final Activity activity, final AccountManagerCallback<Bundle> callback, final Handler handler) {
    if (account == null) {
        throw new IllegalArgumentException("account is null");
    }
    // Always include the calling package name. This just makes life easier
    // down stream.
    final Bundle optionsIn = new Bundle();
    if (options != null) {
        optionsIn.putAll(options);
    }
    optionsIn.putString(KEY_ANDROID_PACKAGE_NAME, mContext.getPackageName());
    return new AmsTask(activity, handler, callback) {

        @Override
        public void doWork() throws RemoteException {
            mService.startUpdateCredentialsSession(mResponse, account, authTokenType, activity != null, optionsIn);
        }
    }.start();
}
Also used : Bundle(android.os.Bundle) RemoteException(android.os.RemoteException) SystemApi(android.annotation.SystemApi)

Example 47 with SystemApi

use of android.annotation.SystemApi in project android_frameworks_base by AOSPA.

the class DevicePolicyManager method getDeviceOwner.

/**
     * Returns the device owner package name, only if it's running on the calling user.
     *
     * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
     *
     * @hide
     */
@SystemApi
public String getDeviceOwner() {
    throwIfParentInstance("getDeviceOwner");
    final ComponentName name = getDeviceOwnerComponentOnCallingUser();
    return name != null ? name.getPackageName() : null;
}
Also used : ComponentName(android.content.ComponentName) SystemApi(android.annotation.SystemApi)

Example 48 with SystemApi

use of android.annotation.SystemApi in project android_frameworks_base by AOSPA.

the class AbstractAccountAuthenticator method finishSession.

/**
     * Finishes the session started by #startAddAccountSession or
     * #startUpdateCredentials by installing the account to device with
     * AccountManager, or updating the local credentials. File I/O may be
     * performed in this call.
     * <p>
     * Note: when overriding this method, {@link #startAddAccountSession} and
     * {@link #startUpdateCredentialsSession} should be overridden too.
     * </p>
     *
     * @param response to send the result back to the AccountManager, will never
     *            be null
     * @param accountType the type of account to authenticate with, will never
     *            be null
     * @param sessionBundle a bundle of session data created by
     *            {@link #startAddAccountSession} used for adding account to
     *            device, or by {@link #startUpdateCredentialsSession} used for
     *            updating local credentials.
     * @return a Bundle result or null if the result is to be returned via the
     *         response. The result will contain either:
     *         <ul>
     *         <li>{@link AccountManager#KEY_INTENT}, or
     *         <li>{@link AccountManager#KEY_ACCOUNT_NAME} and
     *         {@link AccountManager#KEY_ACCOUNT_TYPE} of the account that was
     *         added or local credentials were updated, or
     *         <li>{@link AccountManager#KEY_ERROR_CODE} and
     *         {@link AccountManager#KEY_ERROR_MESSAGE} to indicate an error
     *         </ul>
     * @throws NetworkErrorException if the authenticator could not honor the request due to a
     *             network error
     * @see #startAddAccountSession and #startUpdateCredentialsSession
     * @hide
     */
@SystemApi
public Bundle finishSession(final AccountAuthenticatorResponse response, final String accountType, final Bundle sessionBundle) throws NetworkErrorException {
    if (TextUtils.isEmpty(accountType)) {
        Log.e(TAG, "Account type cannot be empty.");
        Bundle result = new Bundle();
        result.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_BAD_ARGUMENTS);
        result.putString(AccountManager.KEY_ERROR_MESSAGE, "accountType cannot be empty.");
        return result;
    }
    if (sessionBundle == null) {
        Log.e(TAG, "Session bundle cannot be null.");
        Bundle result = new Bundle();
        result.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_BAD_ARGUMENTS);
        result.putString(AccountManager.KEY_ERROR_MESSAGE, "sessionBundle cannot be null.");
        return result;
    }
    if (!sessionBundle.containsKey(KEY_AUTH_TOKEN_TYPE)) {
        // We cannot handle Session bundle not created by default startAddAccountSession(...)
        // nor startUpdateCredentialsSession(...) implementation. Return error.
        Bundle result = new Bundle();
        result.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION);
        result.putString(AccountManager.KEY_ERROR_MESSAGE, "Authenticator must override finishSession if startAddAccountSession" + " or startUpdateCredentialsSession is overridden.");
        response.onResult(result);
        return result;
    }
    String authTokenType = sessionBundle.getString(KEY_AUTH_TOKEN_TYPE);
    Bundle options = sessionBundle.getBundle(KEY_OPTIONS);
    String[] requiredFeatures = sessionBundle.getStringArray(KEY_REQUIRED_FEATURES);
    Account account = sessionBundle.getParcelable(KEY_ACCOUNT);
    boolean containsKeyAccount = sessionBundle.containsKey(KEY_ACCOUNT);
    // Actual options passed to add account or update credentials flow.
    Bundle sessionOptions = new Bundle(sessionBundle);
    // Remove redundant extras in session bundle before passing it to addAccount(...) or
    // updateCredentials(...).
    sessionOptions.remove(KEY_AUTH_TOKEN_TYPE);
    sessionOptions.remove(KEY_REQUIRED_FEATURES);
    sessionOptions.remove(KEY_OPTIONS);
    sessionOptions.remove(KEY_ACCOUNT);
    if (options != null) {
        // options may contains old system info such as
        // AccountManager.KEY_ANDROID_PACKAGE_NAME required by the add account flow or update
        // credentials flow, we should replace with the new values of the current call added
        // to sessionBundle by AccountManager or AccountManagerService.
        options.putAll(sessionOptions);
        sessionOptions = options;
    }
    // contain KEY_ACCOUNT.
    if (containsKeyAccount) {
        return updateCredentials(response, account, authTokenType, options);
    }
    // Otherwise, session bundle was created by startAddAccountSession default implementation.
    return addAccount(response, accountType, authTokenType, requiredFeatures, sessionOptions);
}
Also used : Bundle(android.os.Bundle) SystemApi(android.annotation.SystemApi)

Example 49 with SystemApi

use of android.annotation.SystemApi in project android_frameworks_base by AOSPA.

the class PackageItemInfo method loadSafeLabel.

/**
     * Same as {@link #loadLabel(PackageManager)} with the addition that
     * the returned label is safe for being presented in the UI since it
     * will not contain new lines and the length will be limited to a
     * reasonable amount. This prevents a malicious party to influence UI
     * layout via the app label misleading the user into performing a
     * detrimental for them action. If the label is too long it will be
     * truncated and ellipsized at the end.
     *
     * @param pm A PackageManager from which the label can be loaded; usually
     * the PackageManager from which you originally retrieved this item
     * @return Returns a CharSequence containing the item's label. If the
     * item does not have a label, its name is returned.
     *
     * @hide
     */
@SystemApi
@NonNull
public CharSequence loadSafeLabel(@NonNull PackageManager pm) {
    // loadLabel() always returns non-null
    String label = loadLabel(pm).toString();
    // strip HTML tags to avoid <br> and other tags overwriting original message
    String labelStr = Html.fromHtml(label).toString();
    // If the label contains new line characters it may push the UI
    // down to hide a part of it. Labels shouldn't have new line
    // characters, so just truncate at the first time one is seen.
    final int labelLength = labelStr.length();
    int offset = 0;
    while (offset < labelLength) {
        final int codePoint = labelStr.codePointAt(offset);
        final int type = Character.getType(codePoint);
        if (type == Character.LINE_SEPARATOR || type == Character.CONTROL || type == Character.PARAGRAPH_SEPARATOR) {
            labelStr = labelStr.substring(0, offset);
            break;
        }
        // replace all non-break space to " " in order to be trimmed
        if (type == Character.SPACE_SEPARATOR) {
            labelStr = labelStr.substring(0, offset) + " " + labelStr.substring(offset + Character.charCount(codePoint));
        }
        offset += Character.charCount(codePoint);
    }
    labelStr = labelStr.trim();
    if (labelStr.isEmpty()) {
        return packageName;
    }
    TextPaint paint = new TextPaint();
    paint.setTextSize(42);
    return TextUtils.ellipsize(labelStr, paint, MAX_LABEL_SIZE_PX, TextUtils.TruncateAt.END);
}
Also used : TextPaint(android.text.TextPaint) TextPaint(android.text.TextPaint) SystemApi(android.annotation.SystemApi) NonNull(android.annotation.NonNull)

Example 50 with SystemApi

use of android.annotation.SystemApi in project robolectric by robolectric.

the class ShadowWallpaperManager method setWallpaperComponent.

/**
 * Sets a live wallpaper, {@code wallpaperService}, as the current wallpaper.
 *
 * <p>This only caches the live wallpaper info in the memory. Calling this will remove any
 * previously set static wallpaper.
 */
@SystemApi
@Implementation(minSdk = VERSION_CODES.M)
@RequiresPermission(permission.SET_WALLPAPER_COMPONENT)
protected boolean setWallpaperComponent(ComponentName wallpaperService) throws IOException, XmlPullParserException {
    enforceWallpaperComponentPermission();
    Intent wallpaperServiceIntent = new Intent().setComponent(wallpaperService);
    List<ResolveInfo> resolveInfoList = RuntimeEnvironment.getApplication().getPackageManager().queryIntentServices(wallpaperServiceIntent, PackageManager.GET_META_DATA);
    if (resolveInfoList.size() != 1) {
        throw new IllegalArgumentException("Can't locate the given wallpaper service: " + wallpaperService);
    }
    wallpaperInfo = new WallpaperInfo(RuntimeEnvironment.getApplication(), resolveInfoList.get(0));
    lockScreenImage = null;
    homeScreenImage = null;
    return true;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Intent(android.content.Intent) WallpaperInfo(android.app.WallpaperInfo) SystemApi(android.annotation.SystemApi) RequiresPermission(android.annotation.RequiresPermission) Implementation(org.robolectric.annotation.Implementation)

Aggregations

SystemApi (android.annotation.SystemApi)96 Bundle (android.os.Bundle)36 RemoteException (android.os.RemoteException)33 INotificationManager (android.app.INotificationManager)10 RequiresPermission (android.annotation.RequiresPermission)6 ComponentName (android.content.ComponentName)6 NonNull (android.annotation.NonNull)5 Notification (android.app.Notification)5 AudioFormat (android.media.AudioFormat)5 AudioRecord (android.media.AudioRecord)5 AudioTrack (android.media.AudioTrack)5 Parcel (android.os.Parcel)5 TextPaint (android.text.TextPaint)5 FileWriter (java.io.FileWriter)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ITelecomService (com.android.internal.telecom.ITelecomService)4 ICarrierConfigLoader (com.android.internal.telephony.ICarrierConfigLoader)4 ITelephony (com.android.internal.telephony.ITelephony)4 Implementation (org.robolectric.annotation.Implementation)3