Merge "Verify enableOnBackInvokedCallback at the app-level if ActivityInfo is null" into udc-dev am: 379a3d5325
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22852616 Change-Id: I3e3b222eb0364eae3685b5956bbb3dd966e81dc8 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -21,6 +21,8 @@ import android.annotation.Nullable;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
@@ -421,36 +423,45 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean requestsPredictiveBack;
|
boolean requestsPredictiveBack = false;
|
||||||
|
|
||||||
// Check if the context is from an activity.
|
// Check if the context is from an activity.
|
||||||
while ((context instanceof ContextWrapper) && !(context instanceof Activity)) {
|
while ((context instanceof ContextWrapper) && !(context instanceof Activity)) {
|
||||||
context = ((ContextWrapper) context).getBaseContext();
|
context = ((ContextWrapper) context).getBaseContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean shouldCheckActivity = false;
|
||||||
|
|
||||||
if (context instanceof Activity) {
|
if (context instanceof Activity) {
|
||||||
final Activity activity = (Activity) context;
|
final Activity activity = (Activity) context;
|
||||||
|
|
||||||
if (activity.getActivityInfo().hasOnBackInvokedCallbackEnabled()) {
|
final ActivityInfo activityInfo = activity.getActivityInfo();
|
||||||
requestsPredictiveBack =
|
if (activityInfo != null) {
|
||||||
activity.getActivityInfo().isOnBackInvokedCallbackEnabled();
|
if (activityInfo.hasOnBackInvokedCallbackEnabled()) {
|
||||||
} else {
|
shouldCheckActivity = true;
|
||||||
requestsPredictiveBack =
|
requestsPredictiveBack = activityInfo.isOnBackInvokedCallbackEnabled();
|
||||||
context.getApplicationInfo().isOnBackInvokedCallbackEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, TextUtils.formatSimple("Activity: %s isPredictiveBackEnabled=%s",
|
Log.d(TAG, TextUtils.formatSimple(
|
||||||
activity.getComponentName(),
|
"Activity: %s isPredictiveBackEnabled=%s",
|
||||||
requestsPredictiveBack));
|
activity.getComponentName(),
|
||||||
|
requestsPredictiveBack));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "The ActivityInfo is null, so we cannot verify if this Activity"
|
||||||
|
+ " has the 'android:enableOnBackInvokedCallback' attribute."
|
||||||
|
+ " The application attribute will be used as a fallback.");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
requestsPredictiveBack =
|
|
||||||
context.getApplicationInfo().isOnBackInvokedCallbackEnabled();
|
if (!shouldCheckActivity) {
|
||||||
|
final ApplicationInfo applicationInfo = context.getApplicationInfo();
|
||||||
|
requestsPredictiveBack = applicationInfo.isOnBackInvokedCallbackEnabled();
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, TextUtils.formatSimple("App: %s requestsPredictiveBack=%s",
|
Log.d(TAG, TextUtils.formatSimple("App: %s requestsPredictiveBack=%s",
|
||||||
context.getApplicationInfo().packageName,
|
applicationInfo.packageName,
|
||||||
requestsPredictiveBack));
|
requestsPredictiveBack));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user