Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 190b7573 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 611

* changes:
  change the IsolatedContext to have a test version of the AccountManager that has no IBinder to the AccountManagerService.
parents f0c70a83 0eabf022
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -67,6 +67,15 @@ public class AccountManager {
        mMainHandler = new Handler(mContext.getMainLooper());
        mMainHandler = new Handler(mContext.getMainLooper());
    }
    }


    /**
     * @hide used for testing only
     */
    public AccountManager(Context context, IAccountManager service, Handler handler) {
        mContext = context;
        mService = service;
        mMainHandler = handler;
    }

    public static AccountManager get(Context context) {
    public static AccountManager get(Context context) {
        return (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
        return (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    }
    }
+20 −1
Original line number Original line Diff line number Diff line
@@ -2,6 +2,8 @@ package android.test;


import com.google.android.collect.Lists;
import com.google.android.collect.Lists;


import android.accounts.AccountManager;
import android.accounts.OnAccountsUpdatedListener;
import android.content.ContextWrapper;
import android.content.ContextWrapper;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.Intent;
@@ -11,6 +13,8 @@ import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;


import java.util.List;
import java.util.List;


@@ -21,6 +25,7 @@ import java.util.List;
public class IsolatedContext extends ContextWrapper {
public class IsolatedContext extends ContextWrapper {


    private ContentResolver mResolver;
    private ContentResolver mResolver;
    private final MockAccountManager mMockAccountManager;


    private List<Intent> mBroadcastIntents = Lists.newArrayList();
    private List<Intent> mBroadcastIntents = Lists.newArrayList();


@@ -28,6 +33,7 @@ public class IsolatedContext extends ContextWrapper {
            ContentResolver resolver, Context targetContext) {
            ContentResolver resolver, Context targetContext) {
        super(targetContext);
        super(targetContext);
        mResolver = resolver;
        mResolver = resolver;
        mMockAccountManager = new MockAccountManager();
    }
    }


    /** Returns the list of intents that were broadcast since the last call to this method. */
    /** Returns the list of intents that were broadcast since the last call to this method. */
@@ -78,8 +84,21 @@ public class IsolatedContext extends ContextWrapper {


    @Override
    @Override
    public Object getSystemService(String name) {
    public Object getSystemService(String name) {
        // No services exist in this context.
        if (Context.ACCOUNT_SERVICE.equals(name)) {
            return mMockAccountManager;
        }
        // No other services exist in this context.
        return null;
        return null;
    }
    }


    private class MockAccountManager extends AccountManager {
        public MockAccountManager() {
            super(IsolatedContext.this, null /* IAccountManager */, null /* handler */);
        }

        public void addOnAccountsUpdatedListener(OnAccountsUpdatedListener listener,
                Handler handler, boolean updateImmediately) {
            // do nothing
        }
    }
}
}