Skip to content

Commit cfab438

Browse files
committed
重构AppUtils,兼容ro.fw.version读取固件版本号
1 parent 0ea2594 commit cfab438

File tree

2 files changed

+30
-137
lines changed

2 files changed

+30
-137
lines changed

app/src/main/java/com/ayst/romupgrade/baidu/SystemInfo.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@
1616

1717
package com.ayst.romupgrade.baidu;
1818

19+
import android.os.Build;
20+
1921
import com.baidu.commonlib.interfaces.ISystemInfo;
2022
import com.ayst.romupgrade.util.AppUtils;
2123

2224
public class SystemInfo implements ISystemInfo {
2325
@Override
2426
public String getVersion() {
25-
return AppUtils.getSwVersionName();
27+
return AppUtils.getFwVersion();
2628
}
2729

2830
@Override
2931
public String getModel() {
30-
return AppUtils.getProductName();
32+
return Build.MODEL;
3133
}
3234

3335
@Override
3436
public String getCPU() {
35-
return AppUtils.getPlatform();
37+
return Build.BOARD;
3638
}
3739
}

app/src/main/java/com/ayst/romupgrade/util/AppUtils.java

Lines changed: 25 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import java.util.ArrayList;
4848
import java.util.List;
4949
import java.util.Locale;
50-
import java.util.UUID;
5150

5251
/**
5352
* Created by [email protected] on 2016/4/6.
@@ -61,18 +60,8 @@ public class AppUtils {
6160
private static String mVersionName = "";
6261
private static int mVersionCode = -1;
6362

64-
// Hardware version
65-
private static String mHwVersionName = "";
66-
private static int mHwVersionCode = -1;
67-
6863
// Firmware version
69-
private static String mSwVersionName = "";
70-
private static int mSwVersionCode = -1;
71-
72-
// Product
73-
private static String mProduceName = "";
74-
private static String mProduceId = "";
75-
private static String mPlatform = "";
64+
private static String mFwVersion = "";
7665

7766
// MAC
7867
private static String mEth0Mac = "";
@@ -93,8 +82,8 @@ public class AppUtils {
9382
/**
9483
* Is first run
9584
*
96-
* @param context
97-
* @return
85+
* @param context Context
86+
* @return true: First run, false: Not the first time
9887
*/
9988
public static boolean isFirstRun(Context context) {
10089
boolean isFirst = SPUtils.getInstance(context).getData(KEY_IS_FIRST, true);
@@ -145,105 +134,16 @@ public static int getVersionCode(Context context) {
145134
}
146135

147136
/**
148-
* Get product name
149-
*
150-
* @return product name
151-
*/
152-
public static String getProductName() {
153-
if (TextUtils.isEmpty(mProduceName)) {
154-
mProduceName = AppUtils.getProperty("ro.product.model", "");
155-
}
156-
return mProduceName;
157-
}
158-
159-
/**
160-
* Get chip platform
161-
*
162-
* @return platform
163-
*/
164-
public static String getPlatform() {
165-
if (TextUtils.isEmpty(mPlatform)) {
166-
mPlatform = AppUtils.getProperty("ro.product.board", "");
167-
}
168-
return mPlatform;
169-
}
170-
171-
/**
172-
* Get product id
173-
*
174-
* @return product id
175-
*/
176-
public static String getProductId() {
177-
if (TextUtils.isEmpty(mProduceId)) {
178-
mProduceId = AppUtils.getProperty("ro.topband.product.id", "");
179-
}
180-
return mProduceId;
181-
}
182-
183-
/**
184-
* Get hardware version code
185-
*
186-
* @return version code
187-
*/
188-
public static int getHwVersionCode() {
189-
if (-1 == mHwVersionCode) {
190-
int versionCode = 0;
191-
String value = getHwVersionName();
192-
if (!TextUtils.isEmpty(value)) {
193-
String[] arr = value.split("-");
194-
if (arr.length > 0) {
195-
String str = arr[0].replace(".", "");
196-
mHwVersionCode = Integer.parseInt(str);
197-
}
198-
}
199-
}
200-
return mHwVersionCode;
201-
}
202-
203-
/**
204-
* Get hardware version name
205-
*
206-
* @return version name
207-
*/
208-
public static String getHwVersionName() {
209-
if (TextUtils.isEmpty(mHwVersionName)) {
210-
mHwVersionName = AppUtils.getProperty("ro.topband.hw.version", "");
211-
}
212-
return mHwVersionName;
213-
}
214-
215-
/**
216-
* Get firmware version code
217-
*
218-
* @return version code
219-
*/
220-
public static int getSwVersionCode() {
221-
if (-1 == mSwVersionCode) {
222-
String value = AppUtils.getProperty("ro.topband.sw.versioncode", "0");
223-
mSwVersionCode = Integer.parseInt(value);
224-
}
225-
return mSwVersionCode;
226-
}
227-
228-
/**
229-
* Get firmware version name
230-
*
231-
* @return version name
232-
*/
233-
public static String getSwVersionName() {
234-
if (TextUtils.isEmpty(mSwVersionName)) {
235-
mSwVersionName = AppUtils.getProperty("ro.topband.sw.version", "1.0.0");
236-
}
237-
return mSwVersionName;
238-
}
239-
240-
/**
241-
* Get Android version
137+
* Get firmware version
242138
*
243139
* @return version
244140
*/
245-
public static String getAndroidVersion() {
246-
return AppUtils.getProperty("ro.build.version.release", "");
141+
public static String getFwVersion() {
142+
if (TextUtils.isEmpty(mFwVersion)) {
143+
mFwVersion = getProperty("ro.fw.version",
144+
getProperty("ro.topband.sw.version", "1.0.0"));
145+
}
146+
return mFwVersion;
247147
}
248148

249149
/**
@@ -255,7 +155,7 @@ public static String getAndroidVersion() {
255155
public static String getSerialNo() {
256156
String sn = android.os.Build.SERIAL;
257157
if (TextUtils.isEmpty(sn)) {
258-
sn = AppUtils.getProperty("ro.serialno", "");
158+
sn = getProperty("ro.serialno", "");
259159
if (TextUtils.isEmpty(sn)) {
260160
sn = "unknown";
261161
}
@@ -329,7 +229,7 @@ public static String getLanguage() {
329229
* Whether the network is connected
330230
*
331231
* @param context Context
332-
* @return true/false
232+
* @return true: connected, false: disconnected
333233
*/
334234
public static boolean isConnNetWork(Context context) {
335235
ConnectivityManager conManager = (ConnectivityManager) context.
@@ -342,7 +242,7 @@ public static boolean isConnNetWork(Context context) {
342242
* Whether WiFi is connected
343243
*
344244
* @param context Context
345-
* @return true/false
245+
* @return true: connected, false: disconnected
346246
*/
347247
public static boolean isWifiConnected(Context context) {
348248
ConnectivityManager conManager = (ConnectivityManager) context.
@@ -354,8 +254,8 @@ public static boolean isWifiConnected(Context context) {
354254
/**
355255
* Get Ethernet MAC
356256
*
357-
* @param context
358-
* @return
257+
* @param context Context
258+
* @return Mac
359259
*/
360260
public static String getEth0Mac(Context context) {
361261
if (TextUtils.isEmpty(mEth0Mac)) {
@@ -381,8 +281,8 @@ public static String getEth0Mac(Context context) {
381281
/**
382282
* Get WiFi MAC
383283
*
384-
* @param context
385-
* @return
284+
* @param context Context
285+
* @return Mac
386286
*/
387287
@SuppressLint("HardwareIds")
388288
public static String getWifiMac(Context context) {
@@ -398,8 +298,8 @@ public static String getWifiMac(Context context) {
398298
/**
399299
* Get MAC, get the Ethernet MAC first, then get the WiFi MAC if it is empty.
400300
*
401-
* @param context
402-
* @return
301+
* @param context Context
302+
* @return Mac
403303
*/
404304
public static String getMac(Context context) {
405305
if (TextUtils.isEmpty(mMac)) {
@@ -414,8 +314,8 @@ public static String getMac(Context context) {
414314
/**
415315
* Get the MAC with the colon removed
416316
*
417-
* @param context
418-
* @return
317+
* @param context Context
318+
* @return Mac
419319
*/
420320
public static String getMacNoColon(Context context) {
421321
if (TextUtils.isEmpty(mMacNoColon)) {
@@ -491,15 +391,6 @@ public static void setProperty(String key, String value) {
491391
}
492392
}
493393

494-
/**
495-
* Get UUID
496-
*
497-
* @return UUID
498-
*/
499-
public static String getUUID() {
500-
return UUID.randomUUID().toString().replace("-", "");
501-
}
502-
503394
private static boolean isExternalStorageMounted() {
504395
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
505396
}
@@ -688,7 +579,7 @@ private static List<String> getStorageVolumeList(Context context) {
688579
/**
689580
* reboot
690581
*
691-
* @param context
582+
* @param context Context
692583
*/
693584
public static void reboot(Context context) {
694585
Intent intent = new Intent(Intent.ACTION_REBOOT);
@@ -701,7 +592,7 @@ public static void reboot(Context context) {
701592
/**
702593
* shutdown
703594
*
704-
* @param context
595+
* @param context Context
705596
*/
706597
public static void shutdown(Context context) {
707598
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -720,8 +611,8 @@ public static void shutdown(Context context) {
720611
/**
721612
* start app
722613
*
723-
* @param context
724-
* @param packageName
614+
* @param context Context
615+
* @param packageName PackageName
725616
*/
726617
public static void startApp(@NonNull Context context, @NonNull String packageName) {
727618
Intent intent = context.getPackageManager()

0 commit comments

Comments
 (0)