Launch customized panic setting intent when configured.
When RRO provides a custom intent package for panic settings and there is an app to handle it, launch the custom intent instead of the AOSP version. Bug: 169946508 Test: robotests Change-Id: I8479c6e0dd4a90b5a03640035b710ae4ccc7809c
This commit is contained in:
@@ -17,10 +17,16 @@
|
||||
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.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
@@ -28,11 +34,19 @@ import com.android.settings.R;
|
||||
* Preference controller for emergency sos gesture setting
|
||||
*/
|
||||
public class PanicGesturePreferenceController extends GesturePreferenceController {
|
||||
private static final String TAG = "PanicGesturePreferenceC";
|
||||
|
||||
@VisibleForTesting
|
||||
static final int ON = 1;
|
||||
@VisibleForTesting
|
||||
static final int OFF = 0;
|
||||
@VisibleForTesting
|
||||
static final String ACTION_PANIC_SETTINGS =
|
||||
"com.android.settings.action.panic_settings";
|
||||
@VisibleForTesting
|
||||
Intent mIntent;
|
||||
|
||||
private boolean mUseCustomIntent;
|
||||
|
||||
private static final String PREF_KEY_VIDEO = "panic_button_screen_video";
|
||||
|
||||
@@ -40,16 +54,38 @@ public class PanicGesturePreferenceController extends GesturePreferenceControlle
|
||||
|
||||
public PanicGesturePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
final String panicSettingsPackageName = context.getResources().getString(
|
||||
R.string.panic_gesture_settings_package);
|
||||
if (!TextUtils.isEmpty(panicSettingsPackageName)) {
|
||||
mUseCustomIntent = true;
|
||||
// Use custom intent if it's configured and system can resolve it.
|
||||
final Intent intent = new Intent(ACTION_PANIC_SETTINGS)
|
||||
.setPackage(panicSettingsPackageName);
|
||||
if (canResolveIntent(intent)) {
|
||||
mIntent = intent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isGestureAvailable(Context context) {
|
||||
return context.getResources()
|
||||
.getBoolean(R.bool.config_show_panic_gesture_settings);
|
||||
@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() {
|
||||
return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
final boolean isConfigEnabled = mContext.getResources()
|
||||
.getBoolean(R.bool.config_show_panic_gesture_settings);
|
||||
|
||||
if (!isConfigEnabled) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,6 +93,32 @@ public class PanicGesturePreferenceController extends GesturePreferenceControlle
|
||||
return TextUtils.equals(getPreferenceKey(), "gesture_panic_button");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canHandleClicks() {
|
||||
return !mUseCustomIntent || mIntent != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
if (mUseCustomIntent) {
|
||||
final String packageName = mContext.getResources().getString(
|
||||
R.string.panic_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.panic_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();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_KEY_VIDEO;
|
||||
@@ -72,4 +134,17 @@ public class PanicGesturePreferenceController extends GesturePreferenceControlle
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
|
||||
isChecked ? ON : OFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
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;
|
||||
@@ -47,5 +48,14 @@ public class PanicGestureSettings extends DashboardFragment {
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.panic_gesture_settings);
|
||||
new BaseSearchIndexProvider(R.xml.panic_gesture_settings) {
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
final PanicGesturePreferenceController controller =
|
||||
new PanicGesturePreferenceController(context,
|
||||
"dummy_panic_gesture_pref_key");
|
||||
return !controller.isAvailable()
|
||||
|| controller.shouldSuppressFromSearch();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user