码迷,mamicode.com
首页 > 移动开发 > 详细

Android使用init.rc触发脚本实现隐藏内置应用

时间:2014-12-29 23:09:20      阅读:1067      评论:0      收藏:0      [点我收藏+]

标签:android   init.rc   shell   设置   开发者选项   

【实现逻辑】
通过在property_service.c中设置标志位,在设置中实现接口改变标志位,
使用init.rc中声明的服务来侦听标志位的变化,显式启动声明的服务,执行对应的脚本,把应用后缀从apk重命名为bak,从而实现隐藏(显示逻辑相反)。

【实现步骤】以隐藏Google Play Store(system/priv-app/Phonesky.apk)为例:
1.首先在system/core/init/property_service.c中声明并初始化标志位,0为隐藏,1为显示,默认隐藏
     { "app.launcher.start", AID_SYSTEM, 0},
+   { "app.phonesky.show", AID_SYSTEM, 0}, //Add By zj
     { "cdma.",        AID_RADIO,    0 },    //Add by gfzhu VIA


2.在设置的开发者选项中实现对应的接口:
文件路径:packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java
①声明和初始化:
private static final String SHOW_PHONESKY = "show_phonesky";
private CheckBoxPreference mShowPhonesky;
mShowPhonesky = findAndInitCheckboxPref(SHOW_PHONESKY);

②CheckBox的逻辑:
       (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
+      } else if (preference == mShowPhonesky) { // ZJ Add
+           if(mShowPhonesky.isChecked())
+           {
+              SystemProperties.set("app.phonesky.show","1");
+           }else{
+              SystemProperties.set("app.phonesky.show","0");
+           }
         } else if (preference == mBtHciSnoopLog) {



③增加一个Preference:
packages/apps/Settings/res/xml/development_prefs.xml

     android:targetClass="com.android.settings.SetFullBackupPassword" />
     </PreferenceScreen>
+       <CheckBoxPreference 
+        android:key="show_phonesky" 
+        android:title="@string/show_phonesky" 
+        />
     <CheckBoxPreference 


④添加对应语言的string字符:
<string name="show_phonesky">Show Google Play Store</string>


⑤设置中新增一个监听,初始化Checkbox的逻辑:
packages/apps/Settings/src/com/android/settings/BootReceiver.java
内容如下:
package com.android.settings;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.SystemClock;
import android.util.Log;
import android.os.SystemProperties;

public class BootReceiver extends BroadcastReceiver{

     @Override
     public void onReceive(Context arg0, Intent arg1) {
          // TODO Auto-generated method stub
          
          String action = arg1.getAction();
          if(action.equals(Intent.ACTION_BOOT_COMPLETED))
          { 
             SharedPreferences shared = arg0.getSharedPreferences("com.android.settings_preferences", Context.MODE_PRIVATE);
             boolean show_phonesky = shared.getBoolean("show_phonesky", false);
             if(show_phonesky){
                  SystemProperties.set("app.phonesky.show","1");     
               }else{
                    SystemProperties.set("app.phonesky.show","0");     
               }
          }
     }
}


⑥在Settings的AndroidManifest文件中添加BroadcastReceiver的权限和声明:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name=".BootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
               <category android:name="android.intent.category.DEFAULT" />        
            </intent-filter>      
</receiver>


3.在init.rc中添加对应的服务和触发条件:
路径:mediatek/config/esky27_tb_ccn_mlc_kk/init.rc
+# ZJ Add START
+#Hide or Show Google Play Dynamicly
+#disabled:服务不会自动运行,必须显式地通过服务器来启动。
+#oneshot:当此服务退出时不会自动重启。
+service hidePhonesky /system/bin/hidePhonesky
+       disabled
+       oneshot    
+service showPhonesky /system/bin/showPhonesky
+       disabled
+       oneshot    
+#on property:sys.boot_completed=1
+#   start renamePhonesky
+on property:app.phonesky.show=1
+   start showPhonesky
+on property:app.phonesky.show=0
+   start hidePhonesky
+# ZJ Add END


4.隐藏和显示应用的脚本:
隐藏应用:vendor/ThirdParty/App/dte/hidePhonesky
内容:
#!/system/bin/sh
#!/system/bin/busybox
mount -o remount,rw /system;
mv /system/priv-app/Phonesky.apk /system/priv-app/Phonesky.bak

显示应用:vendor/ThirdParty/App/dte/showPhonesky
内容:
#!/system/bin/sh
#!/system/bin/busybox
mount -o remount,rw /system;
mv /system/priv-app/Phonesky.bak /system/priv-app/Phonesky.apk


5.拷贝脚本到system/bin目录下:
参考以下格式添加到对应的mk文件:
+#添加重命名GooglePlay脚本
+PRODUCT_COPY_FILES += +       vendor/ThirdParty/App/dte/hidePhonesky:system/bin/hidePhonesky +       vendor/ThirdParty/App/dte/showPhonesky:system/bin/showPhonesky +       vendor/ThirdParty/App/dte/Phonesky.bak:system/priv-app/Phonesky.bak





Android使用init.rc触发脚本实现隐藏内置应用

标签:android   init.rc   shell   设置   开发者选项   

原文地址:http://blog.csdn.net/zhoumushui/article/details/42245481

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!