rpicms-android

Android app for the RPICMS.
git clone git://archive.git.mtrnord.blog/RpicmsTeam/rpicms-android.git
Log | Files | Refs

GenericAccountService.java (4734B)


      1 package de.nordgedanken.rpicms.common.accounts;
      2 
      3 /**
      4  * Created by frank on 13.10.14.
      5  */
      6 import android.accounts.AbstractAccountAuthenticator;
      7 import android.accounts.Account;
      8 import android.accounts.AccountAuthenticatorResponse;
      9 import android.accounts.NetworkErrorException;
     10 import android.app.Service;
     11 import android.content.Context;
     12 import android.content.Intent;
     13 import android.os.Bundle;
     14 import android.os.IBinder;
     15 import android.util.Log;
     16 public class GenericAccountService extends Service {
     17 
     18 
     19 
     20         private static final String TAG = "GenericAccountService";
     21         public static final String ACCOUNT_NAME = "Account";
     22         private Authenticator mAuthenticator;
     23 
     24         /**
     25          * Obtain a handle to the {@link android.accounts.Account} used for sync in this application.
     26          *
     27          * <p>It is important that the accountType specified here matches the value in your sync adapter
     28          * configuration XML file for android.accounts.AccountAuthenticator (often saved in
     29          * res/xml/syncadapter.xml). If this is not set correctly, you'll receive an error indicating
     30          * that "caller uid XXXXX is different than the authenticator's uid".
     31          *
     32          * @param accountType AccountType defined in the configuration XML file for
     33          *                    android.accounts.AccountAuthenticator (e.g. res/xml/syncadapter.xml).
     34          * @return Handle to application's account (not guaranteed to resolve unless CreateSyncAccount()
     35          *         has been called)
     36          */
     37         public static Account GetAccount(String accountType) {
     38             // Note: Normally the account name is set to the user's identity (username or email
     39             // address). However, since we aren't actually using any user accounts, it makes more sense
     40             // to use a generic string in this case.
     41             //
     42             // This string should *not* be localized. If the user switches locale, we would not be
     43             // able to locate the old account, and may erroneously register multiple accounts.
     44             final String accountName = ACCOUNT_NAME;
     45             return new Account(accountName, accountType);
     46         }
     47 
     48         @Override
     49         public void onCreate() {
     50             Log.i(TAG, "Service created");
     51             mAuthenticator = new Authenticator(this);
     52         }
     53 
     54         @Override
     55         public void onDestroy() {
     56             Log.i(TAG, "Service destroyed");
     57         }
     58 
     59         @Override
     60         public IBinder onBind(Intent intent) {
     61             return mAuthenticator.getIBinder();
     62         }
     63 
     64         public class Authenticator extends AbstractAccountAuthenticator {
     65             public Authenticator(Context context) {
     66                 super(context);
     67             }
     68 
     69             @Override
     70             public Bundle editProperties(AccountAuthenticatorResponse accountAuthenticatorResponse,
     71                                          String s) {
     72                 throw new UnsupportedOperationException();
     73             }
     74 
     75             @Override
     76             public Bundle addAccount(AccountAuthenticatorResponse accountAuthenticatorResponse,
     77                                      String s, String s2, String[] strings, Bundle bundle)
     78                     throws NetworkErrorException {
     79                 return null;
     80             }
     81 
     82             @Override
     83             public Bundle confirmCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse,
     84                                              Account account, Bundle bundle)
     85                     throws NetworkErrorException {
     86                 return null;
     87             }
     88 
     89             @Override
     90             public Bundle getAuthToken(AccountAuthenticatorResponse accountAuthenticatorResponse,
     91                                        Account account, String s, Bundle bundle)
     92                     throws NetworkErrorException {
     93                 throw new UnsupportedOperationException();
     94             }
     95 
     96             @Override
     97             public String getAuthTokenLabel(String s) {
     98                 throw new UnsupportedOperationException();
     99             }
    100 
    101             @Override
    102             public Bundle updateCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse,
    103                                             Account account, String s, Bundle bundle)
    104                     throws NetworkErrorException {
    105                 throw new UnsupportedOperationException();
    106             }
    107 
    108             @Override
    109             public Bundle hasFeatures(AccountAuthenticatorResponse accountAuthenticatorResponse,
    110                                       Account account, String[] strings)
    111                     throws NetworkErrorException {
    112                 throw new UnsupportedOperationException();
    113             }
    114         }
    115 
    116 
    117 }