Skip to content

Commit f11afc5

Browse files
committed
Switch to printing policy as restriction.
Bug: 64140119 Change-Id: Ib6c39c929c5c698db5c6f4dab649183123370991
1 parent 5138fe2 commit f11afc5

File tree

4 files changed

+6
-42
lines changed

4 files changed

+6
-42
lines changed

app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
269269
private static final String DISABLE_SCREEN_CAPTURE_KEY = "disable_screen_capture";
270270
private static final String DISABLE_STATUS_BAR = "disable_status_bar";
271271
private static final String ENABLE_BACKUP_SERVICE = "enable_backup_service";
272-
private static final String ENABLE_PRINTING = "enable_printing";
273272
private static final String ENABLE_PROCESS_LOGGING = "enable_process_logging";
274273
private static final String ENABLE_NETWORK_LOGGING = "enable_network_logging";
275274
private static final String ENABLE_SYSTEM_APPS_BY_INTENT_KEY = "enable_system_apps_by_intent";
@@ -414,7 +413,6 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
414413

415414
private SwitchPreference mEnableBackupServicePreference;
416415
private SwitchPreference mMandatoryBackupsPreference;
417-
private SwitchPreference mEnablePrintingPreference;
418416
private SwitchPreference mEnableProcessLoggingPreference;
419417
private SwitchPreference mEnableNetworkLoggingPreference;
420418
private SwitchPreference mSetAutoTimeRequiredPreference;
@@ -534,8 +532,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
534532
mEnableBackupServicePreference.setOnPreferenceChangeListener(this);
535533
mMandatoryBackupsPreference = (SwitchPreference) findPreference(MANDATORY_BACKUPS);
536534
mMandatoryBackupsPreference.setOnPreferenceChangeListener(this);
537-
mEnablePrintingPreference = (SwitchPreference) findPreference(ENABLE_PRINTING);
538-
mEnablePrintingPreference.setOnPreferenceChangeListener(this);
539535
findPreference(REQUEST_BUGREPORT_KEY).setOnPreferenceClickListener(this);
540536
mEnableProcessLoggingPreference = (SwitchPreference) findPreference(ENABLE_PROCESS_LOGGING);
541537
mEnableProcessLoggingPreference.setOnPreferenceChangeListener(this);
@@ -649,7 +645,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
649645
reloadMuteAudioUi();
650646
reloadEnableBackupServiceUi();
651647
reloadMandatoryBackupsUi();
652-
reloadEnablePrintingUi();
653648
reloadEnableProcessLoggingUi();
654649
reloadEnableNetworkLoggingUi();
655650
reloadSetAutoTimeRequiredUi();
@@ -1160,10 +1155,6 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
11601155
setupMandatoryBackups(null);
11611156
return true;
11621157
}
1163-
case ENABLE_PRINTING:
1164-
setPrintingEnabled((Boolean) newValue);
1165-
reloadEnablePrintingUi();
1166-
return true;
11671158
case ENABLE_PROCESS_LOGGING:
11681159
setSecurityLoggingEnabled((Boolean) newValue);
11691160
reloadEnableProcessLoggingUi();
@@ -1255,17 +1246,6 @@ private void setScreenCaptureDisabled(boolean disabled) {
12551246
mDevicePolicyManager.setScreenCaptureDisabled(mAdminComponentName, disabled);
12561247
}
12571248

1258-
@TargetApi(Build.VERSION_CODES.P)
1259-
private void setPrintingEnabled(boolean enabled) {
1260-
try {
1261-
ReflectionUtil.invoke(mDevicePolicyManager, "setPrintingEnabled",
1262-
new Class<?>[] {ComponentName.class, boolean.class},
1263-
mAdminComponentName, enabled);
1264-
} catch (ReflectionUtil.ReflectionIsTemporaryException e) {
1265-
Log.e(TAG, "Failed to invoke DevicePolicyManager.setPrintingEnabled", e);
1266-
}
1267-
}
1268-
12691249
@TargetApi(Build.VERSION_CODES.O)
12701250
private boolean isNetworkLoggingEnabled() {
12711251
return mDevicePolicyManager.isNetworkLoggingEnabled(mAdminComponentName);
@@ -2230,16 +2210,6 @@ private void reloadMandatoryBackupsUi() {
22302210
}
22312211
}
22322212

2233-
@TargetApi(Build.VERSION_CODES.P)
2234-
private void reloadEnablePrintingUi() {
2235-
try {
2236-
mEnablePrintingPreference.setChecked(
2237-
(Boolean) ReflectionUtil.invoke(mDevicePolicyManager, "isPrintingEnabled"));
2238-
} catch (ReflectionUtil.ReflectionIsTemporaryException e) {
2239-
Log.e(TAG, "Failed to retrieve printing policies from DevicePolicyManager", e);
2240-
}
2241-
}
2242-
22432213
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
22442214
private void reloadScreenCaptureDisableUi() {
22452215
boolean isScreenCaptureDisabled = mDevicePolicyManager.getScreenCaptureDisabled(

app/src/main/java/com/afwsamples/testdpc/policy/UserRestriction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class UserRestriction {
5252
// TODO: remove it once available in SDK
5353
public static final String DISALLOW_UNIFIED_PASSWORD = "no_unified_password";
5454
public static final String DISALLOW_CONFIG_LOCATION = "no_config_location";
55+
public static final String DISALLOW_PRINTING= "no_printing";
5556

5657
public String key;
5758
public int titleResId;
@@ -198,6 +199,9 @@ public UserRestriction(String key, int titleResId) {
198199
new UserRestriction(
199200
DISALLOW_SHARE_INTO_MANAGED_PROFILE,
200201
R.string.disallow_share_into_work_profile),
202+
new UserRestriction(
203+
DISALLOW_PRINTING,
204+
R.string.disallow_printing),
201205
};
202206

203207
/**
@@ -292,5 +296,6 @@ public UserRestriction(String key, int titleResId) {
292296
DISALLOW_CONFIG_SCREEN_TIMEOUT,
293297
DISALLOW_AMBIENT_DISPLAY,
294298
DISALLOW_SHARE_INTO_MANAGED_PROFILE,
299+
DISALLOW_PRINTING,
295300
};
296301
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@
139139
<string name="set_persistent_device_owner_label">Set</string>
140140
<string name="clear_persistent_device_owner_label">Clear</string>
141141

142-
<!-- Strings for printing settings -->
143-
<string name="printing_settings">Printing settings</string>
144-
<string name="printing_enabled">Printing enabled</string>
145-
146142
<!-- Strings for device reboot -->
147143
<string name="reboot">Reboot device</string>
148144
<string name="reboot_error_msg">Cannot reboot device during an ongoing call.</string>
@@ -430,6 +426,7 @@
430426
<string name="disallow_config_screen_timeout">Disallow config screen timeout</string>
431427
<string name="disallow_ambient_display">Disallow ambient display</string>
432428
<string name="disallow_share_into_work_profile">Disallow sharing data into the profile</string>
429+
<string name="disallow_printing">Disallow printing</string>
433430
<string name="user_restriction_error_msg">Operation not allowed</string>
434431

435432
<!-- Strings for select app -->

app/src/main/res/xml/device_policy_header.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,14 +628,6 @@
628628
testdpc:minSdkVersion="O_MR1" />
629629
</PreferenceCategory>
630630

631-
<PreferenceCategory android:title="@string/printing_settings">
632-
<com.afwsamples.testdpc.common.preference.DpcSwitchPreference
633-
android:key="enable_printing"
634-
android:title="@string/printing_enabled"
635-
testdpc:admin="deviceOwner|profileOwner"
636-
testdpc:minSdkVersion="P" />
637-
</PreferenceCategory>
638-
639631
<PreferenceCategory android:title="@string/transfer_ownership">
640632
<com.afwsamples.testdpc.common.preference.DpcPreference
641633
android:key="transfer_ownership_to_component"

0 commit comments

Comments
 (0)