package com.system.ota;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.system.Os;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import java.io.File;
/*
注意 注意 注意:
一、pubic void applyPayload(String url,long offset,long size,String[] headerKeyValuePairs)
url:升级包(Payload)的路径,ab升级只能使用内置存储,必须在目录 /data/ota_package/xxx
而且需要以file://开头,比如file://data/ota_package/update.zip
update engine只接受固定的路径/data/ota_package/update.zip,其他路径和sdcard不支持
offset:这是payload 在update.zip中的偏移量,需要从升级包文件中计算出来
Size:这是payload文件的大小,可以在payload_properties.txt中找到
headerKeyValuePairs:这是metadata,可以在升级包中的payload_properties.txt中找到
二、 如果adb push /data/ota_package/update.zip 目录下可以升级成功,而下载下来不可以,一般应该是seLiunx权限问题 可以ls -lZ查看下
需要在
/system/sepolicy/private/system_app.te
/system/sepolicy/prebuilts/api/28.0/private/system_app.te 加上下面两句
allow system_app ota_package_file:dir { read open write create remove_name search rename add_name getattr };
allow system_app ota_package_file:file { read write create open rename setattr getattr unlink };
==========================================================================================================
相关代码接口说明如下
一、framwork层 应用接口
源代码位置:framwork/base/core/java/android/os/UpdateEngine.java
framwork/base/core/java/android/os/UpdateEngineCallback.java
二、app应用调取applyUpdate方法我这里只说一下大致流程
当然得系统权限的App了,需要系统签名,这些Api也是@SystemApi的
1、创建 UpdateEngineCallback 的对象 mUpdateEngineCallback
2、创建 UpdateEngine 的对象 mUpdateEngine, 创建后服务开启
3、使用mUpdateEngine.bind(mUpdateEngineCallback) 因为bind方法时接受的callback对象,而我们创建的类继承了callback,传入当前类的对象即可
4、调用 applyPayload(String url,long offset,long size,String[] headerKeyValuePairs) 方法具体执行升级
5、在重写的onStatusUpdate(int status, float percent)方法中根据拿到的状态执行进度逻辑
在重写的onPayloadApplicationComplete(int errorCode);方法中执行升级完成后的逻辑
*/
public class MainActivity extends AppCompatActivity {
private static final String TAG = "ota";
private Button button_test;
private static final int STORAGE_PERMISSIONS_REQUEST_CODE = 0;
private static final String[] REQUIRED_STORAGE_PERMISSIONS = new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) {
Log.e(TAG,"checkSelfPermission ===false");
ActivityCompat.requestPermissions(this, REQUIRED_STORAGE_PERMISSIONS,STORAGE_PERMISSIONS_REQUEST_CODE);
}else{
Log.e(TAG,"checkSelfPermission ===true");
}
setContentView(R.layout.activity_main);
initView();
}
private void initView(){
button_test = findViewById(R.id.button_test);
button_test.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//Toast.makeText(getApplicationContext(),"click", Toast.LENGTH_LONG).show();
chmodFile();//权限不够的话会失败
startOTA();
}
});
}
private void chmodFile(){
try {
File otaFile = new File("/data/ota_package/update.zip");
Os.chmod(otaFile.getAbsolutePath(), 0666);
} catch (Exception e) {
Log.i(TAG,"chmod fail!!!! e="+e.toString());
e.printStackTrace();
}
}
private void startOTA(){
try{
UpdateParser.ParsedUpdate mParsedUpdate = UpdateParser.parse(new File("/data/ota_package/update.zip"));
Log.e(TAG,mParsedUpdate.toString());
SystemUpdateManager mSystemUpdateManager = new SystemUpdateManager(MainActivity.this);
mSystemUpdateManager.startUpdateSystem(mParsedUpdate);
}catch(Exception e){
Log.e(TAG,"e="+e.toString());
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android A/B分区OTA系统升级应用层调用UpdateEngine Apk源码
共115个文件
xml:64个
png:10个
bin:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 148 下载量 131 浏览量
2021-02-08
11:45:16
上传
评论 6
收藏 16.39MB ZIP 举报
温馨提示
最近在搞 Android A/B 分区 OTA 升级,开始以为挺简单的一个事,没想到折腾了几天,还好终于搞定!代码调用其实就那么点,但是参数以及权限之类很关键,搬砖过来走不通,我就是卡了2天,一些莫名的错误,没法定位。后面各种查资料,结合系统代码,写了一个解析类 只需传入update.zip包,解析后升级,爽的一批。需要注意的坑在代码里也备注了,有需要的码友要注意下,特别是如果卡住了找不到原因所在的情况。参考博文: https://blog.csdn.net/daokedream/article/details/113433587
资源推荐
资源详情
资源评论
收起资源包目录
Android A/B分区OTA系统升级应用层调用UpdateEngine Apk源码 (115个子文件)
gradlew.bat 2KB
classAnalysis.bin 3.18MB
executionHistory.bin 1.81MB
jarAnalysis.bin 1.29MB
fileHashes.bin 310KB
taskHistory.bin 27KB
outputFiles.bin 27KB
resourceHashesCache.bin 18KB
last-build.bin 1B
.gitignore 222B
.gitignore 8B
build.gradle 1KB
build.gradle 585B
settings.gradle 46B
gradlew 5KB
app.iml 13KB
SystemOTA.iml 881B
android-framework.jar 15.64MB
gradle-wrapper.jar 53KB
MainActivity.java 5KB
UpdateParser.java 4KB
SystemUpdateManager.java 2KB
ExampleInstrumentedTest.java 744B
BuildConfig.java 435B
ExampleUnitTest.java 376B
buildOutputCleanup.lock 17B
javaCompile.lock 17B
executionHistory.lock 17B
fileHashes.lock 17B
fileContent.lock 17B
Android.mk 715B
ic_launcher_round.png 15KB
ic_launcher_round.png 10KB
ic_launcher.png 9KB
ic_launcher_round.png 7KB
ic_launcher.png 6KB
ic_launcher_round.png 5KB
ic_launcher.png 4KB
ic_launcher.png 3KB
ic_launcher_round.png 3KB
ic_launcher.png 2KB
proguard-rules.pro 772B
gradle.properties 1KB
local.properties 447B
gradle-wrapper.properties 238B
cache.properties 53B
gc.properties 0B
gc.properties 0B
readme 2KB
gradle_models.ser 140KB
build_file_checksums.ser 540B
workspace.xml 19KB
ic_launcher_background.xml 6KB
Project.xml 3KB
ic_launcher_foreground.xml 2KB
AndroidManifest.xml 1KB
Gradle__androidx_test_espresso_espresso_idling_resource_3_1_1_aar.xml 976B
Gradle__androidx_swiperefreshlayout_swiperefreshlayout_1_0_0_aar.xml 920B
Gradle__androidx_coordinatorlayout_coordinatorlayout_1_0_0_aar.xml 912B
Gradle__androidx_test_espresso_espresso_core_3_1_1_aar.xml 899B
Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml 872B
Gradle__androidx_appcompat_appcompat_1_0_2_aar.xml 848B
Gradle__androidx_fragment_fragment_1_0_0_aar.xml 840B
Gradle__androidx_test_monitor_1_1_1_aar.xml 829B
Gradle__androidx_test_ext_junit_1_1_0_aar.xml 828B
Gradle__androidx_test_runner_1_1_1_aar.xml 822B
Gradle__androidx_print_print_1_0_0_aar.xml 816B
Gradle__androidx_test_core_1_1_0_aar.xml 809B
Gradle__androidx_core_core_1_0_1_aar.xml 808B
Gradle__org_hamcrest_hamcrest_integration_1_3_jar.xml 793B
Gradle__androidx_annotation_annotation_1_0_0_jar.xml 765B
Gradle__org_hamcrest_hamcrest_library_1_3_jar.xml 764B
Gradle__androidx_localbroadcastmanager_localbroadcastmanager_1_0_0_aar.xml 747B
Gradle__org_hamcrest_hamcrest_core_1_3_jar.xml 744B
Gradle__androidx_vectordrawable_vectordrawable_animated_1_0_0_aar.xml 744B
Gradle__androidx_legacy_legacy_support_core_utils_1_0_0_aar.xml 738B
Gradle__com_squareup_javawriter_2_1_1_jar.xml 737B
Gradle__androidx_asynclayoutinflater_asynclayoutinflater_1_0_0_aar.xml 734B
Gradle__androidx_lifecycle_lifecycle_livedata_core_2_0_0_aar.xml 734B
Gradle__androidx_versionedparcelable_versionedparcelable_1_0_0_aar.xml 734B
Gradle__androidx_legacy_legacy_support_core_ui_1_0_0_aar.xml 723B
Gradle__javax_inject_javax_inject_1_jar.xml 723B
Gradle__androidx_slidingpanelayout_slidingpanelayout_1_0_0_aar.xml 720B
Gradle__androidx_lifecycle_lifecycle_viewmodel_2_0_0_aar.xml 714B
Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml 709B
Gradle__androidx_lifecycle_lifecycle_runtime_2_0_0_aar.xml 704B
Gradle__androidx_vectordrawable_vectordrawable_1_0_1_aar.xml 699B
Gradle__net_sf_kxml_kxml2_2_3_0_jar.xml 698B
Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml 692B
Gradle__androidx_documentfile_documentfile_1_0_0_aar.xml 685B
Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml 685B
Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml 679B
Gradle__androidx_customview_customview_1_0_0_aar.xml 671B
Gradle__junit_junit_4_12_jar.xml 667B
Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml 664B
activity_main.xml 658B
gradle.xml 649B
Gradle__androidx_loader_loader_1_0_0_aar.xml 643B
Gradle__androidx_lifecycle_lifecycle_common_2_0_0_jar.xml 594B
runConfigurations.xml 575B
共 115 条
- 1
- 2
Crazy程序猿2020
- 粉丝: 411
- 资源: 31
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页