Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.car.settings.accounts; |
| 18 | |
| 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
| 21 | import static org.mockito.ArgumentMatchers.any; |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 22 | import static org.mockito.ArgumentMatchers.eq; |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 23 | import static org.mockito.Mockito.verify; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 24 | import static org.robolectric.RuntimeEnvironment.application; |
| 25 | |
| 26 | import android.accounts.Account; |
| 27 | import android.content.ContentResolver; |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 28 | import android.content.Context; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 29 | import android.content.SyncAdapterType; |
| 30 | import android.content.SyncInfo; |
| 31 | import android.content.SyncStatusInfo; |
| 32 | import android.content.pm.PackageInfo; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 33 | import android.content.pm.ProviderInfo; |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 34 | import android.os.Bundle; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 35 | import android.os.UserHandle; |
| 36 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 37 | import androidx.lifecycle.Lifecycle; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 38 | import androidx.preference.Preference; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 39 | |
| 40 | import com.android.car.settings.CarSettingsRobolectricTestRunner; |
| 41 | import com.android.car.settings.R; |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 42 | import com.android.car.settings.common.LogicalPreferenceGroup; |
| 43 | import com.android.car.settings.common.PreferenceControllerTestHelper; |
| 44 | import com.android.car.settings.testutils.ShadowAccountManager; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 45 | import com.android.car.settings.testutils.ShadowApplicationPackageManager; |
| 46 | import com.android.car.settings.testutils.ShadowContentResolver; |
| 47 | |
| 48 | import org.junit.After; |
| 49 | import org.junit.Before; |
| 50 | import org.junit.Test; |
| 51 | import org.junit.runner.RunWith; |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 52 | import org.mockito.Mock; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 53 | import org.mockito.MockitoAnnotations; |
| 54 | import org.robolectric.Shadows; |
| 55 | import org.robolectric.annotation.Config; |
| 56 | import org.robolectric.shadow.api.Shadow; |
| 57 | |
| 58 | import java.util.ArrayList; |
| 59 | import java.util.Date; |
| 60 | import java.util.List; |
| 61 | |
| 62 | /** |
| 63 | * Unit test for {@link AccountSyncDetailsPreferenceController}. |
| 64 | */ |
| 65 | @RunWith(CarSettingsRobolectricTestRunner.class) |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 66 | @Config(shadows = {ShadowContentResolver.class, ShadowApplicationPackageManager.class, |
| 67 | ShadowAccountManager.class}) |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 68 | public class AccountSyncDetailsPreferenceControllerTest { |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 69 | private static final int SYNCABLE = 1; |
| 70 | private static final int NOT_SYNCABLE = 0; |
| 71 | |
| 72 | private static final int USER_ID = 3; |
| 73 | private static final int NOT_USER_ID = 5; |
| 74 | |
| 75 | private static final String AUTHORITY = "authority"; |
| 76 | private static final String ACCOUNT_TYPE = "com.acct1"; |
| 77 | private static final String DIFFERENT_ACCOUNT_TYPE = "com.acct2"; |
| 78 | |
| 79 | private final Account mAccount = new Account("acct1", ACCOUNT_TYPE); |
| 80 | private final UserHandle mUserHandle = new UserHandle(USER_ID); |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 81 | @Mock |
| 82 | ShadowContentResolver.SyncListener mMockSyncListener; |
| 83 | private Context mContext; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 84 | private AccountSyncDetailsPreferenceController mController; |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 85 | private LogicalPreferenceGroup mPreferenceGroup; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 86 | |
| 87 | @Before |
| 88 | public void setUp() { |
| 89 | MockitoAnnotations.initMocks(this); |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 90 | mContext = application; |
| 91 | ShadowContentResolver.setSyncListener(mMockSyncListener); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 92 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 93 | PreferenceControllerTestHelper<AccountSyncDetailsPreferenceController> helper = |
| 94 | new PreferenceControllerTestHelper<>(mContext, |
| 95 | AccountSyncDetailsPreferenceController.class); |
| 96 | mController = helper.getController(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 97 | mController.setAccount(mAccount); |
| 98 | mController.setUserHandle(mUserHandle); |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 99 | |
| 100 | mPreferenceGroup = new LogicalPreferenceGroup(mContext); |
| 101 | helper.setPreference(mPreferenceGroup); |
| 102 | |
| 103 | helper.markState(Lifecycle.State.STARTED); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @After |
| 107 | public void tearDown() { |
| 108 | ShadowContentResolver.reset(); |
| 109 | } |
| 110 | |
| 111 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 112 | public void refreshUi_syncAdapterDoesNotHaveSameAccountType_shouldNotBeShown() { |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 113 | // Adds a sync adapter type that is visible but does not have the right account type. |
| 114 | SyncAdapterType syncAdapterType = new SyncAdapterType(AUTHORITY, |
| 115 | DIFFERENT_ACCOUNT_TYPE, /* userVisible */ true, /* supportsUploading */ true); |
| 116 | SyncAdapterType[] syncAdapters = {syncAdapterType}; |
| 117 | ShadowContentResolver.setSyncAdapterTypes(syncAdapters); |
| 118 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 119 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 120 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 121 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 125 | public void refreshUi_syncAdapterIsNotVisible_shouldNotBeShown() { |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 126 | // Adds a sync adapter type that has the right account type but is not visible. |
| 127 | SyncAdapterType syncAdapterType = new SyncAdapterType(AUTHORITY, |
| 128 | ACCOUNT_TYPE, /* userVisible */ false, /* supportsUploading */ true); |
| 129 | SyncAdapterType[] syncAdapters = {syncAdapterType}; |
| 130 | ShadowContentResolver.setSyncAdapterTypes(syncAdapters); |
| 131 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 132 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 133 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 134 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 138 | public void refreshUi_syncAdapterIsNotSyncable_shouldNotBeShown() { |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 139 | // Adds a sync adapter type that has the right account type and is visible. |
| 140 | SyncAdapterType syncAdapterType = new SyncAdapterType(AUTHORITY, |
| 141 | ACCOUNT_TYPE, /* userVisible */ true, /* supportsUploading */ true); |
| 142 | SyncAdapterType[] syncAdapters = {syncAdapterType}; |
| 143 | ShadowContentResolver.setSyncAdapterTypes(syncAdapters); |
| 144 | // Sets that the sync adapter to not syncable. |
| 145 | ShadowContentResolver.setIsSyncable(mAccount, AUTHORITY, /* syncable= */ NOT_SYNCABLE); |
| 146 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 147 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 148 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 149 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 153 | public void refreshUi_syncAdapterDoesNotHaveProviderInfo_shouldNotBeShown() { |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 154 | // Adds a sync adapter type that has the right account type and is visible. |
| 155 | SyncAdapterType syncAdapterType = new SyncAdapterType(AUTHORITY, |
| 156 | ACCOUNT_TYPE, /* userVisible */ true, /* supportsUploading */ true); |
| 157 | SyncAdapterType[] syncAdapters = {syncAdapterType}; |
| 158 | ShadowContentResolver.setSyncAdapterTypes(syncAdapters); |
| 159 | // Sets that the sync adapter to syncable. |
| 160 | ShadowContentResolver.setIsSyncable(mAccount, AUTHORITY, /* syncable= */ SYNCABLE); |
| 161 | |
| 162 | // However, no provider info is set for the sync adapter, so it shouldn't be visible. |
| 163 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 164 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 165 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 166 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 170 | public void refreshUi_providerInfoDoesNotHaveLabel_shouldNotBeShown() { |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 171 | // Adds a sync adapter type that has the right account type and is visible. |
| 172 | SyncAdapterType syncAdapterType = new SyncAdapterType(AUTHORITY, |
| 173 | ACCOUNT_TYPE, /* userVisible */ true, /* supportsUploading */ true); |
| 174 | SyncAdapterType[] syncAdapters = {syncAdapterType}; |
| 175 | ShadowContentResolver.setSyncAdapterTypes(syncAdapters); |
| 176 | // Sets that the sync adapter to syncable. |
| 177 | ShadowContentResolver.setIsSyncable(mAccount, AUTHORITY, /* syncable= */ SYNCABLE); |
| 178 | // Sets provider info for the sync adapter but it does not have a label. |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 179 | ProviderInfo info = new ProviderInfo(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 180 | info.authority = AUTHORITY; |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 181 | info.name = ""; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 182 | |
| 183 | ProviderInfo[] providers = {info}; |
| 184 | PackageInfo packageInfo = new PackageInfo(); |
| 185 | packageInfo.packageName = AUTHORITY; |
| 186 | packageInfo.providers = providers; |
| 187 | getShadowApplicationManager().addPackage(packageInfo); |
| 188 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 189 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 190 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 191 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 195 | public void refreshUi_providerLabelShouldBeSet() { |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 196 | // Adds a sync adapter type that has the right account type and is visible. |
| 197 | SyncAdapterType syncAdapterType = new SyncAdapterType(AUTHORITY, |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 198 | ACCOUNT_TYPE, /* userVisible */ true, /* supportsUploading */ true); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 199 | SyncAdapterType[] syncAdapters = {syncAdapterType}; |
| 200 | ShadowContentResolver.setSyncAdapterTypes(syncAdapters); |
| 201 | // Sets that the sync adapter to syncable. |
| 202 | ShadowContentResolver.setIsSyncable(mAccount, AUTHORITY, /* syncable= */ SYNCABLE); |
| 203 | // Sets provider info for the sync adapter with a label. |
James Lemieux | 56770fd | 2018-12-14 15:31:51 -0800 | [diff] [blame] | 204 | ProviderInfo info = new ProviderInfo(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 205 | info.authority = AUTHORITY; |
James Lemieux | 56770fd | 2018-12-14 15:31:51 -0800 | [diff] [blame] | 206 | info.name = "label"; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 207 | |
| 208 | ProviderInfo[] providers = {info}; |
| 209 | PackageInfo packageInfo = new PackageInfo(); |
| 210 | packageInfo.packageName = AUTHORITY; |
| 211 | packageInfo.providers = providers; |
| 212 | getShadowApplicationManager().addPackage(packageInfo); |
| 213 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 214 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 215 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 216 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 217 | Preference pref = mPreferenceGroup.getPreference(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 218 | assertThat(pref.getTitle()).isEqualTo("label"); |
| 219 | } |
| 220 | |
| 221 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 222 | public void refreshUi_masterSyncOff_syncDisabled_shouldNotBeChecked() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 223 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 224 | // Turns off master sync and automatic sync for the adapter. |
| 225 | ContentResolver.setMasterSyncAutomaticallyAsUser(/* sync= */ true, USER_ID); |
| 226 | ContentResolver.setSyncAutomaticallyAsUser(mAccount, AUTHORITY, /* sync= */ false, |
| 227 | USER_ID); |
| 228 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 229 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 230 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 231 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 232 | SyncPreference pref = (SyncPreference) mPreferenceGroup.getPreference(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 233 | assertThat(pref.isChecked()).isFalse(); |
| 234 | } |
| 235 | |
| 236 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 237 | public void refreshUi_masterSyncOn_syncDisabled_shouldBeChecked() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 238 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 239 | // Turns on master sync and turns off automatic sync for the adapter. |
| 240 | ContentResolver.setMasterSyncAutomaticallyAsUser(/* sync= */ false, USER_ID); |
| 241 | ContentResolver.setSyncAutomaticallyAsUser(mAccount, AUTHORITY, /* sync= */ false, |
| 242 | USER_ID); |
| 243 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 244 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 245 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 246 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 247 | SyncPreference pref = (SyncPreference) mPreferenceGroup.getPreference(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 248 | assertThat(pref.isChecked()).isTrue(); |
| 249 | } |
| 250 | |
| 251 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 252 | public void refreshUi_masterSyncOff_syncEnabled_shouldBeChecked() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 253 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 254 | // Turns off master sync and turns on automatic sync for the adapter. |
| 255 | ContentResolver.setMasterSyncAutomaticallyAsUser(/* sync= */ true, USER_ID); |
| 256 | ContentResolver.setSyncAutomaticallyAsUser(mAccount, AUTHORITY, /* sync= */ true, |
| 257 | USER_ID); |
| 258 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 259 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 260 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 261 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 262 | SyncPreference pref = (SyncPreference) mPreferenceGroup.getPreference(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 263 | assertThat(pref.isChecked()).isTrue(); |
| 264 | } |
| 265 | |
| 266 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 267 | public void refreshUi_syncDisabled_summaryShouldBeSet() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 268 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 269 | // Turns off automatic sync for the the sync adapter. |
| 270 | ContentResolver.setSyncAutomaticallyAsUser(mAccount, AUTHORITY, /* sync= */ false, |
| 271 | mUserHandle.getIdentifier()); |
| 272 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 273 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 274 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 275 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 276 | Preference pref = mPreferenceGroup.getPreference(0); |
| 277 | assertThat(pref.getSummary()).isEqualTo(mContext.getString(R.string.sync_disabled)); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 281 | public void refreshUi_syncEnabled_activelySyncing_summaryShouldBeSet() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 282 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 283 | // Turns on automatic sync for the the sync adapter. |
| 284 | ContentResolver.setSyncAutomaticallyAsUser(mAccount, AUTHORITY, /* sync= */ true, |
| 285 | mUserHandle.getIdentifier()); |
| 286 | // Adds the sync adapter to the list of currently syncing adapters. |
| 287 | SyncInfo syncInfo = new SyncInfo(/* authorityId= */ 0, mAccount, AUTHORITY, /* startTime= */ |
| 288 | 0); |
| 289 | List<SyncInfo> syncs = new ArrayList<>(); |
| 290 | syncs.add(syncInfo); |
| 291 | ShadowContentResolver.setCurrentSyncs(syncs); |
| 292 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 293 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 294 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 295 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 296 | Preference pref = mPreferenceGroup.getPreference(0); |
| 297 | assertThat(pref.getSummary()).isEqualTo(mContext.getString(R.string.sync_in_progress)); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 301 | public void refreshUi_syncEnabled_syncHasHappened_summaryShouldBeSet() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 302 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 303 | // Turns on automatic sync for the the sync adapter. |
| 304 | ContentResolver.setSyncAutomaticallyAsUser(mAccount, AUTHORITY, /* sync= */ true, |
| 305 | mUserHandle.getIdentifier()); |
| 306 | // Sets the sync adapter's last successful sync time. |
| 307 | SyncStatusInfo status = new SyncStatusInfo(0); |
| 308 | status.setLastSuccess(0, 83091); |
| 309 | ShadowContentResolver.setSyncStatus(mAccount, AUTHORITY, status); |
| 310 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 311 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 312 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 313 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 314 | Preference pref = mPreferenceGroup.getPreference(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 315 | |
| 316 | String expectedTimeString = mController.formatSyncDate(new Date(83091)); |
| 317 | assertThat(pref.getSummary()).isEqualTo( |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 318 | mContext.getString(R.string.last_synced, expectedTimeString)); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 322 | public void refreshUi_activelySyncing_notInitialSync_shouldHaveActiveSyncIcon() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 323 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 324 | // Adds the sync adapter to the list of currently syncing adapters. |
| 325 | SyncInfo syncInfo = new SyncInfo(/* authorityId= */ 0, mAccount, AUTHORITY, /* startTime= */ |
| 326 | 0); |
| 327 | List<SyncInfo> syncs = new ArrayList<>(); |
| 328 | syncs.add(syncInfo); |
| 329 | ShadowContentResolver.setCurrentSyncs(syncs); |
| 330 | // Sets the sync adapter's initializing state to false (i.e. it's not performing an |
| 331 | // initial sync). |
| 332 | SyncStatusInfo status = new SyncStatusInfo(0); |
| 333 | status.initialize = false; |
| 334 | ShadowContentResolver.setSyncStatus(mAccount, AUTHORITY, status); |
| 335 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 336 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 337 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 338 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 339 | Preference pref = mPreferenceGroup.getPreference(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 340 | |
| 341 | assertThat(Shadows.shadowOf(pref.getIcon()).getCreatedFromResId()).isEqualTo( |
Roshan Agrawal | 24d2d3b | 2018-12-28 15:45:00 -0800 | [diff] [blame] | 342 | R.drawable.ic_sync_anim); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 346 | public void refreshUi_syncPending_notInitialSync_shouldHaveActiveSyncIcon() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 347 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 348 | // Sets the sync adapter's initializing state to false (i.e. it's not performing an |
| 349 | // initial sync). |
| 350 | // Also sets the the sync status to pending |
| 351 | SyncStatusInfo status = new SyncStatusInfo(0); |
| 352 | status.initialize = false; |
| 353 | status.pending = true; |
| 354 | ShadowContentResolver.setSyncStatus(mAccount, AUTHORITY, status); |
| 355 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 356 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 357 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 358 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 359 | Preference pref = mPreferenceGroup.getPreference(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 360 | |
| 361 | assertThat(Shadows.shadowOf(pref.getIcon()).getCreatedFromResId()).isEqualTo( |
Roshan Agrawal | 24d2d3b | 2018-12-28 15:45:00 -0800 | [diff] [blame] | 362 | R.drawable.ic_sync); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 366 | public void refreshUi_syncFailed_shouldHaveProblemSyncIcon() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 367 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 368 | // Turns on automatic sync for the the sync adapter. |
| 369 | ContentResolver.setSyncAutomaticallyAsUser(mAccount, AUTHORITY, /* sync= */ true, |
| 370 | mUserHandle.getIdentifier()); |
| 371 | // Sets the sync adapter's last failure time and message so it appears to have failed |
| 372 | // previously. |
| 373 | SyncStatusInfo status = new SyncStatusInfo(0); |
| 374 | status.lastFailureTime = 10; |
| 375 | status.lastFailureMesg = "too-many-deletions"; |
| 376 | ShadowContentResolver.setSyncStatus(mAccount, AUTHORITY, status); |
| 377 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 378 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 379 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 380 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 381 | Preference pref = mPreferenceGroup.getPreference(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 382 | |
| 383 | assertThat(Shadows.shadowOf(pref.getIcon()).getCreatedFromResId()).isEqualTo( |
| 384 | R.drawable.ic_sync_problem); |
| 385 | } |
| 386 | |
| 387 | @Test |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 388 | public void refreshUi_noSyncStatus_shouldHaveNoIcon() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 389 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 390 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 391 | mController.refreshUi(); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 392 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 393 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 394 | Preference pref = mPreferenceGroup.getPreference(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 395 | |
| 396 | assertThat(pref.getIcon()).isNull(); |
| 397 | assertThat(pref.isIconSpaceReserved()).isTrue(); |
| 398 | } |
| 399 | |
| 400 | @Test |
| 401 | public void onAccountsUpdate_correctUserId_shouldForceUpdatePreferences() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 402 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 403 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 404 | mController.refreshUi(); |
| 405 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 406 | |
| 407 | ShadowContentResolver.reset(); |
| 408 | mController.onAccountsUpdate(mUserHandle); |
| 409 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 410 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(0); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | @Test |
| 414 | public void onAccountsUpdate_incorrectUserId_shouldNotForceUpdatePreferences() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 415 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 416 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 417 | mController.refreshUi(); |
| 418 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 419 | |
| 420 | ShadowContentResolver.reset(); |
| 421 | mController.onAccountsUpdate(new UserHandle(NOT_USER_ID)); |
| 422 | |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 423 | assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); |
| 424 | } |
| 425 | |
| 426 | @Test |
| 427 | public void onSyncPreferenceClicked_preferenceUnchecked_shouldSetSyncAutomaticallyOff() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 428 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 429 | |
| 430 | // Turns off one time sync and turns on automatic sync for the adapter so the preference is |
| 431 | // checked. |
| 432 | ContentResolver.setMasterSyncAutomaticallyAsUser(/* sync= */ true, USER_ID); |
| 433 | ContentResolver.setSyncAutomaticallyAsUser(mAccount, AUTHORITY, /* sync= */ true, |
| 434 | USER_ID); |
| 435 | |
| 436 | mController.refreshUi(); |
| 437 | SyncPreference pref = (SyncPreference) mPreferenceGroup.getPreference(0); |
| 438 | pref.performClick(); |
| 439 | |
| 440 | assertThat(ContentResolver.getSyncAutomaticallyAsUser(mAccount, AUTHORITY, |
| 441 | USER_ID)).isFalse(); |
| 442 | } |
| 443 | |
| 444 | @Test |
| 445 | public void onSyncPreferenceClicked_preferenceUnchecked_shouldCancelSync() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 446 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 447 | |
| 448 | // Turns off one time sync and turns on automatic sync for the adapter so the preference is |
| 449 | // checked. |
| 450 | ContentResolver.setMasterSyncAutomaticallyAsUser(/* sync= */ true, USER_ID); |
| 451 | ContentResolver.setSyncAutomaticallyAsUser(mAccount, AUTHORITY, /* sync= */ true, |
| 452 | USER_ID); |
| 453 | |
| 454 | mController.refreshUi(); |
| 455 | SyncPreference pref = (SyncPreference) mPreferenceGroup.getPreference(0); |
| 456 | pref.performClick(); |
| 457 | |
| 458 | verify(mMockSyncListener).onSyncCanceled(eq(mAccount), eq(AUTHORITY), eq(USER_ID)); |
| 459 | } |
| 460 | |
| 461 | @Test |
| 462 | public void onSyncPreferenceClicked_preferenceChecked_shouldSetSyncAutomaticallyOn() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 463 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 464 | |
| 465 | // Turns off one time sync and automatic sync for the adapter so the preference is |
| 466 | // unchecked. |
| 467 | ContentResolver.setMasterSyncAutomaticallyAsUser(/* sync= */ true, USER_ID); |
| 468 | ContentResolver.setSyncAutomaticallyAsUser(mAccount, AUTHORITY, /* sync= */ false, |
| 469 | USER_ID); |
| 470 | |
| 471 | mController.refreshUi(); |
| 472 | SyncPreference pref = (SyncPreference) mPreferenceGroup.getPreference(0); |
| 473 | pref.performClick(); |
| 474 | |
| 475 | assertThat(ContentResolver.getSyncAutomaticallyAsUser(mAccount, AUTHORITY, |
| 476 | USER_ID)).isTrue(); |
| 477 | } |
| 478 | |
| 479 | @Test |
| 480 | public void onSyncPreferenceClicked_preferenceChecked_masterSyncOff_shouldRequestSync() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 481 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 482 | |
| 483 | // Turns off master sync and automatic sync for the adapter so the preference is unchecked. |
| 484 | ContentResolver.setMasterSyncAutomaticallyAsUser(/* sync= */ false, USER_ID); |
| 485 | ContentResolver.setSyncAutomaticallyAsUser(mAccount, AUTHORITY, /* sync= */ false, |
| 486 | USER_ID); |
| 487 | |
| 488 | mController.refreshUi(); |
| 489 | SyncPreference pref = (SyncPreference) mPreferenceGroup.getPreference(0); |
| 490 | |
| 491 | // Sets master sync off |
| 492 | ContentResolver.setMasterSyncAutomaticallyAsUser(/* sync= */ false, USER_ID); |
| 493 | pref.performClick(); |
| 494 | |
| 495 | verify(mMockSyncListener).onSyncRequested(eq(mAccount), eq(AUTHORITY), eq(USER_ID), |
| 496 | any(Bundle.class)); |
| 497 | } |
| 498 | |
| 499 | @Test |
| 500 | public void onSyncPreferenceClicked_oneTimeSyncOn_shouldRequestSync() { |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 501 | setUpVisibleSyncAdapters(AUTHORITY); |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 502 | |
| 503 | // Turns on one time sync mode |
| 504 | ContentResolver.setMasterSyncAutomaticallyAsUser(/* sync= */ false, USER_ID); |
| 505 | |
| 506 | mController.refreshUi(); |
| 507 | SyncPreference pref = (SyncPreference) mPreferenceGroup.getPreference(0); |
| 508 | pref.performClick(); |
| 509 | |
| 510 | verify(mMockSyncListener).onSyncRequested(eq(mAccount), eq(AUTHORITY), eq(USER_ID), |
| 511 | any(Bundle.class)); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 512 | } |
| 513 | |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 514 | private void setUpVisibleSyncAdapters(String... authorities) { |
| 515 | SyncAdapterType[] syncAdapters = new SyncAdapterType[authorities.length]; |
| 516 | for (int i = 0; i < authorities.length; i++) { |
| 517 | String authority = authorities[i]; |
| 518 | // Adds a sync adapter type that has the right account type and is visible. |
| 519 | SyncAdapterType syncAdapterType = new SyncAdapterType(authority, |
| 520 | ACCOUNT_TYPE, /* userVisible */ true, /* supportsUploading */ true); |
| 521 | syncAdapters[i] = syncAdapterType; |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 522 | |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 523 | // Sets that the sync adapter is syncable. |
| 524 | ShadowContentResolver.setIsSyncable(mAccount, authority, /* syncable= */ SYNCABLE); |
| 525 | |
| 526 | // Sets provider info with a label for the sync adapter. |
| 527 | ProviderInfo info = new ProviderInfo(); |
Roshan Agrawal | f731b0f | 2019-01-02 16:09:40 -0800 | [diff] [blame] | 528 | info.authority = authority; |
Roshan Agrawal | ba4742e | 2018-12-10 15:34:12 -0800 | [diff] [blame] | 529 | info.name = "label"; |
| 530 | ProviderInfo[] providers = {info}; |
| 531 | |
| 532 | PackageInfo packageInfo = new PackageInfo(); |
| 533 | packageInfo.packageName = authority; |
| 534 | packageInfo.providers = providers; |
| 535 | getShadowApplicationManager().addPackage(packageInfo); |
| 536 | } |
| 537 | ShadowContentResolver.setSyncAdapterTypes(syncAdapters); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | private ShadowApplicationPackageManager getShadowApplicationManager() { |
Roshan Agrawal | a6b4ec8 | 2018-11-20 15:33:37 -0800 | [diff] [blame] | 541 | return Shadow.extract(mContext.getPackageManager()); |
Roshan Agrawal | d5f8a23 | 2018-11-08 19:44:24 -0800 | [diff] [blame] | 542 | } |
| 543 | } |