@@ -1634,8 +1634,8 @@ private void requestBugReport() {
1634
1634
mDevicePolicyManagerGateway .requestBugreport (
1635
1635
(v ) -> onSuccessLog ("requestBugreport" ),
1636
1636
(e ) -> onErrorOrFailureShowToast ("requestBugreport" ,
1637
- R . string . bugreport_failure_throttled , R .string .bugreport_failure_exception ,
1638
- e ));
1637
+ e , R .string .bugreport_failure_throttled ,
1638
+ R . string . bugreport_failure_exception ));
1639
1639
}
1640
1640
1641
1641
@ TargetApi (VERSION_CODES .M )
@@ -2170,7 +2170,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
2170
2170
private void removeUser (UserHandle userHandle ) {
2171
2171
mDevicePolicyManagerGateway .removeUser (userHandle ,
2172
2172
(u ) -> onSuccessShowToast ("removeUser()" , R .string .user_removed ),
2173
- (e ) -> onErrorShowToast ("removeUser()" , R .string .failed_to_remove_user , e ));
2173
+ (e ) -> onErrorShowToast ("removeUser()" , e , R .string .failed_to_remove_user ));
2174
2174
}
2175
2175
2176
2176
/**
@@ -2196,7 +2196,7 @@ private void showSwitchUserPrompt() {
2196
2196
showChooseUserPrompt (R .string .switch_user , userHandle -> {
2197
2197
mDevicePolicyManagerGateway .switchUser (userHandle ,
2198
2198
(v ) -> onSuccessShowToast ("switchUser" , R .string .user_switched ),
2199
- (e ) -> onErrorShowToast ("switchUser" , R .string .failed_to_switch_user , e ));
2199
+ (e ) -> onErrorShowToast ("switchUser" , e , R .string .failed_to_switch_user ));
2200
2200
});
2201
2201
}
2202
2202
@@ -2211,7 +2211,7 @@ private void showStartUserInBackgroundPrompt() {
2211
2211
(v ) -> onSuccessShowToast ("startUserInBackground" ,
2212
2212
R .string .user_started_in_background ),
2213
2213
(e ) -> onErrorShowToast ("startUserInBackground" ,
2214
- R .string .failed_to_start_user_in_background , e ));
2214
+ e , R .string .failed_to_start_user_in_background ));
2215
2215
});
2216
2216
}
2217
2217
@@ -2224,7 +2224,7 @@ private void showStopUserPrompt() {
2224
2224
showChooseUserPrompt (R .string .stop_user , userHandle -> {
2225
2225
mDevicePolicyManagerGateway .startUserInBackground (userHandle ,
2226
2226
(v ) -> onSuccessShowToast ("stopUser" , R .string .user_stopped ),
2227
- (e ) -> onErrorShowToast ("stopUser" , R .string .failed_to_stop_user , e ));
2227
+ (e ) -> onErrorShowToast ("stopUser" , e , R .string .failed_to_stop_user ));
2228
2228
});
2229
2229
}
2230
2230
@@ -3322,12 +3322,19 @@ private void showSuspendAppsPrompt(final boolean forUnsuspending) {
3322
3322
@ Override
3323
3323
public void onClick (DialogInterface dialog , int position ) {
3324
3324
String packageName = showApps .get (position );
3325
- if (mDevicePolicyManager .setPackagesSuspended (mAdminComponentName ,
3326
- new String [] {packageName }, !forUnsuspending ).length == 0 ) {
3327
- showToast (successResId , packageName );
3328
- } else {
3329
- showToast (getString (failureResId , packageName ), Toast .LENGTH_LONG );
3330
- }
3325
+ mDevicePolicyManagerGateway .setPackagesSuspended (
3326
+ new String [] {packageName }, !forUnsuspending ,
3327
+ (failed ) -> {
3328
+ if (failed .length == 0 ) {
3329
+ onSuccessShowToast ("setPackagesSuspended" ,
3330
+ successResId , packageName );
3331
+ } else {
3332
+ onErrorShowToast ("setPackagesSuspended" , failureResId ,
3333
+ packageName );
3334
+ }
3335
+ },
3336
+ (e ) -> onErrorShowToast ("setPackagesSuspended" , e , failureResId ,
3337
+ packageName ));
3331
3338
}
3332
3339
})
3333
3340
.show ();
@@ -3416,7 +3423,7 @@ private void clearApplicationUserData(String packageName) {
3416
3423
@ TargetApi (VERSION_CODES .N )
3417
3424
private boolean isPackageSuspended (String packageName ) {
3418
3425
try {
3419
- return mDevicePolicyManager .isPackageSuspended (mAdminComponentName , packageName );
3426
+ return mDevicePolicyManagerGateway .isPackageSuspended (packageName );
3420
3427
} catch (PackageManager .NameNotFoundException e ) {
3421
3428
Log .e (TAG , "Unable check if package is suspended" , e );
3422
3429
return false ;
@@ -3450,8 +3457,10 @@ private void showToast(String msg) {
3450
3457
private void showToast (String msg , int duration ) {
3451
3458
Activity activity = getActivity ();
3452
3459
if (activity == null || activity .isFinishing ()) {
3460
+ Log .w (TAG , "Not toasting '" + msg + "' as activity is finishing or finished" );
3453
3461
return ;
3454
3462
}
3463
+ Log .d (TAG , "Showing toast: " + msg );
3455
3464
Toast .makeText (activity , msg , duration ).show ();
3456
3465
}
3457
3466
@@ -4049,18 +4058,23 @@ private void setAutoTimeZoneEnabled(boolean enabled) {
4049
4058
mDevicePolicyManager .setAutoTimeZoneEnabled (mAdminComponentName , enabled );
4050
4059
}
4051
4060
4052
- private void onSuccessShowToast (String method , int msgId ) {
4061
+ private void onSuccessShowToast (String method , int msgId , Object ... args ) {
4053
4062
Log .d (TAG , method + "() succeeded" );
4054
- showToast (msgId );
4063
+ showToast (msgId , args );
4064
+ }
4065
+
4066
+ private void onErrorShowToast (String method , int msgId , Object ... args ) {
4067
+ Log .e (TAG , method + "() failed" );
4068
+ showToast (msgId , args );
4055
4069
}
4056
4070
4057
- private void onErrorShowToast (String method , int msgId , Exception e ) {
4071
+ private void onErrorShowToast (String method , Exception e , int msgId , Object ... args ) {
4058
4072
Log .e (TAG , method + "() failed: " , e );
4059
- showToast (msgId );
4073
+ showToast (msgId , args );
4060
4074
}
4061
4075
4062
- private void onErrorOrFailureShowToast (String method , int failureMsgId , int errorMsgId ,
4063
- Exception e ) {
4076
+ private void onErrorOrFailureShowToast (String method , Exception e , int failureMsgId ,
4077
+ int errorMsgId ) {
4064
4078
if (e instanceof FailedOperationException ) {
4065
4079
Log .e (TAG , method + " returned false" );
4066
4080
showToast (failureMsgId );
0 commit comments