aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-08-28 22:13:10 -0700
committerScott Jackson <daneren2005@gmail.com>2013-08-28 22:13:10 -0700
commit9e1706fc4e67eca6ba69c1a62f8c0f6fc6a76eba (patch)
treee9fc363fb9fb97f95e1444420611e4411becf5db
parent054f83744088381f99765bf2957ddbed19d8e61f (diff)
downloaddsub-9e1706fc4e67eca6ba69c1a62f8c0f6fc6a76eba.tar.gz
dsub-9e1706fc4e67eca6ba69c1a62f8c0f6fc6a76eba.tar.bz2
dsub-9e1706fc4e67eca6ba69c1a62f8c0f6fc6a76eba.zip
Start of custom SyncAdapters
-rw-r--r--AndroidManifest.xml28
-rw-r--r--res/xml/authenticator.xml7
-rw-r--r--res/xml/syncadapter.xml8
-rw-r--r--src/github/daneren2005/dsub/activity/MainActivity.java13
-rw-r--r--src/github/daneren2005/dsub/service/sync/AuthenticatorService.java90
-rw-r--r--src/github/daneren2005/dsub/service/sync/StubProvider.java61
-rw-r--r--src/github/daneren2005/dsub/service/sync/SyncAdapter.java47
-rw-r--r--src/github/daneren2005/dsub/service/sync/SyncService.java48
-rw-r--r--src/github/daneren2005/dsub/util/Constants.java4
9 files changed, 305 insertions, 1 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 5a17c19c..14294eda 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -15,7 +15,11 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.READ_LOGS"/>
-
+ <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
+ <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
+ <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
+
+
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
<uses-feature android:name="android.hardware.microphone" android:required="false" />
@@ -79,6 +83,24 @@
<service android:name="github.daneren2005.dsub.service.DownloadServiceImpl"
android:label="Subsonic Download Service"/>
+ <service android:name="github.daneren2005.dsub.service.sync.AuthenticatorService">
+ <intent-filter>
+ <action android:name="android.accounts.AccountAuthenticator"/>
+ </intent-filter>
+
+ <meta-data android:name="android.accounts.AccountAuthenticator"
+ android:resource="@xml/authenticator" />
+ </service>
+ <service android:name="github.daneren2005.dsub.service.sync.SyncService"
+ android:exported="true"
+ android:process=":sync">
+
+ <intent-filter>com.example.android.datasync.provider
+ <action android:name="android.content.SyncAdapter"/>
+ </intent-filter>
+ <meta-data android:name="android.content.SyncAdapter"
+ android:resource="@xml/syncadapter" />
+ </service>
<receiver android:name="github.daneren2005.dsub.receiver.MediaButtonIntentReceiver">
<intent-filter android:priority="999">
@@ -136,6 +158,10 @@
<provider android:name="github.daneren2005.dsub.provider.DSubSearchProvider"
android:authorities="github.daneren2005.dsub.provider.DSubSearchProvider"/>
+ <provider android:name="github.daneren2005.dsub.service.sync.StubProvider"
+ android:authorities="github.daneren2005.dsub.provider"
+ android:exported="false"
+ android:syncable="true"/>
<meta-data android:name="android.app.default_searchable"
android:value="github.daneren2005.dsub.activity.QueryReceiverActivity"/>
diff --git a/res/xml/authenticator.xml b/res/xml/authenticator.xml
new file mode 100644
index 00000000..ce62b117
--- /dev/null
+++ b/res/xml/authenticator.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<account-authenticator
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:accountType="subsonic.org"
+ android:icon="@drawable/launch"
+ android:smallIcon="@drawable/launch"
+ android:label="@string/common.appname"/> \ No newline at end of file
diff --git a/res/xml/syncadapter.xml b/res/xml/syncadapter.xml
new file mode 100644
index 00000000..da7b85f7
--- /dev/null
+++ b/res/xml/syncadapter.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
+ android:contentAuthority="github.daneren2005.dsub.provider"
+ android:accountType="subsonic.org"
+ android:userVisible="true"
+ android:supportsUploading="false"
+ android:allowParallelSyncs="false"
+ android:isAlwaysSyncable="true"/> \ No newline at end of file
diff --git a/src/github/daneren2005/dsub/activity/MainActivity.java b/src/github/daneren2005/dsub/activity/MainActivity.java
index 8aa68b3d..042fde94 100644
--- a/src/github/daneren2005/dsub/activity/MainActivity.java
+++ b/src/github/daneren2005/dsub/activity/MainActivity.java
@@ -1,6 +1,9 @@
package github.daneren2005.dsub.activity;
+import android.accounts.Account;
+import android.accounts.AccountManager;
import android.app.AlertDialog;
+import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
@@ -61,6 +64,7 @@ public class MainActivity extends SubsonicActivity {
}
setContentView(R.layout.main);
loadSettings();
+ createAccount();
bottomBar = findViewById(R.id.bottom_bar);
bottomBar.setOnClickListener(new View.OnClickListener() {
@@ -307,6 +311,15 @@ public class MainActivity extends SubsonicActivity {
}
}
+ private void createAccount() {
+ AccountManager accountManager = (AccountManager) this.getSystemService(ACCOUNT_SERVICE);
+ Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE);
+ accountManager.addAccountExplicitly(account, null, null);
+
+ // Make sync run every hour
+ ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_TYPE, new Bundle(), 1000L * 60L * 60L);
+ }
+
private void showInfoDialog() {
if (!infoDialogDisplayed) {
infoDialogDisplayed = true;
diff --git a/src/github/daneren2005/dsub/service/sync/AuthenticatorService.java b/src/github/daneren2005/dsub/service/sync/AuthenticatorService.java
new file mode 100644
index 00000000..ae12c88e
--- /dev/null
+++ b/src/github/daneren2005/dsub/service/sync/AuthenticatorService.java
@@ -0,0 +1,90 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic 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.
+
+ Subsonic 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 Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package github.daneren2005.dsub.service.sync;
+
+import android.accounts.AbstractAccountAuthenticator;
+import android.accounts.Account;
+import android.accounts.AccountAuthenticatorResponse;
+import android.accounts.NetworkErrorException;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.IBinder;
+
+/**
+ * Created by Scott on 8/28/13.
+ */
+
+public class AuthenticatorService extends Service {
+ private SubsonicAuthenticator authenticator;
+
+ @Override
+ public void onCreate() {
+ authenticator = new SubsonicAuthenticator(this);
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return authenticator.getIBinder();
+
+ }
+
+ private class SubsonicAuthenticator extends AbstractAccountAuthenticator {
+ public SubsonicAuthenticator(Context context) {
+ super(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 {
+ return null;
+ }
+
+ @Override
+ public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public String getAuthTokenLabel(String authTokenType) {
+ return null;
+ }
+
+ @Override
+ public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException {
+ return null;
+ }
+ }
+}
diff --git a/src/github/daneren2005/dsub/service/sync/StubProvider.java b/src/github/daneren2005/dsub/service/sync/StubProvider.java
new file mode 100644
index 00000000..d04d8772
--- /dev/null
+++ b/src/github/daneren2005/dsub/service/sync/StubProvider.java
@@ -0,0 +1,61 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic 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.
+
+ Subsonic 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 Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package github.daneren2005.dsub.service.sync;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.net.Uri;
+
+/**
+ * Created by Scott on 8/28/13.
+ */
+
+public class StubProvider extends ContentProvider {
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+ return null;
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ return new String();
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues values) {
+ return null;
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ return 0;
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ return 0;
+ }
+}
diff --git a/src/github/daneren2005/dsub/service/sync/SyncAdapter.java b/src/github/daneren2005/dsub/service/sync/SyncAdapter.java
new file mode 100644
index 00000000..a063ad59
--- /dev/null
+++ b/src/github/daneren2005/dsub/service/sync/SyncAdapter.java
@@ -0,0 +1,47 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic 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.
+
+ Subsonic 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 Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package github.daneren2005.dsub.service.sync;
+
+import android.accounts.Account;
+import android.annotation.TargetApi;
+import android.content.AbstractThreadedSyncAdapter;
+import android.content.ContentProviderClient;
+import android.content.Context;
+import android.content.SyncResult;
+import android.os.Bundle;
+
+/**
+ * Created by Scott on 8/28/13.
+ */
+
+public class SyncAdapter extends AbstractThreadedSyncAdapter {
+ public SyncAdapter(Context context, boolean autoInitialize) {
+ super(context, autoInitialize);
+ }
+ @TargetApi(14)
+ public SyncAdapter(Context context, boolean autoInitialize, boolean allowParallelSyncs) {
+ super(context, autoInitialize, allowParallelSyncs);
+ }
+
+ @Override
+ public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
+
+ }
+}
diff --git a/src/github/daneren2005/dsub/service/sync/SyncService.java b/src/github/daneren2005/dsub/service/sync/SyncService.java
new file mode 100644
index 00000000..aea6069f
--- /dev/null
+++ b/src/github/daneren2005/dsub/service/sync/SyncService.java
@@ -0,0 +1,48 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic 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.
+
+ Subsonic 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 Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package github.daneren2005.dsub.service.sync;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+
+/**
+ * Created by Scott on 8/28/13.
+ */
+
+public class SyncService extends Service {
+ private static SyncAdapter playlistSyncAdapter;
+ private static final Object syncLock = new Object();
+
+ @Override
+ public void onCreate() {
+ synchronized (syncLock) {
+ if(playlistSyncAdapter == null) {
+ playlistSyncAdapter = new SyncAdapter(getApplicationContext(), true);
+ }
+ }
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return playlistSyncAdapter.getSyncAdapterBinder();
+
+ }
+}
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java
index 41e13b2f..d1bd6958 100644
--- a/src/github/daneren2005/dsub/util/Constants.java
+++ b/src/github/daneren2005/dsub/util/Constants.java
@@ -140,6 +140,10 @@ public final class Constants {
public static final String OFFLINE_SYNC_NAME = "github.daneren2005.dsub.offline";
public static final String OFFLINE_SYNC_DEFAULT = "syncDefaults";
+ // Account prefs
+ public static final String SYNC_ACCOUNT_NAME = "Subsonic Account";
+ public static final String SYNC_ACCOUNT_TYPE = "subsonic.org";
+
// Number of free trial days for non-licensed servers.
public static final int FREE_TRIAL_DAYS = 30;