Merge "Fix adding wifi configuration issue" into tm-dev
diff --git a/res/layout/tare_dropdown_page.xml b/res/layout/tare_dropdown_page.xml
index 674b189..9ec7ebf 100644
--- a/res/layout/tare_dropdown_page.xml
+++ b/res/layout/tare_dropdown_page.xml
@@ -16,8 +16,10 @@
       android:theme="@style/Widget.PopupWindow.Settings" />
   <FrameLayout
       android:id="@+id/frame_layout"
-      android:layout_width="match_parent"
+      android:layout_width="0dp"
       android:layout_height="wrap_content"
+      app:layout_constrainedWidth="true"
+      app:layout_constrainedHeight="true"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintStart_toStartOf="parent"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ef6a3c7..2d3532c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -10467,8 +10467,14 @@
         <item quantity="other"><xliff:g id="count" example="10">%d</xliff:g> unused apps</item>
     </plurals>
 
-    <!-- Label of a switch preference that controls whether the system will remove the permissions and free up space when the app has not been used for months [CHAR LIMIT=40]-->
-    <string name="unused_apps_switch">Remove permissions and free up space</string>
+    <!-- Label for category for unused app settings for an app. [CHAR LIMIT=40]-->
+    <string name="unused_apps_category">Unused app settings</string>
+
+    <!-- Label of a switch preference that controls whether the system will pause app activity when the app has not been used for months [CHAR LIMIT=40]-->
+    <string name="unused_apps_switch">Pause app activity</string>
+
+    <!-- Summary of the switch preference that controls whether the system will pause app activity when the app has not been used for months [CHAR LIMIT=NONE]-->
+    <string name="unused_apps_switch_summary">Remove permissions, delete temporary files, and stop notifications if unused</string>
 
     <!-- Label for showing all apps in list [CHAR LIMIT=30] -->
     <string name="filter_all_apps">All apps</string>
@@ -13514,6 +13520,11 @@
     <!-- Summary for allowing screen overlays on Settings app. [CHAR LIMIT=NONE]-->
     <string name="overlay_settings_summary">Allow apps that can display over other apps to overlay Settings screens</string>
 
+    <!-- Developer settings: Title for allowing mock modem service for testing. [CHAR LIMIT=50]-->
+    <string name="allow_mock_modem">Allow Mock Modem</string>
+    <!-- Developer settings: Summary for allowing mock modem service. [CHAR LIMIT=NONE]-->
+    <string name="allow_mock_modem_summary">Allow this device to run Mock Modem service for instrumentation testing. Do not enable this during normal usage of the phone</string>
+
     <!-- Title for media control settings [CHAR LIMIT=50]-->
     <string name="media_controls_title">Media</string>
     <!-- Title of toggle to enable or disable the media resumption feature in quick settings [CHAR LIMIT=50]-->
@@ -13887,9 +13898,15 @@
     <string name="tare_actions_ctp">Actions (Cost to Produce)</string>
     <!-- Title for the various TARE policy's actions' starting prices [CHAR LIMIT=40]-->
     <string name="tare_actions_base_price">Actions (Base Price)</string>
-    <!-- Title for the instant, ongoing, and max rewards apps can obtain for different actions that
-    benefit the user. [CHAR LIMIT=40]-->
-    <string name="tare_rewards">Rewards</string>
+    <!-- Title for the rewards apps can obtain for each instance of an event that implies the user
+    finds the app behavior useful. [CHAR LIMIT=40]-->
+    <string name="tare_rewards_instantaneous">Rewards per single event</string>
+    <!-- Title for the rewards apps can obtain for the total duration (in seconds) of an event that
+    implies the user finds the app behavior useful. [CHAR LIMIT=40]-->
+    <string name="tare_rewards_ongoing">Rewards for total event duration</string>
+    <!-- Title for the max rewards apps can obtain within a 24 hour period for different actions
+    that benefit the user. [CHAR LIMIT=40]-->
+    <string name="tare_rewards_max">Maximum Rewards Per Day</string>
     <!-- Title for the Allow While Idle Exact Wakeup Alarm set via
     AlarmManager.setExactAndAllowWhileIdle() [CHAR LIMIT=50]-->
     <string name="tare_wakeup_exact_idle" translatable="false">
@@ -14025,7 +14042,7 @@
     <string-array name="tare_rewards_subfactors" translatable="false">
         <item>@string/tare_top_activity</item>
         <item>@string/tare_notification_seen</item>
-        <item>@string/tare_notification_seen_15_min</item>
+        <!-- TODO: add back once supported  <item>@string/tare_notification_seen_15_min</item> -->
         <item>@string/tare_notification_interaction</item>
         <item>@string/tare_widget_interaction</item>
         <item>@string/tare_other_interaction</item>
@@ -14088,7 +14105,7 @@
     <string name="placeholder_activity" translatable="false">*This is a temporary placeholder fallback activity.</string>
 
     <!-- The title of the spatial audio [CHAR LIMIT=none] -->
-    <string name="bluetooth_details_spatial_audio_title">Spatial audio</string>
+    <string name="bluetooth_details_spatial_audio_title">Spatial Audio</string>
     <!-- The summary of the spatial audio [CHAR LIMIT=none] -->
     <string name="bluetooth_details_spatial_audio_summary">Audio from compatible media becomes more immersive</string>
     <!-- The title of the head tracking [CHAR LIMIT=none] -->
diff --git a/res/xml/app_info_settings.xml b/res/xml/app_info_settings.xml
index bb5fbae..95fefb6 100644
--- a/res/xml/app_info_settings.xml
+++ b/res/xml/app_info_settings.xml
@@ -148,6 +148,7 @@
         <SwitchPreference
             android:key="hibernation_switch"
             android:title="@string/unused_apps_switch"
+            android:summary="@string/unused_apps_switch_summary"
             settings:controller=
                 "com.android.settings.applications.appinfo.HibernationSwitchPreferenceController" />
     </PreferenceCategory>
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index 9867419..89e5167 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -250,6 +250,11 @@
             android:title="@string/force_high_refresh_rate_toggle"
             android:summary="@string/force_high_refresh_rate_desc" />
 
+        <SwitchPreference
+            android:key="allow_mock_modem"
+            android:title="@string/allow_mock_modem"
+            android:summary="@string/allow_mock_modem_summary" />
+
     </PreferenceCategory>
 
     <PreferenceCategory
diff --git a/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java b/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
index 6441eeb..bc8c600 100644
--- a/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
+++ b/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
@@ -73,11 +73,11 @@
         mSettingsContentObserver.onDisplayPreference(this, preference);
         preference.setEnabled(mPreferenceConfig.isPreferenceEnabled());
         preference.setSummaryProvider(unused -> mPreferenceConfig.getSummary());
-        // TODO: remove setContinuousUpdates and replace with a different way to play the haptic
-        // preview without relying on the setting being propagated to the service.
-        preference.setContinuousUpdates(true);
         preference.setMin(getMin());
         preference.setMax(getMax());
+        // Haptics previews played by the Settings app don't bypass user settings to be played.
+        // The sliders continuously updates the intensity value so the previews can apply them.
+        preference.setContinuousUpdates(true);
     }
 
     @Override
diff --git a/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceController.java b/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceController.java
index 726bbc1..02e8926 100644
--- a/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceController.java
+++ b/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceController.java
@@ -23,6 +23,8 @@
 import android.database.ContentObserver;
 import android.net.Uri;
 import android.os.Handler;
+import android.os.VibrationAttributes;
+import android.os.Vibrator;
 import android.provider.Settings;
 
 import com.android.settings.R;
@@ -42,9 +44,11 @@
         implements LifecycleObserver, OnStart, OnStop {
 
     private final ContentObserver mSettingObserver;
+    private final Vibrator mVibrator;
 
     public VibrationMainSwitchPreferenceController(Context context, String preferenceKey) {
         super(context, preferenceKey);
+        mVibrator = context.getSystemService(Vibrator.class);
         mSettingObserver = new ContentObserver(new Handler(/* async= */ true)) {
             @Override
             public void onChange(boolean selfChange, Uri uri) {
@@ -79,9 +83,17 @@
 
     @Override
     public boolean setChecked(boolean isChecked) {
-        return Settings.System.putInt(mContext.getContentResolver(),
+        boolean success = Settings.System.putInt(mContext.getContentResolver(),
                 VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY,
                 isChecked ? ON : OFF);
+
+        if (success && isChecked) {
+            // Play a haptic as preview for the main toggle only when touch feedback is enabled.
+            VibrationPreferenceConfig.playVibrationPreview(
+                    mVibrator, VibrationAttributes.USAGE_TOUCH);
+        }
+
+        return success;
     }
 
     @Override
diff --git a/src/com/android/settings/accessibility/VibrationPreferenceConfig.java b/src/com/android/settings/accessibility/VibrationPreferenceConfig.java
index 9208b18..b4be528 100644
--- a/src/com/android/settings/accessibility/VibrationPreferenceConfig.java
+++ b/src/com/android/settings/accessibility/VibrationPreferenceConfig.java
@@ -49,6 +49,8 @@
      * all device vibrations.
      */
     public static final String MAIN_SWITCH_SETTING_KEY = Settings.System.VIBRATE_ON;
+    private static final VibrationEffect PREVIEW_VIBRATION_EFFECT =
+            VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK);
 
     protected final ContentResolver mContentResolver;
     private final AudioManager mAudioManager;
@@ -56,14 +58,22 @@
     private final String mSettingKey;
     private final String mRingerModeSilentSummary;
     private final int mDefaultIntensity;
-    private final VibrationAttributes mVibrationAttributes;
+    private final VibrationAttributes mPreviewVibrationAttributes;
 
     /** Returns true if the user setting for enabling device vibrations is enabled. */
     public static boolean isMainVibrationSwitchEnabled(ContentResolver contentResolver) {
         return Settings.System.getInt(contentResolver, MAIN_SWITCH_SETTING_KEY, ON) == ON;
     }
 
-    public VibrationPreferenceConfig(Context context, String settingKey, int vibrationUsage) {
+    /** Play a vibration effect with intensity just selected by the user. */
+    public static void playVibrationPreview(Vibrator vibrator,
+            @VibrationAttributes.Usage int vibrationUsage) {
+        vibrator.vibrate(PREVIEW_VIBRATION_EFFECT,
+                createPreviewVibrationAttributes(vibrationUsage));
+    }
+
+    public VibrationPreferenceConfig(Context context, String settingKey,
+            @VibrationAttributes.Usage int vibrationUsage) {
         mContentResolver = context.getContentResolver();
         mVibrator = context.getSystemService(Vibrator.class);
         mAudioManager = context.getSystemService(AudioManager.class);
@@ -71,9 +81,7 @@
                 R.string.accessibility_vibration_setting_disabled_for_silent_mode_summary);
         mSettingKey = settingKey;
         mDefaultIntensity = mVibrator.getDefaultVibrationIntensity(vibrationUsage);
-        mVibrationAttributes = new VibrationAttributes.Builder()
-                .setUsage(vibrationUsage)
-                .build();
+        mPreviewVibrationAttributes = createPreviewVibrationAttributes(vibrationUsage);
     }
 
     /** Returns the setting key for this setting preference. */
@@ -118,8 +126,7 @@
 
     /** Play a vibration effect with intensity just selected by the user. */
     public void playVibrationPreview() {
-        mVibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK),
-                mVibrationAttributes);
+        mVibrator.vibrate(PREVIEW_VIBRATION_EFFECT, mPreviewVibrationAttributes);
     }
 
     private boolean isRingerModeSilent() {
@@ -128,6 +135,16 @@
         return mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT;
     }
 
+    private static VibrationAttributes createPreviewVibrationAttributes(
+            @VibrationAttributes.Usage int vibrationUsage) {
+        return new VibrationAttributes.Builder()
+                .setUsage(vibrationUsage)
+                // Enforce fresh settings to be applied for the preview vibration, as they
+                // are played immediately after the new user values are set.
+                .setFlags(VibrationAttributes.FLAG_INVALIDATE_SETTINGS_CACHE)
+                .build();
+    }
+
     /** {@link ContentObserver} for a setting described by a {@link VibrationPreferenceConfig}. */
     public static final class SettingObserver extends ContentObserver {
         private static final Uri MAIN_SWITCH_SETTING_URI =
diff --git a/src/com/android/settings/accessibility/VibrationRampingRingerTogglePreferenceController.java b/src/com/android/settings/accessibility/VibrationRampingRingerTogglePreferenceController.java
index 8d1b43e..149bed3 100644
--- a/src/com/android/settings/accessibility/VibrationRampingRingerTogglePreferenceController.java
+++ b/src/com/android/settings/accessibility/VibrationRampingRingerTogglePreferenceController.java
@@ -124,6 +124,12 @@
         if (isRingVibrationEnabled()) {
             // Don't update ramping ringer setting value if ring vibration is disabled.
             mAudioManager.setRampingRingerEnabled(isChecked);
+
+            if (isChecked) {
+                // Vibrate when toggle is enabled for consistency with all the other toggle/slides
+                // in the same screen.
+                mRingVibrationPreferenceConfig.playVibrationPreview();
+            }
         }
         return true;
     }
diff --git a/src/com/android/settings/bluetooth/LeAudioBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/LeAudioBluetoothDetailsHeaderController.java
index 06cee85..7b74f77 100644
--- a/src/com/android/settings/bluetooth/LeAudioBluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/LeAudioBluetoothDetailsHeaderController.java
@@ -275,11 +275,15 @@
                 return;
             }
             boolean isLeft = (deviceId & LEFT_DEVICE_ID) != 0;
-            boolean isRight = (deviceId & LEFT_DEVICE_ID) != 0;
+            boolean isRight = (deviceId & RIGHT_DEVICE_ID) != 0;
             boolean isLeftRight = isLeft && isRight;
             // The LE device updates the BatteryLayout
             if (isLeftRight) {
-                Log.d(TAG, "The device id is left+right. Do nothing.");
+                Log.d(TAG, "Show the legacy battery style if the device id is left+right.");
+                final TextView summary = mLayoutPreference.findViewById(R.id.entity_header_summary);
+                if (summary != null) {
+                    summary.setText(mCachedDevice.getConnectionSummary());
+                }
             } else if (isLeft) {
                 updateBatteryLayout(getBatteryTitleResource(LEFT_DEVICE_ID),
                         getBatterySummaryResource(LEFT_DEVICE_ID), cachedDevice.getBatteryLevel());
diff --git a/src/com/android/settings/core/BasePreferenceController.java b/src/com/android/settings/core/BasePreferenceController.java
index c90fe48..6cc09e2 100644
--- a/src/com/android/settings/core/BasePreferenceController.java
+++ b/src/com/android/settings/core/BasePreferenceController.java
@@ -121,10 +121,13 @@
 
     protected final String mPreferenceKey;
     protected UiBlockListener mUiBlockListener;
+    protected boolean mUiBlockerFinished;
     private boolean mIsForWork;
     @Nullable
     private UserHandle mWorkProfileUser;
     private int mMetricsCategory;
+    private boolean mIsFirstLaunch;
+    private boolean mPrefVisibility;
 
     /**
      * Instantiate a controller as specified controller type and user-defined key.
@@ -195,6 +198,8 @@
     public BasePreferenceController(Context context, String preferenceKey) {
         super(context);
         mPreferenceKey = preferenceKey;
+        mIsFirstLaunch = true;
+        mPrefVisibility = true;
         if (TextUtils.isEmpty(mPreferenceKey)) {
             throw new IllegalArgumentException("Preference key must be set");
         }
@@ -327,6 +332,13 @@
     }
 
     /**
+     * Set back the value of whether this is the first launch.
+     */
+    public void revokeFirstLaunch() {
+        mIsFirstLaunch = false;
+    }
+
+    /**
      * Launches the specified fragment for the work profile user if the associated
      * {@link Preference} is clicked.  Otherwise just forward it to the super class.
      *
@@ -378,6 +390,14 @@
         mUiBlockListener = uiBlockListener;
     }
 
+    public void setUiBlockerFinished(boolean isFinished) {
+        mUiBlockerFinished = isFinished;
+    }
+
+    public boolean getSavedPrefVisibility() {
+        return mPrefVisibility;
+    }
+
     /**
      * Listener to invoke when background job is finished
      */
@@ -428,4 +448,28 @@
     protected UserHandle getWorkProfileUser() {
         return mWorkProfileUser;
     }
+
+    /**
+     * Used for {@link BasePreferenceController} that implements {@link UiBlocker} to control the
+     * preference visibility.
+     */
+    protected void updatePreferenceVisibilityDelegate(Preference preference, boolean isVisible) {
+        if (mUiBlockerFinished || !mIsFirstLaunch) {
+            preference.setVisible(isVisible);
+            return;
+        }
+
+        savePrefVisibility(isVisible);
+
+        // Preferences that should be invisible have a high priority to be updated since the
+        // whole UI should be blocked/invisible. While those that should be visible will be
+        // updated once the blocker work is finished. That's done in DashboardFragment.
+        if (!isVisible) {
+            preference.setVisible(false);
+        }
+    }
+
+    private void savePrefVisibility(boolean isVisible) {
+        mPrefVisibility = isVisible;
+    }
 }
diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java
index 6ac0fa4..bff8226 100644
--- a/src/com/android/settings/dashboard/DashboardFragment.java
+++ b/src/com/android/settings/dashboard/DashboardFragment.java
@@ -250,6 +250,11 @@
             }
             mListeningToCategoryChange = false;
         }
+        mControllers.forEach(controller -> {
+            if (controller instanceof BasePreferenceController.UiBlocker) {
+                ((BasePreferenceController) controller).revokeFirstLaunch();
+            }
+        });
     }
 
     @Override
@@ -424,7 +429,14 @@
             for (AbstractPreferenceController controller : controllerList) {
                 final String key = controller.getPreferenceKey();
                 final Preference preference = findPreference(key);
-                if (preference != null) {
+                if (preference == null) {
+                    continue;
+                }
+                if (controller instanceof BasePreferenceController.UiBlocker) {
+                    final boolean prefVisible =
+                            ((BasePreferenceController) controller).getSavedPrefVisibility();
+                    preference.setVisible(visible && controller.isAvailable() && prefVisible);
+                } else {
                     preference.setVisible(visible && controller.isAvailable());
                 }
             }
@@ -496,6 +508,7 @@
     @Override
     public void onBlockerWorkFinished(BasePreferenceController controller) {
         mBlockerController.countDown(controller.getPreferenceKey());
+        controller.setUiBlockerFinished(mBlockerController.isBlockerFinished());
     }
 
     protected Preference createPreference(Tile tile) {
diff --git a/src/com/android/settings/dashboard/UiBlockerController.java b/src/com/android/settings/dashboard/UiBlockerController.java
index 710175b..b3729f1 100644
--- a/src/com/android/settings/dashboard/UiBlockerController.java
+++ b/src/com/android/settings/dashboard/UiBlockerController.java
@@ -37,7 +37,7 @@
  */
 public class UiBlockerController {
     private static final String TAG = "UiBlockerController";
-    private static final int TIMEOUT_MILLIS = 500;
+    private static final int TIMEOUT_MILLIS = 300;
 
     private CountDownLatch mCountDownLatch;
     private boolean mBlockerFinished;
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 085a372..722e94e 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -518,6 +518,7 @@
         controllers.add(new BugReportInPowerPreferenceController(context));
         controllers.add(new AutomaticSystemServerHeapDumpPreferenceController(context));
         controllers.add(new MockLocationAppPreferenceController(context, fragment));
+        controllers.add(new MockModemPreferenceController(context));
         controllers.add(new DebugViewAttributesPreferenceController(context));
         controllers.add(new SelectDebugAppPreferenceController(context, fragment));
         controllers.add(new WaitForDebuggerPreferenceController(context));
diff --git a/src/com/android/settings/development/MockModemPreferenceController.java b/src/com/android/settings/development/MockModemPreferenceController.java
new file mode 100644
index 0000000..655f157
--- /dev/null
+++ b/src/com/android/settings/development/MockModemPreferenceController.java
@@ -0,0 +1,86 @@
+/*
+ * 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.development;
+
+import android.content.Context;
+import android.os.SystemProperties;
+import android.util.Log;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+/**
+ * PreferenceController for MockModem
+ */
+public class MockModemPreferenceController extends
+        DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
+        PreferenceControllerMixin {
+
+    private static final String TAG = "MockModemPreferenceController";
+    private static final String ALLOW_MOCK_MODEM_KEY =
+            "allow_mock_modem";
+    @VisibleForTesting
+    static final String ALLOW_MOCK_MODEM_PROPERTY =
+            "persist.radio.allow_mock_modem";
+
+    public MockModemPreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return ALLOW_MOCK_MODEM_KEY;
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        final boolean isEnabled = (Boolean) newValue;
+        try {
+            SystemProperties.set(ALLOW_MOCK_MODEM_PROPERTY,
+                    isEnabled ? "true" : "false");
+        } catch (RuntimeException e) {
+            Log.e(TAG, "Fail to set radio system property: " + e.getMessage());
+        }
+        return true;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        try {
+            final boolean isEnabled = SystemProperties.getBoolean(
+                    ALLOW_MOCK_MODEM_PROPERTY, false /* default */);
+            ((SwitchPreference) mPreference).setChecked(isEnabled);
+        } catch (RuntimeException e) {
+            Log.e(TAG, "Fail to get radio system property: " + e.getMessage());
+        }
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchDisabled() {
+        super.onDeveloperOptionsSwitchDisabled();
+        try {
+            SystemProperties.set(ALLOW_MOCK_MODEM_PROPERTY, "false");
+            ((SwitchPreference) mPreference).setChecked(false);
+        } catch (RuntimeException e) {
+            Log.e(TAG, "Fail to set radio system property: " + e.getMessage());
+        }
+    }
+}
diff --git a/src/com/android/settings/development/tare/AlarmManagerFragment.java b/src/com/android/settings/development/tare/AlarmManagerFragment.java
index c4dca37..980954d 100644
--- a/src/com/android/settings/development/tare/AlarmManagerFragment.java
+++ b/src/com/android/settings/development/tare/AlarmManagerFragment.java
@@ -97,7 +97,8 @@
                 // resources.getString(R.string.tare_modifiers),
                 resources.getString(R.string.tare_actions_ctp),
                 resources.getString(R.string.tare_actions_base_price),
-                // resources.getString(R.string.tare_rewards)
+                resources.getString(R.string.tare_rewards_instantaneous),
+                resources.getString(R.string.tare_rewards_max)
         };
 
         mChildren = new String[][]{
@@ -107,7 +108,8 @@
                 // resources.getStringArray(R.array.tare_modifiers_subfactors),
                 resources.getStringArray(R.array.tare_alarm_manager_actions),
                 resources.getStringArray(R.array.tare_alarm_manager_actions),
-                // resources.getStringArray(R.array.tare_rewards_subfactors)
+                resources.getStringArray(R.array.tare_rewards_subfactors),
+                resources.getStringArray(R.array.tare_rewards_subfactors)
         };
 
         mKeys = new String[][]{
@@ -147,7 +149,20 @@
                         EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE,
                         EconomyManager.KEY_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE
                 },
-                // {},
+                {
+                        EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_MAX,
+                        EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_MAX,
+                        EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_MAX,
+                        EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_MAX,
+                        EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_MAX,
+                },
+                {
+                        EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_MAX,
+                        EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_MAX,
+                        EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_MAX,
+                        EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_MAX,
+                        EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_MAX,
+                }
         };
     }
 }
diff --git a/src/com/android/settings/development/tare/JobSchedulerFragment.java b/src/com/android/settings/development/tare/JobSchedulerFragment.java
index 275e012..bffd648 100644
--- a/src/com/android/settings/development/tare/JobSchedulerFragment.java
+++ b/src/com/android/settings/development/tare/JobSchedulerFragment.java
@@ -98,7 +98,9 @@
                 // mResources.getString(R.string.tare_modifiers),
                 resources.getString(R.string.tare_actions_ctp),
                 resources.getString(R.string.tare_actions_base_price),
-                // mResources.getString(R.string.tare_rewards)
+                resources.getString(R.string.tare_rewards_instantaneous),
+                // resources.getString(R.string.tare_rewards_ongoing),
+                resources.getString(R.string.tare_rewards_max)
         };
 
         mChildren = new String[][]{
@@ -108,7 +110,9 @@
                 // mResources.getStringArray(R.array.tare_modifiers_subfactors),
                 resources.getStringArray(R.array.tare_job_scheduler_actions),
                 resources.getStringArray(R.array.tare_job_scheduler_actions),
-                // mResources.getStringArray(R.array.tare_rewards_subfactors)
+                resources.getStringArray(R.array.tare_rewards_subfactors),
+                // {resources.getString(R.string.tare_top_activity)},
+                resources.getStringArray(R.array.tare_rewards_subfactors)
         };
 
         mKeys = new String[][]{
@@ -149,7 +153,21 @@
                         EconomyManager.KEY_JS_ACTION_JOB_MIN_RUNNING_BASE_PRICE,
                         EconomyManager.KEY_JS_ACTION_JOB_TIMEOUT_PENALTY_BASE_PRICE
                 },
-                // {},
+                {
+                        EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_MAX,
+                        EconomyManager.KEY_JS_REWARD_NOTIFICATION_SEEN_MAX,
+                        EconomyManager.KEY_JS_REWARD_NOTIFICATION_INTERACTION_MAX,
+                        EconomyManager.KEY_JS_REWARD_WIDGET_INTERACTION_MAX,
+                        EconomyManager.KEY_JS_REWARD_OTHER_USER_INTERACTION_MAX,
+                },
+                // {EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_ONGOING},
+                {
+                        EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_MAX,
+                        EconomyManager.KEY_JS_REWARD_NOTIFICATION_SEEN_MAX,
+                        EconomyManager.KEY_JS_REWARD_NOTIFICATION_INTERACTION_MAX,
+                        EconomyManager.KEY_JS_REWARD_WIDGET_INTERACTION_MAX,
+                        EconomyManager.KEY_JS_REWARD_OTHER_USER_INTERACTION_MAX,
+                }
         };
     }
 }
diff --git a/src/com/android/settings/development/tare/TareFactorController.java b/src/com/android/settings/development/tare/TareFactorController.java
index b9f813d..62fde6d 100644
--- a/src/com/android/settings/development/tare/TareFactorController.java
+++ b/src/com/android/settings/development/tare/TareFactorController.java
@@ -530,7 +530,7 @@
         } else if (mJobSchedulerMap.containsKey(key)) {
             currentMap = mJobSchedulerMap;
         } else {
-            throw new IllegalArgumentException("Couldn't link key to policy map");
+            throw new IllegalArgumentException("Couldn't link key '" + key + "' to a policy");
         }
         return currentMap.get(key).factorPolicy;
     }
diff --git a/src/com/android/settings/password/ChooseLockSettingsHelper.java b/src/com/android/settings/password/ChooseLockSettingsHelper.java
index 77fcbed..e4d52ba 100644
--- a/src/com/android/settings/password/ChooseLockSettingsHelper.java
+++ b/src/com/android/settings/password/ChooseLockSettingsHelper.java
@@ -44,7 +44,6 @@
 
     private static final String TAG = "ChooseLockSettingsHelper";
 
-    public static final String EXTRA_KEY_TYPE = "type";
     public static final String EXTRA_KEY_PASSWORD = "password";
     public static final String EXTRA_KEY_RETURN_CREDENTIALS = "return_credentials";
     // Force the verifyCredential path instead of checkCredential path. This will be removed
@@ -191,7 +190,7 @@
         /**
          * @param returnCredentials if true, puts the following credentials into intent for
          *                          onActivityResult with the following keys:
-         *                          {@link #EXTRA_KEY_TYPE}, {@link #EXTRA_KEY_PASSWORD},
+         *                          {@link #EXTRA_KEY_PASSWORD},
          *                          {@link #EXTRA_KEY_CHALLENGE_TOKEN},
          *                          {@link #EXTRA_KEY_GK_PW_HANDLE}
          *                          Note that if this is true, this can only be called internally.
diff --git a/src/com/android/settings/password/ConfirmLockPassword.java b/src/com/android/settings/password/ConfirmLockPassword.java
index 7dcfc83..a81f975 100644
--- a/src/com/android/settings/password/ConfirmLockPassword.java
+++ b/src/com/android/settings/password/ConfirmLockPassword.java
@@ -39,7 +39,6 @@
 import android.os.Looper;
 import android.os.SystemClock;
 import android.os.UserManager;
-import android.os.storage.StorageManager;
 import android.text.Editable;
 import android.text.InputType;
 import android.text.TextUtils;
@@ -484,11 +483,6 @@
                         public void onChecked(boolean matched, int timeoutMs) {
                             mPendingLockCheck = null;
                             if (matched && isInternalActivity() && mReturnCredentials) {
-                                // TODO: get rid of EXTRA_KEY_TYPE, since EXTRA_KEY_PASSWORD already
-                                // distinguishes beteween PIN and password.
-                                intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_TYPE,
-                                                mIsAlpha ? StorageManager.CRYPT_TYPE_PASSWORD
-                                                         : StorageManager.CRYPT_TYPE_PIN);
                                 intent.putExtra(
                                         ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, credential);
                             }
diff --git a/src/com/android/settings/password/ConfirmLockPattern.java b/src/com/android/settings/password/ConfirmLockPattern.java
index 8b33aa5..1062d94 100644
--- a/src/com/android/settings/password/ConfirmLockPattern.java
+++ b/src/com/android/settings/password/ConfirmLockPattern.java
@@ -32,7 +32,6 @@
 import android.os.CountDownTimer;
 import android.os.SystemClock;
 import android.os.UserManager;
-import android.os.storage.StorageManager;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
@@ -523,8 +522,6 @@
                             public void onChecked(boolean matched, int timeoutMs) {
                                 mPendingLockCheck = null;
                                 if (matched && isInternalActivity() && mReturnCredentials) {
-                                    intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_TYPE,
-                                                    StorageManager.CRYPT_TYPE_PATTERN);
                                     intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD,
                                                     pattern);
                                 }
diff --git a/src/com/android/settings/wifi/NetworkRequestDialogActivity.java b/src/com/android/settings/wifi/NetworkRequestDialogActivity.java
index b160d90..30f38d2 100644
--- a/src/com/android/settings/wifi/NetworkRequestDialogActivity.java
+++ b/src/com/android/settings/wifi/NetworkRequestDialogActivity.java
@@ -58,12 +58,17 @@
     final static String EXTRA_IS_SPECIFIED_SSID =
         "com.android.settings.wifi.extra.REQUEST_IS_FOR_SINGLE_NETWORK";
 
-    @VisibleForTesting NetworkRequestDialogBaseFragment mDialogFragment;
+    @VisibleForTesting
+    NetworkRequestDialogBaseFragment mDialogFragment;
+    @VisibleForTesting
+    boolean mIsSpecifiedSsid;
+    @VisibleForTesting
+    boolean mShowingErrorDialog;
+    @VisibleForTesting
+    ProgressDialog mProgressDialog;
+
     private NetworkRequestUserSelectionCallback mUserSelectionCallback;
-    private boolean mIsSpecifiedSsid;
-    private boolean mShowingErrorDialog;
     private WifiConfiguration mMatchedConfig;
-    @VisibleForTesting ProgressDialog mProgressDialog;
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -103,7 +108,8 @@
         mDialogFragment.show(getSupportFragmentManager(), TAG);
     }
 
-    private void dismissDialogs() {
+    @VisibleForTesting
+    void dismissDialogs() {
         if (mDialogFragment != null) {
             mDialogFragment.dismiss();
             mDialogFragment = null;
@@ -174,7 +180,9 @@
             return;
         }
 
-        mDialogFragment.onUserSelectionCallbackRegistration(userSelectionCallback);
+        if (mDialogFragment != null) {
+            mDialogFragment.onUserSelectionCallbackRegistration(userSelectionCallback);
+        }
     }
 
     @Override
@@ -201,7 +209,9 @@
             return;
         }
 
-        mDialogFragment.onMatch(scanResults);
+        if (mDialogFragment != null) {
+            mDialogFragment.onMatch(scanResults);
+        }
     }
 
     @Override
diff --git a/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogActivityTest.java b/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogActivityTest.java
index fb20045..616cb0b 100644
--- a/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogActivityTest.java
@@ -25,7 +25,6 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import android.content.Context;
 import android.content.Intent;
 import android.net.wifi.ScanResult;
 import android.net.wifi.WifiConfiguration;
@@ -42,9 +41,12 @@
 import com.android.wifitrackerlib.WifiPickerTracker;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
 import org.robolectric.Robolectric;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
@@ -61,25 +63,26 @@
     private static final String TEST_SSID = "testssid";
     private static final String TEST_CAPABILITY = "wep";
 
-    NetworkRequestDialogActivity mActivity;
+    @Rule
+    public MockitoRule mRule = MockitoJUnit.rule();
+    @Mock
     WifiManager mWifiManager;
-    Context mContext;
+    @Mock
+    NetworkRequestUserSelectionCallback mNetworkRequestUserSelectionCallback;
+
+    NetworkRequestDialogActivity mActivity;
+    List<ScanResult> mScanResults = new ArrayList<>();
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        mContext = spy(RuntimeEnvironment.application);
         FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
         when(fakeFeatureFactory.wifiTrackerLibProvider.createWifiPickerTracker(
                 any(), any(), any(), any(), any(), anyLong(), anyLong(), any()))
                 .thenReturn(mock(WifiPickerTracker.class));
+        mScanResults.add(getScanResult(TEST_SSID, TEST_CAPABILITY));
 
-        NetworkRequestDialogActivity activity =
-            Robolectric.setupActivity(NetworkRequestDialogActivity.class);
-        mActivity = spy(activity);
-
-        mWifiManager = mock(WifiManager.class);
-        when(mActivity.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
+        mActivity = spy(Robolectric.setupActivity(NetworkRequestDialogActivity.class));
+        when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
     }
 
     @Test
@@ -169,10 +172,7 @@
     public void specifiedSsid_onMatch_shouldShowDialogFragment() {
         startSpecifiedActivity();
 
-        final List<ScanResult> scanResults = new ArrayList<>();
-        scanResults.add(getScanResult(TEST_SSID, TEST_CAPABILITY));
-
-        mActivity.onMatch(scanResults);
+        mActivity.onMatch(mScanResults);
 
         assertThat(mActivity.mProgressDialog).isNull();
         assertThat(mActivity.mDialogFragment).isNotNull();
@@ -193,9 +193,7 @@
     public void onUserSelectionConnectFailure_shouldShowDialogFragment() {
         WifiConfiguration wifiConfiguration = mock(WifiConfiguration.class);
         startSpecifiedActivity();
-        final List<ScanResult> scanResults = new ArrayList<>();
-        scanResults.add(getScanResult(TEST_SSID, TEST_CAPABILITY));
-        mActivity.onMatch(scanResults);
+        mActivity.onMatch(mScanResults);
 
         mActivity.onUserSelectionConnectFailure(wifiConfiguration);
 
@@ -205,13 +203,9 @@
 
     @Test
     public void onClickConnectButton_shouldShowProgressDialog() {
-        NetworkRequestUserSelectionCallback networkRequestUserSelectionCallback = mock(
-                NetworkRequestUserSelectionCallback.class);
         startSpecifiedActivity();
-        final List<ScanResult> scanResults = new ArrayList<>();
-        scanResults.add(getScanResult(TEST_SSID, TEST_CAPABILITY));
-        mActivity.onMatch(scanResults);
-        mActivity.onUserSelectionCallbackRegistration(networkRequestUserSelectionCallback);
+        mActivity.onMatch(mScanResults);
+        mActivity.onUserSelectionCallbackRegistration(mNetworkRequestUserSelectionCallback);
 
         mActivity.onClickConnectButton();
 
@@ -222,9 +216,7 @@
     @Test
     public void onCancel_shouldCloseAllUI() {
         startSpecifiedActivity();
-        final List<ScanResult> scanResults = new ArrayList<>();
-        scanResults.add(getScanResult(TEST_SSID, TEST_CAPABILITY));
-        mActivity.onMatch(scanResults);
+        mActivity.onMatch(mScanResults);
 
         mActivity.onCancel();
 
@@ -240,4 +232,20 @@
 
         verify(mActivity).finish();
     }
+
+    @Test
+    public void onUserSelectionCallbackRegistration_dismissDialogsAndDialogIsNull_shouldNotCrash() {
+        mActivity.dismissDialogs();
+
+        mActivity.onUserSelectionCallbackRegistration(mNetworkRequestUserSelectionCallback);
+    }
+
+    @Test
+    public void onMatch_dismissDialogsAndDialogIsNull_shouldNotCrash() {
+        mActivity.mIsSpecifiedSsid = false;
+        mActivity.mShowingErrorDialog = false;
+        mActivity.dismissDialogs();
+
+        mActivity.onMatch(mScanResults);
+    }
 }
diff --git a/tests/unit/src/com/android/settings/development/MockModemPreferenceControllerTest.java b/tests/unit/src/com/android/settings/development/MockModemPreferenceControllerTest.java
new file mode 100644
index 0000000..f811ac4
--- /dev/null
+++ b/tests/unit/src/com/android/settings/development/MockModemPreferenceControllerTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.development;
+
+import static com.android.settings.development.MockModemPreferenceController
+        .ALLOW_MOCK_MODEM_PROPERTY;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.os.Looper;
+import android.os.SystemProperties;
+
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+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;
+
+@RunWith(AndroidJUnit4.class)
+public class MockModemPreferenceControllerTest {
+
+    private Context mContext;
+    private MockModemPreferenceController mController;
+    private SwitchPreference mPreference;
+
+    @Before
+    public void setUp() {
+        mContext = ApplicationProvider.getApplicationContext();
+        mController = new MockModemPreferenceController(mContext);
+        if (Looper.myLooper() == null) {
+            Looper.prepare();
+        }
+
+        final PreferenceManager preferenceManager = new PreferenceManager(mContext);
+        final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
+        mPreference = new SwitchPreference(mContext);
+        mPreference.setKey(mController.getPreferenceKey());
+        screen.addPreference(mPreference);
+        mController.displayPreference(screen);
+    }
+
+    @Test
+    public void onPreferenceChanged_settingDisabled_shouldNotAllowedMockModem() {
+        mController.onPreferenceChange(mPreference, false /* new value */);
+
+        final boolean mode = SystemProperties.getBoolean(
+                ALLOW_MOCK_MODEM_PROPERTY, false /* default */);
+
+        assertThat(mode).isFalse();
+    }
+
+    @Test
+    public void onPreferenceChanged_settingEnabled_shouldAllowMockModem() {
+        mController.onPreferenceChange(mPreference, true /* new value */);
+
+        final boolean mode = SystemProperties.getBoolean(
+                ALLOW_MOCK_MODEM_PROPERTY, false /* default */);
+
+        assertThat(mode).isTrue();
+    }
+
+    @Test
+    public void updateState_settingEnabled_preferenceShouldBeChecked() {
+        SystemProperties.set(ALLOW_MOCK_MODEM_PROPERTY,
+                Boolean.toString(true));
+
+        mController.updateState(mPreference);
+        assertThat(mPreference.isChecked()).isTrue();
+    }
+
+    @Test
+    public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
+        SystemProperties.set(ALLOW_MOCK_MODEM_PROPERTY,
+                Boolean.toString(false));
+
+        mController.updateState(mPreference);
+        assertThat(mPreference.isChecked()).isFalse();
+    }
+
+    @Test
+    public void onDeveloperOptionsDisabled_shouldDisablePreference() {
+        mController.onDeveloperOptionsSwitchDisabled();
+        final boolean mode = SystemProperties.getBoolean(
+                ALLOW_MOCK_MODEM_PROPERTY,
+                false /* default */);
+
+        mController.updateState(mPreference);
+
+        assertThat(mode).isFalse();
+        assertThat(mPreference.isChecked()).isFalse();
+    }
+}