huangcm
2025-04-09 02d4ce54b909bd733f12e9f3fa4c1b03cf2d6f45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package com.DeviceTest;
 
import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
 
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.Permission;
import java.util.ArrayList;
import java.util.Arrays;
 
import com.DeviceTest.helper.ControlButtonUtil;
import com.DeviceTest.helper.SystemUtil;
import com.DeviceTest.helper.TestCase.RESULT;
 
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PermissionInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.os.Environment;
 
public class StorageTestActivity extends Activity {
   private final static String TAG = "StorageTest";
    private TextView mResult;
 
   boolean stop = false;
   private static final String TEST_FILE_PATH = "/system/bin/logcat";
   private static final String TEMP_FILE_PATH = DeviceTest.TEMP_FILE_PATH
           + "_test";
 
   
   protected void onCreate(Bundle savedInstanceState) {
 
       super.onCreate(savedInstanceState);
 
       setTitle(getTitle() + "----("
               + getIntent().getStringExtra(DeviceTest.EXTRA_TEST_PROGRESS) + ")");
       // requestWindowFeature(Window.FEATURE_NO_TITLE);
       getWindow().addFlags(FLAG_FULLSCREEN | FLAG_KEEP_SCREEN_ON);
 
       setContentView(R.layout.storagetest);
 
       boolean pass = true;
 
       mResult = (TextView) findViewById(R.id.resultText);
       String result = "";
//        String sdPath = System.getenv("EXTERNAL_STORAGE");
       String sdPath = Environment.getExternalStorageDirectory().toString();
        Log.e(TAG, "EXTERNAL_STORAGE path :"+sdPath);
       if (sdPath == null) {
           result += getString(R.string.StorageSDNoFind);
           pass = false;
       } else {
           if (!testCopy(sdPath)) {
               pass = false;
               result += getString(R.string.StorageSDCopyF);
           } else {
               result += getString(R.string.StorageSDCopyS);
           }
       }
 
       String usbPath = System.getenv("EXTERNAL_HOST_USB");
       if (null == usbPath) {
           result += getString(R.string.StorageUsbNoFind);
           pass = false;
       } else {
           if (!testCopy(usbPath)) {
               pass = false;
               result += getString(R.string.StorageUsbCopyF);
           } else {
               result += getString(R.string.StorageUsbCopyS);
           }
       }
 
       result += pass ? "Pass!" : "Failed";
       mResult.setText(result);
       ControlButtonUtil.initControlButtonView(this);
       findViewById(R.id.btn_Pass).setVisibility(View.INVISIBLE);
       if (pass) {
           findViewById(R.id.btn_Pass).performClick();
       } else {
           mHandler.postDelayed(mFailedRunnable, DeviceTest.TEST_FAILED_DELAY);
       }
   }
 
   Handler mHandler = new Handler();
   Runnable mFailedRunnable = new Runnable() {
 
       
       public void run() {
           if (stop) {
               return;
           }
           mHandler.removeCallbacks(mFailedRunnable);
           findViewById(R.id.btn_Fail).performClick();
       }
   };
 
   private boolean testCopy(String dstPath) {
       SystemUtil.execScriptCmd("cat " + TEST_FILE_PATH + " > "
               + dstPath + "/test", DeviceTest.TEMP_FILE_PATH, true);
       SystemUtil.execScriptCmd("cat " + dstPath + "/test"
               + " > " + TEMP_FILE_PATH + "\nrm " + dstPath + "/test",
               DeviceTest.TEMP_FILE_PATH, true);
 
       byte[] buffer1 = new byte[1024];
       byte[] buffer2 = new byte[1024];
       int length = 0;
       try {
           BufferedInputStream bisSrc = new BufferedInputStream(
                   new FileInputStream(TEST_FILE_PATH));
           BufferedInputStream bisDst = new BufferedInputStream(
                   new FileInputStream(TEMP_FILE_PATH));
           Arrays.fill(buffer1, (byte) 0);
           Arrays.fill(buffer2, (byte) 0);
           while ((length = bisSrc.read(buffer1)) > 0) {
               if (length != bisDst.read(buffer2)) {
                   Log.e(TAG, "length not equals  : failed");
                   return false;
               }
               if (!Arrays.equals(buffer1, buffer2)) {
                    Log.e(TAG, "data not equals  : failed");
                   return false;
               }
           }
           bisSrc.close();
           bisDst.close();
       } catch (IOException e) {
           e.printStackTrace();
           return false;
       } finally {
           File file = new File(TEMP_FILE_PATH);
           if (file.exists()) {
               file.delete();
           }
       }
       return true;
   }
 
 
   
   public void onStop() {
       super.onStop();
       mHandler.removeCallbacks(mFailedRunnable);
       stop = true;
   }
 
   // if (device != null && progressBar.isShown()) {
   // progressBar.setVisibility(View.GONE);
   // mResult.setText("Find equipment....\n Pass!");
 
   public boolean dispatchKeyEvent(KeyEvent event) {
       if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
           return false;
       }
       return super.dispatchKeyEvent(event);
   }
}