Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 36dd0ca5 authored by kholoud mohamed's avatar kholoud mohamed Committed by Automerger Merge Worker
Browse files

Update Enterprise search keywords/results am: f0645d4c am: 4043a4fb

parents 7d51dc76 4043a4fb
Loading
Loading
Loading
Loading
+414 −0

File added.

Preview size limit exceeded, changes collapsed.

+19 −1
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.settings.intelligence.search.indexing;

import static com.android.settings.intelligence.search.indexing.DevicePolicyResourcesUtils.DEVICE_POLICY_RESOURCES_VERSION_KEY;

import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
@@ -291,11 +294,15 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
        final String fingerprint = Build.FINGERPRINT;
        final String providerVersionedNames =
                IndexDatabaseHelper.buildProviderVersionedNames(context, providers);
        final String devicePolicyResourcesVersion = context.getSystemService(
                DevicePolicyManager.class).getResources().getString(
                        DEVICE_POLICY_RESOURCES_VERSION_KEY, () -> null);
        context.getSharedPreferences(SHARED_PREFS_TAG, Context.MODE_PRIVATE)
                .edit()
                .putBoolean(localeStr, true)
                .putBoolean(fingerprint, true)
                .putString(PREF_KEY_INDEXED_PROVIDERS, providerVersionedNames)
                .putString(DEVICE_POLICY_RESOURCES_VERSION_KEY, devicePolicyResourcesVersion)
                .apply();
    }

@@ -318,10 +325,21 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
        final boolean isIndexed = prefs.getBoolean(fingerprint, false)
                && prefs.getBoolean(localeStr, false)
                && TextUtils.equals(
                prefs.getString(PREF_KEY_INDEXED_PROVIDERS, null), providerVersionedNames);
                prefs.getString(PREF_KEY_INDEXED_PROVIDERS, null), providerVersionedNames)
                && !enterpriseResourcesUpdated(context, prefs);
        return !isIndexed;
    }

    /**
     * returns true if device policy resources have been updated and need reindexing.
     */
    private static boolean enterpriseResourcesUpdated(Context context, SharedPreferences prefs) {
        final String currentVersion = context.getSystemService(DevicePolicyManager.class)
                .getResources().getString(DEVICE_POLICY_RESOURCES_VERSION_KEY, () -> null);
        return !TextUtils.equals(
                prefs.getString(DEVICE_POLICY_RESOURCES_VERSION_KEY, null), currentVersion);
    }

    private void dropTables(SQLiteDatabase db) {
        db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_META_INDEX);
        db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_PREFS_INDEX);
+11 −2
Original line number Diff line number Diff line
@@ -85,7 +85,11 @@ public class XmlParserUtils {
            // It's a resource
            try  {
                final int resValue = Integer.parseInt(keywordRes.substring(1));
                if (DevicePolicyResourcesUtils.isDevicePolicyResource(context, resValue)) {
                    return DevicePolicyResourcesUtils.getDevicePolicyResource(context, resValue);
                } else {
                    return context.getString(resValue);
                }
            } catch (NumberFormatException e) {
                Log.w(TAG, "Failed to parse keyword attribute, skipping " + keywordRes);
                return null;
@@ -111,7 +115,12 @@ public class XmlParserUtils {
    @Nullable
    private static String getData(Context context, AttributeSet set, int[] attrs, int resId) {
        final TypedArray ta = context.obtainStyledAttributes(set, attrs);
        String data = ta.getString(resId);
        String data;
        if (DevicePolicyResourcesUtils.isDevicePolicyResource(context, ta, resId)) {
            data = DevicePolicyResourcesUtils.getDevicePolicyResource(context, ta, resId);
        } else {
            data = ta.getString(resId);
        }
        ta.recycle();
        return data;
    }