Default emergency gesture setting On.
And a few drive-by fixes: * Move all emergency gesture fragments and controllers to emergency package for better code colocation. * Remove the placeholder video preference from emergency_gesture_settings.xml Bug: 178009196 Test: reran robotests Change-Id: Ifcb591e7ab8e5e5494c480cbbe9410c08c296f8e
This commit is contained in:
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/**
|
||||
* Preference controller for emergency gesture setting's entyrpoint preference
|
||||
*/
|
||||
public class EmergencyGestureEntrypointPreferenceController extends BasePreferenceController {
|
||||
private static final String TAG = "EmergencyGestureEntry";
|
||||
|
||||
@VisibleForTesting
|
||||
static final String ACTION_EMERGENCY_GESTURE_SETTINGS =
|
||||
"com.android.settings.action.emergency_gesture_settings";
|
||||
@VisibleForTesting
|
||||
Intent mIntent;
|
||||
|
||||
private boolean mUseCustomIntent;
|
||||
|
||||
public EmergencyGestureEntrypointPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
final String emergencyGestureSettingsPackageName = context.getResources().getString(
|
||||
R.string.emergency_gesture_settings_package);
|
||||
if (!TextUtils.isEmpty(emergencyGestureSettingsPackageName)) {
|
||||
mUseCustomIntent = true;
|
||||
// Use custom intent if it's configured and system can resolve it.
|
||||
final Intent intent = new Intent(ACTION_EMERGENCY_GESTURE_SETTINGS)
|
||||
.setPackage(emergencyGestureSettingsPackageName);
|
||||
if (canResolveIntent(intent)) {
|
||||
mIntent = intent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final boolean canHandleClicks = !mUseCustomIntent || mIntent != null;
|
||||
if (preference != null) {
|
||||
preference.setEnabled(canHandleClicks);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (TextUtils.equals(getPreferenceKey(), preference.getKey()) && mIntent != null) {
|
||||
mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
mContext.startActivity(mIntent);
|
||||
return true;
|
||||
}
|
||||
return super.handlePreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final boolean isConfigEnabled = mContext.getResources()
|
||||
.getBoolean(R.bool.config_show_emergency_gesture_settings);
|
||||
|
||||
if (!isConfigEnabled) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
if (mUseCustomIntent) {
|
||||
final String packageName = mContext.getResources().getString(
|
||||
R.string.emergency_gesture_settings_package);
|
||||
try {
|
||||
final PackageManager pm = mContext.getPackageManager();
|
||||
final ApplicationInfo appInfo = pm.getApplicationInfo(
|
||||
packageName, PackageManager.MATCH_DISABLED_COMPONENTS
|
||||
| PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS);
|
||||
return mContext.getString(R.string.emergency_gesture_entrypoint_summary,
|
||||
appInfo.loadLabel(pm));
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Failed to get custom summary, falling back.");
|
||||
return super.getSummary();
|
||||
}
|
||||
}
|
||||
|
||||
return super.getSummary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not gesture page content should be suppressed from search.
|
||||
*/
|
||||
public boolean shouldSuppressFromSearch() {
|
||||
return mUseCustomIntent;
|
||||
}
|
||||
|
||||
private boolean canResolveIntent(Intent intent) {
|
||||
final ResolveInfo resolveActivity = mContext.getPackageManager()
|
||||
.resolveActivity(intent, 0);
|
||||
return resolveActivity != null;
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.gestures;
|
||||
|
||||
import static android.content.DialogInterface.BUTTON_POSITIVE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.CustomDialogPreferenceCompat;
|
||||
import com.android.settingslib.emergencynumber.EmergencyNumberUtils;
|
||||
|
||||
/**
|
||||
* A dialog preference allowing user to provide a phone number to call during emergency gesture.
|
||||
*/
|
||||
public class EmergencyGestureNumberOverridePreference extends
|
||||
CustomDialogPreferenceCompat {
|
||||
private static final String TAG = "EmergencyGestureNumberO";
|
||||
@VisibleForTesting
|
||||
EditText mEditText;
|
||||
|
||||
private EmergencyNumberUtils mEmergencyNumberUtils;
|
||||
|
||||
public EmergencyGestureNumberOverridePreference(Context context,
|
||||
AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public EmergencyGestureNumberOverridePreference(Context context, AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public EmergencyGestureNumberOverridePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public EmergencyGestureNumberOverridePreference(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
mEmergencyNumberUtils = new EmergencyNumberUtils(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNegativeButtonText(int negativeButtonTextResId) {
|
||||
super.setNegativeButtonText(negativeButtonTextResId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view) {
|
||||
super.onBindDialogView(view);
|
||||
mEditText = view.findViewById(R.id.emergency_gesture_number_override);
|
||||
final String defaultNumber = mEmergencyNumberUtils.getDefaultPoliceNumber();
|
||||
mEditText.setHint(defaultNumber);
|
||||
final String number = mEmergencyNumberUtils.getPoliceNumber();
|
||||
if (!TextUtils.equals(number, defaultNumber)) {
|
||||
mEditText.setText(number);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == BUTTON_POSITIVE) {
|
||||
final String input = mEditText.getText().toString();
|
||||
if (!TextUtils.isEmpty(input)) {
|
||||
mEmergencyNumberUtils.setEmergencyNumberOverride(input);
|
||||
} else {
|
||||
mEmergencyNumberUtils.setEmergencyNumberOverride(
|
||||
mEmergencyNumberUtils.getDefaultPoliceNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.gestures;
|
||||
|
||||
import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.EMERGENCY_NUMBER_OVERRIDE_AUTHORITY;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.text.Spannable;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
import com.android.settingslib.emergencynumber.EmergencyNumberUtils;
|
||||
|
||||
/**
|
||||
* Preference controller for emergency gesture number override.
|
||||
*/
|
||||
public class EmergencyGestureNumberOverridePreferenceController extends BasePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
@VisibleForTesting
|
||||
EmergencyNumberUtils mEmergencyNumberUtils;
|
||||
private final Handler mHandler;
|
||||
private final ContentObserver mSettingsObserver;
|
||||
private Preference mPreference;
|
||||
|
||||
public EmergencyGestureNumberOverridePreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mEmergencyNumberUtils = new EmergencyNumberUtils(context);
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
mSettingsObserver = new EmergencyGestureNumberOverrideSettingsObserver(mHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mContext.getResources()
|
||||
.getBoolean(R.bool.config_show_emergency_gesture_settings) ? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
String number = mEmergencyNumberUtils.getPoliceNumber();
|
||||
String summary = mContext.getString(R.string.emergency_gesture_call_for_help_summary,
|
||||
number);
|
||||
int numberStartIndex = summary.indexOf(number);
|
||||
if (numberStartIndex < 0) {
|
||||
return summary;
|
||||
}
|
||||
Spannable summarySpan = Spannable.Factory.getInstance().newSpannable(summary);
|
||||
PhoneNumberUtils.addTtsSpan(summarySpan, numberStartIndex,
|
||||
numberStartIndex + number.length());
|
||||
return summarySpan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mContext.getContentResolver().registerContentObserver(EMERGENCY_NUMBER_OVERRIDE_AUTHORITY,
|
||||
false, mSettingsObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mContext.getContentResolver().unregisterContentObserver(mSettingsObserver);
|
||||
}
|
||||
|
||||
private class EmergencyGestureNumberOverrideSettingsObserver extends ContentObserver {
|
||||
EmergencyGestureNumberOverrideSettingsObserver(Handler h) {
|
||||
super(h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
if (mPreference != null) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.widget.Switch;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||
|
||||
/**
|
||||
* Preference controller for emergency gesture setting
|
||||
*/
|
||||
public class EmergencyGesturePreferenceController extends BasePreferenceController implements
|
||||
OnMainSwitchChangeListener {
|
||||
|
||||
@VisibleForTesting
|
||||
static final int ON = 1;
|
||||
@VisibleForTesting
|
||||
static final int OFF = 0;
|
||||
|
||||
private static final String SECURE_KEY = Settings.Secure.EMERGENCY_GESTURE_ENABLED;
|
||||
|
||||
private MainSwitchPreference mSwitchBar;
|
||||
|
||||
public EmergencyGesturePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final boolean isConfigEnabled = mContext.getResources()
|
||||
.getBoolean(R.bool.config_show_emergency_gesture_settings);
|
||||
|
||||
if (!isConfigEnabled) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
final Preference pref = screen.findPreference(mPreferenceKey);
|
||||
mSwitchBar = (MainSwitchPreference) pref;
|
||||
mSwitchBar.setTitle(mContext.getString(R.string.emergency_gesture_switchbar_title));
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.updateStatus(isChecked());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public boolean isChecked() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(), SECURE_KEY, OFF) == ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, isChecked ? ON : OFF);
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.gestures;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
/**
|
||||
* Settings page for emergency gesture
|
||||
*/
|
||||
@SearchIndexable
|
||||
public class EmergencyGestureSettings extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "EmergencyGestureSetting";
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.emergency_gesture_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.EMERGENCY_SOS_GESTURE_SETTINGS;
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.emergency_gesture_settings) {
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
final EmergencyGestureEntrypointPreferenceController controller =
|
||||
new EmergencyGestureEntrypointPreferenceController(context,
|
||||
"dummy_emergency_gesture_pref_key");
|
||||
return !controller.isAvailable()
|
||||
|| controller.shouldSuppressFromSearch();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* Preference controller for emergency sos gesture setting
|
||||
*/
|
||||
public class EmergencyGestureSoundPreferenceController extends GesturePreferenceController {
|
||||
|
||||
@VisibleForTesting
|
||||
static final int ON = 1;
|
||||
@VisibleForTesting
|
||||
static final int OFF = 0;
|
||||
|
||||
private static final String SECURE_KEY = Settings.Secure.EMERGENCY_GESTURE_SOUND_ENABLED;
|
||||
|
||||
public EmergencyGestureSoundPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVideoPrefKey() {
|
||||
return "emergency_gesture_screen_video";
|
||||
}
|
||||
|
||||
private static boolean isGestureAvailable(Context context) {
|
||||
return context.getResources()
|
||||
.getBoolean(R.bool.config_show_emergency_gesture_settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(), SECURE_KEY, ON) == ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
|
||||
isChecked ? ON : OFF);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user