Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android使用init.rc觸發腳本實現隱藏內置應用

Android使用init.rc觸發腳本實現隱藏內置應用

編輯:關於Android編程

【實現邏輯】 通過在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 />
     
+       
     




④添加對應語言的string字符:
Show Google Play Store


⑤設置中新增一個監聽,初始化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的權限和聲明:


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





  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved