From fce37aeb0f564efb27c9768c422c84443fc9d528 Mon Sep 17 00:00:00 2001 From: Uwe Trottmann Date: Sat, 10 Aug 2013 00:41:46 +0200 Subject: [PATCH 1/9] Fix crash when disconnecting trakt. --- .../src/com/battlelancer/seriesguide/util/ServiceUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SeriesGuide/src/com/battlelancer/seriesguide/util/ServiceUtils.java b/SeriesGuide/src/com/battlelancer/seriesguide/util/ServiceUtils.java index f24d2b16dc..e19785a9b1 100644 --- a/SeriesGuide/src/com/battlelancer/seriesguide/util/ServiceUtils.java +++ b/SeriesGuide/src/com/battlelancer/seriesguide/util/ServiceUtils.java @@ -263,7 +263,9 @@ public static void clearTraktCredentials(Context context) { editor.commit(); // remove from memory - ServiceUtils.sTraktServiceManagerWithAuthInstance.setAuthentication(null, null); + if (sTraktServiceManagerWithAuthInstance != null) { + sTraktServiceManagerWithAuthInstance.setAuthentication(null, null); + } } /** From 597f82f614136d6ef8e7e262d0d06ecde72bfff7 Mon Sep 17 00:00:00 2001 From: Uwe Trottmann Date: Thu, 8 Aug 2013 22:03:16 +0200 Subject: [PATCH 2/9] Always use helper account creation method. --- .../seriesguide/sync/SgAccountAuthenticator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgAccountAuthenticator.java b/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgAccountAuthenticator.java index 62e6142002..51db12a980 100644 --- a/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgAccountAuthenticator.java +++ b/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgAccountAuthenticator.java @@ -12,6 +12,7 @@ import android.util.Log; import com.battlelancer.seriesguide.SeriesGuideApplication; +import com.uwetrottmann.seriesguide.R; public class SgAccountAuthenticator extends AbstractAccountAuthenticator { @@ -20,8 +21,7 @@ public class SgAccountAuthenticator extends AbstractAccountAuthenticator { private Context mContext; public static Account getSyncAccount(Context context) { - Account account = new Account(SgAccountAuthenticator.ACCOUNT_NAME, context.getPackageName()); - return account; + return new Account(ACCOUNT_NAME, context.getString(R.string.package_name)); } public SgAccountAuthenticator(Context context) { @@ -42,7 +42,7 @@ public Bundle addAccount(AccountAuthenticatorResponse response, String accountTy // set up a dummy account for syncing AccountManager manager = AccountManager.get(mContext); - final Account account = new Account(ACCOUNT_NAME, mContext.getPackageName()); + final Account account = getSyncAccount(mContext); manager.addAccountExplicitly(account, null, null); ContentResolver.setIsSyncable(account, SeriesGuideApplication.CONTENT_AUTHORITY, 1); ContentResolver.setSyncAutomatically(account, SeriesGuideApplication.CONTENT_AUTHORITY, @@ -86,7 +86,7 @@ public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account) throws NetworkErrorException { final Bundle result = new Bundle(); - result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false); + result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true); return result; } From 5b77a87d89d9a01b4ad625a2262391a9e328f29b Mon Sep 17 00:00:00 2001 From: Uwe Trottmann Date: Thu, 8 Aug 2013 22:03:32 +0200 Subject: [PATCH 3/9] Setup account only after launching main activity. --- .../seriesguide/SeriesGuideApplication.java | 15 -------- .../seriesguide/sync/SyncUtils.java | 37 +++++++++++++++++++ .../seriesguide/ui/ShowsActivity.java | 4 ++ 3 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 SeriesGuide/src/com/battlelancer/seriesguide/sync/SyncUtils.java diff --git a/SeriesGuide/src/com/battlelancer/seriesguide/SeriesGuideApplication.java b/SeriesGuide/src/com/battlelancer/seriesguide/SeriesGuideApplication.java index 59b1f0ab2e..6cc475aca9 100644 --- a/SeriesGuide/src/com/battlelancer/seriesguide/SeriesGuideApplication.java +++ b/SeriesGuide/src/com/battlelancer/seriesguide/SeriesGuideApplication.java @@ -17,20 +17,15 @@ package com.battlelancer.seriesguide; -import android.accounts.Account; -import android.accounts.AccountManager; import android.annotation.SuppressLint; import android.app.Application; import android.content.ContentProvider; -import android.content.ContentResolver; import android.content.SharedPreferences; -import android.os.Bundle; import android.os.StrictMode; import android.os.StrictMode.ThreadPolicy; import android.os.StrictMode.VmPolicy; import android.preference.PreferenceManager; -import com.battlelancer.seriesguide.sync.SgAccountAuthenticator; import com.battlelancer.seriesguide.ui.SeriesGuidePreferences; import com.battlelancer.seriesguide.util.ImageProvider; import com.battlelancer.seriesguide.util.Utils; @@ -72,16 +67,6 @@ public void onCreate() { // Set a context for Google Analytics EasyTracker.getInstance().setContext(this); - // Set up a dummy account for syncing - AccountManager manager = AccountManager.get(this); - final Account account = SgAccountAuthenticator.getSyncAccount(this); - if (manager.addAccountExplicitly(account, null, null)) { - ContentResolver.setIsSyncable(account, CONTENT_AUTHORITY, 1); - ContentResolver.setSyncAutomatically(account, CONTENT_AUTHORITY, true); - // Sync daily by default - ContentResolver.addPeriodicSync(account, CONTENT_AUTHORITY, new Bundle(), 24 * 60 * 60); - } - // Enable StrictMode enableStrictMode(); } diff --git a/SeriesGuide/src/com/battlelancer/seriesguide/sync/SyncUtils.java b/SeriesGuide/src/com/battlelancer/seriesguide/sync/SyncUtils.java new file mode 100644 index 0000000000..b572263e41 --- /dev/null +++ b/SeriesGuide/src/com/battlelancer/seriesguide/sync/SyncUtils.java @@ -0,0 +1,37 @@ + +package com.battlelancer.seriesguide.sync; + +import android.accounts.Account; +import android.accounts.AccountManager; +import android.content.ContentResolver; +import android.content.Context; +import android.os.Bundle; + +import com.battlelancer.seriesguide.SeriesGuideApplication; + +public class SyncUtils { + + private static final int SYNC_FREQUENCY = 24 * 60 * 60; // 1 day (in + // seconds) + + public static void createSyncAccount(Context context) { + // Create account, if it's missing. (Either first run, or user has + // deleted account.) + AccountManager manager = AccountManager.get(context); + final Account account = SgAccountAuthenticator.getSyncAccount(context); + if (manager.addAccountExplicitly(account, null, null)) { + // Inform the system that this account supports sync + ContentResolver.setIsSyncable(account, SeriesGuideApplication.CONTENT_AUTHORITY, 1); + // Inform the system that this account is eligible for auto sync + // when the network is up + ContentResolver.setSyncAutomatically(account, SeriesGuideApplication.CONTENT_AUTHORITY, + true); + // Recommend a schedule for automatic synchronization. The system + // may modify this based + // on other scheduled syncs and network utilization. + ContentResolver.addPeriodicSync(account, SeriesGuideApplication.CONTENT_AUTHORITY, + new Bundle(), SYNC_FREQUENCY); + } + } + +} diff --git a/SeriesGuide/src/com/battlelancer/seriesguide/ui/ShowsActivity.java b/SeriesGuide/src/com/battlelancer/seriesguide/ui/ShowsActivity.java index 44281066b2..ee912981e7 100644 --- a/SeriesGuide/src/com/battlelancer/seriesguide/ui/ShowsActivity.java +++ b/SeriesGuide/src/com/battlelancer/seriesguide/ui/ShowsActivity.java @@ -44,6 +44,7 @@ import com.battlelancer.seriesguide.provider.SeriesContract.Shows; import com.battlelancer.seriesguide.settings.AppSettings; import com.battlelancer.seriesguide.sync.SgSyncAdapter; +import com.battlelancer.seriesguide.sync.SyncUtils; import com.battlelancer.seriesguide.ui.FirstRunFragment.OnFirstRunDismissedListener; import com.battlelancer.seriesguide.ui.dialogs.ChangesDialogFragment; import com.battlelancer.seriesguide.util.CompatActionBarNavHandler; @@ -91,6 +92,9 @@ public class ShowsActivity extends BaseTopShowsActivity implements CompatActionB protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getMenu().setContentView(R.layout.shows); + + // Set up a sync account if needed + SyncUtils.createSyncAccount(this); final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); From 200486a1c27059b0ed5463496a397d787c71ac2e Mon Sep 17 00:00:00 2001 From: Uwe Trottmann Date: Thu, 8 Aug 2013 22:22:34 +0200 Subject: [PATCH 4/9] Fix hang when manually adding sync account by returning expected bundle. --- .../sync/SgAccountAuthenticator.java | 45 +++++++------------ .../seriesguide/sync/SgSyncAdapter.java | 8 ++-- .../seriesguide/sync/SyncUtils.java | 15 ++++++- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgAccountAuthenticator.java b/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgAccountAuthenticator.java index 51db12a980..dc3785c148 100644 --- a/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgAccountAuthenticator.java +++ b/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgAccountAuthenticator.java @@ -6,51 +6,30 @@ import android.accounts.AccountAuthenticatorResponse; import android.accounts.AccountManager; import android.accounts.NetworkErrorException; -import android.content.ContentResolver; import android.content.Context; import android.os.Bundle; -import android.util.Log; - -import com.battlelancer.seriesguide.SeriesGuideApplication; -import com.uwetrottmann.seriesguide.R; public class SgAccountAuthenticator extends AbstractAccountAuthenticator { - public static final String ACCOUNT_NAME = "SeriesGuide Sync"; - private static final String TAG = "SgAccountAuthenticator"; private Context mContext; - public static Account getSyncAccount(Context context) { - return new Account(ACCOUNT_NAME, context.getString(R.string.package_name)); - } - public SgAccountAuthenticator(Context context) { super(context); mContext = context; } - @Override - public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) { - return null; - } - @Override public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException { - Log.d(TAG, "Setting up sync account"); - - // set up a dummy account for syncing - AccountManager manager = AccountManager.get(mContext); - final Account account = getSyncAccount(mContext); - manager.addAccountExplicitly(account, null, null); - ContentResolver.setIsSyncable(account, SeriesGuideApplication.CONTENT_AUTHORITY, 1); - ContentResolver.setSyncAutomatically(account, SeriesGuideApplication.CONTENT_AUTHORITY, - true); - Log.d(TAG, "Finished setting up sync account"); + SyncUtils.createSyncAccount(mContext); - return null; + final Account account = SyncUtils.getSyncAccount(mContext); + Bundle bundle = new Bundle(); + bundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); + bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); + return bundle; } @Override @@ -59,6 +38,11 @@ public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account return null; } + @Override + public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) { + throw new UnsupportedOperationException(); + } + @Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { @@ -79,7 +63,12 @@ public Bundle updateCredentials(AccountAuthenticatorResponse response, Account a @Override public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException { - return null; + // This call is used to query whether the Authenticator supports + // specific features. We don't expect to get called, so we always + // return false (no) for any queries. + final Bundle result = new Bundle(); + result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false); + return result; } @Override diff --git a/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgSyncAdapter.java b/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgSyncAdapter.java index 78c0496e67..4ea5993a8c 100644 --- a/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgSyncAdapter.java +++ b/SeriesGuide/src/com/battlelancer/seriesguide/sync/SgSyncAdapter.java @@ -123,7 +123,7 @@ public static void requestSync(Context context, int showTvdbId, boolean isUserRe args.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true); } - final Account account = SgAccountAuthenticator.getSyncAccount(context); + final Account account = SyncUtils.getSyncAccount(context); ContentResolver.requestSync(account, SeriesGuideApplication.CONTENT_AUTHORITY, args); @@ -134,7 +134,7 @@ public static void requestSync(Context context, int showTvdbId, boolean isUserRe * tickle. */ public static void setSyncAutomatically(Context context, boolean sync) { - final Account account = SgAccountAuthenticator.getSyncAccount(context); + final Account account = SyncUtils.getSyncAccount(context); ContentResolver.setSyncAutomatically(account, SeriesGuideApplication.CONTENT_AUTHORITY, sync); } @@ -143,7 +143,7 @@ public static void setSyncAutomatically(Context context, boolean sync) { * Check if the provider should be synced when a network tickle is received. */ public static boolean isSyncAutomatically(Context context) { - return ContentResolver.getSyncAutomatically(SgAccountAuthenticator.getSyncAccount(context), + return ContentResolver.getSyncAutomatically(SyncUtils.getSyncAccount(context), SeriesGuideApplication.CONTENT_AUTHORITY); } @@ -153,7 +153,7 @@ public static boolean isSyncAutomatically(Context context) { */ public static boolean isSyncActive(Context context, boolean displayWarning) { boolean isSyncActive = ContentResolver.isSyncActive( - SgAccountAuthenticator.getSyncAccount(context), + SyncUtils.getSyncAccount(context), SeriesGuideApplication.CONTENT_AUTHORITY); if (isSyncActive) { Toast.makeText(context, R.string.update_inprogress, Toast.LENGTH_LONG).show(); diff --git a/SeriesGuide/src/com/battlelancer/seriesguide/sync/SyncUtils.java b/SeriesGuide/src/com/battlelancer/seriesguide/sync/SyncUtils.java index b572263e41..4c841bffcd 100644 --- a/SeriesGuide/src/com/battlelancer/seriesguide/sync/SyncUtils.java +++ b/SeriesGuide/src/com/battlelancer/seriesguide/sync/SyncUtils.java @@ -6,19 +6,26 @@ import android.content.ContentResolver; import android.content.Context; import android.os.Bundle; +import android.util.Log; import com.battlelancer.seriesguide.SeriesGuideApplication; public class SyncUtils { + private static final String TAG = "SyncUtils"; + + private static final String ACCOUNT_NAME = "SeriesGuide Sync"; + private static final int SYNC_FREQUENCY = 24 * 60 * 60; // 1 day (in // seconds) public static void createSyncAccount(Context context) { + Log.d(TAG, "Setting up sync account"); + // Create account, if it's missing. (Either first run, or user has // deleted account.) AccountManager manager = AccountManager.get(context); - final Account account = SgAccountAuthenticator.getSyncAccount(context); + final Account account = SyncUtils.getSyncAccount(context); if (manager.addAccountExplicitly(account, null, null)) { // Inform the system that this account supports sync ContentResolver.setIsSyncable(account, SeriesGuideApplication.CONTENT_AUTHORITY, 1); @@ -32,6 +39,12 @@ public static void createSyncAccount(Context context) { ContentResolver.addPeriodicSync(account, SeriesGuideApplication.CONTENT_AUTHORITY, new Bundle(), SYNC_FREQUENCY); } + + Log.d(TAG, "Finished setting up sync account"); + } + + public static Account getSyncAccount(Context context) { + return new Account(ACCOUNT_NAME, context.getPackageName()); } } From 22a48e83e27aaaed6a533b279d6d20ab7d15d96c Mon Sep 17 00:00:00 2001 From: Uwe Trottmann Date: Thu, 8 Aug 2013 23:13:52 +0200 Subject: [PATCH 5/9] Only update shows every 12 hours if accessing overview. --- .../seriesguide/ui/OverviewActivity.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/SeriesGuide/src/com/battlelancer/seriesguide/ui/OverviewActivity.java b/SeriesGuide/src/com/battlelancer/seriesguide/ui/OverviewActivity.java index 5593a77623..7dce0d5660 100644 --- a/SeriesGuide/src/com/battlelancer/seriesguide/ui/OverviewActivity.java +++ b/SeriesGuide/src/com/battlelancer/seriesguide/ui/OverviewActivity.java @@ -40,6 +40,7 @@ import com.battlelancer.seriesguide.items.Series; import com.battlelancer.seriesguide.sync.SgSyncAdapter; import com.battlelancer.seriesguide.util.DBUtils; +import com.battlelancer.thetvdbapi.TheTVDB; import com.google.analytics.tracking.android.EasyTracker; import com.uwetrottmann.androidutils.AndroidUtils; import com.uwetrottmann.seriesguide.R; @@ -260,14 +261,18 @@ public boolean onOptionsItemSelected(MenuItem item) { * Delayed request to sync the displayed show. */ private void onUpdateShow() { - final Context context = getApplicationContext(); - final Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - SgSyncAdapter.requestSync(context, mShowId, false); - } - }, 1000); + final String showId = String.valueOf(mShowId); + boolean isTime = TheTVDB.isUpdateShow(showId, System.currentTimeMillis(), this); + if (isTime) { + final Context context = getApplicationContext(); + final Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + @Override + public void run() { + SgSyncAdapter.requestSync(context, mShowId, false); + } + }, 1000); + } } @Override From 9984ab5cdfd8dd84bae0e6152998ed7dd50238db Mon Sep 17 00:00:00 2001 From: Uwe Trottmann Date: Sat, 10 Aug 2013 09:39:25 +0200 Subject: [PATCH 6/9] Check if IabHelper is still available when checking for purchases. --- .../src/com/battlelancer/seriesguide/billing/IabHelper.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SeriesGuide/src/com/battlelancer/seriesguide/billing/IabHelper.java b/SeriesGuide/src/com/battlelancer/seriesguide/billing/IabHelper.java index 529c71bdfa..3bcccbca12 100644 --- a/SeriesGuide/src/com/battlelancer/seriesguide/billing/IabHelper.java +++ b/SeriesGuide/src/com/battlelancer/seriesguide/billing/IabHelper.java @@ -861,6 +861,10 @@ int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteE do { logDebug("Calling getPurchases with continuation token: " + continueToken); + if (!mSetupDone) { + logError("IabHelper was disposed before we would do something."); + return IABHELPER_BAD_RESPONSE; + } Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), itemType, continueToken); From b4908835486f68a5ea03c79b5776c8f28b24e0a6 Mon Sep 17 00:00:00 2001 From: Uwe Trottmann Date: Sat, 10 Aug 2013 09:41:25 +0200 Subject: [PATCH 7/9] Push version to 7.1. --- SeriesGuideFree/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SeriesGuideFree/AndroidManifest.xml b/SeriesGuideFree/AndroidManifest.xml index fe6dd23353..b383caa5a5 100644 --- a/SeriesGuideFree/AndroidManifest.xml +++ b/SeriesGuideFree/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="171" + android:versionName="7.1" > Date: Sat, 10 Aug 2013 09:43:50 +0200 Subject: [PATCH 8/9] Change log for 7.1. --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78659bc774..ee14f89d5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ Changelog All dates are in the European Central timezone. +Version 7.1 *(2013-08-09)* +----------------- + +* NOTICE Allow removal of SeriesGuide account from Android settings. If you experience random crashes, try removing and then adding the SeriesGuide account again. +* FIX Crash when disconnecting from trakt. +* FIX Crash when checking for in-app purchases (X subscription). +* FIX Only update a show once every 12 hours when accessing its overview page. + Version 7 *(2013-08-08)* ----------------- From bfd5e57078a30812e44307e4be731c51727405c2 Mon Sep 17 00:00:00 2001 From: Uwe Trottmann Date: Sat, 10 Aug 2013 10:06:57 +0200 Subject: [PATCH 9/9] Fix release date of 7.1. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee14f89d5e..b9e56c2751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ Changelog All dates are in the European Central timezone. -Version 7.1 *(2013-08-09)* +Version 7.1 *(2013-08-10)* ----------------- * NOTICE Allow removal of SeriesGuide account from Android settings. If you experience random crashes, try removing and then adding the SeriesGuide account again.