package com.hh.hhomc.deviceui;

import android.app.Activity;
import android.text.TextUtils;

import com.common.lib_base.utils.log.AppLogUtils;
import com.common.pos.api.util.ShellUtils;

/**
 * 其余设备
 * 空实现
 */
public class NullDeviceUI implements IDeviceUI {

    //用volatile关键字确保 instance 在多线程下的可见性
    private static volatile NullDeviceUI instance = null;

    //将构造方法私有化，禁止外部通过构造方法创建实例
    private NullDeviceUI() {}

    //提供一个公共的访问方法，用于获取该类的唯一实例
    public static NullDeviceUI getInstance() {
        //如果instance为空，就进行实例化
        if (instance == null) {
            //保证多线程下只有一个线程进行实例化
            synchronized (NullDeviceUI.class) {
                //第二次判断，避免多线程下创建多个实例
                if (instance == null) {
                    instance = new NullDeviceUI();
                }
            }
        }
        return instance;
    }


    @Override
    public void showNotification(Activity activity) {
    }

    @Override
    public void hideNotification(Activity activity) {
    }

    @Override
    public void showNavigationBar(Activity activity) {
    }

    @Override
    public void hideNavigationBar(Activity activity) {
    }

    @Override
    public void showFillLight(Activity activity) {

    }

    @Override
    public void hideFillLight(Activity activity) {

    }

    @Override
    public void reboot() {

    }

    @Override
    public void silenceInstall(String path,SilenceInstallSuccessListener listener) {
        if(TextUtils.isEmpty(path)){
            return;
        }
        try {
            String[] commands = {"0", "chmod", "777", path};
            ShellUtils.execCommand(commands, true);
            String cmd = "pm install -r " + path;
            ShellUtils.CommandResult commandResult = ShellUtils.execCommand(cmd, true);
            if (commandResult != null && commandResult.result == 0 && listener != null) {
                listener.success(true);
            } else if (listener != null) {
                listener.success(false);
            }
        } catch (Exception e) {
            AppLogUtils.e(e.toString());
            if (listener != null) {
                listener.success(false);
            }
        }
    }

    @Override
    public void silenceUnInstall(String packageName) {

    }
}
