android客制化:恢复出厂设置后移除SystemUI

平台:android M

需求:

1.客户需求,预置一个客户带Launcher功能的apk.移除系统全部apk.包括SystemUI.

2.工厂需要系统的Launcher3和systemUI才可以完成测试操作.

思路:

基于以上需求,想到一个解决方案,第一次下载软件,系统带systemUI和Launcher3.工厂测试完成后恢复出厂设置,移除systemUI和Launcher3.


解决方案一:

1.Launcher预置到data/app下.

修改:Launcher3/Android.mk

+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)


2.SystemUI修改

2.1增加一个识别恢复出厂设置的方法.

预置device/mediatek/common/setup文件

修改device/mediatek/common/device.mk

+#setup
+PRODUCT_COPY_FILES += device/mediatek/common/setup:data/app/setup

恢复出厂设置后,该文件被删除,可通过判断该文件的存在来判断时候恢复出厂设置.

2.2 在systemui启动出判断:

SystemServer.java

+if(isFirst()){
+      try {
+           startSystemUi(context);
+       } catch (Throwable e) {
+           reportWtf("starting System UI", e);
+       }
+    }else{
+          Slog.i(TAG, "Do not startSystemUi");
+   }   

+    private boolean isFirst(){
+        File file = new File(path);
+        if (file.exists()) {
+            return true;
+        }
+        return false;
+    } 


        

SystemUIApplication.java

-                if (mServicesStarted) {
-                    final int N = mServices.length;
-                    for (int i = 0; i < N; i++) {
-                        mServices[i].onBootCompleted();
-                    }
-                }
+                               if(isFirst()){
+                                       if (mServicesStarted) {
+                                               final int N = mServices.length;
+                                               for (int i = 0; i < N; i++) {
+                                                       mServices[i].onBootCompleted();
+                                               }
+                                       }
+
+                               }
+               


         if (mServicesStarted) {
             return;
         }
+               if(!isFirst()){
+                       Log.d(TAG, "do not startServicesIfNeeded");
+            return;
+               }else{
+                       Log.d(TAG, "startServicesIfNeeded");
+               }


-        if (mServicesStarted) {
+        if (mServicesStarted && isFirst()) {
             int len = mServices.length;
             for (int i = 0; i < len; i++) {
                 mServices[i].onConfigurationChanged(newConfig);


SystemUIService.java

     @Override
     public void onCreate() {
         super.onCreate();
-        ((SystemUIApplication) getApplication()).startServicesIfNeeded();
+               if(isFirst()){
+                       ((SystemUIApplication) getApplication()).startServicesIfNeeded();
+               }else{
+
+               }
+        
     }
 
     @Override
@@ -38,21 +45,33 @@ public class SystemUIService extends Service {
 
     @Override
     protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        SystemUI[] services = ((SystemUIApplication) getApplication()).getServices();
-        if (args == null || args.length == 0) {
-            for (SystemUI ui: services) {
-                pw.println("dumping service: " + ui.getClass().getName());
-                ui.dump(fd, pw, args);
-            }
-        } else {
-            String svc = args[0];
-            for (SystemUI ui: services) {
-                String name = ui.getClass().getName();
-                if (name.endsWith(svc)) {
-                    ui.dump(fd, pw, args);
-                }
-            }
-        }
+        if(isFirst()){
+               SystemUI[] services = ((SystemUIApplication) getApplication()).getServices();
+               if (args == null || args.length == 0) {
+                   for (SystemUI ui: services) {
+                       pw.println("dumping service: " + ui.getClass().getName());
+                       ui.dump(fd, pw, args);
+                   }
+               } else {
+                   String svc = args[0];
+                   for (SystemUI ui: services) {
+                       String name = ui.getClass().getName();
+                       if (name.endsWith(svc)) {
+                           ui.dump(fd, pw, args);
+                       }
+                   }
+               }
+               }
+        
     }


2.3屏蔽锁屏

frameworks/base/packages/SystemUI/res/values/config.xml

 <bool name="config_enableKeyguardService">false</bool>


以上修改就可以实现恢复出厂设置后屏蔽SystemUI.


解决方案二:

竟然有这种操作.很意外.

/**
 * Uses Root access to enable and disable SystemUI.
 * @param enabled Decide whether to enable or disable.
 */
public void setSystemUIEnabled(boolean enabled){
    try {
        Process p = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(p.getOutputStream());
        os.writeBytes("pm " + (enabled ? "enable" : "disable") 
                + " com.android.systemui\n");
        os.writeBytes("exit\n");
        os.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

setSystemUIEnabled(true);  // Enable SystemUI
setSystemUIEnabled(false); // Disable SystemUI





  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值