Android Open Source - permission-explorer Permission Info Activity






From Project

Back to project page permission-explorer.

License

The source code is released under:

Copyright (C) 2012 Rui Gon?alves and Daniel Cibr?o Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),...

If you think the Android project permission-explorer 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 pt.up.fe.ssin.pexplorer.app;
//w  w  w .ja  va  2  s .  c o m
import java.util.List;

import pt.up.fe.ssin.pexplorer.R;
import pt.up.fe.ssin.pexplorer.data.PermissionCatalog;
import pt.up.fe.ssin.pexplorer.data.PermissionDBOperations;
import pt.up.fe.ssin.pexplorer.utils.ApplicationDetailsHelper;
import pt.up.fe.ssin.pexplorer.utils.PermissionUtils;
import android.app.ListActivity;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PermissionInfo;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;

public class PermissionInfoActivity extends ListActivity {

    private static final String TAB_SPEC_INFO = "info";
    private static final String TAB_SPEC_ACTIONS = "actions";
    private static final String TAB_SPEC_APPS = "apps";

    private PermissionInfo perm;
    private String permDescription;
    private String extendedInfo;
    private List<ApplicationInfo> permittedApps;
    private List<ApplicationInfo> permittedDownloadedApps;

    private TabHost tabHost;
    private ApplicationListAdapter adapter;
    private boolean showAllApps = false;
    private boolean redrawMenuOption = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PermissionCatalog catalog = PermissionCatalog.getInstance(this);
        SharedPreferences prefs = getSharedPreferences(Keys.PREFS_FILE,
                MODE_PRIVATE);

        String name = getIntent().getStringExtra(Keys.INTENT_EXT_NAME);
        try {
            perm = catalog.getInfo(name);
        } catch (NameNotFoundException e) {
            Toast.makeText(this, "permission does not exist",
                    Toast.LENGTH_SHORT).show();
            finish();
            return;
        }

        permDescription = (String) perm.loadDescription(catalog
                .getPackageManager());

        permittedApps = catalog.getApplications(perm);
        permittedDownloadedApps = catalog.filterApplications(permittedApps,
                true);
        extendedInfo = PermissionDBOperations.getPermissionDescription(this,
                perm.name);

        if ((permDescription == null || permDescription.equals(""))
                && (extendedInfo == null || extendedInfo.equals("")))
            permDescription = getString(R.string.no_info_available);

        showAllApps = prefs.getBoolean(Keys.PREFS_SHOW_ALL_APPS,
                Keys.DEFAULT_SHOW_ALL_APPS);

        drawActivity();
    }

    private void drawActivity() {
        setContentView(R.layout.info_main);
        setTitle(PermissionUtils.getShortName(perm));
        drawTabs();

        drawDetailedInfo();
        drawActionsList();
        drawAppsList();
    }

    private void drawTabs() {
        tabHost = (TabHost) findViewById(R.id.tabhost);
        tabHost.setup();

        tabHost.addTab(tabHost
                .newTabSpec(TAB_SPEC_INFO)
                .setContent(R.id.detailed_info)
                .setIndicator(getString(R.string.tab_detailed_info),
                        getResources().getDrawable(R.drawable.ic_tab_info)));

        tabHost.addTab(tabHost
                .newTabSpec(TAB_SPEC_ACTIONS)
                .setContent(R.id.actions_list)
                .setIndicator(getString(R.string.tab_actions_list),
                        getResources().getDrawable(R.drawable.ic_tab_examples)));

        tabHost.addTab(tabHost
                .newTabSpec(TAB_SPEC_APPS)
                .setContent(android.R.id.list)
                .setIndicator(getString(R.string.tab_apps_list),
                        getResources().getDrawable(R.drawable.ic_tab_apps)));
    }

    private void drawDetailedInfo() {
        TextView tv = (TextView) findViewById(R.id.name);
        tv.setText(perm.name);

        tv = (TextView) findViewById(R.id.group);
        tv.setText(perm.group);

        tv = (TextView) findViewById(R.id.level);
        tv.setText(getResources().getStringArray(R.array.level_labels)[perm.protectionLevel]);

        tv = (TextView) findViewById(R.id.description);
        tv.setText(permDescription);

        tv = (TextView) findViewById(R.id.ext_description);
        tv.setText(extendedInfo);
    }

    private void drawActionsList() {
        List<PermissionAction> actions = ActionRegistry.getInstance()
                .getPermissionActions(perm.name);
        ViewGroup actionsView = (ViewGroup) findViewById(R.id.actions_list);

        if (actions.isEmpty()) {
            actionsView.addView(View.inflate(this,
                    R.layout.action_list_empty_msg, null));
            return;
        }

        for (PermissionAction action : actions) {
            View.inflate(this, R.layout.action_button, actionsView);
            Button b = (Button) actionsView.getChildAt(actionsView
                    .getChildCount() - 1);
            b.setText(action.getLabel(this));
            b.setOnClickListener(new OnActionButtonClickListener(action));
        }
    }

    private void drawAppsList() {
        adapter = new ApplicationListAdapter(this, showAllApps ? permittedApps
                : permittedDownloadedApps);
        setListAdapter(adapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        ApplicationInfo app = adapter.getItem(position);
        startActivity(ApplicationDetailsHelper
                .getApplicationDetailsIntent(app.packageName));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.info_apps, menu);
        if (showAllApps) {
            menu.getItem(0).setTitle(R.string.show_only_downloaded_apps);
            menu.getItem(0).setIcon(R.drawable.ic_menu_show_downloaded_apps);
        }

        return true;
    }

    public boolean onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        if (!tabHost.getCurrentTabTag().equals(TAB_SPEC_APPS))
            return false;

        if (redrawMenuOption) {
            menu.getItem(0).setTitle(
                    showAllApps ? R.string.show_only_downloaded_apps
                            : R.string.show_all_apps);
            menu.getItem(0).setIcon(
                    showAllApps ? R.drawable.ic_menu_show_downloaded_apps
                            : R.drawable.ic_menu_show_all_apps);
            redrawMenuOption = false;
        }
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

        case R.id.toggle_show: {
            showAllApps = !showAllApps;

            SharedPreferences.Editor prefs = getSharedPreferences(
                    Keys.PREFS_FILE, MODE_PRIVATE).edit();
            prefs.putBoolean(Keys.PREFS_SHOW_ALL_APPS, showAllApps);
            prefs.commit();

            redrawMenuOption = true;

            adapter = new ApplicationListAdapter(this,
                    showAllApps ? permittedApps : permittedDownloadedApps);
            setListAdapter(adapter);
            return true;
        }

        default:
            return super.onOptionsItemSelected(item);
        }
    }

    private static class OnActionButtonClickListener implements OnClickListener {

        private PermissionAction action;

        public OnActionButtonClickListener(PermissionAction action) {
            this.action = action;
        }

        @Override
        public void onClick(View v) {
            action.execute(v.getContext());
        }
    }
}




Java Source Code List

pt.up.fe.ssin.pexplorer.actions.AccessFineLocationAction.java
pt.up.fe.ssin.pexplorer.actions.AccessNetworkStateAction.java
pt.up.fe.ssin.pexplorer.actions.ChangeWifiStateAction.java
pt.up.fe.ssin.pexplorer.actions.GetAccountsAction.java
pt.up.fe.ssin.pexplorer.actions.InternetAccessAction.java
pt.up.fe.ssin.pexplorer.actions.PhoneCallAction.java
pt.up.fe.ssin.pexplorer.actions.ReadCalendarAction.java
pt.up.fe.ssin.pexplorer.actions.ReadContactsAction.java
pt.up.fe.ssin.pexplorer.actions.ReadPhoneStateAction.java
pt.up.fe.ssin.pexplorer.actions.RebootAction.java
pt.up.fe.ssin.pexplorer.actions.RetrieveRunningTasksAction.java
pt.up.fe.ssin.pexplorer.actions.SendTestSmsAction.java
pt.up.fe.ssin.pexplorer.actions.ShellCommandAction.java
pt.up.fe.ssin.pexplorer.actions.TakePictureAction.java
pt.up.fe.ssin.pexplorer.actions.TakePictureActivity.java
pt.up.fe.ssin.pexplorer.actions.VibrateAction.java
pt.up.fe.ssin.pexplorer.actions.WriteCalendarAction.java
pt.up.fe.ssin.pexplorer.actions.WriteExternalStorageAction.java
pt.up.fe.ssin.pexplorer.actions.WriteSettingsAction.java
pt.up.fe.ssin.pexplorer.app.ActionRegistry.java
pt.up.fe.ssin.pexplorer.app.ApplicationListAdapter.java
pt.up.fe.ssin.pexplorer.app.FilterConfigActivity.java
pt.up.fe.ssin.pexplorer.app.Keys.java
pt.up.fe.ssin.pexplorer.app.PermissionAction.java
pt.up.fe.ssin.pexplorer.app.PermissionExplorerActivity.java
pt.up.fe.ssin.pexplorer.app.PermissionInfoActivity.java
pt.up.fe.ssin.pexplorer.app.PermissionListAdapter.java
pt.up.fe.ssin.pexplorer.data.GlobalSchema.java
pt.up.fe.ssin.pexplorer.data.PermissionCatalog.java
pt.up.fe.ssin.pexplorer.data.PermissionDBOperations.java
pt.up.fe.ssin.pexplorer.data.PermissionExplorerContentProvider.java
pt.up.fe.ssin.pexplorer.entities.Contact.java
pt.up.fe.ssin.pexplorer.utils.ApplicationDetailsHelper.java
pt.up.fe.ssin.pexplorer.utils.Pair.java
pt.up.fe.ssin.pexplorer.utils.PermissionUtils.java
pt.up.fe.ssin.pexplorer.utils.ui.AlertDialogHelper.java
pt.up.fe.ssin.pexplorer.utils.ui.CheckedLinearLayout.java
pt.up.fe.ssin.pexplorer.utils.ui.CheckedRelativeLayout.java
pt.up.fe.ssin.pexplorer.utils.ui.FilterTextWatcher.java
pt.up.fe.ssin.pexplorer.utils.ui.InputDialogBuilder.java
pt.up.fe.ssin.pexplorer.utils.ui.SimpleObjectAdapter.java
pt.up.fe.ssin.pexplorer.utils.ui.views.NonEventBlockingScrollView.java