Only enable device search if the service is enabled
This commit is contained in:
1 parent
891a03ba17
commit
4230a382e4
2 files changed
+27
-21
No files matched your search
@@ -10,7 +10,6 @@ import android.app.search.SearchTarget;
|
||||
import android.app.search.SearchUiManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -147,4 +146,21 @@ public class LawnchairDeviceSearchAlgorithm extends LawnchairSearchAlgorithm imp
|
||||
mCanceled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkSearchCompatibility(Context context) {
|
||||
UI_HELPER_EXECUTOR.execute(() -> {
|
||||
SearchContext searchContext = new SearchContext(1 | 2, 200, new Bundle());
|
||||
SearchUiManager searchManager = context.getSystemService(SearchUiManager.class);
|
||||
SearchSession searchSession = searchManager.createSearchSession(searchContext);
|
||||
Query searchQuery = new Query("dummy", System.currentTimeMillis(), null);
|
||||
searchSession.query(searchQuery, MAIN_EXECUTOR, targets -> {
|
||||
boolean isCompatible = targets.size() != 0;
|
||||
MAIN_EXECUTOR.execute(() -> {
|
||||
PreferenceManager prefs = PreferenceManager.getInstance(context);
|
||||
prefs.getDeviceSearch().set(isCompatible);
|
||||
});
|
||||
searchSession.destroy();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
package app.lawnchair.search
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import app.lawnchair.LawnchairApp
|
||||
import app.lawnchair.allapps.SearchItemBackground
|
||||
import app.lawnchair.preferences.PreferenceManager
|
||||
import app.lawnchair.search.SearchTargetCompat.RESULT_TYPE_APPLICATION
|
||||
import app.lawnchair.search.SearchTargetCompat.RESULT_TYPE_SHORTCUT
|
||||
import com.android.app.search.LayoutType
|
||||
import com.android.app.search.LayoutType.*
|
||||
import com.android.app.search.LayoutType.EMPTY_DIVIDER
|
||||
import com.android.app.search.LayoutType.ICON_SINGLE_VERTICAL_TEXT
|
||||
import com.android.launcher3.BuildConfig
|
||||
import com.android.launcher3.Utilities
|
||||
import com.android.launcher3.allapps.AllAppsGridAdapter
|
||||
@@ -62,25 +60,17 @@ abstract class LawnchairSearchAlgorithm(
|
||||
|
||||
companion object {
|
||||
|
||||
private var hasSearchUiServiceResult: Boolean? = if (Utilities.ATLEAST_S) null else false
|
||||
|
||||
private fun hasSearchUiService(context: Context): Boolean {
|
||||
if (hasSearchUiServiceResult != null) {
|
||||
return hasSearchUiServiceResult!!
|
||||
}
|
||||
val id = context.resources.getIdentifier("config_defaultSearchUiService", "string", "android")
|
||||
var result = false
|
||||
if (id != 0) {
|
||||
val searchUiService = context.resources.getString(id)
|
||||
result = searchUiService.isNotEmpty()
|
||||
}
|
||||
hasSearchUiServiceResult = result
|
||||
return result
|
||||
}
|
||||
private var ranCompatibilityCheck = false
|
||||
|
||||
fun isDeviceSearchEnabled(context: Context): Boolean {
|
||||
if (!Utilities.ATLEAST_S) return false
|
||||
|
||||
val prefs = PreferenceManager.getInstance(context)
|
||||
return prefs.deviceSearch.get() && hasSearchUiService(context) && LawnchairApp.isRecentsEnabled
|
||||
if (!ranCompatibilityCheck) {
|
||||
ranCompatibilityCheck = true
|
||||
LawnchairDeviceSearchAlgorithm.checkSearchCompatibility(context)
|
||||
}
|
||||
return prefs.deviceSearch.get()
|
||||
}
|
||||
|
||||
fun create(context: Context): LawnchairSearchAlgorithm = when {
|
||||
|
||||
Reference in new issue
Block a user