Example usage for android.os RecoverySystem installPackage

List of usage examples for android.os RecoverySystem installPackage

Introduction

In this page you can find the example usage for android.os RecoverySystem installPackage.

Prototype

@RequiresPermission(android.Manifest.permission.RECOVERY)
public static void installPackage(Context context, File packageFile) throws IOException 

Source Link

Document

Reboots the device in order to install the given update package.

Usage

From source file:Main.java

public static void installPackage(Context context, File packageFile) {
    try {/*from  ww w  .jav a2 s  .co m*/
        RecoverySystem.installPackage(context, packageFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.wso2.emm.system.service.api.OTAServerManager.java

public void startInstallUpgradePackage() {
    Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status),
            Constants.Status.SUCCESSFUL);
    Preference.putString(context, context.getResources().getString(R.string.upgrade_install_status),
            Constants.Status.REQUEST_PLACED);
    File recoveryFile = new File(FileUtils.getUpgradePackageFilePath());
    try {/*from w  ww .  j a v a  2s  .com*/
        wakeLock.acquire();
        boolean isAutomaticRetryEnabled = Preference.getBoolean(context,
                context.getResources().getString(R.string.firmware_upgrade_automatic_retry));
        if (getBatteryLevel(context) >= Constants.REQUIRED_BATTERY_LEVEL_TO_FIRMWARE_UPGRADE) {
            Log.d(TAG, "Installing upgrade package");
            if (isAutomaticRetryEnabled || Constants.SILENT_FIRMWARE_INSTALLATION) {
                RecoverySystem.installPackage(context, recoveryFile);
            } else {
                setNotification(context,
                        context.getResources().getString(R.string.ask_from_user_to_install_firmware), true);
            }
        } else if (isAutomaticRetryEnabled) {
            Preference.putString(context, context.getResources().getString(R.string.upgrade_install_status),
                    Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_INSTALL);
            Log.e(TAG, "Upgrade installation differed due to insufficient battery level.");
            setNotification(context, context.getResources().getString(R.string.upgrade_differed_due_to_battery),
                    false);
        } else {
            Preference.putString(context, context.getResources().getString(R.string.upgrade_install_status),
                    Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_INSTALL);
            Log.e(TAG, "Upgrade installation failed due to insufficient battery level.");
            setNotification(context, context.getResources().getString(R.string.upgrade_failed_due_to_battery),
                    false);
        }
    } catch (IOException e) {
        reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_INSTALL_FAILED);
        String message = "Update installation failed due to file error.";
        Log.e(TAG, message + e);
        CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.FAILURE,
                Constants.Status.OTA_IMAGE_VERIFICATION_FAILED, message);
        CommonUtils.callAgentApp(context, Constants.Operation.FAILED_FIRMWARE_UPGRADE_NOTIFICATION,
                Preference.getInt(context, context.getResources().getString(R.string.operation_id)), message);
    } catch (SecurityException e) {
        reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_INSTALL_FAILED);
        String message = "Update installation failure due to security check failure.";
        Log.e(TAG, message + e);
        CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.FAILURE,
                Constants.Status.OTA_IMAGE_VERIFICATION_FAILED, message);
        CommonUtils.callAgentApp(context, Constants.Operation.FAILED_FIRMWARE_UPGRADE_NOTIFICATION,
                Preference.getInt(context, context.getResources().getString(R.string.operation_id)), message);
    } finally {
        wakeLock.release();
    }

}

From source file:org.wso2.iot.system.service.api.OTAServerManager.java

public void startInstallUpgradePackage() {
    Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status),
            Constants.Status.SUCCESSFUL);
    Preference.putString(context, context.getResources().getString(R.string.upgrade_install_status),
            Constants.Status.REQUEST_PLACED);
    File recoveryFile = new File(FileUtils.getUpgradePackageFilePath());
    try {/*from w w w  .j  a  v  a  2  s .co m*/
        wakeLock.acquire();
        boolean isAutomaticRetryEnabled = Preference.getBoolean(context,
                context.getResources().getString(R.string.firmware_upgrade_automatic_retry));
        if (getBatteryLevel(context) >= Constants.REQUIRED_BATTERY_LEVEL_TO_FIRMWARE_UPGRADE) {
            Log.d(TAG, "Installing upgrade package");
            if (isAutomaticRetryEnabled || Constants.SILENT_FIRMWARE_INSTALLATION) {
                CommonUtils.callAgentApp(context, Constants.Operation.FIRMWARE_UPGRADE_COMPLETE,
                        Preference.getInt(context, context.getResources().getString(R.string.operation_id)),
                        "Starting firmware upgrade");
                RecoverySystem.installPackage(context, recoveryFile);
            } else {
                setNotification(context,
                        context.getResources().getString(R.string.ask_from_user_to_install_firmware), true);
            }
        } else if (isAutomaticRetryEnabled) {
            Preference.putString(context, context.getResources().getString(R.string.upgrade_install_status),
                    Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_INSTALL);
            Log.e(TAG, "Upgrade installation differed due to insufficient battery level.");
            setNotification(context, context.getResources().getString(R.string.upgrade_differed_due_to_battery),
                    false);
        } else {
            Preference.putString(context, context.getResources().getString(R.string.upgrade_install_status),
                    Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_INSTALL);
            Log.e(TAG, "Upgrade installation failed due to insufficient battery level.");
            setNotification(context, context.getResources().getString(R.string.upgrade_failed_due_to_battery),
                    false);
        }
    } catch (IOException e) {
        reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_INSTALL_FAILED);
        String message = "Update installation failed due to file error.";
        Log.e(TAG, message + e);
        CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.FAILURE,
                Constants.Status.OTA_IMAGE_VERIFICATION_FAILED, message);
        CommonUtils.callAgentApp(context, Constants.Operation.FAILED_FIRMWARE_UPGRADE_NOTIFICATION,
                Preference.getInt(context, context.getResources().getString(R.string.operation_id)), message);
    } catch (SecurityException e) {
        reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_INSTALL_FAILED);
        String message = "Update installation failure due to security check failure.";
        Log.e(TAG, message + e);
        CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.FAILURE,
                Constants.Status.OTA_IMAGE_VERIFICATION_FAILED, message);
        CommonUtils.callAgentApp(context, Constants.Operation.FAILED_FIRMWARE_UPGRADE_NOTIFICATION,
                Preference.getInt(context, context.getResources().getString(R.string.operation_id)), message);
    } finally {
        wakeLock.release();
    }

}