use of android.annotation.SystemApi in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
the class AccountManager method startAddAccountSession.
/**
* Asks the user to authenticate with an account of a specified type. The
* authenticator for this account type processes this request with the
* appropriate user interface. If the user does elect to authenticate with a
* new account, a bundle of session data for installing the account later is
* returned with optional account password and account status token.
* <p>
* This method may be called from any thread, but the returned
* {@link AccountManagerFuture} must not be used on the main thread.
* <p>
* <p>
* <b>NOTE:</b> The account will not be installed to the device by calling
* this api alone. #finishSession should be called after this to install the
* account on device.
*
* @param accountType The type of account to add; must not be null
* @param authTokenType The type of auth token (see {@link #getAuthToken})
* this account will need to be able to generate, null for none
* @param requiredFeatures The features (see {@link #hasFeatures}) this
* account must have, null for none
* @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
* create an account; 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 activity was specified and user was authenticated
* with an account:
* <ul>
* <li>{@link #KEY_ACCOUNT_SESSION_BUNDLE} - encrypted Bundle for
* adding the the to the 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 only
* {@link #KEY_INTENT} with the {@link Intent} needed to launch the
* actual account creation process. If authenticator doesn't support
* this method, the returned Bundle contains only
* {@link #KEY_ACCOUNT_SESSION_BUNDLE} with encrypted
* {@code options} needed to add account later. If an error
* occurred, {@link AccountManagerFuture#getResult()} throws:
* <ul>
* <li>{@link AuthenticatorException} if no authenticator was
* registered for this account type or the authenticator failed to
* respond
* <li>{@link OperationCanceledException} if the operation was
* canceled for any reason, including the user canceling the
* creation process or adding accounts (of this type) has been
* disabled by policy
* <li>{@link IOException} if the authenticator experienced an I/O
* problem creating a new account, usually because of network
* trouble
* </ul>
* @see #finishSession
* @hide
*/
@SystemApi
public AccountManagerFuture<Bundle> startAddAccountSession(final String accountType, final String authTokenType, final String[] requiredFeatures, final Bundle options, final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
if (accountType == null)
throw new IllegalArgumentException("accountType is null");
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.startAddAccountSession(mResponse, accountType, authTokenType, requiredFeatures, activity != null, optionsIn);
}
}.start();
}
use of android.annotation.SystemApi in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
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 platform_frameworks_base by android.
the class RecoverySystem method installPackage.
/**
* If the package hasn't been processed (i.e. uncrypt'd), set up
* UNCRYPT_PACKAGE_FILE and delete BLOCK_MAP_FILE to trigger uncrypt during the
* reboot.
*
* @param context the Context to use
* @param packageFile the update package to install. Must be on a
* partition mountable by recovery.
* @param processed if the package has been processed (uncrypt'd).
*
* @throws IOException if writing the recovery command file fails, or if
* the reboot itself fails.
*
* @hide
*/
@SystemApi
public static void installPackage(Context context, File packageFile, boolean processed) throws IOException {
synchronized (sRequestLock) {
LOG_FILE.delete();
// Must delete the file in case it was created by system server.
UNCRYPT_PACKAGE_FILE.delete();
String filename = packageFile.getCanonicalPath();
Log.w(TAG, "!!! REBOOTING TO INSTALL " + filename + " !!!");
// If the package name ends with "_s.zip", it's a security update.
boolean securityUpdate = filename.endsWith("_s.zip");
// been done in 'processed' parameter.
if (filename.startsWith("/data/")) {
if (processed) {
if (!BLOCK_MAP_FILE.exists()) {
Log.e(TAG, "Package claimed to have been processed but failed to find " + "the block map file.");
throw new IOException("Failed to find block map file");
}
} else {
FileWriter uncryptFile = new FileWriter(UNCRYPT_PACKAGE_FILE);
try {
uncryptFile.write(filename + "\n");
} finally {
uncryptFile.close();
}
// by system server.
if (!UNCRYPT_PACKAGE_FILE.setReadable(true, false) || !UNCRYPT_PACKAGE_FILE.setWritable(true, false)) {
Log.e(TAG, "Error setting permission for " + UNCRYPT_PACKAGE_FILE);
}
BLOCK_MAP_FILE.delete();
}
// If the package is on the /data partition, use the block map
// file as the package name instead.
filename = "@/cache/recovery/block.map";
}
final String filenameArg = "--update_package=" + filename + "\n";
final String localeArg = "--locale=" + Locale.getDefault().toString() + "\n";
final String securityArg = "--security\n";
String command = filenameArg + localeArg;
if (securityUpdate) {
command += securityArg;
}
RecoverySystem rs = (RecoverySystem) context.getSystemService(Context.RECOVERY_SERVICE);
if (!rs.setupBcb(command)) {
throw new IOException("Setup BCB failed");
}
// Having set up the BCB (bootloader control block), go ahead and reboot
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
pm.reboot(PowerManager.REBOOT_RECOVERY_UPDATE);
throw new IOException("Reboot failed (no permissions?)");
}
}
Aggregations