Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'issue-62'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhodey committed Oct 8, 2014
2 parents 737b2b7 + 4516bfc commit 3655f4f
Show file tree
Hide file tree
Showing 18 changed files with 340 additions and 133 deletions.
12 changes: 6 additions & 6 deletions flock/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ apply plugin: 'witness'
repositories {
mavenCentral()

maven {
url "https://raw.github.com/whispersystems/maven/master/stripe-btc/releases"
}
maven {
url "https://raw.github.com/whispersystems/maven/master/gson/releases/"
}
maven { url 'https://raw.github.com/whispersystems/maven/master/stripe-btc/releases' }
maven { url 'https://raw.github.com/whispersystems/maven/master/gson/releases/' }
}

android {
Expand Down Expand Up @@ -59,6 +55,9 @@ dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
compile group: 'com.stripe', name: 'stripe-java-btc', version: '1.12.0-btc-beta'
compile group: 'com.google.zxing', name: 'core', version: '3.1.0'
compile(group: 'org.whispersystems', name: 'libpastelog', version: '1.0.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
}

dependencyVerification {
Expand All @@ -85,6 +84,7 @@ dependencyVerification {
'com.fasterxml.jackson.core:jackson-annotations:0c8c3811322cc84c09a93f34436fe784a1259dd5376a90aec5a73493456f757d',
'org.slf4j:slf4j-api:fe30825245d2336c859dc38d60c0fc5f3668dbf29cd586828d2b5667ec355b91',
'com.fasterxml.jackson.core:jackson-core:61f84f93e3f901134d7498b50119ee01074f10d59560e45ccd3e1d48cfec493b',
'org.whispersystems:libpastelog:fdc5bea9c48d9b7bb6fbe775717f84537d3334cead157eefc57c8e7ec7e90c81'
]
}

10 changes: 10 additions & 0 deletions flock/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@

<activity android:name="org.anhonesteffort.flock.MigrationReleaseNotesActivity" />

<activity android:name="org.anhonesteffort.flock.SendDebugLogActivity"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"/>

<service android:name="org.anhonesteffort.flock.auth.AccountAuthenticatorService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
Expand Down Expand Up @@ -208,6 +212,12 @@
</intent-filter>
</receiver>

<receiver android:name="org.anhonesteffort.flock.NotificationDrawer">
<intent-filter>
<action android:name="org.anhonesteffort.flock.ACTION_STOP_ASKING_FOR_LOGS"/>
</intent-filter>
</receiver>

<receiver android:name="org.anhonesteffort.flock.MigrationHelperBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.anhonesteffort.flock.crypto.KeyUtil;
import org.anhonesteffort.flock.registration.RegistrationApi;
import org.anhonesteffort.flock.registration.RegistrationApiException;
import org.anhonesteffort.flock.sync.AbstractDavSyncAdapter;
import org.anhonesteffort.flock.sync.key.DavKeyCollection;
import org.anhonesteffort.flock.sync.key.DavKeyStore;
import org.anhonesteffort.flock.webdav.PropertyParseException;
Expand Down Expand Up @@ -109,7 +108,7 @@ private void handleChangeOwsAuthToken(Bundle result, String passphrase) {

registrationApi.setAccountPassword(account, newAuthToken);
DavAccountHelper.setAccountPassword(getBaseContext(), newAuthToken);
AbstractDavSyncAdapter.disableAuthNotificationsForRunningAdapters(getBaseContext(), account.getOsAccount());
NotificationDrawer.disableAuthNotificationsForRunningAdapters(getBaseContext(), account.getOsAccount());

account = new DavAccount(account.getUserId(), newAuthToken, account.getDavHostHREF());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void handleDavLogin(Bundle result, DavAccount account) {

if (DavAccountHelper.isAuthenticated(getBaseContext(), account)) {
DavAccountHelper.setAccountPassword(getBaseContext(), account.getAuthToken());
AbstractDavSyncAdapter.cancelAuthNotification(getBaseContext());
NotificationDrawer.cancelAuthNotification(getBaseContext());

result.putInt(ErrorToaster.KEY_STATUS_CODE, ErrorToaster.CODE_SUCCESS);
}
Expand Down
191 changes: 191 additions & 0 deletions flock/src/main/java/org/anhonesteffort/flock/NotificationDrawer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/*
* Copyright (C) 2014 Open Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.anhonesteffort.flock;

import android.accounts.Account;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.google.common.base.Optional;

import org.anhonesteffort.flock.auth.DavAccount;
import org.anhonesteffort.flock.sync.addressbook.AddressbookSyncScheduler;
import org.anhonesteffort.flock.sync.calendar.CalendarsSyncScheduler;
import org.anhonesteffort.flock.sync.key.KeySyncScheduler;

/**
* rhodey
*/
public class NotificationDrawer extends BroadcastReceiver {

private static final String TAG = "org.anhonesteffort.flock.NotificationDrawer";

private static final int ID_NOTIFICATION_AUTH = 1020;
private static final int ID_NOTIFICATION_SUBSCRIPTION = 1021;
private static final int ID_NOTIFICATION_DEBUG_LOG = 1022;

private static final String PREFERENCES_NAME = "AbstractDavSyncAdapter.PREFERENCES_NAME";
private static final String KEY_VOID_AUTH_NOTIFICATIONS = "KEY_VOID_AUTH_NOTIFICATIONS";

private static final String ACTION_STOP_ASKING_FOR_LOGS = "org.anhonesteffort.flock.ACTION_STOP_ASKING_FOR_LOGS";
private static final String KEY_STOP_ASKING_FOR_LOGS = "KEY_STOP_ASKING_FOR_LOGS";

public static void disableAuthNotificationsForRunningAdapters(Context context, Account account) {
AddressbookSyncScheduler addressbookSync = new AddressbookSyncScheduler(context);
CalendarsSyncScheduler calendarSync = new CalendarsSyncScheduler(context);
KeySyncScheduler keySync = new KeySyncScheduler(context);
SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_MULTI_PROCESS);

if (addressbookSync.syncInProgress(account)) {
settings.edit().putBoolean(KEY_VOID_AUTH_NOTIFICATIONS + addressbookSync.getAuthority(), true).commit();
Log.w(TAG, "disabled auth notifications for " + addressbookSync.getAuthority());
}

if (calendarSync.syncInProgress(account)) {
settings.edit().putBoolean(KEY_VOID_AUTH_NOTIFICATIONS + calendarSync.getAuthority(), true).commit();
Log.w(TAG, "disabled auth notifications for " + calendarSync.getAuthority());
}

if (keySync.syncInProgress(account)) {
settings.edit().putBoolean(KEY_VOID_AUTH_NOTIFICATIONS + keySync.getAuthority(), true).commit();
Log.w(TAG, "disabled auth notifications for " + keySync.getAuthority());
}
}

public static void enableAuthNotifications(Context context, String authority) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_MULTI_PROCESS);
settings.edit().putBoolean(KEY_VOID_AUTH_NOTIFICATIONS + authority, false).commit();
Log.w(TAG, "enabled auth notification for " + authority);
}

public static boolean isAuthNotificationDisabled(Context context, String authority) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_MULTI_PROCESS);

if (settings.getBoolean(KEY_VOID_AUTH_NOTIFICATIONS + authority, false)) {
Log.w(TAG, "auth notification is disabled for " + authority);
return true;
}

return false;
}

private static NotificationManager getNotificationManager(Context context) {
return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}

private static PendingIntent getPendingActivityIntent(Context context, Intent intent) {
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

public static void handleInvalidatePasswordAndShowAuthNotification(Context context) {
Log.w(TAG, "handleInvalidatePasswordAndShowAuthNotification()");

DavAccountHelper.invalidateAccountPassword(context);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
Intent clickIntent = new Intent(context, CorrectPasswordActivity.class);

notificationBuilder.setContentTitle(context.getString(R.string.notification_flock_login_error));
notificationBuilder.setContentText(context.getString(R.string.notification_tap_to_correct_password));
notificationBuilder.setSmallIcon(R.drawable.flock_actionbar_icon);
notificationBuilder.setAutoCancel(true);

notificationBuilder.setContentIntent(getPendingActivityIntent(context, clickIntent));
getNotificationManager(context).notify(ID_NOTIFICATION_AUTH, notificationBuilder.build());
}

public static void cancelAuthNotification(Context context) {
getNotificationManager(context).cancel(ID_NOTIFICATION_AUTH);
}

public static void showSubscriptionExpiredNotification(Context context) {
Log.w(TAG, "showSubscriptionExpiredNotification()");

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
Intent clickIntent = new Intent(context, ManageSubscriptionActivity.class);

notificationBuilder.setContentTitle(context.getString(R.string.notification_flock_subscription_expired));
notificationBuilder.setContentText(context.getString(R.string.notification_tap_to_update_subscription));
notificationBuilder.setSmallIcon(R.drawable.flock_actionbar_icon);
notificationBuilder.setAutoCancel(true);

Optional<DavAccount> account = DavAccountHelper.getAccount(context);
clickIntent.putExtra(ManageSubscriptionActivity.KEY_DAV_ACCOUNT_BUNDLE, account.get().toBundle());

notificationBuilder.setContentIntent(getPendingActivityIntent(context, clickIntent));
getNotificationManager(context).notify(ID_NOTIFICATION_SUBSCRIPTION, notificationBuilder.build());
}

private static boolean isStopAskingForLogsSet(Context context) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_MULTI_PROCESS);
return settings.getBoolean(KEY_STOP_ASKING_FOR_LOGS, false);
}

private static void setStopAskingForLogs(Context context) {
Log.w(TAG, "will stop asking for debug logs :(");
SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_MULTI_PROCESS);
settings.edit().putBoolean(KEY_STOP_ASKING_FOR_LOGS, true).commit();
}

public static void handlePromptForDebugLogIfNotDisabled(Context context) {
if (isStopAskingForLogsSet(context)) {
Log.w(TAG, "user doesn't care to send us logs, not going to ask.");
return;
}

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
Intent sendLogIntent = new Intent(context, SendDebugLogActivity.class);
Intent stopAskingIntent = new Intent(ACTION_STOP_ASKING_FOR_LOGS);

String contentText = context.getString(R.string.something_strange_happened_send_us_your_debug_log);
NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle().bigText(contentText);

notificationBuilder.setSmallIcon(R.drawable.flock_actionbar_icon);
notificationBuilder.setContentTitle(context.getString(R.string.flock_debug_log));
notificationBuilder.setContentText(contentText);
notificationBuilder.setStyle(textStyle);
notificationBuilder.setAutoCancel(true);

notificationBuilder.addAction(R.drawable.navigation_cancel,
context.getString(R.string.dont_ask_again),
PendingIntent.getBroadcast(context, 0, stopAskingIntent, PendingIntent.FLAG_UPDATE_CURRENT));

notificationBuilder.addAction(R.drawable.social_send_now,
context.getString(R.string.send_log),
getPendingActivityIntent(context, sendLogIntent));

getNotificationManager(context).notify(ID_NOTIFICATION_DEBUG_LOG, notificationBuilder.build());
}

public static void cancelDebugLogPrompt(Context context) {
getNotificationManager(context).cancel(ID_NOTIFICATION_DEBUG_LOG);
}

@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_STOP_ASKING_FOR_LOGS)) {
setStopAskingForLogs(context);
cancelDebugLogPrompt(context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,21 @@ public boolean onCreateOptionsMenu(Menu menu) {

@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent nextIntent = null;

switch (item.getItemId()) {
case R.id.button_delete_all_contacts:
Intent nextIntent = new Intent(getBaseContext(), DeleteAllContactsActivity.class);
startActivity(nextIntent);
nextIntent = new Intent(getBaseContext(), DeleteAllContactsActivity.class);
break;

case R.id.button_send_debug_log:
nextIntent = new Intent(getBaseContext(), SendDebugLogActivity.class);
break;
}

if (nextIntent != null)
startActivity(nextIntent);

return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (C) 2014 Open Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.anhonesteffort.flock;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;

import org.whispersystems.libpastelog.SubmitLogFragment;

/**
* rhodey
*/
public class SendDebugLogActivity extends FragmentActivity implements SubmitLogFragment.OnLogSubmittedListener {

private static final String TAG = "org.anhonesteffort.flock.SendDebugLogActivity";

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

setContentView(R.layout.simple_fragment_activity);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setTitle(R.string.send_debug_log);

FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
Fragment sendLogFragment = SubmitLogFragment.newInstance(getString(R.string.support_email_address),
getString(R.string.flock_debug_log));

fragmentTransaction.replace(R.id.fragment_view, sendLogFragment);
fragmentTransaction.commit();

NotificationDrawer.cancelDebugLogPrompt(getBaseContext());
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}

return false;
}

@Override
public void onSuccess() {
Log.d(TAG, "onSuccess()");
Toast.makeText(getBaseContext(), R.string.thanks, Toast.LENGTH_LONG).show();
finish();
}

@Override
public void onFailure() {
Log.d(TAG, "onFailure()");
Toast.makeText(getBaseContext(), R.string.error_connection_error, Toast.LENGTH_LONG).show();
finish();
}

@Override
public void onCancel() {
Log.d(TAG, "onCancel()");
finish();
}
}
Loading

0 comments on commit 3655f4f

Please sign in to comment.