summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Taran Singh <tarandeep@google.com> 2023-03-01 18:42:17 +0000
committer Taran Singh <tarandeep@google.com> 2023-03-28 20:09:04 +0000
commitfbc8c2fb7bc9e5f56b0de1a1f528c6b381fe945d (patch)
treec9e702a001ac38cf8ea4378af7fa43665402976a
parent7a98ed5591328a41f74db1552a6d609bdcb805a7 (diff)
Make scribe setting default_on and secure
1. Migrate scribe pref to Settings.Secure 2. Consider enabled when not set. Bug: 272376168 Test: manually Change-Id: I504d18eb421b84a1deb49bd6fc26f6b9bd5803b6
-rw-r--r--core/api/test-current.txt3
-rw-r--r--core/java/android/provider/Settings.java33
-rw-r--r--core/java/android/view/inputmethod/IInputMethodManagerGlobalInvoker.java6
-rw-r--r--core/java/android/view/inputmethod/InputMethodManager.java27
-rw-r--r--core/java/com/android/internal/view/IInputMethodManager.aidl3
-rw-r--r--packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java2
-rw-r--r--services/core/java/com/android/server/inputmethod/InputMethodManagerService.java32
7 files changed, 66 insertions, 40 deletions
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index e93467b90e68..6e1b3484b008 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -2598,7 +2598,6 @@ package android.provider {
field @Deprecated public static final String NOTIFICATION_BUBBLES = "notification_bubbles";
field public static final String OVERLAY_DISPLAY_DEVICES = "overlay_display_devices";
field public static final String SHOW_FIRST_CRASH_DIALOG = "show_first_crash_dialog";
- field public static final String STYLUS_HANDWRITING_ENABLED = "stylus_handwriting_enabled";
field public static final String USER_DISABLED_HDR_FORMATS = "user_disabled_hdr_formats";
field public static final String USER_PREFERRED_REFRESH_RATE = "user_preferred_refresh_rate";
field public static final String USER_PREFERRED_RESOLUTION_HEIGHT = "user_preferred_resolution_height";
@@ -2630,6 +2629,8 @@ package android.provider {
field public static final String SHOW_FIRST_CRASH_DIALOG_DEV_OPTION = "show_first_crash_dialog_dev_option";
field public static final String SHOW_IME_WITH_HARD_KEYBOARD = "show_ime_with_hard_keyboard";
field public static final String STYLUS_BUTTONS_ENABLED = "stylus_buttons_enabled";
+ field public static final int STYLUS_HANDWRITING_DEFAULT_VALUE = 1; // 0x1
+ field public static final String STYLUS_HANDWRITING_ENABLED = "stylus_handwriting_enabled";
field @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public static final String SYNC_PARENT_SOUNDS = "sync_parent_sounds";
field public static final String VOICE_INTERACTION_SERVICE = "voice_interaction_service";
}
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 7ae280fd7d90..c473d3f81823 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -7113,6 +7113,28 @@ public final class Settings {
"input_method_selector_visibility";
/**
+ * Toggle for enabling stylus handwriting. When enabled, current Input method receives
+ * stylus {@link MotionEvent}s if an {@link Editor} is focused.
+ *
+ * @see #STYLUS_HANDWRITING_DEFAULT_VALUE
+ * @hide
+ */
+ @TestApi
+ @Readable
+ @SuppressLint("NoSettingsProvider")
+ public static final String STYLUS_HANDWRITING_ENABLED = "stylus_handwriting_enabled";
+
+ /**
+ * Default value for {@link #STYLUS_HANDWRITING_ENABLED}.
+ *
+ * @hide
+ */
+ @TestApi
+ @Readable
+ @SuppressLint("NoSettingsProvider")
+ public static final int STYLUS_HANDWRITING_DEFAULT_VALUE = 1;
+
+ /**
* The currently selected voice interaction service flattened ComponentName.
* @hide
*/
@@ -16482,17 +16504,6 @@ public final class Settings {
public static final String AUTOFILL_MAX_VISIBLE_DATASETS = "autofill_max_visible_datasets";
/**
- * Toggle for enabling stylus handwriting. When enabled, current Input method receives
- * stylus {@link MotionEvent}s if an {@link Editor} is focused.
- *
- * @hide
- */
- @TestApi
- @Readable
- @SuppressLint("NoSettingsProvider")
- public static final String STYLUS_HANDWRITING_ENABLED = "stylus_handwriting_enabled";
-
- /**
* Indicates whether a stylus has ever been used on the device.
*
* @hide
diff --git a/core/java/android/view/inputmethod/IInputMethodManagerGlobalInvoker.java b/core/java/android/view/inputmethod/IInputMethodManagerGlobalInvoker.java
index d84acc03826b..ce2c18080b91 100644
--- a/core/java/android/view/inputmethod/IInputMethodManagerGlobalInvoker.java
+++ b/core/java/android/view/inputmethod/IInputMethodManagerGlobalInvoker.java
@@ -508,6 +508,7 @@ final class IInputMethodManagerGlobalInvoker {
@AnyThread
static void prepareStylusHandwritingDelegation(
@NonNull IInputMethodClient client,
+ @UserIdInt int userId,
@NonNull String delegatePackageName,
@NonNull String delegatorPackageName) {
final IInputMethodManager service = getService();
@@ -516,7 +517,7 @@ final class IInputMethodManagerGlobalInvoker {
}
try {
service.prepareStylusHandwritingDelegation(
- client, delegatePackageName, delegatorPackageName);
+ client, userId, delegatePackageName, delegatorPackageName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -525,6 +526,7 @@ final class IInputMethodManagerGlobalInvoker {
@AnyThread
static boolean acceptStylusHandwritingDelegation(
@NonNull IInputMethodClient client,
+ @UserIdInt int userId,
@NonNull String delegatePackageName,
@NonNull String delegatorPackageName) {
final IInputMethodManager service = getService();
@@ -533,7 +535,7 @@ final class IInputMethodManagerGlobalInvoker {
}
try {
return service.acceptStylusHandwritingDelegation(
- client, delegatePackageName, delegatorPackageName);
+ client, userId, delegatePackageName, delegatorPackageName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index 36d2b8a89779..515b95cd951d 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -1553,9 +1553,7 @@ public final class InputMethodManager {
if (fallbackContext == null) {
return false;
}
- if (!isStylusHandwritingEnabled(fallbackContext)) {
- return false;
- }
+
return IInputMethodManagerGlobalInvoker.isStylusHandwritingAvailableAsUser(userId);
}
@@ -2244,11 +2242,6 @@ public final class InputMethodManager {
}
boolean useDelegation = !TextUtils.isEmpty(delegatorPackageName);
- if (!isStylusHandwritingEnabled(view.getContext())) {
- Log.w(TAG, "Stylus handwriting pref is disabled. "
- + "Ignoring calls to start stylus handwriting.");
- return false;
- }
checkFocus();
synchronized (mH) {
@@ -2264,7 +2257,8 @@ public final class InputMethodManager {
}
if (useDelegation) {
return IInputMethodManagerGlobalInvoker.acceptStylusHandwritingDelegation(
- mClient, view.getContext().getOpPackageName(), delegatorPackageName);
+ mClient, UserHandle.myUserId(), view.getContext().getOpPackageName(),
+ delegatorPackageName);
} else {
IInputMethodManagerGlobalInvoker.startStylusHandwriting(mClient);
}
@@ -2272,15 +2266,6 @@ public final class InputMethodManager {
}
}
- private boolean isStylusHandwritingEnabled(@NonNull Context context) {
- if (Settings.Global.getInt(context.getContentResolver(),
- Settings.Global.STYLUS_HANDWRITING_ENABLED, 0) == 0) {
- Log.d(TAG, "Stylus handwriting pref is disabled.");
- return false;
- }
- return true;
- }
-
/**
* Prepares delegation of starting stylus handwriting session to a different editor in same
* or different window than the view on which initial handwriting stroke was detected.
@@ -2344,13 +2329,9 @@ public final class InputMethodManager {
fallbackImm.prepareStylusHandwritingDelegation(delegatorView, delegatePackageName);
}
- if (!isStylusHandwritingEnabled(delegatorView.getContext())) {
- Log.w(TAG, "Stylus handwriting pref is disabled. "
- + "Ignoring prepareStylusHandwritingDelegation().");
- return;
- }
IInputMethodManagerGlobalInvoker.prepareStylusHandwritingDelegation(
mClient,
+ UserHandle.myUserId(),
delegatePackageName,
delegatorView.getContext().getOpPackageName());
}
diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl
index 9a4610e8c0a1..549169388e45 100644
--- a/core/java/com/android/internal/view/IInputMethodManager.aidl
+++ b/core/java/com/android/internal/view/IInputMethodManager.aidl
@@ -150,12 +150,13 @@ interface IInputMethodManager {
/** Prepares delegation of starting stylus handwriting session to a different editor **/
void prepareStylusHandwritingDelegation(in IInputMethodClient client,
+ in int userId,
in String delegatePackageName,
in String delegatorPackageName);
/** Accepts and starts a stylus handwriting session for the delegate view **/
boolean acceptStylusHandwritingDelegation(in IInputMethodClient client,
- in String delegatePackageName, in String delegatorPackageName);
+ in int userId, in String delegatePackageName, in String delegatorPackageName);
/** Returns {@code true} if currently selected IME supports Stylus handwriting. */
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
diff --git a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java
index f2f0fe987f36..19f1a86ec90c 100644
--- a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java
+++ b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java
@@ -273,7 +273,6 @@ public class SettingsBackupTest {
Settings.Global.DYNAMIC_POWER_SAVINGS_DISABLE_THRESHOLD,
Settings.Global.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS,
Settings.Global.SMART_SUGGESTIONS_IN_NOTIFICATIONS_FLAGS,
- Settings.Global.STYLUS_HANDWRITING_ENABLED,
Settings.Global.STYLUS_EVER_USED,
Settings.Global.ENABLE_ADB_INCREMENTAL_INSTALL_DEFAULT,
Settings.Global.ENABLE_MULTI_SLOT_TIMEOUT_MILLIS,
@@ -785,6 +784,7 @@ public class SettingsBackupTest {
Settings.Secure.SMS_DEFAULT_APPLICATION,
Settings.Secure.SPELL_CHECKER_ENABLED, // Intentionally removed in Q
Settings.Secure.STYLUS_BUTTONS_ENABLED,
+ Settings.Secure.STYLUS_HANDWRITING_ENABLED,
Settings.Secure.TRUST_AGENTS_INITIALIZED,
Settings.Secure.KNOWN_TRUST_AGENTS_INITIALIZED,
Settings.Secure.TV_APP_USES_NON_SYSTEM_INPUTS,
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 7a0bf0cacdfb..b440208e3e32 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -20,6 +20,8 @@ import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL;
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL;
import static android.os.IServiceManager.DUMP_FLAG_PROTO;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
+import static android.provider.Settings.Secure.STYLUS_HANDWRITING_DEFAULT_VALUE;
+import static android.provider.Settings.Secure.STYLUS_HANDWRITING_ENABLED;
import static android.server.inputmethod.InputMethodManagerServiceProto.BACK_DISPOSITION;
import static android.server.inputmethod.InputMethodManagerServiceProto.BOUND_TO_METHOD;
import static android.server.inputmethod.InputMethodManagerServiceProto.CUR_ATTRIBUTE;
@@ -2067,10 +2069,14 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
}
synchronized (ImfLock.class) {
+ if (!isStylusHandwritingEnabled(mContext, userId)) {
+ return false;
+ }
+
+ // Check if selected IME of current user supports handwriting.
if (userId == mSettings.getCurrentUserId()) {
return mBindingController.supportsStylusHandwriting();
}
-
//TODO(b/197848765): This can be optimized by caching multi-user methodMaps/methodList.
//TODO(b/210039666): use cache.
final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
@@ -2081,6 +2087,18 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
}
}
+ private boolean isStylusHandwritingEnabled(
+ @NonNull Context context, @UserIdInt int userId) {
+ // If user is a profile, use preference of it`s parent profile.
+ final int profileParentUserId = mUserManagerInternal.getProfileParentId(userId);
+ if (Settings.Secure.getIntForUser(context.getContentResolver(),
+ STYLUS_HANDWRITING_ENABLED, STYLUS_HANDWRITING_DEFAULT_VALUE,
+ profileParentUserId) == 0) {
+ return false;
+ }
+ return true;
+ }
+
@GuardedBy("ImfLock.class")
private List<InputMethodInfo> getInputMethodListLocked(@UserIdInt int userId,
@DirectBootAwareness int directBootAwareness, int callingUid) {
@@ -3418,8 +3436,14 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
@Override
public void prepareStylusHandwritingDelegation(
@NonNull IInputMethodClient client,
+ @UserIdInt int userId,
@NonNull String delegatePackageName,
@NonNull String delegatorPackageName) {
+ if (!isStylusHandwritingEnabled(mContext, userId)) {
+ Slog.w(TAG, "Can not prepare stylus handwriting delegation. Stylus handwriting"
+ + " pref is disabled for user: " + userId);
+ return;
+ }
if (!verifyClientAndPackageMatch(client, delegatorPackageName)) {
Slog.w(TAG, "prepareStylusHandwritingDelegation() fail");
throw new IllegalArgumentException("Delegator doesn't match Uid");
@@ -3430,8 +3454,14 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
@Override
public boolean acceptStylusHandwritingDelegation(
@NonNull IInputMethodClient client,
+ @UserIdInt int userId,
@NonNull String delegatePackageName,
@NonNull String delegatorPackageName) {
+ if (!isStylusHandwritingEnabled(mContext, userId)) {
+ Slog.w(TAG, "Can not accept stylus handwriting delegation. Stylus handwriting"
+ + " pref is disabled for user: " + userId);
+ return false;
+ }
if (!verifyDelegator(client, delegatePackageName, delegatorPackageName)) {
return false;
}