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

Commit 1550c904 authored by Darren Kuo's avatar Darren Kuo Committed by Android (Google) Code Review
Browse files

Merge "Write default ContextualSearch package to secure setting." into main

parents ef0cc5fa 9a266b3e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -12704,6 +12704,16 @@ public final class Settings {
         * @hide
         */
        public static final String CHARGE_OPTIMIZATION_MODE = "charge_optimization_mode";
        /**
         * String property which contains the package name of the contextual
         * search provider supplied by individual OEM's
         * R.string.config_defaultContextualSearchPackageName.
         *
         * @hide
         */
        @Readable
        public static final String CONTEXTUAL_SEARCH_PACKAGE = "contextual_search_package";
    }
    /**
+1 −0
Original line number Diff line number Diff line
@@ -679,6 +679,7 @@ public class SettingsBackupTest {
                 Settings.Secure.COMPLETED_CATEGORY_PREFIX,
                 Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS,
                 Settings.Secure.CONTENT_CAPTURE_ENABLED,
                 Settings.Secure.CONTEXTUAL_SEARCH_PACKAGE,
                 Settings.Secure.DEFAULT_INPUT_METHOD,
                 Settings.Secure.DEFAULT_DEVICE_INPUT_METHOD,
                 Settings.Secure.DEVICE_PAIRED,
+22 −2
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import android.os.ResultReceiver;
import android.os.ServiceManager;
import android.os.ShellCallback;
import android.os.SystemClock;
import android.provider.Settings;
import android.util.Log;
import android.util.Slog;
import android.view.IWindowManager;
@@ -168,6 +169,8 @@ public class ContextualSearchManagerService extends SystemService {
                IWindowManager.Stub.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE)),
                mContext.getSystemService(AppOpsManager.class),
                mAssistDataCallbacks, mLock, OP_ASSIST_STRUCTURE, OP_ASSIST_SCREENSHOT);

        updateSecureSetting();
    }

    @Override
@@ -175,6 +178,22 @@ public class ContextualSearchManagerService extends SystemService {
        publishBinderService(CONTEXTUAL_SEARCH_SERVICE, new ContextualSearchManagerStub());
    }

    private void updateSecureSetting() {
        // Write default package to secure setting every time there is a change. If OEM didn't
        // supply a new value in their config, then we would write empty string.
        Settings.Secure.putString(
            mContext.getContentResolver(),
            Settings.Secure.CONTEXTUAL_SEARCH_PACKAGE,
            getContextualSearchPackageName());
    }

    private String getContextualSearchPackageName() {
      synchronized (this) {
         return mTemporaryPackage != null ? mTemporaryPackage : mContext
                .getResources().getString(R.string.config_defaultContextualSearchPackageName);
      }
    }

    void resetTemporaryPackage() {
        synchronized (this) {
            enforceOverridingPermission("resetTemporaryPackage");
@@ -184,6 +203,7 @@ public class ContextualSearchManagerService extends SystemService {
            }
            if (DEBUG_USER) Log.d(TAG, "mTemporaryPackage reset.");
            mTemporaryPackage = null;
            updateSecureSetting();
        }
    }

@@ -212,6 +232,7 @@ public class ContextualSearchManagerService extends SystemService {
                mTemporaryHandler.removeMessages(MSG_RESET_TEMPORARY_PACKAGE);
            }
            mTemporaryPackage = temporaryPackage;
            updateSecureSetting();
            mTemporaryHandler.sendEmptyMessageDelayed(MSG_RESET_TEMPORARY_PACKAGE, durationMs);
            if (DEBUG_USER) Log.d(TAG, "mTemporaryPackage set to " + mTemporaryPackage);
        }
@@ -243,8 +264,7 @@ public class ContextualSearchManagerService extends SystemService {
    private Intent getResolvedLaunchIntent() {
        synchronized (this) {
            // If mTemporaryPackage is not null, use it to get the ContextualSearch intent.
            String csPkgName = mTemporaryPackage != null ? mTemporaryPackage : mContext
                    .getResources().getString(R.string.config_defaultContextualSearchPackageName);
            String csPkgName = getContextualSearchPackageName();
            if (csPkgName.isEmpty()) {
                // Return null if csPackageName is not specified.
                return null;