diff options
author | Gavin Corkery <gavincorkery@google.com> | 2020-12-14 18:55:55 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-12-14 18:55:55 +0000 |
commit | d45d533b6ec1bb16440b35039c324f9a29dea03b (patch) | |
tree | 416f67fb265a4488d31d5c8a89a71f6711299f48 | |
parent | 85ebf98dcf011e30e41f0bb6369e5168fa639581 (diff) | |
parent | 00dff9634c671ff2d1759f0600414bce1e0646c6 (diff) |
Merge "Replace broadcast with adding a method in BugreportCallback"
5 files changed, 30 insertions, 17 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index e8579517a9e5..244df9b59cc8 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -7001,6 +7001,7 @@ package android.os { public abstract static class BugreportManager.BugreportCallback { ctor public BugreportManager.BugreportCallback(); + method public void onEarlyReportFinished(); method public void onError(int); method public void onFinished(); method public void onProgress(@FloatRange(from=0.0f, to=100.0f) float); diff --git a/core/java/android/os/BugreportManager.java b/core/java/android/os/BugreportManager.java index fe4d7296503f..46ad7b880a37 100644 --- a/core/java/android/os/BugreportManager.java +++ b/core/java/android/os/BugreportManager.java @@ -26,7 +26,6 @@ import android.annotation.SystemApi; import android.annotation.SystemService; import android.app.ActivityManager; import android.content.Context; -import android.content.Intent; import android.os.Handler; import android.util.Log; import android.widget.Toast; @@ -52,8 +51,6 @@ import java.util.concurrent.Executor; public final class BugreportManager { private static final String TAG = "BugreportManager"; - private static final String INTENT_UI_INTENSIVE_BUGREPORT_DUMPS_FINISHED = - "com.android.internal.intent.action.UI_INTENSIVE_BUGREPORT_DUMPS_FINISHED"; private final Context mContext; private final IDumpstate mBinder; @@ -126,6 +123,12 @@ public final class BugreportManager { * Called when taking bugreport finishes successfully. */ public void onFinished() {} + + /** + * Called when it is ready for calling app to show UI, showing any extra UI before this + * callback can interfere with bugreport generation. + */ + public void onEarlyReportFinished() {} } /** @@ -288,21 +291,12 @@ public final class BugreportManager { } @Override - public void onUiIntensiveBugreportDumpsFinished(String callingPackage) + public void onUiIntensiveBugreportDumpsFinished() throws RemoteException { final long identity = Binder.clearCallingIdentity(); try { mExecutor.execute(() -> { - // Send intent to let calling app to show UI safely without interfering with - // the bugreport/screenshot generation. - // TODO(b/154298410): When S is ready for API change, add a method in - // BugreportCallback so we can just call the callback instead of using - // broadcast. - Intent intent = new Intent(INTENT_UI_INTENSIVE_BUGREPORT_DUMPS_FINISHED); - intent.setPackage(callingPackage); - intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); - intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); - mContext.sendBroadcast(intent, android.Manifest.permission.DUMP); + mCallback.onEarlyReportFinished(); }); } finally { Binder.restoreCallingIdentity(identity); diff --git a/core/tests/bugreports/src/com/android/os/bugreports/tests/BugreportManagerTest.java b/core/tests/bugreports/src/com/android/os/bugreports/tests/BugreportManagerTest.java index 9246a2335050..f9e3bc60561c 100644 --- a/core/tests/bugreports/src/com/android/os/bugreports/tests/BugreportManagerTest.java +++ b/core/tests/bugreports/src/com/android/os/bugreports/tests/BugreportManagerTest.java @@ -118,6 +118,7 @@ public class BugreportManagerTest { // Wifi bugreports should not receive any progress. assertThat(callback.hasReceivedProgress()).isFalse(); assertThat(mBugreportFile.length()).isGreaterThan(0L); + assertThat(callback.hasEarlyReportFinished()).isTrue(); assertFdsAreClosed(mBugreportFd); } @@ -135,6 +136,7 @@ public class BugreportManagerTest { // Interactive bugreports show progress updates. assertThat(callback.hasReceivedProgress()).isTrue(); assertThat(mBugreportFile.length()).isGreaterThan(0L); + assertThat(callback.hasEarlyReportFinished()).isTrue(); assertFdsAreClosed(mBugreportFd); } @@ -246,6 +248,7 @@ public class BugreportManagerTest { private int mErrorCode = -1; private boolean mSuccess = false; private boolean mReceivedProgress = false; + private boolean mEarlyReportFinished = false; private final Object mLock = new Object(); @Override @@ -271,6 +274,13 @@ public class BugreportManagerTest { } } + @Override + public void onEarlyReportFinished() { + synchronized (mLock) { + mEarlyReportFinished = true; + } + } + /* Indicates completion; and ended up with a success or error. */ public boolean isDone() { synchronized (mLock) { @@ -295,6 +305,12 @@ public class BugreportManagerTest { return mReceivedProgress; } } + + public boolean hasEarlyReportFinished() { + synchronized (mLock) { + return mEarlyReportFinished; + } + } } public static BugreportManager getBugreportManager() { diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index 02815a571db8..63b9bb39cba0 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -378,6 +378,9 @@ public class BugreportProgressService extends Service { } } + @Override + public void onEarlyReportFinished() {} + /** * Reads bugreport id and links it to the bugreport info to track a bugreport that is in * process. id is incremented in the dumpstate code. diff --git a/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java b/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java index 47fcc0872029..dd507a3b1f81 100644 --- a/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java +++ b/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java @@ -297,9 +297,8 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub { } @Override - public void onUiIntensiveBugreportDumpsFinished(String callingPackage) - throws RemoteException { - mListener.onUiIntensiveBugreportDumpsFinished(callingPackage); + public void onUiIntensiveBugreportDumpsFinished() throws RemoteException { + mListener.onUiIntensiveBugreportDumpsFinished(); } @Override |