pos机双屏异显项目 --- 在密码解锁或设置密码时,副屏不显示或显示张图片

双屏异显项目 ,在密码解锁时,副屏也会同步显示密码,为了用户的密码安全,副屏解锁时,副屏亮度调为0;(锁屏界面getActivity()不能使用,暂时只能调节副屏亮度为0来解决)

另外,在设置中设置密码时,副屏也会同步显示设置的密码,此时让副屏显示一张图片。(这种方式比较简单)

以下只列举来部分代码和分析,详细可以在文章里下载patch
https://download.csdn.net/download/m1126125223/10686720

一、设置
在设置中设置密码、手势,或密码、手势验证的时候,副屏都显示一张图片,在activity中使用的方法基本都一样,不过一一列举,只列出一种;

packages/apps/Settings/src/com/android/settings/ConfirmLockPattern.java
主要是获取屏屏幕的个数
+               DifferentDislay presentation;
+               DisplayManager displayManager = (DisplayManager) getActivity().getSystemService(Context.DISPLAY_SERVICE);
+               Display[] presentationDisplays = displayManager.getDisplays();
+        if (presentationDisplays.length > 1) {
+            presentation = new DifferentDislay(getActivity(), presentationDisplays[1]);
+        } else {
+            presentation = new DifferentDislay(getActivity(), presentationDisplays[0]);
+        }
+                       presentation.show();
new files
DifferentDislay.java
play_video.xml

public class DifferentDislay extends Presentation {
    public VideoView videoView;

    public DifferentDislay(Context outerContext, Display display) {
        super(outerContext, display);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.play_video);

        videoView = (VideoView ) findViewById(R.id.video_view);

    }
}

二、锁屏

开机广播

frameworks/base/packages/Keyguard/AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
frameworks/base/packages/SettingsProvider/res/values/defaults.xml
<integer name="def_keyguad_boot_brightness_enbled">0</integer><!--副屏亮度值0-->

二、需要将副屏的亮度保存到一个文件中,在密码解锁界面,副屏亮度调为0,解锁过后,副屏亮度恢复到原来的亮度

frameworks/base/packages/Keyguard/src/com/android/keyguard/BrightnessUtils.java

+public class BrightnessUtils {
+    private static final String TAG = "BrightnessUtils";
+    public static final String sys_path = "/sys/class/backlight/backlight1/brightness";
+    public final static String BRIGHTNESSVALUES = "bright";
+
+    public static void putValues(String key, String value ,Context context) {
+        SharedPreferences.Editor sp = context.getSharedPreferences(BRIGHTNESSVALUES, context.MODE_PRIVATE).edit();
+        sp.putString(key, value);
+        sp.commit();
+    }
+
+    public static String getValues(String key, String defValue,Context context) {
+        SharedPreferences sp = context.getSharedPreferences(BRIGHTNESSVALUES, context.MODE_PRIVATE);
+        String value = sp.getString(key, defValue);
+        return value;
+    }
+
+
+
+    public static String readSysFile(String sys_path) {
+
+        if (sys_path == null || sys_path.length() == 0) return "";
+
+        File file = new File(sys_path);
+        if (!file.exists()) {
+            Log.d(TAG, "file is not exits");
+            return "";
+        }
+        String prop = "0";// 榛..??M
+        if (file.isDirectory()) {
+            Log.d(TAG, "The File is directory.");
+        } else {
+
+            BufferedReader reader = null;
+            try {
+                reader = new BufferedReader(new FileReader(sys_path));
+                prop = reader.readLine();
+                Log.d(TAG, "readFile: prop=" + prop);
+            } catch (IOException e) {
+                e.printStackTrace();
+                Log.d(TAG, " ***ERROR*** Here is what I know: " + e.getMessage());
+            } finally {
+                if (reader != null) {
+                    try {
+                        reader.close();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+        Log.d(TAG, "readFile cmd from" + sys_path + "data" + "  prop = " + prop);
+        return prop;
+    }
+
+
+    public static void writeSysFile(String sys_path, String value) {
+
+        if (sys_path == null || sys_path.length() == 0) return;
+
+        File file = new File(sys_path);
+        if (!file.exists()) {
+            Log.d(TAG, "file is not exits");
+            return;
+        }
+
+        if (file.isDirectory()) {
+            Log.d(TAG, "The File is directory.");
+        } else {
+            BufferedWriter writer = null;
+            try {
+
+                writer = new BufferedWriter(new FileWriter(sys_path));
+                writer.write(value);//?.€兼.浣.M
+                writer.flush();
+                writer.close();
+                //Log.d(TAG, "write value=" + value);
+            } catch (IOException e) {
+                e.printStackTrace();
+                Log.d(TAG, "can't write the " + sys_path + e.toString());
+            }
+        }
+    }
+}

三、解锁成功后,重新设置副屏亮度

             if (dismissKeyguard) {
                 mDismissing = true;
                 mCallback.dismiss(true);
+                                   /* add by yuanantao 20180821 begin*/                                        
+                                   AsyncTask.execute(new Runnable() {
+                     public void run() {
+                                                String value  = BrightnessUtils.getValues("KERYGUAD", 155+"",mConte
+                         BrightnessUtils.writeSysFile(BrightnessUtils.sys_path,  value);
+                }
+            });

还有一些未详细列举,可以下载参考
https://download.csdn.net/download/m1126125223/10686720

猜你喜欢

转载自blog.csdn.net/m1126125223/article/details/82842802