Search in sources :

Example 16 with ResolveInfo

use of android.content.pm.ResolveInfo in project atlas by alibaba.

the class InstrumentationHook method execStartActivityInternal.

private ActivityResult execStartActivityInternal(final Context context, final Intent intent, final int requestCode, ExecStartActivityCallback callback) {
    //intent.putExtra("atlas_wrapper",true);
    /**
         * bundle update后可能需要预处理
         */
    Log.e("InsturmentationHook", "patch execStartActivity start");
    if (BundlePackageManager.isNeedCheck(intent)) {
        List<org.osgi.framework.Bundle> bundles = Atlas.getInstance().getBundles();
        for (org.osgi.framework.Bundle bundle : bundles) {
            if (((BundleImpl) bundle).isUpdated()) {
                BundlePackageManager packageManager = ((BundleImpl) bundle).getPackageManager();
                if (null != packageManager && packageManager.wrapperActivityIntentIfNeed(intent) != null) {
                    break;
                }
            }
        }
    }
    if (intent != null) {
        Atlas.getInstance().checkDownGradeToH5(intent);
    }
    // Get package name and component name
    String packageName = null;
    String componentName = null;
    if (intent.getComponent() != null) {
        packageName = intent.getComponent().getPackageName();
        componentName = intent.getComponent().getClassName();
    } else {
        ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, 0);
        if (resolveInfo != null && resolveInfo.activityInfo != null) {
            packageName = resolveInfo.activityInfo.packageName;
            componentName = resolveInfo.activityInfo.name;
        }
    }
    if (componentName == null) {
        ActivityResult result = null;
        try {
            // Just invoke callback since component is null
            result = callback.execStartActivity();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    // Taobao may start a component not exist in com.taobao.taobao package.
    if (!StringUtils.equals(context.getPackageName(), packageName)) {
        if (sOnIntentRedirectListener != null) {
            Activity sourceActivity = ActivityTaskMgr.getInstance().peekTopActivity();
            if (!sOnIntentRedirectListener.onExternalRedirect(intent, packageName, componentName, sourceActivity)) {
                Log.e("InstrumentationHook", "fiter app" + packageName);
                return null;
            }
        }
        return callback.execStartActivity();
    }
    String bundleName = AtlasBundleInfoManager.instance().getBundleForComponet(componentName);
    if (!TextUtils.isEmpty(bundleName)) {
        BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(bundleName);
        if (impl != null && impl.checkValidate()) {
            return callback.execStartActivity();
        } else {
            if (ActivityTaskMgr.getInstance().peekTopActivity() != null && Looper.getMainLooper().getThread().getId() == Thread.currentThread().getId()) {
                final String component = componentName;
                asyncStartActivity(context, bundleName, intent, requestCode, component, callback);
            } else {
                callback.execStartActivity();
                Log.e("InsturmentationHook", "patch execStartActivity finish");
            }
        }
        return null;
    }
    // Try to get class from system Classloader
    try {
        Class<?> clazz = null;
        clazz = Framework.getSystemClassLoader().loadClass(componentName);
        if (clazz != null) {
            return callback.execStartActivity();
        }
    } catch (ClassNotFoundException e) {
        fallBackToClassNotFoundCallback(context, intent, componentName);
    }
    return null;
}
Also used : BundleImpl(android.taobao.atlas.framework.BundleImpl) Bundle(android.os.Bundle) BundlePackageManager(android.taobao.atlas.runtime.newcomponent.BundlePackageManager) Activity(android.app.Activity) ResolveInfo(android.content.pm.ResolveInfo)

Example 17 with ResolveInfo

use of android.content.pm.ResolveInfo in project atlas by alibaba.

the class ServiceDetector method findComponent.

public static String findComponent(Intent intent) {
    /*
    	 * Get Package name and component name
    	 */
    String packageName = null;
    String componentName = null;
    if (intent.getComponent() != null) {
        packageName = intent.getComponent().getPackageName();
        componentName = intent.getComponent().getClassName();
    } else {
        ResolveInfo resolveInfo = RuntimeVariables.androidApplication.getPackageManager().resolveService(intent, 0);
        if (resolveInfo != null && resolveInfo.serviceInfo != null) {
            packageName = resolveInfo.serviceInfo.packageName;
            componentName = resolveInfo.serviceInfo.name;
        }
    }
    /*
		 * Taobao may start a component not exist in com.taobao.taobao package
		 */
    if (!StringUtils.equals(RuntimeVariables.androidApplication.getPackageName(), packageName)) {
        return null;
    }
    return componentName;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo)

Example 18 with ResolveInfo

use of android.content.pm.ResolveInfo in project atlas by alibaba.

the class BundlePackageManager method wrapperActivityIntentIfNeed.

/**
     * 检测是否要对Intent进行封装
     * @param intent
     * @return
     */
public ResolveInfo wrapperActivityIntentIfNeed(Intent intent) {
    if (intent == null) {
        return null;
    }
    intent.putExtra("atlas_checked", true);
    if (mExternalActivity != null) {
        ComponentName comp = intent.getComponent();
        if (comp == null) {
            if (intent.getSelector() != null) {
                intent = intent.getSelector();
                comp = intent.getComponent();
            }
        }
        if (comp != null && null == AtlasBundleInfoManager.instance().getBundleForComponet(comp.getClassName())) {
            Object activityObj = mExternalActivity.mComponents.get(comp);
            if (activityObj != null) {
                try {
                    final ResolveInfo ri = new ResolveInfo();
                    ri.activityInfo = (ActivityInfo) activityObj.getClass().getField("info").get(activityObj);
                    wrapperActivityIntent(intent, ri.activityInfo);
                    return ri;
                } catch (Exception e) {
                    return null;
                }
            } else {
                return null;
            }
        } else {
            // 先检测包名
            if (!TextUtils.isEmpty(intent.getPackage()) && !TextUtils.equals(intent.getPackage(), RuntimeVariables.androidApplication.getPackageName())) {
                return null;
            }
            List<ResolveInfo> activityList = mExternalActivity.queryIntent(intent, intent.resolveTypeIfNeeded(RuntimeVariables.androidApplication.getContentResolver()), false);
            if (activityList != null && activityList.size() > 0) {
                /**
                     * 暂时先不增加chooseBestActivity的逻辑
                     */
                wrapperActivityIntent(intent, activityList.get(0).activityInfo);
                return activityList.get(0);
            } else {
                return null;
            }
        }
    } else {
        return null;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ComponentName(android.content.ComponentName) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 19 with ResolveInfo

use of android.content.pm.ResolveInfo in project atlas by alibaba.

the class BundlePackageManager method queryIntentService.

/**
     * 新增service中进行优先filter
     * @param intent
     * @param resolvedType
     * @param flags
     * @param userId
     * @return
     */
public static List<ResolveInfo> queryIntentService(Intent intent, String resolvedType, int flags, int userId) {
    List<Bundle> bundles = Atlas.getInstance().getBundles();
    for (Bundle bundle : bundles) {
        BundleImpl impl = (BundleImpl) bundle;
        if (impl.isUpdated() && impl.getPackageManager() != null) {
            ResolveInfo info = impl.getPackageManager().wrapperServiceIntentIfNeed(intent);
            if (info != null) {
                List<ResolveInfo> rf = new ArrayList<ResolveInfo>(1);
                rf.add(info);
                return rf;
            }
        }
    }
    return null;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) BundleImpl(android.taobao.atlas.framework.BundleImpl) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList)

Example 20 with ResolveInfo

use of android.content.pm.ResolveInfo in project atlas by alibaba.

the class BundlePackageManager method wrapperServiceIntentIfNeed.

/**
     * Service 和 Activity支持动态部署的逻辑存在不同:
     * 动态部署新增的Activity是通过外壳欺骗PackageManagerService,并运用其创建的Binder生成完整的Activity
     * 动态部署新增的Service不同于正常使用的service,目前只支持LocalAIDLService,只是通过代理查找到Service的resolveInfo,并直接通过
     * Class创建Object,然后进程内管理其生命周期,并未通过IPC和PackageManagerService进行通信,不同于android原生的Service
     */
public ResolveInfo wrapperServiceIntentIfNeed(Intent intent) {
    if (intent == null) {
        return null;
    }
    intent.putExtra("atlas_checked", true);
    if (mExternalServices != null) {
        ComponentName comp = intent.getComponent();
        if (comp == null) {
            if (intent.getSelector() != null) {
                intent = intent.getSelector();
                comp = intent.getComponent();
            }
        }
        if (comp != null && null == AtlasBundleInfoManager.instance().getBundleForComponet(comp.getClassName())) {
            Object serviceObj = mExternalServices.mComponents.get(comp);
            if (serviceObj != null) {
                try {
                    final ResolveInfo ri = new ResolveInfo();
                    ri.serviceInfo = (ServiceInfo) serviceObj.getClass().getField("info").get(serviceObj);
                    BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(bundleName);
                    if (!impl.getArchive().isDexOpted()) {
                        impl.getArchive().optDexFile();
                    }
                    return ri;
                } catch (Exception e) {
                    return null;
                }
            } else {
                return null;
            }
        } else {
            // 先检测包名
            if (!TextUtils.isEmpty(intent.getPackage()) && !TextUtils.equals(intent.getPackage(), RuntimeVariables.androidApplication.getPackageName())) {
                return null;
            }
            List<ResolveInfo> serviceList = mExternalServices.queryIntent(intent, intent.resolveTypeIfNeeded(RuntimeVariables.androidApplication.getContentResolver()), false);
            if (serviceList != null && serviceList.size() > 0) {
                BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(bundleName);
                if (!impl.getArchive().isDexOpted()) {
                    impl.getArchive().optDexFile();
                }
                return serviceList.get(0);
            } else {
                return null;
            }
        }
    } else {
        return null;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) BundleImpl(android.taobao.atlas.framework.BundleImpl) ComponentName(android.content.ComponentName) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ResolveInfo (android.content.pm.ResolveInfo)2316 Intent (android.content.Intent)1476 PackageManager (android.content.pm.PackageManager)875 ComponentName (android.content.ComponentName)637 ArrayList (java.util.ArrayList)515 ActivityInfo (android.content.pm.ActivityInfo)360 Test (org.junit.Test)282 ServiceInfo (android.content.pm.ServiceInfo)203 PendingIntent (android.app.PendingIntent)183 ApplicationInfo (android.content.pm.ApplicationInfo)178 RemoteException (android.os.RemoteException)170 Context (android.content.Context)101 Bundle (android.os.Bundle)97 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)81 IOException (java.io.IOException)78 PackageInfo (android.content.pm.PackageInfo)68 HashSet (java.util.HashSet)65 HashMap (java.util.HashMap)63 ActivityNotFoundException (android.content.ActivityNotFoundException)59 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)58