Snap for 8509668 from 5b79b590c4 to tm-qpr1-release
Change-Id: I131925840d12cc53c1ef19c478b6d6d42340e496
This commit is contained in:
@@ -81,6 +81,7 @@
|
|||||||
android:id="@+id/phonebook_sharing_message_confirm_pin"
|
android:id="@+id/phonebook_sharing_message_confirm_pin"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="@dimen/min_tap_target_size"
|
||||||
android:layout_marginStart="@dimen/bluetooth_dialog_padding"
|
android:layout_marginStart="@dimen/bluetooth_dialog_padding"
|
||||||
android:layout_marginEnd="@dimen/bluetooth_dialog_padding"
|
android:layout_marginEnd="@dimen/bluetooth_dialog_padding"
|
||||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1" />
|
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1" />
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
** limitations under the License.
|
** limitations under the License.
|
||||||
*/
|
*/
|
||||||
-->
|
-->
|
||||||
<ScrollView
|
<androidx.core.widget.NestedScrollView
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@@ -35,4 +35,4 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|||||||
@@ -5573,6 +5573,10 @@
|
|||||||
<string name="accessibility_vibration_settings_title">Vibration & haptics</string>
|
<string name="accessibility_vibration_settings_title">Vibration & haptics</string>
|
||||||
<!-- Summary for preference screen for configuring vibrations. [CHAR LIMIT=NONE] -->
|
<!-- Summary for preference screen for configuring vibrations. [CHAR LIMIT=NONE] -->
|
||||||
<string name="accessibility_vibration_settings_summary">Control the vibration strength for different usages</string>
|
<string name="accessibility_vibration_settings_summary">Control the vibration strength for different usages</string>
|
||||||
|
<!-- "Vibration & haptics" preference's state when enabled. This text is shown next to the "Vibration & haptics" preference title. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="accessibility_vibration_settings_state_on">On</string>
|
||||||
|
<!-- "Vibration & haptics" preference's state when disabled. This text is shown next to the "Vibration & haptics" preference title. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="accessibility_vibration_settings_state_off">Off</string>
|
||||||
<!-- Summary for vibration preference shown when it is disabled because the device is in silent mode. [CHAR LIMIT=NONE] -->
|
<!-- Summary for vibration preference shown when it is disabled because the device is in silent mode. [CHAR LIMIT=NONE] -->
|
||||||
<string name="accessibility_vibration_setting_disabled_for_silent_mode_summary">Setting disabled because device is set to silent</string>
|
<string name="accessibility_vibration_setting_disabled_for_silent_mode_summary">Setting disabled because device is set to silent</string>
|
||||||
<!-- Title for the category of preferences to configure device vibrations related to calls. [CHAR LIMIT=NONE] -->
|
<!-- Title for the category of preferences to configure device vibrations related to calls. [CHAR LIMIT=NONE] -->
|
||||||
|
|||||||
@@ -416,8 +416,11 @@ public class TetherSettings extends RestrictedSettingsFragment
|
|||||||
if (usbTethered) {
|
if (usbTethered) {
|
||||||
mUsbTether.setEnabled(!mDataSaverEnabled);
|
mUsbTether.setEnabled(!mDataSaverEnabled);
|
||||||
mUsbTether.setChecked(true);
|
mUsbTether.setChecked(true);
|
||||||
mUsbTether.setDisabledByAdmin(
|
final RestrictedLockUtils.EnforcedAdmin enforcedAdmin =
|
||||||
checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId()));
|
checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId());
|
||||||
|
if (enforcedAdmin != null) {
|
||||||
|
mUsbTether.setDisabledByAdmin(enforcedAdmin);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mUsbTether.setChecked(false);
|
mUsbTether.setChecked(false);
|
||||||
updateUsbPreference();
|
updateUsbPreference();
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ public class VibrationPreferenceController extends BasePreferenceController {
|
|||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
final boolean isVibrateOn = Settings.System.getInt(mContext.getContentResolver(),
|
final boolean isVibrateOn = Settings.System.getInt(mContext.getContentResolver(),
|
||||||
Settings.System.VIBRATE_ON, ON) == ON;
|
Settings.System.VIBRATE_ON, ON) == ON;
|
||||||
return mContext.getText(isVibrateOn ? R.string.switch_on_text : R.string.switch_off_text);
|
return mContext.getText(
|
||||||
|
isVibrateOn
|
||||||
|
? R.string.accessibility_vibration_settings_state_on
|
||||||
|
: R.string.accessibility_vibration_settings_state_off);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,12 +113,6 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
|
|||||||
private static final VibrationAttributes FINGERPRINT_ENROLLING_SONFICATION_ATTRIBUTES =
|
private static final VibrationAttributes FINGERPRINT_ENROLLING_SONFICATION_ATTRIBUTES =
|
||||||
VibrationAttributes.createForUsage(VibrationAttributes.USAGE_ACCESSIBILITY);
|
VibrationAttributes.createForUsage(VibrationAttributes.USAGE_ACCESSIBILITY);
|
||||||
|
|
||||||
private static final VibrationAttributes HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES =
|
|
||||||
VibrationAttributes.createForUsage(VibrationAttributes.USAGE_HARDWARE_FEEDBACK);
|
|
||||||
|
|
||||||
private static final VibrationEffect SUCCESS_VIBRATION_EFFECT =
|
|
||||||
VibrationEffect.get(VibrationEffect.EFFECT_CLICK);
|
|
||||||
|
|
||||||
private FingerprintManager mFingerprintManager;
|
private FingerprintManager mFingerprintManager;
|
||||||
private boolean mCanAssumeUdfps;
|
private boolean mCanAssumeUdfps;
|
||||||
@Nullable private ProgressBar mProgressBar;
|
@Nullable private ProgressBar mProgressBar;
|
||||||
@@ -520,13 +514,6 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
|
|||||||
mErrorText.removeCallbacks(mTouchAgainRunnable);
|
mErrorText.removeCallbacks(mTouchAgainRunnable);
|
||||||
mErrorText.postDelayed(mTouchAgainRunnable, HINT_TIMEOUT_DURATION);
|
mErrorText.postDelayed(mTouchAgainRunnable, HINT_TIMEOUT_DURATION);
|
||||||
} else {
|
} else {
|
||||||
if (mVibrator != null) {
|
|
||||||
mVibrator.vibrate(Process.myUid(),
|
|
||||||
getApplicationContext().getOpPackageName(),
|
|
||||||
SUCCESS_VIBRATION_EFFECT,
|
|
||||||
getClass().getSimpleName() + "::OnEnrollmentProgressChanged",
|
|
||||||
HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mIsAccessibilityEnabled) {
|
if (mIsAccessibilityEnabled) {
|
||||||
final int percent = (int) (((float)(steps - remaining) / (float) steps) * 100);
|
final int percent = (int) (((float)(steps - remaining) / (float) steps) * 100);
|
||||||
@@ -599,7 +586,7 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
|
|||||||
mErrorText.setTranslationY(0f);
|
mErrorText.setTranslationY(0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isResumed() && (mIsAccessibilityEnabled || !mCanAssumeUdfps)) {
|
if (isResumed() && mIsAccessibilityEnabled && !mCanAssumeUdfps) {
|
||||||
mVibrator.vibrate(Process.myUid(), getApplicationContext().getOpPackageName(),
|
mVibrator.vibrate(Process.myUid(), getApplicationContext().getOpPackageName(),
|
||||||
VIBRATE_EFFECT_ERROR, getClass().getSimpleName() + "::showError",
|
VIBRATE_EFFECT_ERROR, getClass().getSimpleName() + "::showError",
|
||||||
FINGERPRINT_ENROLLING_SONFICATION_ATTRIBUTES);
|
FINGERPRINT_ENROLLING_SONFICATION_ATTRIBUTES);
|
||||||
|
|||||||
@@ -479,7 +479,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
|
|||||||
@Override
|
@Override
|
||||||
protected void refresh() {
|
protected void refresh() {
|
||||||
for (LocalBluetoothProfile profile : getProfiles()) {
|
for (LocalBluetoothProfile profile : getProfiles()) {
|
||||||
if (profile != null && !profile.isProfileReady()) {
|
if (profile == null || !profile.isProfileReady()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SwitchPreference pref = mProfilesContainer.findPreference(
|
SwitchPreference pref = mProfilesContainer.findPreference(
|
||||||
|
|||||||
@@ -17,17 +17,29 @@
|
|||||||
package com.android.settings.gestures;
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference controller for One-handed mode shortcut settings
|
* Preference controller for One-handed mode shortcut settings
|
||||||
*/
|
*/
|
||||||
public class OneHandedEnablePreferenceController extends BasePreferenceController {
|
public class OneHandedEnablePreferenceController extends BasePreferenceController
|
||||||
|
implements OneHandedSettingsUtils.TogglesCallback, LifecycleObserver, OnStart, OnStop {
|
||||||
|
|
||||||
|
private final OneHandedSettingsUtils mUtils;
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
public OneHandedEnablePreferenceController(Context context, String preferenceKey) {
|
public OneHandedEnablePreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
|
mUtils = new OneHandedSettingsUtils(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -41,4 +53,30 @@ public class OneHandedEnablePreferenceController extends BasePreferenceControlle
|
|||||||
OneHandedSettingsUtils.isOneHandedModeEnabled(mContext)
|
OneHandedSettingsUtils.isOneHandedModeEnabled(mContext)
|
||||||
? R.string.gesture_setting_on : R.string.gesture_setting_off);
|
? R.string.gesture_setting_on : R.string.gesture_setting_off);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
mUtils.registerToggleAwareObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
mUtils.unregisterToggleAwareObserver();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(Uri uri) {
|
||||||
|
if (mPreference == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (uri.equals(OneHandedSettingsUtils.ONE_HANDED_MODE_ENABLED_URI)) {
|
||||||
|
refreshSummary(mPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.network.helper;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.os.Handler;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link BroadcastReceiver} for {@link Intent}.
|
|
||||||
*
|
|
||||||
* This is {@link BroadcastReceiver} supported by {@link LifecycleCallbackConverter},
|
|
||||||
* and only register when state is either START or RESUME.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
public class LifecycleCallbackIntentReceiver extends LifecycleCallbackConverter<Intent> {
|
|
||||||
private static final String TAG = "LifecycleCallbackIntentReceiver";
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected final BroadcastReceiver mReceiver;
|
|
||||||
|
|
||||||
private final Runnable mRegisterCallback;
|
|
||||||
private final Runnable mUnRegisterCallback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
* @param lifecycle {@link Lifecycle} to monitor
|
|
||||||
* @param context for this BroadcastReceiver
|
|
||||||
* @param filter the IntentFilter for BroadcastReceiver
|
|
||||||
* @param broadcastPermission for permission when listening
|
|
||||||
* @param scheduler for running in background thread
|
|
||||||
* @param resultCallback for the Intent from BroadcastReceiver
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
public LifecycleCallbackIntentReceiver(@NonNull Lifecycle lifecycle,
|
|
||||||
@NonNull Context context, @NonNull IntentFilter filter,
|
|
||||||
String broadcastPermission, Handler scheduler,
|
|
||||||
@NonNull Consumer<Intent> resultCallback) {
|
|
||||||
super(lifecycle, resultCallback);
|
|
||||||
|
|
||||||
// BroadcastReceiver
|
|
||||||
mReceiver = new BroadcastReceiver() {
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
if (isInitialStickyBroadcast()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final String action = intent.getAction();
|
|
||||||
if ((action == null) || (action.length() <= 0)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
postResult(intent);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Register operation
|
|
||||||
mRegisterCallback = () -> {
|
|
||||||
Intent initIntent = context.registerReceiver(mReceiver,
|
|
||||||
filter, broadcastPermission, scheduler);
|
|
||||||
if (initIntent != null) {
|
|
||||||
postResult(initIntent);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Un-Register operation
|
|
||||||
mUnRegisterCallback = () -> {
|
|
||||||
context.unregisterReceiver(mReceiver);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCallbackActive(boolean isActive) {
|
|
||||||
super.setCallbackActive(isActive);
|
|
||||||
Runnable op = (isActive) ? mRegisterCallback : mUnRegisterCallback;
|
|
||||||
op.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
super.close();
|
|
||||||
if (isCallbackActive()) {
|
|
||||||
setCallbackActive(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.network.helper;
|
|
||||||
|
|
||||||
import android.telephony.TelephonyCallback;
|
|
||||||
import android.telephony.TelephonyManager;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link LifecycleCallbackConverter} for supporting the register/unregister work for
|
|
||||||
* {@link TelephonyCallback}.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
public class LifecycleCallbackTelephonyAdapter<T> extends LifecycleCallbackConverter<T> {
|
|
||||||
private static final String TAG = "LifecycleCallbackTelephony";
|
|
||||||
|
|
||||||
private final Runnable mRegisterCallback;
|
|
||||||
private final Runnable mUnRegisterCallback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
* @param lifecycle {@link Lifecycle} to monitor
|
|
||||||
* @param telephonyManager {@link TelephonyManager} to interact with
|
|
||||||
* @param telephonyCallback {@link TelephonyCallback}
|
|
||||||
* @param executor {@link Executor} for receiving the notify from telephony framework.
|
|
||||||
* @param resultCallback for the result from {@link TelephonyCallback}
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
public LifecycleCallbackTelephonyAdapter(@NonNull Lifecycle lifecycle,
|
|
||||||
@NonNull TelephonyManager telephonyManager,
|
|
||||||
@NonNull TelephonyCallback telephonyCallback,
|
|
||||||
Executor executor, @NonNull Consumer<T> resultCallback) {
|
|
||||||
super(lifecycle, resultCallback);
|
|
||||||
|
|
||||||
// Register operation
|
|
||||||
mRegisterCallback = () -> {
|
|
||||||
telephonyManager.registerTelephonyCallback(executor, telephonyCallback);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Un-Register operation
|
|
||||||
mUnRegisterCallback = () -> {
|
|
||||||
telephonyManager.unregisterTelephonyCallback(telephonyCallback);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCallbackActive(boolean isActive) {
|
|
||||||
super.setCallbackActive(isActive);
|
|
||||||
Runnable op = (isActive) ? mRegisterCallback : mUnRegisterCallback;
|
|
||||||
op.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -254,7 +254,5 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
|
|||||||
for (OnMainSwitchChangeListener listener : mSwitchChangeListeners) {
|
for (OnMainSwitchChangeListener listener : mSwitchChangeListeners) {
|
||||||
mMainSwitchBar.addOnSwitchChangeListener(listener);
|
mMainSwitchBar.addOnSwitchChangeListener(listener);
|
||||||
}
|
}
|
||||||
mBeforeCheckedChangeListeners.clear();
|
|
||||||
mSwitchChangeListeners.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import android.os.Process;
|
|||||||
import android.os.SimpleClock;
|
import android.os.SimpleClock;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.EventLog;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Size;
|
import android.util.Size;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -58,6 +59,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.qrcode.QrCamera;
|
import com.android.settingslib.qrcode.QrCamera;
|
||||||
import com.android.settingslib.qrcode.QrDecorateView;
|
import com.android.settingslib.qrcode.QrDecorateView;
|
||||||
|
import com.android.settingslib.wifi.WifiPermissionChecker;
|
||||||
import com.android.wifitrackerlib.WifiEntry;
|
import com.android.wifitrackerlib.WifiEntry;
|
||||||
import com.android.wifitrackerlib.WifiPickerTracker;
|
import com.android.wifitrackerlib.WifiPickerTracker;
|
||||||
|
|
||||||
@@ -117,9 +119,9 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
|
|
||||||
private int mLatestStatusCode = WifiDppUtils.EASY_CONNECT_EVENT_FAILURE_NONE;
|
private int mLatestStatusCode = WifiDppUtils.EASY_CONNECT_EVENT_FAILURE_NONE;
|
||||||
|
|
||||||
@VisibleForTesting
|
private WifiPickerTracker mWifiPickerTracker;
|
||||||
WifiPickerTracker mWifiPickerTracker;
|
|
||||||
private HandlerThread mWorkerThread;
|
private HandlerThread mWorkerThread;
|
||||||
|
private WifiPermissionChecker mWifiPermissionChecker;
|
||||||
|
|
||||||
private final Handler mHandler = new Handler() {
|
private final Handler mHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
@@ -363,6 +365,15 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
mIsConfiguratorMode = true;
|
mIsConfiguratorMode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WifiDppQrCodeScannerFragment(WifiPickerTracker wifiPickerTracker,
|
||||||
|
WifiPermissionChecker wifiPermissionChecker) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
mIsConfiguratorMode = true;
|
||||||
|
mWifiPickerTracker = wifiPickerTracker;
|
||||||
|
mWifiPermissionChecker = wifiPermissionChecker;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enrollee container activity of the fragment should create instance with this constructor and
|
* Enrollee container activity of the fragment should create instance with this constructor and
|
||||||
* specify the SSID string of the WI-Fi network to be provisioned.
|
* specify the SSID string of the WI-Fi network to be provisioned.
|
||||||
@@ -719,6 +730,28 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
resultIntent.putExtra(KEY_WIFI_CONFIGURATION, mEnrolleeWifiConfiguration);
|
resultIntent.putExtra(KEY_WIFI_CONFIGURATION, mEnrolleeWifiConfiguration);
|
||||||
|
|
||||||
final Activity hostActivity = getActivity();
|
final Activity hostActivity = getActivity();
|
||||||
|
if (hostActivity == null) return;
|
||||||
|
if (mWifiPermissionChecker == null) {
|
||||||
|
mWifiPermissionChecker = new WifiPermissionChecker(hostActivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mWifiPermissionChecker.canAccessWifiState()) {
|
||||||
|
Log.w(TAG, "Calling package does not have ACCESS_WIFI_STATE permission for result.");
|
||||||
|
EventLog.writeEvent(0x534e4554, "187176859",
|
||||||
|
mWifiPermissionChecker.getLaunchedPackage(), "no ACCESS_WIFI_STATE permission");
|
||||||
|
hostActivity.finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mWifiPermissionChecker.canAccessFineLocation()) {
|
||||||
|
Log.w(TAG, "Calling package does not have ACCESS_FINE_LOCATION permission for result.");
|
||||||
|
EventLog.writeEvent(0x534e4554, "187176859",
|
||||||
|
mWifiPermissionChecker.getLaunchedPackage(),
|
||||||
|
"no ACCESS_FINE_LOCATION permission");
|
||||||
|
hostActivity.finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hostActivity.setResult(Activity.RESULT_OK, resultIntent);
|
hostActivity.setResult(Activity.RESULT_OK, resultIntent);
|
||||||
hostActivity.finish();
|
hostActivity.finish();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class VibrationPreferenceControllerTest {
|
|||||||
controller.updateState(mPreference);
|
controller.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
||||||
mContext.getString(R.string.switch_on_text));
|
mContext.getString(R.string.accessibility_vibration_settings_state_on));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -103,7 +103,7 @@ public class VibrationPreferenceControllerTest {
|
|||||||
controller.updateState(mPreference);
|
controller.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
||||||
mContext.getString(R.string.switch_on_text));
|
mContext.getString(R.string.accessibility_vibration_settings_state_on));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -114,7 +114,7 @@ public class VibrationPreferenceControllerTest {
|
|||||||
controller.updateState(mPreference);
|
controller.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
||||||
mContext.getString(R.string.switch_off_text));
|
mContext.getString(R.string.accessibility_vibration_settings_state_off));
|
||||||
}
|
}
|
||||||
|
|
||||||
private VibrationPreferenceController createPreferenceController() {
|
private VibrationPreferenceController createPreferenceController() {
|
||||||
|
|||||||
@@ -83,12 +83,12 @@ public class FingerprintEnrollEnrollingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fingerprintUdfpsEnrollSuccessProgress_shouldVibrate() {
|
public void fingerprintUdfpsEnrollSuccessProgress_shouldNotVibrate() {
|
||||||
initializeActivityFor(FingerprintSensorProperties.TYPE_UDFPS_OPTICAL);
|
initializeActivityFor(FingerprintSensorProperties.TYPE_UDFPS_OPTICAL);
|
||||||
|
|
||||||
mActivity.onEnrollmentProgressChange(1, 1);
|
mActivity.onEnrollmentProgressChange(1, 1);
|
||||||
|
|
||||||
verify(mVibrator).vibrate(anyInt(), anyString(), any(), anyString(), any());
|
verify(mVibrator, never()).vibrate(anyInt(), anyString(), any(), anyString(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -18,31 +18,27 @@ package com.android.settings.notification.zen;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.robolectric.RuntimeEnvironment.application;
|
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
|
||||||
import org.robolectric.shadows.ShadowToast;
|
import org.robolectric.shadows.ShadowToast;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@@ -54,42 +50,32 @@ public class ZenModeScheduleRuleSettingsTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Intent mIntent;
|
private Intent mIntent;
|
||||||
|
|
||||||
@Mock
|
private ZenModeScheduleRuleSettings mFragment;
|
||||||
private NotificationManager mNotificationManager;
|
|
||||||
|
|
||||||
private TestFragment mFragment;
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
|
||||||
mContext = application;
|
|
||||||
|
|
||||||
mFragment = spy(new TestFragment());
|
Resources res = mContext.getResources();
|
||||||
mFragment.onAttach(application);
|
|
||||||
|
|
||||||
doReturn(mActivity).when(mFragment).getActivity();
|
|
||||||
|
|
||||||
Resources res = application.getResources();
|
|
||||||
|
|
||||||
doReturn(res).when(mFragment).getResources();
|
|
||||||
when(mActivity.getTheme()).thenReturn(res.newTheme());
|
when(mActivity.getTheme()).thenReturn(res.newTheme());
|
||||||
when(mActivity.getIntent()).thenReturn(mIntent);
|
when(mActivity.getIntent()).thenReturn(mIntent);
|
||||||
when(mActivity.getResources()).thenReturn(res);
|
when(mActivity.getResources()).thenReturn(res);
|
||||||
when(mActivity.getMainLooper()).thenReturn(mock(Looper.class));
|
when(mActivity.getMainLooper()).thenReturn(mock(Looper.class));
|
||||||
|
|
||||||
|
mFragment = spy(new ZenModeScheduleRuleSettings());
|
||||||
|
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||||
when(mFragment.getContext()).thenReturn(mContext);
|
when(mFragment.getContext()).thenReturn(mContext);
|
||||||
|
when(mFragment.getResources()).thenReturn(res);
|
||||||
|
mFragment.onAttach(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
public void onAttach_noRuleId_shouldToastAndFinishAndNoCrash() {
|
||||||
public void onCreate_noRuleId_shouldToastAndFinishAndNoCrash() {
|
|
||||||
final String expected = mContext.getString(R.string.zen_mode_rule_not_found_text);
|
final String expected = mContext.getString(R.string.zen_mode_rule_not_found_text);
|
||||||
|
|
||||||
mFragment.onCreate(null);
|
|
||||||
|
|
||||||
// verify the toast
|
// verify the toast
|
||||||
assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(expected);
|
assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(expected);
|
||||||
|
|
||||||
@@ -98,12 +84,4 @@ public class ZenModeScheduleRuleSettingsTest {
|
|||||||
|
|
||||||
//should not crash
|
//should not crash
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TestFragment extends ZenModeScheduleRuleSettings {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Object getSystemService(final String name) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,19 @@ package com.android.settings.wifi.dpp;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.any;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
|
import com.android.settingslib.wifi.WifiPermissionChecker;
|
||||||
import com.android.wifitrackerlib.WifiEntry;
|
import com.android.wifitrackerlib.WifiEntry;
|
||||||
import com.android.wifitrackerlib.WifiPickerTracker;
|
import com.android.wifitrackerlib.WifiPickerTracker;
|
||||||
|
|
||||||
@@ -49,6 +57,10 @@ public class WifiDppQrCodeScannerFragmentTest {
|
|||||||
WifiPickerTracker mWifiPickerTracker;
|
WifiPickerTracker mWifiPickerTracker;
|
||||||
@Mock
|
@Mock
|
||||||
WifiEntry mWifiEntry;
|
WifiEntry mWifiEntry;
|
||||||
|
@Mock
|
||||||
|
WifiPermissionChecker mWifiPermissionChecker;
|
||||||
|
@Mock
|
||||||
|
FragmentActivity mActivity;
|
||||||
|
|
||||||
WifiDppQrCodeScannerFragment mFragment;
|
WifiDppQrCodeScannerFragment mFragment;
|
||||||
|
|
||||||
@@ -57,8 +69,8 @@ public class WifiDppQrCodeScannerFragmentTest {
|
|||||||
when(mWifiEntry.getSsid()).thenReturn(WIFI_SSID);
|
when(mWifiEntry.getSsid()).thenReturn(WIFI_SSID);
|
||||||
when(mWifiPickerTracker.getWifiEntries()).thenReturn(Arrays.asList(mWifiEntry));
|
when(mWifiPickerTracker.getWifiEntries()).thenReturn(Arrays.asList(mWifiEntry));
|
||||||
|
|
||||||
mFragment = spy(new WifiDppQrCodeScannerFragment());
|
mFragment = spy(
|
||||||
mFragment.mWifiPickerTracker = mWifiPickerTracker;
|
new WifiDppQrCodeScannerFragment(mWifiPickerTracker, mWifiPermissionChecker));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -84,4 +96,52 @@ public class WifiDppQrCodeScannerFragmentTest {
|
|||||||
assertThat(mFragment.canConnectWifi(WIFI_SSID)).isFalse();
|
assertThat(mFragment.canConnectWifi(WIFI_SSID)).isFalse();
|
||||||
verify(mFragment).showErrorMessageAndRestartCamera(anyInt());
|
verify(mFragment).showErrorMessageAndRestartCamera(anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSuccess_noWifiPermission_finishActivityWithoutSetResult() {
|
||||||
|
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||||
|
when(mWifiPermissionChecker.canAccessWifiState()).thenReturn(false);
|
||||||
|
when(mWifiPermissionChecker.canAccessFineLocation()).thenReturn(false);
|
||||||
|
|
||||||
|
mFragment.onSuccess();
|
||||||
|
|
||||||
|
verify(mActivity).finish();
|
||||||
|
verify(mActivity, never()).setResult(eq(Activity.RESULT_OK), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSuccess_hasAccessWifiStatePermissionOnly_finishActivityWithoutSetResult() {
|
||||||
|
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||||
|
when(mWifiPermissionChecker.canAccessWifiState()).thenReturn(true);
|
||||||
|
when(mWifiPermissionChecker.canAccessFineLocation()).thenReturn(false);
|
||||||
|
|
||||||
|
mFragment.onSuccess();
|
||||||
|
|
||||||
|
verify(mActivity).finish();
|
||||||
|
verify(mActivity, never()).setResult(eq(Activity.RESULT_OK), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSuccess_hasAccessFineLocationPermissionOnly_finishActivityWithoutSetResult() {
|
||||||
|
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||||
|
when(mWifiPermissionChecker.canAccessWifiState()).thenReturn(false);
|
||||||
|
when(mWifiPermissionChecker.canAccessFineLocation()).thenReturn(true);
|
||||||
|
|
||||||
|
mFragment.onSuccess();
|
||||||
|
|
||||||
|
verify(mActivity).finish();
|
||||||
|
verify(mActivity, never()).setResult(eq(Activity.RESULT_OK), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSuccess_hasRequiredPermissions_finishActivityWithSetResult() {
|
||||||
|
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||||
|
when(mWifiPermissionChecker.canAccessWifiState()).thenReturn(true);
|
||||||
|
when(mWifiPermissionChecker.canAccessFineLocation()).thenReturn(true);
|
||||||
|
|
||||||
|
mFragment.onSuccess();
|
||||||
|
|
||||||
|
verify(mActivity).setResult(eq(Activity.RESULT_OK), any());
|
||||||
|
verify(mActivity).finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ public class LifecycleCallbackConverterTest implements LifecycleOwner {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
mTestData = new Object();
|
mTestData = new Object();
|
||||||
mConsumer = new TestConsumer();
|
mConsumer = new TestConsumer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initEnvPerTestCase() {
|
||||||
mConverter = new LifecycleCallbackConverter<Object>(getLifecycle(), mConsumer);
|
mConverter = new LifecycleCallbackConverter<Object>(getLifecycle(), mConsumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +55,7 @@ public class LifecycleCallbackConverterTest implements LifecycleOwner {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void converter_dropResult_whenInActive() {
|
public void converter_dropResult_whenInActive() {
|
||||||
|
initEnvPerTestCase();
|
||||||
mConverter.postResult(mTestData);
|
mConverter.postResult(mTestData);
|
||||||
|
|
||||||
assertThat(mConsumer.getCallbackCount()).isEqualTo(0);
|
assertThat(mConsumer.getCallbackCount()).isEqualTo(0);
|
||||||
@@ -59,6 +63,7 @@ public class LifecycleCallbackConverterTest implements LifecycleOwner {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void converter_callbackResult_whenActive() {
|
public void converter_callbackResult_whenActive() {
|
||||||
|
initEnvPerTestCase();
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
||||||
|
|
||||||
@@ -69,6 +74,7 @@ public class LifecycleCallbackConverterTest implements LifecycleOwner {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void converter_dropResult_whenBackToInActive() {
|
public void converter_dropResult_whenBackToInActive() {
|
||||||
|
initEnvPerTestCase();
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
|
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
|
||||||
@@ -79,6 +85,7 @@ public class LifecycleCallbackConverterTest implements LifecycleOwner {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void converter_passResultToUiThread_whenActive() {
|
public void converter_passResultToUiThread_whenActive() {
|
||||||
|
initEnvPerTestCase();
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
||||||
|
|
||||||
|
|||||||
@@ -1,184 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.network.helper;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.lifecycle.LifecycleRegistry;
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class LifecycleCallbackIntentReceiverTest implements LifecycleOwner {
|
|
||||||
|
|
||||||
private final LifecycleRegistry mRegistry = LifecycleRegistry.createUnsafe(this);
|
|
||||||
|
|
||||||
private static final String TEST_SCHEDULER_HANDLER = "testScheduler";
|
|
||||||
private static final String TEST_INTENT_ACTION = "testAction";
|
|
||||||
private static final String TEST_INTENT_PERMISSION = "testPermission";
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private Intent mIntent;
|
|
||||||
private IntentFilter mIntentFilter;
|
|
||||||
private Handler mHandler;
|
|
||||||
private TestConsumer mConsumer;
|
|
||||||
|
|
||||||
private TestObj mTarget;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
mContext = ApplicationProvider.getApplicationContext();
|
|
||||||
|
|
||||||
mIntentFilter = new IntentFilter(TEST_INTENT_ACTION);
|
|
||||||
mIntent = new Intent(TEST_INTENT_ACTION);
|
|
||||||
|
|
||||||
HandlerThread thread = new HandlerThread(TEST_SCHEDULER_HANDLER);
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
mHandler = new Handler(thread.getLooper());
|
|
||||||
mConsumer = new TestConsumer();
|
|
||||||
|
|
||||||
mTarget = new TestObj(getLifecycle(), mContext,
|
|
||||||
mIntentFilter, TEST_INTENT_PERMISSION,
|
|
||||||
mHandler, mConsumer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Lifecycle getLifecycle() {
|
|
||||||
return mRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void receiver_register_whenActive() {
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
|
||||||
|
|
||||||
assertThat(mTarget.getCallbackActiveCount(true)
|
|
||||||
+ mTarget.getCallbackActiveCount(false)).isEqualTo(0);
|
|
||||||
|
|
||||||
mTarget.mReceiver.onReceive(mContext, mIntent);
|
|
||||||
|
|
||||||
assertThat(mConsumer.getCallbackCount()).isEqualTo(0);
|
|
||||||
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
|
||||||
|
|
||||||
assertThat(mTarget.getCallbackActiveCount(true)).isEqualTo(1);
|
|
||||||
assertThat(mConsumer.getCallbackCount()).isEqualTo(0);
|
|
||||||
|
|
||||||
mTarget.mReceiver.onReceive(mContext, mIntent);
|
|
||||||
|
|
||||||
assertThat(mConsumer.getCallbackCount()).isEqualTo(1);
|
|
||||||
assertThat(mConsumer.getData()).isEqualTo(mIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void receiver_unregister_whenInActive() {
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
|
|
||||||
|
|
||||||
assertThat(mTarget.getCallbackActiveCount(false)).isEqualTo(1);
|
|
||||||
|
|
||||||
mTarget.mReceiver.onReceive(mContext, mIntent);
|
|
||||||
|
|
||||||
assertThat(mConsumer.getCallbackCount()).isEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void receiver_register_whenReActive() {
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
|
||||||
|
|
||||||
assertThat(mTarget.getCallbackActiveCount(true)).isEqualTo(2);
|
|
||||||
|
|
||||||
mTarget.mReceiver.onReceive(mContext, mIntent);
|
|
||||||
|
|
||||||
assertThat(mConsumer.getCallbackCount()).isEqualTo(1);
|
|
||||||
assertThat(mConsumer.getData()).isEqualTo(mIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void receiver_close_whenDestroy() {
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
|
|
||||||
|
|
||||||
assertThat(mTarget.getCallbackActiveCount(false)).isEqualTo(1);
|
|
||||||
|
|
||||||
mTarget.mReceiver.onReceive(mContext, mIntent);
|
|
||||||
|
|
||||||
assertThat(mConsumer.getCallbackCount()).isEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TestConsumer implements Consumer<Intent> {
|
|
||||||
long mNumberOfCallback;
|
|
||||||
Intent mLatestData;
|
|
||||||
|
|
||||||
public TestConsumer() {}
|
|
||||||
|
|
||||||
public void accept(Intent data) {
|
|
||||||
mLatestData = data;
|
|
||||||
mNumberOfCallback ++;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected long getCallbackCount() {
|
|
||||||
return mNumberOfCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Intent getData() {
|
|
||||||
return mLatestData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TestObj extends LifecycleCallbackIntentReceiver {
|
|
||||||
long mCallbackActiveCount;
|
|
||||||
long mCallbackInActiveCount;
|
|
||||||
|
|
||||||
public TestObj(Lifecycle lifecycle, Context context, IntentFilter filter,
|
|
||||||
String broadcastPermission, Handler scheduler, Consumer<Intent> resultCallback) {
|
|
||||||
super(lifecycle, context, filter, broadcastPermission, scheduler, resultCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCallbackActive(boolean isActive) {
|
|
||||||
if (isActive) {
|
|
||||||
mCallbackActiveCount ++;
|
|
||||||
} else {
|
|
||||||
mCallbackInActiveCount ++;
|
|
||||||
}
|
|
||||||
super.setCallbackActive(isActive);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected long getCallbackActiveCount(boolean forActive) {
|
|
||||||
return forActive ? mCallbackActiveCount : mCallbackInActiveCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.network.helper;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyObject;
|
|
||||||
import static org.mockito.Mockito.doNothing;
|
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
import android.telephony.TelephonyCallback;
|
|
||||||
import android.telephony.TelephonyManager;
|
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.lifecycle.LifecycleRegistry;
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class LifecycleCallbackTelephonyAdapterTest implements LifecycleOwner {
|
|
||||||
|
|
||||||
private final LifecycleRegistry mRegistry = LifecycleRegistry.createUnsafe(this);
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private TelephonyManager mTelMgr;
|
|
||||||
|
|
||||||
private TestCallback mTestCallback;
|
|
||||||
private AtomicReference<Object> mResult;
|
|
||||||
private LifecycleCallbackTelephonyAdapter<Object> mAdapter;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
mResult = new AtomicReference<Object>();
|
|
||||||
mTestCallback = new TestCallback();
|
|
||||||
|
|
||||||
doNothing().when(mTelMgr).registerTelephonyCallback(null, mTestCallback);
|
|
||||||
doNothing().when(mTelMgr).unregisterTelephonyCallback(mTestCallback);
|
|
||||||
|
|
||||||
mAdapter = new LifecycleCallbackTelephonyAdapter<Object>(getLifecycle(), mTelMgr,
|
|
||||||
mTestCallback, null, result -> mResult.set(result));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Lifecycle getLifecycle() {
|
|
||||||
return mRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void telephonyCallback_register_whenActive() {
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
|
||||||
|
|
||||||
verify(mTelMgr, never()).registerTelephonyCallback(anyObject(), anyObject());
|
|
||||||
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
|
||||||
|
|
||||||
verify(mTelMgr).registerTelephonyCallback(anyObject(), anyObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void telephonyCallback_unregister_whenInActive() {
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
|
||||||
|
|
||||||
verify(mTelMgr, never()).unregisterTelephonyCallback(anyObject());
|
|
||||||
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
|
||||||
|
|
||||||
verify(mTelMgr, never()).unregisterTelephonyCallback(anyObject());
|
|
||||||
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
|
|
||||||
|
|
||||||
verify(mTelMgr).unregisterTelephonyCallback(anyObject());
|
|
||||||
|
|
||||||
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
|
|
||||||
|
|
||||||
verify(mTelMgr, times(1)).unregisterTelephonyCallback(anyObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static class TestCallback extends TelephonyCallback
|
|
||||||
implements TelephonyCallback.CallStateListener {
|
|
||||||
@Override
|
|
||||||
public void onCallStateChanged(int state) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user