1515 */
1616package com .alipay .hulu .replay ;
1717
18+ import android .app .ActivityManager ;
1819import android .content .Context ;
1920import android .content .DialogInterface ;
2021import androidx .appcompat .app .AlertDialog ;
22+
23+ import android .os .Build ;
2124import android .view .View ;
2225
2326import com .alipay .hulu .R ;
2427import com .alipay .hulu .bean .ReplayResultBean ;
2528import com .alipay .hulu .bean .ReplayStepInfoBean ;
29+ import com .alipay .hulu .common .application .LauncherApplication ;
30+ import com .alipay .hulu .common .tools .BackgroundExecutor ;
31+ import com .alipay .hulu .common .tools .CmdTools ;
2632import com .alipay .hulu .common .utils .LogUtil ;
2733import com .alipay .hulu .service .CaseReplayManager ;
34+ import com .alipay .hulu .shared .node .action .PerformActionEnum ;
2835import com .alipay .hulu .shared .node .tree .export .bean .OperationStep ;
36+ import com .alipay .hulu .util .DialogUtils ;
2937
38+ import java .io .IOException ;
3039import java .util .Arrays ;
3140import java .util .Date ;
3241import java .util .List ;
@@ -93,12 +102,62 @@ public List<ReplayResultBean> genReplayResult() {
93102 public abstract void onStepInfo (ReplayStepInfoBean bean );
94103
95104 public void onFloatClick (Context context , final CaseReplayManager manager ) {
96- showFunctionView (context , "是否终止回放" , new Runnable () {
105+ DialogUtils .showFunctionView (context , Arrays .asList (PerformActionEnum .NORMAL_EXIT , PerformActionEnum .FORCE_STOP ), new DialogUtils .FunctionViewCallback <PerformActionEnum >() {
106+
107+ @ Override
108+ public void onExecute (DialogInterface dialog , PerformActionEnum action ) {
109+ if (action == PerformActionEnum .NORMAL_EXIT ) {
110+ manager .stopRunning ();
111+ } else if (action == PerformActionEnum .FORCE_STOP ) {
112+ // 移除所有Task
113+ ActivityManager am = (ActivityManager ) LauncherApplication .getInstance ()
114+ .getSystemService (Context .ACTIVITY_SERVICE );
115+ if (am != null && Build .VERSION .SDK_INT >= 21 ) {
116+ try {
117+ List <ActivityManager .AppTask > tasks = am .getAppTasks ();
118+ for (ActivityManager .AppTask task : tasks ) {
119+ task .finishAndRemoveTask ();
120+ }
121+ } catch (Exception e ) {
122+ e .printStackTrace ();
123+ }
124+ }
125+ BackgroundExecutor .execute (new Runnable () {
126+ @ Override
127+ public void run () {
128+ int pid = android .os .Process .myPid ();
129+ String command = "kill -9 " + pid ;
130+ try {
131+ Runtime .getRuntime ().exec (command );
132+ } catch (IOException e ) {
133+ LogUtil .e (TAG , "强制关闭进程失败" );
134+ }
135+ // adb强杀
136+ try {
137+ String cmd = "am force-stop " + LauncherApplication .getInstance ().getPackageName ();
138+ CmdTools .execCmd (cmd + " && " + cmd );
139+ } catch (Throwable e ) {
140+ LogUtil .w (TAG , "force-stop fail??" , e );
141+ }
142+ }
143+ }, 200 );
144+
145+ // System exit
146+ System .exit (0 );
147+ }
148+ dialog .dismiss ();
149+ }
150+
151+ @ Override
152+ public void onCancel (DialogInterface dialog ) {
153+ dialog .dismiss ();
154+ }
155+
97156 @ Override
98- public void run ( ) {
99- manager . stopRunning ();
157+ public void onDismiss ( DialogInterface dialog ) {
158+
100159 }
101- }, null );
160+ });
102161 }
103162
104163 /**
@@ -109,45 +168,4 @@ public void run() {
109168 public View provideView (Context context ) {
110169 return null ;
111170 }
112-
113- /**
114- * 展示操作dialog
115- * @param message 消息
116- * @param confirmAction 确定动作
117- * @param cancelAction 取消动作
118- */
119- protected void showFunctionView (Context context , String message , final Runnable confirmAction , final Runnable cancelAction ) {
120- try {
121- AlertDialog dialog = new AlertDialog .Builder (context , R .style .SimpleDialogTheme )
122- .setMessage (message )
123- .setPositiveButton (R .string .constant__confirm , new DialogInterface .OnClickListener () {
124- @ Override
125- public void onClick (DialogInterface dialog , int which ) {
126- if (confirmAction != null ) {
127- confirmAction .run ();
128- }
129- dialog .dismiss ();
130- }
131- })
132- .setNegativeButton (R .string .constant__cancel , new DialogInterface .OnClickListener () {
133- @ Override
134- public void onClick (DialogInterface dialog , int which ) {
135- if (cancelAction != null ) {
136- cancelAction .run ();
137- }
138- dialog .dismiss ();
139- }
140- }).setOnCancelListener (new DialogInterface .OnCancelListener () {
141- @ Override
142- public void onCancel (DialogInterface dialog ) {
143- dialog .dismiss ();
144- }
145- }).create ();
146- dialog .getWindow ().setType (com .alipay .hulu .common .constant .Constant .TYPE_ALERT );
147- dialog .setCanceledOnTouchOutside (false );
148- dialog .show ();
149- } catch (Exception e ) {
150- LogUtil .e (TAG , e .getMessage ());
151- }
152- }
153171}
0 commit comments