Fix Settings crash after disabling Settings Suggestion
- Settings Suggestion App is responsible for searching, we can not prevent user disable it. Hide search feature if user disable it. Fixes: 118805907 Fixes: 117921464 Test: manual Change-Id: I61c47c52265a6efd79ef2fa60272bf6513e678b1
This commit is contained in:
@@ -25,9 +25,11 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.search.SearchIndexableResources;
|
||||
|
||||
@@ -64,6 +66,13 @@ public interface SearchFeatureProvider {
|
||||
if (activity == null || toolbar == null) {
|
||||
return;
|
||||
}
|
||||
if (!Utils.isPackageEnabled(activity, getSettingsIntelligencePkgName())) {
|
||||
final ViewGroup parent = (ViewGroup)toolbar.getParent();
|
||||
if (parent != null) {
|
||||
parent.setVisibility(View.GONE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Please forgive me for what I am about to do.
|
||||
//
|
||||
// Need to make the navigation icon non-clickable so that the entire card is clickable
|
||||
|
@@ -56,9 +56,15 @@ public class SearchMenuController implements LifecycleObserver, OnCreateOptionsM
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
final Context context = mHost.getContext();
|
||||
final String SettingsIntelligencePkgName = FeatureFactory.getFactory(context)
|
||||
.getSearchFeatureProvider().getSettingsIntelligencePkgName();
|
||||
if (!Utils.isDeviceProvisioned(mHost.getContext())) {
|
||||
return;
|
||||
}
|
||||
if (!Utils.isPackageEnabled(mHost.getContext(), SettingsIntelligencePkgName)) {
|
||||
return;
|
||||
}
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
@@ -72,10 +78,8 @@ public class SearchMenuController implements LifecycleObserver, OnCreateOptionsM
|
||||
searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
|
||||
searchItem.setOnMenuItemClickListener(target -> {
|
||||
final Context context = mHost.getContext();
|
||||
final Intent intent = SearchFeatureProvider.SEARCH_UI_INTENT;
|
||||
intent.setPackage(FeatureFactory.getFactory(mHost.getContext())
|
||||
.getSearchFeatureProvider().getSettingsIntelligencePkgName());
|
||||
intent.setPackage(SettingsIntelligencePkgName);
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider()
|
||||
.action(context, MetricsProto.MetricsEvent.ACTION_SEARCH_RESULTS);
|
||||
mHost.startActivityForResult(intent, 0 /* requestCode */);
|
||||
|
Reference in New Issue
Block a user