Search in sources :

Example 1 with ServiceInfo

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);
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) IDownload(com.commonsware.android.advservice.remotebinding.IDownload) Intent(android.content.Intent) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException)

Example 2 with ServiceInfo

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;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) ActivityInfo(android.content.pm.ActivityInfo) ProviderInfo(android.content.pm.ProviderInfo) ComponentName(android.content.ComponentName)

Example 3 with ServiceInfo

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();
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) Field(java.lang.reflect.Field) BundleImpl(android.taobao.atlas.framework.BundleImpl) Message(android.os.Message)

Example 4 with ServiceInfo

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 */
        }
    }
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException) ContentResolver(android.content.ContentResolver)

Example 5 with ServiceInfo

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);
        }
    }
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IOException(java.io.IOException) InputMethodInfo(android.view.inputmethod.InputMethodInfo) ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) ArrayList(java.util.ArrayList) List(java.util.List) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Aggregations

ServiceInfo (android.content.pm.ServiceInfo)441 ResolveInfo (android.content.pm.ResolveInfo)203 ComponentName (android.content.ComponentName)182 Intent (android.content.Intent)148 PackageManager (android.content.pm.PackageManager)100 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)72 ArrayList (java.util.ArrayList)72 ApplicationInfo (android.content.pm.ApplicationInfo)59 RemoteException (android.os.RemoteException)52 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 IOException (java.io.IOException)38 PendingIntent (android.app.PendingIntent)37 Test (org.junit.Test)35 InputMethodInfo (android.view.inputmethod.InputMethodInfo)34 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)31 PackageInfo (android.content.pm.PackageInfo)25 ActivityInfo (android.content.pm.ActivityInfo)21 Drawable (android.graphics.drawable.Drawable)21 Bundle (android.os.Bundle)21 AccessibilityManager (android.view.accessibility.AccessibilityManager)21