首页 > 代码库 > Android使用init.rc触发脚本实现隐藏内置应用
Android使用init.rc触发脚本实现隐藏内置应用
【实现逻辑】 通过在property_service.c中设置标志位,在设置中实现接口改变标志位, 使用init.rc中声明的服务来侦听标志位的变化,显式启动声明的服务,执行对应的脚本,把应用后缀从apk重命名为bak,从而实现隐藏(显示逻辑相反)。
【实现步骤】以隐藏Google Play Store(system/priv-app/Phonesky.apk)为例: 1.首先在system/core/init/property_service.c中声明并初始化标志位,0为隐藏,1为显示,默认隐藏
?
1 2 3 | { 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 ①声明和初始化:
?
1 2 3 | private static final String SHOW_PHONESKY = show_phonesky; private CheckBoxPreference mShowPhonesky; mShowPhonesky = findAndInitCheckboxPref(SHOW_PHONESKY); |
②CheckBox的逻辑:
?
1 2 3 4 5 6 7 8 9 | (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
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | android:targetClass=com.android.settings.SetFullBackupPassword /> + <checkboxpreference android:key= "show_phonesky" android:title= "@string/show_phonesky" > <checkboxpreference pre= "" > ④添加对应语言的string字符:<pre class = "brush:java;" ><string name= "show_phonesky" >Show Google Play Store</string></pre> <br> <br> ⑤设置中新增一个监听,初始化Checkbox的逻辑: packages/apps/Settings/src/com/android/settings/BootReceiver.java 内容如下: <pre class = "brush: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 ); } } } }</pre> <br> <br> ⑥在Settings的AndroidManifest文件中添加BroadcastReceiver的权限和声明: <pre class = "brush:java;" ><uses-permission android:name= "android.permission.RECEIVE_BOOT_COMPLETED/" > </uses-permission></pre> <br> 3 .在init.rc中添加对应的服务和触发条件: 路径:mediatek/config/esky27_tb_ccn_mlc_kk/init.rc <pre class = "brush:java;" >+# 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</pre> <br> <br> 4 .隐藏和显示应用的脚本: 隐藏应用:vendor/ThirdParty/App/dte/hidePhonesky 内容:<br> <pre class = "brush:java;" >#!/system/bin/sh #!/system/bin/busybox mount -o remount,rw /system; mv /system/priv-app/Phonesky.apk /system/priv-app/Phonesky.bak</pre> <br> 显示应用:vendor/ThirdParty/App/dte/showPhonesky<br> 内容:<br> <pre class = "brush:java;" >#!/system/bin/sh #!/system/bin/busybox mount -o remount,rw /system; mv /system/priv-app/Phonesky.bak /system/priv-app/Phonesky.apk</pre> <br> <br> 5 .拷贝脚本到system/bin目录下: 参考以下格式添加到对应的mk文件: <pre class = "brush:java;" >+#添加重命名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</pre> </checkboxpreference></checkboxpreference><br> <br> <br> <br> <br> |
结伴旅游,一个免费的交友网站:www.jieberu.com
推推族,免费得门票,游景区:www.tuituizu.com
Android使用init.rc触发脚本实现隐藏内置应用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。