Commit 5ee6b759fc6523891c8c966e40ec29fdb8e661d4

Authored by 孙向锦
1 parent f1cfecc5

手动升级

C5/app/src/main/AndroidManifest.xml
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 xmlns:tools="http://schemas.android.com/tools" 3 xmlns:tools="http://schemas.android.com/tools"
4 package="com.sunvote.xpadapp" 4 package="com.sunvote.xpadapp"
5 android:versionCode="70" 5 android:versionCode="70"
6 - android:versionName="1.4.0.3"> <!-- android:sharedUserId="android.studentUID.system" --> 6 + android:versionName="1.4.0.5"> <!-- android:sharedUserId="android.studentUID.system" -->
7 7
8 <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission> 8 <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
9 <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> 9 <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
C5/app/src/main/java/com/sunvote/xpadapp/MainActivity.java
@@ -1892,7 +1892,6 @@ public class MainActivity extends BaseActivity implements ComListener { @@ -1892,7 +1892,6 @@ public class MainActivity extends BaseActivity implements ComListener {
1892 if(isInVoteState()){ 1892 if(isInVoteState()){
1893 return; 1893 return;
1894 } 1894 }
1895 -  
1896 if(currBillInfo!=null) { 1895 if(currBillInfo!=null) {
1897 if (currBillInfo.billmodel == 1) { //民事选举 1896 if (currBillInfo.billmodel == 1) { //民事选举
1898 if ((data[0] & 0xff) == 0xF2 && data[1] == 20) { 1897 if ((data[0] & 0xff) == 0xF2 && data[1] == 20) {
C5/app/src/main/java/com/sunvote/xpadapp/fragments/AdminFragment.java
@@ -29,6 +29,7 @@ public class AdminFragment extends BaseFragment { @@ -29,6 +29,7 @@ public class AdminFragment extends BaseFragment {
29 private ImageButton btnBack; 29 private ImageButton btnBack;
30 private Button btnConfig; 30 private Button btnConfig;
31 private Button btnPowerOff; 31 private Button btnPowerOff;
  32 + private Button firmUpdate;
32 private Button btnComTest; 33 private Button btnComTest;
33 private Button match; 34 private Button match;
34 35
@@ -40,9 +41,14 @@ public class AdminFragment extends BaseFragment { @@ -40,9 +41,14 @@ public class AdminFragment extends BaseFragment {
40 btnBack = view.findViewById(R.id.admin_btnback); 41 btnBack = view.findViewById(R.id.admin_btnback);
41 btnConfig = view.findViewById(R.id.admin_config_mode); 42 btnConfig = view.findViewById(R.id.admin_config_mode);
42 btnPowerOff = view.findViewById(R.id.admin_btnShutdown); 43 btnPowerOff = view.findViewById(R.id.admin_btnShutdown);
  44 + firmUpdate = view.findViewById(R.id.firm_update);
43 match = view.findViewById(R.id.match); 45 match = view.findViewById(R.id.match);
44 46
45 - tvModalInfo.setText(getString(R.string.app_version) + getVersionName()); 47 + String msg = getString(R.string.app_version) + getVersionName() ;
  48 + if(mMainActivity.mModelInfo != null){
  49 + msg += " 固件版本:" + mMainActivity.mModelInfo.sVer;
  50 + }
  51 + tvModalInfo.setText(msg);
46 btnBack.setOnClickListener(new OnClickListener() { 52 btnBack.setOnClickListener(new OnClickListener() {
47 @Override 53 @Override
48 public void onClick(View v) { 54 public void onClick(View v) {
@@ -127,6 +133,17 @@ public class AdminFragment extends BaseFragment { @@ -127,6 +133,17 @@ public class AdminFragment extends BaseFragment {
127 } 133 }
128 }); 134 });
129 135
  136 + firmUpdate.setOnClickListener(new OnClickListener() {
  137 + @Override
  138 + public void onClick(View v) {
  139 + FragmentManager fm = getFragmentManager();
  140 + FragmentTransaction tx = fm.beginTransaction();
  141 + tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
  142 + tx.replace(R.id.frame_content, new FirmUpdateFragment());
  143 + tx.commit();
  144 + }
  145 + });
  146 +
130 return view; 147 return view;
131 } 148 }
132 149
C5/app/src/main/java/com/sunvote/xpadapp/fragments/FirmUpdateFragment.java
@@ -66,20 +66,21 @@ public class FirmUpdateFragment extends BaseFragment { @@ -66,20 +66,21 @@ public class FirmUpdateFragment extends BaseFragment {
66 66
67 getActivity().registerReceiver(mBroadcastReceiver, filter); 67 getActivity().registerReceiver(mBroadcastReceiver, filter);
68 success = false; 68 success = false;
69 - firmUpdate(); 69 +
70 70
71 btnRetry = (Button)view.findViewById(R.id.firm_update_btn_retry); 71 btnRetry = (Button)view.findViewById(R.id.firm_update_btn_retry);
72 - btnRetry.setVisibility(View.INVISIBLE);  
73 btnRetry.setOnClickListener(new OnClickListener() { 72 btnRetry.setOnClickListener(new OnClickListener() {
74 @Override 73 @Override
75 public void onClick(View v) { 74 public void onClick(View v) {
76 LogUtil.i(TAG, "onClick: retry"); 75 LogUtil.i(TAG, "onClick: retry");
77 - appendLog("重试");  
78 - firmUpdate();  
79 btnRetry.setVisibility(View.INVISIBLE); 76 btnRetry.setVisibility(View.INVISIBLE);
  77 + appendLog("重试");
  78 + firmUpdate(checkFirmFile2());
  79 +
80 } 80 }
81 }); 81 });
82 82
  83 + firmUpdate(checkFirmFile());
83 84
84 return view; 85 return view;
85 } 86 }
@@ -107,15 +108,45 @@ public class FirmUpdateFragment extends BaseFragment { @@ -107,15 +108,45 @@ public class FirmUpdateFragment extends BaseFragment {
107 return files[0]; 108 return files[0];
108 } 109 }
109 110
110 - private void firmUpdate() { 111 + public static File checkFirmFile2() {
  112 + String filePath = Environment.getExternalStorageDirectory().getPath() + "/sunvote/system2/";
  113 + File file = new File(filePath);
  114 + if (!file.exists()) {
  115 + LogUtil.i(TAG, "checkFirmFile: dir not exists");
  116 + return null;
  117 + }
  118 + File[] files = file.listFiles();
  119 +
  120 + if (files == null || files.length == 0) {
  121 + LogUtil.i(TAG, "checkFirmFile:bin not exists");
  122 + return null;
  123 + }
  124 + return files[0];
  125 + }
  126 +
  127 + private void firmUpdate(File file) {
111 128
112 - File file = checkFirmFile();  
113 if(file==null){ 129 if(file==null){
  130 + appendLog("升级文件不存在");
  131 + appendLog("升级文件路径:" + Environment.getExternalStorageDirectory().getPath() + "/sunvote/system2/");
114 Toast.makeText(mMainActivity, "升级文件不存在", Toast.LENGTH_LONG).show(); 132 Toast.makeText(mMainActivity, "升级文件不存在", Toast.LENGTH_LONG).show();
  133 + getActivity().runOnUiThread(new Runnable() {
  134 + @Override
  135 + public void run() {
  136 + btnRetry.setVisibility(View.VISIBLE);
  137 + }
  138 + });
  139 + return;
115 } 140 }
116 - if(!file.getName().endsWith(".bin")){ 141 + if(file != null && !file.getName().endsWith(".bin")){
117 tvInfo.setText("升级文件格式错误"); 142 tvInfo.setText("升级文件格式错误");
118 Toast.makeText(mMainActivity, "升级文件格式错误", Toast.LENGTH_LONG).show(); 143 Toast.makeText(mMainActivity, "升级文件格式错误", Toast.LENGTH_LONG).show();
  144 + getActivity().runOnUiThread(new Runnable() {
  145 + @Override
  146 + public void run() {
  147 + btnRetry.setVisibility(View.VISIBLE);
  148 + }
  149 + });
119 return; 150 return;
120 } 151 }
121 152
@@ -143,6 +174,7 @@ public class FirmUpdateFragment extends BaseFragment { @@ -143,6 +174,7 @@ public class FirmUpdateFragment extends BaseFragment {
143 LogUtil.i(TAG, "handleMessage: 固件更新成功"); 174 LogUtil.i(TAG, "handleMessage: 固件更新成功");
144 tvInfo.setText("固件更新成功"); 175 tvInfo.setText("固件更新成功");
145 appendLog("固件更新成功"); 176 appendLog("固件更新成功");
  177 + btnRetry.setVisibility(View.VISIBLE);
146 Toast.makeText(mMainActivity, "固件更新成功", Toast.LENGTH_LONG).show(); 178 Toast.makeText(mMainActivity, "固件更新成功", Toast.LENGTH_LONG).show();
147 179
148 } else { 180 } else {
C5/app/src/main/java/com/sunvote/xpadcomm/XPadApi.java
@@ -100,15 +100,23 @@ public class XPadApi implements XPadApiInterface { @@ -100,15 +100,23 @@ public class XPadApi implements XPadApiInterface {
100 e.printStackTrace(); 100 e.printStackTrace();
101 } 101 }
102 mBuffer = new byte[0x1F + 4]; 102 mBuffer = new byte[0x1F + 4];
103 - Arrays.fill(mBuffer, (byte) 0x0);  
104 - mBuffer[0] = (byte) 0xF5;  
105 - mBuffer[1] = (byte) 0xAA;  
106 - mBuffer[2] = (byte) 0xAA;  
107 - mBuffer[3] = (byte) 0x1F;  
108 -  
109 - mBuffer[4] = 0x70;  
110 - mBuffer[5] = 0x04;  
111 - writeToCom(mBuffer); 103 + Arrays.fill(mBuffer, (byte) 0x0);
  104 + mBuffer[0] = (byte) 0xF5;
  105 + mBuffer[1] = (byte) 0xAA;
  106 + mBuffer[2] = (byte) 0xAA;
  107 + mBuffer[3] = (byte) 0x1F;
  108 +
  109 + mBuffer[4] = 0x70;
  110 + mBuffer[5] = 0x04;
  111 + writeToCom(mBuffer);
  112 +
  113 + try {
  114 + Thread.sleep(100);
  115 + } catch (InterruptedException e) {
  116 + e.printStackTrace();
  117 + }
  118 + getWorkMode();
  119 +
112 }else{ 120 }else{
113 onLineInfo.onLine = 2 ; 121 onLineInfo.onLine = 2 ;
114 m_listener.onOnLineEvent(onLineInfo); 122 m_listener.onOnLineEvent(onLineInfo);
@@ -1799,7 +1807,7 @@ public class XPadApi implements XPadApiInterface { @@ -1799,7 +1807,7 @@ public class XPadApi implements XPadApiInterface {
1799 byte packL = dt[8];// 数据片编号 1807 byte packL = dt[8];// 数据片编号
1800 LogUtil.d(TAG, "下载。。。msgId:" + msgid + " packH:" + packH + " apckL:" + packL); 1808 LogUtil.d(TAG, "下载。。。msgId:" + msgid + " packH:" + packH + " apckL:" + packL);
1801 1809
1802 - if (downType == 40) {// 文件下载 1810 + if (downType == 40) { // 文件下载
1803 if (lastPackH != packH) { //新的packH 1811 if (lastPackH != packH) { //新的packH
1804 LogUtil.i(TAG, "new packH......."); 1812 LogUtil.i(TAG, "new packH.......");
1805 okBits = 0; 1813 okBits = 0;
C5/app/src/main/java/com/sunvote/xpadcomm/XPadApiInterface.java
@@ -193,7 +193,9 @@ public interface XPadApiInterface { @@ -193,7 +193,9 @@ public interface XPadApiInterface {
193 lineInfo.rx = rx; 193 lineInfo.rx = rx;
194 lineInfo.baseId = baseId; 194 lineInfo.baseId = baseId;
195 lineInfo.keyId = keyId; 195 lineInfo.keyId = keyId;
196 - lineInfo.keySn = new String(keySn); 196 + if(keySn != null){
  197 + lineInfo.keySn = new String(keySn);
  198 + }
197 lineInfo.comError = comError; 199 lineInfo.comError = comError;
198 200
199 return lineInfo; 201 return lineInfo;
C5/app/src/main/res/layout/fragment_admin.xml
@@ -8,62 +8,87 @@ @@ -8,62 +8,87 @@
8 <LinearLayout 8 <LinearLayout
9 android:id="@+id/middle_line" 9 android:id="@+id/middle_line"
10 android:layout_width="720dp" 10 android:layout_width="720dp"
11 - android:layout_height="60dp" 11 + android:layout_height="140dp"
12 android:layout_centerInParent="true" 12 android:layout_centerInParent="true"
13 - android:orientation="horizontal"> 13 + android:orientation="vertical">
14 14
15 - <Button  
16 - android:id="@+id/match"  
17 - android:layout_width="0dp"  
18 - android:layout_height="60dp"  
19 - android:layout_marginRight="80dp"  
20 - android:layout_weight="1"  
21 - android:background="@color/blue"  
22 - android:gravity="center"  
23 - android:text="配对"  
24 - android:textColor="@color/white"  
25 - android:textSize="@dimen/big_text_p5"  
26 - android:textStyle="bold" />  
27 -  
28 - <Button  
29 - android:id="@+id/admin_config_mode"  
30 - android:layout_width="0dp" 15 + <LinearLayout
  16 + android:layout_width="720dp"
31 android:layout_height="60dp" 17 android:layout_height="60dp"
32 - android:layout_marginRight="80dp"  
33 - android:layout_weight="1"  
34 - android:background="@color/blue"  
35 - android:gravity="center"  
36 - android:text="@string/modifi_idsn"  
37 - android:textColor="@color/white"  
38 - android:textSize="@dimen/big_text_p5"  
39 - android:textStyle="bold" /> 18 + android:orientation="horizontal">
40 19
  20 + <Button
  21 + android:id="@+id/match"
  22 + android:layout_width="0dp"
  23 + android:layout_height="60dp"
  24 + android:layout_marginRight="80dp"
  25 + android:layout_weight="1"
  26 + android:background="@color/blue"
  27 + android:gravity="center"
  28 + android:text="配对"
  29 + android:textColor="@color/white"
  30 + android:textSize="@dimen/big_text_p5"
  31 + android:textStyle="bold" />
41 32
  33 + <Button
  34 + android:id="@+id/admin_config_mode"
  35 + android:layout_width="0dp"
  36 + android:layout_height="60dp"
  37 + android:layout_marginRight="80dp"
  38 + android:layout_weight="1"
  39 + android:background="@color/blue"
  40 + android:gravity="center"
  41 + android:text="@string/modifi_idsn"
  42 + android:textColor="@color/white"
  43 + android:textSize="@dimen/big_text_p5"
  44 + android:textStyle="bold" />
42 45
43 - <Button  
44 - android:id="@+id/admin_btnComTest"  
45 - android:layout_width="0dp"  
46 - android:layout_height="60dp"  
47 - android:layout_weight="1"  
48 - android:background="@color/blue"  
49 - android:gravity="center"  
50 - android:text="退出应用"  
51 - android:textColor="@color/white"  
52 - android:textSize="@dimen/big_text_p5"  
53 - android:textStyle="bold" />  
54 -  
55 - <Button  
56 - android:id="@+id/admin_btnShutdown"  
57 - android:layout_width="0dp" 46 + </LinearLayout>
  47 +
  48 + <LinearLayout
  49 + android:layout_width="720dp"
58 android:layout_height="60dp" 50 android:layout_height="60dp"
59 - android:layout_marginLeft="80dp"  
60 - android:layout_weight="1"  
61 - android:background="@drawable/oppos_selector"  
62 - android:gravity="center"  
63 - android:text="@string/shutdown"  
64 - android:textColor="@color/white"  
65 - android:textSize="@dimen/big_text_p5"  
66 - android:textStyle="bold"/> 51 + android:layout_marginTop="20dp"
  52 + android:orientation="horizontal">
  53 +
  54 + <Button
  55 + android:id="@+id/admin_btnComTest"
  56 + android:layout_width="0dp"
  57 + android:layout_height="60dp"
  58 + android:layout_marginRight="80dp"
  59 + android:layout_weight="1"
  60 + android:background="@color/blue"
  61 + android:gravity="center"
  62 + android:text="退出应用"
  63 + android:textColor="@color/white"
  64 + android:textSize="@dimen/big_text_p5"
  65 + android:textStyle="bold" />
  66 +
  67 + <Button
  68 + android:id="@+id/admin_btnShutdown"
  69 + android:layout_width="0dp"
  70 + android:layout_height="60dp"
  71 + android:layout_marginLeft="80dp"
  72 + android:layout_weight="1"
  73 + android:background="@drawable/oppos_selector"
  74 + android:gravity="center"
  75 + android:text="@string/shutdown"
  76 + android:textColor="@color/white"
  77 + android:textSize="@dimen/big_text_p5"
  78 + android:textStyle="bold" />
  79 +
  80 + <Button
  81 + android:id="@+id/firm_update"
  82 + android:layout_width="0dp"
  83 + android:layout_height="60dp"
  84 + android:layout_marginLeft="80dp"
  85 + android:layout_weight="1"
  86 + android:gravity="center"
  87 + android:text="固件升级"
  88 + android:textColor="@color/white"
  89 + android:textSize="@dimen/big_text_p5"
  90 + android:textStyle="bold" />
  91 + </LinearLayout>
67 92
68 </LinearLayout> 93 </LinearLayout>
69 94
@@ -71,12 +96,12 @@ @@ -71,12 +96,12 @@
71 android:id="@+id/admin_modal_title" 96 android:id="@+id/admin_modal_title"
72 android:layout_width="wrap_content" 97 android:layout_width="wrap_content"
73 android:layout_height="wrap_content" 98 android:layout_height="wrap_content"
74 - android:layout_centerHorizontal="true"  
75 android:layout_above="@id/middle_line" 99 android:layout_above="@id/middle_line"
  100 + android:layout_centerHorizontal="true"
76 android:layout_marginBottom="48dp" 101 android:layout_marginBottom="48dp"
77 android:text="@string/admin_setting" 102 android:text="@string/admin_setting"
78 - android:textSize="@dimen/big_text_p2"  
79 android:textColor="@color/white" 103 android:textColor="@color/white"
  104 + android:textSize="@dimen/big_text_p2"
80 android:textStyle="bold" /> 105 android:textStyle="bold" />
81 106
82 <TextView 107 <TextView
@@ -99,5 +124,4 @@ @@ -99,5 +124,4 @@
99 android:background="@drawable/back" /> 124 android:background="@drawable/back" />
100 125
101 126
102 -  
103 </RelativeLayout> 127 </RelativeLayout>
C5/app/src/main/res/layout/fragment_firm_update.xml
@@ -9,8 +9,9 @@ @@ -9,8 +9,9 @@
9 android:layout_width="wrap_content" 9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content" 10 android:layout_height="wrap_content"
11 android:layout_centerHorizontal="true" 11 android:layout_centerHorizontal="true"
12 - android:layout_marginTop="30dp"  
13 - android:textSize="48sp" /> 12 + android:layout_marginTop="10dp"
  13 + android:textSize="48sp"
  14 + />
14 15
15 <TextView 16 <TextView
16 android:id="@+id/firm_update_ver" 17 android:id="@+id/firm_update_ver"
@@ -18,7 +19,7 @@ @@ -18,7 +19,7 @@
18 android:layout_height="wrap_content" 19 android:layout_height="wrap_content"
19 android:layout_below="@id/firm_update_title" 20 android:layout_below="@id/firm_update_title"
20 android:layout_centerHorizontal="true" 21 android:layout_centerHorizontal="true"
21 - android:layout_marginTop="100dp" 22 + android:layout_marginTop="10dp"
22 android:textSize="30sp" /> 23 android:textSize="30sp" />
23 24
24 <TextView 25 <TextView
@@ -27,7 +28,7 @@ @@ -27,7 +28,7 @@
27 android:layout_height="wrap_content" 28 android:layout_height="wrap_content"
28 android:layout_below="@id/firm_update_ver" 29 android:layout_below="@id/firm_update_ver"
29 android:layout_centerHorizontal="true" 30 android:layout_centerHorizontal="true"
30 - android:layout_marginTop="40dp" 31 + android:layout_marginTop="10dp"
31 android:textSize="30sp" /> 32 android:textSize="30sp" />
32 33
33 <TextView 34 <TextView
@@ -36,7 +37,7 @@ @@ -36,7 +37,7 @@
36 android:layout_height="wrap_content" 37 android:layout_height="wrap_content"
37 android:layout_below="@id/firm_update_info" 38 android:layout_below="@id/firm_update_info"
38 android:layout_centerHorizontal="true" 39 android:layout_centerHorizontal="true"
39 - android:layout_marginTop="30dp" 40 + android:layout_marginTop="10dp"
40 android:textSize="30sp" /> 41 android:textSize="30sp" />
41 42
42 <Button 43 <Button