Android Open Source - Cardeto App Info Module






From Project

Back to project page Cardeto.

License

The source code is released under:

Apache License

If you think the Android project Cardeto listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ggt.cardeto.embeddedwebserver.appinfomodule;
//w w w  . j  av a2 s.co  m
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.content.pm.ServiceInfo;

import com.ggt.cardeto.R;
import com.ggt.cardeto.embeddedwebserver.CardetoWebServerModule;
import com.ggt.cardeto.utils.CardetoConstants;

import java.util.Properties;

/**
 * This cardeto module display app info.
 *
 * @author guiguito
 */
public class AppInfoModule implements CardetoWebServerModule {

    private Context mContext;

    private static final String APPINFO_MODULE_TAG = "appinfo";

    public AppInfoModule(Context context) {
        mContext = context;
    }

    @Override
    public String getModuleTitle() {
        return mContext.getString(R.string.appinfo_module_title);
    }

    @Override
    public String getDescription() {
        return mContext.getString(R.string.appinfo_module_description);
    }

    @Override
    public String getUrl() {
        return "./" + APPINFO_MODULE_TAG;
    }

    @Override
    public boolean matchURI(String uri) {
        if (uri != null && uri.startsWith("/" + APPINFO_MODULE_TAG))
            return true;
        else
            return false;
    }

    @Override
    public StringBuilder handleRequest(String uri, String method,
                                       Properties header, Properties params, Properties files) {
        StringBuilder result = new StringBuilder();
        result.append(mContext.getString(R.string.html_header));
        result.append(CardetoConstants.HTML_RETURN + "\n");
        result.append(CardetoConstants.HTML_RETURN + "\n");
        result.append("<a href=\"/\">"
                + mContext.getString(R.string.back_to_modules_list) + "</a>"
                + CardetoConstants.HTML_RETURN + "\n");
        result.append(CardetoConstants.HTML_RETURN + "\n");

        try {
            result.append("<U><B>App name</B></U> : "
                    + mContext.getApplicationInfo().name);
            result.append(CardetoConstants.HTML_RETURN + "\n");
            result.append("<U><B>App class</B></U> : "
                    + mContext.getApplicationInfo().className);
            result.append(CardetoConstants.HTML_RETURN + "\n");
            result.append("<U><B>Version code</B></U> : "
                    + mContext.getPackageManager().getPackageInfo(
                    mContext.getApplicationInfo().packageName,
                    PackageManager.GET_RECEIVERS).versionCode);
            result.append(CardetoConstants.HTML_RETURN + "\n");
            result.append("<U><B>Version name</B></U> : "
                    + mContext.getPackageManager().getPackageInfo(
                    mContext.getApplicationInfo().packageName,
                    PackageManager.GET_RECEIVERS).versionName);
            result.append(CardetoConstants.HTML_RETURN + "\n");
            result.append(CardetoConstants.HTML_RETURN + "\n");

            ActivityInfo[] activitiesInfo = mContext.getPackageManager()
                    .getPackageInfo(mContext.getApplicationInfo().packageName,
                            PackageManager.GET_ACTIVITIES).activities;
            ServiceInfo[] servicesInfo = mContext.getPackageManager()
                    .getPackageInfo(mContext.getApplicationInfo().packageName,
                            PackageManager.GET_SERVICES).services;
            PermissionInfo[] permissionsInfo = mContext.getPackageManager()
                    .getPackageInfo(mContext.getApplicationInfo().packageName,
                            PackageManager.GET_PERMISSIONS).permissions;
            ActivityInfo[] receiversInfo = mContext.getPackageManager()
                    .getPackageInfo(mContext.getApplicationInfo().packageName,
                            PackageManager.GET_RECEIVERS).receivers;
            if (activitiesInfo != null) {
                result.append("<U><B>Activities</B></U>");
                result.append(CardetoConstants.HTML_RETURN + "\n");
                for (ActivityInfo activityInfo : activitiesInfo) {
                    result.append(activityInfo.toString());
                    result.append(CardetoConstants.HTML_RETURN + "\n");
                }
                result.append(CardetoConstants.HTML_RETURN + "\n");
            }
            if (servicesInfo != null) {
                result.append("<U><B>Services</B></U>");
                result.append(CardetoConstants.HTML_RETURN + "\n");
                for (ServiceInfo serviceInfo : servicesInfo) {
                    result.append(serviceInfo.toString());
                    result.append(CardetoConstants.HTML_RETURN + "\n");
                }
                result.append(CardetoConstants.HTML_RETURN + "\n");
            }
            if (permissionsInfo != null) {
                result.append("<U><B>Permissions</B></U>");
                result.append(CardetoConstants.HTML_RETURN + "\n");
                for (PermissionInfo permissionInfo : permissionsInfo) {
                    result.append(permissionInfo.toString());
                    result.append(CardetoConstants.HTML_RETURN + "\n");
                }
                result.append(CardetoConstants.HTML_RETURN + "\n");
            }
            if (receiversInfo != null) {
                result.append("<U><B>ReceiversInfo</B></U>");
                result.append(CardetoConstants.HTML_RETURN + "\n");
                for (ActivityInfo receiverInfo : receiversInfo) {
                    result.append(receiverInfo.toString());
                    result.append(CardetoConstants.HTML_RETURN + "\n");
                }
                result.append(CardetoConstants.HTML_RETURN + "\n");
            }
            // TODO add more app info

        } catch (PackageManager.NameNotFoundException e) {
            // Do nothing. Adapter will be empty.
        }
        result.append(CardetoConstants.HTML_RETURN + "\n");
        result.append(mContext.getString(R.string.html_footer));
        return result;
    }
}




Java Source Code List

com.ggt.cardeto.CardetoService.java
com.ggt.cardeto.embeddedwebserver.CardetoWebServerModule.java
com.ggt.cardeto.embeddedwebserver.CardetoWebServer.java
com.ggt.cardeto.embeddedwebserver.appinfomodule.AppInfoModule.java
com.ggt.cardeto.embeddedwebserver.clipboardmodule.ClipboardModule.java
com.ggt.cardeto.embeddedwebserver.logcatmodule.LogcatModule.java
com.ggt.cardeto.embeddedwebserver.sqlitemodule.GenericSQLiteDatabaseHelper.java
com.ggt.cardeto.embeddedwebserver.sqlitemodule.SQLiteModule.java
com.ggt.cardeto.embeddedwebserver.sqlitemodule.tableouputrenderers.CSVRenderer.java
com.ggt.cardeto.embeddedwebserver.sqlitemodule.tableouputrenderers.HtmlRenderer.java
com.ggt.cardeto.embeddedwebserver.sqlitemodule.tableouputrenderers.JsonRenderer.java
com.ggt.cardeto.embeddedwebserver.sqlitemodule.tableouputrenderers.TableOutputRenderer.java
com.ggt.cardeto.embeddedwebserver.sqlitemodule.tableouputrenderers.XmlRenderer.java
com.ggt.cardeto.embeddedwebserver.staticvarsmodule.StaticVarsModule.java
com.ggt.cardeto.externallib.NanoHTTPD.java
com.ggt.cardeto.utils.CardetoConstants.java
com.ggt.cardeto.utils.NetworkUtilsOld.java
com.ggt.cardeto.utils.NetworkUtils.java
com.ggt.cardetosample.TestActivity.java
com.ggt.cardetosample.database.CardetoSampleDatabaseDataSource.java
com.ggt.cardetosample.database.CardetoSampleDatabaseHelper.java
com.ggt.cardetosample.database.Log.java