method public android.os.Bundle call(java.lang.String, java.lang.String, android.os.Bundle) throws android.os.RemoteException;
method public final android.net.Uri canonicalize(android.net.Uri) throws android.os.RemoteException;
method public void close();
+ method public static void closeQuietly(android.content.ContentProviderClient);
method public int delete(android.net.Uri, java.lang.String, java.lang.String[]) throws android.os.RemoteException;
method public android.content.ContentProvider getLocalContentProvider();
method public java.lang.String[] getStreamTypes(android.net.Uri, java.lang.String) throws android.os.RemoteException;
ctor public FileUriExposedException(java.lang.String);
}
+ public class FileUtils {
+ method public static void closeQuietly(java.lang.AutoCloseable);
+ method public static void closeQuietly(java.io.FileDescriptor);
+ method public static long copy(java.io.File, java.io.File) throws java.io.IOException;
+ method public static long copy(java.io.File, java.io.File, android.os.CancellationSignal, java.util.concurrent.Executor, android.os.FileUtils.ProgressListener) throws java.io.IOException;
+ method public static long copy(java.io.InputStream, java.io.OutputStream) throws java.io.IOException;
+ method public static long copy(java.io.InputStream, java.io.OutputStream, android.os.CancellationSignal, java.util.concurrent.Executor, android.os.FileUtils.ProgressListener) throws java.io.IOException;
+ method public static long copy(java.io.FileDescriptor, java.io.FileDescriptor) throws java.io.IOException;
+ method public static long copy(java.io.FileDescriptor, java.io.FileDescriptor, android.os.CancellationSignal, java.util.concurrent.Executor, android.os.FileUtils.ProgressListener) throws java.io.IOException;
+ }
+
+ public static abstract interface FileUtils.ProgressListener {
+ method public abstract void onProgress(long);
+ }
+
public class Handler {
ctor public Handler();
ctor public Handler(android.os.Handler.Callback);
method public java.lang.String getIccAuthentication(int, int, java.lang.String);
method public java.lang.String getImei();
method public java.lang.String getImei(int);
- method public java.lang.String getTypeAllocationCode();
- method public java.lang.String getTypeAllocationCode(int);
method public java.lang.String getLine1Number();
- method public java.lang.String getMeid();
- method public java.lang.String getMeid(int);
method public java.lang.String getManufacturerCode();
method public java.lang.String getManufacturerCode(int);
+ method public java.lang.String getMeid();
+ method public java.lang.String getMeid(int);
method public java.lang.String getMmsUAProfUrl();
method public java.lang.String getMmsUserAgent();
method public java.lang.String getNai();
method public int getSimState();
method public int getSimState(int);
method public java.lang.String getSubscriberId();
+ method public java.lang.String getTypeAllocationCode();
+ method public java.lang.String getTypeAllocationCode(int);
method public java.lang.String getVisualVoicemailPackageName();
method public java.lang.String getVoiceMailAlphaTag();
method public java.lang.String getVoiceMailNumber();
*/
private static final int MAX_REPLY_HISTORY = 5;
+ /**
+ * Maximum numbers of action buttons in a notification.
+ * @hide
+ */
+ public static final int MAX_ACTION_BUTTONS = 3;
/**
* If the notification contained an unsent draft for a RemoteInput when the user clicked on it,
public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT
= "android.rebuild.hudViewActionCount";
- private static final int MAX_ACTION_BUTTONS = 3;
-
private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY =
SystemProperties.getBoolean("notifications.only_title", true);
}
public static final class Message {
-
- static final String KEY_TEXT = "text";
+ /** @hide */
+ public static final String KEY_TEXT = "text";
static final String KEY_TIMESTAMP = "time";
static final String KEY_SENDER = "sender";
static final String KEY_SENDER_PERSON = "sender_person";
import dalvik.system.CloseGuard;
+import libcore.io.IoUtils;
+
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
return ContentProvider.coerceToLocalContentProvider(mContentProvider);
}
+ /**
+ * Closes the given object quietly, ignoring any checked exceptions. Does
+ * nothing if the given object is {@code null}.
+ */
+ public static void closeQuietly(ContentProviderClient client) {
+ IoUtils.closeQuietly(client);
+ }
+
/** {@hide} */
public static void releaseQuietly(ContentProviderClient client) {
- if (client != null) {
- try {
- client.release();
- } catch (Exception ignored) {
- }
- }
+ IoUtils.closeQuietly(client);
}
private class NotRespondingRunnable implements Runnable {
mAppId = in.readLong();
mAppVersion = in.readInt();
mVersionRestrictionMask = in.readInt();
- mAppIdVendorMask = in.readInt();
+ mAppIdVendorMask = in.readLong();
}
public int describeContents() {
}
public void writeToParcel(Parcel out, int flags) {
-
out.writeLong(mAppId);
out.writeInt(mAppVersion);
out.writeInt(mVersionRestrictionMask);
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;
+import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
/**
- * Tools for managing files. Not for public consumption.
- * @hide
+ * Utility methods useful for working with files.
*/
public class FileUtils {
private static final String TAG = "FileUtils";
- public static final int S_IRWXU = 00700;
- public static final int S_IRUSR = 00400;
- public static final int S_IWUSR = 00200;
- public static final int S_IXUSR = 00100;
+ /** {@hide} */ public static final int S_IRWXU = 00700;
+ /** {@hide} */ public static final int S_IRUSR = 00400;
+ /** {@hide} */ public static final int S_IWUSR = 00200;
+ /** {@hide} */ public static final int S_IXUSR = 00100;
- public static final int S_IRWXG = 00070;
- public static final int S_IRGRP = 00040;
- public static final int S_IWGRP = 00020;
- public static final int S_IXGRP = 00010;
+ /** {@hide} */ public static final int S_IRWXG = 00070;
+ /** {@hide} */ public static final int S_IRGRP = 00040;
+ /** {@hide} */ public static final int S_IWGRP = 00020;
+ /** {@hide} */ public static final int S_IXGRP = 00010;
- public static final int S_IRWXO = 00007;
- public static final int S_IROTH = 00004;
- public static final int S_IWOTH = 00002;
- public static final int S_IXOTH = 00001;
+ /** {@hide} */ public static final int S_IRWXO = 00007;
+ /** {@hide} */ public static final int S_IROTH = 00004;
+ /** {@hide} */ public static final int S_IWOTH = 00002;
+ /** {@hide} */ public static final int S_IXOTH = 00001;
+
+ private FileUtils() {
+ }
/** Regular expression for safe filenames: no spaces or metacharacters.
*
private static final long COPY_CHECKPOINT_BYTES = 524288;
+ /**
+ * Listener that is called periodically as progress is made.
+ */
public interface ProgressListener {
public void onProgress(long progress);
}
* @param uid to apply through {@code chown}, or -1 to leave unchanged
* @param gid to apply through {@code chown}, or -1 to leave unchanged
* @return 0 on success, otherwise errno.
+ * @hide
*/
public static int setPermissions(File path, int mode, int uid, int gid) {
return setPermissions(path.getAbsolutePath(), mode, uid, gid);
* @param uid to apply through {@code chown}, or -1 to leave unchanged
* @param gid to apply through {@code chown}, or -1 to leave unchanged
* @return 0 on success, otherwise errno.
+ * @hide
*/
public static int setPermissions(String path, int mode, int uid, int gid) {
try {
* @param uid to apply through {@code chown}, or -1 to leave unchanged
* @param gid to apply through {@code chown}, or -1 to leave unchanged
* @return 0 on success, otherwise errno.
+ * @hide
*/
public static int setPermissions(FileDescriptor fd, int mode, int uid, int gid) {
try {
return 0;
}
- public static void copyPermissions(File from, File to) throws IOException {
+ /**
+ * Copy the owner UID, owner GID, and mode bits from one file to another.
+ *
+ * @param from File where attributes should be copied from.
+ * @param to File where attributes should be copied to.
+ * @hide
+ */
+ public static void copyPermissions(@NonNull File from, @NonNull File to) throws IOException {
try {
final StructStat stat = Os.stat(from.getAbsolutePath());
Os.chmod(to.getAbsolutePath(), stat.st_mode);
}
/**
- * Return owning UID of given path, otherwise -1.
+ * @deprecated use {@link Os#stat(String)} instead.
+ * @hide
*/
+ @Deprecated
public static int getUid(String path) {
try {
return Os.stat(path).st_uid;
/**
* Perform an fsync on the given FileOutputStream. The stream at this
* point must be flushed but not yet closed.
+ *
+ * @hide
*/
public static boolean sync(FileOutputStream stream) {
try {
/**
* @deprecated use {@link #copy(File, File)} instead.
+ * @hide
*/
@Deprecated
public static boolean copyFile(File srcFile, File destFile) {
/**
* @deprecated use {@link #copy(File, File)} instead.
+ * @hide
*/
@Deprecated
public static void copyFileOrThrow(File srcFile, File destFile) throws IOException {
/**
* @deprecated use {@link #copy(InputStream, OutputStream)} instead.
+ * @hide
*/
@Deprecated
public static boolean copyToFile(InputStream inputStream, File destFile) {
/**
* @deprecated use {@link #copy(InputStream, OutputStream)} instead.
+ * @hide
*/
@Deprecated
public static void copyToFileOrThrow(InputStream in, File destFile) throws IOException {
* @return number of bytes copied.
*/
public static long copy(@NonNull File from, @NonNull File to) throws IOException {
- return copy(from, to, null, null);
+ return copy(from, to, null, null, null);
}
/**
* Attempts to use several optimization strategies to copy the data in the
* kernel before falling back to a userspace copy as a last resort.
*
- * @param listener to be periodically notified as the copy progresses.
* @param signal to signal if the copy should be cancelled early.
+ * @param executor that listener events should be delivered via.
+ * @param listener to be periodically notified as the copy progresses.
* @return number of bytes copied.
*/
public static long copy(@NonNull File from, @NonNull File to,
- @Nullable ProgressListener listener, @Nullable CancellationSignal signal)
- throws IOException {
+ @Nullable CancellationSignal signal, @Nullable Executor executor,
+ @Nullable ProgressListener listener) throws IOException {
try (FileInputStream in = new FileInputStream(from);
FileOutputStream out = new FileOutputStream(to)) {
- return copy(in, out, listener, signal);
+ return copy(in, out, signal, executor, listener);
}
}
* @return number of bytes copied.
*/
public static long copy(@NonNull InputStream in, @NonNull OutputStream out) throws IOException {
- return copy(in, out, null, null);
+ return copy(in, out, null, null, null);
}
/**
* Attempts to use several optimization strategies to copy the data in the
* kernel before falling back to a userspace copy as a last resort.
*
- * @param listener to be periodically notified as the copy progresses.
* @param signal to signal if the copy should be cancelled early.
+ * @param executor that listener events should be delivered via.
+ * @param listener to be periodically notified as the copy progresses.
* @return number of bytes copied.
*/
public static long copy(@NonNull InputStream in, @NonNull OutputStream out,
- @Nullable ProgressListener listener, @Nullable CancellationSignal signal)
- throws IOException {
+ @Nullable CancellationSignal signal, @Nullable Executor executor,
+ @Nullable ProgressListener listener) throws IOException {
if (ENABLE_COPY_OPTIMIZATIONS) {
if (in instanceof FileInputStream && out instanceof FileOutputStream) {
return copy(((FileInputStream) in).getFD(), ((FileOutputStream) out).getFD(),
- listener, signal);
+ signal, executor, listener);
}
}
// Worse case fallback to userspace
- return copyInternalUserspace(in, out, listener, signal);
+ return copyInternalUserspace(in, out, signal, executor, listener);
}
/**
*/
public static long copy(@NonNull FileDescriptor in, @NonNull FileDescriptor out)
throws IOException {
- return copy(in, out, null, null);
+ return copy(in, out, null, null, null);
}
/**
* Attempts to use several optimization strategies to copy the data in the
* kernel before falling back to a userspace copy as a last resort.
*
- * @param listener to be periodically notified as the copy progresses.
* @param signal to signal if the copy should be cancelled early.
+ * @param executor that listener events should be delivered via.
+ * @param listener to be periodically notified as the copy progresses.
* @return number of bytes copied.
*/
public static long copy(@NonNull FileDescriptor in, @NonNull FileDescriptor out,
- @Nullable ProgressListener listener, @Nullable CancellationSignal signal)
- throws IOException {
- return copy(in, out, listener, signal, Long.MAX_VALUE);
+ @Nullable CancellationSignal signal, @Nullable Executor executor,
+ @Nullable ProgressListener listener) throws IOException {
+ return copy(in, out, Long.MAX_VALUE, signal, executor, listener);
}
/**
* Attempts to use several optimization strategies to copy the data in the
* kernel before falling back to a userspace copy as a last resort.
*
- * @param listener to be periodically notified as the copy progresses.
- * @param signal to signal if the copy should be cancelled early.
* @param count the number of bytes to copy.
+ * @param signal to signal if the copy should be cancelled early.
+ * @param executor that listener events should be delivered via.
+ * @param listener to be periodically notified as the copy progresses.
* @return number of bytes copied.
+ * @hide
*/
- public static long copy(@NonNull FileDescriptor in, @NonNull FileDescriptor out,
- @Nullable ProgressListener listener, @Nullable CancellationSignal signal, long count)
- throws IOException {
+ public static long copy(@NonNull FileDescriptor in, @NonNull FileDescriptor out, long count,
+ @Nullable CancellationSignal signal, @Nullable Executor executor,
+ @Nullable ProgressListener listener) throws IOException {
if (ENABLE_COPY_OPTIMIZATIONS) {
try {
final StructStat st_in = Os.fstat(in);
final StructStat st_out = Os.fstat(out);
if (S_ISREG(st_in.st_mode) && S_ISREG(st_out.st_mode)) {
- return copyInternalSendfile(in, out, listener, signal, count);
+ return copyInternalSendfile(in, out, count, signal, executor, listener);
} else if (S_ISFIFO(st_in.st_mode) || S_ISFIFO(st_out.st_mode)) {
- return copyInternalSplice(in, out, listener, signal, count);
+ return copyInternalSplice(in, out, count, signal, executor, listener);
}
} catch (ErrnoException e) {
throw e.rethrowAsIOException();
}
// Worse case fallback to userspace
- return copyInternalUserspace(in, out, listener, signal, count);
+ return copyInternalUserspace(in, out, count, signal, executor, listener);
}
/**
* Requires one of input or output to be a pipe.
+ *
+ * @hide
*/
@VisibleForTesting
- public static long copyInternalSplice(FileDescriptor in, FileDescriptor out,
- ProgressListener listener, CancellationSignal signal, long count)
+ public static long copyInternalSplice(FileDescriptor in, FileDescriptor out, long count,
+ CancellationSignal signal, Executor executor, ProgressListener listener)
throws ErrnoException {
long progress = 0;
long checkpoint = 0;
if (signal != null) {
signal.throwIfCanceled();
}
- if (listener != null) {
- listener.onProgress(progress);
+ if (executor != null && listener != null) {
+ final long progressSnapshot = progress;
+ executor.execute(() -> {
+ listener.onProgress(progressSnapshot);
+ });
}
checkpoint = 0;
}
}
- if (listener != null) {
- listener.onProgress(progress);
+ if (executor != null && listener != null) {
+ final long progressSnapshot = progress;
+ executor.execute(() -> {
+ listener.onProgress(progressSnapshot);
+ });
}
return progress;
}
/**
* Requires both input and output to be a regular file.
+ *
+ * @hide
*/
@VisibleForTesting
- public static long copyInternalSendfile(FileDescriptor in, FileDescriptor out,
- ProgressListener listener, CancellationSignal signal, long count)
+ public static long copyInternalSendfile(FileDescriptor in, FileDescriptor out, long count,
+ CancellationSignal signal, Executor executor, ProgressListener listener)
throws ErrnoException {
long progress = 0;
long checkpoint = 0;
if (signal != null) {
signal.throwIfCanceled();
}
- if (listener != null) {
- listener.onProgress(progress);
+ if (executor != null && listener != null) {
+ final long progressSnapshot = progress;
+ executor.execute(() -> {
+ listener.onProgress(progressSnapshot);
+ });
}
checkpoint = 0;
}
}
- if (listener != null) {
- listener.onProgress(progress);
+ if (executor != null && listener != null) {
+ final long progressSnapshot = progress;
+ executor.execute(() -> {
+ listener.onProgress(progressSnapshot);
+ });
}
return progress;
}
+ /** {@hide} */
+ @Deprecated
@VisibleForTesting
public static long copyInternalUserspace(FileDescriptor in, FileDescriptor out,
- ProgressListener listener, CancellationSignal signal, long count) throws IOException {
+ ProgressListener listener, CancellationSignal signal, long count)
+ throws IOException {
+ return copyInternalUserspace(in, out, count, signal, Runnable::run, listener);
+ }
+
+ /** {@hide} */
+ @VisibleForTesting
+ public static long copyInternalUserspace(FileDescriptor in, FileDescriptor out, long count,
+ CancellationSignal signal, Executor executor, ProgressListener listener)
+ throws IOException {
if (count != Long.MAX_VALUE) {
return copyInternalUserspace(new SizedInputStream(new FileInputStream(in), count),
- new FileOutputStream(out), listener, signal);
+ new FileOutputStream(out), signal, executor, listener);
} else {
return copyInternalUserspace(new FileInputStream(in),
- new FileOutputStream(out), listener, signal);
+ new FileOutputStream(out), signal, executor, listener);
}
}
+ /** {@hide} */
@VisibleForTesting
public static long copyInternalUserspace(InputStream in, OutputStream out,
- ProgressListener listener, CancellationSignal signal) throws IOException {
+ CancellationSignal signal, Executor executor, ProgressListener listener)
+ throws IOException {
long progress = 0;
long checkpoint = 0;
byte[] buffer = new byte[8192];
if (signal != null) {
signal.throwIfCanceled();
}
- if (listener != null) {
- listener.onProgress(progress);
+ if (executor != null && listener != null) {
+ final long progressSnapshot = progress;
+ executor.execute(() -> {
+ listener.onProgress(progressSnapshot);
+ });
}
checkpoint = 0;
}
}
- if (listener != null) {
- listener.onProgress(progress);
+ if (executor != null && listener != null) {
+ final long progressSnapshot = progress;
+ executor.execute(() -> {
+ listener.onProgress(progressSnapshot);
+ });
}
return progress;
}
/**
* Check if a filename is "safe" (no metacharacters or spaces).
* @param file The file to check
+ * @hide
*/
public static boolean isFilenameSafe(File file) {
// Note, we check whether it matches what's known to be safe,
* @param ellipsis to add of the file was truncated (can be null)
* @return the contents of the file, possibly truncated
* @throws IOException if something goes wrong reading the file
+ * @hide
*/
public static String readTextFile(File file, int max, String ellipsis) throws IOException {
InputStream input = new FileInputStream(file);
}
}
+ /** {@hide} */
public static void stringToFile(File file, String string) throws IOException {
stringToFile(file.getAbsolutePath(), string);
}
- /*
+ /**
* Writes the bytes given in {@code content} to the file whose absolute path
* is {@code filename}.
+ *
+ * @hide
*/
public static void bytesToFile(String filename, byte[] content) throws IOException {
if (filename.startsWith("/proc/")) {
* @param filename
* @param string
* @throws IOException
+ * @hide
*/
public static void stringToFile(String filename, String string) throws IOException {
bytesToFile(filename, string.getBytes(StandardCharsets.UTF_8));
}
/**
- * Computes the checksum of a file using the CRC32 checksum routine.
- * The value of the checksum is returned.
+ * Computes the checksum of a file using the CRC32 checksum routine. The
+ * value of the checksum is returned.
*
- * @param file the file to checksum, must not be null
+ * @param file the file to checksum, must not be null
* @return the checksum value or an exception is thrown.
+ * @deprecated this is a weak hashing algorithm, and should not be used due
+ * to its potential for collision.
+ * @hide
*/
+ @Deprecated
public static long checksumCrc32(File file) throws FileNotFoundException, IOException {
CRC32 checkSummer = new CRC32();
CheckedInputStream cis = null;
* @param minCount Always keep at least this many files.
* @param minAgeMs Always keep files younger than this age, in milliseconds.
* @return if any files were deleted.
+ * @hide
*/
public static boolean deleteOlderFiles(File dir, int minCount, long minAgeMs) {
if (minCount < 0 || minAgeMs < 0) {
* Both files <em>must</em> have been resolved using
* {@link File#getCanonicalFile()} to avoid symlink or path traversal
* attacks.
+ *
+ * @hide
*/
public static boolean contains(File[] dirs, File file) {
for (File dir : dirs) {
* Both files <em>must</em> have been resolved using
* {@link File#getCanonicalFile()} to avoid symlink or path traversal
* attacks.
+ *
+ * @hide
*/
public static boolean contains(File dir, File file) {
if (dir == null || file == null) return false;
return contains(dir.getAbsolutePath(), file.getAbsolutePath());
}
+ /** {@hide} */
public static boolean contains(String dirPath, String filePath) {
if (dirPath.equals(filePath)) {
return true;
return filePath.startsWith(dirPath);
}
+ /** {@hide} */
public static boolean deleteContentsAndDir(File dir) {
if (deleteContents(dir)) {
return dir.delete();
}
}
+ /** {@hide} */
public static boolean deleteContents(File dir) {
File[] files = dir.listFiles();
boolean success = true;
/**
* Check if given filename is valid for an ext4 filesystem.
+ *
+ * @hide
*/
public static boolean isValidExtFilename(String name) {
return (name != null) && name.equals(buildValidExtFilename(name));
/**
* Mutate the given filename to make it valid for an ext4 filesystem,
* replacing any invalid characters with "_".
+ *
+ * @hide
*/
public static String buildValidExtFilename(String name) {
if (TextUtils.isEmpty(name) || ".".equals(name) || "..".equals(name)) {
/**
* Check if given filename is valid for a FAT filesystem.
+ *
+ * @hide
*/
public static boolean isValidFatFilename(String name) {
return (name != null) && name.equals(buildValidFatFilename(name));
/**
* Mutate the given filename to make it valid for a FAT filesystem,
* replacing any invalid characters with "_".
+ *
+ * @hide
*/
public static String buildValidFatFilename(String name) {
if (TextUtils.isEmpty(name) || ".".equals(name) || "..".equals(name)) {
return res.toString();
}
+ /** {@hide} */
@VisibleForTesting
public static String trimFilename(String str, int maxBytes) {
final StringBuilder res = new StringBuilder(str);
return res.toString();
}
+ /** {@hide} */
private static void trimFilename(StringBuilder res, int maxBytes) {
byte[] raw = res.toString().getBytes(StandardCharsets.UTF_8);
if (raw.length > maxBytes) {
}
}
+ /** {@hide} */
public static String rewriteAfterRename(File beforeDir, File afterDir, String path) {
if (path == null) return null;
final File result = rewriteAfterRename(beforeDir, afterDir, new File(path));
return (result != null) ? result.getAbsolutePath() : null;
}
+ /** {@hide} */
public static String[] rewriteAfterRename(File beforeDir, File afterDir, String[] paths) {
if (paths == null) return null;
final String[] result = new String[paths.length];
* Given a path under the "before" directory, rewrite it to live under the
* "after" directory. For example, {@code /before/foo/bar.txt} would become
* {@code /after/foo/bar.txt}.
+ *
+ * @hide
*/
public static File rewriteAfterRename(File beforeDir, File afterDir, File file) {
if (file == null || beforeDir == null || afterDir == null) return null;
return null;
}
+ /** {@hide} */
private static File buildUniqueFileWithExtension(File parent, String name, String ext)
throws FileNotFoundException {
File file = buildFile(parent, name, ext);
* 'example.txt' or 'example (1).txt', etc.
*
* @throws FileNotFoundException
+ * @hide
*/
public static File buildUniqueFile(File parent, String mimeType, String displayName)
throws FileNotFoundException {
/**
* Generates a unique file name under the given parent directory, keeping
* any extension intact.
+ *
+ * @hide
*/
public static File buildUniqueFile(File parent, String displayName)
throws FileNotFoundException {
* If the display name doesn't have an extension that matches the requested MIME type, the
* extension is regarded as a part of filename and default extension for that MIME type is
* appended.
+ *
+ * @hide
*/
public static String[] splitFileName(String mimeType, String displayName) {
String name;
return new String[] { name, ext };
}
+ /** {@hide} */
private static File buildFile(File parent, String name, String ext) {
if (TextUtils.isEmpty(ext)) {
return new File(parent, name);
}
}
+ /** {@hide} */
public static @NonNull String[] listOrEmpty(@Nullable File dir) {
if (dir == null) return EmptyArray.STRING;
final String[] res = dir.list();
}
}
+ /** {@hide} */
public static @NonNull File[] listFilesOrEmpty(@Nullable File dir) {
if (dir == null) return EMPTY;
final File[] res = dir.listFiles();
}
}
+ /** {@hide} */
public static @NonNull File[] listFilesOrEmpty(@Nullable File dir, FilenameFilter filter) {
if (dir == null) return EMPTY;
final File[] res = dir.listFiles(filter);
}
}
+ /** {@hide} */
public static @Nullable File newFileOrNull(@Nullable String path) {
return (path != null) ? new File(path) : null;
}
* Creates a directory with name {@code name} under an existing directory {@code baseDir}.
* Returns a {@code File} object representing the directory on success, {@code null} on
* failure.
+ *
+ * @hide
*/
public static @Nullable File createDir(File baseDir, String name) {
final File dir = new File(baseDir, name);
* Round the given size of a storage device to a nice round power-of-two
* value, such as 256MB or 32GB. This avoids showing weird values like
* "29.5GB" in UI.
+ *
+ * @hide
*/
public static long roundStorageSize(long size) {
long val = 1;
return val * pow;
}
+ /**
+ * Closes the given object quietly, ignoring any checked exceptions. Does
+ * nothing if the given object is {@code null}.
+ */
+ public static void closeQuietly(@Nullable AutoCloseable closeable) {
+ IoUtils.closeQuietly(closeable);
+ }
+
+ /**
+ * Closes the given object quietly, ignoring any checked exceptions. Does
+ * nothing if the given object is {@code null}.
+ */
+ public static void closeQuietly(@Nullable FileDescriptor fd) {
+ IoUtils.closeQuietly(fd);
+ }
+
+ /** {@hide} */
@VisibleForTesting
public static class MemoryPipe extends Thread implements AutoCloseable {
private final FileDescriptor[] pipe;
protected Void doInBackground(Void... params) {
try (InputStream in = new FileInputStream(mFile);
OutputStream out = new FileOutputStream(mDestination.getFileDescriptor())) {
- FileUtils.copy(in, out, null, mCancellationSignal);
+ FileUtils.copy(in, out, mCancellationSignal, null, null);
} catch (OperationCanceledException e) {
// Ignored; already handled below
} catch (IOException e) {
public static final String PROVIDER_INTERFACE = "android.content.action.DOCUMENTS_PROVIDER";
/** {@hide} */
- public static final String EXTRA_PACKAGE_NAME = "android.content.extra.PACKAGE_NAME";
+ @Deprecated
+ public static final String EXTRA_PACKAGE_NAME = Intent.EXTRA_PACKAGE_NAME;
/** {@hide} */
public static final String EXTRA_SHOW_ADVANCED = "android.content.extra.SHOW_ADVANCED";
package android.util;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-import org.apache.harmony.xml.ExpatReader;
-import org.kxml2.io.KXmlParser;
+import libcore.util.XmlObjectFactory;
+
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+
/**
* XML utility methods.
*/
public class Xml {
- /** @hide */ public Xml() {}
+ private Xml() {}
/**
* {@link org.xmlpull.v1.XmlPullParser} "relaxed" feature name.
public static void parse(String xml, ContentHandler contentHandler)
throws SAXException {
try {
- XMLReader reader = new ExpatReader();
+ XMLReader reader = XmlObjectFactory.newXMLReader();
reader.setContentHandler(contentHandler);
reader.parse(new InputSource(new StringReader(xml)));
} catch (IOException e) {
*/
public static void parse(Reader in, ContentHandler contentHandler)
throws IOException, SAXException {
- XMLReader reader = new ExpatReader();
+ XMLReader reader = XmlObjectFactory.newXMLReader();
reader.setContentHandler(contentHandler);
reader.parse(new InputSource(in));
}
*/
public static void parse(InputStream in, Encoding encoding,
ContentHandler contentHandler) throws IOException, SAXException {
- XMLReader reader = new ExpatReader();
+ XMLReader reader = XmlObjectFactory.newXMLReader();
reader.setContentHandler(contentHandler);
InputSource source = new InputSource(in);
source.setEncoding(encoding.expatName);
*/
public static XmlPullParser newPullParser() {
try {
- KXmlParser parser = new KXmlParser();
+ XmlPullParser parser = XmlObjectFactory.newXmlPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
return parser;
* Creates a new xml serializer.
*/
public static XmlSerializer newSerializer() {
- try {
- return XmlSerializerFactory.instance.newSerializer();
- } catch (XmlPullParserException e) {
- throw new AssertionError(e);
- }
- }
-
- /** Factory for xml serializers. Initialized on demand. */
- static class XmlSerializerFactory {
- static final String TYPE
- = "org.kxml2.io.KXmlParser,org.kxml2.io.KXmlSerializer";
- static final XmlPullParserFactory instance;
- static {
- try {
- instance = XmlPullParserFactory.newInstance(TYPE, null);
- } catch (XmlPullParserException e) {
- throw new AssertionError(e);
- }
- }
+ return XmlObjectFactory.newXmlSerializer();
}
/**
*/
public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
if ((event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED)
- && !TextUtils.isEmpty(getAccessibilityPaneTitle())) {
+ && isAccessibilityPane()) {
event.getText().add(getAccessibilityPaneTitle());
}
}
}
}
}
- if (!TextUtils.isEmpty(getAccessibilityPaneTitle())) {
+ if (isAccessibilityPane()) {
if (isVisible != oldVisible) {
notifyViewAccessibilityStateChangedIfNeeded(isVisible
? AccessibilityEvent.CONTENT_CHANGE_TYPE_PANE_APPEARED
"external/skia/src/image",
"external/skia/src/images",
"frameworks/base/media/jni",
- "libcore/include",
"system/media/camera/include",
"system/media/private/camera/include",
],
#define LOG_TAG "MeasuredParagraph"
#include "GraphicsJNI.h"
-#include "ScopedIcuLocale.h"
#include "unicode/locid.h"
#include "unicode/brkiter.h"
#include "utils/misc.h"
#define LOG_TAG "StaticLayout"
-#include "ScopedIcuLocale.h"
#include "unicode/locid.h"
#include "unicode/brkiter.h"
#include "utils/misc.h"
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
+ <bool name="config_showAreaUpdateInfoSettings">true</bool>
+</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
+ <bool name="config_showAreaUpdateInfoSettings">true</bool>
+</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
+ <bool name="config_showAreaUpdateInfoSettings">true</bool>
+</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
+ <bool name="config_showAreaUpdateInfoSettings">true</bool>
+</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
+ <bool name="config_showAreaUpdateInfoSettings">true</bool>
+</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
+ <bool name="config_showAreaUpdateInfoSettings">true</bool>
+</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
+ <bool name="config_showAreaUpdateInfoSettings">true</bool>
+</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
+ <bool name="config_showAreaUpdateInfoSettings">true</bool>
+</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
+ <bool name="config_showAreaUpdateInfoSettings">true</bool>
+</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
+ <bool name="config_showAreaUpdateInfoSettings">true</bool>
+</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
+ <bool name="config_showAreaUpdateInfoSettings">true</bool>
+</resources>
for (int i = 0; i < reps; i++) {
try (FileInputStream in = new FileInputStream(mSrc);
FileOutputStream out = new FileOutputStream(mDest)) {
- copyInternalUserspace(in.getFD(), out.getFD(), null, null, Long.MAX_VALUE);
+ copyInternalUserspace(in.getFD(), out.getFD(), Long.MAX_VALUE, null, null, null);
}
}
}
for (int i = 0; i < reps; i++) {
try (FileInputStream in = new FileInputStream(mSrc);
FileOutputStream out = new FileOutputStream(mDest)) {
- copyInternalSendfile(in.getFD(), out.getFD(), null, null, Long.MAX_VALUE);
+ copyInternalSendfile(in.getFD(), out.getFD(), Long.MAX_VALUE, null, null, null);
}
}
}
for (int i = 0; i < reps; i++) {
try (MemoryPipe in = MemoryPipe.createSource(mData);
FileOutputStream out = new FileOutputStream(mDest)) {
- copyInternalUserspace(in.getFD(), out.getFD(), null, null, Long.MAX_VALUE);
+ copyInternalUserspace(in.getFD(), out.getFD(), Long.MAX_VALUE, null, null, null);
}
}
}
for (int i = 0; i < reps; i++) {
try (MemoryPipe in = MemoryPipe.createSource(mData);
FileOutputStream out = new FileOutputStream(mDest)) {
- copyInternalSplice(in.getFD(), out.getFD(), null, null, Long.MAX_VALUE);
+ copyInternalSplice(in.getFD(), out.getFD(), Long.MAX_VALUE, null, null, null);
}
}
}
for (int i = 0; i < reps; i++) {
try (FileInputStream in = new FileInputStream(mSrc);
MemoryPipe out = MemoryPipe.createSink(mData)) {
- copyInternalUserspace(in.getFD(), out.getFD(), null, null, Long.MAX_VALUE);
+ copyInternalUserspace(in.getFD(), out.getFD(), Long.MAX_VALUE, null, null, null);
}
}
}
for (int i = 0; i < reps; i++) {
try (FileInputStream in = new FileInputStream(mSrc);
MemoryPipe out = MemoryPipe.createSink(mData)) {
- copyInternalSplice(in.getFD(), out.getFD(), null, null, Long.MAX_VALUE);
+ copyInternalSplice(in.getFD(), out.getFD(), Long.MAX_VALUE, null, null, null);
}
}
}
try (MemoryPipe in = MemoryPipe.createSource(source);
FileOutputStream out = new FileOutputStream(dest)) {
- FileUtils.copy(in.getFD(), out.getFD(), null, null, size);
+ FileUtils.copy(in.getFD(), out.getFD(), size, null, null, null);
}
actual = readFile(dest);
device_uses_hwc2: {
cflags: ["-DUSE_HWC2"],
},
+ eng: {
+ lto: {
+ never: true,
+ },
+ },
},
}
import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE;
+import android.annotation.NonNull;
import android.app.INotificationManager;
+import android.app.Notification;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
private float mDismissToViewRatioLimit;
private int mStreakLimit;
+ private SmartActionsHelper mSmartActionsHelper;
// key : impressions tracker
// TODO: prune deleted channels and apps
// Contexts are correctly hooked up by the creation step, which is required for the observer
// to be hooked up/initialized.
new SettingsObserver(mHandler);
+ mSmartActionsHelper = new SmartActionsHelper();
}
private void loadFile() {
@Override
public Adjustment onNotificationEnqueued(StatusBarNotification sbn) {
if (DEBUG) Log.i(TAG, "ENQUEUED " + sbn.getKey());
- return null;
+ ArrayList<Notification.Action> actions =
+ mSmartActionsHelper.suggestActions(this, sbn);
+ if (actions.isEmpty()) {
+ return null;
+ }
+ return createEnqueuedNotificationAdjustment(sbn, actions);
+ }
+
+ /** A convenience helper for creating an adjustment for an SBN. */
+ private Adjustment createEnqueuedNotificationAdjustment(
+ @NonNull StatusBarNotification statusBarNotification,
+ @NonNull ArrayList<Notification.Action> smartActions) {
+ Bundle signals = new Bundle();
+ signals.putParcelableArrayList(Adjustment.KEY_SMART_ACTIONS, smartActions);
+ return new Adjustment(
+ statusBarNotification.getPackageName(),
+ statusBarNotification.getKey(),
+ signals,
+ "smart action" /* explanation */,
+ statusBarNotification.getUserId());
}
@Override
}
}
}
-}
\ No newline at end of file
+}
--- /dev/null
+/**
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.ext.services.notification;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.app.Notification;
+import android.app.RemoteAction;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.service.notification.StatusBarNotification;
+import android.text.TextUtils;
+import android.util.ArrayMap;
+import android.view.textclassifier.TextClassification;
+import android.view.textclassifier.TextClassificationManager;
+import android.view.textclassifier.TextClassifier;
+import android.view.textclassifier.TextLinks;
+
+import com.android.internal.util.Preconditions;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+public class SmartActionsHelper {
+ private static final ArrayList<Notification.Action> EMPTY_LIST = new ArrayList<>();
+
+ // If a notification has any of these flags set, it's inelgibile for actions being added.
+ private static final int FLAG_MASK_INELGIBILE_FOR_ACTIONS =
+ Notification.FLAG_ONGOING_EVENT
+ | Notification.FLAG_FOREGROUND_SERVICE
+ | Notification.FLAG_GROUP_SUMMARY
+ | Notification.FLAG_NO_CLEAR;
+ private static final int MAX_ACTION_EXTRACTION_TEXT_LENGTH = 400;
+ private static final int MAX_ACTIONS_PER_LINK = 1;
+ private static final int MAX_SMART_ACTIONS = Notification.MAX_ACTION_BUTTONS;
+
+ SmartActionsHelper() {}
+
+ /**
+ * Adds action adjustments based on the notification contents.
+ *
+ * TODO: Once we have a API in {@link TextClassificationManager} to predict smart actions
+ * from notification text / message, we can replace most of the code here by consuming that API.
+ */
+ @NonNull
+ ArrayList<Notification.Action> suggestActions(
+ @Nullable Context context, @NonNull StatusBarNotification sbn) {
+ if (!isEligibleForActionAdjustment(sbn)) {
+ return EMPTY_LIST;
+ }
+ if (context == null) {
+ return EMPTY_LIST;
+ }
+ TextClassificationManager tcm = context.getSystemService(TextClassificationManager.class);
+ if (tcm == null) {
+ return EMPTY_LIST;
+ }
+ Notification.Action[] actions = sbn.getNotification().actions;
+ int numOfExistingActions = actions == null ? 0: actions.length;
+ int maxSmartActions = MAX_SMART_ACTIONS - numOfExistingActions;
+ return suggestActionsFromText(
+ tcm,
+ getMostSalientActionText(sbn.getNotification()), maxSmartActions);
+ }
+
+ /**
+ * Returns whether a notification is eligible for action adjustments.
+ *
+ * <p>We exclude system notifications, those that get refreshed frequently, or ones that relate
+ * to fundamental phone functionality where any error would result in a very negative user
+ * experience.
+ */
+ private boolean isEligibleForActionAdjustment(@NonNull StatusBarNotification sbn) {
+ Notification notification = sbn.getNotification();
+ String pkg = sbn.getPackageName();
+ if (notification.actions != null
+ && notification.actions.length >= Notification.MAX_ACTION_BUTTONS) {
+ return false;
+ }
+ if (0 != (notification.flags & FLAG_MASK_INELGIBILE_FOR_ACTIONS)) {
+ return false;
+ }
+ if (TextUtils.isEmpty(pkg) || pkg.equals("android")) {
+ return false;
+ }
+ // For now, we are only interested in messages.
+ return Notification.CATEGORY_MESSAGE.equals(notification.category)
+ || Notification.MessagingStyle.class.equals(notification.getNotificationStyle());
+ }
+
+ /** Returns the text most salient for action extraction in a notification. */
+ @Nullable
+ private CharSequence getMostSalientActionText(@NonNull Notification notification) {
+ /* If it's messaging style, use the most recent message. */
+ Parcelable[] messages = notification.extras.getParcelableArray(Notification.EXTRA_MESSAGES);
+ if (messages != null && messages.length != 0) {
+ Bundle lastMessage = (Bundle) messages[messages.length - 1];
+ CharSequence lastMessageText =
+ lastMessage.getCharSequence(Notification.MessagingStyle.Message.KEY_TEXT);
+ if (!TextUtils.isEmpty(lastMessageText)) {
+ return lastMessageText;
+ }
+ }
+
+ // Fall back to using the normal text.
+ return notification.extras.getCharSequence(Notification.EXTRA_TEXT);
+ }
+
+ /** Returns a list of actions to act on entities in a given piece of text. */
+ @NonNull
+ private ArrayList<Notification.Action> suggestActionsFromText(
+ @NonNull TextClassificationManager tcm, @Nullable CharSequence text,
+ int maxSmartActions) {
+ if (TextUtils.isEmpty(text)) {
+ return EMPTY_LIST;
+ }
+ TextClassifier textClassifier = tcm.getTextClassifier();
+
+ // We want to process only text visible to the user to avoid confusing suggestions, so we
+ // truncate the text to a reasonable length. This is particularly important for e.g.
+ // email apps that sometimes include the text for the entire thread.
+ text = text.subSequence(0, Math.min(text.length(), MAX_ACTION_EXTRACTION_TEXT_LENGTH));
+
+ // Extract all entities.
+ TextLinks.Request textLinksRequest = new TextLinks.Request.Builder(text)
+ .setEntityConfig(
+ TextClassifier.EntityConfig.createWithHints(
+ Collections.singletonList(
+ TextClassifier.HINT_TEXT_IS_NOT_EDITABLE)))
+ .build();
+ TextLinks links = textClassifier.generateLinks(textLinksRequest);
+ ArrayMap<String, Integer> entityTypeFrequency = getEntityTypeFrequency(links);
+
+ ArrayList<Notification.Action> actions = new ArrayList<>();
+ for (TextLinks.TextLink link : links.getLinks()) {
+ // Ignore any entity type for which we have too many entities. This is to handle the
+ // case where a notification contains e.g. a list of phone numbers. In such cases, the
+ // user likely wants to act on the whole list rather than an individual entity.
+ if (link.getEntityCount() == 0
+ || entityTypeFrequency.get(link.getEntity(0)) != 1) {
+ continue;
+ }
+
+ // Generate the actions, and add the most prominent ones to the action bar.
+ TextClassification classification =
+ textClassifier.classifyText(
+ new TextClassification.Request.Builder(
+ text, link.getStart(), link.getEnd()).build());
+ int numOfActions = Math.min(
+ MAX_ACTIONS_PER_LINK, classification.getActions().size());
+ for (int i = 0; i < numOfActions; ++i) {
+ RemoteAction action = classification.getActions().get(i);
+ actions.add(
+ new Notification.Action.Builder(
+ action.getIcon(),
+ action.getTitle(),
+ action.getActionIntent())
+ .build());
+ // We have enough smart actions.
+ if (actions.size() >= maxSmartActions) {
+ return actions;
+ }
+ }
+ }
+ return actions;
+ }
+
+ /**
+ * Given the links extracted from a piece of text, returns the frequency of each entity
+ * type.
+ */
+ @NonNull
+ private ArrayMap<String, Integer> getEntityTypeFrequency(@NonNull TextLinks links) {
+ ArrayMap<String, Integer> entityTypeCount = new ArrayMap<>();
+ for (TextLinks.TextLink link : links.getLinks()) {
+ if (link.getEntityCount() == 0) {
+ continue;
+ }
+ String entityType = link.getEntity(0);
+ if (entityTypeCount.containsKey(entityType)) {
+ entityTypeCount.put(entityType, entityTypeCount.get(entityType) + 1);
+ } else {
+ entityTypeCount.put(entityType, 1);
+ }
+ }
+ return entityTypeCount;
+ }
+}
+ " cannot be null");
}
- mCallingPackageName = extras.getString(DocumentsContract.EXTRA_PACKAGE_NAME);
+ mCallingPackageName = extras.getString(Intent.EXTRA_PACKAGE_NAME);
if (savedInstanceState == null) {
MetricsLogger.action(this, MetricsEvent.PRINT_PREVIEW, mCallingPackageName);
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.setType("application/pdf");
intent.putExtra(Intent.EXTRA_TITLE, info.getName());
- intent.putExtra(DocumentsContract.EXTRA_PACKAGE_NAME, mCallingPackageName);
+ intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mCallingPackageName);
try {
startActivityForResult(intent, ACTIVITY_REQUEST_CREATE_FILE);
<string name="enabled_by_admin" msgid="5302986023578399263">"Activada per l\'administrador"</string>
<string name="disabled_by_admin" msgid="8505398946020816620">"Desactivada per l\'administrador"</string>
<string name="disabled" msgid="9206776641295849915">"Desactivat"</string>
- <string name="external_source_trusted" msgid="2707996266575928037">"Permeses"</string>
- <string name="external_source_untrusted" msgid="2677442511837596726">"No permeses"</string>
+ <string name="external_source_trusted" msgid="2707996266575928037">"Amb permís"</string>
+ <string name="external_source_untrusted" msgid="2677442511837596726">"Sense permís"</string>
<string name="install_other_apps" msgid="6986686991775883017">"Instal·lar aplicacions desconegudes"</string>
<string name="home" msgid="3256884684164448244">"Pàgina d\'inici de configuració"</string>
<string-array name="battery_labels">
<string name="show_notification_channel_warnings_summary" msgid="5536803251863694895">"अनुप्रयोगले कुनै मान्य च्यानल बिना सूचना पोस्ट गर्दा स्क्रिनमा चेतावनी देखाउँछ"</string>
<string name="force_allow_on_external" msgid="3215759785081916381">"बाह्यमा बल प्रयोगको अनुमति प्राप्त अनुप्रयोगहरू"</string>
<string name="force_allow_on_external_summary" msgid="3640752408258034689">"म्यानिफेेस्टका मानहरूको ख्याल नगरी कुनै पनि अनुप्रयोगलाई बाह्य भण्डारणमा लेख्न सकिने खाले बनाउँछ"</string>
- <string name="force_resizable_activities" msgid="8615764378147824985">"à¤\97तिविधिहरà¥\82 रिसाà¤\87à¤\9c à¤\97रà¥\8dनà¤\95à¥\8b लाà¤\97ि बाधà¥\8dय à¤\97रà¥\8dनà¥\81हà¥\8bसà¥\8d"</string>
+ <string name="force_resizable_activities" msgid="8615764378147824985">"à¤\86à¤\95ार बदलà¥\8dन यà¥\8bà¤\97à¥\8dय हà¥\81नà¥\87 बनाà¤\89न à¤\97तिविधिहरà¥\82लाà¤\88 बाधà¥\8dयातà¥\8dमà¤\95 बनाà¤\89नà¥\81हà¥\8bसà¥\8d।"</string>
<string name="force_resizable_activities_summary" msgid="6667493494706124459">"म्यानिफेेस्ट मानहरूको ख्याल नगरी, बहु-विन्डोको लागि सबै रिसाइज गर्न सकिने गतिविधिहरू बनाउनुहोस्।"</string>
<string name="enable_freeform_support" msgid="1461893351278940416">"फ्रिफर्म विन्डोहरू सक्रिय गर्नुहोस्"</string>
<string name="enable_freeform_support_summary" msgid="8247310463288834487">"प्रयोगात्मक फ्रिफर्म विन्डोहरूका लागि समर्थन सक्रिय गर्नुहोस्।"</string>
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string-array name="wifi_status">
<item msgid="1922181315419294640"></item>
- <item msgid="8934131797783724664">"ஸà¯\8dà®\95à¯\87னà¯\8d à®\9aà¯\86யà¯\8dà®\95ிறதà¯\81â\80¦"</item>
+ <item msgid="8934131797783724664">"தà¯\87à®\9fà¯\81à®\95ிறதà¯\81..."</item>
<item msgid="8513729475867537913">"இணைக்கிறது..."</item>
<item msgid="515055375277271756">"அங்கீகரிக்கிறது..."</item>
<item msgid="1943354004029184381">"IP முகவரியைப் பெறுகிறது…"</item>
</string-array>
<string-array name="wifi_status_with_ssid">
<item msgid="7714855332363650812"></item>
- <item msgid="8878186979715711006">"ஸà¯\8dà®\95à¯\87னà¯\8d à®\9aà¯\86யà¯\8dà®\95ிறதà¯\81â\80¦"</item>
+ <item msgid="8878186979715711006">"தà¯\87à®\9fà¯\81à®\95ிறதà¯\81..."</item>
<item msgid="355508996603873860">"<xliff:g id="NETWORK_NAME">%1$s</xliff:g> இல் இணைக்கிறது…"</item>
<item msgid="554971459996405634">"<xliff:g id="NETWORK_NAME">%1$s</xliff:g> உடன் அங்கீகரிக்கிறது…"</item>
<item msgid="7928343808033020343">"<xliff:g id="NETWORK_NAME">%1$s</xliff:g> இலிருந்து IP முகவரியைப் பெறுகிறது…"</item>
</string-array>
<string-array name="window_animation_scale_entries">
<item msgid="8134156599370824081">"அனிமேஷனை முடக்கு"</item>
- <item msgid="6624864048416710414">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 .5x"</item>
- <item msgid="2219332261255416635">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 1x"</item>
- <item msgid="3544428804137048509">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 1.5x"</item>
- <item msgid="3110710404225974514">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 2x"</item>
- <item msgid="4402738611528318731">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 5x"</item>
- <item msgid="6189539267968330656">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 10x"</item>
+ <item msgid="6624864048416710414">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d .5x"</item>
+ <item msgid="2219332261255416635">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 1x"</item>
+ <item msgid="3544428804137048509">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 1.5x"</item>
+ <item msgid="3110710404225974514">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 2x"</item>
+ <item msgid="4402738611528318731">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 5x"</item>
+ <item msgid="6189539267968330656">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 10x"</item>
</string-array>
<string-array name="transition_animation_scale_entries">
<item msgid="8464255836173039442">"அனிமேஷனை முடக்கு"</item>
- <item msgid="3375781541913316411">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 .5x"</item>
- <item msgid="1991041427801869945">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 1x"</item>
- <item msgid="4012689927622382874">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 1.5x"</item>
- <item msgid="3289156759925947169">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 2x"</item>
- <item msgid="7705857441213621835">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 5x"</item>
- <item msgid="6660750935954853365">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 10x"</item>
+ <item msgid="3375781541913316411">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d .5x"</item>
+ <item msgid="1991041427801869945">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 1x"</item>
+ <item msgid="4012689927622382874">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 1.5x"</item>
+ <item msgid="3289156759925947169">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 2x"</item>
+ <item msgid="7705857441213621835">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 5x"</item>
+ <item msgid="6660750935954853365">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 10x"</item>
</string-array>
<string-array name="animator_duration_scale_entries">
<item msgid="6039901060648228241">"அனிமேஷனை முடக்கு"</item>
- <item msgid="1138649021950863198">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 .5x"</item>
- <item msgid="4394388961370833040">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 1x"</item>
- <item msgid="8125427921655194973">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 1.5x"</item>
- <item msgid="3334024790739189573">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 2x"</item>
- <item msgid="3170120558236848008">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 5x"</item>
- <item msgid="1069584980746680398">"à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81 10x"</item>
+ <item msgid="1138649021950863198">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d .5x"</item>
+ <item msgid="4394388961370833040">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 1x"</item>
+ <item msgid="8125427921655194973">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 1.5x"</item>
+ <item msgid="3334024790739189573">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 2x"</item>
+ <item msgid="3170120558236848008">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 5x"</item>
+ <item msgid="1069584980746680398">"à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d 10x"</item>
</string-array>
<string-array name="overlay_display_devices_entries">
<item msgid="1606809880904982133">"ஏதுமில்லை"</item>
<string name="track_frame_time" msgid="6094365083096851167">"சுயவிவர HWUI ரெண்டரிங்"</string>
<string name="enable_gpu_debug_layers" msgid="3848838293793255097">"GPU பிழைத்திருத்த லேயர்களை இயக்கு"</string>
<string name="enable_gpu_debug_layers_summary" msgid="8009136940671194940">"பிழைத்திருத்த ஆப்ஸிற்கு, GPU பிழைத்திருத்த லேயர்களை ஏற்றுவதற்கு அனுமதி"</string>
- <string name="window_animation_scale_title" msgid="6162587588166114700">"à®\9aாளர à®\85னிமà¯\87ஷனà¯\8d à®\85ளவà¯\81"</string>
- <string name="transition_animation_scale_title" msgid="387527540523595875">"à®\85னிமà¯\87ஷனà¯\8d மாறà¯\8dறதà¯\8dதினà¯\8d à®\85ளவà¯\81"</string>
+ <string name="window_animation_scale_title" msgid="6162587588166114700">"à®\9aாளர à®\85னிமà¯\87ஷனà¯\8d வà¯\87à®\95à®®à¯\8d"</string>
+ <string name="transition_animation_scale_title" msgid="387527540523595875">"à®\85னிமà¯\87ஷனà¯\8d மாறà¯\8dறதà¯\8dதினà¯\8d வà¯\87à®\95à®®à¯\8d"</string>
<string name="animator_duration_scale_title" msgid="3406722410819934083">"அனிமேட்டர் கால அளவு"</string>
<string name="overlay_display_devices_title" msgid="5364176287998398539">"இரண்டாம்நிலைக் காட்சிகளை உருவகப்படுத்து"</string>
<string name="debug_applications_category" msgid="4206913653849771549">"ஆப்ஸ்"</string>
<string name="picture_color_mode" msgid="4560755008730283695">"படத்தின் வண்ணப் பயன்முறை"</string>
<string name="picture_color_mode_desc" msgid="1141891467675548590">"sRGBஐப் பயன்படுத்தும்"</string>
<string name="daltonizer_mode_disabled" msgid="7482661936053801862">"முடக்கப்பட்டது"</string>
- <string name="daltonizer_mode_monochromacy" msgid="8485709880666106721">"à®®à¯\8bனà¯\8bà®\95à¯\81à®°à¯\8bà®®à®\9aி"</string>
+ <string name="daltonizer_mode_monochromacy" msgid="8485709880666106721">"à®\92à®±à¯\8dà®±à¯\88 நிறதà¯\8d தனà¯\8dà®®à¯\88"</string>
<string name="daltonizer_mode_deuteranomaly" msgid="5475532989673586329">"நிறம் அடையாளங்காண முடியாமை (சிவப்பு-பச்சை)"</string>
<string name="daltonizer_mode_protanomaly" msgid="8424148009038666065">"நிறம் அடையாளங்காண முடியாமை (சிவப்பு-பச்சை)"</string>
<string name="daltonizer_mode_tritanomaly" msgid="481725854987912389">"நிறம் அடையாளங்காண முடியாமை (நீலம்-மஞ்சள்)"</string>
import android.annotation.Nullable;
import android.app.Activity;
-import androidx.lifecycle.LifecycleOwner;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.Menu;
import android.view.MenuItem;
+import androidx.fragment.app.FragmentActivity;
+import androidx.lifecycle.LifecycleOwner;
+
/**
* {@link Activity} that has hooks to observe activity lifecycle events.
*/
-public class ObservableActivity extends Activity implements LifecycleOwner {
+public class ObservableActivity extends FragmentActivity implements LifecycleOwner {
private final Lifecycle mLifecycle = new Lifecycle(this);
- public Lifecycle getLifecycle() {
+ public Lifecycle getSettingsLifecycle() {
return mLifecycle;
}
import static androidx.lifecycle.Lifecycle.Event.ON_START;
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
-import android.app.DialogFragment;
-import androidx.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
+import androidx.fragment.app.DialogFragment;
+import androidx.lifecycle.LifecycleOwner;
+
/**
* {@link DialogFragment} that has hooks to observe fragment lifecycle events.
*/
protected final Lifecycle mLifecycle = new Lifecycle(this);
+ public Lifecycle getSettingsLifecycle() {
+ return mLifecycle;
+ }
+
@Override
public void onAttach(Context context) {
super.onAttach(context);
}
return lifecycleHandled;
}
-
- @Override
- public Lifecycle getLifecycle() {
- return mLifecycle;
- }
}
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
import android.annotation.CallSuper;
-import android.app.Fragment;
-import androidx.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
+import androidx.fragment.app.Fragment;
+import androidx.lifecycle.LifecycleOwner;
+
public class ObservableFragment extends Fragment implements LifecycleOwner {
private final Lifecycle mLifecycle = new Lifecycle(this);
- public Lifecycle getLifecycle() {
+ public Lifecycle getSettingsLifecycle() {
return mLifecycle;
}
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
import android.annotation.CallSuper;
-import androidx.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.Bundle;
-import androidx.preference.PreferenceFragment;
-import androidx.preference.PreferenceScreen;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
+import androidx.lifecycle.LifecycleOwner;
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.PreferenceScreen;
+
/**
- * {@link PreferenceFragment} that has hooks to observe fragment lifecycle events.
+ * {@link PreferenceFragmentCompat} that has hooks to observe fragment lifecycle events.
*/
-public abstract class ObservablePreferenceFragment extends PreferenceFragment
+public abstract class ObservablePreferenceFragment extends PreferenceFragmentCompat
implements LifecycleOwner {
private final Lifecycle mLifecycle = new Lifecycle(this);
- public Lifecycle getLifecycle() {
+ public Lifecycle getSettingsLifecycle() {
return mLifecycle;
}
import static androidx.lifecycle.Lifecycle.Event.ON_START;
import static com.google.common.truth.Truth.assertThat;
-import androidx.lifecycle.LifecycleOwner;
import android.content.Context;
+import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
+import android.widget.LinearLayout;
import com.android.settingslib.SettingsLibRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.events.OnAttach;
import com.android.settingslib.core.lifecycle.events.OnResume;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
+import com.android.settingslib.testutils.FragmentTestUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.android.controller.ActivityController;
-import org.robolectric.android.controller.FragmentController;
+
+import androidx.lifecycle.LifecycleOwner;
@RunWith(SettingsLibRobolectricTestRunner.class)
public class LifecycleTest {
public TestFragment() {
mFragObserver = new TestObserver();
- getLifecycle().addObserver(mFragObserver);
+ getSettingsLifecycle().addObserver(mFragObserver);
}
}
public TestActivity() {
mActObserver = new TestObserver();
- getLifecycle().addObserver(mActObserver);
+ getSettingsLifecycle().addObserver(mActObserver);
}
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ LinearLayout view = new LinearLayout(this);
+ view.setId(1);
+
+ setContentView(view);
+ }
}
public static class TestObserver implements LifecycleObserver, OnAttach, OnStart, OnResume,
@Test
public void runThroughActivityLifecycles_shouldObserveEverything() {
ActivityController<TestActivity> ac = Robolectric.buildActivity(TestActivity.class);
- TestActivity activity = ac.get();
+ TestActivity activity = ac.setup().get();
- ac.start();
assertThat(activity.mActObserver.mOnStartObserved).isTrue();
- ac.resume();
assertThat(activity.mActObserver.mOnResumeObserved).isTrue();
activity.onCreateOptionsMenu(null);
assertThat(activity.mActObserver.mOnCreateOptionsMenuObserved).isTrue();
@Test
public void runThroughDialogFragmentLifecycles_shouldObserveEverything() {
- FragmentController<TestDialogFragment> fragmentController =
- Robolectric.buildFragment(TestDialogFragment.class);
- TestDialogFragment fragment = fragmentController.get();
+ final TestDialogFragment fragment = new TestDialogFragment();
+ FragmentTestUtils.startFragment(fragment);
- fragmentController.create().start().resume();
fragment.onCreateOptionsMenu(null, null);
fragment.onPrepareOptionsMenu(null);
fragment.onOptionsItemSelected(null);
- fragmentController.pause().stop().destroy();
+ assertThat(fragment.mFragObserver.mOnCreateOptionsMenuObserved).isTrue();
+ assertThat(fragment.mFragObserver.mOnPrepareOptionsMenuObserved).isTrue();
+ assertThat(fragment.mFragObserver.mOnOptionsItemSelectedObserved).isTrue();
assertThat(fragment.mFragObserver.mOnAttachObserved).isTrue();
assertThat(fragment.mFragObserver.mOnAttachHasContext).isTrue();
assertThat(fragment.mFragObserver.mOnStartObserved).isTrue();
assertThat(fragment.mFragObserver.mOnResumeObserved).isTrue();
+ fragment.onPause();
assertThat(fragment.mFragObserver.mOnPauseObserved).isTrue();
+ fragment.onStop();
assertThat(fragment.mFragObserver.mOnStopObserved).isTrue();
+ fragment.onDestroy();
assertThat(fragment.mFragObserver.mOnDestroyObserved).isTrue();
- assertThat(fragment.mFragObserver.mOnCreateOptionsMenuObserved).isTrue();
- assertThat(fragment.mFragObserver.mOnPrepareOptionsMenuObserved).isTrue();
- assertThat(fragment.mFragObserver.mOnOptionsItemSelectedObserved).isTrue();
}
@Test
public void runThroughFragmentLifecycles_shouldObserveEverything() {
- FragmentController<TestFragment> fragmentController =
- Robolectric.buildFragment(TestFragment.class);
- TestFragment fragment = fragmentController.get();
+ final TestFragment fragment = new TestFragment();
+ FragmentTestUtils.startFragment(fragment);
- fragmentController.create().start().resume();
fragment.onCreateOptionsMenu(null, null);
fragment.onPrepareOptionsMenu(null);
fragment.onOptionsItemSelected(null);
- fragmentController.pause().stop().destroy();
+ assertThat(fragment.mFragObserver.mOnCreateOptionsMenuObserved).isTrue();
+ assertThat(fragment.mFragObserver.mOnPrepareOptionsMenuObserved).isTrue();
+ assertThat(fragment.mFragObserver.mOnOptionsItemSelectedObserved).isTrue();
assertThat(fragment.mFragObserver.mOnAttachObserved).isTrue();
assertThat(fragment.mFragObserver.mOnAttachHasContext).isTrue();
assertThat(fragment.mFragObserver.mOnStartObserved).isTrue();
assertThat(fragment.mFragObserver.mOnResumeObserved).isTrue();
+ fragment.onPause();
assertThat(fragment.mFragObserver.mOnPauseObserved).isTrue();
+ fragment.onStop();
assertThat(fragment.mFragObserver.mOnStopObserved).isTrue();
+ fragment.onDestroy();
assertThat(fragment.mFragObserver.mOnDestroyObserved).isTrue();
- assertThat(fragment.mFragObserver.mOnCreateOptionsMenuObserved).isTrue();
- assertThat(fragment.mFragObserver.mOnPrepareOptionsMenuObserved).isTrue();
- assertThat(fragment.mFragObserver.mOnOptionsItemSelectedObserved).isTrue();
}
@Test
@Test
public void onOptionItemSelectedShortCircuitsIfAnObserverHandlesTheMenuItem() {
- FragmentController<TestFragment> fragmentController =
- Robolectric.buildFragment(TestFragment.class);
- TestFragment fragment = fragmentController.get();
- OptionItemAccepter accepter = new OptionItemAccepter();
+ final TestFragment fragment = new TestFragment();
+ FragmentTestUtils.startFragment(fragment);
+
+ final OptionItemAccepter accepter = new OptionItemAccepter();
fragment.getLifecycle().addObserver(accepter);
- fragmentController.create().start().resume();
+
fragment.onCreateOptionsMenu(null, null);
fragment.onPrepareOptionsMenu(null);
fragment.onOptionsItemSelected(null);
- fragmentController.pause().stop().destroy();
assertThat(accepter.wasCalled).isFalse();
}
--- /dev/null
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settingslib.testutils;
+
+import android.os.Bundle;
+import android.widget.LinearLayout;
+
+import org.robolectric.Robolectric;
+
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentManager;
+
+/**
+ * Utilities for creating Fragments for testing.
+ * <p>
+ * TODO(b/111195449) - Duplicated from org.robolectric.shadows.support.v4.SupportFragmentTestUtil
+ */
+@Deprecated
+public class FragmentTestUtils {
+
+ public static void startFragment(Fragment fragment) {
+ buildFragmentManager(FragmentUtilActivity.class)
+ .beginTransaction().add(fragment, null).commit();
+ }
+
+ public static void startFragment(Fragment fragment,
+ Class<? extends FragmentActivity> activityClass) {
+ buildFragmentManager(activityClass)
+ .beginTransaction().add(fragment, null).commit();
+ }
+
+ public static void startVisibleFragment(Fragment fragment) {
+ buildFragmentManager(FragmentUtilActivity.class)
+ .beginTransaction().add(1, fragment, null).commit();
+ }
+
+ public static void startVisibleFragment(Fragment fragment,
+ Class<? extends FragmentActivity> activityClass, int containerViewId) {
+ buildFragmentManager(activityClass)
+ .beginTransaction().add(containerViewId, fragment, null).commit();
+ }
+
+ private static FragmentManager buildFragmentManager(
+ Class<? extends FragmentActivity> activityClass) {
+ FragmentActivity activity = Robolectric.setupActivity(activityClass);
+ return activity.getSupportFragmentManager();
+ }
+
+ private static class FragmentUtilActivity extends FragmentActivity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ LinearLayout view = new LinearLayout(this);
+ view.setId(1);
+
+ setContentView(view);
+ }
+ }
+}
}
private final class UpgradeController {
- private static final int SETTINGS_VERSION = 169;
+ private static final int SETTINGS_VERSION = 170;
private final int mUserId;
currentVersion = 169;
}
+ if (currentVersion == 169) {
+ // Version 169: by default, add STREAM_VOICE_CALL to list of streams that can
+ // be muted.
+ final SettingsState systemSettings = getSystemSettingsLocked(userId);
+ final Setting currentSetting = systemSettings.getSettingLocked(
+ Settings.System.MUTE_STREAMS_AFFECTED);
+ if (!currentSetting.isNull()) {
+ try {
+ int currentSettingIntegerValue = Integer.parseInt(
+ currentSetting.getValue());
+ if ((currentSettingIntegerValue
+ & (1 << AudioManager.STREAM_VOICE_CALL)) == 0) {
+ systemSettings.insertSettingLocked(
+ Settings.System.MUTE_STREAMS_AFFECTED,
+ Integer.toString(
+ currentSettingIntegerValue
+ | (1 << AudioManager.STREAM_VOICE_CALL)),
+ null, true, SettingsState.SYSTEM_PACKAGE_NAME);
+ }
+ } catch (NumberFormatException e) {
+ // remove the setting in case it is not a valid integer
+ Slog.w("Failed to parse integer value of MUTE_STREAMS_AFFECTED"
+ + "setting, removing setting", e);
+ systemSettings.deleteSettingLocked(
+ Settings.System.MUTE_STREAMS_AFFECTED);
+ }
+
+ }
+ currentVersion = 170;
+ }
+
// vXXX: Add new settings above this point.
if (currentVersion != newVersion) {
-->
<dimen name="qs_header_system_icons_area_height">48dp</dimen>
+ <!-- How far the quick-quick settings panel extends below the status bar -->
+ <dimen name="qs_quick_header_panel_height">128dp</dimen>
+
<!-- The height of the container that holds the system icons in the quick settings header in the
car setting. -->
<dimen name="car_qs_header_system_icons_area_height">54dp</dimen>
import android.os.Handler;
import android.provider.AlarmClock;
import android.service.notification.ZenModeConfig;
+import android.widget.FrameLayout;
import androidx.annotation.VisibleForTesting;
import android.text.format.DateUtils;
import android.util.AttributeSet;
updateResources();
}
+ /**
+ * The height of QQS should always be the status bar height + 128dp. This is normally easy, but
+ * when there is a notch involved the status bar can remain a fixed pixel size.
+ */
+ private void updateMinimumHeight() {
+ int sbHeight = mContext.getResources().getDimensionPixelSize(
+ com.android.internal.R.dimen.status_bar_height);
+ int qqsHeight = mContext.getResources().getDimensionPixelSize(
+ R.dimen.qs_quick_header_panel_height);
+
+ setMinimumHeight(sbHeight + qqsHeight);
+ }
+
private void updateResources() {
Resources resources = mContext.getResources();
+ updateMinimumHeight();
// Update height for a few views, especially due to landscape mode restricting space.
mHeaderTextContainerView.getLayoutParams().height =
com.android.internal.R.dimen.quick_qs_offset_height);
mSystemIconsView.setLayoutParams(mSystemIconsView.getLayoutParams());
- getLayoutParams().height = resources.getDimensionPixelSize(mQsDisabled
- ? com.android.internal.R.dimen.quick_qs_offset_height
- : com.android.internal.R.dimen.quick_qs_total_height);
- setLayoutParams(getLayoutParams());
+ FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
+ if (mQsDisabled) {
+ lp.height = resources.getDimensionPixelSize(
+ com.android.internal.R.dimen.quick_qs_offset_height);
+ } else {
+ lp.height = Math.max(getMinimumHeight(),
+ resources.getDimensionPixelSize(
+ com.android.internal.R.dimen.quick_qs_offset_height));
+ }
+
+ setLayoutParams(lp);
updateStatusIconAlphaAnimator();
updateHeaderTextContainerAlphaAnimator();
state |= DISABLE_SYSTEM_INFO;
state |= DISABLE_CLOCK;
}
+
+ // In landscape, the heads up show but shouldHideNotificationIcons() return false
+ // because the visual icon is in notification icon area rather than heads up's space.
+ // whether the notification icon show or not, clock should hide when heads up show.
+ if (mStatusBarComponent.isHeadsUpShouldBeVisible()) {
+ state |= DISABLE_CLOCK;
+ }
+
if (mNetworkController != null && EncryptionHelper.IS_DATA_ENCRYPTED) {
if (mNetworkController.hasEmergencyCryptKeeperText()) {
state |= DISABLE_NOTIFICATION_ICONS;
}
private void updateStatusBarIcons() {
- boolean showIconsWhenExpanded = isFullWidth() && getExpandedHeight() < getOpeningHeight();
+ boolean showIconsWhenExpanded = (isPanelVisibleBecauseOfHeadsUp() || isFullWidth())
+ && getExpandedHeight() < getOpeningHeight();
if (showIconsWhenExpanded && mNoVisibleNotifications && isOnKeyguard()) {
showIconsWhenExpanded = false;
}
for (ScrimState state : ScrimState.values()) {
state.setHasBackdrop(hasBackdrop);
}
+
+ // Backdrop event may arrive after state was already applied,
+ // in this case, back-scrim needs to be re-evaluated
+ if (mState == ScrimState.AOD || mState == ScrimState.PULSING) {
+ float newBehindAlpha = mState.getBehindAlpha(mNotificationDensity);
+ if (mCurrentBehindAlpha != newBehindAlpha) {
+ mCurrentBehindAlpha = newBehindAlpha;
+ updateScrims();
+ }
+ }
}
public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) {
public void prepare(ScrimState previousState) {
final boolean alwaysOnEnabled = mDozeParameters.getAlwaysOn();
mBlankScreen = mDisplayRequiresBlanking;
- mCurrentBehindAlpha = mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
mCurrentInFrontAlpha = alwaysOnEnabled ? mAodFrontScrimAlpha : 1f;
mCurrentInFrontTint = Color.BLACK;
mCurrentBehindTint = Color.BLACK;
}
@Override
+ public float getBehindAlpha(float busyness) {
+ return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
+ }
+
+ @Override
public boolean isLowPowerState() {
return true;
}
public void prepare(ScrimState previousState) {
mCurrentInFrontAlpha = 0;
mCurrentInFrontTint = Color.BLACK;
- mCurrentBehindAlpha = mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
mCurrentBehindTint = Color.BLACK;
mBlankScreen = mDisplayRequiresBlanking;
}
+
+ @Override
+ public float getBehindAlpha(float busyness) {
+ return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
+ }
},
/**
}
}
+ public boolean isHeadsUpShouldBeVisible() {
+ return mHeadsUpAppearanceController.shouldBeVisible();
+ }
+
/**
* All changes to the status bar and notifications funnel through here and are batched.
*/
*/
private int targetScrollForView(ExpandableView v, int positionInLinearLayout) {
return positionInLinearLayout + v.getIntrinsicHeight() +
- getImeInset() - getHeight() + getTopPadding();
+ getImeInset() - getHeight()
+ + ((!isExpanded() && isPinnedHeadsUp(v)) ? mHeadsUpInset : getTopPadding());
}
@Override
}
private int getScrollRange() {
- int scrollRange = Math.max(0, mContentHeight - mMaxLayoutHeight);
+ // In current design, it only use the top HUN to treat all of HUNs
+ // although there are more than one HUNs
+ int contentHeight = mContentHeight;
+ if (!isExpanded() && mHeadsUpManager.hasPinnedHeadsUp()) {
+ contentHeight = mHeadsUpInset + getTopHeadsUpPinnedHeight();
+ }
+ int scrollRange = Math.max(0, contentHeight - mMaxLayoutHeight);
int imeInset = getImeInset();
- scrollRange += Math.min(imeInset, Math.max(0, mContentHeight - (getHeight() - imeInset)));
+ scrollRange += Math.min(imeInset, Math.max(0, contentHeight - (getHeight() - imeInset)));
return scrollRange;
}
childState.yTranslation = topState.yTranslation + topState.height
- childState.height;
}
+
+ // heads up notification show and this row is the top entry of heads up
+ // notifications. i.e. this row should be the only one row that has input field
+ // To check if the row need to do translation according to scroll Y
+ // heads up show full of row's content and any scroll y indicate that the
+ // translationY need to move up the HUN.
+ if (!mIsExpanded && isTopEntry && ambientState.getScrollY() > 0) {
+ childState.yTranslation -= ambientState.getScrollY();
+ }
}
if (row.isHeadsUpAnimatingAway()) {
childState.hidden = false;
}
@Test
+ public void setHasBackdrop_withAodWallpaperAndAlbumArt() {
+ mScrimController.setWallpaperSupportsAmbientMode(true);
+ mScrimController.transitionTo(ScrimState.AOD);
+ mScrimController.finishAnimationsImmediately();
+ mScrimController.setHasBackdrop(true);
+ mScrimController.finishAnimationsImmediately();
+ // Front scrim should be transparent
+ // Back scrim should be visible with tint
+ assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_FULLY_OPAQUE);
+ assertScrimTint(mScrimBehind, true /* tinted */);
+ assertScrimTint(mScrimInFront, true /* tinted */);
+ }
+
+ @Test
public void transitionToAod_withFrontAlphaUpdates() {
// Assert that setting the AOD front scrim alpha doesn't take effect in a non-AOD state.
mScrimController.transitionTo(ScrimState.KEYGUARD);
+++ /dev/null
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.sax;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.util.Log;
-import android.util.Xml;
-import org.kxml2.io.KXmlParser;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import com.android.frameworks.saxtests.R;
-
-public class ExpatPerformanceTest extends AndroidTestCase {
-
- private static final String TAG = ExpatPerformanceTest.class.getSimpleName();
-
- private byte[] mXmlBytes;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- InputStream in = mContext.getResources().openRawResource(R.raw.youtube);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int length;
- while ((length = in.read(buffer)) != -1) {
- out.write(buffer, 0, length);
- }
- mXmlBytes = out.toByteArray();
-
- Log.i("***", "File size: " + (mXmlBytes.length / 1024) + "k");
- }
-
- @LargeTest
- public void testPerformance() throws Exception {
-// try {
-// Debug.startMethodTracing("expat3");
-// for (int i = 0; i < 1; i++) {
- runJavaPullParser();
- runSax();
- runExpatPullParser();
-// }
-// } finally {
-// Debug.stopMethodTracing();
-// }
- }
-
- private InputStream newInputStream() {
- return new ByteArrayInputStream(mXmlBytes);
- }
-
- private void runSax() throws IOException, SAXException {
- long start = System.currentTimeMillis();
- Xml.parse(newInputStream(), Xml.Encoding.UTF_8, new DefaultHandler());
- long elapsed = System.currentTimeMillis() - start;
- Log.i(TAG, "expat SAX: " + elapsed + "ms");
- }
-
- private void runExpatPullParser() throws XmlPullParserException, IOException {
- long start = System.currentTimeMillis();
- XmlPullParser pullParser = Xml.newPullParser();
- pullParser.setInput(newInputStream(), "UTF-8");
- withPullParser(pullParser);
- long elapsed = System.currentTimeMillis() - start;
- Log.i(TAG, "expat pull: " + elapsed + "ms");
- }
-
- private void runJavaPullParser() throws XmlPullParserException, IOException {
- XmlPullParser pullParser;
- long start = System.currentTimeMillis();
- pullParser = new KXmlParser();
- pullParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
- pullParser.setInput(newInputStream(), "UTF-8");
- withPullParser(pullParser);
- long elapsed = System.currentTimeMillis() - start;
- Log.i(TAG, "java pull parser: " + elapsed + "ms");
- }
-
- private static void withPullParser(XmlPullParser pullParser)
- throws IOException, XmlPullParserException {
- int eventType = pullParser.next();
- while (eventType != XmlPullParser.END_DOCUMENT) {
- switch (eventType) {
- case XmlPullParser.START_TAG:
- pullParser.getName();
-// int nattrs = pullParser.getAttributeCount();
-// for (int i = 0; i < nattrs; ++i) {
-// pullParser.getAttributeName(i);
-// pullParser.getAttributeValue(i);
-// }
- break;
- case XmlPullParser.END_TAG:
- pullParser.getName();
- break;
- case XmlPullParser.TEXT:
- pullParser.getText();
- break;
- }
- eventType = pullParser.next();
- }
- }
-}
final int callingUid = Binder.getCallingUid();
final long origId = Binder.clearCallingIdentity();
try {
- synchronized (this) {
+ synchronized (mService.mGlobalLock) {
mService.mStackSupervisor.startActivityFromRecents(callingPid, callingUid, mTaskId,
null);
}
static final int UNKNOWN_VOLUME = -1;
+ static final String PROPERTY_PREFERRED_ADDRESS_AUDIO_SYSTEM =
+ "persist.sys.hdmi.addr.audiosystem";
static final String PROPERTY_PREFERRED_ADDRESS_PLAYBACK = "persist.sys.hdmi.addr.playback";
static final String PROPERTY_PREFERRED_ADDRESS_TV = "persist.sys.hdmi.addr.tv";
return new HdmiCecLocalDeviceTv(service);
case HdmiDeviceInfo.DEVICE_PLAYBACK:
return new HdmiCecLocalDevicePlayback(service);
+ case HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM:
+ return new HdmiCecLocalDeviceAudioSystem(service);
default:
return null;
}
--- /dev/null
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.server.hdmi;
+
+
+import android.hardware.hdmi.HdmiDeviceInfo;
+import android.os.SystemProperties;
+
+/**
+ * Represent a logical device of type {@link HdmiDeviceInfo#DEVICE_AUDIO_SYSTEM} residing in
+ * Android system.
+ */
+public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDevice {
+
+ protected HdmiCecLocalDeviceAudioSystem(HdmiControlService service) {
+ super(service, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
+ }
+
+ @Override
+ @HdmiAnnotations.ServiceThreadOnly
+ protected void onAddressAllocated(int logicalAddress, int reason) {
+ assertRunOnServiceThread();
+ mService.sendCecCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand(
+ mAddress, mService.getPhysicalAddress(), mDeviceType));
+ mService.sendCecCommand(HdmiCecMessageBuilder.buildDeviceVendorIdCommand(
+ mAddress, mService.getVendorId()));
+ startQueuedActions();
+ }
+
+ @Override
+ @HdmiAnnotations.ServiceThreadOnly
+ protected int getPreferredAddress() {
+ assertRunOnServiceThread();
+ return SystemProperties.getInt(Constants.PROPERTY_PREFERRED_ADDRESS_AUDIO_SYSTEM,
+ Constants.ADDR_UNREGISTERED);
+ }
+
+ @Override
+ @HdmiAnnotations.ServiceThreadOnly
+ protected void setPreferredAddress(int addr) {
+ assertRunOnServiceThread();
+ SystemProperties.set(Constants.PROPERTY_PREFERRED_ADDRESS_AUDIO_SYSTEM,
+ String.valueOf(addr));
+ }
+}
* @return newly created {@link HdmiCecMessage}
*/
static HdmiCecMessage buildReportAudioStatus(int src, int dest, int volume, boolean mute) {
- byte[] params = new byte[] {
- mute ? (byte) (1 & 0xFF) : (byte) (0 & 0xFF),
- (byte) (volume & 0xFF)
- };
+ byte status = (byte) ((byte) (mute ? 1 << 7 : 0) | ((byte) volume & 0x7F));
+ byte[] params = new byte[] { status };
return buildCommand(src, dest, Constants.MESSAGE_REPORT_AUDIO_STATUS, params);
}
// inserted above to hold the session active.
try {
final Int64Ref last = new Int64Ref(0);
- FileUtils.copy(incomingFd.getFileDescriptor(), targetFd, (long progress) -> {
- if (params.sizeBytes > 0) {
- final long delta = progress - last.value;
- last.value = progress;
- addClientProgress((float) delta / (float) params.sizeBytes);
- }
- }, null, lengthBytes);
+ FileUtils.copy(incomingFd.getFileDescriptor(), targetFd, lengthBytes, null,
+ Runnable::run, (long progress) -> {
+ if (params.sizeBytes > 0) {
+ final long delta = progress - last.value;
+ last.value = progress;
+ addClientProgress((float) delta / (float) params.sizeBytes);
+ }
+ });
} finally {
IoUtils.closeQuietly(targetFd);
IoUtils.closeQuietly(incomingFd);
intent.setData(Uri.fromParts("printjob", printJob.getId().flattenToString(), null));
intent.putExtra(PrintManager.EXTRA_PRINT_DOCUMENT_ADAPTER, adapter.asBinder());
intent.putExtra(PrintManager.EXTRA_PRINT_JOB, printJob);
- intent.putExtra(DocumentsContract.EXTRA_PACKAGE_NAME, packageName);
+ intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
IntentSender intentSender = PendingIntent.getActivityAsUser(
mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT
public static final int SERVICE_TYPE_VIDEO = 4;
public static final int SERVICE_TYPE_EMERGENCY = 5;
- /** {@link AccessNetworkConstants.TransportType}*/
- private final int mTransportType;
-
@Domain
private final int mDomain;
+ /** {@link AccessNetworkConstants.TransportType}*/
+ private final int mTransportType;
+
@RegState
private final int mRegState;
private DataSpecificRegistrationStates mDataSpecificStates;
/**
- * @param transportType Transport type. Must be {@link AccessNetworkConstants.TransportType}
* @param domain Network domain. Must be DOMAIN_CS or DOMAIN_PS.
+ * @param transportType Transport type. Must be {@link AccessNetworkConstants.TransportType}
* @param regState Network registration state.
* @param accessNetworkTechnology See TelephonyManager NETWORK_TYPE_XXXX.
* @param reasonForDenial Reason for denial if the registration state is DENIED.
* @param availableServices The supported service.
* @param cellIdentity The identity representing a unique cell
*/
- public NetworkRegistrationState(int transportType, int domain, int regState,
+ public NetworkRegistrationState(int domain, int transportType, int regState,
int accessNetworkTechnology, int reasonForDenial, boolean emergencyOnly,
int[] availableServices, @Nullable CellIdentity cellIdentity) {
- mTransportType = transportType;
mDomain = domain;
+ mTransportType = transportType;
mRegState = regState;
mAccessNetworkTechnology = accessNetworkTechnology;
mReasonForDenial = reasonForDenial;
* Constructor for voice network registration states.
* @hide
*/
- public NetworkRegistrationState(int transportType, int domain, int regState,
+ public NetworkRegistrationState(int domain, int transportType, int regState,
int accessNetworkTechnology, int reasonForDenial, boolean emergencyOnly,
int[] availableServices, @Nullable CellIdentity cellIdentity, boolean cssSupported,
int roamingIndicator, int systemIsInPrl, int defaultRoamingIndicator) {
- this(transportType, domain, regState, accessNetworkTechnology,
+ this(domain, transportType, regState, accessNetworkTechnology,
reasonForDenial, emergencyOnly, availableServices, cellIdentity);
mVoiceSpecificStates = new VoiceSpecificRegistrationStates(cssSupported, roamingIndicator,
* Constructor for data network registration states.
* @hide
*/
- public NetworkRegistrationState(int transportType, int domain, int regState,
+ public NetworkRegistrationState(int domain, int transportType, int regState,
int accessNetworkTechnology, int reasonForDenial, boolean emergencyOnly,
int[] availableServices, @Nullable CellIdentity cellIdentity, int maxDataCalls) {
- this(transportType, domain, regState, accessNetworkTechnology,
+ this(domain, transportType, regState, accessNetworkTechnology,
reasonForDenial, emergencyOnly, availableServices, cellIdentity);
mDataSpecificStates = new DataSpecificRegistrationStates(maxDataCalls);
}
protected NetworkRegistrationState(Parcel source) {
- mTransportType = source.readInt();
mDomain = source.readInt();
+ mTransportType = source.readInt();
mRegState = source.readInt();
mAccessNetworkTechnology = source.readInt();
mReasonForDenial = source.readInt();
@Override
public String toString() {
return new StringBuilder("NetworkRegistrationState{")
- .append("transportType=").append(mTransportType)
.append(" domain=").append((mDomain == DOMAIN_CS) ? "CS" : "PS")
+ .append("transportType=").append(mTransportType)
.append(" regState=").append(regStateToString(mRegState))
.append(" accessNetworkTechnology=")
.append(TelephonyManager.getNetworkTypeName(mAccessNetworkTechnology))
}
NetworkRegistrationState other = (NetworkRegistrationState) o;
- return mTransportType == other.mTransportType
- && mDomain == other.mDomain
+ return mDomain == other.mDomain
+ && mTransportType == other.mTransportType
&& mRegState == other.mRegState
&& mAccessNetworkTechnology == other.mAccessNetworkTechnology
&& mReasonForDenial == other.mReasonForDenial
@Override
public void writeToParcel(Parcel dest, int flags) {
- dest.writeInt(mTransportType);
dest.writeInt(mDomain);
+ dest.writeInt(mTransportType);
dest.writeInt(mRegState);
dest.writeInt(mAccessNetworkTechnology);
dest.writeInt(mReasonForDenial);
/**
* Get the network registration states with given transport type and domain.
*
+ * @param domain The network domain. Must be {@link NetworkRegistrationState#DOMAIN_CS} or
+ * {@link NetworkRegistrationState#DOMAIN_PS}.
* @param transportType The transport type. See {@link AccessNetworkConstants.TransportType}
- * @param domain The network domain. Must be DOMAIN_CS or DOMAIN_PS.
* @return The matching NetworkRegistrationState.
* @hide
*/
@SystemApi
- public NetworkRegistrationState getNetworkRegistrationStates(int transportType, int domain) {
+ public NetworkRegistrationState getNetworkRegistrationStates(int domain, int transportType) {
synchronized (mNetworkRegistrationStates) {
for (NetworkRegistrationState networkRegistrationState : mNetworkRegistrationStates) {
if (networkRegistrationState.getTransportType() == transportType