Skip to content

Commit 2d015cc

Browse files
committed
用反射替換SystemProperties
1 parent 01957ae commit 2d015cc

3 files changed

Lines changed: 31 additions & 127 deletions

File tree

printlibrary/src/main/java/android/os/SystemProperties.java

Lines changed: 0 additions & 103 deletions
This file was deleted.

printlibrary/src/main/java/com/sunmi/peripheral/printer/SunmiPrinterService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import android.os.IInterface;
88
import android.os.Parcel;
99
import android.os.RemoteException;
10-
import android.os.SystemProperties;
1110

1211
import java.util.List;
1312
import java.util.Locale;
@@ -2569,7 +2568,7 @@ public static class Proxy implements SunmiPrinterService {
25692568
}
25702569

25712570
private void setTable() {
2572-
String model = SystemProperties.get("ro.sunmi.hardware").toUpperCase(Locale.ENGLISH);
2571+
String model = Utils.getSystemProperty("ro.sunmi.hardware").toUpperCase(Locale.ENGLISH);
25732572
if(model.contains("V2") || model.contains("P2") || model.contains("P1")
25742573
|| model.contains("V1S") || "QBAO_H1".equals(model)){
25752574
transaction_table = Stub.TRANSCTION_DATASHEET[0];

printlibrary/src/main/java/com/sunmi/peripheral/printer/Utils.java

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package com.sunmi.peripheral.printer;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Context;
45
import android.content.Intent;
56
import android.content.IntentFilter;
67
import android.os.Build;
7-
import android.os.SystemProperties;
88
import android.text.TextUtils;
99
import android.util.Log;
1010

11-
import java.io.BufferedReader;
12-
import java.io.FileReader;
1311
import java.lang.reflect.Method;
1412
import java.util.ArrayList;
1513

@@ -188,28 +186,38 @@ private static String filterModel(String str) {
188186
return "";
189187
}
190188

191-
public static boolean isSPIPrint() {
192-
if (TextUtils.equals("M2-202", Build.MODEL)) {
193-
return SystemProperties.getBoolean("persist.sys.isSPI", false);
194-
} else if (TextUtils.equals("M2-Pro", Build.MODEL)) {
195-
return true;
196-
}
197-
BufferedReader reader;
189+
public static String getSystemProperty(String key) {
198190
try {
199-
reader = new BufferedReader(new FileReader("/proc/neostra_hw_info"));
200-
String line;
201-
while ((line = reader.readLine()) != null) {
202-
Log.d("printlibrary", "hasSPI" + line.contains("SPI=ON"));
203-
return line.contains("SPI=ON") ? true : false;
204-
}
205-
reader.close();
206-
} catch (Exception e) {
207-
// TODO Auto-generated catch block\r
208-
e.printStackTrace();
209-
}
210-
return false;
191+
@SuppressLint("PrivateApi")
192+
Class<?> clz = Class.forName("android.os.SystemProperties");
193+
Method getMethod = clz.getMethod("get", String.class, String.class);
194+
return (String) getMethod.invoke(clz, key, "");
195+
} catch (Exception e) {/**/}
196+
return "";
211197
}
212198

199+
// public static boolean isSPIPrint() {
200+
// if (TextUtils.equals("M2-202", Build.MODEL)) {
201+
// return SystemProperties.getBoolean("persist.sys.isSPI", false);
202+
// } else if (TextUtils.equals("M2-Pro", Build.MODEL)) {
203+
// return true;
204+
// }
205+
// BufferedReader reader;
206+
// try {
207+
// reader = new BufferedReader(new FileReader("/proc/neostra_hw_info"));
208+
// String line;
209+
// while ((line = reader.readLine()) != null) {
210+
// Log.d("printlibrary", "hasSPI" + line.contains("SPI=ON"));
211+
// return line.contains("SPI=ON") ? true : false;
212+
// }
213+
// reader.close();
214+
// } catch (Exception e) {
215+
// // TODO Auto-generated catch block\r
216+
// e.printStackTrace();
217+
// }
218+
// return false;
219+
// }
220+
213221
//获取电量
214222
public static int getElect(Context context) {
215223
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);

0 commit comments

Comments
 (0)