90
90
import com .afwsamples .testdpc .common .BaseSearchablePolicyPreferenceFragment ;
91
91
import com .afwsamples .testdpc .common .CertificateUtil ;
92
92
import com .afwsamples .testdpc .common .MediaDisplayFragment ;
93
- import com .afwsamples .testdpc .common .ReflectionUtil ;
94
93
import com .afwsamples .testdpc .common .UserArrayAdapter ;
95
94
import com .afwsamples .testdpc .common .Util ;
96
95
import com .afwsamples .testdpc .common .preference .DpcPreference ;
149
148
import java .util .List ;
150
149
import java .util .Set ;
151
150
import java .util .TimeZone ;
152
- import java .util .concurrent .Executor ;
153
151
import java .util .stream .Collectors ;
154
152
155
153
import static android .os .UserManager .DISALLOW_INSTALL_UNKNOWN_SOURCES ;
@@ -1854,16 +1852,7 @@ private void showSwitchUserPrompt() {
1854
1852
@ TargetApi (28 )
1855
1853
private void showStartUserInBackgroundPrompt () {
1856
1854
showChooseUserPrompt (R .string .start_user_in_background , userHandle -> {
1857
- int status = USER_OPERATION_ERROR_UNKNOWN ;
1858
- try {
1859
- status = (int ) ReflectionUtil .invoke (
1860
- mDevicePolicyManager ,
1861
- "startUserInBackground" ,
1862
- mAdminComponentName ,
1863
- userHandle );
1864
- } catch (ReflectionUtil .ReflectionIsTemporaryException e ) {
1865
- Log .e (TAG ,"Can't invoke startUserInBackground" , e );
1866
- }
1855
+ int status = mDevicePolicyManager .startUserInBackground (mAdminComponentName , userHandle );
1867
1856
showToast (status == USER_OPERATION_SUCCESS
1868
1857
? R .string .user_started_in_background
1869
1858
: R .string .failed_to_start_user_in_background );
@@ -1877,16 +1866,7 @@ private void showStartUserInBackgroundPrompt() {
1877
1866
@ TargetApi (28 )
1878
1867
private void showStopUserPrompt () {
1879
1868
showChooseUserPrompt (R .string .stop_user , userHandle -> {
1880
- int status = USER_OPERATION_ERROR_UNKNOWN ;
1881
- try {
1882
- status = (int ) ReflectionUtil .invoke (
1883
- mDevicePolicyManager ,
1884
- "stopUser" ,
1885
- mAdminComponentName ,
1886
- userHandle );
1887
- } catch (ReflectionUtil .ReflectionIsTemporaryException e ) {
1888
- Log .e (TAG ,"Can't invoke stopUser" , e );
1889
- }
1869
+ int status = mDevicePolicyManager .stopUser (mAdminComponentName , userHandle );
1890
1870
showToast (status == USER_OPERATION_SUCCESS ? R .string .user_stopped
1891
1871
: R .string .failed_to_stop_user );
1892
1872
});
@@ -1927,15 +1907,7 @@ private void showChooseUserPrompt(int titleResId, UserCallback callback) {
1927
1907
*/
1928
1908
@ TargetApi (28 )
1929
1909
private void logoutUser () {
1930
- int status = USER_OPERATION_ERROR_UNKNOWN ;
1931
- try {
1932
- status = (int ) ReflectionUtil .invoke (
1933
- mDevicePolicyManager ,
1934
- "logoutUser" ,
1935
- mAdminComponentName );
1936
- } catch (ReflectionUtil .ReflectionIsTemporaryException e ) {
1937
- Log .e (TAG ,"Can't invoke logoutUser" , e );
1938
- }
1910
+ int status = mDevicePolicyManager .logoutUser (mAdminComponentName );
1939
1911
showToast (status == USER_OPERATION_SUCCESS ? R .string .user_logouted
1940
1912
: R .string .failed_to_logout_user );
1941
1913
}
@@ -2849,22 +2821,14 @@ private void showClearAppDataPrompt() {
2849
2821
2850
2822
@ TargetApi (28 )
2851
2823
private void clearApplicationUserData (String packageName ) {
2852
- try {
2853
- ReflectionUtil .invoke (
2854
- mDevicePolicyManager , "clearApplicationUserData" ,
2855
- new Class []{ComponentName .class , String .class , Executor .class ,
2856
- DevicePolicyManager .OnClearApplicationUserDataListener .class },
2857
- mAdminComponentName ,
2858
- packageName ,
2859
- new MainThreadExecutor (),
2860
- (DevicePolicyManager .OnClearApplicationUserDataListener )
2861
- (__ , succeed ) -> showToast (
2862
- succeed ? R .string .clear_app_data_success
2863
- : R .string .clear_app_data_failure ,
2864
- packageName ));
2865
- } catch (ReflectionUtil .ReflectionIsTemporaryException e ) {
2866
- Log .e (LOG_TAG , "cannot invoke clearApplicationUserData" , e );
2867
- }
2824
+ mDevicePolicyManager .clearApplicationUserData (
2825
+ mAdminComponentName ,
2826
+ packageName ,
2827
+ new MainThreadExecutor (),
2828
+ (__ , succeed ) -> showToast (succeed ?
2829
+ R .string .clear_app_data_success
2830
+ : R .string .clear_app_data_failure ,
2831
+ packageName ));
2868
2832
}
2869
2833
2870
2834
@ TargetApi (Build .VERSION_CODES .N )
@@ -3154,25 +3118,7 @@ private void relaunchInLockTaskMode() {
3154
3118
intent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
3155
3119
3156
3120
final ActivityOptions options = ActivityOptions .makeBasic ();
3157
- try {
3158
- ReflectionUtil .invoke (
3159
- options ,
3160
- "setLockTaskMode" ,
3161
- new Class []{boolean .class },
3162
- true );
3163
- } catch (ReflectionUtil .ReflectionIsTemporaryException e1 ) {
3164
- // API name was recently changed, so we should be robust enough to support both.
3165
- // This workaround can be removed once the new API name is in the SDK prebuilt.
3166
- try {
3167
- ReflectionUtil .invoke (
3168
- options ,
3169
- "setLockTaskEnabled" ,
3170
- new Class []{boolean .class },
3171
- true );
3172
- } catch (ReflectionUtil .ReflectionIsTemporaryException e2 ) {
3173
- Log .e (TAG , "Unable to set lock task activity option." , e2 );
3174
- }
3175
- }
3121
+ options .setLockTaskMode (true );
3176
3122
3177
3123
try {
3178
3124
startActivity (intent , options .toBundle ());
0 commit comments