【全志Android11平台】内置图片到设备里

一、前言

在产品开发中,有客户提到了要内置一些照片和视频,但相应的apk扫的是sdcard里的资源,sdcard是后面挂载起来的,所以采用shell脚本结合rc服务去处理这个问题。

二、代码路径

device\softwinner\ares\tv303c2-tuna_p2\system
device\softwinner\ares\tv303c2_tuna_p2.mk
frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.java
system/core/rootdir/init.rc

三、处理步骤

1.将图片内置到product/etc目录下

将图片视频资源放到device\softwinner\ares\tv303c2-tuna_p2\system目录下,在这个代码路径里device\softwinner\ares\tv303c2_tuna_p2.mk添加如下:

+ PRODUCT_COPY_FILES += $(call find-copy-subdir-files,*,$(PRODUCT_DEVICE_PATH)/system/kehu_intel_PicturesVideos,product/etc)

2.写脚本将product/etc里的图片视频资源转移到sdcard目录下

mv_PicturesVideos.sh

#!/system/bin/sh

# 源目录和目标目录的路径
source_directory="/product/etc"
target_directory="/sdcard"

# 检查目标目录是否存在
if [ -d "$target_directory" ]; then
  # 循环遍历源目录中的文件
  for file in "$source_directory"/*; do
    # 检查文件是否为普通文件
    if [ -f "$file" ]; then
      # 获取文件扩展名
      extension="${file##*.}"
      # 检查文件扩展名是否为 mp4 或 jpg
      if [ "$extension" == "mp4" ] || [ "$extension" == "jpg" ]; then
        # 获取文件名
        filename=$(basename "$file")
        # 将文件移动到目标目录
        mv "$file" "$target_directory/$filename"
        echo "Moved file: $filename"
      fi
    fi
  done
  echo "All video (mp4) and image (jpg) files moved successfully."
else
  echo "Target directory does not exist. Skipping file move."
fi

if [ -f "/sdcard/star.mp4" ]; then
  setprop persist.sys.mvflag 1
else
  setprop persist.sys.mvflag 0
  echo "/sdcard/star.mp4 no exits"
fi

 将脚本放到system目录下,生成在机器system/bin中

PRODUCT_COPY_FILES += $(PRODUCT_DEVICE_PATH)/system/mv_PicturesVideos.sh:system/bin/mv_PicturesVideos.sh

 将此脚本挂在init.rc中,用persist.sys.mv_PicturesVideos属性去执行

+ on property:persist.sys.mv_PicturesVideos=1
+    start mv_PicturesVideos

3.执行脚本

在PhoneWindowManager.java里执行脚本(通过属性去判断有没有执行成功,如果没有成功则继续执行)

public void init(Context context, IWindowManager windowManager,
            WindowManagerFuncs windowManagerFuncs) {
....
 mKeyguardDelegate = new KeyguardServiceDelegate(mContext,
                new StateCallback() {
                    @Override
                    public void onTrustedChanged() {
                        mWindowManagerFuncs.notifyKeyguardTrustedChanged();
                    }

                    @Override
                    public void onShowingChanged() {
                        mWindowManagerFuncs.onKeyguardShowingAndNotOccludedChanged();
                    }
                });
+    mHandler.postDelayed(mPerformloadingRunnable,60000);//大概在60秒后sdcard被挂起,mPerformloadingRunnable实现在下面
...
}

+ private final Runnable mPerformloadingRunnable = new Runnable() {
+        @Override
+        public void run() {
+            //执行rc服务挂载的脚本
+            SystemProperties.set("persist.sys.mv_PicturesVideos","1");
+            //判断脚本里设置的属性,为1执行成功,为0执行失败
+            String mvflag = SystemProperties.get("persist.sys.mvflag","0");   
+            if (mvflag.equals("0")){
+                Log.d("mvtest","mvflag is no exists");
+                SystemProperties.set("persist.sys.mv_PicturesVideos","1");
+                //执行失败则继续执行
+                mHandler.postDelayed(this, 2000);
+            }else{
+                Log.d("mvtest","mvflag is exists");
+            }  
+        }
+    };

四、总结

这个处理方法,我觉得还是不太好,以后看看有没有更好的方法,但为了及时完成需求,只能先这样处理了。

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值