Java Code Examples for android.content.ComponentName.unflattenFromString()

The following are Jave code examples for showing how to use unflattenFromString() of the android.content.ComponentName class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: https-github.com-hyb1996-NoRootScriptDroid   File: AccessibilityServiceUtils.java   Source Code and License Vote up 6 votes
public static boolean isAccessibilityServiceEnabled(Context context, Class<? extends AccessibilityService> accessibilityService) {
    ComponentName expectedComponentName = new ComponentName(context, accessibilityService);

    String enabledServicesSetting = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
    if (enabledServicesSetting == null)
        return false;

    TextUtils.SimpleStringSplitter colonSplitter = new TextUtils.SimpleStringSplitter(':');
    colonSplitter.setString(enabledServicesSetting);

    while (colonSplitter.hasNext()) {
        String componentNameString = colonSplitter.next();
        ComponentName enabledService = ComponentName.unflattenFromString(componentNameString);

        if (enabledService != null && enabledService.equals(expectedComponentName))
            return true;
    }

    return false;
}
 
Example 2
Project: lineagex86   File: ZenModeExternalRuleSettings.java   Source Code and License Vote up 6 votes
public static RuleInfo getRuleInfo(ServiceInfo si) {
    if (si == null || si.metaData == null) return null;
    final String ruleType = si.metaData.getString(MD_RULE_TYPE);
    final String defaultConditionId = si.metaData.getString(MD_DEFAULT_CONDITION_ID);
    final String configurationActivity = si.metaData.getString(MD_CONFIGURATION_ACTIVITY);
    if (ruleType != null && !ruleType.trim().isEmpty() && defaultConditionId != null) {
        final RuleInfo ri = new RuleInfo();
        ri.serviceComponent = new ComponentName(si.packageName, si.name);
        ri.settingsAction = ZenModeExternalRuleSettings.ACTION;
        ri.caption = ruleType;
        ri.defaultConditionId = Uri.parse(defaultConditionId);
        if (configurationActivity != null) {
            ri.configurationActivity = ComponentName.unflattenFromString(configurationActivity);
        }
        return ri;
    }
    return null;
}
 
Example 3
Project: LaunchEnr   File: ComponentKey.java   Source Code and License Vote up 6 votes
/**
 * Creates a new component key from an encoded component key string in the form of
 * [flattenedComponentString#userId].  If the userId is not present, then it defaults
 * to the current user.
 */
public ComponentKey(Context context, String componentKeyStr) {
    int userDelimiterIndex = componentKeyStr.indexOf("#");
    if (userDelimiterIndex != -1) {
        String componentStr = componentKeyStr.substring(0, userDelimiterIndex);
        Long componentUser = Long.valueOf(componentKeyStr.substring(userDelimiterIndex + 1));
        componentName = ComponentName.unflattenFromString(componentStr);
        user = UserManagerCompat.getInstance(context)
                .getUserForSerialNumber(componentUser.longValue());
    } else {
        // No user provided, default to the current user
        componentName = ComponentName.unflattenFromString(componentKeyStr);
        user = Process.myUserHandle();
    }
    mHashCode = Arrays.hashCode(new Object[] {componentName, user});
}
 
Example 4
Project: CSipSimple   File: RewriterPlugin.java   Source Code and License Vote up 6 votes
/**
 * Rewrite a number using a given plugin.
 * Warning this should never be done on main thread otherwise will always fail due to thread issues.
 * 
 * @param context The application context to use to talk to plugin
 * @param componentName The fully qualified component name of the plugin
 * @param number The number to rewrite
 */
public static String rewriteNumber(Context context, final String componentName, String number) {
    ComponentName cn = ComponentName.unflattenFromString(componentName);

    Intent it = new Intent(SipManager.ACTION_REWRITE_NUMBER);
    it.putExtra(Intent.EXTRA_PHONE_NUMBER, number);
    it.setComponent(cn);
    
    OnRewriteReceiver resultTreater = new OnRewriteReceiver(number);
    context.sendOrderedBroadcast(it, permission.PROCESS_OUTGOING_CALLS, resultTreater, null,
            Activity.RESULT_OK, null, null);
    
    return resultTreater.getResult();
}
 
Example 5
Project: AI-Powered-Intelligent-Banking-Platform   File: RecognitionServiceManager.java   Source Code and License Vote up 6 votes
public static Pair<String, String> getLabel(Context context, String comboAsString) {
    String recognizer = "[?]";
    String language = "[?]";
    String[] splits = TextUtils.split(comboAsString, SEPARATOR);
    if (splits.length > 0) {
        PackageManager pm = context.getPackageManager();
        ComponentName recognizerComponentName = ComponentName.unflattenFromString(splits[0]);
        if (recognizerComponentName != null) {
            try {
                ServiceInfo si = pm.getServiceInfo(recognizerComponentName, 0);
                recognizer = si.loadLabel(pm).toString();
            } catch (PackageManager.NameNotFoundException e) {
                // ignored
            }
        }
    }
    if (splits.length > 1) {
        language = makeLangLabel(splits[1]);
    }
    return new Pair<>(recognizer, language);
}
 
Example 6
Project: IFWManager   File: IntentFirewall.java   Source Code and License Vote up 6 votes
@Override
protected void readChild(XmlPullParser parser) throws IOException, XmlPullParserException {
    String currentTag = parser.getName();

    if (currentTag.equals(TAG_INTENT_FILTER)) {
        FirewallIntentFilter intentFilter = new FirewallIntentFilter(this);
        intentFilter.readFromXml(parser);
        mIntentFilters.add(intentFilter);
    } else if (currentTag.equals(TAG_COMPONENT_FILTER)) {
        String componentStr = parser.getAttributeValue(null, ATTR_NAME);
        if (componentStr == null) {
            throw new XmlPullParserException("Component name must be specified.",
                    parser, null);
        }

        ComponentName componentName = ComponentName.unflattenFromString(componentStr);
        if (componentName == null) {
            throw new XmlPullParserException("Invalid component name: " + componentStr);
        }

        mComponentFilters.add(componentName);
    } else {
        super.readChild(parser);
    }
}
 
Example 7
Project: SimpleUILauncher   File: ComponentKey.java   Source Code and License Vote up 6 votes
/**
 * Creates a new component key from an encoded component key string in the form of
 * [flattenedComponentString#userId].  If the userId is not present, then it defaults
 * to the current user.
 */
public ComponentKey(Context context, String componentKeyStr) {
    int userDelimiterIndex = componentKeyStr.indexOf("#");
    if (userDelimiterIndex != -1) {
        String componentStr = componentKeyStr.substring(0, userDelimiterIndex);
        Long componentUser = Long.valueOf(componentKeyStr.substring(userDelimiterIndex + 1));
        componentName = ComponentName.unflattenFromString(componentStr);
        user = UserManagerCompat.getInstance(context)
                .getUserForSerialNumber(componentUser.longValue());
    } else {
        // No user provided, default to the current user
        componentName = ComponentName.unflattenFromString(componentKeyStr);
        user = UserHandleCompat.myUserHandle();
    }
    Preconditions.assertNotNull(componentName);
    Preconditions.assertNotNull(user);
    mHashCode = Arrays.hashCode(new Object[] {componentName, user});
}
 
Example 8
Project: notifications-forwarder   File: WelcomeActivity.java   Source Code and License Vote up 6 votes
private boolean isNotificationServiceEnabled(){
    String pkgName = getPackageName();
    final String flat = Settings.Secure.getString(getContentResolver(),
            ENABLED_NOTIFICATION_LISTENERS);
    if (!TextUtils.isEmpty(flat)) {
        final String[] names = flat.split(":");
        for (int i = 0; i < names.length; i++) {
            final ComponentName cn = ComponentName.unflattenFromString(names[i]);
            if (cn != null) {
                if (TextUtils.equals(pkgName, cn.getPackageName())) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 9
Project: Linux-notifier-Android   File: MainActivity.java   Source Code and License Vote up 6 votes
private Boolean isNotificationListenerEnabled()
{
    String listenerString = Settings.Secure.getString(getContentResolver(), "enabled_notification_listeners");

    if (listenerString != null && !listenerString.equals(""))
    {
        String[] listeners = listenerString.split(":");
        for (String listener : listeners)
        {
            ComponentName componentName = ComponentName.unflattenFromString(listener);
            if (componentName != null)
                if (componentName.getPackageName().equals(getPackageName()))
                    return true;
        }
    }
    return false;
}
 
Example 10
Project: boohee_v5.6   File: NotificationManagerCompat.java   Source Code and License Vote up 6 votes
public static Set<String> getEnabledListenerPackages(Context context) {
    String enabledNotificationListeners = Secure.getString(context.getContentResolver(), SETTING_ENABLED_NOTIFICATION_LISTENERS);
    if (!(enabledNotificationListeners == null || enabledNotificationListeners.equals(sEnabledNotificationListeners))) {
        String[] components = enabledNotificationListeners.split(":");
        Set<String> packageNames = new HashSet(components.length);
        for (String component : components) {
            ComponentName componentName = ComponentName.unflattenFromString(component);
            if (componentName != null) {
                packageNames.add(componentName.getPackageName());
            }
        }
        synchronized (sEnabledNotificationListenersLock) {
            sEnabledNotificationListenerPackages = packageNames;
            sEnabledNotificationListeners = enabledNotificationListeners;
        }
    }
    return sEnabledNotificationListenerPackages;
}
 
Example 11
Project: lineagex86   File: ServiceListing.java   Source Code and License Vote up 5 votes
private void loadEnabledServices() {
    mEnabledServices.clear();
    final String flat = Settings.Secure.getString(mContentResolver, mConfig.setting);
    if (flat != null && !"".equals(flat)) {
        final String[] names = flat.split(":");
        for (int i = 0; i < names.length; i++) {
            final ComponentName cn = ComponentName.unflattenFromString(names[i]);
            if (cn != null) {
                mEnabledServices.add(cn);
            }
        }
    }
}
 
Example 12
Project: CurrentActivity   File: AccessibilityServiceUtils.java   Source Code and License Vote up 5 votes
public static boolean isAccessibilityServiceEnabled(Context context, Class<? extends AccessibilityService> accessibilityService) {
    String enabledServicesSetting = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
    if (enabledServicesSetting == null) return false;
    TextUtils.SimpleStringSplitter colonSplitter = new TextUtils.SimpleStringSplitter(':');
    colonSplitter.setString(enabledServicesSetting);
    while (colonSplitter.hasNext()) {
        ComponentName enabledService = ComponentName.unflattenFromString(colonSplitter.next());
        if (enabledService != null && enabledService.equals(new ComponentName(context, accessibilityService)))
            return true;
    }
    return false;
}
 
Example 13
Project: CSipSimple   File: Theme.java   Source Code and License Vote up 5 votes
public Theme(Context ctxt, String packageName) {
	pm = ctxt.getPackageManager();
	
	ComponentName cn = ComponentName.unflattenFromString(packageName);
	
	try {
           pInfos = pm.getPackageInfo(cn.getPackageName(), 0);
           remoteRes = pm.getResourcesForApplication(cn.getPackageName());
       } catch (NameNotFoundException e) {
           Log.e(THIS_FILE, "Impossible to get resources from " + cn.toShortString());
           remoteRes = null;
           pInfos = null;
       }
}
 
Example 14
Project: MiPushFramework   File: XmsfApp.java   Source Code and License Vote up 5 votes
private HashSet<ComponentName> loadEnabledServices() {
    HashSet<ComponentName> hashSet = new HashSet();
    String string = Settings.Secure.getString(getContentResolver()
            , "enabled_notification_listeners");
    if (!(string == null || "".equals(string))) {
        String[] split = string.split(":");
        for (String unflattenFromString : split) {
            ComponentName unflattenFromString2 = ComponentName.unflattenFromString(unflattenFromString);
            if (unflattenFromString2 != null) {
                hashSet.add(unflattenFromString2);
            }
        }
    }
    return hashSet;
}
 
Example 15
Project: Liteframework   File: NotificationService.java   Source Code and License Vote up 5 votes
public static boolean isNotificationListenEnable(Context context, String pkgName) {
    final String flat = Settings.Secure.getString(context.getContentResolver(), ENABLED_NOTIFICATION_LISTENERS);
    if (!TextUtils.isEmpty(flat)) {
        final String[] names = flat.split(":");
        for (int i = 0; i < names.length; i++) {
            final ComponentName cn = ComponentName.unflattenFromString(names[i]);
            if (cn != null) {
                if (TextUtils.equals(pkgName, cn.getPackageName())) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 16
Project: TPlayer   File: BroadcastBadger2.java   Source Code and License Vote up 5 votes
@Override
public BadgerInfo handleBadger(Intent intent) {
    BadgerInfo info = new BadgerInfo();
    String componentName = intent.getStringExtra(getComponentKey());
    ComponentName component = ComponentName.unflattenFromString(componentName);
    if (component != null) {
        info.packageName = component.getPackageName();
        info.className = component.getClassName();
        info.badgerCount = intent.getIntExtra(getCountKey(), 0);
        return info;
    }
    return null;
}
 
Example 17
Project: AI-Powered-Intelligent-Banking-Platform   File: RecognitionServiceManager.java   Source Code and License Vote up 4 votes
public static String getServiceLabel(Context context, String service) {
    ComponentName recognizerComponentName = ComponentName.unflattenFromString(service);
    return getServiceLabel(context, recognizerComponentName);
}
 
Example 18
Project: AI-Powered-Intelligent-Banking-Platform   File: RecognitionServiceManager.java   Source Code and License Vote up 4 votes
public static String getServiceLabel(Context context, String service) {
    ComponentName recognizerComponentName = ComponentName.unflattenFromString(service);
    return getServiceLabel(context, recognizerComponentName);
}
 
Example 19
Project: AI-Powered-Intelligent-Banking-Platform   File: RecognitionServiceManager.java   Source Code and License Vote up 4 votes
/**
 * @param str string like {@code ee.ioc.phon.android.speak/.HttpRecognitionService;et-ee}
 * @return ComponentName in the input string
 */
public static ComponentName getComponentName(String str) {
    String[] splits = getServiceAndLang(str);
    return ComponentName.unflattenFromString(splits[0]);
}
 
Example 20
Project: CSipSimple   File: ActivityChooserModel.java   Source Code and License Vote up 2 votes
/**
 * Creates a new instance.
 *
 * @param activityName The activity component name flattened to string.
 * @param time The time the activity was chosen.
 * @param weight The weight of the record.
 */
public HistoricalRecord(String activityName, long time, float weight) {
    this(ComponentName.unflattenFromString(activityName), time, weight);
}