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.
- Loading branch information
1 parent
652113a
commit 1bb59de
Showing
6 changed files
with
324 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package android.ext.settings.app; | ||
|
||
import static android.ext.settings.ExtSettings.CLIPBOARD_READ_ACCESS; | ||
|
||
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.ClipboardReadSetting; | ||
|
||
/** @hide */ | ||
public class AswClipboardRead extends AppSwitch { | ||
public static final AswClipboardRead I = new AswClipboardRead(); | ||
|
||
private AswClipboardRead() { | ||
gosPsFlag = GosPackageState.FLAG_CLIPBOARD_READ; | ||
gosPsFlagNonDefault = GosPackageState.FLAG_CLIPBOARD_READ_NON_DEFAULT; | ||
gosPsFlagSuppressNotif = GosPackageState.FLAG_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 true; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
protected boolean getDefaultValueInner(Context ctx, int userId, ApplicationInfo appInfo, | ||
@Nullable GosPackageStateBase ps, StateInfo si) { | ||
si.defaultValueReason = DVR_DEFAULT_SETTING; | ||
return CLIPBOARD_READ_ACCESS.get(ctx, userId) == ClipboardReadSetting.ALLOWED; | ||
} | ||
|
||
public boolean isNotificationSuppressed(Context ctx, int userId, | ||
@Nullable GosPackageStateBase ps) { | ||
if (isUsingDefaultValue(ps)) { | ||
return CLIPBOARD_READ_ACCESS.get(ctx, userId) == ClipboardReadSetting.BLOCKED; | ||
} | ||
|
||
return isNotificationSuppressed(ps); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
services/core/java/android/content/clipboard/ClipboardManagerInternal.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,8 @@ | ||
package android.content.clipboard; | ||
|
||
/** | ||
* @hide | ||
*/ | ||
public abstract class ClipboardManagerInternal { | ||
public abstract void setAllowOneTimeAccess(String pkg, int userId); | ||
} |
50 changes: 50 additions & 0 deletions
50
services/core/java/com/android/server/clipboard/ClipboardHelper.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,50 @@ | ||
package com.android.server.clipboard; | ||
|
||
import android.content.ClipData; | ||
import android.content.Context; | ||
import android.content.pm.ApplicationInfo; | ||
import android.content.pm.PackageManagerInternal; | ||
import android.ext.settings.app.AswClipboardRead; | ||
import android.os.Process; | ||
|
||
import com.android.server.LocalServices; | ||
import com.android.server.ext.ClipboardReadNotification; | ||
import com.android.server.pm.pkg.GosPackageStatePm; | ||
|
||
class ClipboardHelper { | ||
static final ClipData dummyClip = ClipData.newPlainText(null, ""); | ||
|
||
static int getPackageUid(String pkgName, int userId) { | ||
var pmi = LocalServices.getService(PackageManagerInternal.class); | ||
return pmi.getPackageUid(pkgName, 0, userId); | ||
} | ||
|
||
static boolean isReadAllowedForPackage(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 false; | ||
} | ||
GosPackageStatePm ps = pmi.getGosPackageState(pkgName, userId); | ||
return AswClipboardRead.I.get(ctx, userId, appInfo, ps); | ||
} | ||
|
||
static boolean isNotificationSuppressed(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 AswClipboardRead.I.isNotificationSuppressed(ctx, userId, ps); | ||
} | ||
|
||
static void maybeNotifyAccessDenied(Context ctx, int deviceId, String pkgName, int pkgUid, | ||
String primaryClipPackage, int primaryClipUid) { | ||
var n = ClipboardReadNotification.maybeCreate(ctx, deviceId, pkgName, pkgUid, | ||
primaryClipPackage, primaryClipUid); | ||
if (n != null) { | ||
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
Oops, something went wrong.