2626import android .annotation .NonNull ;
2727import android .annotation .Nullable ;
2828import android .app .ActivityManager ;
29- import android .app .ActivityManagerInternal ;
3029import android .app .AppGlobals ;
3130import android .app .IActivityManager ;
3231import android .content .ComponentName ;
3332import android .content .Context ;
3433import android .content .pm .ApplicationInfo ;
3534import android .content .pm .PackageManager ;
36- import android .content .pm .PackageManager .NameNotFoundException ;
3735import android .content .pm .ServiceInfo ;
3836import android .graphics .Rect ;
3937import android .graphics .drawable .Drawable ;
4543import android .os .Looper ;
4644import android .os .RemoteCallbackList ;
4745import android .os .RemoteException ;
48- import android .os .UserHandle ;
4946import android .os .UserManager ;
5047import android .provider .Settings ;
5148import android .service .autofill .AutofillService ;
7067import com .android .internal .logging .MetricsLogger ;
7168import com .android .internal .logging .nano .MetricsProto .MetricsEvent ;
7269import com .android .internal .os .HandlerCaller ;
73- import com .android .server .LocalServices ;
7470import com .android .server .autofill .ui .AutoFillUI ;
7571
7672import java .io .PrintWriter ;
@@ -283,7 +279,7 @@ void setHasCallback(int sessionId, int uid, boolean hasIt) {
283279 int startSessionLocked (@ NonNull IBinder activityToken , int uid ,
284280 @ NonNull IBinder appCallbackToken , @ NonNull AutofillId autofillId ,
285281 @ NonNull Rect virtualBounds , @ Nullable AutofillValue value , boolean hasCallback ,
286- int flags , @ NonNull ComponentName componentName ) {
282+ int flags , @ NonNull String packageName ) {
287283 if (!isEnabled ()) {
288284 return 0 ;
289285 }
@@ -293,7 +289,7 @@ int startSessionLocked(@NonNull IBinder activityToken, int uid,
293289 pruneAbandonedSessionsLocked ();
294290
295291 final Session newSession = createSessionByTokenLocked (activityToken , uid , appCallbackToken ,
296- hasCallback , componentName );
292+ hasCallback , packageName );
297293 if (newSession == null ) {
298294 return NO_SESSION ;
299295 }
@@ -390,8 +386,7 @@ void disableOwnedAutofillServicesLocked(int uid) {
390386 }
391387
392388 private Session createSessionByTokenLocked (@ NonNull IBinder activityToken , int uid ,
393- @ NonNull IBinder appCallbackToken , boolean hasCallback ,
394- @ NonNull ComponentName componentName ) {
389+ @ NonNull IBinder appCallbackToken , boolean hasCallback , @ NonNull String packageName ) {
395390 // use random ids so that one app cannot know that another app creates sessions
396391 int sessionId ;
397392 int tries = 0 ;
@@ -405,44 +400,14 @@ private Session createSessionByTokenLocked(@NonNull IBinder activityToken, int u
405400 sessionId = sRandom .nextInt ();
406401 } while (sessionId == NO_SESSION || mSessions .indexOfKey (sessionId ) >= 0 );
407402
408- assertCallerLocked (componentName );
409-
410403 final Session newSession = new Session (this , mUi , mContext , mHandlerCaller , mUserId , mLock ,
411404 sessionId , uid , activityToken , appCallbackToken , hasCallback ,
412- mUiLatencyHistory , mInfo .getServiceInfo ().getComponentName (), componentName );
405+ mUiLatencyHistory , mInfo .getServiceInfo ().getComponentName (), packageName );
413406 mSessions .put (newSession .id , newSession );
414407
415408 return newSession ;
416409 }
417410
418- /**
419- * Asserts the component is owned by the caller.
420- */
421- private void assertCallerLocked (@ NonNull ComponentName componentName ) {
422- final String packageName = componentName .getPackageName ();
423- final PackageManager pm = mContext .getPackageManager ();
424- final int callingUid = Binder .getCallingUid ();
425- final int packageUid ;
426- try {
427- packageUid = pm .getPackageUidAsUser (packageName , UserHandle .getCallingUserId ());
428- } catch (NameNotFoundException e ) {
429- throw new SecurityException ("Could not verify UID for " + componentName );
430- }
431- if (callingUid != packageUid && !LocalServices .getService (ActivityManagerInternal .class )
432- .hasRunningActivity (callingUid , packageName )) {
433- final String [] packages = pm .getPackagesForUid (callingUid );
434- final String callingPackage = packages != null ? packages [0 ] : "uid-" + callingUid ;
435- Slog .w (TAG , "App (package=" + callingPackage + ", UID=" + callingUid
436- + ") passed component (" + componentName + ") owned by UID " + packageUid );
437- mMetricsLogger .write (new LogMaker (MetricsEvent .AUTOFILL_FORGED_COMPONENT_ATTEMPT )
438- .setPackageName (callingPackage )
439- .addTaggedData (MetricsEvent .FIELD_AUTOFILL_SERVICE , getServicePackageName ())
440- .addTaggedData (MetricsEvent .FIELD_AUTOFILL_FORGED_COMPONENT_NAME ,
441- componentName == null ? "null" : componentName .flattenToShortString ()));
442- throw new SecurityException ("Invalid component: " + componentName );
443- }
444- }
445-
446411 /**
447412 * Restores a session after an activity was temporarily destroyed.
448413 *
0 commit comments