fix: 引入Settings的Module
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 com.android.settings;
|
||||
|
||||
import static com.android.settings.UserCredentialsSettings.Credential;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Process;
|
||||
import android.test.InstrumentationTestCase;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
/**
|
||||
* User credentials settings fragment tests
|
||||
*
|
||||
* To run the test, use command:
|
||||
* adb shell am instrument -e class com.android.settings.UserCredentialsTest
|
||||
* -w com.android.settings.tests.unit/androidx.test.runner.AndroidJUnitRunner
|
||||
*
|
||||
*/
|
||||
public class UserCredentialsTest extends InstrumentationTestCase {
|
||||
private static final String TAG = "UserCredentialsTests";
|
||||
|
||||
@SmallTest
|
||||
public void testCredentialIsParcelable() {
|
||||
final String alias = "credential-test-alias";
|
||||
Credential c = new Credential(alias, Process.SYSTEM_UID);
|
||||
|
||||
c.storedTypes.add(Credential.Type.CA_CERTIFICATE);
|
||||
c.storedTypes.add(Credential.Type.USER_KEY);
|
||||
|
||||
Parcel p = Parcel.obtain();
|
||||
c.writeToParcel(p, /* flags */ 0);
|
||||
p.setDataPosition(0);
|
||||
|
||||
Credential r = Credential.CREATOR.createFromParcel(p);
|
||||
assertEquals(c.alias, r.alias);
|
||||
assertEquals(c.uid, r.uid);
|
||||
assertEquals(c.storedTypes, r.storedTypes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 com.android.settings;
|
||||
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class UtilsTest extends AndroidTestCase {
|
||||
private static final int TEST_PRIMARY_USER_ID = 10;
|
||||
private static final int TEST_MANAGED_PROFILE_ID = 11;
|
||||
|
||||
@Mock private UserManager mUserManager;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
// // this is necessary for mockito to work
|
||||
System.setProperty("dexmaker.dexcache", getContext().getCacheDir().toString());
|
||||
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mUserManager.getUserHandle()).thenReturn(TEST_PRIMARY_USER_ID);
|
||||
UserInfo primaryUser = new UserInfo(TEST_PRIMARY_USER_ID, null,
|
||||
UserInfo.FLAG_INITIALIZED | UserInfo.FLAG_PRIMARY);
|
||||
when(mUserManager.getUserInfo(TEST_PRIMARY_USER_ID)).thenReturn(primaryUser);
|
||||
UserInfo managedProfile = new UserInfo(TEST_MANAGED_PROFILE_ID, null,
|
||||
UserInfo.FLAG_INITIALIZED | UserInfo.FLAG_MANAGED_PROFILE);
|
||||
when(mUserManager.getUserInfo(eq(TEST_MANAGED_PROFILE_ID))).thenReturn(managedProfile);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testGetManagedProfile() {
|
||||
UserHandle[] userHandles = new UserHandle[] {
|
||||
new UserHandle(TEST_PRIMARY_USER_ID),
|
||||
new UserHandle(TEST_MANAGED_PROFILE_ID)
|
||||
};
|
||||
when(mUserManager.getUserProfiles())
|
||||
.thenReturn(new ArrayList<UserHandle>(Arrays.asList(userHandles)));
|
||||
assertEquals(TEST_MANAGED_PROFILE_ID,
|
||||
Utils.getManagedProfile(mUserManager).getIdentifier());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testGetManagedProfile_notPresent() {
|
||||
UserHandle[] userHandles = new UserHandle[] {
|
||||
new UserHandle(TEST_PRIMARY_USER_ID)
|
||||
};
|
||||
when(mUserManager.getUserProfiles())
|
||||
.thenReturn(new ArrayList<UserHandle>(Arrays.asList(userHandles)));
|
||||
assertNull(Utils.getManagedProfile(mUserManager));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.accessibility;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.Settings.AccessibilitySettingsActivity;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ToggleFeaturePreferenceFragmentTest {
|
||||
private static final String SUMMARY_TEXT = "Here's some summary text";
|
||||
|
||||
@Rule
|
||||
public final ActivityTestRule<AccessibilitySettingsActivity> mActivityRule =
|
||||
new ActivityTestRule<>(AccessibilitySettingsActivity.class, true);
|
||||
|
||||
private final Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
|
||||
@BeforeClass
|
||||
public static void oneTimeSetup() {
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mInstrumentation.runOnMainSync(() -> {
|
||||
MyToggleFeaturePreferenceFragment fragment = new MyToggleFeaturePreferenceFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(AccessibilitySettings.EXTRA_SUMMARY, SUMMARY_TEXT);
|
||||
fragment.setArguments(args);
|
||||
new SubSettingLauncher(mActivityRule.getActivity())
|
||||
.setDestination(MyToggleFeaturePreferenceFragment.class.getName())
|
||||
.setArguments(args)
|
||||
.setSourceMetricsCategory(
|
||||
InstrumentedPreferenceFragment.METRICS_CATEGORY_UNKNOWN)
|
||||
.launch();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryTestDisplayed() {
|
||||
onView(withText(SUMMARY_TEXT)).check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
public static class MyToggleFeaturePreferenceFragment extends ToggleFeaturePreferenceFragment {
|
||||
@Override
|
||||
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
int getUserShortcutTypes() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.uiautomator.UiDevice;
|
||||
import android.support.test.uiautomator.UiObject;
|
||||
import android.support.test.uiautomator.UiObjectNotFoundException;
|
||||
import android.support.test.uiautomator.UiScrollable;
|
||||
import android.support.test.uiautomator.UiSelector;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.applications.manageapplications;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.content.pm.ApplicationInfo;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppFilter;
|
||||
import com.android.settingslib.applications.ApplicationsState.CompoundFilter;
|
||||
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ManageApplicationsUnitTest {
|
||||
@Test
|
||||
public void getCompositeFilter_filtersVolumeForAudio() {
|
||||
AppFilter filter =
|
||||
ManageApplications.getCompositeFilter(
|
||||
ManageApplications.LIST_TYPE_STORAGE,
|
||||
ManageApplications.STORAGE_TYPE_MUSIC,
|
||||
"uuid");
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.volumeUuid = "uuid";
|
||||
info.category = ApplicationInfo.CATEGORY_AUDIO;
|
||||
final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
|
||||
appEntry.info = info;
|
||||
|
||||
assertThat(filter.filterApp(appEntry)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCompositeFilter_filtersVolumeForVideo() {
|
||||
AppFilter filter =
|
||||
ManageApplications.getCompositeFilter(
|
||||
ManageApplications.LIST_TYPE_MOVIES,
|
||||
ManageApplications.STORAGE_TYPE_DEFAULT,
|
||||
"uuid");
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.volumeUuid = "uuid";
|
||||
info.category = ApplicationInfo.CATEGORY_VIDEO;
|
||||
final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
|
||||
appEntry.info = info;
|
||||
|
||||
assertThat(filter.filterApp(appEntry)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCompositeFilter_filtersVolumeForGames() {
|
||||
ApplicationsState.AppFilter filter =
|
||||
ManageApplications.getCompositeFilter(
|
||||
ManageApplications.LIST_TYPE_GAMES,
|
||||
ManageApplications.STORAGE_TYPE_DEFAULT,
|
||||
"uuid");
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.volumeUuid = "uuid";
|
||||
info.category = ApplicationInfo.CATEGORY_GAME;
|
||||
final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
|
||||
appEntry.info = info;
|
||||
|
||||
assertThat(filter.filterApp(appEntry)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCompositeFilter_isEmptyNormally() {
|
||||
ApplicationsState.AppFilter filter =
|
||||
ManageApplications.getCompositeFilter(
|
||||
ManageApplications.LIST_TYPE_MAIN,
|
||||
ManageApplications.STORAGE_TYPE_DEFAULT,
|
||||
"uuid");
|
||||
assertThat(filter).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCompositeFilter_worksWithInstantApps() throws Exception {
|
||||
Field field = AppUtils.class.getDeclaredField("sInstantAppDataProvider");
|
||||
field.setAccessible(true);
|
||||
field.set(AppUtils.class, (InstantAppDataProvider) (i -> true));
|
||||
|
||||
AppFilter filter =
|
||||
ManageApplications.getCompositeFilter(
|
||||
ManageApplications.LIST_TYPE_STORAGE,
|
||||
ManageApplications.STORAGE_TYPE_MUSIC,
|
||||
"uuid");
|
||||
AppFilter composedFilter = new CompoundFilter(ApplicationsState.FILTER_INSTANT, filter);
|
||||
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.volumeUuid = "uuid";
|
||||
info.category = ApplicationInfo.CATEGORY_AUDIO;
|
||||
info.privateFlags = ApplicationInfo.PRIVATE_FLAG_INSTANT;
|
||||
final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
|
||||
appEntry.info = info;
|
||||
|
||||
assertThat(composedFilter.filterApp(appEntry)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCompositeFilter_worksForLegacyPrivateSettings() throws Exception {
|
||||
ApplicationsState.AppFilter filter =
|
||||
ManageApplications.getCompositeFilter(
|
||||
ManageApplications.LIST_TYPE_STORAGE,
|
||||
ManageApplications.STORAGE_TYPE_LEGACY,
|
||||
"uuid");
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.volumeUuid = "uuid";
|
||||
info.category = ApplicationInfo.CATEGORY_GAME;
|
||||
final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
|
||||
appEntry.info = info;
|
||||
|
||||
assertThat(filter.filterApp(appEntry)).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.backup;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class BackupIntentTest {
|
||||
private static final String INTENT_PRIVACY_SETTINGS = "android.settings.PRIVACY_SETTINGS";
|
||||
private static final String BACKUP_SETTINGS_ACTIVITY =
|
||||
"com.android.settings.Settings$PrivacyDashboardActivity";
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
mContext = instrumentation.getTargetContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrivacySettingsIntentResolvesToOnlyOneActivity(){
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
Intent intent = new Intent(INTENT_PRIVACY_SETTINGS);
|
||||
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
|
||||
assertThat(activities).isNotNull();
|
||||
assertThat(activities.size()).isEqualTo(1);
|
||||
assertThat(activities.get(0).activityInfo.getComponentName().getClassName()).
|
||||
isEqualTo(BACKUP_SETTINGS_ACTIVITY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.bluetooth;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.text.InputFilter;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
public class Utf8ByteLengthFilterTest extends AndroidTestCase {
|
||||
|
||||
@SmallTest
|
||||
public void testFilter() {
|
||||
// Define the variables
|
||||
CharSequence source;
|
||||
SpannableStringBuilder dest;
|
||||
// Constructor to create a LengthFilter
|
||||
InputFilter lengthFilter = new Utf8ByteLengthFilter(10);
|
||||
InputFilter[] filters = {lengthFilter};
|
||||
|
||||
// filter() implicitly invoked. If the total length > filter length, the filter will
|
||||
// cut off the source CharSequence from beginning to fit the filter length.
|
||||
source = "abc";
|
||||
dest = new SpannableStringBuilder("abcdefgh");
|
||||
dest.setFilters(filters);
|
||||
|
||||
dest.insert(1, source);
|
||||
String expectedString1 = "aabbcdefgh";
|
||||
assertEquals(expectedString1, dest.toString());
|
||||
|
||||
dest.replace(5, 8, source);
|
||||
String expectedString2 = "aabbcabcgh";
|
||||
assertEquals(expectedString2, dest.toString());
|
||||
|
||||
dest.insert(2, source);
|
||||
assertEquals(expectedString2, dest.toString());
|
||||
|
||||
dest.delete(1, 3);
|
||||
String expectedString3 = "abcabcgh";
|
||||
assertEquals(expectedString3, dest.toString());
|
||||
|
||||
dest.append("12345");
|
||||
String expectedString4 = "abcabcgh12";
|
||||
assertEquals(expectedString4, dest.toString());
|
||||
|
||||
source = "\u60a8\u597d"; // 2 Chinese chars == 6 bytes in UTF-8
|
||||
dest.replace(8, 10, source);
|
||||
assertEquals(expectedString3, dest.toString());
|
||||
|
||||
dest.replace(0, 1, source);
|
||||
String expectedString5 = "\u60a8bcabcgh";
|
||||
assertEquals(expectedString5, dest.toString());
|
||||
|
||||
dest.replace(0, 4, source);
|
||||
String expectedString6 = "\u60a8\u597dbcgh";
|
||||
assertEquals(expectedString6, dest.toString());
|
||||
|
||||
source = "\u00a3\u00a5"; // 2 Latin-1 chars == 4 bytes in UTF-8
|
||||
dest.delete(2, 6);
|
||||
dest.insert(0, source);
|
||||
String expectedString7 = "\u00a3\u00a5\u60a8\u597d";
|
||||
assertEquals(expectedString7, dest.toString());
|
||||
|
||||
dest.replace(2, 3, source);
|
||||
String expectedString8 = "\u00a3\u00a5\u00a3\u597d";
|
||||
assertEquals(expectedString8, dest.toString());
|
||||
|
||||
dest.replace(3, 4, source);
|
||||
String expectedString9 = "\u00a3\u00a5\u00a3\u00a3\u00a5";
|
||||
assertEquals(expectedString9, dest.toString());
|
||||
|
||||
// filter() explicitly invoked
|
||||
dest = new SpannableStringBuilder("abcdefgh");
|
||||
CharSequence beforeFilterSource = "TestLengthFilter";
|
||||
String expectedAfterFilter = "TestLength";
|
||||
CharSequence actualAfterFilter = lengthFilter.filter(beforeFilterSource, 0,
|
||||
beforeFilterSource.length(), dest, 0, dest.length());
|
||||
assertEquals(expectedAfterFilter, actualAfterFilter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.core;
|
||||
|
||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.support.test.uiautomator.By;
|
||||
import android.support.test.uiautomator.Direction;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.support.test.uiautomator.UiObject2;
|
||||
import android.support.test.uiautomator.Until;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.development.featureflags.FeatureFlagsDashboard;
|
||||
import com.android.settingslib.core.instrumentation.Instrumentable;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class LifecycleEventHandlingTest {
|
||||
|
||||
private static final long TIMEOUT = 2000;
|
||||
|
||||
private Context mContext;
|
||||
private String mTargetPackage;
|
||||
private UiDevice mDevice;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||
mDevice.wakeUp();
|
||||
mDevice.executeShellCommand("wm dismiss-keyguard");
|
||||
mContext = InstrumentationRegistry.getTargetContext();
|
||||
mTargetPackage = mContext.getPackageName();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Presubmit
|
||||
@Ignore("b/133334887")
|
||||
public void launchDashboard_shouldSeeFooter() {
|
||||
new SubSettingLauncher(mContext)
|
||||
.setDestination(FeatureFlagsDashboard.class.getName())
|
||||
.setSourceMetricsCategory(Instrumentable.METRICS_CATEGORY_UNKNOWN)
|
||||
.addFlags(FLAG_ACTIVITY_NEW_TASK)
|
||||
.launch();
|
||||
|
||||
final String footerText = "Experimental";
|
||||
// Scroll to bottom
|
||||
final UiObject2 view = mDevice.wait(
|
||||
Until.findObject(By.res(mTargetPackage, "main_content")),
|
||||
TIMEOUT);
|
||||
view.scroll(Direction.DOWN, 100f);
|
||||
|
||||
assertThat(mDevice.wait(Until.findObject(By.text(footerText)), TIMEOUT))
|
||||
.isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 com.android.settings.dashboard;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
|
||||
/***
|
||||
* Matches on the first view with id if there are multiple views using the same Id.
|
||||
*/
|
||||
public class FirstIdViewMatcher {
|
||||
|
||||
public static Matcher<View> withFirstId(final int id) {
|
||||
return new TypeSafeMatcher<View>() {
|
||||
Resources resources = null;
|
||||
private boolean mMatched;
|
||||
|
||||
public void describeTo(Description description) {
|
||||
String idDescription = Integer.toString(id);
|
||||
if (resources != null) {
|
||||
try {
|
||||
idDescription = resources.getResourceName(id);
|
||||
} catch (Resources.NotFoundException e) {
|
||||
// No big deal, will just use the int value.
|
||||
idDescription = String.format("%s (resource name not found)", id);
|
||||
}
|
||||
}
|
||||
description.appendText("with first id: " + idDescription);
|
||||
}
|
||||
|
||||
public boolean matchesSafely(View view) {
|
||||
this.resources = view.getResources();
|
||||
if (mMatched) {
|
||||
return false;
|
||||
} else {
|
||||
mMatched = id == view.getId();
|
||||
return mMatched;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 com.android.settings.dashboard;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.espresso.matcher.ViewMatchers.Visibility;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class PreferenceThemeTest {
|
||||
|
||||
private Instrumentation mInstrumentation;
|
||||
private Context mTargetContext;
|
||||
private String mTargetPackage;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
mTargetContext = mInstrumentation.getTargetContext();
|
||||
mTargetPackage = mTargetContext.getPackageName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startSetupWizardLockScreen_preferenceIconSpaceNotReserved() {
|
||||
launchSetupWizardLockScreen();
|
||||
// Icons should not be shown, and the frame should not occupy extra space.
|
||||
onView(allOf(withId(R.id.icon_frame), withEffectiveVisibility(Visibility.VISIBLE)))
|
||||
.check(doesNotExist());
|
||||
onView(withId(R.id.icon_container)).check(doesNotExist());
|
||||
}
|
||||
|
||||
private void launchSetupWizardLockScreen() {
|
||||
final Intent settingsIntent = new Intent("com.android.settings.SETUP_LOCK_SCREEN")
|
||||
.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
.setPackage(mTargetPackage)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
InstrumentationRegistry.getInstrumentation().startActivitySync(settingsIntent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.dashboard;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.MediumTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@MediumTest
|
||||
public class UiBlockerControllerTest {
|
||||
private static final long TIMEOUT = 600;
|
||||
private static final String KEY_1 = "key1";
|
||||
private static final String KEY_2 = "key2";
|
||||
|
||||
private Instrumentation mInstrumentation;
|
||||
private UiBlockerController mSyncableController;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
|
||||
mSyncableController = new UiBlockerController(Arrays.asList(KEY_1, KEY_2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void start_isSyncedReturnFalseUntilAllWorkDone() throws InterruptedException {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
mSyncableController.start(() -> latch.countDown());
|
||||
|
||||
// Return false at first
|
||||
assertThat(mSyncableController.isBlockerFinished()).isFalse();
|
||||
|
||||
// Return false if only one job is done
|
||||
mSyncableController.countDown(KEY_1);
|
||||
assertThat(mSyncableController.isBlockerFinished()).isFalse();
|
||||
|
||||
// Return true if all jobs done
|
||||
mSyncableController.countDown(KEY_2);
|
||||
assertThat(latch.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue();
|
||||
assertThat(mSyncableController.isBlockerFinished()).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.datetime.timezone.model;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class TimeZoneDataTest {
|
||||
|
||||
private TimeZoneData mTimeZoneData;
|
||||
@Before
|
||||
public void setUp() {
|
||||
mTimeZoneData = TimeZoneData.getInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupCountryTimeZones_shouldReturnAtLeastOneTimeZoneInEveryRegion() {
|
||||
Set<String> regionIds = mTimeZoneData.getRegionIds();
|
||||
for (String regionId : regionIds) {
|
||||
FilteredCountryTimeZones countryTimeZones =
|
||||
mTimeZoneData.lookupCountryTimeZones(regionId);
|
||||
assertThat(countryTimeZones).isNotNull();
|
||||
assertThat(countryTimeZones.getTimeZoneIds().size()).isGreaterThan(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupCountryCodesForZoneId_shouldNotReturnHiddenZone() {
|
||||
/*
|
||||
Simferopol is filtered out for two reasons:
|
||||
1) because we specifically exclude it with the picker attribute, and
|
||||
2) because it's the same as Moscow after Oct 2014.
|
||||
*/
|
||||
assertThat(mTimeZoneData.lookupCountryCodesForZoneId("Europe/Simferopol").isEmpty())
|
||||
.isTrue();
|
||||
assertThat(mTimeZoneData.lookupCountryCodesForZoneId("Europe/London").isEmpty())
|
||||
.isFalse();
|
||||
assertThat(mTimeZoneData.lookupCountryCodesForZoneId("America/Los_Angeles").isEmpty())
|
||||
.isFalse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.display;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.Settings.NightDisplaySettingsActivity;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class NightDisplaySettingsActivityTest {
|
||||
|
||||
private Context mTargetContext;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
mTargetContext = instrumentation.getTargetContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightDisplaySettingsIntent_resolvesCorrectly() {
|
||||
final boolean nightDisplayAvailable = mTargetContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable);
|
||||
final PackageManager pm = mTargetContext.getPackageManager();
|
||||
final Intent intent = new Intent(Settings.ACTION_NIGHT_DISPLAY_SETTINGS);
|
||||
final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||
|
||||
if (nightDisplayAvailable) {
|
||||
Assert.assertNotNull("No activity for " + Settings.ACTION_NIGHT_DISPLAY_SETTINGS, ri);
|
||||
Assert.assertEquals(mTargetContext.getPackageName(), ri.activityInfo.packageName);
|
||||
Assert.assertEquals(NightDisplaySettingsActivity.class.getName(),
|
||||
ri.activityInfo.name);
|
||||
} else {
|
||||
Assert.assertNull("Should have no activity for "
|
||||
+ Settings.ACTION_NIGHT_DISPLAY_SETTINGS, ri);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.display;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.om.IOverlayManager;
|
||||
import android.content.om.OverlayInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ThemePreferenceControllerTest {
|
||||
|
||||
private IOverlayManager mMockOverlayManager;
|
||||
private ContextWrapper mContext;
|
||||
private ThemePreferenceController mPreferenceController;
|
||||
private PackageManager mMockPackageManager;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mMockOverlayManager = mock(IOverlayManager.class);
|
||||
mMockPackageManager = mock(PackageManager.class);
|
||||
mContext = new ContextWrapper(InstrumentationRegistry.getTargetContext()) {
|
||||
@Override
|
||||
public PackageManager getPackageManager() {
|
||||
return mMockPackageManager;
|
||||
}
|
||||
};
|
||||
mPreferenceController = new ThemePreferenceController(mContext, mMockOverlayManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState() throws Exception {
|
||||
OverlayInfo info1 = new OverlayInfo("com.android.Theme1", "android", "",
|
||||
OverlayInfo.CATEGORY_THEME, "", OverlayInfo.STATE_ENABLED, 0, 0, true);
|
||||
OverlayInfo info2 = new OverlayInfo("com.android.Theme2", "android", "",
|
||||
OverlayInfo.CATEGORY_THEME, "", 0, 0, 0, true);
|
||||
when(mMockPackageManager.getApplicationInfo(any(), anyInt())).thenAnswer(inv -> {
|
||||
ApplicationInfo info = mock(ApplicationInfo.class);
|
||||
if ("com.android.Theme1".equals(inv.getArguments()[0])) {
|
||||
when(info.loadLabel(any())).thenReturn("Theme1");
|
||||
} else {
|
||||
when(info.loadLabel(any())).thenReturn("Theme2");
|
||||
}
|
||||
return info;
|
||||
});
|
||||
when(mMockPackageManager.getPackageInfo(anyString(), anyInt())).thenReturn(
|
||||
new PackageInfo());
|
||||
when(mMockOverlayManager.getOverlayInfosForTarget(any(), anyInt())).thenReturn(
|
||||
list(info1, info2));
|
||||
ListPreference pref = mock(ListPreference.class);
|
||||
mPreferenceController.updateState(pref);
|
||||
ArgumentCaptor<String[]> arg = ArgumentCaptor.forClass(String[].class);
|
||||
verify(pref).setEntries(arg.capture());
|
||||
|
||||
|
||||
CharSequence[] entries = arg.getValue();
|
||||
assertThat(entries).asList().containsExactly("Theme1", "Theme2");
|
||||
|
||||
verify(pref).setEntryValues(arg.capture());
|
||||
CharSequence[] entryValues = arg.getValue();
|
||||
assertThat(entryValues).asList().containsExactly(
|
||||
"com.android.Theme1", "com.android.Theme2");
|
||||
|
||||
verify(pref).setValue(eq("com.android.Theme1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_withStaticOverlay() throws Exception {
|
||||
OverlayInfo info1 = new OverlayInfo("com.android.Theme1", "android", "",
|
||||
OverlayInfo.CATEGORY_THEME, "", OverlayInfo.STATE_ENABLED, 0, 0, true);
|
||||
OverlayInfo info2 = new OverlayInfo("com.android.Theme2", "android", "",
|
||||
OverlayInfo.CATEGORY_THEME, "", OverlayInfo.STATE_ENABLED, 0, 0, true);
|
||||
when(mMockPackageManager.getApplicationInfo(any(), anyInt())).thenAnswer(inv -> {
|
||||
ApplicationInfo info = mock(ApplicationInfo.class);
|
||||
if ("com.android.Theme1".equals(inv.getArguments()[0])) {
|
||||
when(info.loadLabel(any())).thenReturn("Theme1");
|
||||
} else {
|
||||
when(info.loadLabel(any())).thenReturn("Theme2");
|
||||
}
|
||||
return info;
|
||||
});
|
||||
PackageInfo pi = mock(PackageInfo.class);
|
||||
when(pi.isStaticOverlayPackage()).thenReturn(true);
|
||||
when(mMockPackageManager.getPackageInfo(eq("com.android.Theme1"), anyInt())).thenReturn(pi);
|
||||
when(mMockPackageManager.getPackageInfo(eq("com.android.Theme2"), anyInt())).thenReturn(
|
||||
new PackageInfo());
|
||||
when(mMockOverlayManager.getOverlayInfosForTarget(any(), anyInt())).thenReturn(
|
||||
list(info1, info2));
|
||||
ListPreference pref = mock(ListPreference.class);
|
||||
mPreferenceController.updateState(pref);
|
||||
ArgumentCaptor<String[]> arg = ArgumentCaptor.forClass(String[].class);
|
||||
verify(pref).setEntries(arg.capture());
|
||||
|
||||
|
||||
CharSequence[] entries = arg.getValue();
|
||||
assertThat(entries).asList().containsExactly("Theme2");
|
||||
|
||||
verify(pref).setEntryValues(arg.capture());
|
||||
CharSequence[] entryValues = arg.getValue();
|
||||
assertThat(entryValues).asList().containsExactly("com.android.Theme2");
|
||||
|
||||
verify(pref).setValue(eq("com.android.Theme2"));
|
||||
}
|
||||
|
||||
private ArrayList<OverlayInfo> list(OverlayInfo... infos) {
|
||||
ArrayList<OverlayInfo> list = new ArrayList<>();
|
||||
for (OverlayInfo info : infos) {
|
||||
list.add(info);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.homepage.contextualcards;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ContextualCardLoaderTest {
|
||||
|
||||
private static final Uri TEST_URI = Uri.parse("content://test/test");
|
||||
|
||||
private Context mContext;
|
||||
private ContextualCardLoader mContextualCardLoader;
|
||||
private EligibleCardChecker mEligibleCardChecker;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = InstrumentationRegistry.getTargetContext();
|
||||
mContextualCardLoader = new ContextualCardLoader(mContext);
|
||||
mEligibleCardChecker = new EligibleCardChecker(mContext, getContextualCard(TEST_URI));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterEligibleCards_twoInvalidCards_shouldReturnOneCard() {
|
||||
final String sliceUri1 = "content://com.android.settings.slices/action/flashlight"; //valid
|
||||
final String sliceUri2 = "content://com.android.settings.test.slices/action/flashlight";
|
||||
final String sliceUri3 = "cotent://com.android.settings.slices/action/flashlight";
|
||||
|
||||
final List<ContextualCard> cards = new ArrayList<>();
|
||||
cards.add(getContextualCard(Uri.parse(sliceUri1)));
|
||||
cards.add(getContextualCard(Uri.parse(sliceUri2)));
|
||||
cards.add(getContextualCard(Uri.parse(sliceUri3)));
|
||||
|
||||
final List<ContextualCard> result = mContextualCardLoader.filterEligibleCards(cards);
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindSlice_flashlightUri_shouldReturnFlashlightSlice() {
|
||||
final Slice loadedSlice =
|
||||
mEligibleCardChecker.bindSlice(CustomSliceRegistry.FLASHLIGHT_SLICE_URI);
|
||||
|
||||
assertThat(loadedSlice.getUri()).isEqualTo(CustomSliceRegistry.FLASHLIGHT_SLICE_URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindSlice_noProvider_shouldReturnNull() {
|
||||
final String sliceUri = "content://com.android.settings.test.slices/action/flashlight";
|
||||
|
||||
final Slice loadedSlice = mEligibleCardChecker.bindSlice(Uri.parse(sliceUri));
|
||||
|
||||
assertThat(loadedSlice).isNull();
|
||||
}
|
||||
|
||||
private ContextualCard getContextualCard(Uri sliceUri) {
|
||||
return new ContextualCard.Builder()
|
||||
.setName("test_card")
|
||||
.setRankingScore(0.5f)
|
||||
.setCardType(ContextualCard.CardType.SLICE)
|
||||
.setSliceUri(sliceUri)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.notification;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class AppBubbleNotificationSettingsTest {
|
||||
|
||||
private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
|
||||
|
||||
private UiDevice mUiDevice;
|
||||
private Context mTargetContext;
|
||||
private Instrumentation mInstrumentation;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
mTargetContext = mInstrumentation.getTargetContext();
|
||||
|
||||
mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||
mUiDevice.wakeUp();
|
||||
mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchBubbleNotificationSetting_shouldNotCrash() {
|
||||
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_BUBBLE_SETTINGS)
|
||||
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
mInstrumentation.startActivitySync(intent);
|
||||
|
||||
CharSequence name = mTargetContext.getApplicationInfo().loadLabel(
|
||||
mTargetContext.getPackageManager());
|
||||
onView(allOf(withText(name.toString()))).check(matches(isDisplayed()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.notification;
|
||||
|
||||
import static android.app.NotificationManager.IMPORTANCE_MIN;
|
||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.app.INotificationManager;
|
||||
import android.app.Instrumentation;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Process;
|
||||
import android.os.ServiceManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class ChannelNotificationSettingsTest {
|
||||
private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
|
||||
|
||||
private UiDevice mUiDevice;
|
||||
private Context mTargetContext;
|
||||
private Instrumentation mInstrumentation;
|
||||
private NotificationChannel mNotificationChannel;
|
||||
private NotificationManager mNm;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
mTargetContext = mInstrumentation.getTargetContext();
|
||||
|
||||
mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||
mUiDevice.wakeUp();
|
||||
mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
|
||||
|
||||
mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mNotificationChannel = new NotificationChannel(this.getClass().getName(),
|
||||
this.getClass().getName(), IMPORTANCE_MIN);
|
||||
mNm.createNotificationChannel(mNotificationChannel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchNotificationSetting_shouldNotCrash() {
|
||||
final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
|
||||
.putExtra(Settings.EXTRA_CHANNEL_ID, mNotificationChannel.getId())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mInstrumentation.startActivitySync(intent);
|
||||
|
||||
onView(allOf(withText(mNotificationChannel.getName().toString()))).check(
|
||||
matches(isDisplayed()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchNotificationSettings_blockedChannel() throws Exception {
|
||||
NotificationChannel blocked =
|
||||
new NotificationChannel("blocked", "blocked", IMPORTANCE_NONE);
|
||||
mNm.createNotificationChannel(blocked);
|
||||
|
||||
INotificationManager sINM = INotificationManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||
blocked.setImportance(IMPORTANCE_NONE);
|
||||
sINM.updateNotificationChannelForPackage(
|
||||
mTargetContext.getPackageName(), Process.myUid(), blocked);
|
||||
|
||||
final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
|
||||
.putExtra(Settings.EXTRA_CHANNEL_ID, blocked.getId())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mInstrumentation.startActivitySync(intent);
|
||||
|
||||
onView(allOf(withText("At your request, Android is blocking this category of notifications"
|
||||
+ " from appearing on this device"))).check(matches(isDisplayed()));
|
||||
|
||||
try {
|
||||
onView(allOf(withText("On the lock screen"))).check(matches(isDisplayed()));
|
||||
fail("settings appearing for blocked channel");
|
||||
} catch (Exception e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
# Default reviewers for this and subdirectories.
|
||||
asc@google.com
|
||||
dsandler@android.com
|
||||
juliacr@google.com
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.password;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.action.ViewActions.pressKey;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.espresso.action.ViewActions;
|
||||
import androidx.test.espresso.matcher.ViewMatchers;
|
||||
import androidx.test.filters.MediumTest;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.google.android.setupcompat.PartnerCustomizationLayout;
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@MediumTest
|
||||
public class SetupChooseLockPasswordAppTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Rule
|
||||
public ActivityTestRule<SetupChooseLockPassword> mActivityTestRule =
|
||||
new ActivityTestRule<>(
|
||||
SetupChooseLockPassword.class,
|
||||
true /* enable touch at launch */,
|
||||
false /* don't launch at every test */);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = InstrumentationRegistry.getTargetContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipDialogIsShown() throws Throwable {
|
||||
SetupChooseLockPassword activity = mActivityTestRule.launchActivity(null);
|
||||
PartnerCustomizationLayout layout = activity.findViewById(R.id.setup_wizard_layout);
|
||||
final Button skipOrClearButton =
|
||||
layout.getMixin(FooterBarMixin.class).getSecondaryButtonView();
|
||||
|
||||
assertThat(skipOrClearButton.getText()).isEqualTo(mContext.getString(R.string.skip_label));
|
||||
assertThat(skipOrClearButton.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
skipOrClearButton.performClick();
|
||||
assertWithMessage("Is finishing").that(activity.isFinishing()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearIsNotShown_when_activityLaunchedInitially() {
|
||||
SetupChooseLockPassword activity = mActivityTestRule.launchActivity(null);
|
||||
PartnerCustomizationLayout layout = activity.findViewById(R.id.setup_wizard_layout);
|
||||
assertThat(layout.getMixin(FooterBarMixin.class).getSecondaryButtonView().getText())
|
||||
.isEqualTo(mContext.getString(R.string.lockpassword_clear_label));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearIsNotShown_when_nothingEntered() throws Throwable {
|
||||
SetupChooseLockPassword activity = mActivityTestRule.launchActivity(null);
|
||||
PartnerCustomizationLayout layout = activity.findViewById(R.id.setup_wizard_layout);
|
||||
onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234"))
|
||||
.perform(pressKey(KeyEvent.KEYCODE_ENTER));
|
||||
assertThat(
|
||||
layout.getMixin(FooterBarMixin.class).getSecondaryButtonView().getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearIsShown_when_somethingEnteredToConfirm() {
|
||||
SetupChooseLockPassword activity = mActivityTestRule.launchActivity(null);
|
||||
PartnerCustomizationLayout layout = activity.findViewById(R.id.setup_wizard_layout);
|
||||
onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234"))
|
||||
.perform(pressKey(KeyEvent.KEYCODE_ENTER));
|
||||
mActivityTestRule.launchActivity(null);
|
||||
onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234"))
|
||||
.perform(pressKey(KeyEvent.KEYCODE_ENTER))
|
||||
.perform(ViewActions.typeText("1"));
|
||||
// clear should be present if text field contains content
|
||||
assertThat(
|
||||
layout.getMixin(FooterBarMixin.class).getSecondaryButtonView().getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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.print;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.print.PageRange;
|
||||
import android.print.PrintAttributes;
|
||||
import android.print.PrintDocumentAdapter;
|
||||
import android.print.PrintDocumentInfo;
|
||||
import android.print.PrintJob;
|
||||
import android.print.PrintManager;
|
||||
import android.support.test.uiautomator.By;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.support.test.uiautomator.UiObject2;
|
||||
import android.support.test.uiautomator.Until;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.LargeTest;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class PrintJobSettingsActivityTest {
|
||||
private static final String EXTRA_PRINT_JOB_ID = "EXTRA_PRINT_JOB_ID";
|
||||
private static final String LOG_TAG = PrintJobSettingsActivityTest.class.getSimpleName();
|
||||
|
||||
// Any activity is fine
|
||||
@Rule
|
||||
public final ActivityTestRule<Settings.PrintSettingsActivity> mActivityRule =
|
||||
new ActivityTestRule<>(Settings.PrintSettingsActivity.class, true);
|
||||
|
||||
public static void runShellCommand(@NonNull String cmd) throws IOException {
|
||||
ParcelFileDescriptor stdOut =
|
||||
InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(
|
||||
cmd);
|
||||
|
||||
try (FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(stdOut)) {
|
||||
byte[] buf = new byte[512];
|
||||
while (fis.read(buf) != -1) {
|
||||
// keep reading
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void requirePrintFeature() {
|
||||
assumeTrue(InstrumentationRegistry.getTargetContext().getPackageManager().hasSystemFeature(
|
||||
PackageManager.FEATURE_PRINTING));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void wakeUpScreen() throws Exception {
|
||||
runShellCommand("input keyevent KEYCODE_WAKEUP");
|
||||
}
|
||||
|
||||
@Test
|
||||
@LargeTest
|
||||
public void viewPrintJobSettings() throws Exception {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
Object isWriteCalled = new Object();
|
||||
|
||||
// Create adapter that is good enough to start a print preview
|
||||
PrintDocumentAdapter adapter = new PrintDocumentAdapter() {
|
||||
@Override
|
||||
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
|
||||
CancellationSignal cancellationSignal,
|
||||
LayoutResultCallback callback, Bundle extras) {
|
||||
callback.onLayoutFinished(new PrintDocumentInfo.Builder(uuid.toString()).build(),
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination,
|
||||
CancellationSignal cancellationSignal,
|
||||
WriteResultCallback callback) {
|
||||
synchronized (isWriteCalled) {
|
||||
isWriteCalled.notify();
|
||||
}
|
||||
callback.onWriteFailed(null);
|
||||
}
|
||||
};
|
||||
|
||||
Activity activity = mActivityRule.getActivity();
|
||||
PrintManager pm = mActivityRule.getActivity().getSystemService(PrintManager.class);
|
||||
|
||||
// Start printing
|
||||
PrintJob printJob = pm.print(uuid.toString(), adapter, null);
|
||||
|
||||
// Wait until print preview is up
|
||||
synchronized (isWriteCalled) {
|
||||
isWriteCalled.wait();
|
||||
}
|
||||
|
||||
// Start print job settings
|
||||
Intent intent = new Intent(android.provider.Settings.ACTION_PRINT_SETTINGS);
|
||||
intent.putExtra(EXTRA_PRINT_JOB_ID, printJob.getId().flattenToString());
|
||||
intent.setData(Uri.fromParts("printjob", printJob.getId().flattenToString(), null));
|
||||
activity.startActivity(intent);
|
||||
|
||||
UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||
UiObject2 printPrefTitle = uiDevice.wait(Until.findObject(By.text("Configuring "
|
||||
+ uuid.toString())), 5000);
|
||||
assertNotNull(printPrefTitle);
|
||||
|
||||
Log.i(LOG_TAG, "Found " + printPrefTitle.getText());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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 com.android.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.provider.SearchIndexablesContract;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SearchIndexablesContractTest {
|
||||
|
||||
@Test
|
||||
public void testRawColumns_matchContractIndexing() {
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_RANK)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[0]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_TITLE)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[1]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_SUMMARY_ON)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[2]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_SUMMARY_OFF)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[3]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_ENTRIES)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[4]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_KEYWORDS)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[5]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_SCREEN_TITLE)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[6]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_CLASS_NAME)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[7]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_ICON_RESID)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[8]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_INTENT_ACTION)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[9]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_INTENT_TARGET_PACKAGE)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[10]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_INTENT_TARGET_CLASS)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[11]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_KEY)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[12]);
|
||||
assertThat(SearchIndexablesContract.RawData.COLUMN_USER_ID)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[13]);
|
||||
assertThat(SearchIndexablesContract.RawData.PAYLOAD_TYPE)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[14]);
|
||||
assertThat(SearchIndexablesContract.RawData.PAYLOAD)
|
||||
.isEqualTo(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS[15]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SearchResultTrampolineTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = InstrumentationRegistry.getTargetContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canLaunchSettingsTrampolineWithIntentAction() {
|
||||
final PackageManager pm = mContext.getPackageManager();
|
||||
final ResolveInfo info =
|
||||
pm.resolveActivity(new Intent("com.android.settings.SEARCH_RESULT_TRAMPOLINE"), 0);
|
||||
|
||||
assertThat(info.activityInfo.name)
|
||||
.isEqualTo(SearchResultTrampoline.class.getName());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.provider.SearchIndexablesContract;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class SettingsSearchIndexablesProviderTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = InstrumentationRegistry.getTargetContext();
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
System.clearProperty(SettingsSearchIndexablesProvider.SYSPROP_CRASH_ON_ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSiteMapPairsFetched() {
|
||||
final Uri uri = Uri.parse("content://" + mContext.getPackageName() + "/" +
|
||||
SearchIndexablesContract.SITE_MAP_PAIRS_PATH);
|
||||
final Cursor cursor = mContext.getContentResolver().query(uri, null, null, null, null);
|
||||
|
||||
final int size = cursor.getCount();
|
||||
assertThat(size).isGreaterThan(0);
|
||||
while (cursor.moveToNext()) {
|
||||
assertThat(cursor.getString(cursor.getColumnIndexOrThrow(
|
||||
SearchIndexablesContract.SiteMapColumns.PARENT_CLASS)))
|
||||
.isNotEmpty();
|
||||
assertThat(cursor.getString(cursor.getColumnIndexOrThrow(
|
||||
SearchIndexablesContract.SiteMapColumns.CHILD_CLASS)))
|
||||
.isNotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All {@link Indexable.SearchIndexProvider} should collect a list of non-indexable keys
|
||||
* without crashing. This test enables crashing of individual providers in the indexing pipeline
|
||||
* and checks that there are no crashes.
|
||||
*/
|
||||
@Test
|
||||
@Presubmit
|
||||
public void nonIndexableKeys_shouldNotCrash() {
|
||||
// Allow crashes in the indexing pipeline.
|
||||
System.setProperty(SettingsSearchIndexablesProvider.SYSPROP_CRASH_ON_ERROR,
|
||||
"enabled");
|
||||
|
||||
final Uri uri = Uri.parse("content://" + mContext.getPackageName() + "/" +
|
||||
SearchIndexablesContract.NON_INDEXABLES_KEYS_PATH);
|
||||
mContext.getContentResolver().query(uri, null, null, null, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
include /src/com/android/settings/sim/OWNERS
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (C) 2009 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.tests;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.android.settings.tests.unit.R;
|
||||
|
||||
public class BluetoothRequestPermissionTest extends Activity {
|
||||
private static final String TAG = "BluetoothRequestPermissionTest";
|
||||
BluetoothAdapter mAdapter;
|
||||
private ArrayAdapter<String> mMsgAdapter;
|
||||
|
||||
// Discoverable button alternates between 20 second timeout and no timeout.
|
||||
private boolean mDiscoveryWithTimeout = true;
|
||||
|
||||
private class BtOnClickListener implements OnClickListener {
|
||||
final boolean mEnableOnly; // enable or enable + discoverable
|
||||
|
||||
public BtOnClickListener(boolean enableOnly) {
|
||||
mEnableOnly = enableOnly;
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
requestPermission(mEnableOnly);
|
||||
}
|
||||
}
|
||||
|
||||
private class BtScanOnClickListener implements OnClickListener {
|
||||
public void onClick(View v) {
|
||||
Button scanButton = (Button) v;
|
||||
if (mAdapter.isDiscovering()) {
|
||||
mAdapter.cancelDiscovery();
|
||||
scanButton.setText(R.string.start_scan);
|
||||
} else {
|
||||
mAdapter.startDiscovery();
|
||||
scanButton.setText(R.string.stop_scan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.bluetooth_request_permission_test);
|
||||
mAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
Button enable = (Button) findViewById(R.id.enable);
|
||||
enable.setOnClickListener(new BtOnClickListener(true /* enable */));
|
||||
|
||||
Button discoverable = (Button) findViewById(R.id.discoverable);
|
||||
discoverable.setOnClickListener(new BtOnClickListener(false /* enable & discoverable */));
|
||||
|
||||
Button scanButton = (Button) findViewById(R.id.scan);
|
||||
scanButton.setOnClickListener(new BtScanOnClickListener());
|
||||
if (mAdapter.isDiscovering()) {
|
||||
scanButton.setText(R.string.stop_scan);
|
||||
} else {
|
||||
scanButton.setText(R.string.start_scan);
|
||||
}
|
||||
|
||||
mMsgAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
|
||||
|
||||
ListView listView = (ListView) findViewById(R.id.msg_container);
|
||||
listView.setAdapter(mMsgAdapter);
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
|
||||
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
|
||||
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
filter.addAction(BluetoothDevice.ACTION_FOUND);
|
||||
registerReceiver(mReceiver, filter);
|
||||
addMsg("Initialized");
|
||||
}
|
||||
|
||||
void requestPermission(boolean enableOnly) {
|
||||
Intent i = new Intent();
|
||||
if (enableOnly) {
|
||||
addMsg("Starting activity to enable bt");
|
||||
i.setAction(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
} else {
|
||||
addMsg("Starting activity to enable bt + discovery");
|
||||
i.setAction(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
|
||||
// Discoverability duration toggles between 20 seconds and no timeout.
|
||||
int timeout = (mDiscoveryWithTimeout ? 20 : 0);
|
||||
i.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, timeout);
|
||||
mDiscoveryWithTimeout = !mDiscoveryWithTimeout;
|
||||
}
|
||||
startActivityForResult(i, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode != 1) {
|
||||
Log.e(TAG, "Unexpected onActivityResult " + requestCode + " " + resultCode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (resultCode == Activity.RESULT_CANCELED) {
|
||||
addMsg("Result = RESULT_CANCELED");
|
||||
} else if (resultCode == Activity.RESULT_OK) {
|
||||
addMsg("Result = RESULT_OK (not expected for discovery)");
|
||||
} else {
|
||||
addMsg("Result = " + resultCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
private void addMsg(String msg) {
|
||||
mMsgAdapter.add(msg);
|
||||
Log.d(TAG, "msg");
|
||||
}
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent == null)
|
||||
return;
|
||||
String action = intent.getAction();
|
||||
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
|
||||
String stateStr = "???";
|
||||
switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothDevice.ERROR)) {
|
||||
case BluetoothAdapter.STATE_OFF:
|
||||
stateStr = "off";
|
||||
break;
|
||||
case BluetoothAdapter.STATE_TURNING_ON:
|
||||
stateStr = "turning on";
|
||||
break;
|
||||
case BluetoothAdapter.STATE_ON:
|
||||
stateStr = "on";
|
||||
break;
|
||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
||||
stateStr = "turning off";
|
||||
break;
|
||||
}
|
||||
addMsg("Bluetooth status = " + stateStr);
|
||||
} else if (action.equals(BluetoothDevice.ACTION_FOUND)) {
|
||||
String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
|
||||
addMsg("Found: " + name);
|
||||
} else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)) {
|
||||
addMsg("Scan started...");
|
||||
} else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) {
|
||||
addMsg("Scan ended");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.tests;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settings.tests.unit.R;
|
||||
|
||||
public class Manufacturer extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.manufacturer_main);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.tests;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settings.tests.unit.R;
|
||||
|
||||
public class Operator extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.operator_main);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.utils;
|
||||
|
||||
import static com.android.settings.utils.FileSizeFormatter.GIGABYTE_IN_BYTES;
|
||||
import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.icu.util.MeasureUnit;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class FileSizeFormatterTest {
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mContext = InstrumentationRegistry.getTargetContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatFileSize_zero() throws Exception {
|
||||
assertThat(
|
||||
FileSizeFormatter.formatFileSize(
|
||||
mContext,
|
||||
0 /* size */,
|
||||
MeasureUnit.GIGABYTE,
|
||||
GIGABYTE_IN_BYTES))
|
||||
.isEqualTo("0.00 GB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatFileSize_smallSize() throws Exception {
|
||||
assertThat(
|
||||
FileSizeFormatter.formatFileSize(
|
||||
mContext,
|
||||
MEGABYTE_IN_BYTES * 11 /* size */,
|
||||
MeasureUnit.GIGABYTE,
|
||||
GIGABYTE_IN_BYTES))
|
||||
.isEqualTo("0.01 GB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatFileSize_lessThanOneSize() throws Exception {
|
||||
assertThat(
|
||||
FileSizeFormatter.formatFileSize(
|
||||
mContext,
|
||||
MEGABYTE_IN_BYTES * 155 /* size */,
|
||||
MeasureUnit.GIGABYTE,
|
||||
GIGABYTE_IN_BYTES))
|
||||
.isEqualTo("0.16 GB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatFileSize_greaterThanOneSize() throws Exception {
|
||||
assertThat(
|
||||
FileSizeFormatter.formatFileSize(
|
||||
mContext,
|
||||
MEGABYTE_IN_BYTES * 1551 /* size */,
|
||||
MeasureUnit.GIGABYTE,
|
||||
GIGABYTE_IN_BYTES))
|
||||
.isEqualTo("1.6 GB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatFileSize_greaterThanTen() throws Exception {
|
||||
// Should round down due to truncation
|
||||
assertThat(
|
||||
FileSizeFormatter.formatFileSize(
|
||||
mContext,
|
||||
GIGABYTE_IN_BYTES * 15 + MEGABYTE_IN_BYTES * 50 /* size */,
|
||||
MeasureUnit.GIGABYTE,
|
||||
GIGABYTE_IN_BYTES))
|
||||
.isEqualTo("15 GB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatFileSize_handlesNegativeFileSizes() throws Exception {
|
||||
assertThat(
|
||||
FileSizeFormatter.formatFileSize(
|
||||
mContext,
|
||||
MEGABYTE_IN_BYTES * -155 /* size */,
|
||||
MeasureUnit.GIGABYTE,
|
||||
GIGABYTE_IN_BYTES))
|
||||
.isEqualTo("-0.16 GB");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.testutils;
|
||||
|
||||
import android.os.IBinder;
|
||||
import android.os.ServiceManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
// This class is for replacing existing system service with the mocked service.
|
||||
// Copied from CellBroadcastReceiver app.
|
||||
public final class MockedServiceManager {
|
||||
|
||||
private final String TAG = MockedServiceManager.class.getSimpleName();
|
||||
|
||||
private final HashMap<String, IBinder> mServiceManagerMockedServices = new HashMap<>();
|
||||
|
||||
private final HashMap<InstanceKey, Object> mOldInstances = new HashMap<>();
|
||||
|
||||
private final LinkedList<InstanceKey> mInstanceKeys = new LinkedList<>();
|
||||
|
||||
private static class InstanceKey {
|
||||
final Class mClass;
|
||||
final String mInstName;
|
||||
final Object mObj;
|
||||
|
||||
InstanceKey(final Class c, final String instName, final Object obj) {
|
||||
mClass = c;
|
||||
mInstName = instName;
|
||||
mObj = obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (mClass.getName().hashCode() * 31 + mInstName.hashCode()) * 31;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
InstanceKey other = (InstanceKey) obj;
|
||||
return (other.mClass == mClass && other.mInstName.equals(mInstName)
|
||||
&& other.mObj == mObj);
|
||||
}
|
||||
}
|
||||
|
||||
public MockedServiceManager() throws Exception {
|
||||
replaceInstance(ServiceManager.class, "sCache", null, mServiceManagerMockedServices);
|
||||
}
|
||||
|
||||
public void replaceService(String key, IBinder binder) {
|
||||
mServiceManagerMockedServices.put(key, binder);
|
||||
}
|
||||
|
||||
public void restoreAllServices() throws Exception {
|
||||
restoreInstances();
|
||||
}
|
||||
|
||||
public synchronized void replaceInstance(final Class c, final String instanceName,
|
||||
final Object obj, final Object newValue)
|
||||
throws Exception {
|
||||
Field field = c.getDeclaredField(instanceName);
|
||||
field.setAccessible(true);
|
||||
|
||||
InstanceKey key = new InstanceKey(c, instanceName, obj);
|
||||
if (!mOldInstances.containsKey(key)) {
|
||||
mOldInstances.put(key, field.get(obj));
|
||||
mInstanceKeys.add(key);
|
||||
}
|
||||
field.set(obj, newValue);
|
||||
}
|
||||
|
||||
public synchronized void restoreInstances() throws Exception {
|
||||
Iterator<InstanceKey> it = mInstanceKeys.descendingIterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
InstanceKey key = it.next();
|
||||
Field field = key.mClass.getDeclaredField(key.mInstName);
|
||||
field.setAccessible(true);
|
||||
field.set(key.mObj, mOldInstances.get(key));
|
||||
}
|
||||
|
||||
mInstanceKeys.clear();
|
||||
mOldInstances.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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 com.android.settings.vpn2;
|
||||
|
||||
import static com.android.settings.vpn2.AppManagementFragment.appHasVpnPermission;
|
||||
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Process;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
public class AppSettingsTest extends AndroidTestCase {
|
||||
private static final String TAG = AppSettingsTest.class.getSimpleName();
|
||||
|
||||
@Mock private Context mContext;
|
||||
@Mock private AppOpsManager mAppOps;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getSystemService(eq(Context.APP_OPS_SERVICE))).thenReturn(mAppOps);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testAppOpsRequiredToOpenFragment() {
|
||||
ApplicationInfo mockApp = createMockApp();
|
||||
|
||||
final AppOpsManager.PackageOps[] blankOps = {
|
||||
new AppOpsManager.PackageOps(mockApp.packageName, mockApp.uid, new ArrayList<>()),
|
||||
new AppOpsManager.PackageOps(mockApp.packageName, mockApp.uid, new ArrayList<>())
|
||||
};
|
||||
|
||||
// List with one package op
|
||||
when(mAppOps.getOpsForPackage(eq(mockApp.uid), eq(mockApp.packageName),
|
||||
any(int[].class))).thenReturn(Arrays.asList(
|
||||
new AppOpsManager.PackageOps[] {blankOps[0]}));
|
||||
assertTrue(appHasVpnPermission(mContext, mockApp));
|
||||
|
||||
// List with more than one package op
|
||||
when(mAppOps.getOpsForPackage(eq(mockApp.uid), eq(mockApp.packageName),
|
||||
any(int[].class))).thenReturn(Arrays.asList(blankOps));
|
||||
assertTrue(appHasVpnPermission(mContext, mockApp));
|
||||
|
||||
// Empty list
|
||||
when(mAppOps.getOpsForPackage(eq(mockApp.uid), eq(mockApp.packageName),
|
||||
any(int[].class))).thenReturn(Collections.emptyList());
|
||||
assertFalse(appHasVpnPermission(mContext, mockApp));
|
||||
|
||||
// Null list (may be returned in place of an empty list)
|
||||
when(mAppOps.getOpsForPackage(eq(mockApp.uid), eq(mockApp.packageName),
|
||||
any(int[].class))).thenReturn(null);
|
||||
assertFalse(appHasVpnPermission(mContext, mockApp));
|
||||
}
|
||||
|
||||
private static ApplicationInfo createMockApp() {
|
||||
final ApplicationInfo app = new ApplicationInfo();
|
||||
app.packageName = "com.example.mockvpn";
|
||||
app.uid = Process.FIRST_APPLICATION_UID;
|
||||
return app;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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 com.android.settings.vpn2;
|
||||
|
||||
import static org.mockito.AdditionalMatchers.not;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyBoolean;
|
||||
import static org.mockito.Mockito.argThat;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.internal.net.LegacyVpnInfo;
|
||||
import com.android.internal.net.VpnProfile;
|
||||
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PreferenceListTest extends AndroidTestCase {
|
||||
private static final String TAG = "PreferenceListTest";
|
||||
|
||||
@Mock VpnSettings mSettings;
|
||||
|
||||
final Map<String, LegacyVpnPreference> mLegacyMocks = new HashMap<>();
|
||||
final Map<AppVpnInfo, AppPreference> mAppMocks = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mLegacyMocks.clear();
|
||||
mAppMocks.clear();
|
||||
|
||||
doAnswer(invocation -> {
|
||||
final String key = ((VpnProfile)(invocation.getArguments()[0])).key;
|
||||
if (!mLegacyMocks.containsKey(key)) {
|
||||
mLegacyMocks.put(key, mock(LegacyVpnPreference.class));
|
||||
}
|
||||
return mLegacyMocks.get(key);
|
||||
}).when(mSettings).findOrCreatePreference(any(VpnProfile.class), anyBoolean());
|
||||
|
||||
doAnswer(invocation -> {
|
||||
final AppVpnInfo key = (AppVpnInfo)(invocation.getArguments()[0]);
|
||||
if (!mAppMocks.containsKey(key)) {
|
||||
mAppMocks.put(key, mock(AppPreference.class));
|
||||
}
|
||||
return mAppMocks.get(key);
|
||||
}).when(mSettings).findOrCreatePreference(any(AppVpnInfo.class));
|
||||
|
||||
doNothing().when(mSettings).setShownPreferences(any());
|
||||
doReturn(true).when(mSettings).canAddPreferences();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testNothingShownByDefault() {
|
||||
final VpnSettings.UpdatePreferences updater = new VpnSettings.UpdatePreferences(mSettings);
|
||||
updater.run();
|
||||
|
||||
verify(mSettings, never()).findOrCreatePreference(any(VpnProfile.class), anyBoolean());
|
||||
assertEquals(0, mLegacyMocks.size());
|
||||
assertEquals(0, mAppMocks.size());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testDisconnectedLegacyVpnShown() {
|
||||
final VpnProfile vpnProfile = new VpnProfile("test-disconnected");
|
||||
|
||||
final VpnSettings.UpdatePreferences updater = new VpnSettings.UpdatePreferences(mSettings);
|
||||
updater.legacyVpns(
|
||||
/* vpnProfiles */ Collections.<VpnProfile>singletonList(vpnProfile),
|
||||
/* connectedLegacyVpns */ Collections.<String, LegacyVpnInfo>emptyMap(),
|
||||
/* lockdownVpnKey */ null);
|
||||
updater.run();
|
||||
|
||||
verify(mSettings, times(1)).findOrCreatePreference(any(VpnProfile.class), eq(true));
|
||||
assertEquals(1, mLegacyMocks.size());
|
||||
assertEquals(0, mAppMocks.size());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testConnectedLegacyVpnShownIfDeleted() {
|
||||
final LegacyVpnInfo connectedLegacyVpn =new LegacyVpnInfo();
|
||||
connectedLegacyVpn.key = "test-connected";
|
||||
|
||||
final VpnSettings.UpdatePreferences updater = new VpnSettings.UpdatePreferences(mSettings);
|
||||
updater.legacyVpns(
|
||||
/* vpnProfiles */ Collections.<VpnProfile>emptyList(),
|
||||
/* connectedLegacyVpns */ new HashMap<String, LegacyVpnInfo>() {{
|
||||
put(connectedLegacyVpn.key, connectedLegacyVpn);
|
||||
}},
|
||||
/* lockdownVpnKey */ null);
|
||||
updater.run();
|
||||
|
||||
verify(mSettings, times(1)).findOrCreatePreference(any(VpnProfile.class), eq(false));
|
||||
assertEquals(1, mLegacyMocks.size());
|
||||
assertEquals(0, mAppMocks.size());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testConnectedLegacyVpnShownExactlyOnce() {
|
||||
final VpnProfile vpnProfile = new VpnProfile("test-no-duplicates");
|
||||
final LegacyVpnInfo connectedLegacyVpn = new LegacyVpnInfo();
|
||||
connectedLegacyVpn.key = new String(vpnProfile.key);
|
||||
|
||||
final VpnSettings.UpdatePreferences updater = new VpnSettings.UpdatePreferences(mSettings);
|
||||
updater.legacyVpns(
|
||||
/* vpnProfiles */ Collections.<VpnProfile>singletonList(vpnProfile),
|
||||
/* connectedLegacyVpns */ new HashMap<String, LegacyVpnInfo>() {{
|
||||
put(connectedLegacyVpn.key, connectedLegacyVpn);
|
||||
}},
|
||||
/* lockdownVpnKey */ null);
|
||||
updater.run();
|
||||
|
||||
final ArgumentMatcher<VpnProfile> equalsFake = arg -> {
|
||||
if (arg == vpnProfile) return true;
|
||||
if (arg == null) return false;
|
||||
return TextUtils.equals(arg.key, vpnProfile.key);
|
||||
};
|
||||
|
||||
// The VPN profile should have been used to create a preference and set up at laest once
|
||||
// with update=true to fill in all the fields.
|
||||
verify(mSettings, atLeast(1)).findOrCreatePreference(argThat(equalsFake), eq(true));
|
||||
|
||||
// ...But no other VPN profile key should ever have been passed in.
|
||||
verify(mSettings, never()).findOrCreatePreference(not(argThat(equalsFake)), anyBoolean());
|
||||
|
||||
// And so we should still have exactly 1 preference created.
|
||||
assertEquals(1, mLegacyMocks.size());
|
||||
assertEquals(0, mAppMocks.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
include /src/com/android/settings/wifi/calling/OWNERS
|
||||
Reference in New Issue
Block a user