本文整理汇总了Java中android.content.pm.ComponentInfo类的典型用法代码示例。如果您正苦于以下问题:Java ComponentInfo类的具体用法?Java ComponentInfo怎么用?Java ComponentInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ComponentInfo类属于android.content.pm包,在下文中一共展示了ComponentInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preMakeApplication
import android.content.pm.ComponentInfo; //导入依赖的package包/类
private static void preMakeApplication(Context hostContext, ComponentInfo pluginInfo) {
try {
Object loadedApk = sPluginLoadedApkCache.get(pluginInfo.packageName);
if (loadedApk != null && FieldUtils.readField(loadedApk, "mApplication") == null) {
if (Looper.getMainLooper() != Looper.myLooper()) {
Object lock = new Object();
mExec.set(false);
mHandle.post(new 1(loadedApk, pluginInfo, lock));
if (!mExec.get()) {
synchronized (lock) {
try {
lock.wait();
} catch (InterruptedException e) {
}
}
return;
}
return;
}
MethodUtils.invokeMethod(loadedApk, "makeApplication", Boolean.valueOf(false), ActivityThreadCompat.getInstrumentation());
}
} catch (Exception e2) {
JLog.logApk("插件preMakeApplication 失败 e=" + e2.getMessage());
}
}
示例2: doAdjust
import android.content.pm.ComponentInfo; //导入依赖的package包/类
private void doAdjust(HashMap<String, String> processMap, HashMap<String, ? extends ComponentInfo> infos) throws Exception {
for (HashMap.Entry<String, ? extends ComponentInfo> entry : infos.entrySet()) {
ComponentInfo info = entry.getValue();
if (info != null) {
String targetProcess = processMap.get(info.processName);
// 如果原始进程名称为空,说明解析插件 apk 时有问题(未解析每个组件的进程名称)。
// 此处抛出异常。
if (!TextUtils.isEmpty(targetProcess)) {
info.processName = targetProcess;
}
if (LOG) {
Log.d(PLUGIN_TAG, info.name + ":" + info.processName);
}
}
}
}
示例3: getStubProcessByTarget
import android.content.pm.ComponentInfo; //导入依赖的package包/类
public String getStubProcessByTarget(ComponentInfo targetInfo) {
for (ProcessItem processItem : items.values()) {
if (processItem.pkgs.contains(targetInfo.packageName) && TextUtils.equals(processItem.targetProcessName, targetInfo.processName)) {
return processItem.stubProcessName;
} else {
try {
boolean signed = false;
for (String pkg : processItem.pkgs) {
if (PluginManager.getInstance().checkSignatures(targetInfo.packageName, pkg) == PackageManager.SIGNATURE_MATCH) {
signed = true;
break;
}
}
if (signed && TextUtils.equals(processItem.targetProcessName, targetInfo.processName)) {
return processItem.stubProcessName;
}
} catch (Exception e) {
Log.e(TAG, "getStubProcessByTarget:error", e);
}
}
}
return null;
}
示例4: getStubProcessByTarget
import android.content.pm.ComponentInfo; //导入依赖的package包/类
public String getStubProcessByTarget(ComponentInfo targetInfo) {
for (ProcessItem processItem : items.values()) {
if (processItem.pkgs.contains(targetInfo.packageName) && TextUtils.equals(processItem.targetProcessName, targetInfo.processName)) {
return processItem.stubProcessName;
} else {
try {
boolean signed = false;
for (String pkg : processItem.pkgs) {
if (PluginManager.getInstance().checkSignatures(targetInfo.packageName, pkg) == PackageManager.SIGNATURE_MATCH) {
signed = true;
break;
}
}
if (signed && TextUtils.equals(processItem.targetProcessName, targetInfo.processName)) {
return processItem.stubProcessName;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return null;
}
示例5: isDevicePlugin
import android.content.pm.ComponentInfo; //导入依赖的package包/类
private boolean isDevicePlugin(final ComponentInfo compInfo) {
if (!compInfo.exported) {
return false;
}
Bundle metaData = compInfo.metaData;
if (metaData == null) {
return false;
}
if (metaData.get(PLUGIN_META_DATA) == null) {
return false;
}
if (!(metaData.get(PLUGIN_META_DATA) instanceof Integer)) {
return false;
}
DevicePluginXml xml = DevicePluginXmlUtil.getXml(mContext, compInfo);
return xml != null;
}
示例6: parseComponentItem
import android.content.pm.ComponentInfo; //导入依赖的package包/类
/**
* <href a="http://developer.android.com/reference/android/content/pm/ComponentInfo.html">ComponentInfo</href>
*/
private static void parseComponentItem(XmlResourceParser parser,
ComponentInfo info) {
final int attCount = parser.getAttributeCount();
for (int i = 0; i < attCount; i++) {
String attName = parser.getAttributeName(i);
String attValue = parser.getAttributeValue(i);
if (ATTR_PROCESS.equals(attName)) {
String cName = attValue;
info.processName = cName;
} else if (ATTR_EXPORTED.equals(attName)) {
info.exported = Boolean.parseBoolean(attName);
} else if (ATTR_ENABLED.equals(attName)) {
info.enabled = Boolean.parseBoolean(attName);
} else if (ATTR_DESCRIPTION.equals(attName)) {
info.descriptionRes = toResId(attValue);
}
}
parsePackageItem(parser, info);
}
示例7: isComponentEnabled
import android.content.pm.ComponentInfo; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static boolean isComponentEnabled(PackageManager manager, ComponentName component) {
switch (manager.getComponentEnabledSetting(component)) {
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
return false;
case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
return true;
case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
default:
try {
PackageInfo packageInfo = manager.getPackageInfo(
component.getPackageName(),
PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES
| PackageManager.GET_PROVIDERS | PackageManager.GET_DISABLED_COMPONENTS);
List<ComponentInfo> components = new ArrayList<>();
if (packageInfo.activities != null) {
Collections.addAll(components, packageInfo.activities);
}
if (packageInfo.services != null) {
Collections.addAll(components, packageInfo.services);
}
if (packageInfo.providers != null) {
Collections.addAll(components, packageInfo.providers);
}
for (ComponentInfo componentInfo : components) {
if (componentInfo.name.equals(component.getClassName())) {
return componentInfo.isEnabled();
}
}
return false;
} catch (PackageManager.NameNotFoundException e) {
// the package isn't installed on the device
return false;
}
}
}
示例8: isComponentEnabled
import android.content.pm.ComponentInfo; //导入依赖的package包/类
public static boolean isComponentEnabled(PackageManager pm, String pkg, String cls) {
ComponentName componentName = new ComponentName(pkg, cls);
int componentEnabledSetting = pm.getComponentEnabledSetting(componentName);
switch (componentEnabledSetting) {
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
return false;
case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
return true;
case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
default:
// We need to get the application info to get the component's default state
try {
PackageInfo packageInfo = pm.getPackageInfo(pkg, PackageManager.GET_ACTIVITIES
| PackageManager.GET_RECEIVERS
| PackageManager.GET_SERVICES
| PackageManager.GET_PROVIDERS
| PackageManager.GET_DISABLED_COMPONENTS);
List<ComponentInfo> components = new ArrayList<>();
if (packageInfo.activities != null) Collections.addAll(components, packageInfo.activities);
if (packageInfo.services != null) Collections.addAll(components, packageInfo.services);
if (packageInfo.providers != null) Collections.addAll(components, packageInfo.providers);
for (ComponentInfo componentInfo : components) {
if (componentInfo.name.equals(cls)) {
return componentInfo.enabled; //This is the default value (set in AndroidManifest.xml)
//return componentInfo.isEnabled(); //Whole package dependant
}
}
// the component is not declared in the AndroidManifest
return false;
} catch (PackageManager.NameNotFoundException e) {
// the package isn't installed on the device
return false;
}
}
}
示例9: queryIntentResolveInfo
import android.content.pm.ComponentInfo; //导入依赖的package包/类
private <T extends ComponentInfo> ResolveInfo queryIntentResolveInfo(Intent intent,Class<T> infoClass ){
if(intent==null){
return null;
}
AdditionalComponentIntentResolver resolver = null;
if(infoClass == ActivityInfo.class){
resolver = mExternalActivity;
}else{
resolver = mExternalServices;
}
if(resolver!=null) {
ComponentName comp = intent.getComponent();
if (comp == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
if (intent.getSelector() != null) {
intent = intent.getSelector();
comp = intent.getComponent();
}
}
}
if (comp != null) {
Object obj = resolver.mComponents.get(comp);
if (obj!=null){
try {
final ResolveInfo ri = new ExternalResolverInfo();
if(resolver == mExternalActivity) {
ri.activityInfo = (ActivityInfo) obj.getClass().getField("info").get(obj);
}else{
ri.serviceInfo = (ServiceInfo) obj.getClass().getField("info").get(obj);
}
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> list = resolver.queryIntent(intent,
intent.resolveTypeIfNeeded(RuntimeVariables.androidApplication.getContentResolver()), false);
if(list!=null && list.size()>0){
return new ExternalResolverInfo(list.get(0));
}else{
return null;
}
}
}else{
return null;
}
}
示例10: getProcessName
import android.content.pm.ComponentInfo; //导入依赖的package包/类
public static String getProcessName(ComponentInfo componentInfo) {
String processName = componentInfo.processName;
if (processName == null) {
processName = componentInfo.packageName;
componentInfo.processName = processName;
}
return processName;
}
示例11: isSameComponent
import android.content.pm.ComponentInfo; //导入依赖的package包/类
public static boolean isSameComponent(ComponentInfo first, ComponentInfo second) {
if (first != null && second != null) {
String pkg1 = first.packageName + "";
String pkg2 = second.packageName + "";
String name1 = first.name + "";
String name2 = second.name + "";
return pkg1.equals(pkg2) && name1.equals(name2);
}
return false;
}
示例12: fixComponentInfo
import android.content.pm.ComponentInfo; //导入依赖的package包/类
public static void fixComponentInfo(PackageSetting setting, ComponentInfo info, int userId) {
if (info != null) {
if (TextUtils.isEmpty(info.processName)) {
info.processName = info.packageName;
}
info.name = fixComponentClassName(info.packageName, info.name);
if (info.processName == null) {
info.processName = info.applicationInfo.processName;
}
}
}
示例13: getPluginName
import android.content.pm.ComponentInfo; //导入依赖的package包/类
/**
* 从 ComponentInfo 获取 插件名称
*/
public static String getPluginName(ComponentInfo ci) {
if (ci != null && ci.packageName != null) {
int indexOfLastDot = ci.packageName.lastIndexOf(".");
if (indexOfLastDot > 0) {
return ci.packageName.substring(indexOfLastDot + 1);
}
}
return "";
}
示例14: setTargetProcessName
import android.content.pm.ComponentInfo; //导入依赖的package包/类
void setTargetProcessName(ComponentInfo stubInfo, ComponentInfo targetInfo) {
for (ProcessItem item : items.values()) {
if (TextUtils.equals(item.stubProcessName, stubInfo.processName)) {
if (!item.pkgs.contains(targetInfo.packageName)) {
item.pkgs.add(targetInfo.packageName);
}
item.targetProcessName = targetInfo.processName;
}
}
}
示例15: fixComponentInfo
import android.content.pm.ComponentInfo; //导入依赖的package包/类
public static void fixComponentInfo(AppSetting appSetting, ComponentInfo info, int userId) {
if (info != null) {
if (TextUtils.isEmpty(info.processName)) {
info.processName = info.packageName;
}
fixApplicationInfo(appSetting, info.applicationInfo, userId);
info.name = fixComponentClassName(info.packageName, info.name);
if (info.processName == null) {
info.processName = info.applicationInfo.processName;
}
}
}