Merge "Use the text classifier in the right user" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b012745bc0
@@ -234,7 +234,6 @@ public class ClipboardService extends SystemService {
|
|||||||
private final AppOpsManager mAppOps;
|
private final AppOpsManager mAppOps;
|
||||||
private final ContentCaptureManagerInternal mContentCaptureInternal;
|
private final ContentCaptureManagerInternal mContentCaptureInternal;
|
||||||
private final AutofillManagerInternal mAutofillInternal;
|
private final AutofillManagerInternal mAutofillInternal;
|
||||||
private final TextClassificationManager mTextClassificationManager;
|
|
||||||
private final IBinder mPermissionOwner;
|
private final IBinder mPermissionOwner;
|
||||||
private final HostClipboardMonitor mHostClipboardMonitor;
|
private final HostClipboardMonitor mHostClipboardMonitor;
|
||||||
private final Handler mWorkerHandler;
|
private final Handler mWorkerHandler;
|
||||||
@@ -265,8 +264,6 @@ public class ClipboardService extends SystemService {
|
|||||||
mAppOps = (AppOpsManager) getContext().getSystemService(Context.APP_OPS_SERVICE);
|
mAppOps = (AppOpsManager) getContext().getSystemService(Context.APP_OPS_SERVICE);
|
||||||
mContentCaptureInternal = LocalServices.getService(ContentCaptureManagerInternal.class);
|
mContentCaptureInternal = LocalServices.getService(ContentCaptureManagerInternal.class);
|
||||||
mAutofillInternal = LocalServices.getService(AutofillManagerInternal.class);
|
mAutofillInternal = LocalServices.getService(AutofillManagerInternal.class);
|
||||||
mTextClassificationManager = (TextClassificationManager)
|
|
||||||
getContext().getSystemService(Context.TEXT_CLASSIFICATION_SERVICE);
|
|
||||||
final IBinder permOwner = mUgmInternal.newUriPermissionOwner("clipboard");
|
final IBinder permOwner = mUgmInternal.newUriPermissionOwner("clipboard");
|
||||||
mPermissionOwner = permOwner;
|
mPermissionOwner = permOwner;
|
||||||
if (IS_EMULATOR) {
|
if (IS_EMULATOR) {
|
||||||
@@ -659,12 +656,12 @@ public class ClipboardService extends SystemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int userId = UserHandle.getUserId(uid);
|
||||||
if (clip != null) {
|
if (clip != null) {
|
||||||
startClassificationLocked(clip);
|
startClassificationLocked(clip, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update this user
|
// Update this user
|
||||||
final int userId = UserHandle.getUserId(uid);
|
|
||||||
setPrimaryClipInternalLocked(getClipboardLocked(userId), clip, uid, sourcePackage);
|
setPrimaryClipInternalLocked(getClipboardLocked(userId), clip, uid, sourcePackage);
|
||||||
|
|
||||||
// Update related users
|
// Update related users
|
||||||
@@ -763,14 +760,15 @@ public class ClipboardService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private void startClassificationLocked(@NonNull ClipData clip) {
|
private void startClassificationLocked(@NonNull ClipData clip, @UserIdInt int userId) {
|
||||||
TextClassifier classifier;
|
TextClassifier classifier;
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
classifier = mTextClassificationManager.createTextClassificationSession(
|
classifier = createTextClassificationManagerAsUser(userId)
|
||||||
new TextClassificationContext.Builder(
|
.createTextClassificationSession(
|
||||||
getContext().getPackageName(),
|
new TextClassificationContext.Builder(
|
||||||
TextClassifier.WIDGET_TYPE_CLIPBOARD
|
getContext().getPackageName(),
|
||||||
|
TextClassifier.WIDGET_TYPE_CLIPBOARD
|
||||||
).build()
|
).build()
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -1125,4 +1123,8 @@ public class ClipboardService extends SystemService {
|
|||||||
&& item.getIntent() == null;
|
&& item.getIntent() == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TextClassificationManager createTextClassificationManagerAsUser(@UserIdInt int userId) {
|
||||||
|
Context context = getContext().createContextAsUser(UserHandle.of(userId), /* flags= */ 0);
|
||||||
|
return context.getSystemService(TextClassificationManager.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user