19
19
import static android .os .UserManager .DISALLOW_INSTALL_UNKNOWN_SOURCES ;
20
20
21
21
import android .accessibilityservice .AccessibilityServiceInfo ;
22
+ import android .annotation .SuppressLint ;
23
+ import android .annotation .TargetApi ;
22
24
import android .app .Activity ;
23
25
import android .app .AlertDialog ;
24
26
import android .app .Fragment ;
35
37
import android .net .Uri ;
36
38
import android .os .AsyncTask ;
37
39
import android .os .BatteryManager ;
40
+ import android .os .Build ;
38
41
import android .os .Bundle ;
39
42
import android .os .UserHandle ;
40
43
import android .os .UserManager ;
@@ -500,14 +503,7 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
500
503
showRemoveDeviceOwnerPrompt ();
501
504
return true ;
502
505
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 ();
511
507
return true ;
512
508
case REQUEST_PROCESS_LOGS :
513
509
showFragment (new ProcessLogsFragment ());
@@ -619,21 +615,16 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
619
615
showFragment (new DelegatedCertInstallerFragment ());
620
616
return true ;
621
617
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 );
625
619
return true ;
626
620
case REENABLE_STATUS_BAR :
627
- mDevicePolicyManager . setStatusBarDisabled (mAdminComponentName , false );
621
+ setStatusBarDisabled (false );
628
622
return true ;
629
623
case DISABLE_KEYGUARD :
630
- if (!mDevicePolicyManager .setKeyguardDisabled (mAdminComponentName , true )) {
631
- // this should not happen
632
- showToast ("Unable to disable keyguard" );
633
- }
624
+ setKeyGuardDisabled (true );
634
625
return true ;
635
626
case REENABLE_KEYGUARD :
636
- mDevicePolicyManager . setKeyguardDisabled ( mAdminComponentName , false );
627
+ setKeyGuardDisabled ( false );
637
628
return true ;
638
629
case START_KIOSK_MODE :
639
630
showManageLockTaskListPrompt (R .string .kiosk_select_title ,
@@ -681,6 +672,7 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
681
672
}
682
673
683
674
@ Override
675
+ @ SuppressLint ("NewApi" )
684
676
public boolean onPreferenceChange (Preference preference , Object newValue ) {
685
677
String key = preference .getKey ();
686
678
@@ -689,18 +681,16 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
689
681
preference .setSummary ((String ) newValue );
690
682
return true ;
691
683
case DISABLE_CAMERA_KEY :
692
- mDevicePolicyManager . setCameraDisabled (mAdminComponentName , (Boolean ) newValue );
684
+ setCameraDisabled ((Boolean ) newValue );
693
685
// Reload UI to verify the camera is enable / disable correctly.
694
686
reloadCameraDisableUi ();
695
687
return true ;
696
688
case ENABLE_PROCESS_LOGGING :
697
- mDevicePolicyManager .setSecurityLoggingEnabled (mAdminComponentName ,
698
- (Boolean ) newValue );
689
+ setSecurityLoggingEnabled ((Boolean ) newValue );
699
690
reloadEnableProcessLoggingUi ();
700
691
return true ;
701
692
case DISABLE_SCREEN_CAPTURE_KEY :
702
- mDevicePolicyManager .setScreenCaptureDisabled (mAdminComponentName ,
703
- (Boolean ) newValue );
693
+ setScreenCaptureDisabled ((Boolean ) newValue );
704
694
// Reload UI to verify that screen capture was enabled / disabled correctly.
705
695
reloadScreenCaptureDisableUi ();
706
696
return true ;
@@ -736,6 +726,58 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
736
726
return false ;
737
727
}
738
728
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
+
739
781
/**
740
782
* Dispatches an intent to capture image or video.
741
783
*/
@@ -956,6 +998,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
956
998
/**
957
999
* Shows a message box with the device wifi mac address.
958
1000
*/
1001
+ @ TargetApi (Build .VERSION_CODES .N )
959
1002
private void showWifiMacAddress () {
960
1003
final String macAddress = mDevicePolicyManager .getWifiMacAddress (mAdminComponentName );
961
1004
final String message = macAddress != null ? macAddress
@@ -1068,6 +1111,7 @@ private void disableIncompatibleManagementOptionsByApiLevel() {
1068
1111
* Shows the default response for future runtime permission requests by applications, and lets
1069
1112
* the user change the default value.
1070
1113
*/
1114
+ @ TargetApi (Build .VERSION_CODES .M )
1071
1115
private void showSetPermissionPolicyDialog () {
1072
1116
if (getActivity () == null || getActivity ().isFinishing ()) {
1073
1117
return ;
@@ -1190,6 +1234,7 @@ private void showDisableAccountTypeList() {
1190
1234
* Shows a prompt asking for the username of the new user and whether the setup wizard should
1191
1235
* be skipped.
1192
1236
*/
1237
+ @ TargetApi (Build .VERSION_CODES .N )
1193
1238
private void showCreateAndManageUserPrompt () {
1194
1239
if (getActivity () == null || getActivity ().isFinishing ()) {
1195
1240
return ;
@@ -1317,11 +1362,13 @@ public void onClick(DialogInterface dialogInterface, int i) {
1317
1362
.show ();
1318
1363
}
1319
1364
1365
+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
1320
1366
private void reloadCameraDisableUi () {
1321
1367
boolean isCameraDisabled = mDevicePolicyManager .getCameraDisabled (mAdminComponentName );
1322
1368
mDisableCameraSwitchPreference .setChecked (isCameraDisabled );
1323
1369
}
1324
1370
1371
+ @ TargetApi (Build .VERSION_CODES .N )
1325
1372
private void reloadEnableProcessLoggingUi () {
1326
1373
if (mEnableProcessLoggingPreference .isEnabled ()) {
1327
1374
boolean isProcessLoggingEnabled = mDevicePolicyManager .isSecurityLoggingEnabled (
@@ -1331,19 +1378,22 @@ private void reloadEnableProcessLoggingUi() {
1331
1378
}
1332
1379
}
1333
1380
1381
+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
1334
1382
private void reloadScreenCaptureDisableUi () {
1335
1383
boolean isScreenCaptureDisabled = mDevicePolicyManager .getScreenCaptureDisabled (
1336
1384
mAdminComponentName );
1337
1385
mDisableScreenCaptureSwitchPreference .setChecked (isScreenCaptureDisabled );
1338
1386
}
1339
1387
1388
+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
1340
1389
private void reloadSetAutoTimeRequiredUi () {
1341
1390
if (mDevicePolicyManager .isDeviceOwnerApp (mPackageName )) {
1342
1391
boolean isAutoTimeRequired = mDevicePolicyManager .getAutoTimeRequired ();
1343
1392
mSetAutoTimeRequiredPreference .setChecked (isAutoTimeRequired );
1344
1393
}
1345
1394
}
1346
1395
1396
+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
1347
1397
private void reloadMuteAudioUi () {
1348
1398
final boolean isAudioMuted = mDevicePolicyManager .isMasterVolumeMuted (mAdminComponentName );
1349
1399
mMuteAudioSwitchPreference .setChecked (isAudioMuted );
@@ -1542,6 +1592,7 @@ public void onClick(DialogInterface dialog, int which) {
1542
1592
*
1543
1593
* Once the alias is chosen and deleted, a {@link Toast} shows status- success or failure.
1544
1594
*/
1595
+ @ TargetApi (Build .VERSION_CODES .N )
1545
1596
private void choosePrivateKeyForRemoval () {
1546
1597
KeyChain .choosePrivateKeyAlias (getActivity (), new KeyChainAliasCallback () {
1547
1598
@ Override
@@ -1795,6 +1846,7 @@ public void onClick(DialogInterface dialog, int position) {
1795
1846
/**
1796
1847
* Shows an alert dialog which displays a list of suspended/non-suspended apps.
1797
1848
*/
1849
+ @ TargetApi (Build .VERSION_CODES .N )
1798
1850
private void showSuspendAppsPrompt (final boolean forUnsuspending ) {
1799
1851
final List <String > showApps = new ArrayList <>();
1800
1852
if (forUnsuspending ) {
@@ -2063,6 +2115,7 @@ private void showWifiConfigCreationDialog() {
2063
2115
dialog .show (getFragmentManager (), TAG_WIFI_CONFIG_CREATION );
2064
2116
}
2065
2117
2118
+ @ TargetApi (Build .VERSION_CODES .N )
2066
2119
private void reboot () {
2067
2120
if (mTelephonyManager .getCallState () != TelephonyManager .CALL_STATE_IDLE ) {
2068
2121
showToast (R .string .reboot_error_msg );
@@ -2071,12 +2124,7 @@ private void reboot() {
2071
2124
mDevicePolicyManager .reboot (mAdminComponentName );
2072
2125
}
2073
2126
2074
- abstract class ManageLockTaskListCallback {
2127
+ abstract class ManageLockTaskListCallback {
2075
2128
public abstract void onPositiveButtonClicked (String [] lockTaskArray );
2076
2129
}
2077
-
2078
- @ Override
2079
- public Context getContext () {
2080
- return (Context ) getActivity ();
2081
- }
2082
2130
}
0 commit comments