Android15系统实现刷机防呆功能
最近遇到一个项目,客户要求4G的ddr固件不能刷机到3G的ddr大货主板上来,怕这样出货之后引起投诉。因为本身客户有多个项目在进行,有4G的固件和3G的固件,要求不能进行互刷,至少要进系统后有提示刷错固件。我采用的方法是系统进到桌面Launcher后去获取ddr的容量,判断不对就弹一个不可点击不可消失的弹框,客户也满意接受,具体的代码实现如下:
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 4e566abddc..cfc23335dc 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -285,6 +285,8 @@ import java.util.function.Predicate;import java.util.function.Supplier;import java.util.stream.Stream;+import android.app.ActivityManager;
+import android.app.AlertDialog;/*** Default launcher application.*/
@@ -595,6 +597,19 @@ public class Launcher extends StatefulActivity<LauncherState>RuleController.getInstance(this).setRules(RuleController.parseRules(this, R.xml.split_configuration));}
+
+ ActivityManager activityManager = (ActivityManager) getSystemService(this.ACTIVITY_SERVICE);
+ long totalMemory = activityManager.getTotalRam();
+ //Log.d("wzh","Laucher_totalMemory = " + totalMemory);
+ if(totalMemory < 2786946304L || totalMemory > 3586946304L) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle("软件错误")
+ .setMessage("内存不对")
+ .setCancelable(false);
+
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ }}protected ModelCallbacks createModelCallbacks() {