1919import static android .os .UserManager .DISALLOW_INSTALL_UNKNOWN_SOURCES ;
2020
2121import android .accessibilityservice .AccessibilityServiceInfo ;
22+ import android .annotation .SuppressLint ;
23+ import android .annotation .TargetApi ;
2224import android .app .Activity ;
2325import android .app .AlertDialog ;
2426import android .app .Fragment ;
3537import android .net .Uri ;
3638import android .os .AsyncTask ;
3739import android .os .BatteryManager ;
40+ import android .os .Build ;
3841import android .os .Bundle ;
3942import android .os .UserHandle ;
4043import android .os .UserManager ;
@@ -500,14 +503,7 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
500503 showRemoveDeviceOwnerPrompt ();
501504 return true ;
502505 case REQUEST_BUGREPORT_KEY :
503- boolean startedSuccessfully = mDevicePolicyManager .requestBugreport (
504- mAdminComponentName );
505- if (!startedSuccessfully ) {
506- Context context = getContext ();
507- Util .showNotification (context , R .string .bugreport_title ,
508- context .getString (R .string .bugreport_failure_throttled ),
509- Util .BUGREPORT_NOTIFICATION_ID );
510- }
506+ requestBugReport ();
511507 return true ;
512508 case REQUEST_PROCESS_LOGS :
513509 showFragment (new ProcessLogsFragment ());
@@ -619,21 +615,16 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
619615 showFragment (new DelegatedCertInstallerFragment ());
620616 return true ;
621617 case DISABLE_STATUS_BAR :
622- if (!mDevicePolicyManager .setStatusBarDisabled (mAdminComponentName , true )) {
623- showToast ("Unable to disable status bar when lock password is set." );
624- }
618+ setStatusBarDisabled (true );
625619 return true ;
626620 case REENABLE_STATUS_BAR :
627- mDevicePolicyManager . setStatusBarDisabled (mAdminComponentName , false );
621+ setStatusBarDisabled (false );
628622 return true ;
629623 case DISABLE_KEYGUARD :
630- if (!mDevicePolicyManager .setKeyguardDisabled (mAdminComponentName , true )) {
631- // this should not happen
632- showToast ("Unable to disable keyguard" );
633- }
624+ setKeyGuardDisabled (true );
634625 return true ;
635626 case REENABLE_KEYGUARD :
636- mDevicePolicyManager . setKeyguardDisabled ( mAdminComponentName , false );
627+ setKeyGuardDisabled ( false );
637628 return true ;
638629 case START_KIOSK_MODE :
639630 showManageLockTaskListPrompt (R .string .kiosk_select_title ,
@@ -681,6 +672,7 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
681672 }
682673
683674 @ Override
675+ @ SuppressLint ("NewApi" )
684676 public boolean onPreferenceChange (Preference preference , Object newValue ) {
685677 String key = preference .getKey ();
686678
@@ -689,18 +681,16 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
689681 preference .setSummary ((String ) newValue );
690682 return true ;
691683 case DISABLE_CAMERA_KEY :
692- mDevicePolicyManager . setCameraDisabled (mAdminComponentName , (Boolean ) newValue );
684+ setCameraDisabled ((Boolean ) newValue );
693685 // Reload UI to verify the camera is enable / disable correctly.
694686 reloadCameraDisableUi ();
695687 return true ;
696688 case ENABLE_PROCESS_LOGGING :
697- mDevicePolicyManager .setSecurityLoggingEnabled (mAdminComponentName ,
698- (Boolean ) newValue );
689+ setSecurityLoggingEnabled ((Boolean ) newValue );
699690 reloadEnableProcessLoggingUi ();
700691 return true ;
701692 case DISABLE_SCREEN_CAPTURE_KEY :
702- mDevicePolicyManager .setScreenCaptureDisabled (mAdminComponentName ,
703- (Boolean ) newValue );
693+ setScreenCaptureDisabled ((Boolean ) newValue );
704694 // Reload UI to verify that screen capture was enabled / disabled correctly.
705695 reloadScreenCaptureDisableUi ();
706696 return true ;
@@ -736,6 +726,58 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
736726 return false ;
737727 }
738728
729+ @ TargetApi (Build .VERSION_CODES .M )
730+ private void setCameraDisabled (boolean disabled ) {
731+ mDevicePolicyManager .setCameraDisabled (mAdminComponentName , disabled );
732+ }
733+
734+ @ TargetApi (Build .VERSION_CODES .N )
735+ private void setSecurityLoggingEnabled (boolean enabled ) {
736+ mDevicePolicyManager .setSecurityLoggingEnabled (mAdminComponentName , enabled );
737+ }
738+
739+ @ TargetApi (Build .VERSION_CODES .M )
740+ private void setKeyGuardDisabled (boolean disabled ) {
741+ if (!mDevicePolicyManager .setKeyguardDisabled (mAdminComponentName , disabled )) {
742+ // this should not happen
743+ if (disabled ) {
744+ showToast (R .string .unable_disable_keyguard );
745+ } else {
746+ showToast (R .string .unable_enable_keyguard );
747+ }
748+ }
749+ }
750+
751+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
752+ private void setScreenCaptureDisabled (boolean disabled ) {
753+ mDevicePolicyManager .setScreenCaptureDisabled (mAdminComponentName , disabled );
754+ }
755+
756+ private void setMasterVolumeMuted (boolean muted ) {
757+
758+ }
759+
760+ @ TargetApi (Build .VERSION_CODES .N )
761+ private void requestBugReport () {
762+ boolean startedSuccessfully = mDevicePolicyManager .requestBugreport (
763+ mAdminComponentName );
764+ if (!startedSuccessfully ) {
765+ Context context = getActivity ();
766+ Util .showNotification (context , R .string .bugreport_title ,
767+ context .getString (R .string .bugreport_failure_throttled ),
768+ Util .BUGREPORT_NOTIFICATION_ID );
769+ }
770+ }
771+
772+ @ TargetApi (Build .VERSION_CODES .M )
773+ private void setStatusBarDisabled (boolean disable ) {
774+ if (!mDevicePolicyManager .setStatusBarDisabled (mAdminComponentName , disable )) {
775+ if (disable ) {
776+ showToast ("Unable to disable status bar when lock password is set." );
777+ }
778+ }
779+ }
780+
739781 /**
740782 * Dispatches an intent to capture image or video.
741783 */
@@ -956,6 +998,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
956998 /**
957999 * Shows a message box with the device wifi mac address.
9581000 */
1001+ @ TargetApi (Build .VERSION_CODES .N )
9591002 private void showWifiMacAddress () {
9601003 final String macAddress = mDevicePolicyManager .getWifiMacAddress (mAdminComponentName );
9611004 final String message = macAddress != null ? macAddress
@@ -1068,6 +1111,7 @@ private void disableIncompatibleManagementOptionsByApiLevel() {
10681111 * Shows the default response for future runtime permission requests by applications, and lets
10691112 * the user change the default value.
10701113 */
1114+ @ TargetApi (Build .VERSION_CODES .M )
10711115 private void showSetPermissionPolicyDialog () {
10721116 if (getActivity () == null || getActivity ().isFinishing ()) {
10731117 return ;
@@ -1190,6 +1234,7 @@ private void showDisableAccountTypeList() {
11901234 * Shows a prompt asking for the username of the new user and whether the setup wizard should
11911235 * be skipped.
11921236 */
1237+ @ TargetApi (Build .VERSION_CODES .N )
11931238 private void showCreateAndManageUserPrompt () {
11941239 if (getActivity () == null || getActivity ().isFinishing ()) {
11951240 return ;
@@ -1317,11 +1362,13 @@ public void onClick(DialogInterface dialogInterface, int i) {
13171362 .show ();
13181363 }
13191364
1365+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
13201366 private void reloadCameraDisableUi () {
13211367 boolean isCameraDisabled = mDevicePolicyManager .getCameraDisabled (mAdminComponentName );
13221368 mDisableCameraSwitchPreference .setChecked (isCameraDisabled );
13231369 }
13241370
1371+ @ TargetApi (Build .VERSION_CODES .N )
13251372 private void reloadEnableProcessLoggingUi () {
13261373 if (mEnableProcessLoggingPreference .isEnabled ()) {
13271374 boolean isProcessLoggingEnabled = mDevicePolicyManager .isSecurityLoggingEnabled (
@@ -1331,19 +1378,22 @@ private void reloadEnableProcessLoggingUi() {
13311378 }
13321379 }
13331380
1381+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
13341382 private void reloadScreenCaptureDisableUi () {
13351383 boolean isScreenCaptureDisabled = mDevicePolicyManager .getScreenCaptureDisabled (
13361384 mAdminComponentName );
13371385 mDisableScreenCaptureSwitchPreference .setChecked (isScreenCaptureDisabled );
13381386 }
13391387
1388+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
13401389 private void reloadSetAutoTimeRequiredUi () {
13411390 if (mDevicePolicyManager .isDeviceOwnerApp (mPackageName )) {
13421391 boolean isAutoTimeRequired = mDevicePolicyManager .getAutoTimeRequired ();
13431392 mSetAutoTimeRequiredPreference .setChecked (isAutoTimeRequired );
13441393 }
13451394 }
13461395
1396+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
13471397 private void reloadMuteAudioUi () {
13481398 final boolean isAudioMuted = mDevicePolicyManager .isMasterVolumeMuted (mAdminComponentName );
13491399 mMuteAudioSwitchPreference .setChecked (isAudioMuted );
@@ -1542,6 +1592,7 @@ public void onClick(DialogInterface dialog, int which) {
15421592 *
15431593 * Once the alias is chosen and deleted, a {@link Toast} shows status- success or failure.
15441594 */
1595+ @ TargetApi (Build .VERSION_CODES .N )
15451596 private void choosePrivateKeyForRemoval () {
15461597 KeyChain .choosePrivateKeyAlias (getActivity (), new KeyChainAliasCallback () {
15471598 @ Override
@@ -1795,6 +1846,7 @@ public void onClick(DialogInterface dialog, int position) {
17951846 /**
17961847 * Shows an alert dialog which displays a list of suspended/non-suspended apps.
17971848 */
1849+ @ TargetApi (Build .VERSION_CODES .N )
17981850 private void showSuspendAppsPrompt (final boolean forUnsuspending ) {
17991851 final List <String > showApps = new ArrayList <>();
18001852 if (forUnsuspending ) {
@@ -2063,6 +2115,7 @@ private void showWifiConfigCreationDialog() {
20632115 dialog .show (getFragmentManager (), TAG_WIFI_CONFIG_CREATION );
20642116 }
20652117
2118+ @ TargetApi (Build .VERSION_CODES .N )
20662119 private void reboot () {
20672120 if (mTelephonyManager .getCallState () != TelephonyManager .CALL_STATE_IDLE ) {
20682121 showToast (R .string .reboot_error_msg );
@@ -2071,12 +2124,7 @@ private void reboot() {
20712124 mDevicePolicyManager .reboot (mAdminComponentName );
20722125 }
20732126
2074- abstract class ManageLockTaskListCallback {
2127+ abstract class ManageLockTaskListCallback {
20752128 public abstract void onPositiveButtonClicked (String [] lockTaskArray );
20762129 }
2077-
2078- @ Override
2079- public Context getContext () {
2080- return (Context ) getActivity ();
2081- }
20822130}
0 commit comments