This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add per-app clipboard access setting
- Loading branch information
1 parent
6db320e
commit 6ce6622
Showing
7 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
core/java/android/ext/settings/app/AswDenyClipboardRead.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package android.ext.settings.app; | ||
|
||
import android.annotation.Nullable; | ||
import android.content.Context; | ||
import android.content.pm.ApplicationInfo; | ||
import android.content.pm.GosPackageState; | ||
import android.content.pm.GosPackageStateBase; | ||
import android.ext.settings.ExtSettings; | ||
|
||
/** @hide */ | ||
public class AswDenyClipboardRead extends AppSwitch { | ||
public static final AswDenyClipboardRead I = new AswDenyClipboardRead(); | ||
|
||
private AswDenyClipboardRead() { | ||
gosPsFlag = GosPackageState.FLAG_DENY_CLIPBOARD_READ; | ||
gosPsFlagNonDefault = GosPackageState.FLAG_DENY_CLIPBOARD_READ_NON_DEFAULT; | ||
gosPsFlagSuppressNotif = GosPackageState.FLAG_DENY_CLIPBOARD_READ_SUPPRESS_NOTIF; | ||
} | ||
|
||
@Override | ||
public Boolean getImmutableValue(Context ctx, int userId, ApplicationInfo appInfo, | ||
@Nullable GosPackageStateBase ps, StateInfo si) { | ||
if (appInfo.isSystemApp()) { | ||
si.immutabilityReason = IR_IS_SYSTEM_APP; | ||
return false; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
protected boolean getDefaultValueInner(Context ctx, int userId, ApplicationInfo appInfo, | ||
@Nullable GosPackageStateBase ps, StateInfo si) { | ||
si.defaultValueReason = DVR_DEFAULT_SETTING; | ||
return ExtSettings.DENY_CLIPBOARD_READ_BY_DEFAULT.get(ctx, userId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
services/core/java/com/android/server/clipboard/ClipboardAccessHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.android.server.clipboard; | ||
|
||
import android.content.ClipData; | ||
import android.content.Context; | ||
import android.content.pm.ApplicationInfo; | ||
import android.content.pm.GosPackageState; | ||
import android.content.pm.PackageManagerInternal; | ||
import android.ext.SettingsIntents; | ||
import android.ext.settings.app.AswDenyClipboardRead; | ||
import android.os.Process; | ||
|
||
import com.android.internal.R; | ||
import com.android.server.LocalServices; | ||
import com.android.server.ext.AppSwitchNotification; | ||
import com.android.server.pm.pkg.GosPackageStatePm; | ||
|
||
public class ClipboardAccessHelper { | ||
static final ClipData dummyClip = ClipData.newPlainText(null, ""); | ||
|
||
static boolean isReadBlockedForPackage(Context ctx, String pkgName, int userId) { | ||
var pmi = LocalServices.getService(PackageManagerInternal.class); | ||
ApplicationInfo appInfo = pmi.getApplicationInfo(pkgName, 0, Process.SYSTEM_UID, userId); | ||
if (appInfo == null) { | ||
return true; | ||
} | ||
GosPackageStatePm ps = pmi.getGosPackageState(pkgName, userId); | ||
return AswDenyClipboardRead.I.get(ctx, userId, appInfo, ps); | ||
} | ||
|
||
static void maybeNotifyAccessDenied(Context ctx, String pkgName, int userId) { | ||
var pmi = LocalServices.getService(PackageManagerInternal.class); | ||
ApplicationInfo appInfo = pmi.getApplicationInfo(pkgName, 0, Process.SYSTEM_UID, userId); | ||
if (appInfo == null) { | ||
return; | ||
} | ||
var n = AppSwitchNotification.create(ctx, appInfo, SettingsIntents.APP_CLIPBOARD); | ||
n.titleRes = R.string.notif_clipboard_read_deny_title; | ||
n.gosPsFlagSuppressNotif = GosPackageState.FLAG_DENY_CLIPBOARD_READ_SUPPRESS_NOTIF; | ||
n.maybeShow(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters