android 9.0 动态修改开机动画保存的路径

 

需求:客户要求开机之后,自己手动修改开机动画,并且重启 恢复出厂设置,都不会是修改的动画还原回刷机的动画。

 

初始做法:把开机动画保存在data分区,然后开机的播动画的时候,去播放。后面发现有概率不播放这个动画,去播放原来刷机的动画。进一步发现是,data分区开机动画播放的时候没加载到。

然后各种想办法,都没用。

 

最终做法:后面和OMD商量找到  /mnt/vendor/persist/ 这个路径也可以播放动画,经过N次+权限之后,动画播放正常。

 

 

会长的代码修改如下:



 优化动态修改开机动画概率不生效的问题,修改保存路径 /mnt/vendor/persist/

diff --git a/device/qcom/common/rootdir/etc/init.qcom.rc b/device/qcom/common/rootdir/etc/init.qcom.rc
index af40c59..c329996 100755
--- a/device/qcom/common/rootdir/etc/init.qcom.rc
+++ b/device/qcom/common/rootdir/etc/init.qcom.rc
@@ -159,9 +159,9 @@ on boot
 #   ReadMin, ReadInitial, ReadMax, WriteMin, WriteInitial, WriteMax,
     setprop net.tcp.buffersize.wifi    524288,2097152,4194304,262144,524288,1048576
 
-
     setprop ro.telephony.call_ring.multiple false
 
+	chmod 0666 /mnt/vendor/persist/bootanimation.zip
 
     #Remove SUID bit for iproute2 ip tool
     chmod 0755 /system/bin/ip
diff --git a/device/qcom/sepolicy/vendor/common/bootanim.te b/device/qcom/sepolicy/vendor/common/bootanim.te
old mode 100644
new mode 100755
index ee1340b..2376003
--- a/device/qcom/sepolicy/vendor/common/bootanim.te
+++ b/device/qcom/sepolicy/vendor/common/bootanim.te
@@ -29,4 +29,7 @@
 typeattribute bootanim system_writes_vendor_properties_violators;
 binder_call(bootanim, mediaserver);
 allow bootanim mediaserver_service:service_manager find;
+allow bootanim mnt_user_file:dir { getattr search open read };
+allow bootanim mnt_vendor_file:dir { getattr search open read write};
+allow bootanim mnt_vendor_file:file {open read create write};
 userdebug_or_eng(`allow bootanim self:process execmem;')
diff --git a/device/qcom/sepolicy/vendor/common/domain.te b/device/qcom/sepolicy/vendor/common/domain.te
old mode 100644
new mode 100755
index 3fcbc83..3fa5e7a
--- a/device/qcom/sepolicy/vendor/common/domain.te
+++ b/device/qcom/sepolicy/vendor/common/domain.te
@@ -27,6 +27,8 @@ neverallow {
     coredomain
     -init
     -ueventd
+	-bootanim
+	-system_app
     } vendor_persist_type: { dir file } *;
 
 allow { domain - coredomain } mnt_vendor_file:lnk_file r_file_perms;
diff --git a/device/qcom/sepolicy/vendor/common/system_app.te b/device/qcom/sepolicy/vendor/common/system_app.te
index b34b832..243f09d 100755
--- a/device/qcom/sepolicy/vendor/common/system_app.te
+++ b/device/qcom/sepolicy/vendor/common/system_app.te
@@ -227,4 +227,7 @@ allow system_app sysfs_battery_supply:file { read getattr open };
 allow system_app system_data_file:dir create_dir_perms;
 allow system_app system_data_file:file create_file_perms;
 
+allow system_app mnt_vendor_file:dir create_dir_perms;
+allow system_app mnt_vendor_file:file create_file_perms;
+
 allow system_app vendor_file:file { write read open getattr};
diff --git a/frameworks/base/cmds/bootanimation/BootAnimation.cpp b/frameworks/base/cmds/bootanimation/BootAnimation.cpp
index 59851d3..60467ae 100755
--- a/frameworks/base/cmds/bootanimation/BootAnimation.cpp
+++ b/frameworks/base/cmds/bootanimation/BootAnimation.cpp
@@ -66,7 +66,7 @@
 namespace android {
 
 static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip";
-static const char PRODUCT_BOOTANIMATION_FILE[] = "/data/bootanimation.zip";
+static const char PRODUCT_BOOTANIMATION_FILE[] = "/mnt/vendor/persist/bootanimation.zip";//"/data/bootanimation.zip";
 static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip";
 static const char PRODUCT_ENCRYPTED_BOOTANIMATION_FILE[] = "/product/media/bootanimation-encrypted.zip";
 static const char SYSTEM_ENCRYPTED_BOOTANIMATION_FILE[] = "/system/media/bootanimation-encrypted.zip";
diff --git a/packages/apps/Settings/res/layout/cw_mode_activity_main.xml b/packages/apps/Settings/res/layout/cw_mode_activity_main.xml
index 484ba75..4c233c6 100755
--- a/packages/apps/Settings/res/layout/cw_mode_activity_main.xml
+++ b/packages/apps/Settings/res/layout/cw_mode_activity_main.xml
@@ -43,6 +43,18 @@
             android:text="Set bootanimation"
             tools:layout_editor_absoluteX="90dp"
             tools:layout_editor_absoluteY="190dp" />
+		<TextView
+            android:id="@+id/bootanexist"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="bootaimation not exists" />	
+        <Button
+            android:id="@+id/remove_bootan"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Remove bootanimation"
+            tools:layout_editor_absoluteX="90dp"
+            tools:layout_editor_absoluteY="190dp" />			
 
     </LinearLayout>
 
diff --git a/packages/apps/Settings/src/com/android/settings/CW_ModelActivity.java b/packages/apps/Settings/src/com/android/settings/CW_ModelActivity.java
index 087061d..4ce2e80 100755
--- a/packages/apps/Settings/src/com/android/settings/CW_ModelActivity.java
+++ b/packages/apps/Settings/src/com/android/settings/CW_ModelActivity.java
@@ -9,6 +9,7 @@ import android.util.Log;
 import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;
+import android.widget.TextView;
 import android.widget.Toast;
 
 import java.io.File;
@@ -23,14 +24,17 @@ import android.provider.Settings.System;
 import android.provider.Settings;
 import android.text.BidiFormatter;
 import android.os.Build;
+import android.graphics.Color;
 
 public class CW_ModelActivity extends Activity {
 
-    Button button ,model,updatelogo ,display;
+    Button button ,remove_bootan,model,updatelogo ,display;
     EditText modeleditText, dispalyeditText;
+	TextView bootanexist;
     private final String sdcardBootAnimation = "/mnt/sdcard/Android/bootanimation.zip";
     private final String sdcardShutAnimation = "/mnt/sdcard/Android/shutanimation.zip";
-    private final String customBootAnimation = "/data/bootanimation.zip";
+   // private final String customBootAnimation = "/data/bootanimation.zip";
+    private final String customBootAnimation = "/mnt/vendor/persist/bootanimation.zip";
     private final String customShutAnimation = "/data/shutanimation.zip";
     private final String customModelNumber = "/data/model";
     private final String customDispaly = "/data/dispaly";
@@ -46,6 +50,8 @@ public class CW_ModelActivity extends Activity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.cw_mode_activity_main);
         button =findViewById(R.id.button);
+        remove_bootan =findViewById(R.id.remove_bootan);
+        bootanexist =findViewById(R.id.bootanexist);
         display = findViewById(R.id.dispaly);
         model=findViewById(R.id.model);
         modeleditText =findViewById(R.id.set_model_et);
@@ -59,6 +65,14 @@ public class CW_ModelActivity extends Activity {
         modeleditText.setText(mDeviceName);
         String dispaly = BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY) ;
         dispalyeditText.setText(dispaly);
+		if(sfile.exists()){
+			bootanexist.setText("BootAnimation is exist");
+			bootanexist.setTextColor(Color.GREEN);
+		}else{
+			bootanexist.setText("BootAnimation is null");
+			bootanexist.setTextColor(Color.GRAY);
+		}
+		
         button.setOnClickListener(new View.OnClickListener() {
 
             @Override
@@ -77,6 +91,40 @@ public class CW_ModelActivity extends Activity {
                 }else{
                     Toast.makeText(getApplicationContext(),"file not exit",Toast.LENGTH_SHORT).show();
                 }
+				
+				if(sfile.exists()){
+					bootanexist.setText("BootAnimation is exist");
+					 bootanexist.setTextColor(Color.GREEN);
+				}else{
+					bootanexist.setText("BootAnimation is null");
+					bootanexist.setTextColor(Color.GRAY);
+				}
+            }
+        });
+		
+		remove_bootan.setOnClickListener(new View.OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                Log.i("--Method--", "rrrrrrrrrr remove_bootan   customBootAnimation==========");
+
+                if(sfile.exists()){
+						if (sfile.delete()) {
+							Toast.makeText(getApplicationContext(),"BootAnimation exist,file is  deleted",Toast.LENGTH_SHORT).show();        
+						}
+					 
+                }else{
+                    Toast.makeText(getApplicationContext(),"BootAnimation not exit",Toast.LENGTH_SHORT).show();
+                }
+				
+				if(sfile.exists()){
+					bootanexist.setText("BootAnimation is exist");
+					 bootanexist.setTextColor(Color.GREEN);
+				}else{
+					bootanexist.setText("BootAnimation is null");
+					bootanexist.setTextColor(Color.GRAY);
+				}
+				
             }
         });
 
diff --git a/system/sepolicy/prebuilts/api/28.0/public/bootanim.te b/system/sepolicy/prebuilts/api/28.0/public/bootanim.te
index dd6a868..de41779 100755
--- a/system/sepolicy/prebuilts/api/28.0/public/bootanim.te
+++ b/system/sepolicy/prebuilts/api/28.0/public/bootanim.te
@@ -40,6 +40,14 @@ allow bootanim system_file:dir r_dir_perms;
 # Read ro.boot.bootreason b/30654343
 get_prop(bootanim, bootloader_boot_reason_prop)
 
+allow bootanim audioserver:binder call;
+
 #Read the bootanimtion
 allow bootanim system_data_file:dir create_dir_perms;
 allow bootanim system_data_file:file {read open};
+
+allow bootanim storage_file:dir create_dir_perms;
+allow bootanim storage_file:file {read open};
+allow bootanim storage_file:lnk_file {read open};
+
+
diff --git a/system/sepolicy/prebuilts/api/28.0/public/domain.te b/system/sepolicy/prebuilts/api/28.0/public/domain.te
index 9fbbc3e..c347764 100755
--- a/system/sepolicy/prebuilts/api/28.0/public/domain.te
+++ b/system/sepolicy/prebuilts/api/28.0/public/domain.te
@@ -1410,4 +1410,6 @@ neverallow {
   coredomain
   -init
   -ueventd
+  -bootanim
+  -system_app
 } mnt_vendor_file:dir *;
diff --git a/system/sepolicy/public/bootanim.te b/system/sepolicy/public/bootanim.te
index dd6a868..de41779 100755
--- a/system/sepolicy/public/bootanim.te
+++ b/system/sepolicy/public/bootanim.te
@@ -40,6 +40,14 @@ allow bootanim system_file:dir r_dir_perms;
 # Read ro.boot.bootreason b/30654343
 get_prop(bootanim, bootloader_boot_reason_prop)
 
+allow bootanim audioserver:binder call;
+
 #Read the bootanimtion
 allow bootanim system_data_file:dir create_dir_perms;
 allow bootanim system_data_file:file {read open};
+
+allow bootanim storage_file:dir create_dir_perms;
+allow bootanim storage_file:file {read open};
+allow bootanim storage_file:lnk_file {read open};
+
+
diff --git a/system/sepolicy/public/domain.te b/system/sepolicy/public/domain.te
index 9fbbc3e..c347764 100755
--- a/system/sepolicy/public/domain.te
+++ b/system/sepolicy/public/domain.te
@@ -1410,4 +1410,6 @@ neverallow {
   coredomain
   -init
   -ueventd
+  -bootanim
+  -system_app
 } mnt_vendor_file:dir *;

 

Android 9.0中,动态申请存储权限是必须的,以提高应用程序的安全性和隐私保护。以下是如何在Android 9.0动态申请存储权限的步骤: 1. 在AndroidManifest.xml文件中添加存储权限的声明。 ```xml <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> ``` 2. 检查应用程序是否已经被授予存储权限。可以使用`checkSelfPermission`方法进行检查,并在需要的情况下请求授予权限。 ```java if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // 未获得存储权限,进行权限请求 ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode); } else { // 已获得存储权限,执行相应操作 // do something } ``` 3. 实现`onRequestPermissionsResult`方法,处理用户对权限请求的响应。如果用户授予了权限,可以继续执行相关操作。 ```java @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == requestCode) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // 用户授予了存储权限,执行相应操作 // do something } else { // 用户拒绝了存储权限,可以向用户解释为什么需要该权限 } } } ``` 需要注意的是,在Android 9.0之后,需要在`AndroidManifest.xml`文件中进行权限声明,同时还需要在运行时动态请求权限。这样做可以提高用户对应用程序的信任,同时保护用户的隐私和数据安全。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值