Add policy for nearby app streaming
App streaming is when the device starts an app on a virtual display and sends a video stream of the app to nearby devices. The policy specifies options in which app streaming is supported. The default policy is streaming only to devices with the same managed account.
Bug: 179910177
Test: Builds successfully
Change-Id: I1a9424d0de524a0cdfcc00b2bc39196e7f231480
diff --git a/core/api/current.txt b/core/api/current.txt
index 06e3f88..a10ebd4 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -7128,6 +7128,7 @@
method public int getMaximumFailedPasswordsForWipe(@Nullable android.content.ComponentName);
method public long getMaximumTimeToLock(@Nullable android.content.ComponentName);
method @NonNull public java.util.List<java.lang.String> getMeteredDataDisabledPackages(@NonNull android.content.ComponentName);
+ method public int getNearbyAppStreamingPolicy();
method public int getNearbyNotificationStreamingPolicy();
method @Deprecated @ColorInt public int getOrganizationColor(@NonNull android.content.ComponentName);
method @Nullable public CharSequence getOrganizationName(@NonNull android.content.ComponentName);
@@ -7272,6 +7273,7 @@
method public void setMaximumFailedPasswordsForWipe(@NonNull android.content.ComponentName, int);
method public void setMaximumTimeToLock(@NonNull android.content.ComponentName, long);
method @NonNull public java.util.List<java.lang.String> setMeteredDataDisabledPackages(@NonNull android.content.ComponentName, @NonNull java.util.List<java.lang.String>);
+ method public void setNearbyAppStreamingPolicy(int);
method public void setNearbyNotificationStreamingPolicy(int);
method public void setNetworkLoggingEnabled(@Nullable android.content.ComponentName, boolean);
method @Deprecated public void setOrganizationColor(@NonNull android.content.ComponentName, int);
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 6de7b5c..89d08cc 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -7221,6 +7221,42 @@
}
/**
+ * Called by a device/profile owner to set nearby app streaming policy. App streaming is when
+ * the device starts an app on a virtual display and sends a video stream of the app to nearby
+ * devices.
+ *
+ * @param policy One of the {@code NearbyStreamingPolicy} constants.
+ * @throws SecurityException if caller is not a device or profile owner.
+ */
+ public void setNearbyAppStreamingPolicy(@NearbyStreamingPolicy int policy) {
+ throwIfParentInstance("setNearbyAppStreamingPolicy");
+ if (mService == null) {
+ return;
+ }
+ try {
+ mService.setNearbyAppStreamingPolicy(policy);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Returns the current runtime nearby app streaming policy set by the device or profile owner.
+ * The default is {@link #NEARBY_STREAMING_DISABLED}.
+ */
+ public @NearbyStreamingPolicy int getNearbyAppStreamingPolicy() {
+ throwIfParentInstance("getNearbyAppStreamingPolicy");
+ if (mService == null) {
+ return NEARBY_STREAMING_DISABLED;
+ }
+ try {
+ return mService.getNearbyAppStreamingPolicy();
+ } catch (RemoteException re) {
+ throw re.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Called by a device owner, or alternatively a profile owner from Android 8.0 (API level 26) or
* higher, to set whether auto time is required. If auto time is required, no user will be able
* set the date and time and network date and time will be used.
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 394e53f..8a8c69c 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -135,6 +135,9 @@
void setNearbyNotificationStreamingPolicy(int policy);
int getNearbyNotificationStreamingPolicy();
+ void setNearbyAppStreamingPolicy(int policy);
+ int getNearbyAppStreamingPolicy();
+
void setKeyguardDisabledFeatures(in ComponentName who, int which, boolean parent);
int getKeyguardDisabledFeatures(in ComponentName who, int userHandle, boolean parent);
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java b/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java
index f86ca92..a419bf8 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java
@@ -72,6 +72,8 @@
private static final String TAG_DISABLE_ACCOUNT_MANAGEMENT = "disable-account-management";
private static final String TAG_NEARBY_NOTIFICATION_STREAMING_POLICY =
"nearby-notification-streaming-policy";
+ private static final String TAG_NEARBY_APP_STREAMING_POLICY =
+ "nearby-app-streaming-policy";
private static final String TAG_REQUIRE_AUTO_TIME = "require_auto_time";
private static final String TAG_FORCE_EPHEMERAL_USERS = "force_ephemeral_users";
private static final String TAG_IS_NETWORK_LOGGING_ENABLED = "is_network_logging_enabled";
@@ -165,6 +167,9 @@
@DevicePolicyManager.NearbyStreamingPolicy
int mNearbyNotificationStreamingPolicy = NEARBY_STREAMING_DISABLED;
+ @DevicePolicyManager.NearbyStreamingPolicy
+ int mNearbyAppStreamingPolicy = NEARBY_STREAMING_DISABLED;
+
@Nullable
FactoryResetProtectionPolicy mFactoryResetProtectionPolicy = null;
@@ -559,6 +564,10 @@
writeAttributeValueToXml(out, TAG_NEARBY_NOTIFICATION_STREAMING_POLICY,
mNearbyNotificationStreamingPolicy);
}
+ if (mNearbyAppStreamingPolicy != NEARBY_STREAMING_DISABLED) {
+ writeAttributeValueToXml(out, TAG_NEARBY_APP_STREAMING_POLICY,
+ mNearbyAppStreamingPolicy);
+ }
if (!TextUtils.isEmpty(mOrganizationId)) {
writeTextToXml(out, TAG_ORGANIZATION_ID, mOrganizationId);
}
@@ -806,6 +815,8 @@
mPasswordComplexity = parser.getAttributeInt(null, ATTR_VALUE);
} else if (TAG_NEARBY_NOTIFICATION_STREAMING_POLICY.equals(tag)) {
mNearbyNotificationStreamingPolicy = parser.getAttributeInt(null, ATTR_VALUE);
+ } else if (TAG_NEARBY_APP_STREAMING_POLICY.equals(tag)) {
+ mNearbyAppStreamingPolicy = parser.getAttributeInt(null, ATTR_VALUE);
} else if (TAG_ORGANIZATION_ID.equals(tag)) {
type = parser.next();
if (type == TypedXmlPullParser.TEXT) {
@@ -1169,6 +1180,9 @@
pw.print("mNearbyNotificationStreamingPolicy=");
pw.println(mNearbyNotificationStreamingPolicy);
+ pw.print("mNearbyAppStreamingPolicy=");
+ pw.println(mNearbyAppStreamingPolicy);
+
if (!TextUtils.isEmpty(mOrganizationId)) {
pw.print("mOrganizationId=");
pw.println(mOrganizationId);
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 34f6353..1858712 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -7509,6 +7509,42 @@
}
}
+ @Override
+ public void setNearbyAppStreamingPolicy(int policy) {
+ if (!mHasFeature) {
+ return;
+ }
+
+ final CallerIdentity caller = getCallerIdentity();
+ Preconditions.checkCallAuthorization(isDeviceOwner(caller) || isProfileOwner(caller));
+
+ synchronized (getLockObject()) {
+ final ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked(caller);
+ if (admin.mNearbyAppStreamingPolicy != policy) {
+ admin.mNearbyAppStreamingPolicy = policy;
+ saveSettingsLocked(caller.getUserId());
+ }
+ }
+ }
+
+ @Override
+ public int getNearbyAppStreamingPolicy() {
+ if (!mHasFeature) {
+ return NEARBY_STREAMING_DISABLED;
+ }
+
+ final CallerIdentity caller = getCallerIdentity();
+ Preconditions.checkCallAuthorization(
+ isDeviceOwner(caller)
+ || isProfileOwner(caller)
+ || hasCallingOrSelfPermission(permission.READ_NEARBY_STREAMING_POLICY));
+
+ synchronized (getLockObject()) {
+ final ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked(caller);
+ return admin.mNearbyAppStreamingPolicy;
+ }
+ }
+
/**
* Set whether auto time is required by the specified admin (must be device or profile owner).
*/