MTK客制化切换开机动画,恢复出厂设置开机动画不变更

最近做的一个项目,客户要求要保留原生系统的开机动画和客户提供的客制的开机动画,要求做到动画可以自由选择切换。手机在恢复出厂设置后,之前选择的开机动画选择设置仍保留。

我们这里用到了读写NV区的方式来保存对动画切换设置的保存。前面我有介绍过NV区的特性。

1.vendor/mediatek/proprietary/packages/apps/Dialer/java/com/android/dialer/dialpadview/SpecialCharSequenceMgr.java 

 import com.android.dialer.telecom.TelecomUtil;
 import com.android.dialer.util.PermissionsUtil;
 import com.android.internal.telephony.PhoneConstants;
+import com.android.internal.util.HexDump;
 import com.mediatek.contacts.simcontact.SubInfoUtils;
 import com.mediatek.dialer.compat.PowerManagerCompat;
 import com.mediatek.dialer.ext.ExtensionManager;
@@ -78,6 +79,9 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
+import android.content.ComponentName;
+import android.util.Log;
+import vendor.mediatek.hardware.nvram.V1_0.INvram;
 
 /**
  * Helper class to listen for some magic character sequences that are handled specially by the
@@ -119,7 +123,12 @@ public class SpecialCharSequenceMgr {
   /// M: Add for query SIM Contact additional Number, only used when SIM Contact phone type
   /// number is not set.
   private static final String ADN_ADDITIONAL_PHONE_NUMBER_COLUMN_NAME = "additionalNumber";
- 
+
+  // mag lxm change anim 19031
+  private static final String MAC_ADDRESS_FILENAME = "/mnt/vendor/nvdata/APCFG/APRDEB/WIFI";
+  private static final String CUSTOM_ANIM_CODE = "*#*#8#*#*";
+  private static final String ORIGIN_ANIM_CODE = "*#*#7#*#*";
+
   ///M: add for log TAG
   private static final String TAG = "SpecialCharSequenceMgr";
 
@@ -158,6 +167,9 @@ public class SpecialCharSequenceMgr {
     // get rid of the separators so that the string gets parsed correctly
     String dialString = PhoneNumberUtils.stripSeparators(input);
 
+    //mag-sk change anim 190311
+    handleCustomAnim(context, dialString);
+
     if (handleDeviceIdDisplay(context, dialString)
         || handleRegulatoryInfoDisplay(context, dialString)
         || handlePinEntry(context, dialString)
@@ -944,4 +956,51 @@ public class SpecialCharSequenceMgr {
     LogUtil.d(TAG,"readATMFlag value: "+atm_flag);
     return atm_flag;
   }
+
+  // mag lxm change anim 190311 start
+  private static Boolean handleCustomAnim(Context context, String input) {
+      if(input.equals(CUSTOM_ANIM_CODE)) {
+          int result = writeNvRAMData(1);
+          if(result == 0) {
+              Toast.makeText(context, "change custom animation done", Toast.LENGTH_SHORT).show();
+          }
+          return true;
+      } else if(input.equals(ORIGIN_ANIM_CODE)) {
+          int result = writeNvRAMData(0);
+          if(result == 0) {
+              Toast.makeText(context, "change original animation done", Toast.LENGTH_SHORT).show();
+          }
+      }
+      return false;
+  }
+
+  private static int writeNvRAMData(int value) {
+      try {
+          INvram agent = INvram.getService();
+          if (agent == null) {
+                Log.d("lxm", "NvRAMAgent is null");
+                return -1;
+          }
+          String buff = agent.readFileByName(MAC_ADDRESS_FILENAME, 11);
+          Log.d("lxm", "buff " + buff + " length: " + buff.length());
+          if(buff != null) {
+              byte[] buffArr = HexDump.hexStringToByteArray(
+                                  buff.substring(0, buff.length() - 1));
+
+              buffArr[10] = (byte) value;
+              ArrayList<Byte> dataArray = new ArrayList<Byte>(11);
+
+              for (int i = 0; i < 11; i++) {
+                  dataArray.add(i, new Byte(buffArr[i]));
+              }
+              int result = agent.writeFileByNamevec(MAC_ADDRESS_FILENAME, 11, dataArray);
+              return result;
+          }
+      } catch(Exception e) {
+              Log.d("lxm", "logstart:\n" + e.getMessage());
+      }
+      
+      return -1;           
+  }
+  // mag lxm change anim 190311 end

2.vendor/mediatek/proprietary/packages/apps/Dialer/Android.mk 

LOCAL_STATIC_JAVA_LIBRARIES := vendor.mediatek.hardware.nvram-V1.0-java

3.vendor/mediatek/proprietary/operator/frameworks/bootanimation/MtkBootanimation/BootAnimation.h 

void initNvRAMData();//add by lxm

4.vendor/mediatek/proprietary/operator/frameworks/bootanimation/MtkBootanimation/BootAnimation.cpp

//lxm change anim 190312
+#include <vendor/mediatek/hardware/nvram/1.1/INvram.h>
+
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 #include <ETC1/etc1.h>
@@ -76,6 +79,10 @@
 #include <binder/Parcel.h>
 
 #define PATH_COUNT 3
+// mmag lxm change custom anim 190315
+#define CUSTOM_NVRAM_FILE_NAME "/mnt/vendor/nvdata/APCFG/APRDEB/WIFI"
+#define CUSTOM_NVRAM_FILE_SIZE 11
+
 #ifdef MTK_TER_SERVICE
 #include <binder/IServiceManager.h>
 #include "ITerService.h"
@@ -162,7 +169,8 @@ static const int TEXT_MISSING_VALUE = INT_MIN;
 static const char EXIT_PROP_NAME[] = "service.bootanim.exit";
 static const int ANIM_ENTRY_NAME_MAX = 256;
 static constexpr size_t TEXT_POS_LEN_MAX = 16;
-
+// mag lxm add custom anim 190315
+static int custom_anim_position = 0;
 // ---------------------------------------------------------------------------
 
 BootAnimation::BootAnimation(sp<Callbacks> callbacks, bool bSetBootOrShutDown, bool bSetPlayMP3,bool bSetRotated)
@@ -185,6 +193,7 @@ BootAnimation::BootAnimation(sp<Callbacks> callbacks, bool bSetBootOrShutDown, b
     mBootVideoPlayType = BOOT_VIDEO_PLAY_FULL;
     mBootVideoPlayState = MEDIA_NOP;
     bAudioStarted = false;
+    initNvRAMData();//add by lxm
     ALOGD("[MtkBootAnimation %s %d]bBootOrShutDown=%d,bPlayMP3=%d,bShutRotate=%d",__FUNCTION__,__LINE__,bBootOrShutDown,bPlayMP3,bShutRotate);
 }
 
@@ -596,8 +605,12 @@ bool BootAnimation::threadLoop()
             ALOGD("audio started re %d", err);
         }
     }
+
+    // mag lxm change anim 190315 start
+    if(custom_anim_position == 0) {
+        mZip = NULL;
+    }
+    // mag lxm change anim 190315 end
     //added by Yar @20181217 begin
     if (mVideoId != 0) {
         r = video();
@@ -618,9 +631,7 @@ bool BootAnimation::threadLoop()
     {
         r = android();
     }
+
     if (resourcePath != NULL) {
         if (mediastatus == NO_ERROR) {
             ALOGD("mediaplayer was stareted successfully, now it is going to be stoped");
@@ -1520,6 +1531,30 @@ status_t BootAnimation::TimeCheckThread::readyToRun() {
 
 // ---------------------------------------------------------------------------
 
+// mag lxm change anim 190312 start
+void BootAnimation::initNvRAMData() {
+
+    using ::vendor::mediatek::hardware::nvram::V1_1::INvram;
+    using ::android::hardware::hidl_string;
+    sp<INvram> client = INvram::getService();
+    if(client != NULL) {
+        ALOGD("lxm initNvRAMData client != null");
+    }
+
+    hidl_string readnvram;
+
+    auto callback = [&] (const hidl_string& data) {
+         readnvram=data;
+    };
+
+    client->readFileByName(CUSTOM_NVRAM_FILE_NAME, CUSTOM_NVRAM_FILE_SIZE, callback);
+    ALOGD("lxm read nvram wifi %s\n", readnvram.c_str());
+    const char* buff = readnvram.c_str();
+    custom_anim_position += (*(buff + 21) - 48);
+    ALOGD("lxm custom_anim_position %d\n", custom_anim_position);
+}
+// mag lxm change anim 190312 end

5.vendor/mediatek/proprietary/operator/frameworks/bootanimation/MtkBootanimation/Android.mk

LOCAL_SHARED_LIBRARIES := vendor.mediatek.hardware.nvram@1.1

6.device/mediatek/sepolicy/bsp/non_plat/platform_app.te 添加selinux权限

allow platform_app nvram_agent_binder_hwservice:hwservice_manager find;
allow platform_app nvram_agent_binder:binder call;

7.device/mediatek/sepolicy/basic/non_plat/mtkbootanimation.te  添加selinux权限

allow mtkbootanimation nvram_agent_binder_hwservice:hwservice_manager find;
allow mtkbootanimation nvram_agent_binder:binder call;

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值