diff --git a/res/values/strings.xml b/res/values/strings.xml index 97c07260b20..5a0285f4caa 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -794,12 +794,18 @@ Screen lock + + Status widget + - Widget + Other widget None + + Default + Change lock screen diff --git a/res/xml/security_settings_biometric_weak.xml b/res/xml/security_settings_biometric_weak.xml index 6593f07a9fc..590eb95d952 100644 --- a/res/xml/security_settings_biometric_weak.xml +++ b/res/xml/security_settings_biometric_weak.xml @@ -26,6 +26,18 @@ android:summary="@string/unlock_set_unlock_mode_biometric_weak" android:persistent="false"/> + + + + diff --git a/res/xml/security_settings_chooser.xml b/res/xml/security_settings_chooser.xml index 98422ba5130..08428b02b52 100644 --- a/res/xml/security_settings_chooser.xml +++ b/res/xml/security_settings_chooser.xml @@ -26,6 +26,12 @@ android:summary="@string/unlock_set_unlock_mode_none" android:persistent="false"/> + + + + + + + + + + + extraInfos = new ArrayList(); + noneInfo.label = getResources().getString(R.string.widget_default); + noneInfo.provider = new ComponentName("", ""); + extraInfos.add(noneInfo); + + ArrayList extraExtras = new ArrayList(); + Bundle b = new Bundle(); + b.putBoolean(EXTRA_DEFAULT_WIDGET, true); + extraExtras.add(b); + + // Launch the widget picker + pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, extraInfos); + pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, extraExtras); + startActivityForResult(pickIntent, REQUEST_PICK_STATUS_APPWIDGET); } else { Log.e(TAG, "Unable to allocate an AppWidget id in lock screen"); } @@ -567,44 +631,56 @@ public class SecuritySettings extends SettingsPreferenceFragment // is called by grabbing the value from lockPatternUtils. We can't set it here // because mBiometricWeakLiveliness could be null return; - } else if (requestCode == REQUEST_PICK_APPWIDGET || - requestCode == REQUEST_CREATE_APPWIDGET) { + } else if (requestCode == REQUEST_PICK_USER_SELECTED_APPWIDGET || + requestCode == REQUEST_PICK_STATUS_APPWIDGET || + requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET || + requestCode == REQUEST_CREATE_STATUS_APPWIDGET) { int appWidgetId = (data == null) ? -1 : data.getIntExtra( AppWidgetManager.EXTRA_APPWIDGET_ID, -1); - if (requestCode == REQUEST_PICK_APPWIDGET && resultCode == Activity.RESULT_OK) { + if ((requestCode == REQUEST_PICK_USER_SELECTED_APPWIDGET || + requestCode == REQUEST_PICK_STATUS_APPWIDGET) && + resultCode == Activity.RESULT_OK) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity()); - boolean noWidget = data.getBooleanExtra(EXTRA_NO_WIDGET, false); + boolean defaultOrNoWidget = data.getBooleanExtra(EXTRA_NO_WIDGET, false) || + data.getBooleanExtra(EXTRA_DEFAULT_WIDGET, false); AppWidgetProviderInfo appWidget = null; - if (!noWidget) { + if (!defaultOrNoWidget) { appWidget = appWidgetManager.getAppWidgetInfo(appWidgetId); } - if (!noWidget && appWidget.configure != null) { + int newRequestCode = requestCode == REQUEST_PICK_USER_SELECTED_APPWIDGET ? + REQUEST_CREATE_USER_SELECTED_APPWIDGET : + REQUEST_CREATE_STATUS_APPWIDGET; + if (!defaultOrNoWidget && appWidget.configure != null) { // Launch over to configure widget, if needed Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); intent.setComponent(appWidget.configure); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET); + startActivityForResultSafely(intent, newRequestCode); } else { // Otherwise just add it - if (noWidget) { + if (defaultOrNoWidget) { // If we selected "none", delete the allocated id AppWidgetHost.deleteAppWidgetIdForSystem(appWidgetId); data.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); } - onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data); + onActivityResult(newRequestCode, Activity.RESULT_OK, data); } - } else if ( - requestCode == REQUEST_CREATE_APPWIDGET && resultCode == Activity.RESULT_OK) { + } else if ((requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET || + requestCode == REQUEST_CREATE_STATUS_APPWIDGET) && + resultCode == Activity.RESULT_OK) { // If a widget existed before, delete it - int oldAppWidgetId = getUserSelectedAppWidgetId(); + int oldAppWidgetId = requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET ? + getUserSelectedAppWidgetId() : getStatusAppWidgetId(); if (oldAppWidgetId != -1) { AppWidgetHost.deleteAppWidgetIdForSystem(oldAppWidgetId); } Settings.Secure.putString(getContentResolver(), - Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID, + (requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET ? + Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID : + Settings.Secure.LOCK_SCREEN_STATUS_APPWIDGET_ID), Integer.toString(appWidgetId)); } else { AppWidgetHost.deleteAppWidgetIdForSystem(appWidgetId);