info.guardianproject.panic.PanicResponder Java Examples

The following examples show how to use info.guardianproject.panic.PanicResponder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SettingActivity.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
private void setInitialValues() {

   //     mDeleteUnsecuredMedia.setChecked(Preferences.getDeleteInsecureMedia());
        mEnableNotification.setChecked(Preferences.isNotificationEnabled());
        mNotificationVibrate.setChecked(Preferences.getNotificationVibrate());
        mNotificationSound.setChecked(Preferences.getNotificationSound());

     //   mHeartbeatInterval.setText(String.valueOf(Preferences.getHeartbeatInterval()));

        ArrayList<CharSequence> entries = new ArrayList<CharSequence>();
        ArrayList<CharSequence> entryValues = new ArrayList<CharSequence>();
        entries.add(0, getString(R.string.panic_app_none));
        entries.add(1, getString(R.string.panic_app_default));
        entryValues.add(0, Panic.PACKAGE_NAME_NONE);
        entryValues.add(1, Panic.PACKAGE_NAME_DEFAULT);

        for (ResolveInfo resolveInfo : PanicResponder.resolveTriggerApps(pm)) {
            if (resolveInfo.activityInfo == null)
                continue;
            entries.add(resolveInfo.activityInfo.loadLabel(pm));
            entryValues.add(resolveInfo.activityInfo.packageName);
        }
        mPanicTriggerApp.setEntries(entries.toArray(new CharSequence[entries.size()]));
        mPanicTriggerApp.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
        PanicResponder.configTriggerAppListPreference(mPanicTriggerApp,
                R.string.panic_trigger_app_summary, R.string.panic_app_none_summary);
    }
 
Example #2
Source File: PanicSetupActivity.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_done:
            PanicResponder.setTriggerPackageName(this);
            setResult(Activity.RESULT_OK, intent);
            finish();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #3
Source File: SettingActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
private void setInitialValues() {
        mOtrMode.setValue(Preferences.getOtrMode());

//        mLinkifyOnTor.setChecked(Preferences.getDoLinkify());
        mHideOfflineContacts.setChecked(Preferences.getHideOfflineContacts());
        mDeleteUnsecuredMedia.setChecked(Preferences.getDeleteInsecureMedia());
        mEnableNotification.setChecked(Preferences.isNotificationEnabled());
        mNotificationVibrate.setChecked(Preferences.getNotificationVibrate());
        mNotificationSound.setChecked(Preferences.getNotificationSound());
        mForegroundService.setChecked(Preferences.getUseForegroundPriority());

        mHeartbeatInterval.setText(String.valueOf(Preferences.getHeartbeatInterval()));

        ArrayList<CharSequence> entries = new ArrayList<CharSequence>();
        ArrayList<CharSequence> entryValues = new ArrayList<CharSequence>();
        entries.add(0, getString(R.string.panic_app_none));
        entries.add(1, getString(R.string.panic_app_default));
        entryValues.add(0, Panic.PACKAGE_NAME_NONE);
        entryValues.add(1, Panic.PACKAGE_NAME_DEFAULT);

        for (ResolveInfo resolveInfo : PanicResponder.resolveTriggerApps(pm)) {
            if (resolveInfo.activityInfo == null)
                continue;
            entries.add(resolveInfo.activityInfo.loadLabel(pm));
            entryValues.add(resolveInfo.activityInfo.packageName);
        }
        mPanicTriggerApp.setEntries(entries.toArray(new CharSequence[entries.size()]));
        mPanicTriggerApp.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
        PanicResponder.configTriggerAppListPreference(mPanicTriggerApp,
                R.string.panic_trigger_app_summary, R.string.panic_app_none_summary);
    }
 
Example #4
Source File: PanicSetupActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_done:
            PanicResponder.setTriggerPackageName(this);
            setResult(Activity.RESULT_OK, intent);
            finish();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #5
Source File: RouterActivity.java    From zom-android-matrix with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mApp = (ImApp)getApplication();

    mHandler = new MyHandler(this);

    Intent intent = getIntent();

    mDoLock = ACTION_LOCK_APP.equals(intent.getAction());

    if (mDoLock) {
        shutdownAndLock(this);

        return;
    } else if (Panic.isTriggerIntent(intent)) {
        if (PanicResponder.receivedTriggerFromConnectedApp(this)) {
            if (Preferences.uninstallApp()) {
                // lock and delete first for rapid response, then uninstall
                shutdownAndLock(this);
                PanicResponder.deleteAllAppData(this);
                Intent uninstall = new Intent(Intent.ACTION_DELETE);
                uninstall.setData(Uri.parse("package:" + getPackageName()));
                startActivity(uninstall);
            } else if (Preferences.clearAppData()) {
                // lock first for rapid response, then delete
                shutdownAndLock(this);
                PanicResponder.deleteAllAppData(this);
            } else if (Preferences.lockApp()) {
                shutdownAndLock(this);
            }
            // TODO add other responses here, paying attention to if/else order
        } else if (PanicResponder.shouldUseDefaultResponseToTrigger(this)) {
            if (Preferences.lockApp()) {
                shutdownAndLock(this);
            }
        }
        // this Intent should not trigger any more processing
        finish();
        return;
    }

    mSignInHelper = new SignInHelper(this, mHandler);
    mDoSignIn = intent.getBooleanExtra(EXTRA_DO_SIGNIN, false);

    AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);

    mCacheWord = new CacheWordHandler(this, (ICacheWordSubscriber)this);
    mCacheWord.connectToService();

    // if we have an incoming contact, send it to the right place
    String scheme = intent.getScheme();
    if(TextUtils.equals(scheme, "keanu"))
    {
        intent.setClass(this, AddContactActivity.class);
        startActivity(intent);
        finish();
        return;
    }

}
 
Example #6
Source File: RouterActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mApp = (ImApp)getApplication();

    mHandler = new MyHandler(this);

    Intent intent = getIntent();

    mDoLock = ACTION_LOCK_APP.equals(intent.getAction());

    if (mDoLock) {
        shutdownAndLock(this);

        return;
    } else if (Panic.isTriggerIntent(intent)) {
        if (PanicResponder.receivedTriggerFromConnectedApp(this)) {
            if (Preferences.uninstallApp()) {
                // lock and delete first for rapid response, then uninstall
                shutdownAndLock(this);
                PanicResponder.deleteAllAppData(this);
                Intent uninstall = new Intent(Intent.ACTION_DELETE);
                uninstall.setData(Uri.parse("package:" + getPackageName()));
                startActivity(uninstall);
            } else if (Preferences.clearAppData()) {
                // lock first for rapid response, then delete
                shutdownAndLock(this);
                PanicResponder.deleteAllAppData(this);
            } else if (Preferences.lockApp()) {
                shutdownAndLock(this);
            }
            // TODO add other responses here, paying attention to if/else order
        } else if (PanicResponder.shouldUseDefaultResponseToTrigger(this)) {
            if (Preferences.lockApp()) {
                shutdownAndLock(this);
            }
        }
        // this Intent should not trigger any more processing
        finish();
        return;
    }

    mSignInHelper = new SignInHelper(this, mHandler);
    mDoSignIn = intent.getBooleanExtra(EXTRA_DO_SIGNIN, true);

    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

    mCacheWord = new CacheWordHandler(this, (ICacheWordSubscriber)this);
    mCacheWord.connectToService();

    // if we have an incoming contact, send it to the right place
    String scheme = intent.getScheme();
    if(TextUtils.equals(scheme, "xmpp"))
    {
        intent.setClass(this, AddContactActivity.class);
        startActivity(intent);
        finish();
        return;
    }
}
 
Example #7
Source File: PanicPreferencesFragment.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.preferences_panic);

    pm = getActivity().getPackageManager();
    prefExit = (CheckBoxPreference) findPreference(Preferences.PREF_PANIC_EXIT);
    prefApp = (ListPreference) findPreference(PREF_APP);
    prefHide = (CheckBoxPreference) findPreference(Preferences.PREF_PANIC_HIDE);
    prefHide.setTitle(getString(R.string.panic_hide_title, getString(R.string.app_name)));
    prefResetRepos = (CheckBoxPreference) findPreference(Preferences.PREF_PANIC_RESET_REPOS);
    categoryAppsToUninstall = (PreferenceCategory) findPreference("pref_panic_apps_to_uninstall");

    if (PanicResponder.checkForDisconnectIntent(getActivity())) {
        // the necessary action should have been performed by the check already
        getActivity().finish();
        return;
    }
    String connectIntentSender = PanicResponder.getConnectIntentSender(getActivity());
    // if there's a connecting app and it is not the old one
    if (!TextUtils.isEmpty(connectIntentSender) && !TextUtils.equals(connectIntentSender, PanicResponder
            .getTriggerPackageName(getActivity()))) {
        // Show dialog allowing the user to opt-in
        showOptInDialog();
    }

    prefApp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String packageName = (String) newValue;
            PanicResponder.setTriggerPackageName(getActivity(), packageName);
            if (packageName.equals(Panic.PACKAGE_NAME_NONE)) {
                prefHide.setChecked(false);
                prefHide.setEnabled(false);
                prefResetRepos.setChecked(false);
                prefResetRepos.setEnabled(false);
                getActivity().setResult(Activity.RESULT_CANCELED);
            } else {
                prefHide.setEnabled(true);
                prefResetRepos.setEnabled(true);
            }
            showPanicApp(packageName);
            return true;
        }
    });
    showPanicApp(PanicResponder.getTriggerPackageName(getActivity()));
}
 
Example #8
Source File: PanicPreferencesFragment.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
private void showPanicApp(String packageName) {
    // Fill list of available panic apps
    ArrayList<CharSequence> entries = new ArrayList<>();
    ArrayList<CharSequence> entryValues = new ArrayList<>();
    entries.add(0, getString(R.string.panic_app_setting_none));
    entryValues.add(0, Panic.PACKAGE_NAME_NONE);

    for (ResolveInfo resolveInfo : PanicResponder.resolveTriggerApps(pm)) {
        if (resolveInfo.activityInfo == null) continue;
        entries.add(resolveInfo.activityInfo.loadLabel(pm));
        entryValues.add(resolveInfo.activityInfo.packageName);
    }

    prefApp.setEntries(entries.toArray(new CharSequence[entries.size()]));
    prefApp.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
    prefApp.setDefaultValue(Panic.PACKAGE_NAME_NONE);

    if (entries.size() <= 1) {
        // bring the user to Ripple if no other panic apps are available
        prefApp.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("market://details?id=info.guardianproject.ripple"));
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                    startActivity(intent);
                }
                return true;
            }
        });
    }

    if (TextUtils.isEmpty(packageName) || packageName.equals(Panic.PACKAGE_NAME_NONE)) {
        // no panic app set
        prefApp.setValue(Panic.PACKAGE_NAME_NONE);
        prefApp.setSummary(getString(R.string.panic_app_setting_summary));

        prefApp.setIcon(null); // otherwise re-setting view resource doesn't work
        Drawable icon = ContextCompat.getDrawable(getActivity(), R.drawable.ic_cancel);
        TypedValue typedValue = new TypedValue();
        Resources.Theme theme = getActivity().getTheme();
        theme.resolveAttribute(R.attr.appListItem, typedValue, true);
        @ColorInt int color = typedValue.data;
        icon.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        prefApp.setIcon(icon);

        // disable destructive panic actions
        prefHide.setEnabled(false);
        showWipeList();
    } else {
        // try to display connected panic app
        try {
            prefApp.setValue(packageName);
            prefApp.setSummary(pm.getApplicationLabel(pm.getApplicationInfo(packageName, 0)));
            prefApp.setIcon(pm.getApplicationIcon(packageName));
            prefHide.setEnabled(true);
            prefResetRepos.setEnabled(true);
            showWipeList();
        } catch (PackageManager.NameNotFoundException e) {
            // revert back to no app, just to be safe
            PanicResponder.setTriggerPackageName(getActivity(), Panic.PACKAGE_NAME_NONE);
            showPanicApp(Panic.PACKAGE_NAME_NONE);
        }
    }
}