您的位置:首页 > 产品设计 > UI/UE

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

2017-06-19 10:12 197 查看
平台: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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  SystemUI