a
554325746@qq.com
2019-12-25 603cb36a5123e46656b06a5deb8d7ac7ff81307f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package com.alfeye.a1io;
 
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
/**
 * 设备相关操作 工具类
 * Created by DELL on 2018/11/30.
 */
 
public class DeviceControl {
 
    private static final String ACTION_CAMERA_HDR = "com.alf.camera.hdr";
    private static final String KEY_CAMERA_HDR = "key_camera_hdr";
    private static final String DEV_INFORMATIONSCREEN = "com.alf.screen.action";
    private static final String KEY_OPEN_SCREEN = "input keyevent 224";
    private static final String KEY_CLOSE_SCREEN = "input keyevent 223";
    private static SharedPreferences sharedPreferences;
 
    //-------------------------------------------------------
    /**
     * 安装 本地应用
     */
    private static final String ACTION_INSTALL_PACKAGES = "com.alfeye.upgradeserver.action_install_packages";
 
    /**
     * APK包名
     */
    private static String KEY_PACKAGENAME = "key_packagename";
    /**
     * Apk路径
     */
    private static String KEY_APK_FILEPATH = "key_apk_filepath";
    /**
     * 是否显示安装界面
     */
    private static String KEY_IS_SHOW_LOADING = "key_is_show_loading";
    /**
     * 安装完成 是否启动APK
     */
    private static String KEY_IS_START_APK = "key_is_start_apk";
 
    private DeviceControl() {
 
    }
 
    /**
     * 开启屏幕并预览
     *
     *
     **/
    public static void openScreen() {
        execCommandSilent(KEY_OPEN_SCREEN);
    }
 
    /**
     * 关闭屏幕  需要系統簽名
     **/
    public static void closeScreen() {
        execCommandSilent(KEY_CLOSE_SCREEN);
    }
 
 
    /**
     * 关闭
     *
     * @param command
     */
    public static void execCommandSilent(String command) {
        try {
            Process p = Runtime.getRuntime().exec(new String[]{"/system/bin/sh", "-c", command});
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String readLine = br.readLine();
            while (readLine != null) {
                readLine = br.readLine();
            }
            br.close();
            p.destroy();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 初始化
     *
     * @param context
     */
    private static void init(Context context) {
        if (sharedPreferences == null) {
            sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        }
    }
 
    /**
     * 摄像头宽动态控制
     *
     * @param context
     * @param state
     */
    public static void configCameraHdr(Context context, boolean state) {
        if (sharedPreferences == null) {
            init(context);
        }
        sendCameraHdrBroadcast(context, state);
        sharedPreferences.edit().putBoolean(KEY_CAMERA_HDR, state).apply();
    }
 
    /**
     * 获取Hdr的状态
     */
    public static boolean getCameraHdrStatus(Context context) {
        if (sharedPreferences == null) {
            init(context);
        }
        return sharedPreferences.getBoolean(KEY_CAMERA_HDR, false);
    }
 
    /**
     * A1屏幕息屏 亮屏
     * 不需要簽名
     * @param context
     * @param state   true亮屏  false息屏
     */
    public static void sendInformationScreen(Context context, boolean state) {
        Intent camerIntent = new Intent(DEV_INFORMATIONSCREEN);
        camerIntent.putExtra("on", state);
        context.sendBroadcast(camerIntent);
    }
 
 
    /**
     * 摄像头宽动态控制
     *
     * @param context
     * @param state   true开启  false关闭
     */
    private static void sendCameraHdrBroadcast(Context context, boolean state) {
        Intent camerIntent = new Intent(ACTION_CAMERA_HDR);
        camerIntent.putExtra("enabled", state ? "true" : "false");
        context.sendBroadcast(camerIntent);
    }
 
    /**
     * 设备重启
     *
     * @param context
     */
    public static void rebootSystem(Context context) {
        Intent devIntent = new Intent();
        devIntent.setAction("com.alf.reboot.system");
        context.sendBroadcast(devIntent);
    }
 
    /**
     * 隐藏 系统导航栏
     *
     * @param context
     * @param state   true 隐藏  false 还原显示
     */
    public static void hideNavigationBar(Context context, boolean state) {
        Intent sbarIntent = new Intent();
        sbarIntent.setAction("com.alf.switch_status_bar");
        sbarIntent.putExtra("hide", state);
        context.sendBroadcast(sbarIntent);
    }
 
    /**
     * 设置应用为 系统launcher
     * 需要再androidManifest添加
     * 启动的activity 需要设置为 HOME LAUNCHER
     * <intent-filter>
     * <action android:name="android.intent.action.MAIN"/>
     * <category android:name="android.intent.category.LAUNCHER"/>
     * <category android:name="android.intent.category.HOME"/>
     * <category android:name="android.intent.category.DEFAULT"/>
     * </intent-filter>
     *
     * @param context
     * @param pkgname 包名
     */
    public static void setSystemLauncher(Context context, String pkgname) {
        Intent intentLauncher = new Intent();
        //设置launcher 广播
        intentLauncher.setAction("com.alf.set.default.launcher");
        intentLauncher.putExtra("pkgname", pkgname);
        context.sendBroadcast(intentLauncher);
    }
 
 
 
 
    /**
     * 静默安装 APK
     *
     * @param context
     * @param apkPackageName APK包名
     * @param apkFilePath    Apk路径
     * @param isShowLoading  是否显示安装加载界面
     * @param isStartApk     安装完成 是否启动APK
     */
    public static void startInstallApk(Context context, String apkPackageName, String apkFilePath, boolean isShowLoading, boolean isStartApk) {
        try {
            Intent intent = new Intent();
            intent.setPackage("com.alfeye.upgradeserver");
            intent.setAction(ACTION_INSTALL_PACKAGES);
            intent.putExtra(KEY_PACKAGENAME, apkPackageName);
            intent.putExtra(KEY_APK_FILEPATH, apkFilePath);
            intent.putExtra(KEY_IS_SHOW_LOADING, isShowLoading);
            intent.putExtra(KEY_IS_START_APK, isStartApk);
            context.startService(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
}