use of android.content.pm.ServiceInfo in project atlas by alibaba.
the class AtlasBundleInfoManager method findBundleByComponentName.
// private String getFromAssets(String fileName,Context context){
// BufferedReader bufReader = null;
// try {
// InputStreamReader inputReader = new InputStreamReader(context.getResources().getAssets().open(fileName), CHARSET);
// bufReader = new BufferedReader(inputReader);
// String line="";
// String result="";
// while((line = bufReader.readLine()) != null)
// result += line;
// return result;
// } catch (Exception e) {
// e.printStackTrace();
// return null;
// } finally {
// if(bufReader!=null){
// try {
// bufReader.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// }
// }
//
// private String getFromFile(String fileName){
// File file = new File(fileName);
// Long fileLength = file.length();
// byte[] filecontent = new byte[fileLength.intValue()];
// try {
// FileInputStream in = new FileInputStream(file);
// in.read(filecontent);
// in.close();
// return new String(filecontent,CHARSET);
// } catch (Throwable e) {
// e.printStackTrace();
// }
// return null;
// }
private String findBundleByComponentName(String componentClassName) {
getComponentInfoFromManifestIfNeed();
ComponentName componentName = new ComponentName(RuntimeVariables.androidApplication.getPackageName(), componentClassName);
if (activityInfos != null) {
ActivityInfo info = activityInfos.get(componentClassName);
if (info != null) {
if (info.metaData != null) {
return info.metaData.getString("bundleLocation");
} else {
try {
ActivityInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getActivityInfo(componentName, PackageManager.GET_META_DATA);
if (detailInfo != null && detailInfo.metaData != null) {
info.metaData = detailInfo.metaData;
return detailInfo.metaData.getString("bundleLocation");
} else {
return null;
}
} catch (Throwable e) {
}
}
}
}
if (serviceInfos != null) {
ServiceInfo info = serviceInfos.get(componentClassName);
if (info != null) {
if (info.metaData != null) {
return info.metaData.getString("bundleLocation");
} else {
try {
ServiceInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getServiceInfo(componentName, PackageManager.GET_META_DATA);
if (detailInfo != null && detailInfo.metaData != null) {
info = detailInfo;
return detailInfo.metaData.getString("bundleLocation");
} else {
return null;
}
} catch (Throwable e) {
}
}
}
}
if (receiverInfos != null) {
ActivityInfo info = receiverInfos.get(componentClassName);
if (info != null) {
if (info.metaData != null) {
return info.metaData.getString("bundleLocation");
} else {
try {
ActivityInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getReceiverInfo(componentName, PackageManager.GET_META_DATA);
if (detailInfo != null && detailInfo.metaData != null) {
info.metaData = detailInfo.metaData;
return detailInfo.metaData.getString("bundleLocation");
} else {
return null;
}
} catch (Throwable e) {
}
}
}
}
if (providerInfos != null) {
ProviderInfo info = providerInfos.get(componentClassName);
if (info != null) {
if (info.metaData != null) {
return info.metaData.getString("bundleLocation");
} else {
try {
ProviderInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getProviderInfo(componentName, PackageManager.GET_META_DATA);
if (detailInfo != null && detailInfo.metaData != null) {
info.metaData = detailInfo.metaData;
return detailInfo.metaData.getString("bundleLocation");
} else {
return null;
}
} catch (Throwable e) {
}
}
}
}
return null;
}
use of android.content.pm.ServiceInfo in project atlas by alibaba.
the class ActivityThreadHook method handleService.
private void handleService(final Message message) throws Exception {
Class ReceiverData = Class.forName("android.app.ActivityThread$CreateServiceData");
final Field info_field = ReceiverData.getDeclaredField("info");
info_field.setAccessible(true);
final ServiceInfo info = (ServiceInfo) info_field.get(message.obj);
String componentName = info.name;
String bundleName = AtlasBundleInfoManager.instance().getBundleForComponet(componentName);
if (!TextUtils.isEmpty(bundleName)) {
BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(bundleName);
if (impl != null && impl.checkValidate()) {
mActivityThreadHandler.handleMessage(message);
if (sDelayServiceMessageList != null) {
sDelayServiceMessageList.remove(message);
}
executeDelayMsg();
} else {
if (sDelayServiceMessageList == null) {
sDelayServiceMessageList = new ArrayList<Message>();
sDelayServiceMessageList.add(Message.obtain(message));
}
BundleUtil.checkBundleStateAsync(bundleName, new Runnable() {
@Override
public void run() {
try {
executeDelayMsg();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
}, null);
}
} else {
mActivityThreadHandler.handleMessage(message);
if (sDelayServiceMessageList != null) {
sDelayServiceMessageList.remove(message);
}
executeDelayMsg();
}
}
use of android.content.pm.ServiceInfo in project mechanoid by robotoworks.
the class OperationServiceBridge method initConfigurations.
protected void initConfigurations() {
String packageName = Mechanoid.getApplicationContext().getPackageName();
PackageManager pm = Mechanoid.getApplicationContext().getPackageManager();
try {
PackageInfo info = pm.getPackageInfo(packageName, PackageManager.GET_SERVICES);
ServiceInfo[] services = info.services;
if (services == null) {
return;
}
for (ServiceInfo si : services) {
String serviceName = si.name;
Class<?> clz = ReflectUtil.loadClassSilently(Ops.class.getClassLoader(), serviceName);
if (clz != null && Service.class.isAssignableFrom(clz)) {
Field field = ReflectUtil.getFieldSilently(clz, "CONFIG");
if (field != null) {
OperationServiceConfiguration factory = (OperationServiceConfiguration) ReflectUtil.getFieldValueSilently(field);
mConfigurations.put(clz.getName(), factory);
}
}
}
} catch (NameNotFoundException e) {
}
}
use of android.content.pm.ServiceInfo in project platform_frameworks_base by android.
the class InputMethodSubtypeSwitchingControllerTest method addDummyImeSubtypeListItems.
private static void addDummyImeSubtypeListItems(List<ImeSubtypeListItem> items, String imeName, String imeLabel, List<String> subtypeLocales, boolean supportsSwitchingToNextInputMethod) {
final ResolveInfo ri = new ResolveInfo();
final ServiceInfo si = new ServiceInfo();
final ApplicationInfo ai = new ApplicationInfo();
ai.packageName = DUMMY_PACKAGE_NAME;
ai.enabled = true;
si.applicationInfo = ai;
si.enabled = true;
si.packageName = DUMMY_PACKAGE_NAME;
si.name = imeName;
si.exported = true;
si.nonLocalizedLabel = imeLabel;
ri.serviceInfo = si;
List<InputMethodSubtype> subtypes = null;
if (subtypeLocales != null) {
subtypes = new ArrayList<>();
for (String subtypeLocale : subtypeLocales) {
subtypes.add(createDummySubtype(subtypeLocale));
}
}
final InputMethodInfo imi = new InputMethodInfo(ri, DUMMY_IS_AUX_IME, DUMMY_SETTING_ACTIVITY_NAME, subtypes, DUMMY_IS_DEFAULT_RES_ID, DUMMY_FORCE_DEFAULT, supportsSwitchingToNextInputMethod);
if (subtypes == null) {
items.add(new ImeSubtypeListItem(imeName, null, /* variableName */
imi, NOT_A_SUBTYPE_ID, null, SYSTEM_LOCALE));
} else {
for (int i = 0; i < subtypes.size(); ++i) {
final String subtypeLocale = subtypeLocales.get(i);
items.add(new ImeSubtypeListItem(imeName, subtypeLocale, imi, i, subtypeLocale, SYSTEM_LOCALE));
}
}
}
use of android.content.pm.ServiceInfo in project platform_frameworks_base by android.
the class ActiveServices method retrieveServiceLocked.
private ServiceLookupResult retrieveServiceLocked(Intent service, String resolvedType, String callingPackage, int callingPid, int callingUid, int userId, boolean createIfNeeded, boolean callingFromFg, boolean isBindExternal) {
ServiceRecord r = null;
if (DEBUG_SERVICE)
Slog.v(TAG_SERVICE, "retrieveServiceLocked: " + service + " type=" + resolvedType + " callingUid=" + callingUid);
userId = mAm.mUserController.handleIncomingUser(callingPid, callingUid, userId, false, ActivityManagerService.ALLOW_NON_FULL_IN_PROFILE, "service", null);
ServiceMap smap = getServiceMap(userId);
final ComponentName comp = service.getComponent();
if (comp != null) {
r = smap.mServicesByName.get(comp);
}
if (r == null && !isBindExternal) {
Intent.FilterComparison filter = new Intent.FilterComparison(service);
r = smap.mServicesByIntent.get(filter);
}
if (r != null && (r.serviceInfo.flags & ServiceInfo.FLAG_EXTERNAL_SERVICE) != 0 && !callingPackage.equals(r.packageName)) {
// If an external service is running within its own package, other packages
// should not bind to that instance.
r = null;
}
if (r == null) {
try {
// TODO: come back and remove this assumption to triage all services
ResolveInfo rInfo = AppGlobals.getPackageManager().resolveService(service, resolvedType, ActivityManagerService.STOCK_PM_FLAGS | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId);
ServiceInfo sInfo = rInfo != null ? rInfo.serviceInfo : null;
if (sInfo == null) {
Slog.w(TAG_SERVICE, "Unable to start service " + service + " U=" + userId + ": not found");
return null;
}
ComponentName name = new ComponentName(sInfo.applicationInfo.packageName, sInfo.name);
if ((sInfo.flags & ServiceInfo.FLAG_EXTERNAL_SERVICE) != 0) {
if (isBindExternal) {
if (!sInfo.exported) {
throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + name + " is not exported");
}
if ((sInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) == 0) {
throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + name + " is not an isolatedProcess");
}
// Run the service under the calling package's application.
ApplicationInfo aInfo = AppGlobals.getPackageManager().getApplicationInfo(callingPackage, ActivityManagerService.STOCK_PM_FLAGS, userId);
if (aInfo == null) {
throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + "could not resolve client package " + callingPackage);
}
sInfo = new ServiceInfo(sInfo);
sInfo.applicationInfo = new ApplicationInfo(sInfo.applicationInfo);
sInfo.applicationInfo.packageName = aInfo.packageName;
sInfo.applicationInfo.uid = aInfo.uid;
name = new ComponentName(aInfo.packageName, name.getClassName());
service.setComponent(name);
} else {
throw new SecurityException("BIND_EXTERNAL_SERVICE required for " + name);
}
} else if (isBindExternal) {
throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + name + " is not an externalService");
}
if (userId > 0) {
if (mAm.isSingleton(sInfo.processName, sInfo.applicationInfo, sInfo.name, sInfo.flags) && mAm.isValidSingletonCall(callingUid, sInfo.applicationInfo.uid)) {
userId = 0;
smap = getServiceMap(0);
}
sInfo = new ServiceInfo(sInfo);
sInfo.applicationInfo = mAm.getAppInfoForUser(sInfo.applicationInfo, userId);
}
r = smap.mServicesByName.get(name);
if (r == null && createIfNeeded) {
Intent.FilterComparison filter = new Intent.FilterComparison(service.cloneFilter());
ServiceRestarter res = new ServiceRestarter();
BatteryStatsImpl.Uid.Pkg.Serv ss = null;
BatteryStatsImpl stats = mAm.mBatteryStatsService.getActiveStatistics();
synchronized (stats) {
ss = stats.getServiceStatsLocked(sInfo.applicationInfo.uid, sInfo.packageName, sInfo.name);
}
r = new ServiceRecord(mAm, ss, name, filter, sInfo, callingFromFg, res);
res.setService(r);
smap.mServicesByName.put(name, r);
smap.mServicesByIntent.put(filter, r);
// Make sure this component isn't in the pending list.
for (int i = mPendingServices.size() - 1; i >= 0; i--) {
ServiceRecord pr = mPendingServices.get(i);
if (pr.serviceInfo.applicationInfo.uid == sInfo.applicationInfo.uid && pr.name.equals(name)) {
mPendingServices.remove(i);
}
}
}
} catch (RemoteException ex) {
// pm is in same process, this will never happen.
}
}
if (r != null) {
if (mAm.checkComponentPermission(r.permission, callingPid, callingUid, r.appInfo.uid, r.exported) != PackageManager.PERMISSION_GRANTED) {
if (!r.exported) {
Slog.w(TAG, "Permission Denial: Accessing service " + r.name + " from pid=" + callingPid + ", uid=" + callingUid + " that is not exported from uid " + r.appInfo.uid);
return new ServiceLookupResult(null, "not exported from uid " + r.appInfo.uid);
}
Slog.w(TAG, "Permission Denial: Accessing service " + r.name + " from pid=" + callingPid + ", uid=" + callingUid + " requires " + r.permission);
return new ServiceLookupResult(null, r.permission);
} else if (r.permission != null && callingPackage != null) {
final int opCode = AppOpsManager.permissionToOpCode(r.permission);
if (opCode != AppOpsManager.OP_NONE && mAm.mAppOpsService.noteOperation(opCode, callingUid, callingPackage) != AppOpsManager.MODE_ALLOWED) {
Slog.w(TAG, "Appop Denial: Accessing service " + r.name + " from pid=" + callingPid + ", uid=" + callingUid + " requires appop " + AppOpsManager.opToName(opCode));
return null;
}
}
if (!mAm.mIntentFirewall.checkService(r.name, service, callingUid, callingPid, resolvedType, r.appInfo)) {
return null;
}
return new ServiceLookupResult(r, null);
}
return null;
}
Aggregations