Skip to content

Commit

Permalink
Merge "Write default ContextualSearch package to secure setting." int…
Browse files Browse the repository at this point in the history
…o main
  • Loading branch information
Darren Kuo authored and Android (Google) Code Review committed Jun 14, 2024
2 parents ef0cc5f + 9a266b3 commit 1550c90
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
10 changes: 10 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -12704,6 +12704,16 @@ public static void setLocationProviderEnabled(ContentResolver cr,
* @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";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
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;
Expand Down Expand Up @@ -168,13 +169,31 @@ public ContextualSearchManagerService(@NonNull Context context) {
IWindowManager.Stub.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE)),
mContext.getSystemService(AppOpsManager.class),
mAssistDataCallbacks, mLock, OP_ASSIST_STRUCTURE, OP_ASSIST_SCREENSHOT);

updateSecureSetting();
}

@Override
public void onStart() {
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");
Expand All @@ -184,6 +203,7 @@ void resetTemporaryPackage() {
}
if (DEBUG_USER) Log.d(TAG, "mTemporaryPackage reset.");
mTemporaryPackage = null;
updateSecureSetting();
}
}

Expand Down Expand Up @@ -212,6 +232,7 @@ public void handleMessage(Message msg) {
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);
}
Expand Down Expand Up @@ -243,8 +264,7 @@ private long getTokenValidDurationMs() {
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;
Expand Down

0 comments on commit 1550c90

Please sign in to comment.