Methods Summary |
---|
private final void | addActiveOwnerLocked(int uid, java.lang.String pkg)
final IPackageManager pm = AppGlobals.getPackageManager();
final int targetUserHandle = UserHandle.getCallingUserId();
final long oldIdentity = Binder.clearCallingIdentity();
try {
PackageInfo pi = pm.getPackageInfo(pkg, 0, targetUserHandle);
if (pi == null) {
throw new IllegalArgumentException("Unknown package " + pkg);
}
if (!UserHandle.isSameApp(pi.applicationInfo.uid, uid)) {
throw new SecurityException("Calling uid " + uid
+ " does not own package " + pkg);
}
} catch (RemoteException e) {
// Can't happen; the package manager is in the same process
} finally {
Binder.restoreCallingIdentity(oldIdentity);
}
PerUserClipboard clipboard = getClipboard();
if (clipboard.primaryClip != null && !clipboard.activePermissionOwners.contains(pkg)) {
final int N = clipboard.primaryClip.getItemCount();
for (int i=0; i<N; i++) {
grantItemLocked(clipboard.primaryClip.getItemAt(i), pkg, UserHandle.getUserId(uid));
}
clipboard.activePermissionOwners.add(pkg);
}
|
public void | addPrimaryClipChangedListener(android.content.IOnPrimaryClipChangedListener listener, java.lang.String callingPackage)
synchronized (this) {
getClipboard().primaryClipListeners.register(listener,
new ListenerInfo(Binder.getCallingUid(), callingPackage));
}
|
private final void | checkDataOwnerLocked(android.content.ClipData data, int uid)
final int N = data.getItemCount();
for (int i=0; i<N; i++) {
checkItemOwnerLocked(data.getItemAt(i), uid);
}
|
private final void | checkItemOwnerLocked(ClipData.Item item, int uid)
if (item.getUri() != null) {
checkUriOwnerLocked(item.getUri(), uid);
}
Intent intent = item.getIntent();
if (intent != null && intent.getData() != null) {
checkUriOwnerLocked(intent.getData(), uid);
}
|
private final void | checkUriOwnerLocked(android.net.Uri uri, int uid)
if (!"content".equals(uri.getScheme())) {
return;
}
long ident = Binder.clearCallingIdentity();
try {
// This will throw SecurityException for us.
mAm.checkGrantUriPermission(uid, null, ContentProvider.getUriWithoutUserId(uri),
Intent.FLAG_GRANT_READ_URI_PERMISSION,
ContentProvider.getUserIdFromUri(uri, UserHandle.getUserId(uid)));
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(ident);
}
|
private com.android.server.clipboard.ClipboardService$PerUserClipboard | getClipboard()
return getClipboard(UserHandle.getCallingUserId());
|
private com.android.server.clipboard.ClipboardService$PerUserClipboard | getClipboard(int userId)
synchronized (mClipboards) {
PerUserClipboard puc = mClipboards.get(userId);
if (puc == null) {
puc = new PerUserClipboard(userId);
mClipboards.put(userId, puc);
}
return puc;
}
|
public android.content.ClipData | getPrimaryClip(java.lang.String pkg)
synchronized (this) {
if (mAppOps.noteOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
pkg) != AppOpsManager.MODE_ALLOWED) {
return null;
}
addActiveOwnerLocked(Binder.getCallingUid(), pkg);
return getClipboard().primaryClip;
}
|
public android.content.ClipDescription | getPrimaryClipDescription(java.lang.String callingPackage)
synchronized (this) {
if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
callingPackage) != AppOpsManager.MODE_ALLOWED) {
return null;
}
PerUserClipboard clipboard = getClipboard();
return clipboard.primaryClip != null ? clipboard.primaryClip.getDescription() : null;
}
|
java.util.List | getRelatedProfiles(int userId)
final List<UserInfo> related;
final long origId = Binder.clearCallingIdentity();
try {
related = mUm.getProfiles(userId, true);
} catch (RemoteException e) {
Slog.e(TAG, "Remote Exception calling UserManager: " + e);
return null;
} finally{
Binder.restoreCallingIdentity(origId);
}
return related;
|
private final void | grantItemLocked(ClipData.Item item, java.lang.String pkg, int userId)
if (item.getUri() != null) {
grantUriLocked(item.getUri(), pkg, userId);
}
Intent intent = item.getIntent();
if (intent != null && intent.getData() != null) {
grantUriLocked(intent.getData(), pkg, userId);
}
|
private final void | grantUriLocked(android.net.Uri uri, java.lang.String pkg, int userId)
long ident = Binder.clearCallingIdentity();
try {
int sourceUserId = ContentProvider.getUserIdFromUri(uri, userId);
uri = ContentProvider.getUriWithoutUserId(uri);
mAm.grantUriPermissionFromOwner(mPermissionOwner, Process.myUid(), pkg,
uri, Intent.FLAG_GRANT_READ_URI_PERMISSION, sourceUserId, userId);
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(ident);
}
|
public boolean | hasClipboardText(java.lang.String callingPackage)
synchronized (this) {
if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
callingPackage) != AppOpsManager.MODE_ALLOWED) {
return false;
}
PerUserClipboard clipboard = getClipboard();
if (clipboard.primaryClip != null) {
CharSequence text = clipboard.primaryClip.getItemAt(0).getText();
return text != null && text.length() > 0;
}
return false;
}
|
public boolean | hasPrimaryClip(java.lang.String callingPackage)
synchronized (this) {
if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
callingPackage) != AppOpsManager.MODE_ALLOWED) {
return false;
}
return getClipboard().primaryClip != null;
}
|
public boolean | onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags)
try {
return super.onTransact(code, data, reply, flags);
} catch (RuntimeException e) {
if (!(e instanceof SecurityException)) {
Slog.wtf("clipboard", "Exception: ", e);
}
throw e;
}
|
private void | removeClipboard(int userId)
synchronized (mClipboards) {
mClipboards.remove(userId);
}
|
public void | removePrimaryClipChangedListener(android.content.IOnPrimaryClipChangedListener listener)
synchronized (this) {
getClipboard().primaryClipListeners.unregister(listener);
}
|
private final void | revokeItemLocked(ClipData.Item item)
if (item.getUri() != null) {
revokeUriLocked(item.getUri());
}
Intent intent = item.getIntent();
if (intent != null && intent.getData() != null) {
revokeUriLocked(intent.getData());
}
|
private final void | revokeUriLocked(android.net.Uri uri)
int userId = ContentProvider.getUserIdFromUri(uri,
UserHandle.getUserId(Binder.getCallingUid()));
long ident = Binder.clearCallingIdentity();
try {
uri = ContentProvider.getUriWithoutUserId(uri);
mAm.revokeUriPermissionFromOwner(mPermissionOwner, uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION,
userId);
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(ident);
}
|
private final void | revokeUris(com.android.server.clipboard.ClipboardService$PerUserClipboard clipboard)
if (clipboard.primaryClip == null) {
return;
}
final int N = clipboard.primaryClip.getItemCount();
for (int i=0; i<N; i++) {
revokeItemLocked(clipboard.primaryClip.getItemAt(i));
}
|
public void | setPrimaryClip(android.content.ClipData clip, java.lang.String callingPackage)
synchronized (this) {
if (clip != null && clip.getItemCount() <= 0) {
throw new IllegalArgumentException("No items");
}
final int callingUid = Binder.getCallingUid();
if (mAppOps.noteOp(AppOpsManager.OP_WRITE_CLIPBOARD, callingUid,
callingPackage) != AppOpsManager.MODE_ALLOWED) {
return;
}
checkDataOwnerLocked(clip, callingUid);
final int userId = UserHandle.getUserId(callingUid);
PerUserClipboard clipboard = getClipboard(userId);
revokeUris(clipboard);
setPrimaryClipInternal(clipboard, clip);
List<UserInfo> related = getRelatedProfiles(userId);
if (related != null) {
int size = related.size();
if (size > 1) { // Related profiles list include the current profile.
boolean canCopy = false;
try {
canCopy = !mUm.getUserRestrictions(userId).getBoolean(
UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE);
} catch (RemoteException e) {
Slog.e(TAG, "Remote Exception calling UserManager: " + e);
}
// Copy clip data to related users if allowed. If disallowed, then remove
// primary clip in related users to prevent pasting stale content.
if (!canCopy) {
clip = null;
} else {
clip.fixUrisLight(userId);
}
for (int i = 0; i < size; i++) {
int id = related.get(i).id;
if (id != userId) {
setPrimaryClipInternal(getClipboard(id), clip);
}
}
}
}
}
|
void | setPrimaryClipInternal(com.android.server.clipboard.ClipboardService$PerUserClipboard clipboard, android.content.ClipData clip)
clipboard.activePermissionOwners.clear();
if (clip == null && clipboard.primaryClip == null) {
return;
}
clipboard.primaryClip = clip;
final long ident = Binder.clearCallingIdentity();
final int n = clipboard.primaryClipListeners.beginBroadcast();
try {
for (int i = 0; i < n; i++) {
try {
ListenerInfo li = (ListenerInfo)
clipboard.primaryClipListeners.getBroadcastCookie(i);
if (mAppOps.checkOpNoThrow(AppOpsManager.OP_READ_CLIPBOARD, li.mUid,
li.mPackageName) == AppOpsManager.MODE_ALLOWED) {
clipboard.primaryClipListeners.getBroadcastItem(i)
.dispatchPrimaryClipChanged();
}
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing
// the dead object for us.
}
}
} finally {
clipboard.primaryClipListeners.finishBroadcast();
Binder.restoreCallingIdentity(ident);
}
|