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();
}
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;
}
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);
}
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);
}
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;
}
Aggregations