文档

接入指南

更新时间:

1. 系统升级接入指南

1.1 初始化

在application的onCreate()方法中,做如下必需项的设置:(必须要做。如果同时接入系统升级和应用升级的话,只需做1次即可。)

// 必需设置
FotaContext.getInstance().initContext(this);
FotaContext.getInstance().setFirmwareVersion(this, SystemProperties.get("ro.yunos.build.version"));
FotaContext.getInstance().setSafeguardAuth(getApplicationContext(), "aicc");

可选的设置有,通过setCustomizedFilterFields()方法,设置自定义查询条件:(无自定义查询条件的话,可不做。)

// 可选设置
JSONArray jsonArray = null;
try {
    jsonArray = new JSONArray();
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("name", "field1");
    jsonObject.put("value", "value1");
    jsonArray.put(jsonObject);

    JSONObject jsonObject2 = new JSONObject();
    jsonObject2.put("name", "field2");
    jsonObject2.put("value", "value2");
    jsonArray.put(jsonObject2);
} catch (Exception e) {
    Log.e(TAG, "Exception happened in FotaMainApplication onCreate, e.getMessage()=" + e.getMessage());
    e.printStackTrace();
}
Log.d(TAG, "FotaMainApplication onCreate jsonArray.toString=" + jsonArray.toString());
FotaContext.getInstance().setCustomizedFilterFields(this, jsonArray.toString());

1.2 绑定osupdate service

更详细的内容,请参考“系统升级参考设计apk的代码实现”。

// 使用OsUpdateServiceManager的静态方法,绑定osupdate service。
// 返回值:
//       true:已经绑定,false:未绑定。需要调用者自己维护该返回值。
// 入参:
//       context,应用的上下文
//       connection,一个ServiceConnection
bindDownloadService(Context context, ServiceConnection connection)

// 示例代码
boolean isBound = OsUpdateServiceManager.bindDownloadService(this, mConnection);

private ServiceConnection mConnection = new ServiceConnection() {
    public void onServiceConnected(ComponentName arg0, IBinder arg1) {
        // 取得osupdate service的实例
        mService = IOsUpdateService.Stub.asInterface(arg1);
        try {
            mService.getFotaDownloadEnvironmentRemote().setUiMode(FotaDownloadEnvironment.UI_MODE_INTERACTIVE);
            mService.getFotaDownloadEnvironmentRemote().setIsUserCheckingUi(true);
            // 注册监听listener
            mService.addListener(mListener);
            // 获取osupdate service的状态
            mMajorStatus = mService.getServiceStatus();
            mMinorStatus = mService.getServiceMinorStatus();
            // 根据不同的状态,分别做处理
            switch (mMajorStatus) {
                case FotaDownloadServiceManager.STATUS_VERYFY_DONE:
                case FotaDownloadServiceManager.STATUS_INSTALL_FORCED_TIMER_TICK:
                case FotaDownloadServiceManager.STATUS_INSTALLING:
                case FotaDownloadServiceManager.STATUS_DOWNLOADING:
                case FotaDownloadServiceManager.STATUS_INSTALL_ERROR:
                    switch (mMinorStatus) {
                        case FotaDownloadServiceManager.STATUS_PRECHECK_POWER_LOW:
                        case FotaDownloadServiceManager.STATUS_PRECHECK_POWER_NEED_CHARGING:
                        case FotaDownloadServiceManager.STATUS_PRECHECK_DATA_STORAGE_TOO_LOW:
                        case FotaDownloadServiceManager.STATUS_INSTALL_ERROR_FILE_NOTFOUND:
                        default:
                    }
                case FotaDownloadServiceManager.STATUS_DOWNLOAD_ERROR:
                case FotaDownloadServiceManager.STATUS_VERYFY_FAILED:
                case FotaDownloadServiceManager.STATUS_CHECK_SUCCESS:
                default:
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
            finish();
        }
    }

    public void onServiceDisconnected(ComponentName arg0) {
        mService = null;
        mIsBound = false;
    }
};

1.3 注册监听osupdate service状态变化的listener

更详细的内容,请参考“系统升级参考设计apk的代码实现”。

// 注册监听listener
mService.addListener(mListener);

// listener的定义
private FotaDownloadServiceIListener mListener = new FotaDownloadServiceIListener() {
    // 从service返回新版本信息
    public void onGotXml(FotaRootXmlInfo fota) throws RemoteException {
        mFotaXml = fota;
        synchronized (myCurrentVersionInfoLocker) {
            if (mFotaXml != null && !TextUtils.isEmpty(fota.getSystemVersion())
                    && !TextUtils.isEmpty(fota.getSize())) {
                mCurrentFotaVersionInfo = new FotaVersionInfo();
                mCurrentFotaVersionInfo.setSystemVersion(fota.getSystemVersion());
                mCurrentFotaVersionInfo.setSize(fota.getSize());
                mCurrentFotaVersionInfo.setTimeStamp(fota.getTimeStamp());
                mCurrentFotaVersionInfo.setUpdateInfoText(fota.getUpdateInfoText());
                mCurrentFotaVersionInfo.setUpdateInfoUrl(fota.getUpdateInfoUrl());
            } else {
                mCurrentFotaVersionInfo = mLocalFotaVersionInfo;
            }
        }
    }

    // osupdate service侧状态变化,通过该方法回调到这里
    public void onServiceStatusChange(final int majorStatus, final int minorStatus) {
        handler.post(new Runnable() {
            public void run() {
                onStatusChangedByService(majorStatus, minorStatus);
            }
        });
    }

    // service侧更新下载进度,通过该方法回调到这里
    public void onDownloadProcess(final int progress, float completeFileSize) {
        Log.i(TAG, "FotaUpdateInfo.onDownloadProcess called, partCount: " + progress + ", value: " + completeFileSize);
        handler.post(new Runnable() {
            public void run() {
                updateProgressbar(progress);
            }
        });
    }
};

1.4 参考设计apk中的用户交互

1) 处理强制夜间升级的弹窗

在应用的AndroidManifest.xml文件中,处理弹窗的类中,增加如下2个action的接收:

// 收到该广播,用于显示一个提示:
/*
* 更新提示
* 将在今晚自动升级或者将在明晚完成自动升级
* 只有一个按钮:我知道了
* 用户点击按钮之后,弹窗消失
*/
<action android:name="com.aliyun.aicc.fota.action.popupdialog.OSUPDATE_SERVICE_MIDNIGHT_INSTALL_TIP" />

// 如果云端配置为“夜间强制升级”,
// 端侧fota sdk内部:当下载完该升级包,并且校验通过之后,将设置Alarm,在夜间2:00~3:00之间的某一时刻,发出该广播。
// 应用层收到该广播之后,可显示一个倒计时弹窗,倒计时超时之后,自动重启设备进行升级。
<action android:name="com.aliyun.aicc.fota.action.popupdialog.OSUPDATE_SERVICE_MIDNIGHT_INSTALL" />

具体实现,请参考设计apk中的PopupDialogReceiver.java中的如下方法:

showNightForcedUpdateTipDialog()
showMidnightInstallDialog()

2. 应用升级接入指南

2.1 初始化

FotaContext.getInstance().initContext(this);
FotaContext.getInstance().setSafeguardAuth(this, "aicc");
FotaContext.getInstance().setEnvironment(FotaContext.CLOUD_ENV_ONLINE);

FotaAppConfig.getInstance().setAutoCheckPackagesList(this, 190*1000, new String[]{"com.yunos.member","com.alios.app1","com.alios.app2"});

2.2 静默下载,自动安装

FotaAppConfig.getInstance().setAutoUpgradeUnderWifi(this, true);
FotaAppConfig.getInstance().setAutoUpgradeUnderMobile(this,true);

服务端选择自动安装(只有自升级应用APK才可以选择这一项)

2.3 自定义安装

对于插件选择的安装类型是自定义安装

3. push接入指南

3.1 在应用的manifest文件中,加入push广播的接收

<receiver android:name="com.aliyun.aicc.fota.push.PushReceiver">
    <intent-filter>
        <action android:name="com.aliyun.aicc.fota" />
    </intent-filter>
</receiver>

3.2 下载并集成cmns apk

  • 说明:

    • cmns apk是配合ota中的消息推送,诊断等功能所使用的关联apk。

    • 下载到的文件后缀名是.zip,手动改为.apk,并对该apk重新做签名。

4. 升级诊断接入指南

4.1 在应用的manifest文件中,加入升级诊断service

<service
    android:name="com.aliyun.aicc.fota.service.DiagnoseService" android:exported="false">
    <intent-filter>
        <action android:name="com.aliyun.aicc.fota.action.Diagnose" />
    </intent-filter>
</service>

4.2 升级诊断的使用

1. 系统升级的诊断

使用方法见:https://help.aliyun.com/document_detail/73309.html

2. 应用升级的诊断

与上面的系统升级诊断类似。

  • 本页导读 (0)
文档反馈