2424import android .annotation .NonNull ;
2525import android .annotation .Nullable ;
2626import android .annotation .SystemService ;
27- import android .app .Activity ;
2827import android .content .ComponentName ;
2928import android .content .Context ;
3029import android .content .Intent ;
@@ -387,6 +386,13 @@ boolean autofillCallbackRequestShowFillUi(@NonNull View anchor, int width, int h
387386 * Runs the specified action on the UI thread.
388387 */
389388 void runOnUiThread (Runnable action );
389+
390+ /**
391+ * Gets the complete component name of this client.
392+ *
393+ * <p>Temporary method on O-MR1 only.
394+ */
395+ ComponentName getComponentNameForAutofill ();
390396 }
391397
392398 /**
@@ -943,11 +949,8 @@ private AutofillClient getClientLocked() {
943949 return mContext .getAutofillClient ();
944950 }
945951
946- private ComponentName getComponentNameFromContext () {
947- if (mContext instanceof Activity ) {
948- return ((Activity ) mContext ).getComponentName ();
949- }
950- return null ;
952+ private ComponentName getComponentNameFromContext (AutofillClient client ) {
953+ return client == null ? null : client .getComponentNameForAutofill ();
951954 }
952955
953956 /** @hide */
@@ -1000,7 +1003,8 @@ private void startSessionLocked(@NonNull AutofillId id, @NonNull Rect bounds,
10001003 return ;
10011004 }
10021005 try {
1003- final ComponentName componentName = getComponentNameFromContext ();
1006+ final AutofillClient client = getClientLocked ();
1007+ final ComponentName componentName = getComponentNameFromContext (client );
10041008 if (componentName == null ) {
10051009 Log .w (TAG , "startSessionLocked(): context is not activity: " + mContext );
10061010 return ;
@@ -1011,7 +1015,6 @@ private void startSessionLocked(@NonNull AutofillId id, @NonNull Rect bounds,
10111015 if (mSessionId != NO_SESSION ) {
10121016 mState = STATE_ACTIVE ;
10131017 }
1014- final AutofillClient client = getClientLocked ();
10151018 if (client != null ) {
10161019 client .autofillCallbackResetableStateAvailable ();
10171020 }
@@ -1065,7 +1068,8 @@ private void updateSessionLocked(AutofillId id, Rect bounds, AutofillValue value
10651068
10661069 try {
10671070 if (restartIfNecessary ) {
1068- final ComponentName componentName = getComponentNameFromContext ();
1071+ final AutofillClient client = getClientLocked ();
1072+ final ComponentName componentName = getComponentNameFromContext (client );
10691073 if (componentName == null ) {
10701074 Log .w (TAG , "startSessionLocked(): context is not activity: " + mContext );
10711075 return ;
@@ -1077,7 +1081,6 @@ private void updateSessionLocked(AutofillId id, Rect bounds, AutofillValue value
10771081 if (sDebug ) Log .d (TAG , "Session restarted: " + mSessionId + "=>" + newId );
10781082 mSessionId = newId ;
10791083 mState = (mSessionId == NO_SESSION ) ? STATE_UNKNOWN : STATE_ACTIVE ;
1080- final AutofillClient client = getClientLocked ();
10811084 if (client != null ) {
10821085 client .autofillCallbackResetableStateAvailable ();
10831086 }
0 commit comments