<meta-data android:name="com.android.settings.summary" android:resource="@string/manufacturer_settings_summary" />
<meta-data android:name="com.android.settings.icon" android:resource="@drawable/ic_settings_applications" />
</activity>
+
+ <service android:name="com.android.settings.accounts.TestAuthService">
+ <intent-filter>
+ <action android:name="android.accounts.AccountAuthenticator" />
+ </intent-filter>
+ <meta-data android:name="android.accounts.AccountAuthenticator"
+ android:resource="@xml/authenticator" />
+ </service>
+
</application>
<instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
<string name="manufacturer_hello" translatable="false">Hello Manufacturer!</string>
<string name="manufacturer_settings_title" translatable="false">Manufacturer</string>
<string name="manufacturer_settings_summary" translatable="false">Manufacturer hook that can be used to start activity of choice</string>
+ <string name="account_auth_label" translatable="false">Settings Test Account</string>
+ <string name="account_type" translatable="false">com.settingstest.account-prefs</string>
+ <string name="account_pref_title" translatable="false">Test preference for external account</string>
</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <SwitchPreference
+ android:key="account_test_switch"
+ android:title="@string/account_pref_title" />
+
+</PreferenceScreen>
+
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<account-authenticator
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:label="@string/account_auth_label"
+ android:icon="@drawable/ic_settings_applications"
+ android:accountType="@string/account_type"
+ android:accountPreferences="@xml/account_preferences" />
+
--- /dev/null
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.accounts;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.content.Context;
+import android.content.Intent;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject;
+import android.support.test.uiautomator.UiSelector;
+import android.support.test.uiautomator.UiScrollable;
+import android.support.test.uiautomator.UiObjectNotFoundException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class AccountsSettingsTest {
+
+ private static final String ACCOUNTS = "Accounts";
+ private static final String ACCOUNT_TYPE = "com.settingstest.account-prefs";
+ private static final String PREF_TITLE = "Test preference for external account";
+
+ private UiDevice mDevice;
+ private Context mContext;
+ private String mTargetPackage;
+
+ @Before
+ public void setUp() {
+ mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ mContext = InstrumentationRegistry.getTargetContext();
+ mTargetPackage = mContext.getPackageName();
+ }
+
+ @Test
+ public void testExternalAccountInfoExists() throws UiObjectNotFoundException {
+ // add a test account
+ final String testAccountName = "Test Account";
+ final Account account = new Account(testAccountName, ACCOUNT_TYPE);
+ final AccountManager accountManager = AccountManager.get(mContext);
+ final boolean accountAdded =
+ accountManager.addAccountExplicitly(account, null /* password */, null /* userdata */);
+ assertThat(accountAdded).isTrue();
+
+ // launch Accounts Settings and select the test account
+ launchAccountsSettings();
+ mDevice.findObject(new UiSelector().text(testAccountName)).click();
+ final UiObject testPreference = mDevice.findObject(new UiSelector().text(PREF_TITLE));
+ // remove test account
+ accountManager.removeAccountExplicitly(account);
+
+ assertThat(testPreference.exists()).isTrue();
+ }
+
+ private void launchAccountsSettings() throws UiObjectNotFoundException {
+ // launch settings
+ Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
+ .addCategory(Intent.CATEGORY_LAUNCHER)
+ .setPackage(mTargetPackage)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ mContext.startActivity(settingsIntent);
+ // selects Accounts
+ final UiScrollable settings = new UiScrollable(
+ new UiSelector().packageName(mTargetPackage).scrollable(true));
+ final String titleAccounts = ACCOUNTS;
+ settings.scrollTextIntoView(titleAccounts);
+ mDevice.findObject(new UiSelector().text(titleAccounts)).click();
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.accounts;
+
+import android.accounts.AbstractAccountAuthenticator;
+import android.accounts.Account;
+import android.accounts.AccountAuthenticatorResponse;
+import android.accounts.AccountManager;
+import android.accounts.NetworkErrorException;
+import android.content.Context;
+import android.os.Bundle;
+
+public class Authenticator extends AbstractAccountAuthenticator {
+
+ public Authenticator(Context context) {
+ super(context);
+ }
+
+ @Override
+ public Bundle editProperties(AccountAuthenticatorResponse r, String s) {
+ return null;
+ }
+
+ @Override
+ public Bundle addAccount(AccountAuthenticatorResponse r, String s, String s2, String[] strings,
+ Bundle bundle) throws NetworkErrorException {
+ final Bundle result = new Bundle();
+ result.putString(AccountManager.KEY_ACCOUNT_NAME, "Test Account");
+ result.putString(AccountManager.KEY_ACCOUNT_TYPE, s);
+ return result;
+ }
+
+ @Override
+ public Bundle confirmCredentials(AccountAuthenticatorResponse r, Account account, Bundle bundle)
+ throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public Bundle getAuthToken(AccountAuthenticatorResponse r, Account account, String s,
+ Bundle bundle) throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public String getAuthTokenLabel(String s) {
+ return s;
+ }
+
+ @Override
+ public Bundle updateCredentials(AccountAuthenticatorResponse r, Account account, String s,
+ Bundle bundle) throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public Bundle hasFeatures(AccountAuthenticatorResponse r, Account account, String[] strings)
+ throws NetworkErrorException {
+ return null;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.accounts;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+
+public class TestAuthService extends Service {
+
+ private Authenticator mAuthenticator;
+
+ @Override
+ public void onCreate() {
+ mAuthenticator = new Authenticator(this);
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return mAuthenticator.getIBinder();
+ }
+
+}