diff --git a/res/values/strings.xml b/res/values/strings.xml index c732dd8a0e3..81858b759c5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1411,8 +1411,10 @@ Choose your backup screen lock method - - If you forget your screen lock, your IT admin can\u2019t reset it. Set a separate work lock + + If you forget your screen lock, your IT admin can\u2019t reset it. + + Set a separate work lock If you forget this lock, ask your IT admin to reset it diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java b/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java index 14b4a7a5a7e..650267a4757 100644 --- a/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java +++ b/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java @@ -55,6 +55,7 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i private BluetoothPairingController mPairingController; private BluetoothPairingDialog mPairingDialogActivity; private EditText mPairingView; + private boolean mPositiveClicked = false; /** * The interface we expect a listener to implement. Typically this should be done by * the controller. @@ -85,7 +86,9 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i @Override public void onDestroy() { super.onDestroy(); - mPairingController.onCancel(); + if (!mPositiveClicked) { + mPairingController.onCancel(); + } } @Override @@ -110,6 +113,7 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { + mPositiveClicked = true; mPairingController.onDialogPositiveClick(this); } else if (which == DialogInterface.BUTTON_NEGATIVE) { mPairingController.onDialogNegativeClick(this); diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java index c8eb488df09..7e6eefe2e41 100644 --- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java +++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java @@ -39,6 +39,7 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment { private static final String SETTINGS_PACKAGE_NAME = "com.android.settings"; private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); + private static final String SLICE_ACTION = "com.android.settings.SEARCH_RESULT_TRAMPOLINE"; @VisibleForTesting static final String KEY_CONNECTED_DEVICES = "connected_device_list"; @@ -72,8 +73,10 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment { SettingsUIDeviceConfig.BT_NEAR_BY_SUGGESTION_ENABLED, true); String callingAppPackageName = PasswordUtils.getCallingAppPackageName( getActivity().getActivityToken()); + String action = getIntent() != null ? getIntent().getAction() : ""; if (DEBUG) { - Log.d(TAG, "onAttach() calling package name is : " + callingAppPackageName); + Log.d(TAG, "onAttach() calling package name is : " + callingAppPackageName + + ", action : " + action); } use(AvailableMediaDeviceGroupController.class).init(this); use(ConnectedDeviceGroupController.class).init(this); @@ -81,9 +84,15 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment { use(SlicePreferenceController.class).setSliceUri(nearbyEnabled ? Uri.parse(getString(R.string.config_nearby_devices_slice_uri)) : null); - use(DiscoverableFooterPreferenceController.class).setAlwaysDiscoverable( - TextUtils.equals(SETTINGS_PACKAGE_NAME, callingAppPackageName) - || TextUtils.equals(SYSTEMUI_PACKAGE_NAME, callingAppPackageName)); + use(DiscoverableFooterPreferenceController.class) + .setAlwaysDiscoverable(isAlwaysDiscoverable(callingAppPackageName, action)); + } + + @VisibleForTesting + boolean isAlwaysDiscoverable(String callingAppPackageName, String action) { + return TextUtils.equals(SLICE_ACTION, action) ? false + : TextUtils.equals(SETTINGS_PACKAGE_NAME, callingAppPackageName) + || TextUtils.equals(SYSTEMUI_PACKAGE_NAME, callingAppPackageName); } /** diff --git a/src/com/android/settings/localepicker/AppLocalePickerActivity.java b/src/com/android/settings/localepicker/AppLocalePickerActivity.java index 1ed6f5be3b1..791a4e8e785 100644 --- a/src/com/android/settings/localepicker/AppLocalePickerActivity.java +++ b/src/com/android/settings/localepicker/AppLocalePickerActivity.java @@ -38,7 +38,7 @@ import com.android.settings.applications.appinfo.AppLocaleDetails; import com.android.settings.core.SettingsBaseActivity; public class AppLocalePickerActivity extends SettingsBaseActivity - implements LocalePickerWithRegion.LocaleSelectedListener { + implements LocalePickerWithRegion.LocaleSelectedListener, MenuItem.OnActionExpandListener { private static final String TAG = AppLocalePickerActivity.class.getSimpleName(); private String mPackageName; @@ -75,9 +75,10 @@ public class AppLocalePickerActivity extends SettingsBaseActivity mLocalePickerWithRegion = LocalePickerWithRegion.createLanguagePicker( mContextAsUser, - AppLocalePickerActivity.this, + this, false /* translate only */, - mPackageName); + mPackageName, + this); mAppLocaleDetails = AppLocaleDetails.newInstance(mPackageName); mAppLocaleDetailContainer = launchAppLocaleDetailsPage(); // Launch Locale picker part. @@ -103,6 +104,18 @@ public class AppLocalePickerActivity extends SettingsBaseActivity finish(); } + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + mAppBarLayout.setExpanded(false /*expanded*/, false /*animate*/); + return true; + } + + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + mAppBarLayout.setExpanded(false /*expanded*/, false /*animate*/); + return true; + } + /** Sets the app's locale to the supplied language tag */ private void setAppDefaultLocale(String languageTag) { LocaleManager localeManager = mContextAsUser.getSystemService(LocaleManager.class); diff --git a/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java b/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java index 288f1ac1e53..c509bac575c 100644 --- a/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java +++ b/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java @@ -16,8 +16,12 @@ package com.android.settings.network.telephony; +import static android.content.Context.MODE_PRIVATE; + +import android.content.SharedPreferences; import android.os.Bundle; import android.telephony.SubscriptionManager; +import android.util.Log; import androidx.fragment.app.FragmentActivity; @@ -27,14 +31,27 @@ public class SubscriptionActionDialogActivity extends FragmentActivity { private static final String TAG = "SubscriptionActionDialogActivity"; // Arguments protected static final String ARG_SUB_ID = "sub_id"; - protected SubscriptionManager mSubscriptionManager; + public static final String SIM_ACTION_DIALOG_PREFS = "sim_action_dialog_prefs"; + // Shared preference keys + public static final String KEY_PROGRESS_STATE = "progress_state"; + public static final int PROGRESS_IS_NOT_SHOWING = 0; + public static final int PROGRESS_IS_SHOWING = 1; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mSubscriptionManager = getSystemService(SubscriptionManager.class); + setProgressState(PROGRESS_IS_NOT_SHOWING); + } + + + @Override + public void finish() { + setProgressState(PROGRESS_IS_NOT_SHOWING); + super.finish(); } /** @@ -44,11 +61,13 @@ public class SubscriptionActionDialogActivity extends FragmentActivity { */ protected void showProgressDialog(String message) { ProgressDialogFragment.show(getFragmentManager(), message, null); + setProgressState(PROGRESS_IS_SHOWING); } /** Dismisses the loading dialog. */ protected void dismissProgressDialog() { ProgressDialogFragment.dismiss(getFragmentManager()); + setProgressState(PROGRESS_IS_NOT_SHOWING); } /** @@ -60,4 +79,10 @@ public class SubscriptionActionDialogActivity extends FragmentActivity { protected void showErrorDialog(String title, String message) { AlertDialogFragment.show(this, title, message); } + + protected void setProgressState(int state) { + final SharedPreferences prefs = getSharedPreferences(SIM_ACTION_DIALOG_PREFS, MODE_PRIVATE); + prefs.edit().putInt(KEY_PROGRESS_STATE, state).apply(); + Log.i(TAG, "setProgressState:" + state); + } } diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java index d3988faf8a9..8a4e9bb6c13 100644 --- a/src/com/android/settings/password/ChooseLockGeneric.java +++ b/src/com/android/settings/password/ChooseLockGeneric.java @@ -25,6 +25,7 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE; import static android.app.admin.DevicePolicyResources.Strings.Settings.LOCK_SETTINGS_NEW_PROFILE_LOCK_TITLE; import static android.app.admin.DevicePolicyResources.Strings.Settings.LOCK_SETTINGS_UPDATE_PROFILE_LOCK_TITLE; import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_IT_ADMIN_CANT_RESET_SCREEN_LOCK; +import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_IT_ADMIN_CANT_RESET_SCREEN_LOCK_ACTION; import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_SCREEN_LOCK_SETUP_MESSAGE; import static com.android.settings.password.ChooseLockPassword.ChooseLockPasswordFragment.RESULT_FINISHED; @@ -78,7 +79,6 @@ import com.android.settings.core.SubSettingLauncher; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.safetycenter.LockScreenSafetySource; import com.android.settings.search.SearchFeatureProvider; -import com.android.settings.utils.AnnotationSpan; import com.android.settingslib.RestrictedPreference; import com.android.settingslib.widget.FooterPreference; @@ -621,15 +621,20 @@ public class ChooseLockGeneric extends SettingsActivity { } else if (!mForFace && !mForBiometrics && !mForFingerprint && !mIsManagedProfile && mController.isScreenLockRestrictedByAdmin() && profileUserId != UserHandle.USER_NULL) { - CharSequence description = - mDpm.getResources().getString(WORK_PROFILE_IT_ADMIN_CANT_RESET_SCREEN_LOCK, - () -> null); - if (description == null) { - description = getText( - R.string.lock_settings_picker_admin_restricted_personal_message); - } - final AnnotationSpan.LinkInfo linkInfo = new AnnotationSpan.LinkInfo( - AnnotationSpan.LinkInfo.DEFAULT_ANNOTATION, (view) -> { + final StringBuilder description = new StringBuilder( + mDpm.getResources().getString( + WORK_PROFILE_IT_ADMIN_CANT_RESET_SCREEN_LOCK, + () -> getString( + R.string.lock_settings_picker_admin_restricted_personal_message))); + footer.setVisible(true); + footer.setTitle(description); + + final StringBuilder setLockText = new StringBuilder( + mDpm.getResources().getString( + WORK_PROFILE_IT_ADMIN_CANT_RESET_SCREEN_LOCK_ACTION, + () -> getString( + R.string.lock_settings_picker_admin_restricted_personal_message_action))); + View.OnClickListener setLockClickListener = (v) -> { final Bundle extras = new Bundle(); extras.putInt(Intent.EXTRA_USER_ID, profileUserId); if (mUserPassword != null) { @@ -642,10 +647,9 @@ public class ChooseLockGeneric extends SettingsActivity { .setArguments(extras) .launch(); finish(); - }); - CharSequence footerText = AnnotationSpan.linkify(description, linkInfo); - footer.setVisible(true); - footer.setTitle(footerText); + }; + footer.setLearnMoreText(setLockText); + footer.setLearnMoreAction(setLockClickListener); } else { footer.setVisible(false); } diff --git a/src/com/android/settings/sim/SimDialogActivity.java b/src/com/android/settings/sim/SimDialogActivity.java index 1125e1fe295..732277b3d8a 100644 --- a/src/com/android/settings/sim/SimDialogActivity.java +++ b/src/com/android/settings/sim/SimDialogActivity.java @@ -16,8 +16,11 @@ package com.android.settings.sim; +import static android.content.Context.MODE_PRIVATE; + import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; @@ -32,6 +35,7 @@ import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import com.android.settings.R; +import com.android.settings.network.telephony.SubscriptionActionDialogActivity; import java.util.List; @@ -60,6 +64,7 @@ public class SimDialogActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + getWindow().addSystemFlags( WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); showOrUpdateDialog(); @@ -72,6 +77,13 @@ public class SimDialogActivity extends FragmentActivity { showOrUpdateDialog(); } + private int getProgressState() { + final SharedPreferences prefs = getSharedPreferences( + SubscriptionActionDialogActivity.SIM_ACTION_DIALOG_PREFS, MODE_PRIVATE); + return prefs.getInt(SubscriptionActionDialogActivity.KEY_PROGRESS_STATE, + SubscriptionActionDialogActivity.PROGRESS_IS_NOT_SHOWING); + } + private void showOrUpdateDialog() { final int dialogType = getIntent().getIntExtra(DIALOG_TYPE_KEY, INVALID_PICK); @@ -80,6 +92,13 @@ public class SimDialogActivity extends FragmentActivity { return; } + if (dialogType == PREFERRED_PICK + && getProgressState() == SubscriptionActionDialogActivity.PROGRESS_IS_SHOWING) { + Log.d(TAG, "Finish the sim dialog since the sim action dialog is showing the progress"); + finish(); + return; + } + final String tag = Integer.toString(dialogType); final FragmentManager fragmentManager = getSupportFragmentManager(); SimDialogFragment fragment = (SimDialogFragment) fragmentManager.findFragmentByTag(tag); diff --git a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java index 97d54854f40..5f0f2b9dddf 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java @@ -54,16 +54,24 @@ public class ConnectedDeviceDashboardFragmentTest { private static final String KEY_DISCOVERABLE_FOOTER = "discoverable_footer"; private static final String KEY_SEE_ALL = "previously_connected_devices_see_all"; private static final String KEY_ADD_BT_DEVICES = "add_bt_devices"; + private static final String SETTINGS_PACKAGE_NAME = "com.android.settings"; + private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui"; + private static final String SLICE_ACTION = "com.android.settings.SEARCH_RESULT_TRAMPOLINE"; + private static final String TEST_APP_NAME = "com.testapp.settings"; + private static final String TEST_ACTION = "com.testapp.settings.ACTION_START"; + @Mock private PackageManager mPackageManager; private Context mContext; + private ConnectedDeviceDashboardFragment mFragment; @Before public void setUp() { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); + mFragment = new ConnectedDeviceDashboardFragment(); doReturn(mPackageManager).when(mContext).getPackageManager(); doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH); } @@ -87,6 +95,26 @@ public class ConnectedDeviceDashboardFragmentTest { KEY_NEARBY_DEVICES, KEY_DISCOVERABLE_FOOTER, KEY_SEE_ALL); } + @Test + public void isAlwaysDiscoverable_callingAppIsNotFromSystemApp_returnsFalse() { + assertThat(mFragment.isAlwaysDiscoverable(TEST_APP_NAME, TEST_ACTION)).isFalse(); + } + + @Test + public void isAlwaysDiscoverable_callingAppIsFromSettings_returnsTrue() { + assertThat(mFragment.isAlwaysDiscoverable(SETTINGS_PACKAGE_NAME, TEST_ACTION)).isTrue(); + } + + @Test + public void isAlwaysDiscoverable_callingAppIsFromSystemUI_returnsTrue() { + assertThat(mFragment.isAlwaysDiscoverable(SYSTEMUI_PACKAGE_NAME, TEST_ACTION)).isTrue(); + } + + @Test + public void isAlwaysDiscoverable_actionIsFromSlice_returnsFalse() { + assertThat(mFragment.isAlwaysDiscoverable(SYSTEMUI_PACKAGE_NAME, SLICE_ACTION)).isFalse(); + } + @Test public void getPreferenceControllers_containSlicePrefController() { final List controllers =