Search in sources :

Example 1 with ImPlugin

use of org.awesomeapp.messenger.plugin.ImPlugin in project Zom-Android by zom.

the class ImPluginHelper method loadAvailablePlugins.

public void loadAvailablePlugins() {
    if (mLoaded) {
        return;
    }
    List<ResolveInfo> plugins = getPlugins();
    for (ResolveInfo info : plugins) {
        Log.d(TAG, "Found plugin " + info);
        ServiceInfo serviceInfo = info.serviceInfo;
        if (serviceInfo == null) {
            Log.e(TAG, "Ignore bad IM plugin: " + info);
            continue;
        }
        String providerName = null;
        String providerFullName = null;
        String signUpUrl = null;
        Bundle metaData = serviceInfo.metaData;
        if (metaData != null) {
            providerName = metaData.getString(ImPluginConstants.METADATA_PROVIDER_NAME);
            providerFullName = metaData.getString(ImPluginConstants.METADATA_PROVIDER_FULL_NAME);
            signUpUrl = metaData.getString(ImPluginConstants.METADATA_SIGN_UP_URL);
        }
        if (TextUtils.isEmpty(providerName) || TextUtils.isEmpty(providerFullName)) {
            Log.e(TAG, "Ignore bad IM plugin: " + info + ". Lack of required meta data");
            continue;
        }
        if (isPluginDuplicated(providerName)) {
            Log.e(TAG, "Ignore duplicated IM plugin: " + info);
            continue;
        }
        if (!serviceInfo.packageName.equals(mContext.getPackageName())) {
            Log.e(TAG, "Ignore plugin in package: " + serviceInfo.packageName);
            continue;
        }
        ImPluginInfo pluginInfo = new ImPluginInfo(providerName, serviceInfo.packageName, serviceInfo.name, serviceInfo.applicationInfo.sourceDir);
        ImPlugin plugin = loadPlugin(pluginInfo);
        if (plugin == null) {
            Log.e(TAG, "Ignore bad IM plugin");
            continue;
        }
        try {
            updateProviderDb(plugin, pluginInfo, providerFullName, signUpUrl);
        } catch (SQLiteFullException e) {
            Log.e(TAG, "Storage full", e);
            return;
        }
        mPluginsInfo.add(pluginInfo);
        mPluginObjects.add(plugin);
    }
    mLoaded = true;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) Bundle(android.os.Bundle) ImPluginInfo(org.awesomeapp.messenger.plugin.ImPluginInfo) SQLiteFullException(android.database.sqlite.SQLiteFullException) ImPlugin(org.awesomeapp.messenger.plugin.ImPlugin)

Example 2 with ImPlugin

use of org.awesomeapp.messenger.plugin.ImPlugin in project Zom-Android by zom.

the class ImPluginHelper method createAdditionalProvider.

public long createAdditionalProvider(String name) {
    List<ResolveInfo> plugins = getPlugins();
    ResolveInfo info = null;
    ServiceInfo serviceInfo = null;
    Bundle metaData = null;
    long providerId = -1;
    for (ResolveInfo _info : plugins) {
        serviceInfo = _info.serviceInfo;
        if (serviceInfo == null) {
            Log.e(TAG, "Ignore bad IM plugin: " + _info);
            continue;
        }
        if (serviceInfo.metaData == null) {
            Log.e(TAG, "Ignore bad IM plugin: " + _info);
            continue;
        }
        metaData = serviceInfo.metaData;
        if (name.equals(metaData.getString(ImPluginConstants.METADATA_PROVIDER_NAME))) {
            info = _info;
            break;
        }
    }
    if (info == null) {
        Log.e(TAG, "Did not find plugin " + name);
        return -1;
    }
    String providerName = metaData.getString(ImPluginConstants.METADATA_PROVIDER_NAME);
    String providerFullName = metaData.getString(ImPluginConstants.METADATA_PROVIDER_FULL_NAME);
    String signUpUrl = metaData.getString(ImPluginConstants.METADATA_SIGN_UP_URL);
    if (TextUtils.isEmpty(providerName) || TextUtils.isEmpty(providerFullName)) {
        Log.e(TAG, "Ignore bad IM plugin: " + info + ". Lack of required meta data");
        return -1;
    }
    /*
        if (!serviceInfo.packageName.equals(mContext.getPackageName())) {
            Log.e(TAG, "Ignore plugin in package: " + serviceInfo.packageName);
            return -1;
        }*/
    ImPluginInfo pluginInfo = new ImPluginInfo(providerName, serviceInfo.packageName, serviceInfo.name, serviceInfo.applicationInfo.sourceDir);
    ImPlugin plugin = loadPlugin(pluginInfo);
    if (plugin == null) {
        Log.e(TAG, "Ignore bad IM plugin");
        return -1;
    }
    try {
        providerId = insertProviderDb(plugin, pluginInfo, providerFullName, signUpUrl);
    } catch (SQLiteFullException e) {
        Log.e(TAG, "Storage full", e);
        return -1;
    }
    mPluginsInfo.add(pluginInfo);
    mPluginObjects.add(plugin);
    return providerId;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) Bundle(android.os.Bundle) ImPluginInfo(org.awesomeapp.messenger.plugin.ImPluginInfo) SQLiteFullException(android.database.sqlite.SQLiteFullException) ImPlugin(org.awesomeapp.messenger.plugin.ImPlugin)

Aggregations

ResolveInfo (android.content.pm.ResolveInfo)2 ServiceInfo (android.content.pm.ServiceInfo)2 SQLiteFullException (android.database.sqlite.SQLiteFullException)2 Bundle (android.os.Bundle)2 ImPlugin (org.awesomeapp.messenger.plugin.ImPlugin)2 ImPluginInfo (org.awesomeapp.messenger.plugin.ImPluginInfo)2