diff options
author | Changfei Chen <changfeichen@google.com> | 2016-10-03 18:52:38 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-10-03 18:52:38 +0000 |
commit | b352779394abb8c552def622a60c17129609ad05 (patch) | |
tree | e3e8160312182e131e814c32b1eb07cd8d2f5ba6 | |
parent | be7f2196724ef097c17284ff2edcfd3786a19e8f (diff) | |
parent | edb05a3b7cd731bfd6ae9f626865ee2335438999 (diff) | |
download | platform_testing-b352779394abb8c552def622a60c17129609ad05.tar.gz |
Merge "Refactor account logic from util and move it into the app helper library." into nyc-mr1-dev
4 files changed, 15 insertions, 84 deletions
diff --git a/libraries/base-app-helpers/Android.mk b/libraries/base-app-helpers/Android.mk index ce06cc53e..0111a0a25 100644 --- a/libraries/base-app-helpers/Android.mk +++ b/libraries/base-app-helpers/Android.mk @@ -17,7 +17,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := base-app-helpers -LOCAL_STATIC_JAVA_LIBRARIES := account-util dpad-util +LOCAL_STATIC_JAVA_LIBRARIES := dpad-util LOCAL_JAVA_LIBRARIES := ub-uiautomator launcher-helper-lib LOCAL_SRC_FILES := $(call all-java-files-under, src) diff --git a/libraries/base-app-helpers/src/android/platform/test/helpers/AbstractStandardAppHelper.java b/libraries/base-app-helpers/src/android/platform/test/helpers/AbstractStandardAppHelper.java index 91586dbd6..ea8e46a6c 100644 --- a/libraries/base-app-helpers/src/android/platform/test/helpers/AbstractStandardAppHelper.java +++ b/libraries/base-app-helpers/src/android/platform/test/helpers/AbstractStandardAppHelper.java @@ -16,7 +16,10 @@ package android.platform.test.helpers; +import android.accounts.Account; +import android.accounts.AccountManager; import android.app.Instrumentation; +import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -25,7 +28,6 @@ import android.support.test.launcherhelper.ILauncherStrategy; import android.support.test.launcherhelper.LauncherStrategyFactory; import android.support.test.uiautomator.By; import android.support.test.uiautomator.UiDevice; -import android.test.util.account.AccountUtil; public abstract class AbstractStandardAppHelper implements IStandardAppHelper { public UiDevice mDevice; @@ -99,10 +101,6 @@ public abstract class AbstractStandardAppHelper implements IStandardAppHelper { return mInstrumentation.getContext().getResources().getConfiguration().orientation; } - protected boolean hasRegisteredGoogleAccount() { - return AccountUtil.hasRegisteredGoogleAccount(); - } - protected void requiresGoogleAccount() { if (!hasRegisteredGoogleAccount()) { throw new AccountException("This method requires a Google account be registered."); @@ -114,4 +112,15 @@ public abstract class AbstractStandardAppHelper implements IStandardAppHelper { throw new AccountException("This method requires no Google account be registered."); } } + + protected boolean hasRegisteredGoogleAccount() { + Context context = mInstrumentation.getContext(); + Account[] accounts = AccountManager.get(context).getAccounts(); + for (int i = 0; i < accounts.length; ++i) { + if (accounts[i].type.equals("com.google")) { + return true; + } + } + return false; + } } diff --git a/utils/account/Android.mk b/utils/account/Android.mk deleted file mode 100644 index e0a203489..000000000 --- a/utils/account/Android.mk +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (C) 2016 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. -# -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) -LOCAL_MODULE := account-util -LOCAL_JAVA_LIBRARIES := android-support-test -LOCAL_SRC_FILES := $(call all-java-files-under, src) - -include $(BUILD_STATIC_JAVA_LIBRARY) diff --git a/utils/account/src/android/test/util/account/AccountUtil.java b/utils/account/src/android/test/util/account/AccountUtil.java deleted file mode 100644 index a67841646..000000000 --- a/utils/account/src/android/test/util/account/AccountUtil.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2016 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 android.test.util.account; - -import android.accounts.Account; -import android.accounts.AccountManager; -import android.content.Context; -import android.support.test.InstrumentationRegistry; - -/** - * An open-source Android account utility used for instrumentation tests. - */ -public class AccountUtil { - /** - * @return a list of the registered accounts on the device - */ - public static Account[] getRegisteredAccounts() { - Context context = InstrumentationRegistry.getContext(); - return AccountManager.get(context).getAccounts(); - } - - /** - * @return a Google-registered account, if there is one or more, or null otherwise - */ - public static String getRegisteredGoogleAccount() { - Account[] accounts = getRegisteredAccounts(); - for (int i = 0; i < accounts.length; ++i) { - if (accounts[i].type.equals("com.google")) { - return accounts[i].name; - } - } - return null; - } - - /** - * @return true if there is a Google-registered account on the device - */ - public static boolean hasRegisteredGoogleAccount() { - return (getRegisteredGoogleAccount() != null); - } -} |