use of android.content.pm.ServiceInfo in project cw-omnibus by commonsguy.
the class DownloadFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
appContext = (Application) getActivity().getApplicationContext();
Intent implicit = new Intent(IDownload.class.getName());
List<ResolveInfo> matches = getActivity().getPackageManager().queryIntentServices(implicit, 0);
if (matches.size() == 0) {
Toast.makeText(getActivity(), "Cannot find a matching service!", Toast.LENGTH_LONG).show();
} else if (matches.size() > 1) {
Toast.makeText(getActivity(), "Found multiple matching services!", Toast.LENGTH_LONG).show();
} else {
ServiceInfo svcInfo = matches.get(0).serviceInfo;
try {
String otherHash = SignatureUtils.getSignatureHash(getActivity(), svcInfo.applicationInfo.packageName);
String expected = getActivity().getString(R.string.expected_sig_hash);
if (expected.equals(otherHash)) {
Intent explicit = new Intent(implicit);
ComponentName cn = new ComponentName(svcInfo.applicationInfo.packageName, svcInfo.name);
explicit.setComponent(cn);
appContext.bindService(explicit, this, Context.BIND_AUTO_CREATE);
} else {
Toast.makeText(getActivity(), "Unexpected signature found!", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.e(getClass().getSimpleName(), "Exception trying to get signature hash", e);
}
}
}
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 android_frameworks_base by ParanoidAndroid.
the class EnableAccessibilityController method enableAccessibility.
private void enableAccessibility() {
List<AccessibilityServiceInfo> services = getInstalledSpeakingAccessibilityServices(mContext);
if (services.isEmpty()) {
return;
}
boolean keyguardLocked = false;
try {
keyguardLocked = mWindowManager.isKeyguardLocked();
} catch (RemoteException re) {
/* ignore */
}
final boolean hasMoreThanOneUser = mUserManager.getUsers().size() > 1;
AccessibilityServiceInfo service = services.get(0);
boolean enableTouchExploration = (service.flags & AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE) != 0;
// Try to find a service supporting explore by touch.
if (!enableTouchExploration) {
final int serviceCount = services.size();
for (int i = 1; i < serviceCount; i++) {
AccessibilityServiceInfo candidate = services.get(i);
if ((candidate.flags & AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE) != 0) {
enableTouchExploration = true;
service = candidate;
break;
}
}
}
ServiceInfo serviceInfo = service.getResolveInfo().serviceInfo;
ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);
if (!keyguardLocked || !hasMoreThanOneUser) {
final int userId = ActivityManager.getCurrentUser();
String enabledServiceString = componentName.flattenToString();
ContentResolver resolver = mContext.getContentResolver();
// Enable one speaking accessibility service.
Settings.Secure.putStringForUser(resolver, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, enabledServiceString, userId);
// Allow the services we just enabled to toggle touch exploration.
Settings.Secure.putStringForUser(resolver, Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, enabledServiceString, userId);
// Enable touch exploration.
if (enableTouchExploration) {
Settings.Secure.putIntForUser(resolver, Settings.Secure.TOUCH_EXPLORATION_ENABLED, 1, userId);
}
// Enable accessibility script injection (AndroidVox) for web content.
Settings.Secure.putIntForUser(resolver, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, 1, userId);
// Turn on accessibility mode last.
Settings.Secure.putIntForUser(resolver, Settings.Secure.ACCESSIBILITY_ENABLED, 1, userId);
} else if (keyguardLocked) {
try {
mAccessibilityManager.temporaryEnableAccessibilityStateUntilKeyguardRemoved(componentName, enableTouchExploration);
} catch (RemoteException re) {
/* ignore */
}
}
}
use of android.content.pm.ServiceInfo in project android_frameworks_base by ParanoidAndroid.
the class InputMethodManagerService method buildInputMethodListLocked.
void buildInputMethodListLocked(ArrayList<InputMethodInfo> list, HashMap<String, InputMethodInfo> map, boolean resetDefaultEnabledIme) {
if (DEBUG) {
Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme + " \n ------ \n" + getStackTrace());
}
list.clear();
map.clear();
// Use for queryIntentServicesAsUser
final PackageManager pm = mContext.getPackageManager();
String disabledSysImes = mSettings.getDisabledSystemInputMethods();
if (disabledSysImes == null)
disabledSysImes = "";
final List<ResolveInfo> services = pm.queryIntentServicesAsUser(new Intent(InputMethod.SERVICE_INTERFACE), PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, mSettings.getCurrentUserId());
final HashMap<String, List<InputMethodSubtype>> additionalSubtypes = mFileManager.getAllAdditionalInputMethodSubtypes();
for (int i = 0; i < services.size(); ++i) {
ResolveInfo ri = services.get(i);
ServiceInfo si = ri.serviceInfo;
ComponentName compName = new ComponentName(si.packageName, si.name);
if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) {
Slog.w(TAG, "Skipping input method " + compName + ": it does not require the permission " + android.Manifest.permission.BIND_INPUT_METHOD);
continue;
}
if (DEBUG)
Slog.d(TAG, "Checking " + compName);
try {
InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
list.add(p);
final String id = p.getId();
map.put(id, p);
if (DEBUG) {
Slog.d(TAG, "Found an input method " + p);
}
} catch (XmlPullParserException e) {
Slog.w(TAG, "Unable to load input method " + compName, e);
} catch (IOException e) {
Slog.w(TAG, "Unable to load input method " + compName, e);
}
}
if (resetDefaultEnabledIme) {
final ArrayList<InputMethodInfo> defaultEnabledIme = InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, list);
for (int i = 0; i < defaultEnabledIme.size(); ++i) {
final InputMethodInfo imi = defaultEnabledIme.get(i);
if (DEBUG) {
Slog.d(TAG, "--- enable ime = " + imi);
}
setInputMethodEnabledLocked(imi.getId(), true);
}
}
final String defaultImiId = mSettings.getSelectedInputMethod();
if (!TextUtils.isEmpty(defaultImiId)) {
if (!map.containsKey(defaultImiId)) {
Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
if (chooseNewDefaultIMELocked()) {
updateFromSettingsLocked(true);
}
} else {
// Double check that the default IME is certainly enabled.
setInputMethodEnabledLocked(defaultImiId, true);
}
}
}
Aggregations