Rename onGetAnrDelayMillis to onAnrDelayStarted
The system will call into onAnrDelayStarted to notify the MediaProvider to show a progress dialog in the interim, while an app is about to ANR on a blocked transcoding session. See Idb9190a0e6014ce64bf1412c26f6ae03f97e922d for more details Bug: 170486601 Test: Manual CTS-Coverage-Bug: 179658703 Change-Id: I6c078ca3221e13cadf003f3504a7f796c7b18388
This commit is contained in:
@@ -10068,10 +10068,10 @@ package android.service.storage {
|
||||
|
||||
public abstract class ExternalStorageService extends android.app.Service {
|
||||
ctor public ExternalStorageService();
|
||||
method public void onAnrDelayStarted(@NonNull String, int, int, int);
|
||||
method @NonNull public final android.os.IBinder onBind(@NonNull android.content.Intent);
|
||||
method public abstract void onEndSession(@NonNull String) throws java.io.IOException;
|
||||
method public void onFreeCache(@NonNull java.util.UUID, long) throws java.io.IOException;
|
||||
method public long onGetAnrDelayMillis(@NonNull String, int);
|
||||
method public abstract void onStartSession(@NonNull String, int, @NonNull android.os.ParcelFileDescriptor, @NonNull java.io.File, @NonNull java.io.File) throws java.io.IOException;
|
||||
method public abstract void onVolumeStateChanged(@NonNull android.os.storage.StorageVolume) throws java.io.IOException;
|
||||
field public static final int FLAG_SESSION_ATTRIBUTE_INDEXABLE = 2; // 0x2
|
||||
|
||||
@@ -102,14 +102,6 @@ public abstract class ExternalStorageService extends Service {
|
||||
*/
|
||||
public static final String EXTRA_PACKAGE_NAME = "android.service.storage.extra.package_name";
|
||||
|
||||
/**
|
||||
* {@link Bundle} key for a {@link Long} value.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public static final String EXTRA_ANR_TIMEOUT_MS =
|
||||
"android.service.storage.extra.anr_timeout_ms";
|
||||
|
||||
/** @hide */
|
||||
@IntDef(flag = true, prefix = {"FLAG_SESSION_"},
|
||||
value = {FLAG_SESSION_TYPE_FUSE, FLAG_SESSION_ATTRIBUTE_INDEXABLE})
|
||||
@@ -178,12 +170,12 @@ public abstract class ExternalStorageService extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when {@code packageName} is about to ANR
|
||||
* Called when {@code packageName} is about to ANR. The {@link ExternalStorageService} can
|
||||
* show a progress dialog for the {@code reason}.
|
||||
*
|
||||
* @return ANR dialog delay in milliseconds
|
||||
*/
|
||||
public long onGetAnrDelayMillis(@NonNull String packageName, int uid) {
|
||||
throw new UnsupportedOperationException("onGetAnrDelayMillis not implemented");
|
||||
public void onAnrDelayStarted(@NonNull String packageName, int uid, int tid, int reason) {
|
||||
throw new UnsupportedOperationException("onAnrDelayStarted not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -247,14 +239,14 @@ public abstract class ExternalStorageService extends Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAnrDelayMillis(String packageName, int uid, RemoteCallback callback)
|
||||
throws RemoteException {
|
||||
public void notifyAnrDelayStarted(String packageName, int uid, int tid, int reason,
|
||||
RemoteCallback callback) throws RemoteException {
|
||||
mHandler.post(() -> {
|
||||
try {
|
||||
long timeoutMs = onGetAnrDelayMillis(packageName, uid);
|
||||
sendTimeoutResult(packageName, timeoutMs, null /* throwable */, callback);
|
||||
onAnrDelayStarted(packageName, uid, tid, reason);
|
||||
sendResult(packageName, null /* throwable */, callback);
|
||||
} catch (Throwable t) {
|
||||
sendTimeoutResult(packageName, 0 /* timeoutMs */, t, callback);
|
||||
sendResult(packageName, t, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -267,16 +259,5 @@ public abstract class ExternalStorageService extends Service {
|
||||
}
|
||||
callback.sendResult(bundle);
|
||||
}
|
||||
|
||||
private void sendTimeoutResult(String packageName, long timeoutMs, Throwable throwable,
|
||||
RemoteCallback callback) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(EXTRA_PACKAGE_NAME, packageName);
|
||||
bundle.putLong(EXTRA_ANR_TIMEOUT_MS, timeoutMs);
|
||||
if (throwable != null) {
|
||||
bundle.putParcelable(EXTRA_ERROR, new ParcelableException(throwable));
|
||||
}
|
||||
callback.sendResult(bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,6 @@ oneway interface IExternalStorageService
|
||||
in RemoteCallback callback);
|
||||
void freeCache(@utf8InCpp String sessionId, in String volumeUuid, long bytes,
|
||||
in RemoteCallback callback);
|
||||
void getAnrDelayMillis(String packageName, int uid, in RemoteCallback callback);
|
||||
void notifyAnrDelayStarted(String packageName, int uid, int tid, int reason,
|
||||
in RemoteCallback callback);
|
||||
}
|
||||
@@ -162,22 +162,17 @@ public final class StorageSessionController {
|
||||
*
|
||||
* @return ANR dialog delay in milliseconds
|
||||
*/
|
||||
public long getAnrDelayMillis(String packageName, int uid)
|
||||
public void notifyAnrDelayStarted(String packageName, int uid, int tid, int reason)
|
||||
throws ExternalStorageServiceException {
|
||||
final int userId = UserHandle.getUserId(uid);
|
||||
final StorageUserConnection connection;
|
||||
synchronized (mLock) {
|
||||
int size = mConnections.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
int key = mConnections.keyAt(i);
|
||||
StorageUserConnection connection = mConnections.get(key);
|
||||
if (connection != null) {
|
||||
long delay = connection.getAnrDelayMillis(packageName, uid);
|
||||
if (delay > 0) {
|
||||
return delay;
|
||||
}
|
||||
}
|
||||
}
|
||||
connection = mConnections.get(userId);
|
||||
}
|
||||
|
||||
if (connection != null) {
|
||||
connection.notifyAnrDelayStarted(packageName, uid, tid, reason);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.server.storage;
|
||||
|
||||
import static android.service.storage.ExternalStorageService.EXTRA_ANR_TIMEOUT_MS;
|
||||
import static android.service.storage.ExternalStorageService.EXTRA_ERROR;
|
||||
import static android.service.storage.ExternalStorageService.FLAG_SESSION_ATTRIBUTE_INDEXABLE;
|
||||
import static android.service.storage.ExternalStorageService.FLAG_SESSION_TYPE_FUSE;
|
||||
@@ -148,17 +147,13 @@ public final class StorageUserConnection {
|
||||
*
|
||||
* @return ANR dialog delay in milliseconds
|
||||
*/
|
||||
public long getAnrDelayMillis(String packageName, int uid)
|
||||
public void notifyAnrDelayStarted(String packageName, int uid, int tid, int reason)
|
||||
throws ExternalStorageServiceException {
|
||||
synchronized (mSessionsLock) {
|
||||
for (String sessionId : mSessions.keySet()) {
|
||||
long delay = mActiveConnection.getAnrDelayMillis(packageName, uid);
|
||||
if (delay > 0) {
|
||||
return delay;
|
||||
}
|
||||
mActiveConnection.notifyAnrDelayStarted(packageName, uid, tid, reason);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,9 +248,6 @@ public final class StorageUserConnection {
|
||||
@GuardedBy("mLock")
|
||||
private final ArrayList<CompletableFuture<Void>> mOutstandingOps = new ArrayList<>();
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private final ArrayList<CompletableFuture<Long>> mOutstandingTimeoutOps = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
ServiceConnection oldConnection = null;
|
||||
@@ -272,9 +264,6 @@ public final class StorageUserConnection {
|
||||
for (CompletableFuture<Void> op : mOutstandingOps) {
|
||||
op.cancel(true);
|
||||
}
|
||||
for (CompletableFuture<Long> op : mOutstandingTimeoutOps) {
|
||||
op.cancel(true);
|
||||
}
|
||||
mOutstandingOps.clear();
|
||||
}
|
||||
|
||||
@@ -297,15 +286,6 @@ public final class StorageUserConnection {
|
||||
DEFAULT_REMOTE_TIMEOUT_SECONDS);
|
||||
}
|
||||
|
||||
private long waitForAsyncLong(AsyncStorageServiceCall asyncCall) throws Exception {
|
||||
CompletableFuture<Long> opFuture = new CompletableFuture<>();
|
||||
RemoteCallback callback =
|
||||
new RemoteCallback(result -> setTimeoutResult(result, opFuture));
|
||||
|
||||
return waitForAsync(asyncCall, callback, opFuture, mOutstandingTimeoutOps,
|
||||
1 /* timeoutSeconds */);
|
||||
}
|
||||
|
||||
private <T> T waitForAsync(AsyncStorageServiceCall asyncCall, RemoteCallback callback,
|
||||
CompletableFuture<T> opFuture, ArrayList<CompletableFuture<T>> outstandingOps,
|
||||
long timeoutSeconds) throws Exception {
|
||||
@@ -380,27 +360,17 @@ public final class StorageUserConnection {
|
||||
}
|
||||
}
|
||||
|
||||
public long getAnrDelayMillis(String packgeName, int uid)
|
||||
public void notifyAnrDelayStarted(String packgeName, int uid, int tid, int reason)
|
||||
throws ExternalStorageServiceException {
|
||||
try {
|
||||
return waitForAsyncLong((service, callback) ->
|
||||
service.getAnrDelayMillis(packgeName, uid, callback));
|
||||
waitForAsyncVoid((service, callback) ->
|
||||
service.notifyAnrDelayStarted(packgeName, uid, tid, reason, callback));
|
||||
} catch (Exception e) {
|
||||
throw new ExternalStorageServiceException("Failed to notify app not responding: "
|
||||
throw new ExternalStorageServiceException("Failed to notify ANR delay started: "
|
||||
+ packgeName, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void setTimeoutResult(Bundle result, CompletableFuture<Long> future) {
|
||||
ParcelableException ex = result.getParcelable(EXTRA_ERROR);
|
||||
if (ex != null) {
|
||||
future.completeExceptionally(ex);
|
||||
} else {
|
||||
long timeoutMs = result.getLong(EXTRA_ANR_TIMEOUT_MS);
|
||||
future.complete(timeoutMs);
|
||||
}
|
||||
}
|
||||
|
||||
private void setResult(Bundle result, CompletableFuture<Void> future) {
|
||||
ParcelableException ex = result.getParcelable(EXTRA_ERROR);
|
||||
if (ex != null) {
|
||||
|
||||
Reference in New Issue
Block a user