1. 程式人生 > >pos機雙屏異顯專案 --- 在密碼解鎖或設定密碼時,副屏不顯示或顯示張圖片

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