Snap for 8769194 from 2050925500 to udc-release
Change-Id: I252be1318de30e130363ff529d24501770158c90
This commit is contained in:
1
OWNERS
1
OWNERS
@@ -12,6 +12,7 @@ stanleytfwang@google.com
|
||||
sunnyshao@google.com
|
||||
tmfang@google.com
|
||||
yantingyang@google.com
|
||||
ykhung@google.com
|
||||
|
||||
# Emergency only
|
||||
hanxu@google.com
|
||||
|
||||
@@ -606,7 +606,7 @@
|
||||
<!-- Date & time setting screen setting switch title: whether the system clock (Unix epoch time) should be determined automatically [CHAR LIMIT=100] -->
|
||||
<string name="date_time_auto">Set time automatically</string>
|
||||
<!-- Date & time setting screen setting switch title: whether the time zone should be determined automatically [CHAR LIMIT=100] -->
|
||||
<string name="zone_auto_title">Set time zone automatically</string>
|
||||
<string name="zone_auto_title">Set automatically</string>
|
||||
<!-- Date & time setting screen setting option summary text for the automatic 24 hour setting checkbox [CHAR LIMIT=100] -->
|
||||
<string name="date_time_24hour_auto">Use locale default</string>
|
||||
<!-- Date & time setting screen setting check box title [CHAR LIMIT=30] -->
|
||||
@@ -4254,7 +4254,7 @@
|
||||
<string name="managed_profile_location_services">Location services for work</string>
|
||||
|
||||
<!-- [CHAR LIMIT=60] Date&Time settings screen, toggle button title -->
|
||||
<string name="location_time_zone_detection_toggle_title">Use location to set time zone</string>
|
||||
<string name="location_time_zone_detection_toggle_title">Use location</string>
|
||||
<!-- [CHAR LIMIT=60] Date&Time settings screen, title of the dialog shown when user tries to
|
||||
enable GeoTZ when Location toggle is off. -->
|
||||
<string name="location_time_zone_detection_location_is_off_dialog_title">Device location needed</string>
|
||||
@@ -4280,6 +4280,8 @@
|
||||
<!-- [CHAR LIMIT=NONE] Location settings screen, summary when location time zone detection is not
|
||||
allowed for the user, e.g. because of device policy -->
|
||||
<string name="location_time_zone_detection_not_allowed">Location time zone detection changes are not allowed</string>
|
||||
<!-- [CHAR LIMIT=NONE] Location settings screen, summary when location time zone detection is enabled. -->
|
||||
<string name="location_time_zone_detection_auto_is_on">Location may be used to set time zone</string>
|
||||
|
||||
<!-- [CHAR LIMIT=30] Security & location settings screen, setting check box label for Google location service (cell ID, wifi, etc.) -->
|
||||
<string name="location_network_based">Wi\u2011Fi & mobile network location</string>
|
||||
@@ -6835,6 +6837,14 @@
|
||||
behalf. It comes from the <xliff:g id="voice_input_service_app_name">%s</xliff:g>
|
||||
application. Enable the use of this service?</string>
|
||||
|
||||
<!-- On-device recognition settings --><skip />
|
||||
<!-- [CHAR_LIMIT=NONE] Name of the settings item to open the on-device recognition settings. -->
|
||||
<string name="on_device_recognition_settings">On-device recognition settings</string>
|
||||
<!-- [CHAR_LIMIT=NONE] Title of the on-device recognition settings -->
|
||||
<string name="on_device_recognition_settings_title">On-device recognition</string>
|
||||
<!-- [CHAR_LIMIT=NONE] Summary of the on-device recognition settings -->
|
||||
<string name="on_device_recognition_settings_summary">On-device speech recognition</string>
|
||||
|
||||
<!-- [CHAR LIMIT=50] The text for the settings section that is used to set a preferred text to speech engine -->
|
||||
<string name="tts_engine_preference_title">Preferred engine</string>
|
||||
<!-- [CHAR LIMIT=50] The text for a settings screen of the currently set text to speech engine -->
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
<com.android.settingslib.RestrictedSwitchPreference
|
||||
android:key="auto_zone"
|
||||
android:title="@string/zone_auto_title"
|
||||
settings:allowDividerAbove="true"
|
||||
settings:userRestriction="no_config_date_time"/>
|
||||
|
||||
<!-- This preference gets removed if location-based time zone detection is not supported -->
|
||||
|
||||
@@ -63,6 +63,13 @@
|
||||
android:title="@string/voice_input_settings_title"
|
||||
android:fragment="com.android.settings.language.DefaultVoiceInputPicker" />
|
||||
|
||||
<Preference
|
||||
android:key="on_device_recognition_settings"
|
||||
android:title="@string/on_device_recognition_settings_title"
|
||||
android:summary="@string/on_device_recognition_settings_summary"
|
||||
settings:controller=
|
||||
"com.android.settings.language.OnDeviceRecognitionPreferenceController" />
|
||||
|
||||
<Preference
|
||||
android:key="tts_settings_summary"
|
||||
android:title="@string/tts_settings_title"
|
||||
|
||||
@@ -70,6 +70,7 @@ import com.android.settings.homepage.DeepLinkHomepageActivityInternal;
|
||||
import com.android.settings.homepage.SettingsHomepageActivity;
|
||||
import com.android.settings.homepage.TopLevelSettings;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.password.PasswordUtils;
|
||||
import com.android.settings.wfd.WifiDisplaySettings;
|
||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||
import com.android.settingslib.core.instrumentation.Instrumentable;
|
||||
@@ -154,6 +155,7 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
public static final String EXTRA_IS_FROM_SLICE = "is_from_slice";
|
||||
|
||||
public static final String EXTRA_USER_HANDLE = "user_handle";
|
||||
public static final String EXTRA_INITIAL_CALLING_PACKAGE = "initial_calling_package";
|
||||
|
||||
/**
|
||||
* Personal or Work profile tab of {@link ProfileSelectFragment}
|
||||
@@ -418,6 +420,8 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
}
|
||||
|
||||
private boolean tryStartTwoPaneDeepLink(Intent intent) {
|
||||
intent.putExtra(EXTRA_INITIAL_CALLING_PACKAGE, PasswordUtils.getCallingAppPackageName(
|
||||
getActivityToken()));
|
||||
final Intent trampolineIntent;
|
||||
if (intent.getBooleanExtra(EXTRA_IS_FROM_SLICE, false)) {
|
||||
// Get menu key for slice deep link case.
|
||||
@@ -505,6 +509,17 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the initial calling package name that launches the activity. */
|
||||
public String getInitialCallingPackage() {
|
||||
String callingPackage = PasswordUtils.getCallingAppPackageName(getActivityToken());
|
||||
if (!TextUtils.equals(callingPackage, getPackageName())) {
|
||||
return callingPackage;
|
||||
}
|
||||
|
||||
String initialCallingPackage = getIntent().getStringExtra(EXTRA_INITIAL_CALLING_PACKAGE);
|
||||
return TextUtils.isEmpty(initialCallingPackage) ? callingPackage : initialCallingPackage;
|
||||
}
|
||||
|
||||
/** Returns the initial fragment name that the activity will launch. */
|
||||
@VisibleForTesting
|
||||
public String getInitialFragmentName(Intent intent) {
|
||||
|
||||
@@ -639,13 +639,17 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
|
||||
new Animator.AnimatorListener() {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) { }
|
||||
public void onAnimationStart(Animator animation) {
|
||||
startIconAnimation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) { }
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
stopIconAnimation();
|
||||
|
||||
if (mProgressBar.getProgress() >= PROGRESS_BAR_MAX) {
|
||||
mProgressBar.postDelayed(mDelayedFinishRunnable, getFinishDelay());
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ import android.util.Log;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.SettingsUIDeviceConfig;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.password.PasswordUtils;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.slices.SlicePreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
@@ -71,8 +71,8 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
|
||||
super.onAttach(context);
|
||||
final boolean nearbyEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
|
||||
SettingsUIDeviceConfig.BT_NEAR_BY_SUGGESTION_ENABLED, true);
|
||||
String callingAppPackageName = PasswordUtils.getCallingAppPackageName(
|
||||
getActivity().getActivityToken());
|
||||
String callingAppPackageName = ((SettingsActivity) getActivity())
|
||||
.getInitialCallingPackage();
|
||||
String action = getIntent() != null ? getIntent().getAction() : "";
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onAttach() calling package name is : " + callingAppPackageName
|
||||
|
||||
@@ -174,7 +174,7 @@ public class LocationTimeZoneDetectionPreferenceController
|
||||
// If capability is possessed, toggle status already tells all the information needed.
|
||||
// Returning null will make previous text stick on toggling.
|
||||
// See AbstractPreferenceController#refreshSummary.
|
||||
return "";
|
||||
summaryResId = R.string.location_time_zone_detection_auto_is_on;
|
||||
} else {
|
||||
// This is unexpected: getAvailabilityStatus() should ensure that the UI element isn't
|
||||
// even shown for known cases, or the capability is unknown.
|
||||
|
||||
@@ -50,6 +50,7 @@ public class LanguageAndInputSettings extends DashboardFragment {
|
||||
|
||||
private static final String KEY_KEYBOARDS_CATEGORY = "keyboards_category";
|
||||
private static final String KEY_SPEECH_CATEGORY = "speech_category";
|
||||
private static final String KEY_ON_DEVICE_RECOGNITION = "odsr_settings";
|
||||
private static final String KEY_TEXT_TO_SPEECH = "tts_settings_summary";
|
||||
private static final String KEY_POINTER_CATEGORY = "pointer_category";
|
||||
|
||||
@@ -123,11 +124,21 @@ public class LanguageAndInputSettings extends DashboardFragment {
|
||||
new DefaultVoiceInputPreferenceController(context, lifecycle);
|
||||
final TtsPreferenceController ttsPreferenceController =
|
||||
new TtsPreferenceController(context, KEY_TEXT_TO_SPEECH);
|
||||
final OnDeviceRecognitionPreferenceController onDeviceRecognitionPreferenceController =
|
||||
new OnDeviceRecognitionPreferenceController(context, KEY_ON_DEVICE_RECOGNITION);
|
||||
|
||||
controllers.add(defaultVoiceInputPreferenceController);
|
||||
controllers.add(ttsPreferenceController);
|
||||
controllers.add(new PreferenceCategoryController(context,
|
||||
KEY_SPEECH_CATEGORY).setChildren(
|
||||
Arrays.asList(defaultVoiceInputPreferenceController, ttsPreferenceController)));
|
||||
List<AbstractPreferenceController> speechCategoryChildren = new ArrayList<>(
|
||||
List.of(defaultVoiceInputPreferenceController, ttsPreferenceController));
|
||||
|
||||
if (onDeviceRecognitionPreferenceController.isAvailable()) {
|
||||
controllers.add(onDeviceRecognitionPreferenceController);
|
||||
speechCategoryChildren.add(onDeviceRecognitionPreferenceController);
|
||||
}
|
||||
|
||||
controllers.add(new PreferenceCategoryController(context, KEY_SPEECH_CATEGORY)
|
||||
.setChildren(speechCategoryChildren));
|
||||
|
||||
// Pointer
|
||||
final PointerSpeedController pointerController = new PointerSpeedController(context);
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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.language;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
/** Controller of the On-device recognition preference. */
|
||||
public class OnDeviceRecognitionPreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String TAG = "OnDeviceRecognitionPreferenceController";
|
||||
|
||||
private Optional<Intent> mIntent;
|
||||
|
||||
public OnDeviceRecognitionPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (mIntent == null) {
|
||||
mIntent = Optional.ofNullable(onDeviceRecognitionIntent());
|
||||
}
|
||||
return mIntent.isPresent()
|
||||
? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
if (mIntent != null && mIntent.isPresent()) {
|
||||
preference.setIntent(mIntent.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an {@link Intent} for the activity in the default on-device recognizer service if
|
||||
* there is a properly defined speech recognition xml meta-data for that service.
|
||||
*
|
||||
* @return {@link Intent} if the proper activity is fount, {@code null} otherwise.
|
||||
*/
|
||||
@Nullable
|
||||
private Intent onDeviceRecognitionIntent() {
|
||||
final String resString = mContext.getString(
|
||||
R.string.config_defaultOnDeviceSpeechRecognitionService);
|
||||
|
||||
if (resString == null) {
|
||||
Log.v(TAG, "No on-device recognizer, intent not created.");
|
||||
return null;
|
||||
}
|
||||
|
||||
final ComponentName defaultOnDeviceRecognizerComponentName =
|
||||
ComponentName.unflattenFromString(resString);
|
||||
|
||||
if (defaultOnDeviceRecognizerComponentName == null) {
|
||||
Log.v(TAG, "Invalid on-device recognizer string format, intent not created.");
|
||||
return null;
|
||||
}
|
||||
|
||||
final ArrayList<VoiceInputHelper.RecognizerInfo> validRecognitionServices =
|
||||
VoiceInputHelper.validRecognitionServices(mContext);
|
||||
|
||||
if (validRecognitionServices.isEmpty()) {
|
||||
Log.v(TAG, "No speech recognition services"
|
||||
+ "with proper `recognition-service` meta-data found.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Filter the recognizer services which are in the same package as the default on-device
|
||||
// speech recognizer and have a settings activity defined in the meta-data.
|
||||
final ArrayList<VoiceInputHelper.RecognizerInfo> validOnDeviceRecognitionServices =
|
||||
new ArrayList<>();
|
||||
for (VoiceInputHelper.RecognizerInfo recognizerInfo: validRecognitionServices) {
|
||||
if (!defaultOnDeviceRecognizerComponentName.getPackageName().equals(
|
||||
recognizerInfo.mService.packageName)) {
|
||||
Log.v(TAG, String.format("Recognition service not in the same package as the "
|
||||
+ "default on-device recognizer: %s.",
|
||||
recognizerInfo.mComponentName.flattenToString()));
|
||||
} else if (recognizerInfo.mSettings == null) {
|
||||
Log.v(TAG, String.format("Recognition service with no settings activity: %s.",
|
||||
recognizerInfo.mComponentName.flattenToString()));
|
||||
} else {
|
||||
validOnDeviceRecognitionServices.add(recognizerInfo);
|
||||
Log.v(TAG, String.format("Recognition service in the same package as the default "
|
||||
+ "on-device recognizer with settings activity: %s.",
|
||||
recognizerInfo.mSettings.flattenToString()));
|
||||
}
|
||||
}
|
||||
|
||||
if (validOnDeviceRecognitionServices.isEmpty()) {
|
||||
Log.v(TAG, "No speech recognition services with proper `recognition-service` "
|
||||
+ "meta-data found in the same package as the default on-device recognizer.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Not more than one proper recognition services should be found in the same
|
||||
// package as the default on-device recognizer. If that happens,
|
||||
// the first one which passed the filter will be selected.
|
||||
if (validOnDeviceRecognitionServices.size() > 1) {
|
||||
Log.w(TAG, "More than one recognition services with proper `recognition-service` "
|
||||
+ "meta-data found in the same package as the default on-device recognizer.");
|
||||
}
|
||||
VoiceInputHelper.RecognizerInfo chosenRecognizer = validOnDeviceRecognitionServices.get(0);
|
||||
|
||||
return new Intent(Intent.ACTION_MAIN).setComponent(chosenRecognizer.mSettings);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import android.provider.Settings;
|
||||
import android.speech.RecognitionService;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.util.Xml;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
@@ -44,12 +45,11 @@ public final class VoiceInputHelper {
|
||||
static final String TAG = "VoiceInputHelper";
|
||||
final Context mContext;
|
||||
|
||||
final List<ResolveInfo> mAvailableRecognition;
|
||||
|
||||
/**
|
||||
* Base info of the Voice Input provider.
|
||||
*
|
||||
* TODO: Remove this superclass as we only have 1 class now (RecognizerInfo).
|
||||
* TODO: Group recognition service xml meta-data attributes in a single class.
|
||||
*/
|
||||
public static class BaseInfo implements Comparable<BaseInfo> {
|
||||
public final ServiceInfo mService;
|
||||
@@ -90,16 +90,12 @@ public final class VoiceInputHelper {
|
||||
}
|
||||
}
|
||||
|
||||
final ArrayList<RecognizerInfo> mAvailableRecognizerInfos = new ArrayList<>();
|
||||
ArrayList<RecognizerInfo> mAvailableRecognizerInfos = new ArrayList<>();
|
||||
|
||||
ComponentName mCurrentRecognizer;
|
||||
|
||||
public VoiceInputHelper(Context context) {
|
||||
mContext = context;
|
||||
|
||||
mAvailableRecognition = mContext.getPackageManager().queryIntentServices(
|
||||
new Intent(RecognitionService.SERVICE_INTERFACE),
|
||||
PackageManager.GET_META_DATA);
|
||||
}
|
||||
|
||||
/** Draws the UI of the Voice Input picker page. */
|
||||
@@ -113,63 +109,120 @@ public final class VoiceInputHelper {
|
||||
mCurrentRecognizer = null;
|
||||
}
|
||||
|
||||
// Iterate through all the available recognizers and load up their info to show
|
||||
// in the preference.
|
||||
int size = mAvailableRecognition.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
ResolveInfo resolveInfo = mAvailableRecognition.get(i);
|
||||
ComponentName comp = new ComponentName(resolveInfo.serviceInfo.packageName,
|
||||
resolveInfo.serviceInfo.name);
|
||||
ServiceInfo si = resolveInfo.serviceInfo;
|
||||
String settingsActivity = null;
|
||||
// Always show in voice input settings unless specifically set to False.
|
||||
boolean selectableAsDefault = true;
|
||||
try (XmlResourceParser parser = si.loadXmlMetaData(mContext.getPackageManager(),
|
||||
RecognitionService.SERVICE_META_DATA)) {
|
||||
if (parser == null) {
|
||||
throw new XmlPullParserException("No " + RecognitionService.SERVICE_META_DATA
|
||||
+ " meta-data for " + si.packageName);
|
||||
}
|
||||
final ArrayList<RecognizerInfo> validRecognitionServices =
|
||||
validRecognitionServices(mContext);
|
||||
|
||||
Resources res = mContext.getPackageManager().getResourcesForApplication(
|
||||
si.applicationInfo);
|
||||
|
||||
AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||
|
||||
int type;
|
||||
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
||||
&& type != XmlPullParser.START_TAG) {
|
||||
// Intentionally do nothing.
|
||||
}
|
||||
|
||||
String nodeName = parser.getName();
|
||||
if (!"recognition-service".equals(nodeName)) {
|
||||
throw new XmlPullParserException(
|
||||
"Meta-data does not start with recognition-service tag");
|
||||
}
|
||||
|
||||
TypedArray array = res.obtainAttributes(attrs,
|
||||
com.android.internal.R.styleable.RecognitionService);
|
||||
settingsActivity = array.getString(
|
||||
com.android.internal.R.styleable.RecognitionService_settingsActivity);
|
||||
selectableAsDefault = array.getBoolean(
|
||||
com.android.internal.R.styleable.RecognitionService_selectableAsDefault,
|
||||
true);
|
||||
array.recycle();
|
||||
} catch (XmlPullParserException e) {
|
||||
Log.e(TAG, "error parsing recognition service meta-data", e);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "error parsing recognition service meta-data", e);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.e(TAG, "error parsing recognition service meta-data", e);
|
||||
}
|
||||
// The current recognizer must always be shown in the settings, whatever its
|
||||
// selectableAsDefault value is.
|
||||
if (selectableAsDefault || comp.equals(mCurrentRecognizer)) {
|
||||
mAvailableRecognizerInfos.add(new RecognizerInfo(mContext.getPackageManager(),
|
||||
resolveInfo.serviceInfo, settingsActivity, selectableAsDefault));
|
||||
// Filter all recognizers which can be selected as default or are the current recognizer.
|
||||
mAvailableRecognizerInfos = new ArrayList<>();
|
||||
for (RecognizerInfo recognizerInfo: validRecognitionServices) {
|
||||
if (recognizerInfo.mSelectableAsDefault || new ComponentName(
|
||||
recognizerInfo.mService.packageName, recognizerInfo.mService.name)
|
||||
.equals(mCurrentRecognizer)) {
|
||||
mAvailableRecognizerInfos.add(recognizerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(mAvailableRecognizerInfos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query all services with {@link RecognitionService#SERVICE_INTERFACE} intent. Filter only
|
||||
* those which have proper xml meta-data which start with a `recognition-service` tag.
|
||||
* Filtered services are sorted by their labels in the ascending order.
|
||||
*
|
||||
* @param context {@link Context} inside which the settings app is run.
|
||||
*
|
||||
* @return {@link ArrayList}<{@link RecognizerInfo}>
|
||||
* containing info about the filtered speech recognition services.
|
||||
*/
|
||||
static ArrayList<RecognizerInfo> validRecognitionServices(Context context) {
|
||||
final List<ResolveInfo> resolvedRecognitionServices =
|
||||
context.getPackageManager().queryIntentServices(
|
||||
new Intent(RecognitionService.SERVICE_INTERFACE),
|
||||
PackageManager.GET_META_DATA);
|
||||
|
||||
final ArrayList<RecognizerInfo> validRecognitionServices = new ArrayList<>();
|
||||
|
||||
for (ResolveInfo resolveInfo: resolvedRecognitionServices) {
|
||||
final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
|
||||
|
||||
final Pair<String, Boolean> recognitionServiceAttributes =
|
||||
parseRecognitionServiceXmlMetadata(context, serviceInfo);
|
||||
|
||||
if (recognitionServiceAttributes != null) {
|
||||
validRecognitionServices.add(new RecognizerInfo(
|
||||
context.getPackageManager(),
|
||||
serviceInfo,
|
||||
recognitionServiceAttributes.first /* settingsActivity */,
|
||||
recognitionServiceAttributes.second /* selectableAsDefault */));
|
||||
}
|
||||
}
|
||||
|
||||
return validRecognitionServices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load recognition service's xml meta-data and parse it. Return the meta-data attributes,
|
||||
* namely, `settingsActivity` {@link String} and `selectableAsDefault` {@link Boolean}.
|
||||
*
|
||||
* <p>Parsing fails if the meta-data for the given service is not found
|
||||
* or the found meta-data does not start with a `recognition-service`.</p>
|
||||
*
|
||||
* @param context {@link Context} inside which the settings app is run.
|
||||
* @param serviceInfo {@link ServiceInfo} containing info
|
||||
* about the speech recognition service in question.
|
||||
*
|
||||
* @return {@link Pair}<{@link String}, {@link Boolean}> containing `settingsActivity`
|
||||
* and `selectableAsDefault` attributes if the parsing was successful, {@code null} otherwise.
|
||||
*/
|
||||
private static Pair<String, Boolean> parseRecognitionServiceXmlMetadata(
|
||||
Context context, ServiceInfo serviceInfo) {
|
||||
// Default recognition service attribute values.
|
||||
// Every recognizer can be selected unless specified otherwise.
|
||||
String settingsActivity;
|
||||
boolean selectableAsDefault = true;
|
||||
|
||||
// Parse xml meta-data.
|
||||
try (XmlResourceParser parser = serviceInfo.loadXmlMetaData(
|
||||
context.getPackageManager(), RecognitionService.SERVICE_META_DATA)) {
|
||||
if (parser == null) {
|
||||
throw new XmlPullParserException(String.format("No %s meta-data for %s package",
|
||||
RecognitionService.SERVICE_META_DATA, serviceInfo.packageName));
|
||||
}
|
||||
|
||||
final Resources res = context.getPackageManager().getResourcesForApplication(
|
||||
serviceInfo.applicationInfo);
|
||||
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||
|
||||
// Xml meta-data must start with a `recognition-service tag`.
|
||||
int type;
|
||||
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
||||
&& type != XmlPullParser.START_TAG) {
|
||||
// Intentionally do nothing.
|
||||
}
|
||||
|
||||
final String nodeName = parser.getName();
|
||||
if (!"recognition-service".equals(nodeName)) {
|
||||
throw new XmlPullParserException(String.format(
|
||||
"%s package meta-data does not start with a `recognition-service` tag",
|
||||
serviceInfo.packageName));
|
||||
}
|
||||
|
||||
final TypedArray array = res.obtainAttributes(attrs,
|
||||
com.android.internal.R.styleable.RecognitionService);
|
||||
settingsActivity = array.getString(
|
||||
com.android.internal.R.styleable.RecognitionService_settingsActivity);
|
||||
selectableAsDefault = array.getBoolean(
|
||||
com.android.internal.R.styleable.RecognitionService_selectableAsDefault,
|
||||
selectableAsDefault);
|
||||
array.recycle();
|
||||
} catch (XmlPullParserException | IOException
|
||||
| PackageManager.NameNotFoundException e) {
|
||||
Log.e(TAG, String.format("Error parsing %s package recognition service meta-data",
|
||||
serviceInfo.packageName), e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return Pair.create(settingsActivity, selectableAsDefault);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ import androidx.preference.PreferenceGroup;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.Settings.TetherSettingsActivity;
|
||||
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.gestures.OneHandedSettingsUtils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
@@ -127,7 +128,7 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
|
||||
return false;
|
||||
}
|
||||
final Intent shortcutIntent = createResultIntent(
|
||||
buildShortcutIntent(info),
|
||||
buildShortcutIntent(uiContext, info),
|
||||
info, clickTarget.getTitle());
|
||||
mHost.setResult(Activity.RESULT_OK, shortcutIntent);
|
||||
logCreateShortcut(info);
|
||||
@@ -210,10 +211,14 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
|
||||
info.activityInfo.name);
|
||||
}
|
||||
|
||||
private static Intent buildShortcutIntent(ResolveInfo info) {
|
||||
return new Intent(SHORTCUT_PROBE)
|
||||
private static Intent buildShortcutIntent(Context context, ResolveInfo info) {
|
||||
Intent intent = new Intent(SHORTCUT_PROBE)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
.setClassName(info.activityInfo.packageName, info.activityInfo.name);
|
||||
if (ActivityEmbeddingUtils.isEmbeddingActivityEnabled(context)) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
|
||||
private static ShortcutInfo createShortcutInfo(Context context, Intent shortcutIntent,
|
||||
@@ -277,8 +282,8 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
|
||||
ResolveInfo ri = context.getPackageManager().resolveActivity(si.getIntent(), 0);
|
||||
|
||||
if (ri != null) {
|
||||
updatedShortcuts.add(createShortcutInfo(context, buildShortcutIntent(ri), ri,
|
||||
si.getShortLabel()));
|
||||
updatedShortcuts.add(createShortcutInfo(context,
|
||||
buildShortcutIntent(context, ri), ri, si.getShortLabel()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,26 +16,83 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
|
||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowFragment;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link AccessibilityButtonFragment}. */
|
||||
@Config(shadows = ShadowFragment.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AccessibilityButtonFragmentTest {
|
||||
|
||||
private Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Rule
|
||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Spy
|
||||
private Resources mResources = spy(mContext.getResources());
|
||||
private AccessibilityButtonFragment mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mFragment = spy(new TestAccessibilityButtonFragment(mContext));
|
||||
when(mFragment.getResources()).thenReturn(mResources);
|
||||
when(mFragment.getActivity()).thenReturn(Robolectric.setupActivity(FragmentActivity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreate_navigationGestureEnabled_setCorrectTitle() {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
|
||||
.thenReturn(NAV_BAR_MODE_GESTURAL);
|
||||
|
||||
mFragment.onAttach(mContext);
|
||||
mFragment.onCreate(Bundle.EMPTY);
|
||||
|
||||
assertThat(mFragment.getActivity().getTitle().toString()).isEqualTo(
|
||||
mContext.getString(R.string.accessibility_button_gesture_title));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreate_navigationGestureDisabled_setCorrectTitle() {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
|
||||
.thenReturn(NAV_BAR_MODE_2BUTTON);
|
||||
|
||||
mFragment.onAttach(mContext);
|
||||
mFragment.onCreate(Bundle.EMPTY);
|
||||
|
||||
assertThat(mFragment.getActivity().getTitle().toString()).isEqualTo(
|
||||
mContext.getString(R.string.accessibility_button_title));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonIndexableKeys_existInXmlLayout() {
|
||||
@@ -47,4 +104,37 @@ public class AccessibilityButtonFragmentTest {
|
||||
|
||||
assertThat(keys).containsAtLeastElementsIn(niks);
|
||||
}
|
||||
|
||||
private static class TestAccessibilityButtonFragment extends AccessibilityButtonFragment {
|
||||
|
||||
private final Context mContext;
|
||||
private final PreferenceManager mPreferenceManager;
|
||||
|
||||
TestAccessibilityButtonFragment(Context context) {
|
||||
super();
|
||||
mContext = context;
|
||||
mPreferenceManager = new PreferenceManager(context);
|
||||
mPreferenceManager.setPreferences(mPreferenceManager.createPreferenceScreen(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPreferenceScreenResId() {
|
||||
return R.xml.placeholder_prefs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreferenceScreen getPreferenceScreen() {
|
||||
return mPreferenceManager.getPreferenceScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreferenceManager getPreferenceManager() {
|
||||
return mPreferenceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,8 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
|
||||
new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
|
||||
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
assertThat(mController.getSummary().toString()).isEmpty();
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
mContext.getString(R.string.location_time_zone_detection_auto_is_on));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user