2021-07-24 02:37:17 +00:00
package androidx.core.app ;
import android.app.Activity ;
import android.content.ComponentName ;
import android.content.Context ;
import android.content.Intent ;
import android.content.pm.ActivityInfo ;
import android.content.pm.PackageManager ;
import android.os.Build ;
import android.os.Bundle ;
import android.util.Log ;
import androidx.annotation.NonNull ;
import androidx.annotation.Nullable ;
2021-12-17 21:59:34 +00:00
import b.d.b.a.a ;
2022-03-07 09:34:54 +00:00
/* loaded from: classes.dex */
2021-07-24 02:37:17 +00:00
public final class NavUtils {
public static final String PARENT_ACTIVITY = " android.support.PARENT_ACTIVITY " ;
private static final String TAG = " NavUtils " ;
private NavUtils ( ) {
}
@Nullable
public static Intent getParentActivityIntent ( @NonNull Activity activity ) {
Intent parentActivityIntent = activity . getParentActivityIntent ( ) ;
if ( parentActivityIntent ! = null ) {
return parentActivityIntent ;
}
String parentActivityName = getParentActivityName ( activity ) ;
if ( parentActivityName = = null ) {
return null ;
}
ComponentName componentName = new ComponentName ( activity , parentActivityName ) ;
try {
return getParentActivityName ( activity , componentName ) = = null ? Intent . makeMainActivity ( componentName ) : new Intent ( ) . setComponent ( componentName ) ;
} catch ( PackageManager . NameNotFoundException unused ) {
2021-08-09 22:51:56 +00:00
Log . e ( TAG , " getParentActivityIntent: bad parentActivityName ' " + parentActivityName + " ' in manifest " ) ;
2021-07-24 02:37:17 +00:00
return null ;
}
}
@Nullable
public static Intent getParentActivityIntent ( @NonNull Context context , @NonNull ComponentName componentName ) throws PackageManager . NameNotFoundException {
String parentActivityName = getParentActivityName ( context , componentName ) ;
if ( parentActivityName = = null ) {
return null ;
}
ComponentName componentName2 = new ComponentName ( componentName . getPackageName ( ) , parentActivityName ) ;
return getParentActivityName ( context , componentName2 ) = = null ? Intent . makeMainActivity ( componentName2 ) : new Intent ( ) . setComponent ( componentName2 ) ;
}
@Nullable
public static Intent getParentActivityIntent ( @NonNull Context context , @NonNull Class < ? > cls ) throws PackageManager . NameNotFoundException {
String parentActivityName = getParentActivityName ( context , new ComponentName ( context , cls ) ) ;
if ( parentActivityName = = null ) {
return null ;
}
ComponentName componentName = new ComponentName ( context , parentActivityName ) ;
return getParentActivityName ( context , componentName ) = = null ? Intent . makeMainActivity ( componentName ) : new Intent ( ) . setComponent ( componentName ) ;
}
@Nullable
public static String getParentActivityName ( @NonNull Activity activity ) {
try {
return getParentActivityName ( activity , activity . getComponentName ( ) ) ;
} catch ( PackageManager . NameNotFoundException e ) {
throw new IllegalArgumentException ( e ) ;
}
}
@Nullable
public static String getParentActivityName ( @NonNull Context context , @NonNull ComponentName componentName ) throws PackageManager . NameNotFoundException {
String string ;
PackageManager packageManager = context . getPackageManager ( ) ;
int i = Build . VERSION . SDK_INT ;
int i2 = 640 ;
if ( i > = 29 ) {
i2 = 269222528 ;
} else if ( i > = 24 ) {
i2 = 787072 ;
}
ActivityInfo activityInfo = packageManager . getActivityInfo ( componentName , i2 ) ;
String str = activityInfo . parentActivityName ;
if ( str ! = null ) {
return str ;
}
Bundle bundle = activityInfo . metaData ;
2021-08-09 22:51:56 +00:00
if ( bundle = = null | | ( string = bundle . getString ( PARENT_ACTIVITY ) ) = = null ) {
2021-07-24 02:37:17 +00:00
return null ;
}
if ( string . charAt ( 0 ) ! = '.' ) {
return string ;
}
return context . getPackageName ( ) + string ;
}
public static void navigateUpFromSameTask ( @NonNull Activity activity ) {
Intent parentActivityIntent = getParentActivityIntent ( activity ) ;
if ( parentActivityIntent ! = null ) {
navigateUpTo ( activity , parentActivityIntent ) ;
return ;
}
2022-03-21 18:52:30 +00:00
StringBuilder R = a . R ( " Activity " ) ;
R . append ( activity . getClass ( ) . getSimpleName ( ) ) ;
R . append ( " does not have a parent activity name specified. (Did you forget to add the android.support.PARENT_ACTIVITY <meta-data> element in your manifest?) " ) ;
throw new IllegalArgumentException ( R . toString ( ) ) ;
2021-07-24 02:37:17 +00:00
}
public static void navigateUpTo ( @NonNull Activity activity , @NonNull Intent intent ) {
activity . navigateUpTo ( intent ) ;
}
public static boolean shouldUpRecreateTask ( @NonNull Activity activity , @NonNull Intent intent ) {
return activity . shouldUpRecreateTask ( intent ) ;
}
}