Merge "Update DocsUI to use AuthenticationRequiredException instead." into arc-apps
diff --git a/src/com/android/documentsui/Model.java b/src/com/android/documentsui/Model.java
index 9cc6972..55f7945 100644
--- a/src/com/android/documentsui/Model.java
+++ b/src/com/android/documentsui/Model.java
@@ -21,7 +21,7 @@
import static com.android.documentsui.base.Shared.VERBOSE;
import android.annotation.IntDef;
-import android.app.RecoverableSecurityException;
+import android.app.AuthenticationRequiredException;
import android.database.Cursor;
import android.database.MergeCursor;
import android.net.Uri;
@@ -310,10 +310,10 @@
return mUpdateType == TYPE_UPDATE_EXCEPTION;
}
- public boolean hasRecoverableException() {
+ public boolean hasAuthenticationException() {
return mRemoteActionEnabled
&& hasException()
- && mException instanceof RecoverableSecurityException;
+ && mException instanceof AuthenticationRequiredException;
}
public @Nullable Exception getException() {
diff --git a/src/com/android/documentsui/dirlist/Message.java b/src/com/android/documentsui/dirlist/Message.java
index fdaf786..41afa32 100644
--- a/src/com/android/documentsui/dirlist/Message.java
+++ b/src/com/android/documentsui/dirlist/Message.java
@@ -17,15 +17,16 @@
package com.android.documentsui.dirlist;
import android.annotation.Nullable;
-import android.app.Activity;
-import android.app.RecoverableSecurityException;
+import android.app.AuthenticationRequiredException;
+import android.app.PendingIntent;
import android.graphics.drawable.Drawable;
+import android.util.Log;
+import com.android.documentsui.Model.Update;
import com.android.documentsui.R;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.Shared;
import com.android.documentsui.dirlist.DocumentsAdapter.Environment;
-import com.android.documentsui.Model.Update;
/**
* Data object used by {@link InflateMessageDocumentHolder} and {@link HeaderMessageDocumentHolder}.
@@ -92,6 +93,7 @@
final static class HeaderMessage extends Message {
+ private static final String TAG = "HeaderMessage";
HeaderMessage(Environment env, Runnable callback) {
super(env, callback);
@@ -103,7 +105,7 @@
// Error gets first dibs ... for now
// TODO: These should be different Message objects getting updated instead of
// overwriting.
- if (event.hasRecoverableException()) {
+ if (event.hasAuthenticationException()) {
updateToRecoverableExceptionHeader(event);
} else if (mEnv.getModel().error != null) {
update(mEnv.getModel().error, null,
@@ -122,9 +124,13 @@
mEnv.getContext().getString(R.string.open_app, root.title),
mEnv.getContext().getDrawable(R.drawable.ic_dialog_info));
mCallback = () -> {
- RecoverableSecurityException exception =
- (RecoverableSecurityException) event.getException();
- exception.showAsDialog((Activity) mEnv.getContext());
+ AuthenticationRequiredException exception =
+ (AuthenticationRequiredException) event.getException();
+ try {
+ exception.getUserAction().send();
+ } catch (PendingIntent.CanceledException ignored) {
+ Log.d(TAG, "User Action either caneled or ignored.");
+ }
};
}
}
@@ -138,7 +144,7 @@
@Override
void update(Update event) {
reset();
- if (event.hasException() && !event.hasRecoverableException()) {
+ if (event.hasException() && !event.hasAuthenticationException()) {
updateToInflatedErrorMesage(
Shared.DEBUG ? Shared.getStackTrace(event.getException()) : null);
} else if (mEnv.getModel().getModelIds().length == 0) {
diff --git a/tests/common/com/android/documentsui/DemoProvider.java b/tests/common/com/android/documentsui/DemoProvider.java
index 2994f61..f8d5eed 100644
--- a/tests/common/com/android/documentsui/DemoProvider.java
+++ b/tests/common/com/android/documentsui/DemoProvider.java
@@ -16,8 +16,8 @@
package com.android.documentsui;
+import android.app.AuthenticationRequiredException;
import android.app.PendingIntent;
-import android.app.RecoverableSecurityException;
import android.content.Intent;
import android.database.Cursor;
import android.database.MatrixCursor;
@@ -90,17 +90,17 @@
case "throw a nice exception":
throw new RuntimeException();
- case "throw a recoverable exception":
+ case "throw a authentication exception":
PendingIntent intent = PendingIntent.getActivity(getContext(), 0, new Intent(), 0);
- throw new RecoverableSecurityException(new UnsupportedOperationException(),
- "message", "title", intent);
+ throw new AuthenticationRequiredException(new UnsupportedOperationException(),
+ intent);
default:
addFolder(c, "show info");
addFolder(c, "show error");
addFolder(c, "show both error and info");
addFolder(c, "throw a nice exception");
- addFolder(c, "throw a recoverable exception");
+ addFolder(c, "throw a authentication exception");
break;
}
diff --git a/tests/functional/com/android/documentsui/FilesActivityUiTest.java b/tests/functional/com/android/documentsui/FilesActivityUiTest.java
index 8d49f3e..9c0dc11 100644
--- a/tests/functional/com/android/documentsui/FilesActivityUiTest.java
+++ b/tests/functional/com/android/documentsui/FilesActivityUiTest.java
@@ -64,7 +64,7 @@
public void testProtectedFolder_showsAuthenticationUi() throws Exception {
bots.roots.openRoot("Demo Root");
bots.main.switchToListMode();
- bots.directory.openDocument("throw a recoverable exception");
+ bots.directory.openDocument("throw a authentication exception");
bots.directory.assertHeaderMessageText(
"Authentication is required to see the content of this directory");