Skip to content

Commit

Permalink
Report start op for read and write clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed Aug 4, 2021
1 parent 0545029 commit adadd3c
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Binder;
import android.os.Handler;
import android.os.Looper;
import android.os.ServiceManager;

import github.tornaco.android.thanos.core.app.ThanosManager;
import github.tornaco.android.thanos.core.secure.ops.AppOpsManager;
import util.Consumer;

public class ClipboardManagerProxyProvider {
public static ClipboardManager provide(Context context) {
try {
Expand All @@ -21,20 +26,43 @@ public static ClipboardManager provide(Context context) {


private static class ClipboardManagerProxy extends ClipboardManager {
private final Context context;

public ClipboardManagerProxy(Context context)
throws ServiceManager.ServiceNotFoundException {
super(context, new Handler(Looper.getMainLooper()));
this.context = context;
}

@Override
public ClipData getPrimaryClip() {
logging("ClipboardManagerProxy getPrimaryClip");
ThanosManager.from(context).ifServiceInstalled(new Consumer<ThanosManager>() {
@Override
public void accept(ThanosManager thanosManager) {
thanosManager.getAppOpsManager()
.onStartOp(new Binder(),
AppOpsManager.OP_READ_CLIPBOARD,
Binder.getCallingUid(),
context.getPackageName());
}
});
return super.getPrimaryClip();
}

@Override
public void setPrimaryClip(ClipData clip) {
logging("ClipboardManagerProxy setPrimaryClip");
ThanosManager.from(context).ifServiceInstalled(new Consumer<ThanosManager>() {
@Override
public void accept(ThanosManager thanosManager) {
thanosManager.getAppOpsManager()
.onStartOp(new Binder(),
AppOpsManager.OP_WRITE_CLIPBOARD,
Binder.getCallingUid(),
context.getPackageName());
}
});
super.setPrimaryClip(clip);
}
}
Expand Down

0 comments on commit adadd3c

Please sign in to comment.