Snap for 8853148 from 3bab68f912 to udc-release
Change-Id: If3eecf842141bd8289725faecab523c35e2afac9
This commit is contained in:
@@ -36,6 +36,16 @@
|
||||
android:paddingLeft="0dp"
|
||||
android:paddingRight="0dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sud_layout_description"
|
||||
android:text="@string/lockpassword_choose_your_pattern_description"
|
||||
style="@style/SudDescription.Glif"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minLines="4"
|
||||
android:paddingStart="?attr/sudMarginStart"
|
||||
android:paddingEnd="?attr/sudMarginEnd"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/headerText"
|
||||
style="@style/SudDescription.Glif"
|
||||
|
||||
@@ -4386,6 +4386,8 @@
|
||||
<string name="lockpassword_choose_your_profile_pin_header">Set a work PIN</string>
|
||||
<!-- Header on first screen of choose device pattern flow [CHAR LIMIT=40] -->
|
||||
<string name="lockpassword_choose_your_pattern_header">Set a pattern</string>
|
||||
<!-- Description on first screen of choose device pattern flow [CHAR LIMIT=NONE] -->
|
||||
<string name="lockpassword_choose_your_pattern_description">For added security, set a pattern to unlock the device</string>
|
||||
<!-- Header on first screen of choose work profile pattern flow [CHAR LIMIT=40] -->
|
||||
<string name="lockpassword_choose_your_profile_pattern_header">Set a work pattern</string>
|
||||
|
||||
@@ -9421,12 +9423,12 @@
|
||||
|
||||
<!-- app summary of notification app list screen [CHAR LIMIT=100] -->
|
||||
<plurals name="notifications_sent_daily">
|
||||
<item quantity="one">~<xliff:g id="number">%d</xliff:g> notification per day</item>
|
||||
<item quantity="other">~<xliff:g id="number">%,d</xliff:g> notifications per day</item>
|
||||
<item quantity="one">About <xliff:g id="number">%d</xliff:g> notification per day</item>
|
||||
<item quantity="other">About <xliff:g id="number">%,d</xliff:g> notifications per day</item>
|
||||
</plurals>
|
||||
<plurals name="notifications_sent_weekly">
|
||||
<item quantity="one">~<xliff:g id="number">%d</xliff:g> notification per week</item>
|
||||
<item quantity="other">~<xliff:g id="number">%,d</xliff:g> notifications per week</item>
|
||||
<item quantity="one">About <xliff:g id="number">%d</xliff:g> notification per week</item>
|
||||
<item quantity="other">About <xliff:g id="number">%,d</xliff:g> notifications per week</item>
|
||||
</plurals>
|
||||
<!-- app summary of notification app list screen [CHAR LIMIT=100] -->
|
||||
<string name="notifications_sent_never">Never</string>
|
||||
|
||||
@@ -26,7 +26,6 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.autofill.PasswordsPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultAutofillPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultWorkAutofillPreferenceController;
|
||||
@@ -96,7 +95,7 @@ public class AccountDashboardFragment extends DashboardFragment {
|
||||
}
|
||||
|
||||
private static void buildAccountPreferenceControllers(
|
||||
Context context, SettingsPreferenceFragment parent, String[] authorities,
|
||||
Context context, DashboardFragment parent, String[] authorities,
|
||||
List<AbstractPreferenceController> controllers) {
|
||||
final AccountPreferenceController accountPrefController =
|
||||
new AccountPreferenceController(context, parent, authorities,
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.autofill.PasswordsPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
@@ -78,7 +77,7 @@ public class AccountPersonalDashboardFragment extends DashboardFragment {
|
||||
}
|
||||
|
||||
private static void buildAccountPreferenceControllers(
|
||||
Context context, SettingsPreferenceFragment parent, String[] authorities,
|
||||
Context context, DashboardFragment parent, String[] authorities,
|
||||
List<AbstractPreferenceController> controllers) {
|
||||
final AccountPreferenceController accountPrefController =
|
||||
new AccountPreferenceController(context, parent, authorities,
|
||||
|
||||
@@ -58,10 +58,10 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.AccessiblePreferenceCategory;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
@@ -101,7 +101,7 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
private Preference mProfileNotAvailablePreference;
|
||||
private String[] mAuthorities;
|
||||
private int mAuthoritiesCount = 0;
|
||||
private SettingsPreferenceFragment mFragment;
|
||||
private DashboardFragment mFragment;
|
||||
private int mAccountProfileOrder = ORDER_ACCOUNT_PROFILES;
|
||||
private AccountRestrictionHelper mHelper;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -145,13 +145,13 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
public ArrayMap<String, AccountTypePreference> accountPreferences = new ArrayMap<>();
|
||||
}
|
||||
|
||||
public AccountPreferenceController(Context context, SettingsPreferenceFragment parent,
|
||||
public AccountPreferenceController(Context context, DashboardFragment parent,
|
||||
String[] authorities, @ProfileSelectFragment.ProfileType int type) {
|
||||
this(context, parent, authorities, new AccountRestrictionHelper(context), type);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
AccountPreferenceController(Context context, SettingsPreferenceFragment parent,
|
||||
AccountPreferenceController(Context context, DashboardFragment parent,
|
||||
String[] authorities, AccountRestrictionHelper helper,
|
||||
@ProfileSelectFragment.ProfileType int type) {
|
||||
super(context);
|
||||
@@ -314,6 +314,9 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
for (int i = 0; i < profilesCount; i++) {
|
||||
updateAccountTypes(mProfiles.valueAt(i));
|
||||
}
|
||||
|
||||
// Refresh for the auto-sync preferences
|
||||
mFragment.forceUpdatePreferences();
|
||||
}
|
||||
|
||||
private void updateProfileUi(final UserInfo userInfo) {
|
||||
@@ -409,7 +412,6 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
return preference;
|
||||
}
|
||||
|
||||
|
||||
private Preference newManagedProfileSettings() {
|
||||
Preference preference = new Preference(mFragment.getPreferenceManager().getContext());
|
||||
preference.setKey(PREF_KEY_WORK_PROFILE_SETTING);
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.autofill.PasswordsPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
@@ -78,7 +77,7 @@ public class AccountWorkProfileDashboardFragment extends DashboardFragment {
|
||||
}
|
||||
|
||||
private static void buildAccountPreferenceControllers(
|
||||
Context context, SettingsPreferenceFragment parent, String[] authorities,
|
||||
Context context, DashboardFragment parent, String[] authorities,
|
||||
List<AbstractPreferenceController> controllers) {
|
||||
final AccountPreferenceController accountPrefController =
|
||||
new AccountPreferenceController(context, parent, authorities,
|
||||
|
||||
@@ -415,6 +415,30 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
updatePreferenceVisibility(mPreferenceControllers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force update all the preferences in this fragment.
|
||||
*/
|
||||
public void forceUpdatePreferences() {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
if (screen == null || mPreferenceControllers == null) {
|
||||
return;
|
||||
}
|
||||
for (List<AbstractPreferenceController> controllerList : mPreferenceControllers.values()) {
|
||||
for (AbstractPreferenceController controller : controllerList) {
|
||||
final String key = controller.getPreferenceKey();
|
||||
final Preference preference = findPreference(key);
|
||||
if (preference == null) {
|
||||
continue;
|
||||
}
|
||||
final boolean available = controller.isAvailable();
|
||||
if (available) {
|
||||
controller.updateState(preference);
|
||||
}
|
||||
preference.setVisible(available);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updatePreferenceVisibility(
|
||||
Map<Class, List<AbstractPreferenceController>> preferenceControllers) {
|
||||
|
||||
@@ -85,13 +85,15 @@ public class StorageAsyncLoader
|
||||
|
||||
for (UserInfo info : infos) {
|
||||
final StorageResult result = getAppsAndGamesSize(info.id);
|
||||
|
||||
final Bundle media = new Bundle();
|
||||
media.putString(ContentResolver.QUERY_ARG_SQL_SELECTION, MediaColumns.VOLUME_NAME
|
||||
+ "= '" + MediaStore.VOLUME_EXTERNAL_PRIMARY + "'");
|
||||
result.imagesSize = getFilesSize(info.id, MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||
null /* queryArgs */);
|
||||
media /* queryArgs */);
|
||||
result.videosSize = getFilesSize(info.id, MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
||||
null /* queryArgs */);
|
||||
media /* queryArgs */);
|
||||
result.audioSize = getFilesSize(info.id, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
null /* queryArgs */);
|
||||
media /* queryArgs */);
|
||||
|
||||
final Bundle documentsAndOtherQueryArgs = new Bundle();
|
||||
documentsAndOtherQueryArgs.putString(ContentResolver.QUERY_ARG_SQL_SELECTION,
|
||||
@@ -100,13 +102,14 @@ public class StorageAsyncLoader
|
||||
+ " AND " + FileColumns.MEDIA_TYPE + "!=" + FileColumns.MEDIA_TYPE_AUDIO
|
||||
+ " AND " + FileColumns.MIME_TYPE + " IS NOT NULL");
|
||||
result.documentsAndOtherSize = getFilesSize(info.id,
|
||||
MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL),
|
||||
MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY),
|
||||
documentsAndOtherQueryArgs);
|
||||
|
||||
final Bundle trashQueryArgs = new Bundle();
|
||||
trashQueryArgs.putInt(MediaStore.QUERY_ARG_MATCH_TRASHED, MediaStore.MATCH_ONLY);
|
||||
result.trashSize = getFilesSize(info.id,
|
||||
MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL), trashQueryArgs);
|
||||
MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY),
|
||||
trashQueryArgs);
|
||||
|
||||
results.put(info.id, result);
|
||||
}
|
||||
|
||||
@@ -347,6 +347,7 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
|
||||
trapezoidIndex, mBatteryIndexedMap.size(), isForce));
|
||||
|
||||
mTrapezoidIndex = trapezoidIndex;
|
||||
mBatteryChartView.setSelectedIndex(mTrapezoidIndex);
|
||||
mHandler.post(() -> {
|
||||
final long start = System.currentTimeMillis();
|
||||
removeAndCacheAllPrefs();
|
||||
|
||||
@@ -110,9 +110,11 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
|
||||
@VisibleForTesting
|
||||
Paint mTrapezoidCurvePaint = null;
|
||||
private TrapezoidSlot[] mTrapezoidSlots;
|
||||
@VisibleForTesting
|
||||
TrapezoidSlot[] mTrapezoidSlots;
|
||||
// Records the location to calculate selected index.
|
||||
private float mTouchUpEventX = Float.MIN_VALUE;
|
||||
@VisibleForTesting
|
||||
float mTouchUpEventX = Float.MIN_VALUE;
|
||||
private BatteryChartViewV2.OnSelectListener mOnSelectListener;
|
||||
|
||||
public BatteryChartViewV2(Context context) {
|
||||
@@ -161,10 +163,6 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
if (mSelectedIndex != index) {
|
||||
mSelectedIndex = index;
|
||||
invalidate();
|
||||
// Callbacks to the listener if we have.
|
||||
if (mOnSelectListener != null) {
|
||||
mOnSelectListener.onSelect(mSelectedIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,11 +299,9 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
|| !isValidToDraw(trapezoidIndex)) {
|
||||
return;
|
||||
}
|
||||
// Selects all if users click the same trapezoid item two times.
|
||||
if (trapezoidIndex == mSelectedIndex) {
|
||||
setSelectedIndex(SELECTED_INDEX_ALL);
|
||||
} else {
|
||||
setSelectedIndex(trapezoidIndex);
|
||||
if (mOnSelectListener != null) {
|
||||
mOnSelectListener.onSelect(
|
||||
trapezoidIndex == mSelectedIndex ? SELECTED_INDEX_ALL : trapezoidIndex);
|
||||
}
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK);
|
||||
}
|
||||
@@ -614,7 +610,8 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
}
|
||||
|
||||
// A container class for each trapezoid left and right location.
|
||||
private static final class TrapezoidSlot {
|
||||
@VisibleForTesting
|
||||
static final class TrapezoidSlot {
|
||||
public float mLeft;
|
||||
public float mRight;
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
|
||||
public class AutoSyncWorkDataPreferenceController extends AutoSyncPersonalDataPreferenceController {
|
||||
/** An account sync data preference controller for work */
|
||||
public class AutoSyncWorkDataPreferenceController extends AutoSyncDataPreferenceController {
|
||||
|
||||
private static final String KEY_AUTO_SYNC_WORK_ACCOUNT = "auto_sync_work_account_data";
|
||||
|
||||
@@ -38,6 +39,7 @@ public class AutoSyncWorkDataPreferenceController extends AutoSyncPersonalDataPr
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
mUserHandle = Utils.getManagedProfileWithDisabled(mUserManager);
|
||||
return mUserHandle != null && !mUserManager.isManagedProfile() && !mUserManager.isLinkedUser()
|
||||
&& mUserManager.getProfiles(UserHandle.myUserId()).size() > 1;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.settings.wifi;
|
||||
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
|
||||
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -51,6 +52,7 @@ import com.android.wifitrackerlib.WifiEntry;
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
import com.google.android.setupdesign.util.ThemeHelper;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.time.Clock;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
@@ -96,10 +98,12 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
// Interval between initiating NetworkDetailsTracker scans.
|
||||
private static final long SCAN_INTERVAL_MILLIS = 10_000;
|
||||
|
||||
private WifiDialog mDialog;
|
||||
@VisibleForTesting
|
||||
WifiDialog mDialog;
|
||||
private AccessPoint mAccessPoint;
|
||||
|
||||
private WifiDialog2 mDialog2;
|
||||
@VisibleForTesting
|
||||
WifiDialog2 mDialog2;
|
||||
|
||||
// The received intent supports a key of WifiTrackerLib or SettingsLib.
|
||||
private boolean mIsWifiTrackerLib;
|
||||
@@ -108,6 +112,7 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
private NetworkDetailsTracker mNetworkDetailsTracker;
|
||||
private HandlerThread mWorkerThread;
|
||||
private WifiManager mWifiManager;
|
||||
private LockScreenMonitor mLockScreenMonitor;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -184,6 +189,10 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
mDialog.setOnDismissListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (mDialog2 != null || mDialog != null) {
|
||||
mLockScreenMonitor = new LockScreenMonitor(this);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -221,6 +230,10 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
}
|
||||
}
|
||||
|
||||
if (mLockScreenMonitor != null) {
|
||||
mLockScreenMonitor.release();
|
||||
mLockScreenMonitor = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@@ -411,4 +424,45 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void dismissDialog() {
|
||||
if (mDialog != null) {
|
||||
mDialog.dismiss();
|
||||
mDialog = null;
|
||||
}
|
||||
if (mDialog2 != null) {
|
||||
mDialog2.dismiss();
|
||||
mDialog2 = null;
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static final class LockScreenMonitor implements KeyguardManager.KeyguardLockedStateListener {
|
||||
private final WeakReference<WifiDialogActivity> mWifiDialogActivity;
|
||||
private KeyguardManager mKeyguardManager;
|
||||
|
||||
LockScreenMonitor(WifiDialogActivity activity) {
|
||||
mWifiDialogActivity = new WeakReference<>(activity);
|
||||
mKeyguardManager = activity.getSystemService(KeyguardManager.class);
|
||||
mKeyguardManager.addKeyguardLockedStateListener(activity.getMainExecutor(), this);
|
||||
}
|
||||
|
||||
void release() {
|
||||
if (mKeyguardManager == null) return;
|
||||
mKeyguardManager.removeKeyguardLockedStateListener(this);
|
||||
mKeyguardManager = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyguardLockedStateChanged(boolean isKeyguardLocked) {
|
||||
if (!isKeyguardLocked) return;
|
||||
WifiDialogActivity activity = mWifiDialogActivity.get();
|
||||
if (activity == null) return;
|
||||
activity.dismissDialog();
|
||||
|
||||
Log.e(TAG, "Dismiss Wi-Fi dialog to prevent leaking user data on lock screen!");
|
||||
EventLog.writeEvent(0x534e4554, "231583603", -1 /* UID */,
|
||||
"Leak Wi-Fi dialog on lock screen");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.AccessiblePreferenceCategory;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
import com.android.settings.testutils.shadow.ShadowAccountManager;
|
||||
import com.android.settings.testutils.shadow.ShadowContentResolver;
|
||||
@@ -77,7 +77,7 @@ public class AccountPreferenceControllerTest {
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private UserManager mUserManager;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private SettingsPreferenceFragment mFragment;
|
||||
private DashboardFragment mFragment;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private AccountManager mAccountManager;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
|
||||
@@ -297,6 +297,14 @@ public class DashboardFragmentTest {
|
||||
mTestFragment.updatePreferenceVisibility(prefControllers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forceUpdatePreferences_prefKeyNull_shouldNotCrash() {
|
||||
mTestFragment.addPreferenceController(new TestPreferenceController(mContext));
|
||||
|
||||
// Should not crash
|
||||
mTestFragment.forceUpdatePreferences();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkUiBlocker_noUiBlocker_controllerIsNull() {
|
||||
mTestFragment.mBlockerController = null;
|
||||
|
||||
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.when;
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.content.Context;
|
||||
import android.os.LocaleList;
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
@@ -55,6 +56,8 @@ public final class BatteryChartViewV2Test {
|
||||
private AccessibilityServiceInfo mMockAccessibilityServiceInfo;
|
||||
@Mock
|
||||
private AccessibilityManager mMockAccessibilityManager;
|
||||
@Mock
|
||||
private View mMockView;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -74,13 +77,13 @@ public final class BatteryChartViewV2Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAccessibilityEnabled_disable_returnFalse() {
|
||||
public void isAccessibilityEnabled_disable_returnFalse() {
|
||||
doReturn(false).when(mMockAccessibilityManager).isEnabled();
|
||||
assertThat(BatteryChartViewV2.isAccessibilityEnabled(mContext)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAccessibilityEnabled_emptyInfo_returnFalse() {
|
||||
public void isAccessibilityEnabled_emptyInfo_returnFalse() {
|
||||
doReturn(true).when(mMockAccessibilityManager).isEnabled();
|
||||
doReturn(new ArrayList<AccessibilityServiceInfo>())
|
||||
.when(mMockAccessibilityManager)
|
||||
@@ -90,45 +93,41 @@ public final class BatteryChartViewV2Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAccessibilityEnabled_validServiceId_returnTrue() {
|
||||
public void isAccessibilityEnabled_validServiceId_returnTrue() {
|
||||
doReturn(true).when(mMockAccessibilityManager).isEnabled();
|
||||
assertThat(BatteryChartViewV2.isAccessibilityEnabled(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSelectedIndex_invokesCallback() {
|
||||
public void onClick_invokesCallback() {
|
||||
mBatteryChartView.setLevels(new int[] {90, 80, 70, 60});
|
||||
for (int i = 0; i < mBatteryChartView.mTrapezoidSlots.length; i++) {
|
||||
mBatteryChartView.mTrapezoidSlots[i] = new BatteryChartViewV2.TrapezoidSlot();
|
||||
mBatteryChartView.mTrapezoidSlots[i].mLeft = i;
|
||||
mBatteryChartView.mTrapezoidSlots[i].mRight = i + 0.5f;
|
||||
}
|
||||
mBatteryChartView.mSelectedIndex = 2;
|
||||
final int[] selectedIndex = new int[1];
|
||||
final int expectedIndex = 2;
|
||||
mBatteryChartView.mSelectedIndex = 1;
|
||||
mBatteryChartView.setOnSelectListener(
|
||||
trapezoidIndex -> {
|
||||
selectedIndex[0] = trapezoidIndex;
|
||||
});
|
||||
|
||||
mBatteryChartView.setSelectedIndex(expectedIndex);
|
||||
// Verify onClick() a different index 1.
|
||||
mBatteryChartView.mTouchUpEventX = 1;
|
||||
selectedIndex[0] = Integer.MIN_VALUE;
|
||||
mBatteryChartView.onClick(mMockView);
|
||||
assertThat(selectedIndex[0]).isEqualTo(1);
|
||||
|
||||
assertThat(mBatteryChartView.mSelectedIndex)
|
||||
.isEqualTo(expectedIndex);
|
||||
assertThat(selectedIndex[0]).isEqualTo(expectedIndex);
|
||||
// Verify onClick() the same index 2.
|
||||
mBatteryChartView.mTouchUpEventX = 2;
|
||||
selectedIndex[0] = Integer.MIN_VALUE;
|
||||
mBatteryChartView.onClick(mMockView);
|
||||
assertThat(selectedIndex[0]).isEqualTo(BatteryChartViewV2.SELECTED_INDEX_ALL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSelectedIndex_sameIndex_notInvokesCallback() {
|
||||
final int[] selectedIndex = new int[1];
|
||||
final int expectedIndex = 1;
|
||||
mBatteryChartView.mSelectedIndex = expectedIndex;
|
||||
mBatteryChartView.setOnSelectListener(
|
||||
trapezoidIndex -> {
|
||||
selectedIndex[0] = trapezoidIndex;
|
||||
});
|
||||
|
||||
mBatteryChartView.setSelectedIndex(expectedIndex);
|
||||
|
||||
assertThat(selectedIndex[0]).isNotEqualTo(expectedIndex);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickable_isChartGraphSlotsEnabledIsFalse_notClickable() {
|
||||
public void clickable_isChartGraphSlotsEnabledIsFalse_notClickable() {
|
||||
mBatteryChartView.setClickableForce(true);
|
||||
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
|
||||
.thenReturn(false);
|
||||
@@ -139,7 +138,7 @@ public final class BatteryChartViewV2Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickable_accessibilityIsDisabled_clickable() {
|
||||
public void clickable_accessibilityIsDisabled_clickable() {
|
||||
mBatteryChartView.setClickableForce(true);
|
||||
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
|
||||
.thenReturn(true);
|
||||
@@ -151,7 +150,7 @@ public final class BatteryChartViewV2Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickable_accessibilityIsEnabledWithoutValidId_clickable() {
|
||||
public void clickable_accessibilityIsEnabledWithoutValidId_clickable() {
|
||||
mBatteryChartView.setClickableForce(true);
|
||||
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
|
||||
.thenReturn(true);
|
||||
@@ -166,7 +165,7 @@ public final class BatteryChartViewV2Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickable_accessibilityIsEnabledWithValidId_notClickable() {
|
||||
public void clickable_accessibilityIsEnabledWithValidId_notClickable() {
|
||||
mBatteryChartView.setClickableForce(true);
|
||||
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
|
||||
.thenReturn(true);
|
||||
@@ -178,7 +177,7 @@ public final class BatteryChartViewV2Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickable_restoreFromNonClickableState() {
|
||||
public void clickable_restoreFromNonClickableState() {
|
||||
final int[] levels = new int[13];
|
||||
for (int index = 0; index < levels.length; index++) {
|
||||
levels[index] = index + 1;
|
||||
@@ -200,14 +199,14 @@ public final class BatteryChartViewV2Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnAttachedToWindow_addAccessibilityStateChangeListener() {
|
||||
public void onAttachedToWindow_addAccessibilityStateChangeListener() {
|
||||
mBatteryChartView.onAttachedToWindow();
|
||||
verify(mMockAccessibilityManager)
|
||||
.addAccessibilityStateChangeListener(mBatteryChartView);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDetachedFromWindow_removeAccessibilityStateChangeListener() {
|
||||
public void onDetachedFromWindow_removeAccessibilityStateChangeListener() {
|
||||
mBatteryChartView.onAttachedToWindow();
|
||||
mBatteryChartView.mHandler.postDelayed(
|
||||
mBatteryChartView.mUpdateClickableStateRun, 1000);
|
||||
@@ -222,7 +221,7 @@ public final class BatteryChartViewV2Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnAccessibilityStateChanged_postUpdateStateRunnable() {
|
||||
public void onAccessibilityStateChanged_postUpdateStateRunnable() {
|
||||
mBatteryChartView.mHandler = spy(mBatteryChartView.mHandler);
|
||||
mBatteryChartView.onAccessibilityStateChanged(/*enabled=*/ true);
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
@@ -46,7 +47,6 @@ import com.android.wifitrackerlib.WifiEntry;
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -82,6 +82,8 @@ public class WifiDialogActivityTest {
|
||||
Intent mResultData;
|
||||
@Mock
|
||||
WifiConfigController mController;
|
||||
@Mock
|
||||
KeyguardManager mKeyguardManager;
|
||||
|
||||
WifiDialogActivity mActivity;
|
||||
|
||||
@@ -99,6 +101,7 @@ public class WifiDialogActivityTest {
|
||||
mActivity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(mActivity.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||
when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
when(mActivity.getSystemService(KeyguardManager.class)).thenReturn(mKeyguardManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -294,4 +297,35 @@ public class WifiDialogActivityTest {
|
||||
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dismissDialog_hasDialog_dialogDismiss() {
|
||||
mActivity.mDialog = mWifiDialog;
|
||||
mActivity.mDialog2 = mWifiDialog2;
|
||||
|
||||
mActivity.dismissDialog();
|
||||
|
||||
verify(mWifiDialog).dismiss();
|
||||
verify(mWifiDialog2).dismiss();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onKeyguardLockedStateChanged_keyguardIsNotLocked_doNotDismissDialog() {
|
||||
WifiDialogActivity.LockScreenMonitor lockScreenMonitor =
|
||||
new WifiDialogActivity.LockScreenMonitor(mActivity);
|
||||
|
||||
lockScreenMonitor.onKeyguardLockedStateChanged(false /* isKeyguardLocked */);
|
||||
|
||||
verify(mActivity, never()).dismissDialog();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onKeyguardLockedStateChanged_keyguardIsLocked_dismissDialog() {
|
||||
WifiDialogActivity.LockScreenMonitor lockScreenMonitor =
|
||||
new WifiDialogActivity.LockScreenMonitor(mActivity);
|
||||
|
||||
lockScreenMonitor.onKeyguardLockedStateChanged(true /* isKeyguardLocked */);
|
||||
|
||||
verify(mActivity).dismissDialog();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user